com.taco.text
Class CompositeConverter

java.lang.Object
  extended by com.taco.text.AbstractInterpolatingStringToObjectConverter
      extended by com.taco.text.InterpolatingConverter
          extended by com.taco.text.CompositeConverter
All Implemented Interfaces:
IInterpolatingConverter, IInterpolatingStringToObjectConverter, IStringToObjectConverter, IInterpolatingResourceBundleToObjectConverter, java.lang.Cloneable
Direct Known Subclasses:
BracedPropertyCompositeConverter

public abstract class CompositeConverter
extends InterpolatingConverter

An interpolating converter that creates objects that have many properties.


Nested Class Summary
protected static class CompositeConverter.AbstractCompositeUpdater
          A useful base class for a listener that updates a composite when the value corresponding to an argument map key changes.
protected static class CompositeConverter.AbstractMapConsistencyListener
          A useful base class for observable map updaters.
protected static class CompositeConverter.CompositeUpdater
          A property change listener that updates a composite using the set property action used to configure it originally.
protected static class CompositeConverter.DefaultMapConsistencyListener
          A property change listener for beans which updates the observable map when a property of the bean changes.
static class CompositeConverter.DelayedConvertedResult
          A delayed result that evaluates another delayed result and converts it.
static interface CompositeConverter.ICompositeUpdater
          A marker interface for a listener that updates a composite when the value corresponding to an argument map key changes.
static interface CompositeConverter.IMapConsistencyListener
          A marker interface for listeners that update the argument map when a composite's property changes.
static interface CompositeConverter.ISetPropertyAction
          An interface that specifies the action taken in order to set a property value of a composite object.
protected static class CompositeConverter.NotUpdaterListenerFilter
          A filter that rejects instances of ICompositeUpdater that update a specific property of a composite object, so that when a map consistency listener puts a value in the map, an updater doesn't set the property again.
protected static class CompositeConverter.ReflectionSetPropertyAction
          An implementation of ISetPropertyAction which uses reflection to set the property.
 
Field Summary
protected static java.util.Map _DEFAULT_COMPOSITE_CONVERTER_MAP
          A map from property names that this class handles to converters for the value of properties.
protected static java.util.List _DEFAULT_COMPOSITE_CREATION_PROPERTY_NAMES
          The property names every composite uses for creation.
protected static java.lang.String _SHOULD_READ_GLOBAL_NAME
          A string used for the globalName parameter which means that the global name should be read from the bundle.
 
Fields inherited from class com.taco.text.InterpolatingConverter
_BAD_OBJECT_MAPPER, _IGNORE_PROPERTY_VALUE, _IMPORTS, _STATIC_IMPORTS, _TO_OBJECT_MAPPER_CONVERTER, DEFAULT_INSTANCE
 
Fields inherited from class com.taco.text.AbstractInterpolatingStringToObjectConverter
_defArgMap, _defBundle
 
Constructor Summary
CompositeConverter()
          Create a new instance whose implementation of IStringToObjectConverter is incapable of resolving references.
CompositeConverter(java.util.ResourceBundle bundle, INoReturnMap argMap)
          Create a new instance whose implementation of IStringToObjectConverter uses the specified resource bundle and argument map to resolve references.
 
Method Summary
protected  void _addMapConsistencyListener(java.lang.Object composite, java.lang.String propertyName, IObjectMapper toMapValueConverter, INoReturnMap argMap, java.lang.Object mapKey, java.lang.reflect.Method addListenerMethod)
          Add a listener to composite that will update the value associated with mapKey in observableMap when the propertyName property of the composite changes.
protected  void _addMapConsistencyListeners(KeyLookupRecord keyLookupRecord, java.lang.Object composite, INoReturnMap argMap)
          If composite is a bean and supports bound properties, add a property change listener to the bean that updates the observable map when the bean's property is changed.
protected  void _addProperties(java.lang.Object composite, java.lang.String baseKey, java.util.Collection propertyNames, java.util.ResourceBundle bundle, INoReturnMap argMap, KeyLookupRecord context, java.util.Map propertyMap)
          Create all properties with the argument collection of property names, and put them in the property map.
protected  void _addUpdaterListeners(KeyLookupRecord keyLookupRecord, java.lang.Object composite, INoReturnMap argMap)
          Add listeners to the observable argument map, so that the composite's properties will be updated on changes to the argument map.
