atg.nucleus
Class BeanConfigurator

java.lang.Object
  extended by atg.nucleus.BeanConfigurator

public class BeanConfigurator
extends java.lang.Object

A BeanConfigurator configures a bean from a Properties list of name/value String pairs. Configuration includes setting property values, and hooking up event listeners.

The BeanConfigurator begins by obtaining the BeanInfo for the bean. The BeanInfo will list all of the bean's settable properties, and all of the bean's event sets.

The BeanConfigurator then enumerates through the bean's settable properties. For each property, the configurator looks in the Properties list for a property with the same name. Properties that take arrays as values are treated the same way. For example, two methods "setPrice(float)" and "setPrices(float[])" would define two properties: "price" and "prices". One property expects a "float" as a value, the other expects an array of floats as a value.

The BeanConfigurator then looks at the String value of the property and attempts to convert that value to the type expected for the property. The configurator knows how to perform conversions for the following types: boolean, byte, char, short, int, long, float, double, String, plus some others listed below. If the property value is actually an array of these types, then the values are expected to be separated by commas. As explained below, the BeanConfigurator can be extended to recognize other types of property values.

For example, using the above "price" and "prices" properties, the following lines in the Properties file would set the property values correctly:

   price=12.5
   prices=14.6,8.0,12.9
 

If the type of the property is not recognized by the configurator, then the configurator will assume that the property value names another service in the Nucleus. The name is resolved using a NameResolver. For example, if a property has the signature "setMimeTyper(MimeTyper)", then the configurator will expect a property with the name "mimeTyper", and the value of that property should name another bean in the nucleus of type "MimeTyper". For example:

   mimeTyper=../converters/MimeTyper
 

The same applies to array values. For example, if a property has the signature "setMimeTypers(MimeTyper[])", that property could be set with the line:

   mimeTypersList=../converters/MimeTyper,backups/MimeTyper
 

Both names will be resolved to beans in the nucleus and assigned to a two-element array which will in turn be assigned to the property.

Event sets are handled in a similar manner. If a bean has an event set called "notify", then the configurator will expect a property name "notifyListeners". The value of that property is treated as a comma-separated list of bean names that are resolved individually and added as listeners. For example:

   notifyListeners=../logs/NotifyLog,../scheduler/Schedules
 

