net.sf.morph.transform.transformers
Class TypeChangingGraphTransformer

java.lang.Object
  extended by net.sf.morph.transform.transformers.BaseTransformer
      extended by net.sf.morph.transform.transformers.BaseCompositeTransformer
          extended by net.sf.morph.transform.transformers.SimpleDelegatingTransformer
              extended by net.sf.morph.transform.transformers.TypeChangingGraphTransformer
All Implemented Interfaces:
java.lang.Cloneable, net.sf.composite.Component, net.sf.composite.Composite, net.sf.composite.SimpleComposite, net.sf.composite.SpecializableComposite, net.sf.composite.StrictlyTypedComposite, Converter, Copier, DecoratedConverter, DecoratedCopier, DecoratedTransformer, ExplicitTransformer, ImpreciseTransformer, Transformer

public class TypeChangingGraphTransformer
extends SimpleDelegatingTransformer

A transformer that performs a deep copy of the data in an object graph while also allowing the types in the destination graph to be different than the types in the source graph. A typical application of this transformer is to transform a domain model into a graph of transfer objects suitable for transferring to a remote client or another tier of an n-tier architecture.

Note: if you are using this transformer to transformer an object graph composed of CGLIB proxies (such as an object graph created by Hibernate), you may need to specify your source types as interfaces, because CGLIB proxies may not necessarily be instances of the expected class.

Since:
December 1, 2005
Author:
Matt Sgarlata

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
TypeChangingGraphTransformer()
          Construct a new TypeChangingGraphTransformer.
 
Method Summary
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  Reflector createReflector()
           
protected  ContainerCopier getContainerCopier()
           
protected  IdentityConverter getIdentityConverter()
           
protected  PropertyNameMatchingCopier getPropertyNameMatchingCopier()
           
 java.util.Map getSourceToDestinationTypeMapping()
           
protected  Transformer getTransformer(java.lang.Class transformerType)
           
protected  void initializeImpl()
          Gives subclasses a chance to perform any computations needed to initialize the transformer.
 void setSourceToDestinationTypeMapping(java.util.Map sourceToDestinationTypeMapping)
           
 
Methods inherited from class net.sf.morph.transform.transformers.SimpleDelegatingTransformer
clearVisitedSourceToDestinationMapIfNecessary, clone, copyImpl, createDefaultComponents, createReusableSource, decrementStackDepth, getCachedResult, getComponents, getCopier, getDestinationClassesImpl, getSourceClassesImpl, getSpecializer, getTransformer, getTransformer, getTransformers, getVisitedSourceToDestinationMap, hasVisited, hasVisitedDestination, incrementStackDepth, isAutomaticallyHandlingNulls, isImpreciseTransformationImpl, isPerformingLogging, isPreferPreciseTransformers, isSpecializable, isTransformableImpl, recordVisit, setComponents, setPreferPreciseTransformers, setSpecializer, specialize
 
Methods inherited from class net.sf.morph.transform.transformers.BaseCompositeTransformer
getComponentType, getComponentValidator, isNarrowingComponentArray, isWrappingRuntimeExceptions, setComponentValidator, setNestedTransformer, updateNestedTransformerComponents
 
Methods inherited from class net.sf.morph.transform.transformers.BaseTransformer
convert, convert, copy, copy, createDefaultReflector, createNewInstance, createNewInstanceImpl, equals, equals, equalsUnidirectionalTest, getDestinationClasses, getInstantiatingReflector, getLocale, getLog, getNestedTransformer, getReflector, getReflector, getSourceClasses, getTransformableCallCache, getTransformerName, initialize, isCachingIsTransformableCalls, isImpreciseTransformation, isInitialized, isTransformable, setCachingIsTransformableCalls, setDestinationClasses, setInitialized, setLog, setReflector, setSourceClasses, setTransformableCallCache, setTransformerName, toString
 
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

TypeChangingGraphTransformer

public TypeChangingGraphTransformer()
Construct a new TypeChangingGraphTransformer.

Method Detail

getTransformer

protected Transformer getTransformer(java.lang.Class transformerType)

getContainerCopier

protected ContainerCopier getContainerCopier()

getPropertyNameMatchingCopier

protected PropertyNameMatchingCopier getPropertyNameMatchingCopier()

getIdentityConverter

protected IdentityConverter getIdentityConverter()

createReflector

protected Reflector createReflector()

initializeImpl

protected void initializeImpl()
                       throws java.lang.Exception
Description copied from class: SimpleDelegatingTransformer
Gives subclasses a chance to perform any computations needed to initialize the transformer.

Overrides:
initializeImpl in class SimpleDelegatingTransformer
Throws:
java.lang.Exception
See Also:
BaseCompositeTransformer.initializeImpl()

convertImpl

protected java.lang.Object convertImpl(java.lang.Class destinationType,
                                       java.lang.Object source,
                                       java.util.Locale locale)
                                throws java.lang.Exception
Description copied from class: SimpleDelegatingTransformer
The implementation of the 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.

Overrides:
convertImpl in class SimpleDelegatingTransformer
locale - the locale in which the conversion should take place. for converters that are not locale-aware, the local argument can simply be ignored
Throws:
java.lang.Exception
See Also:
BaseTransformer.convertImpl(java.lang.Class, java.lang.Object, java.util.Locale)

getSourceToDestinationTypeMapping

public java.util.Map getSourceToDestinationTypeMapping()

setSourceToDestinationTypeMapping

public void setSourceToDestinationTypeMapping(java.util.Map sourceToDestinationTypeMapping)


Copyright © 2004-2008.