protected  void _configureComposite(java.lang.Object composite, java.lang.String baseKey, java.util.ResourceBundle bundle, INoReturnMap argMap, java.util.Map propertyMap, boolean wasInstanceDefined, java.lang.String globalName)
          Configure the composite object, putting properties from the argument property map.
protected  java.lang.Object _createComposite(java.util.Map propertyMap, java.util.ResourceBundle bundle, INoReturnMap argMap)
          Given the property key / value map, return a composite object ready to have its properties set (if legal).
protected  java.beans.PropertyChangeListener _createUpdaterListener(java.lang.Object composite, java.lang.String propertyName, IObjectMapper fromMapValueConverter)
          Create a property change listener to add to the observable argument map, so that the composite is updated when a value in the map changes.
protected abstract  CompositeConverter.ISetPropertyAction _getActionForProperty(java.lang.String propertyName)
          Return an instance ISetPropertyAction for the argument property name.
protected abstract  java.lang.Object _literalToObject(java.lang.String s, java.util.ResourceBundle bundle, INoReturnMap argMap, java.lang.String globalName)
          Given s, which is a string literal, not a reference to a resource bundle key or a key in the argument map, convert s to an object.
protected  InterpolatingConverter _makeInitConverter(java.lang.Object composite)
          Create a converter used for the preInit and postInit special properties.
protected  void _setProperties(java.lang.Object composite, java.util.Map propertyMap)
          Given the partially created object and a map of property names to property values, configure the object to reflect all of the properties.
protected  java.lang.Object _toObject(java.util.ResourceBundle bundle, java.lang.String baseKey, INoReturnMap argMap, KeyLookupRecord context, java.lang.String globalName)
          If the value associated with baseKey is a non-null string, use this instance to convert it to an object.
 void configureComposite(java.lang.Object composite, java.lang.String baseKey, java.util.ResourceBundle bundle, INoReturnMap argMap)
          Configure the composite object.
abstract  IInterpolatingConverter getConverterForProperty(java.lang.String propertyName, java.lang.Object composite)
          Return an instance of IInterpolatingConverter for the argument property name.
 java.lang.String getConverterNameForProperty(java.lang.String propertyName)
          Return a string that indicates the type of converter used for the argument property.
 java.util.Collection getCreationPropertyNames()
          Return a collection of names of properties of the composite needed at construction time.
abstract  java.util.Collection getPropertyNames()
          Return a collection of names of properties of the composite being created.
 boolean isPropertyReadable(java.lang.String propertyName)
          Return true if the property is readable by this converter.
 boolean isPropertyUpdatable(java.lang.String propertyName)
          Return true if the property is updatable by this converter.
 boolean isPropertyWritable(java.lang.String propertyName)
          Return true if the property is writable by this converter.
 
Methods inherited from class com.taco.text.InterpolatingConverter
_argMapReferenceToObject, _getStandardImports, _getStandardStaticImports, _literalResultToObject, _scriptSnippetToObject, _toObjectMapper, clone, name, toObject, toObject, toObject
 
Methods inherited from class com.taco.text.AbstractInterpolatingStringToObjectConverter
toObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_DEFAULT_COMPOSITE_CREATION_PROPERTY_NAMES

protected static final java.util.List _DEFAULT_COMPOSITE_CREATION_PROPERTY_NAMES
The property names every composite uses for creation. This is an empty list, but may change in the future.


_DEFAULT_COMPOSITE_CONVERTER_MAP

protected static final java.util.Map _DEFAULT_COMPOSITE_CONVERTER_MAP
A map from property names that this class handles to converters for the value of properties. This is the empty map, but may change in the future.


_SHOULD_READ_GLOBAL_NAME

protected static final java.lang.String _SHOULD_READ_GLOBAL_NAME
A string used for the globalName parameter which means that the global name should be read from the bundle.

See Also:
Constant Field Values
Constructor Detail

CompositeConverter

public CompositeConverter()
Create a new instance whose implementation of IStringToObjectConverter is incapable of resolving references.


CompositeConverter

public CompositeConverter(java.util.ResourceBundle bundle,
                          INoReturnMap argMap)
Create a new instance whose implementation of IStringToObjectConverter uses the specified resource bundle and argument map to resolve references.

Method Detail

configureComposite

public void configureComposite(java.lang.Object composite,
                               java.lang.String baseKey,
                               java.util.ResourceBundle bundle,
                               INoReturnMap argMap)