As mentioned above, the BeanConfigurator can be extended to recognize new property types. One does this by registering implementations of java.beans.PropertyEditor, or by providing a named PropertyEditor class. These implementations must support the setAsText() and getAsText() methods. By default, the BeanConfigurator recognizes the following objects for which PropertyEditors are statically registered:

  • The primitives: boolean, byte, char, short, int, long, float, double. These are parsed into their primitive values. Char is parsed by taking the first character of the value.
  • java.lang.String: the property value becomes the String
  • java.io.File: a File object is created around the value. Any trailing "/" characters are removed, and the "/" character is converted to the OS-specific separator character. This allows the same File specification Strings to be used on all OS's.
  • java.util.Date: the Date is parsed in a flexible format that contains both date and time. If either date or time is not specified, the current date or time is used instead. Some example valid dates you can use for nucleus date properties are:
        1/23/89
        1/23/89 4:45:21
        1/23/89 4:45
        1/23/1989 4:45
        4:45:21
        4:45pm
        April 23 89
        April 23 89 4pm
        23 April 89 4:45
      
  • java.net.InetAddress: the property value is a hostname, and is converted to and IP address. The hostname may be a machine name such as "www.atg.com", or it may be an IP addres such as "205.181.94.1".
  • java.util.Properties: the properties are parsed in the form "prop1=val1,prop2=val2,prop3=val3...", where both the property names and values are converted to Strings. Property names and values cannot contain the characters "=" or ",".
  • atg.service.scheduler.Schedule: this is used to define a Schedule for a job that will be passed to the Scheduler. See the documentation for SchedulePropertyEditor to see the format for specifying the schedule.

    See Also:
    ScheduleEditor

    Field Summary
    static java.lang.String CLASS_VERSION
              Class version string
     
    Constructor Summary
    BeanConfigurator()
              Constructs a new blank BeanConfigurator
     
    Method Summary
     void configureBean(java.lang.String pConfigurationName, java.lang.Object pBean, atg.nucleus.ConfigurationState pState, NameResolver pResolver, ApplicationLogging pLog)
              Configures the specified bean from the specified ConfigurationState
     void configureBean(java.lang.String pConfigurationName, java.lang.Object pBean, java.util.Properties pProperties, java.util.Properties pAbsoluteProperties, NameResolver pResolver, ApplicationLogging pLog)
              Configures the specified bean by walking through the given BeanInfo description.
     void configureState(java.lang.String pConfigurationName, atg.nucleus.ConfigurationState pState, java.util.Properties pProperties, java.util.Properties pAbsoluteProperties, ApplicationLogging pLog)
              Configures the specified ConfigurationState from the specified properties.
     void configureStateProperty(java.lang.String pConfigurationName, atg.nucleus.ConfigurationState pState, java.beans.PropertyDescriptor pDescriptor, java.util.Properties pProperties, java.util.Properties pAbsoluteProperties, ApplicationLogging pLog)
              Configures a state property by searching the Properties for the property's name and configuring the ConfigurationState appropriately.
     atg.nucleus.ConfigurationProperty getArrayConfigurationProperty(java.lang.String pConfigurationName, java.lang.String pName, java.lang.String pValue, java.lang.String pAbsValue, java.lang.Class pClass, ApplicationLogging pLog)
              Treats the specified value as a comma-separated list of values, which are assigned to an array whose components are of the type specified by the class (which must be an array type).
     atg.nucleus.ConfigurationProperty getLinkedConfigurationProperty(java.lang.String pConfigurationName, java.lang.String pName, java.lang.String pAbsValue, java.lang.Class pClass, ApplicationLogging pLog)
              Obtains a property value where the value is of the form "serviceName.propertyName".
     atg.nucleus.ConfigurationProperty getProperty(java.lang.String pConfigurationName, java.lang.String pName, java.lang.String pValue, java.lang.String pAbsValue, java.lang.Class pClass, ApplicationLogging pLog)
              Converts the specified value to the specified class.
     atg.nucleus.PropertyValueParser getPropertyValueParser(java.lang.Class pClass)
              FIX THIS: This method is included for backward-compatibility with atg.repository that looks for implementations of PropertyValueParser.
     boolean isConfigurationExceptionWarning(java.lang.Object pBean, java.lang.String pPropertyName, NameResolver pResolver)
              Whether the configuration exception should be a warning instead of an error.
     boolean isConstant(java.lang.Class pClass)
              Returns true if a property of the given class is a constant value, false if the property points to another service.
     void representState(java.lang.String pConfigurationName, atg.nucleus.ConfigurationState pState, java.util.Properties pProperties)
              Represents the specified ConfigurationState as a set of Properties.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    CLASS_VERSION

    public static java.lang.String CLASS_VERSION
    Class version string

    Constructor Detail

    BeanConfigurator

    public BeanConfigurator()
    Constructs a new blank BeanConfigurator

    Method Detail

    getPropertyValueParser

    public atg.nucleus.PropertyValueParser getPropertyValueParser(java.lang.Class pClass)
    FIX THIS: This method is included for backward-compatibility with atg.repository that looks for implementations of PropertyValueParser. It should be removed (along with PropertyValueParser itself) when that code acquires its own branch.


    configureBean

    public void configureBean(java.lang.String pConfigurationName,
                              java.lang.Object pBean,
                              java.util.Properties pProperties,
                              java.util.Properties pAbsoluteProperties,
                              NameResolver pResolver,
                              ApplicationLogging pLog)
    Configures the specified bean by walking through the given BeanInfo description.

    Parameters:
    pConfigurationName - the name to be used in error messages
    pBean - the bean to be configured
    pProperties - the properties file to be used to configure the bean
    pAbsoluteProperties - the properties file to be used to configure the bean, containing all entries in absolute form
    pResolver - the NameResolver to be used to resolve bean names found as property values.
    pLog - the logger to which errors and informative messages should be printed.

    configureBean

    public void configureBean(java.lang.String pConfigurationName,
                              java.lang.Object pBean,
                              atg.nucleus.ConfigurationState pState,
                              NameResolver pResolver,
                              ApplicationLogging pLog)
    Configures the specified bean from the specified ConfigurationState

    Parameters:
    pConfigurationName - the name to be used in error messages
    pBean - the bean to be configured
    pState - the configuration state to use to configure the bean
    pResolver - the NameResolver to be used to resolve bean
    pLog - the logger to which errors and informative messages should be printed.

    configureState

    public void configureState(java.lang.String pConfigurationName,
                               atg.nucleus.ConfigurationState pState,
                               java.util.Properties pProperties,
                               java.util.Properties pAbsoluteProperties,
                               ApplicationLogging pLog)
    Configures the specified ConfigurationState from the specified properties.

    Parameters:
    pConfigurationName - the name to be used in error messages
    pState - the ConfigurationState which represents the configured state of the bean.
    pProperties - the properties file to be used to configure the bean
    pAbsoluteProperties - the properties file to be used to configure the bean, containing all entries in absolute form names found as property values.
    pLog - the logger to which errors and informative messages should be printed.

    isConstant

    public boolean isConstant(java.lang.Class pClass)
    Returns true if a property of the given class is a constant value, false if the property points to another service.


    configureStateProperty

    public void configureStateProperty(java.lang.String pConfigurationName,
                                       atg.nucleus.ConfigurationState pState,
                                       java.beans.PropertyDescriptor pDescriptor,
                                       java.util.Properties pProperties,
                                       java.util.Properties pAbsoluteProperties,
                                       ApplicationLogging pLog)
    Configures a state property by searching the Properties for the property's name and configuring the ConfigurationState appropriately.

    Parameters:
    pConfigurationName - the name to be used in error messages
    pState - the ConfigurationState to be configured
    pDescriptor - the PropertyDescriptor of the property to be configured
    pProperties - the properties file to be used to configure the bean
    pAbsoluteProperties - the properties file to be used to configure the bean, containing all entries in absolute form
    pLog - the logger to which errors and informative messages should be printed.

    getProperty

    public atg.nucleus.ConfigurationProperty getProperty(java.lang.String pConfigurationName,
                                                         java.lang.String pName,
                                                         java.lang.String pValue,
                                                         java.lang.String pAbsValue,
                                                         java.lang.Class pClass,
                                                         ApplicationLogging pLog)
    Converts the specified value to the specified class. If the class is not known, then the value is treated as the name of a service in the context. If the class is an array, then the value will be broken up into its comma-separated parts and the value returned will be an array of those parts. If the class is a ServiceMap, then the value is parsed as a Properties, except that each value is resolved as a service name.


    getArrayConfigurationProperty

    public atg.nucleus.ConfigurationProperty getArrayConfigurationProperty(java.lang.String pConfigurationName,
                                                                           java.lang.String pName,
                                                                           java.lang.String pValue,
                                                                           java.lang.String pAbsValue,
                                                                           java.lang.Class pClass,
                                                                           ApplicationLogging pLog)
    Treats the specified value as a comma-separated list of values, which are assigned to an array whose components are of the type specified by the class (which must be an array type). If the component type of the array is not known, then the values are treated as names of services in Nucleus.


    getLinkedConfigurationProperty

    public atg.nucleus.ConfigurationProperty getLinkedConfigurationProperty(java.lang.String pConfigurationName,
                                                                            java.lang.String pName,
                                                                            java.lang.String pAbsValue,
                                                                            java.lang.Class pClass,
                                                                            ApplicationLogging pLog)
    Obtains a property value where the value is of the form "serviceName.propertyName".


    representState

    public void representState(java.lang.String pConfigurationName,
                               atg.nucleus.ConfigurationState pState,
                               java.util.Properties pProperties)
                        throws java.beans.IntrospectionException,
                               java.lang.IllegalArgumentException
    Represents the specified ConfigurationState as a set of Properties.

    Parameters:
    pConfigurationName - the name to be used in error messages
    pState - the ConfigurationState which represents the configured state of the bean.
    pProperties - the properties to be used to represent the bean
    Throws:
    java.beans.IntrospectionException
    java.lang.IllegalArgumentException

    isConfigurationExceptionWarning

    public boolean isConfigurationExceptionWarning(java.lang.Object pBean,
                                                   java.lang.String pPropertyName,
                                                   NameResolver pResolver)
    Whether the configuration exception should be a warning instead of an error.