com.taco.text
Class DispatchingConverter

java.lang.Object
  extended by com.taco.text.AbstractInterpolatingStringToObjectConverter
      extended by com.taco.text.InterpolatingConverter
          extended by com.taco.text.DispatchingConverter
All Implemented Interfaces:
IInterpolatingConverter, IInterpolatingStringToObjectConverter, IStringToObjectConverter, IInterpolatingResourceBundleToObjectConverter, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DispatchingBorderConverter, DispatchingComponentConverter, DispatchingLayoutConverter

public class DispatchingConverter
extends InterpolatingConverter
implements java.lang.Cloneable, java.io.Serializable

A string and resource bundle to object converter that uses the first word of a string or the key appended with ".dispatchType" in the resource bundle to dispatch to another converter.

See Also:
Serialized Form

Field Summary
protected  java.util.Map _suffixToTypeMap
          A map between resource bundle key suffixes (lower-case String)and dispatch types (String) that are guesses for the dispatch type corresponding to resource bundle keys ending with a suffix.
protected  java.util.Map _typeToConfigurerMap
          A map between dispatch types (String) and instances of CompositeConverter that handle the corresponding types.
protected  java.util.Map _typeToConverterMap
          A map between dispatch types (String) and instances of IInterpolatingConverter that handle the corresponding types.
 
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
DispatchingConverter()
           
DispatchingConverter(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  java.lang.String _getTypeForSuffix(java.lang.String suffix)
          Return the dispatch type for the argument suffix, which should be in lower-case.
protected  java.lang.String _guessType(java.lang.String baseName)
          The ".dispatchType" subkey was not found for the argument resource bundle key.
protected  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  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.
 java.lang.Object clone()
           
 void configureComposite(java.lang.String id, java.lang.Object composite, java.lang.String baseKey, java.util.ResourceBundle bundle, INoReturnMap argMap)
          If there is a composite data converter installed for the argument type of object, use it to configure the composite.
 CompositeConverter getConfigurerForType(java.lang.String type)
          Return the composite configurer associated with the argument type.
 IInterpolatingConverter getConverterForType(java.lang.String type)
          Return the converter associated with the argument type.
 void installConfigurer(java.lang.String id, CompositeConverter configurer)
          Install a composite converter that uses a resource bundle to configure a composite object.
 void installConverter(java.lang.String id, IInterpolatingConverter converter)
          Install a converter from a string that begins with the argument string, or a from a resource bundle.
 void installTypeForSuffix(java.lang.String suffix, java.lang.String type)
          Install a type for resource bundle keys ending with the argument suffix.
 java.lang.String name()
          Use this instance's simple class name to derive a name for this converter.
 
Methods inherited from class com.taco.text.InterpolatingConverter
_argMapReferenceToObject, _getStandardImports, _getStandardStaticImports, _literalResultToObject, _scriptSnippetToObject, _toObjectMapper, 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

_typeToConverterMap

protected java.util.Map _typeToConverterMap
A map between dispatch types (String) and instances of IInterpolatingConverter that handle the corresponding types.


_typeToConfigurerMap

protected java.util.Map _typeToConfigurerMap
A map between dispatch types (String) and instances of CompositeConverter that handle the corresponding types.


_suffixToTypeMap

protected java.util.Map _suffixToTypeMap
A map between resource bundle key suffixes (lower-case String)and dispatch types (String) that are guesses for the dispatch type corresponding to resource bundle keys ending with a suffix.

Constructor Detail

DispatchingConverter

public DispatchingConverter()

DispatchingConverter

public DispatchingConverter(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

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class InterpolatingConverter
Throws:
java.lang.CloneNotSupportedException

installConverter

public void installConverter(java.lang.String id,
                             IInterpolatingConverter converter)

Install a converter from a string that begins with the argument string, or a from a resource bundle. If converter is null, uninstall the converter for the ID.

This implementation associates id with converter in _typeToConverterMap.


installConfigurer

public void installConfigurer(java.lang.String id,
                              CompositeConverter configurer)

Install a composite converter that uses a resource bundle to configure a composite object. If converter is null, uninstall the configurer for the ID.

This implementation associates id with converter in _typeToConfigurerMap.


configureComposite

public void configureComposite(java.lang.String id,
                               java.lang.Object composite,
                               java.lang.String baseKey,
                               java.util.ResourceBundle bundle,
                               INoReturnMap argMap)
If there is a composite data converter installed for the argument type of object, use it to configure the composite. Otherwise, throw an UnsupportedOperationException.


getConverterForType

public IInterpolatingConverter getConverterForType(java.lang.String type)

Return the converter associated with the argument type. If no converter is associated with the argument type, return null.

This default implementation simply returns the result of looking up type in _typeToConverterMap.


getConfigurerForType

public CompositeConverter getConfigurerForType(java.lang.String type)

Return the composite configurer associated with the argument type. If no configurer is associated with the argument type, return null.

This default implementation simply returns the result of looking up type in _typeToConfigurerMap.


installTypeForSuffix

public void installTypeForSuffix(java.lang.String suffix,
                                 java.lang.String type)
Install a type for resource bundle keys ending with the argument suffix. If the dispatch type associated with a resource bundle key is not present, the bundle key will be examined. Bundle keys ending with one of the installed suffixes will automatically be dispatched to a converter for the corresponding installed type. The suffix may be mixed-case; this method will convert it to lower-case. Any existing mapping from the same suffix to a type will be silently overwritten. If null is used for the type, no type will be guessed for the argument suffix.


name

public java.lang.String name()
Use this instance's simple class name to derive a name for this converter. If the converter's class name starts with "Dispatching", discard it. Also discard the trailing "Converter" suffix if present.

Specified by:
name in interface IInterpolatingConverter
Overrides:
name in class InterpolatingConverter

_literalToObject

protected 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

_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

_guessType

protected java.lang.String _guessType(java.lang.String baseName)

The ".dispatchType" subkey was not found for the argument resource bundle key. Using the name, guess the appropriate type. If no good guess can be determined, return null.

This default implementation sees if the base name ends with (case insensitively) one of the suffixes in the suffix to type map, which is modified by _installTypeForSuffix(). If it does, it returns the first type encountered.


_getTypeForSuffix

protected java.lang.String _getTypeForSuffix(java.lang.String suffix)
Return the dispatch type for the argument suffix, which should be in lower-case.