net.sf.morph.transform.copiers
Class CopierDecorator

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

public class CopierDecorator
extends BaseTransformer
implements DecoratedCopier, DecoratedConverter, ExplicitTransformer

Decorates any Copier so that it implements DecoratedCopier.

Since:
Dec 5, 2004
Author:
Matt Sgarlata

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
 
Constructor Summary
CopierDecorator()
          Create a new CopierDecorator.
CopierDecorator(Copier copier)
          Create a new CopierDecorator.
CopierDecorator(Copier copier, java.util.Locale defaultLocale)
          Create a new CopierDecorator.
 
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.
 java.util.Locale getDefaultLocale()
          Get the defaultLocale.
protected  java.lang.Class[] getDestinationClassesImpl()
          Transformer.getDestinationClasses() implementation template method.
protected  java.util.Locale getLocale()
          Retrieves the current Locale if none is specified in the method arguments for a converter or copier.
 Copier getNestedCopier()
           
protected  java.lang.Class[] getSourceClassesImpl()
          Transformer.getSourceClasses() implementation template method.
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 isTransformableImpl(java.lang.Class destinationType, java.lang.Class sourceType)
          Default implementation for Transformer#isTransformable(Class, Class) that assumes that each source type can be converted into each destination type.
protected  boolean isWrappingRuntimeExceptions()
          Indicates whether runtime exceptions should be wrapped as TransformationExceptions.
 void setDefaultLocale(java.util.Locale defaultLocale)
          Set the defaultLocale.
 void setDestinationClasses(java.lang.Class[] destinationClasses)
          Configures the destinationClasses property of this transformer.
 void setNestedCopier(Copier copier)
           
protected  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, createReusableSource, equals, equals, equalsUnidirectionalTest, getDestinationClasses, getInstantiatingReflector, getLog, getNestedTransformer, getReflector, getReflector, getSourceClasses, getTransformableCallCache, getTransformerName, initialize, initializeImpl, isCachingIsTransformableCalls, isImpreciseTransformation, isImpreciseTransformationImpl, isInitialized, isPerformingLogging, isTransformable, 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
 

Constructor Detail

CopierDecorator

public CopierDecorator()
Create a new CopierDecorator.


CopierDecorator

public CopierDecorator(Copier copier)
Create a new CopierDecorator.

Parameters:
copier -

CopierDecorator

public CopierDecorator(Copier copier,
                       java.util.Locale defaultLocale)
Create a new CopierDecorator.

Parameters:
copier -
defaultLocale -
Method Detail

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

getNestedCopier

public Copier getNestedCopier()
Returns:
Returns the nested copier.

setNestedCopier

public void setNestedCopier(Copier copier)
Parameters:
copier - The nested copier to set.

getDefaultLocale

public java.util.Locale getDefaultLocale()
Get the defaultLocale.

Returns:
Locale

setDefaultLocale

public void setDefaultLocale(java.util.Locale defaultLocale)
Set the defaultLocale.

Parameters:
defaultLocale - the Locale 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
See Also:
BaseTransformer.setSourceClasses(java.lang.Class[])

getSourceClassesImpl

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

Specified by:
getSourceClassesImpl in class BaseTransformer
Returns:
Class[]

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
See Also:
BaseTransformer.setDestinationClasses(java.lang.Class[])

getDestinationClassesImpl

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

Specified by:
getDestinationClassesImpl in class BaseTransformer
Returns:
Class[]

isAutomaticallyHandlingNulls

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. 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.

Overrides:
isAutomaticallyHandlingNulls in class BaseTransformer
Returns:
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
See Also:
BaseTransformer.isAutomaticallyHandlingNulls()

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

setNestedTransformer

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

Overrides:
setNestedTransformer in class BaseTransformer

isTransformableImpl

protected boolean isTransformableImpl(java.lang.Class destinationType,
                                      java.lang.Class sourceType)
                               throws java.lang.Exception
Default implementation for Transformer#isTransformable(Class, Class) that assumes that each source type can be converted into each destination type.

Overrides:
isTransformableImpl in class BaseTransformer
Parameters:
destinationType - the destination type to test
sourceType - the source type to test
Returns:
whether the destination type is transformable to the source type
Throws:
TransformationException - if it could not be determined if sourceType is transformable into destinationType
java.lang.Exception

getLocale

protected java.util.Locale getLocale()
Retrieves the current Locale if none is specified in the method arguments for a converter or copier. Attempts to load the Locale using Spring's org.springframework.context.i18n.LocaleContextHolder, if Spring is on the classpath. Otherwise, returns the default Locale by calling Locale.getDefault().

Overrides:
getLocale in class BaseTransformer
Returns:
the current Locale


Copyright © 2004-2008.