com.mortbay.Util
Class ContainerIteratorTransformer
java.lang.Object
|
+--com.mortbay.Util.ConverterBase
|
+--com.mortbay.Util.ContainerIteratorTransformer
- public class ContainerIteratorTransformer
- extends ConverterBase
Class to transform leaves in trees of containers
Objects of this class are not Thread-safe.
This class is a Transformer that handles Transformation of the leaves
of Container object types (specifically, Vectors and Dictionaries) - it
iterates over the containers and recursively tries to transform the leaf
elements. Any leaf elements that are transformed are replaced in place in
the container.
Array elements can also be transformed - see the note below.
The user can install this Transformer in a ConverterSet and add
Transformers to handle the types they would like transformed to the same
set.
Arrays are set types in java and thus not suitable for conversion or
transformation unless being handled as Objects. In this case it is better,
however, to use Vectors instead - they are more generic and dynamically
sized. If you need to transform or convert objects in an array to a
different type, use the constructor for handling arrays, but make sure
your transformers will convert only to types your Array can handle. The
base type of the Array will be passed to the Transformer as the convertTo
parameter when transforming array elements.
Usage
ConverterSet cs = new ConverterSet();
cs.setTransformMode(true);
cs.register(new XXXTransformer());
cs.register(new ContainerIteratorTransformer());
cs.convert(hashtable, cs.getClass(), cs);
Note
that it is required for the user to setTransformMode on
the ConverterSet which, by default, operates in Converter mode.
- Version:
- 1.0 Fri Jun 9 2000
- Author:
- Matthew Watson (mattw)
- See Also:
ConverterSet
Method Summary |
protected java.lang.Object |
doConvert(java.lang.Object toConvert,
java.lang.Class convertTo,
Converter context,
boolean safe)
Convert an Object to another type. |
java.lang.Object |
getBaseObject()
Return the root object being transformed by this Transformer. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
ContainerIteratorTransformer
public ContainerIteratorTransformer()
ContainerIteratorTransformer
public ContainerIteratorTransformer(boolean arrays)
- Constructor for handling array element transformation
- Parameters:
arrays
- Set to true for array element transformation
getBaseObject
public java.lang.Object getBaseObject()
- Return the root object being transformed by this Transformer. This
will be the object passed into the outermost invokation of convert().
- Returns:
- The root object being transformed by this Transformer.
doConvert
protected java.lang.Object doConvert(java.lang.Object toConvert,
java.lang.Class convertTo,
Converter context,
boolean safe)
- Description copied from class: ConverterBase
- Convert an Object to another type.
- Overrides:
- doConvert in class ConverterBase
- Tags copied from class: ConverterBase
- Parameters:
toConvert
- Value to convertconvertTo
- Type to convert tocontext
- The context within which the converter was called.
If Converters use other Converters, this is passed as
the outermost Converter so that recursive calls have
access to all available Converters. Converter
implementations should pass this if passed null.safe
- If false, errors should be returned.- Returns:
- null if this converter doesn't handle this type to convertTo,
or a ConvertFail exception if there was an error and safe is false.