net.sf.morph.transform.copiers
Class BasePropertyNameCopier

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
All Implemented Interfaces:
net.sf.composite.Component, Converter, Copier, DecoratedConverter, DecoratedCopier, DecoratedTransformer, ExplicitTransformer, NodeCopier, Transformer
Direct Known Subclasses:
PropertyNameMappingCopier, PropertyNameMatchingCopier

public abstract class BasePropertyNameCopier
extends BaseReflectorTransformer
implements DecoratedCopier, DecoratedConverter, NodeCopier

Base class for copiers that copy information from one bean to another based on the property names in the source and destination objects.

Since:
Feb 5, 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
BasePropertyNameCopier()
          Create a new BasePropertyNameCopier.
BasePropertyNameCopier(boolean errorOnMissingProperty)
          Create a new BasePropertyNameCopier.
 
Method Summary
protected  Transformer chooseTransformer(java.lang.String sourceProperty, java.lang.Object source, java.lang.String destinationProperty, java.lang.Object destination, java.util.Locale locale, java.lang.Integer preferredTransformationType)
          Choose the appropriate property transformer.
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)
          Perform the specified property copy.
 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.
 Transformer getNestedTransformer()
          NodeCopier.getNestedTransformer()
protected  java.lang.Integer getPreferredTransformationType(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object sourceValue, java.lang.Object destination, java.lang.String destinationProperty, java.lang.Object destinationValue, java.util.Locale locale, java.lang.Integer preferredTransformationType)
          Extension point for subclasses to override preferredTransformationType.
 java.util.Map getPropertyTransformers()
          Get the Map of Transformers to use instead of nestedTransformer.
protected  java.lang.Class[] getSourceClassesImpl()
          Transformer.getSourceClasses() implementation template method.
 boolean isErrorOnMissingProperty()
          Return true if errors should should be thrown when a property is missing.
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 setErrorOnMissingProperty(boolean isStrict)
          Set the value of the errorOnMissingProperty flag.
 void setNestedTransformer(Transformer transformer)
          NodeCopier.setNestedTransformer(Transformer)
 void setPropertyTransformers(java.util.Map propertyTransformers)
          Set the Map of Transformers to use instead of nestedTransformer.
 void setSourceClasses(java.lang.Class[] sourceClasses)
          Configures the sourceClasses property of this transformer.
 
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, copyImpl, createDefaultReflector, createNewInstance, createNewInstanceImpl, equals, equals, equalsUnidirectionalTest, getDestinationClasses, getInstantiatingReflector, getLocale, getLog, getReflector, getReflector, getSourceClasses, getTransformableCallCache, getTransformerName, initialize, initializeImpl, 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

BasePropertyNameCopier

public BasePropertyNameCopier()
Create a new BasePropertyNameCopier.


BasePropertyNameCopier

public BasePropertyNameCopier(boolean errorOnMissingProperty)
Create a new BasePropertyNameCopier.

Parameters:
errorOnMissingProperty -
Method Detail

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

isErrorOnMissingProperty

public boolean isErrorOnMissingProperty()
Return true if errors should should be thrown when a property is missing.

Returns:
true if errors should be thrown when a property is missing or
false, otherwise.

setErrorOnMissingProperty

public void setErrorOnMissingProperty(boolean isStrict)
Set the value of the errorOnMissingProperty flag.

Parameters:
errorOnMissingProperty - The value of errorOnMissingProperty to set.

chooseTransformer

protected Transformer chooseTransformer(java.lang.String sourceProperty,
                                        java.lang.Object source,
                                        java.lang.String destinationProperty,
                                        java.lang.Object destination,
                                        java.util.Locale locale,
                                        java.lang.Integer preferredTransformationType)
Choose the appropriate property transformer.

Parameters:
sourceProperty -
source -
destinationProperty -
destination -
locale -
preferredTransformationType -
Returns:

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)
Perform the specified property copy.

Parameters:
sourceProperty -
source -
destinationProperty -
destination -
locale -
preferredTransformationType -

getPreferredTransformationType

protected java.lang.Integer getPreferredTransformationType(java.lang.Object source,
                                                           java.lang.String sourceProperty,
                                                           java.lang.Object sourceValue,
                                                           java.lang.Object destination,
                                                           java.lang.String destinationProperty,
                                                           java.lang.Object destinationValue,
                                                           java.util.Locale locale,
                                                           java.lang.Integer preferredTransformationType)
Extension point for subclasses to override preferredTransformationType.

Parameters:
source -
sourceProperty -
sourceValue -
destination -
destinationProperty -
destinationValue -
locale -
preferredTransformationType -
Returns:
Integer
See Also:
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

getNestedTransformer

public Transformer getNestedTransformer()
NodeCopier.getNestedTransformer()

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

setNestedTransformer

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

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

getPropertyTransformers

public java.util.Map getPropertyTransformers()
Get the Map of Transformers to use instead of nestedTransformer.

Returns:
Map

setPropertyTransformers

public void setPropertyTransformers(java.util.Map propertyTransformers)
Set the Map of Transformers to use instead of nestedTransformer.

Parameters:
propertyTransformers -

getSourceClassesImpl

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

Overrides:
getSourceClassesImpl in class BaseReflectorTransformer
Returns:
Class[]
Throws:
java.lang.Exception

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

getDestinationClassesImpl

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

Overrides:
getDestinationClassesImpl in class BaseReflectorTransformer
Returns:
Class[]
Throws:
java.lang.Exception

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


Copyright © 2004-2008.