net.sf.morph.transform.copiers
Class PropertyExpressionMappingCopier

java.lang.Object
  extended by net.sf.morph.transform.transformers.BaseTransformer
      extended by net.sf.morph.transform.copiers.PropertyExpressionMappingCopier
All Implemented Interfaces:
net.sf.composite.Component, Converter, Copier, DecoratedConverter, DecoratedCopier, DecoratedTransformer, ExplicitTransformer, NodeCopier, Transformer

public class PropertyExpressionMappingCopier
extends BaseTransformer
implements DecoratedConverter, DecoratedCopier, NodeCopier

Maps property expressions between objects using a Morph Language. The map you specify should have String keys, and in its simplest form, will have String values as well. However, the values in the mapping may be containers of Strings as well, allowing you to map > 1 destination for a given source property.

Since:
Morph 1.1
Author:
Matt Benson

Field Summary
 
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
PropertyExpressionMappingCopier()
          Create a new PropertyExpressionMappingCopier.
PropertyExpressionMappingCopier(java.util.Map mapping)
          Create a new PropertyExpressionMappingCopier.
 
Method Summary
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  void copyProperty(java.lang.String sourceProperty, java.lang.Object source, java.lang.String destinationProperty, java.lang.Object destination, java.util.Locale locale, java.lang.Integer preferredTransformationType)
          Copy source.sourceProperty to dest.destProperty.
 java.lang.Object createReusableSource(java.lang.Class destinationClass, java.lang.Object source)
          NodeCopier.createReusableSource(Class, Object)
protected  java.lang.Class[] getDestinationClassesImpl()
          Transformer.getDestinationClasses() implementation template method.
 Language getLanguage()
          Get the language of this PropertyExpressionMappingCopier.
 java.util.Map getMapping()
          Get the mapping of this PropertyExpressionMappingCopier.
 Transformer getNestedTransformer()
          NodeCopier.getNestedTransformer()
protected  java.lang.Class[] getSourceClassesImpl()
          Transformer.getSourceClasses() implementation template method.
protected  void initializeImpl()
          Gives subclasses a chance to perform any computations needed to initialize the transformer.
protected  boolean isWrappingRuntimeExceptions()
          Indicates whether runtime exceptions should be wrapped as TransformationExceptions.
 void setDestinationClasses(java.lang.Class[] destinationClasses)
          Configures the destinationClasses property of this transformer.
 void setLanguage(Language language)
          Set the language of this PropertyExpressionMappingCopier.
 void setMapping(java.util.Map mapping)
          Set the mapping of this PropertyExpressionMappingCopier.
 void setNestedTransformer(Transformer nestedTransformer)
          NodeCopier.setNestedTransformer(Transformer)
 void setSourceClasses(java.lang.Class[] sourceClasses)
          Configures the sourceClasses property of this transformer.
 
Methods inherited from class net.sf.morph.transform.transformers.BaseTransformer
clone, convert, convert, convertImpl, copy, copy, createDefaultReflector, createNewInstance, createNewInstanceImpl, equals, equals, equalsUnidirectionalTest, getDestinationClasses, getInstantiatingReflector, getLocale, getLog, getReflector, getReflector, getSourceClasses, getTransformableCallCache, getTransformerName, initialize, isAutomaticallyHandlingNulls, isCachingIsTransformableCalls, isImpreciseTransformation, isImpreciseTransformationImpl, isInitialized, isPerformingLogging, isTransformable, isTransformableImpl, setCachingIsTransformableCalls, setInitialized, setLog, setReflector, 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.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.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.NodeCopier
createNewInstance
 
Methods inherited from interface net.sf.morph.transform.Copier
copy
 
Methods inherited from interface net.sf.morph.transform.Transformer
getDestinationClasses, getSourceClasses
 

Constructor Detail

PropertyExpressionMappingCopier

public PropertyExpressionMappingCopier()
Create a new PropertyExpressionMappingCopier.


PropertyExpressionMappingCopier

public PropertyExpressionMappingCopier(java.util.Map mapping)
Create a new PropertyExpressionMappingCopier.

Parameters:
mapping - property mapping
Method Detail

getLanguage

public Language getLanguage()
Get the language of this PropertyExpressionMappingCopier.

Returns:
the language

setLanguage

public void setLanguage(Language language)
Set the language of this PropertyExpressionMappingCopier.

Parameters:
language - the language to set

initializeImpl

protected void initializeImpl()
                       throws java.lang.Exception
Gives subclasses a chance to perform any computations needed to initialize the transformer.

