|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.morph.transform.transformers.BaseTransformer
net.sf.morph.transform.transformers.BaseCompositeTransformer
net.sf.morph.transform.transformers.SimpleDelegatingTransformer
public class SimpleDelegatingTransformer
Delegates transformations to a list of transformers. The transformers are
tried in the order in which they appear in the components
property of this transformer.
By default this transformer is initialized with a set of transformers that will meet basic needs. This list of transformers is subject to change in future versions of Morph, but we do not anticipate removing transformers, only adding new ones or modifying existing ones. This means if a transformation works in an older version of Morph it will also work in a newer version. A transformation's behavior may in some cases change between releases, but we will avoid this whenever possible.
The default set of transformers includes both converters and copiers. For calls to copy methods, only the copiers will be used. For calls to convert methods, the converters and the copiers will be used, since all Copiers provided by the Morph framework are also Converters.
Any delegates which implement
NodeCopier will automatically have this
transformer marked as the parent transformer. This is important for
performing deep copies of object graphs. Note that it is safe for a SimpleDelegatingTransformer
to implement the NodeCopier interface only if all its components do so.
| Field Summary |
|---|
| Fields inherited from class net.sf.morph.transform.transformers.BaseCompositeTransformer |
|---|
components |
| Fields inherited from class net.sf.morph.transform.transformers.BaseTransformer |
|---|
destinationClasses, log, sourceClasses |
| Fields inherited from interface net.sf.morph.transform.Transformer |
|---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
| Fields inherited from interface net.sf.morph.transform.Transformer |
|---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
| Fields inherited from interface net.sf.morph.transform.Transformer |
|---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
| Fields inherited from interface net.sf.morph.transform.Transformer |
|---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
| Fields inherited from interface net.sf.morph.transform.Transformer |
|---|
TRANSFORMATION_TYPE_CONVERT, TRANSFORMATION_TYPE_COPY |
| Constructor Summary | |
|---|---|
SimpleDelegatingTransformer()
Construct a new SimpleDelegatingTransformer. |
|
SimpleDelegatingTransformer(Transformer[] components)
Construct a new SimpleDelegatingTransformer. |
|
SimpleDelegatingTransformer(Transformer[] components,
boolean appendDefaultComponents)
Construct a new SimpleDelegatingTransformer. |
|
| Method Summary | |
|---|---|
protected void |
clearVisitedSourceToDestinationMapIfNecessary()
If we have popped everybody off the stack, clear the cache. |
java.lang.Object |
clone()
|
protected java.lang.Object |
convertImpl(java.lang.Class destinationType,
java.lang.Object source,
java.util.Locale locale)
The implementation of the convert method, which may omit
the invalid argument checks already performed by this base class. |
protected void |
copyImpl(java.lang.Object destination,
java.lang.Object source,
java.util.Locale locale,
java.lang.Integer preferredTransformationType)
Implementation of the copy method. |
protected Transformer[] |
createDefaultComponents()
Create the default set of Transformer components. |
protected java.lang.Object |
createReusableSource(java.lang.Class destinationClass,
java.lang.Object source)
NodeCopier.createReusableSource(Class, Object) |
protected void |
decrementStackDepth()
Decrement the depth of the nested copy stack. |
protected java.lang.Object |
getCachedResult(java.lang.Object source,
java.lang.Class destinationType)
Get the cached object in the process of being transformed |
java.lang.Object[] |
getComponents()
|
protected Copier |
getCopier(java.lang.Class destinationClass,
java.lang.Class sourceClass)
Finds a Copier that is capable of transforming sourceClass
to destinationClass. |
protected java.lang.Class[] |
getDestinationClassesImpl()
Transformer.getDestinationClasses() implementation template method. |
protected java.lang.Class[] |
getSourceClassesImpl()
Transformer.getSourceClasses() implementation template method. |
net.sf.composite.specialize.Specializer |
getSpecializer()
Get the Specializer for this SDT. |
protected Transformer |
getTransformer(java.lang.Class destinationClass,
java.lang.Class sourceClass)
Finds a Transformer that is capable of transforming sourceClass to destinationClass. |
protected Transformer |
getTransformer(java.util.Map registry,
java.lang.Class transformerType,
java.lang.Class destinationClass,
java.lang.Class sourceClass)
Finds a transformer of type transformerType that is
capable of transforming sourceClass to
destinationClass. |
Transformer[] |
getTransformers()
Get our components as a typesafe Transformer array. |
protected java.util.Map |
getVisitedSourceToDestinationMap()
Gets a Map of all the nodes in the object graph that have been transformed so far by this transformer. |
protected boolean |
hasVisited(java.lang.Object source,
java.lang.Class destinationType)
Avoid recursion by checking whether we have already begun a conversion of the specified source object to the specified destination class. |
protected boolean |
hasVisitedDestination(java.lang.Object source,
java.lang.Object destination)
Avoid recursion by checking whether we have already begun a copy of the specified source object to the specified destination object. |
protected void |
incrementStackDepth()
Increment the depth of the nested copy stack. |
protected void |
initializeImpl()
Gives subclasses a chance to perform any computations needed to initialize the transformer. |
protected boolean |
isAutomaticallyHandlingNulls()
Indicates whether null values will automatically be
converted to null by this base class before even calling
the subclass's BaseTransformer.convertImpl(Class, Object, Locale) method. |
protected boolean |
isImpreciseTransformationImpl(java.lang.Class destinationClass,
java.lang.Class sourceClass)
Implementation of isImpreciseTransformation |
protected boolean |
isPerformingLogging()
Let the delegate do the logging |
boolean |
isPreferPreciseTransformers()
Get the preferPreciseTransformers. |
boolean |
isSpecializable(java.lang.Class type)
|
protected boolean |
isTransformableImpl(java.lang.Class destinationType,
java.lang.Class sourceType)
Determines if one of the delegate transformers is capable of performing the given transformation. |
protected void |
recordVisit(java.lang.Object source,
java.lang.Class destinationType,
java.lang.Object destination)
Cache destination object for this source/destination class combination. |
void |
setComponents(java.lang.Object[] components)
|
void |
setPreferPreciseTransformers(boolean preferPreciseTransformers)
Set the preferPreciseTransformers. |
void |
setSpecializer(net.sf.composite.specialize.Specializer specializer)
Set the Specializer for this SDT. |
java.lang.Object |
specialize(java.lang.Class compositeType)
|
| Methods inherited from class net.sf.morph.transform.transformers.BaseCompositeTransformer |
|---|
getComponentType, getComponentValidator, isNarrowingComponentArray, isWrappingRuntimeExceptions, setComponentValidator, setNestedTransformer, updateNestedTransformerComponents |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface net.sf.morph.transform.ExplicitTransformer |
|---|
isTransformable |
| Methods inherited from interface net.sf.morph.transform.Transformer |
|---|
getDestinationClasses, getSourceClasses |
| Methods inherited from interface net.sf.morph.transform.DecoratedCopier |
|---|
copy |
| Methods inherited from interface net.sf.morph.transform.Copier |
|---|
copy |
| Methods inherited from interface net.sf.morph.transform.Transformer |
|---|
getDestinationClasses, getSourceClasses |
| Methods inherited from interface net.sf.morph.transform.Transformer |
|---|
getDestinationClasses, getSourceClasses |
| Methods inherited from interface net.sf.morph.transform.ExplicitTransformer |
|---|
isTransformable |
| Methods inherited from interface net.sf.morph.transform.DecoratedConverter |
|---|
convert, equals, equals |
| Methods inherited from interface net.sf.morph.transform.Converter |
|---|
convert |
| Methods inherited from interface net.sf.morph.transform.Transformer |
|---|
getDestinationClasses, getSourceClasses |
| Methods inherited from interface net.sf.morph.transform.Transformer |
|---|
getDestinationClasses, getSourceClasses |
| Methods inherited from interface net.sf.morph.transform.ExplicitTransformer |
|---|
isTransformable |
| Methods inherited from interface net.sf.morph.transform.ImpreciseTransformer |
|---|
isImpreciseTransformation |
| Constructor Detail |
|---|
public SimpleDelegatingTransformer()
public SimpleDelegatingTransformer(Transformer[] components)
components -
public SimpleDelegatingTransformer(Transformer[] components,
boolean appendDefaultComponents)
components - appendDefaultComponents - | Method Detail |
|---|
protected Transformer[] createDefaultComponents()
protected void initializeImpl()
throws java.lang.Exception
initializeImpl in class BaseCompositeTransformerjava.lang.ExceptionBaseCompositeTransformer.initializeImpl()
protected boolean isTransformableImpl(java.lang.Class destinationType,
java.lang.Class sourceType)
throws java.lang.Exception
isTransformableImpl in class BaseTransformerdestinationType - the destination type to testsourceType - the source type to test
TransformationException - if it could not be determined if sourceType is
transformable into destinationType
java.lang.Exception
protected boolean isImpreciseTransformationImpl(java.lang.Class destinationClass,
java.lang.Class sourceClass)
isImpreciseTransformationImpl in class BaseTransformer
protected java.lang.Class[] getSourceClassesImpl()
throws java.lang.Exception
Transformer.getSourceClasses() implementation template method.
getSourceClassesImpl in class BaseTransformerjava.lang.ExceptionBaseTransformer.getSourceClassesImpl()
protected java.lang.Class[] getDestinationClassesImpl()
throws java.lang.Exception
Transformer.getDestinationClasses() implementation template method.
getDestinationClassesImpl in class BaseTransformerjava.lang.ExceptionBaseTransformer.getDestinationClassesImpl()
protected void copyImpl(java.lang.Object destination,
java.lang.Object source,
java.util.Locale locale,
java.lang.Integer preferredTransformationType)
throws java.lang.Exception
copyImpl in class BaseTransformerjava.lang.ExceptionBaseTransformer.copyImpl(java.lang.Object, java.lang.Object, java.util.Locale, java.lang.Integer)
protected java.lang.Object convertImpl(java.lang.Class destinationType,
java.lang.Object source,
java.util.Locale locale)
throws java.lang.Exception
convert method, which may omit
the invalid argument checks already performed by this base class. By
default, this method creates a new instance of the destinationClass and
copies information from the source to the destination. This
implementation should be fine as-is for Copiers, but Converters will need
to implement this method since they will not be implementing the copy
method.
convertImpl in class BaseTransformerlocale - the locale in which the conversion should take place. for
converters that are not locale-aware, the local argument can
simply be ignored
java.lang.ExceptionBaseTransformer.convertImpl(java.lang.Class, java.lang.Object, java.util.Locale)protected void incrementStackDepth()
protected void decrementStackDepth()
protected void clearVisitedSourceToDestinationMapIfNecessary()
protected void recordVisit(java.lang.Object source,
java.lang.Class destinationType,
java.lang.Object destination)
source - destinationType - destination -
protected boolean hasVisited(java.lang.Object source,
java.lang.Class destinationType)
source - destinationType -
protected boolean hasVisitedDestination(java.lang.Object source,
java.lang.Object destination)
source - destination -
protected java.lang.Object getCachedResult(java.lang.Object source,
java.lang.Class destinationType)
source - destinationType -
public java.lang.Object specialize(java.lang.Class compositeType)
specialize in interface net.sf.composite.SpecializableCompositeSpecializableComposite.specialize(java.lang.Class)
public boolean isSpecializable(java.lang.Class type)
throws net.sf.composite.CompositeException
isSpecializable in interface net.sf.composite.SpecializableCompositenet.sf.composite.CompositeExceptionSpecializableComposite.isSpecializable(java.lang.Class)
protected Transformer getTransformer(java.util.Map registry,
java.lang.Class transformerType,
java.lang.Class destinationClass,
java.lang.Class sourceClass)
transformerType that is
capable of transforming sourceClass to
destinationClass. Caches results in the
registry.
registry - a cache that remembers which transformers can be used for
which transformationstransformerType - the type of the returned transformerdestinationClass - the destinationClass of the transformationsourceClass - the sourceClass of the transformation
TransformationException - if no suitable transformer could be found
protected Copier getCopier(java.lang.Class destinationClass,
java.lang.Class sourceClass)
sourceClass
to destinationClass.
destinationClass - the destinationClass of the transformationsourceClass - the sourceClass of the transformation
TransformationException - if no suitable copier could be found
protected Transformer getTransformer(java.lang.Class destinationClass,
java.lang.Class sourceClass)
sourceClass to destinationClass.
destinationClass - the destinationClass of the transformationsourceClass - the sourceClass of the transformation
TransformationException - if no suitable transformer could be foundpublic Transformer[] getTransformers()
public java.lang.Object[] getComponents()
BaseCompositeTransformer
getComponents in interface net.sf.composite.SimpleCompositegetComponents in class BaseCompositeTransformerSimpleComposite.getComponents()public void setComponents(java.lang.Object[] components)
BaseCompositeTransformer
setComponents in interface net.sf.composite.SimpleCompositesetComponents in class BaseCompositeTransformerSimpleComposite.setComponents(java.lang.Object[])protected boolean isPerformingLogging()
isPerformingLogging in class BaseTransformerprotected boolean isAutomaticallyHandlingNulls()
null values will automatically be
converted to null by this base class before even calling
the subclass's BaseTransformer.convertImpl(Class, Object, Locale) method.
Subclasses which depend on this behavior (which is all subclasses, by
default) should include null as one of their source and
destination classes so that the actual behavior of the transformer is
consistent with the values that are returned by the
BaseTransformer.isTransformable(Class, Class) method. The conversions will
happen automatically even if the source and destination classes don't
contain null, but for the sake of consistency the
nulls should be included.
isAutomaticallyHandlingNulls in class BaseTransformernull values will automatically be
converted to null by this base class before even
calling the subclass's
BaseTransformer.convertImpl(Class, Object, Locale) methodBaseTransformer.isAutomaticallyHandlingNulls()
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class BaseTransformerjava.lang.CloneNotSupportedExceptionBaseTransformer.clone()protected java.util.Map getVisitedSourceToDestinationMap()
public net.sf.composite.specialize.Specializer getSpecializer()
public void setSpecializer(net.sf.composite.specialize.Specializer specializer)
specializer -
protected java.lang.Object createReusableSource(java.lang.Class destinationClass,
java.lang.Object source)
NodeCopier.createReusableSource(Class, Object)
createReusableSource in class BaseTransformerBaseTransformer.createReusableSource(java.lang.Class, java.lang.Object)public boolean isPreferPreciseTransformers()
public void setPreferPreciseTransformers(boolean preferPreciseTransformers)
preferPreciseTransformers - the boolean to set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||