Configure the composite object.

Parameters:
composite - The object to configure.
baseKey - The resource bundle key to use as the base key.
bundle - The resource bundle.
argMap - The argument map (may be null).

_configureComposite

protected void _configureComposite(java.lang.Object composite,
                                   java.lang.String baseKey,
                                   java.util.ResourceBundle bundle,
                                   INoReturnMap argMap,
                                   java.util.Map propertyMap,
                                   boolean wasInstanceDefined,
                                   java.lang.String globalName)
Configure the composite object, putting properties from the argument property map.


_toObject

protected java.lang.Object _toObject(java.util.ResourceBundle bundle,
                                     java.lang.String baseKey,
                                     INoReturnMap argMap,
                                     KeyLookupRecord context,
                                     java.lang.String globalName)
                              throws java.text.ParseException,
                                     java.util.MissingResourceException
Description copied from class: InterpolatingConverter
If the value associated with baseKey is a non-null string, use this instance to convert it to an object. Otherwise, return the object.

Overrides:
_toObject in class InterpolatingConverter
Throws:
java.text.ParseException
java.util.MissingResourceException

_addProperties

protected void _addProperties(java.lang.Object composite,
                              java.lang.String baseKey,
                              java.util.Collection propertyNames,
                              java.util.ResourceBundle bundle,
                              INoReturnMap argMap,
                              KeyLookupRecord context,
                              java.util.Map propertyMap)
Create all properties with the argument collection of property names, and put them in the property map.


_literalToObject

protected abstract java.lang.Object _literalToObject(java.lang.String s,
                                                     java.util.ResourceBundle bundle,
                                                     INoReturnMap argMap,
                                                     java.lang.String globalName)
                                              throws java.text.ParseException,
                                                     java.util.MissingResourceException
Description copied from class: InterpolatingConverter

Given s, which is a string literal, not a reference to a resource bundle key or a key in the argument map, convert s to an object.

*

This implementation simply returns s unchanged.

Overrides:
_literalToObject in class InterpolatingConverter
Throws:
java.text.ParseException
java.util.MissingResourceException

_addUpdaterListeners

protected void _addUpdaterListeners(KeyLookupRecord keyLookupRecord,
                                    java.lang.Object composite,
                                    INoReturnMap argMap)
Add listeners to the observable argument map, so that the composite's properties will be updated on changes to the argument map.


_createUpdaterListener

protected java.beans.PropertyChangeListener _createUpdaterListener(java.lang.Object composite,
                                                                   java.lang.String propertyName,
                                                                   IObjectMapper fromMapValueConverter)

Create a property change listener to add to the observable argument map, so that the composite is updated when a value in the map changes. Return null if not listener should be added.

This default implementation looks up the set property action associated with propertyName. If the action is not found, this implementation returns null. Otherwise, it returns a new instance of CompositeUpdater


_addMapConsistencyListeners

protected void _addMapConsistencyListeners(KeyLookupRecord keyLookupRecord,
                                           java.lang.Object composite,
                                           INoReturnMap argMap)
If composite is a bean and supports bound properties, add a property change listener to the bean that updates the observable map when the bean's property is changed.


_addMapConsistencyListener

protected void _addMapConsistencyListener(java.lang.Object composite,
                                          java.lang.String propertyName,
                                          IObjectMapper toMapValueConverter,
                                          INoReturnMap argMap,
                                          java.lang.Object mapKey,
                                          java.lang.reflect.Method addListenerMethod)

Add a listener to composite that will update the value associated with mapKey in observableMap when the propertyName property of the composite changes. When the property changes, toMapConverter, if non-null, should be used to convert the property value to the value actually put in the map.

This method should not throw any exceptions.