Overrides:
initializeImpl in class BaseTransformer
Throws:
java.lang.Exception

copyImpl

protected void copyImpl(java.lang.Object destination,
                        java.lang.Object source,
                        java.util.Locale locale,
                        java.lang.Integer preferredTransformationType)
                 throws java.lang.Exception
Implementation of the copy method. By default, this method throws UnsupportedOperationException.

Overrides:
copyImpl in class BaseTransformer
Throws:
java.lang.Exception

copyProperty

protected void copyProperty(java.lang.String sourceProperty,
                            java.lang.Object source,
                            java.lang.String destinationProperty,
                            java.lang.Object destination,
                            java.util.Locale locale,
                            java.lang.Integer preferredTransformationType)
                     throws java.lang.Exception
Copy source.sourceProperty to dest.destProperty.

Parameters:
sourceProperty -
source -
destinationProperty -
destination -
locale -
preferredTransformationType -
Throws:
java.lang.Exception

getDestinationClassesImpl

protected java.lang.Class[] getDestinationClassesImpl()
                                               throws java.lang.Exception
Transformer.getDestinationClasses() implementation template method.

Specified by:
getDestinationClassesImpl in class BaseTransformer
Returns:
Class[]
Throws:
java.lang.Exception

getSourceClassesImpl

protected java.lang.Class[] getSourceClassesImpl()
                                          throws java.lang.Exception
Transformer.getSourceClasses() implementation template method.

Specified by:
getSourceClassesImpl in class BaseTransformer
Returns:
Class[]
Throws:
java.lang.Exception

getMapping

public java.util.Map getMapping()
Get the mapping of this PropertyExpressionMappingCopier.

Returns:
the mapping

setMapping

public void setMapping(java.util.Map mapping)
Set the mapping of this PropertyExpressionMappingCopier.

Parameters:
mapping - the mapping to set

setSourceClasses

public void setSourceClasses(java.lang.Class[] sourceClasses)
Configures the sourceClasses property of this transformer. Note that this method should be called before the transformer is used. Otherwise, if another thread is in the middle of transforming an object graph and this method is called, the behavior of the transformer can change partway through the transformation.

Overrides:
setSourceClasses in class BaseTransformer
Parameters:
sourceClasses - the new sourceClasses for this transformer

setDestinationClasses

public void setDestinationClasses(java.lang.Class[] destinationClasses)
Configures the destinationClasses property of this transformer. Note that this method should be called before the transformer is used. Otherwise, if another thread is in the middle of transforming an object graph and this method is called, the behavior of the transformer can change partway through the transformation.

Overrides:
setDestinationClasses in class BaseTransformer
Parameters:
destinationClasses - the new destinationClasses for this transformer

createReusableSource

public java.lang.Object createReusableSource(java.lang.Class destinationClass,
                                             java.lang.Object source)
NodeCopier.createReusableSource(Class, Object)

Specified by:
createReusableSource in interface NodeCopier
Overrides:
createReusableSource in class BaseTransformer
Parameters:
destinationClass - the destination class to which this source object will be transformed
source - a source object that will undergo a transformation by this copier
Returns:
a reusable version of fthe source object

setNestedTransformer

public void setNestedTransformer(Transformer nestedTransformer)
NodeCopier.setNestedTransformer(Transformer)

Specified by:
setNestedTransformer in interface NodeCopier
Overrides:
setNestedTransformer in class BaseTransformer
Parameters:
nestedTransformer - the transformer used to perform nested transformations

getNestedTransformer

public Transformer getNestedTransformer()
NodeCopier.getNestedTransformer()

Specified by:
getNestedTransformer in interface NodeCopier
Overrides:
getNestedTransformer in class BaseTransformer
Returns:
Transformer

isWrappingRuntimeExceptions

protected boolean isWrappingRuntimeExceptions()
Indicates whether runtime exceptions should be wrapped as TransformationExceptions. By default, this method returns true.

Simple transformers in Morph that operate on JDK types like Numbers and Strings will usually set this value to true so that they throw TransformationExceptions if problems occur. More complex transformers that operate on graphs of objects are encouraged to set this value to false so that runtime exceptions are not wrapped. This way, problems accessing data will be expressed by the native API of a user's domain objects and avoid the need to catch Morph-specific exceptions (assuming the use of runtime exceptions in said domain objects).

Overrides:
isWrappingRuntimeExceptions in class BaseTransformer
Returns:
true
See Also:
BaseTransformer.isWrappingRuntimeExceptions()


Copyright © 2004-2008.