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:
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
ScheduleEditor
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string
|
Constructor and Description |
---|
BeanConfigurator()
Constructs a new blank BeanConfigurator
|
Modifier and Type | Method and Description |
---|---|
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.
|
public BeanConfigurator()
public atg.nucleus.PropertyValueParser getPropertyValueParser(java.lang.Class pClass)
public void configureBean(java.lang.String pConfigurationName, java.lang.Object pBean, java.util.Properties pProperties, java.util.Properties pAbsoluteProperties, NameResolver pResolver, ApplicationLogging pLog)
pConfigurationName
- the name to be used in error messagespBean
- the bean to be configuredpProperties
- the properties file to be used to configure
the beanpAbsoluteProperties
- the properties file to be used to
configure the bean, containing all entries in absolute formpResolver
- 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.public void configureBean(java.lang.String pConfigurationName, java.lang.Object pBean, atg.nucleus.ConfigurationState pState, NameResolver pResolver, ApplicationLogging pLog)
pConfigurationName
- the name to be used in error messagespBean
- the bean to be configuredpState
- the configuration state to use to configure the beanpResolver
- the NameResolver to be used to resolve beanpLog
- the logger to which errors and informative messages
should be printed.public void configureState(java.lang.String pConfigurationName, atg.nucleus.ConfigurationState pState, java.util.Properties pProperties, java.util.Properties pAbsoluteProperties, ApplicationLogging pLog)
pConfigurationName
- the name to be used in error messagespState
- the ConfigurationState which represents the configured
state of the bean.pProperties
- the properties file to be used to configure
the beanpAbsoluteProperties
- 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.public boolean isConstant(java.lang.Class pClass)
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)
pConfigurationName
- the name to be used in error messagespState
- the ConfigurationState to be configuredpDescriptor
- the PropertyDescriptor of the property to be
configuredpProperties
- the properties file to be used to configure
the beanpAbsoluteProperties
- the properties file to be used to
configure the bean, containing all entries in absolute formpLog
- the logger to which errors and informative messages
should be printed.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)
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)
public atg.nucleus.ConfigurationProperty getLinkedConfigurationProperty(java.lang.String pConfigurationName, java.lang.String pName, java.lang.String pAbsValue, java.lang.Class pClass, ApplicationLogging pLog)
public void representState(java.lang.String pConfigurationName, atg.nucleus.ConfigurationState pState, java.util.Properties pProperties) throws java.beans.IntrospectionException, java.lang.IllegalArgumentException
pConfigurationName
- the name to be used in error messagespState
- the ConfigurationState which represents the configured
state of the bean.pProperties
- the properties to be used to represent
the beanjava.beans.IntrospectionException
java.lang.IllegalArgumentException
public boolean isConfigurationExceptionWarning(java.lang.Object pBean, java.lang.String pPropertyName, NameResolver pResolver)