By default, this implementation sees if the addPropertyChangeListener() method was found (if it is addListenerMethod is non-null. If it is, it adds an instance of DefaultMapConsistencyListener to the list of listeners for the propertyName property of the composite.

Parameters:
composite - The composite object to add a listener to.
propertyName - The name of property of the composite, which when changed, should cause the listener to update the argument map.
toMapValueConverter - If non-null, the strategy to used to convert the property value of the composite to the value put in the argument map.
argMap - The argument map.
mapKey - The argument map key to keep consistent.
addListenerMethod - If non-null, a method of the composite that can be used to add a property change listener to it. It has the signature void addPropertyChangeListener(String propertyName, PropertyChangeListener). This parameter only needs to be referenced by this default implementation of the method.

_createComposite

protected java.lang.Object _createComposite(java.util.Map propertyMap,
                                            java.util.ResourceBundle bundle,
                                            INoReturnMap argMap)

Given the property key / value map, return a composite object ready to have its properties set (if legal). This method may completely configure the composite, or it may defer setting some properties to _setProperties(). However, properties set here instead of in _setProperties() cannot be updated.

This base implementation throws an UnsupportedOperationException. This is not abstract so only _literalToObject() needs to be implemented to make a subclass a concrete class that can create an object via the "instance" property and configure the object afterwards.


_setProperties

protected void _setProperties(java.lang.Object composite,
                              java.util.Map propertyMap)
Given the partially created object and a map of property names to property values, configure the object to reflect all of the properties. Return the fully configured object. Only properties set here can be updated after the composite has been created. If an error occurs executing one of the set property actions, catch it and warn the user, but don't rethrow the exception.


_makeInitConverter

protected InterpolatingConverter _makeInitConverter(java.lang.Object composite)
Create a converter used for the preInit and postInit special properties. This implementation returns an instance converter with "me" set to the composite in the BeanShell environment.


getCreationPropertyNames

public java.util.Collection getCreationPropertyNames()

Return a collection of names of properties of the composite needed at construction time. These are appended after the base key name and a '.' character to create keys to lookup in a resource bundle when converting from resource bundle to composites.

This base implementation returns a singleton list with "instance" in it.


getPropertyNames

public abstract java.util.Collection getPropertyNames()
Return a collection of names of properties of the composite being created. These properties should be configurable after the composite is actually constructed. These are appended after the base key name and a '.' character to create keys to lookup in a resource bundle when converting from resource bundle to composites.


getConverterForProperty

public abstract IInterpolatingConverter getConverterForProperty(java.lang.String propertyName,
                                                                java.lang.Object composite)
Return an instance of IInterpolatingConverter for the argument property name. If no converter pair is associated with the property name, return null.


getConverterNameForProperty

public java.lang.String getConverterNameForProperty(java.lang.String propertyName)

Return a string that indicates the type of converter used for the argument property. This method is meant to be called by development tools.

This default implementation checks if property name is one of "instance", "preInit", or "postInit". If so, it returns "Instance" since the instance converter is used to convert these implied properties. Otherwise, it calls getConverterForProperty(propertyName, null). If a NullPointerException is thrown, the string "" is returned. Otherwise, the result of invoking the converter's name() method is returned.


isPropertyReadable

public boolean isPropertyReadable(java.lang.String propertyName)

Return true if the property is readable by this converter. If true, the value of the corresponding key in the argument map is used to set the property of the composite when it is created.

This method is meant to be called by development tools.

This default implementation returns true unless propertyName is null, in which case a NullPointerException is thrown.

Parameters:
propertyName - The property name to test.
Returns:
true iff the property is updatable.
Throws:
java.lang.NullPointerException - if propertyName is null.

isPropertyUpdatable

public boolean isPropertyUpdatable(java.lang.String propertyName)

Return true if the property is updatable by this converter. If true and the argument map is observable, a map updater listener is installed in the argument map which updates the property in the created composite when the corresponding key in the argument map is mapped to a value.

This method is meant to be called by development tools.

This default implementation returns true unless propertyName is null, in which case a NullPointerException is thrown.

Parameters:
propertyName - The property name to test.
Returns:
true iff the property is updatable.
Throws:
java.lang.NullPointerException - if propertyName is null.

isPropertyWritable

public boolean isPropertyWritable(java.lang.String propertyName)

Return true if the property is writable by this converter. If true and the argument map is not null, a map consistency listener is installed in the created composite which updates the value mapped to the corresponding key in the argument map when the property value of the composite changes.

This method is meant to be called by development tools.

This default implementation returns true unless propertyName is null, in which case a NullPointerException is thrown.

Parameters:
propertyName - The property name to test.
Returns:
true iff the property is updatable.
Throws:
java.lang.NullPointerException - if propertyName is null.

_getActionForProperty

protected abstract CompositeConverter.ISetPropertyAction _getActionForProperty(java.lang.String propertyName)
Return an instance ISetPropertyAction for the argument property name. If no action is associated with the property name, return null.