net.sf.morph.transform.copiers
Class PropertyNameMappingCopier

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

public class PropertyNameMappingCopier
extends BasePropertyNameCopier

Copies properties from the source to the destination based on a mapping of property names.

By default, property name mappings are considered bidirectional, so if you call addMapping("foo", "bar"), the copy method will copy the value of foo to bar and will also copy bar to foo. Mappings specified by the setMapping method are considered bidirectional as well. If this behavior is not desired, just set the bidirectional property to false.

If a property in the mapping cannot be copied, by default a TransformationException will be thrown. To turn off this behavior, set errorOnMissingProperty to false.

Since:
Jan 25, 2005
Author:
Matt Sgarlata, Alexander Volanis

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
PropertyNameMappingCopier()
          Create a new PropertyNameMappingCopier.
PropertyNameMappingCopier(boolean errorOnMissingProperty)
          Create a new PropertyNameMappingCopier.
 
Method Summary
 void addMapping(java.lang.String sourcePropertyName, java.lang.String destinationPropertyName)
          Add a single mapping.
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  java.util.Map getMapping()
          Get the property mapping.
protected  void initializeImpl()
          Gives subclasses a chance to perform any computations needed to initialize the transformer.
 boolean isBidirectional()
          Learn whether this copier is bidirectional.
 void setBidirectional(boolean bidirectional)
          Set whether this copier is bidirectional.
 void setMapping(java.util.Map mapping)
          Set the property mapping.
 
Methods inherited from class net.sf.morph.transform.copiers.BasePropertyNameCopier
chooseTransformer, copyProperty, createReusableSource, getDestinationClassesImpl, getNestedTransformer, getPreferredTransformationType, getPropertyTransformers, getSourceClassesImpl, isErrorOnMissingProperty, isWrappingRuntimeExceptions, setDestinationClasses, setErrorOnMissingProperty, setNestedTransformer, setPropertyTransformers, setSourceClasses
 
Methods inherited from class net.sf.morph.transform.transformers.BaseReflectorTransformer
getBeanReflector, getContainerReflector, getGrowableContainerReflector, getIndexedContainerReflector, getMutableIndexedContainerReflector, hasReflector
 
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.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.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

PropertyNameMappingCopier

public PropertyNameMappingCopier()
Create a new PropertyNameMappingCopier.


PropertyNameMappingCopier

public PropertyNameMappingCopier(boolean errorOnMissingProperty)
Create a new PropertyNameMappingCopier.

Parameters:
errorOnMissingProperty -
Method Detail

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 TransformationException
Implementation of the copy method. By default, this method throws UnsupportedOperationException.

Overrides:
copyImpl in class BaseTransformer
Throws:
TransformationException

getMapping

protected java.util.Map getMapping()
Get the property mapping.

Returns:
Map

setMapping

public void setMapping(java.util.Map mapping)
Set the property mapping.

Parameters:
mapping -

addMapping

public void addMapping(java.lang.String sourcePropertyName,
                       java.lang.String destinationPropertyName)
Add a single mapping.

Parameters:
sourcePropertyName -
destinationPropertyName -

isBidirectional

public boolean isBidirectional()
Learn whether this copier is bidirectional.

Returns:
boolean

setBidirectional

public void setBidirectional(boolean bidirectional)
Set whether this copier is bidirectional.

Parameters:
bidirectional -


Copyright © 2004-2008.