|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.morph.transform.transformers.BaseTransformer net.sf.morph.transform.transformers.BaseReflectorTransformer net.sf.morph.transform.copiers.ContainerCopier
public class ContainerCopier
Copies information from any container object to any object that has either a
GrowableContainerReflector
or a
MutableIndexedContainerReflector
. If the source object has a
growable container reflector, information is added to the end of the
destination when a copy is performed. If the source object does not have a
growable container reflector (i.e. - it has a mutable indexed reflector),
information copied from the source to the destination will overwrite the
information in the destination.
By default, this means:
Destinations | Sources |
---|---|
java.util.List java.util.Set java.lang.Object[], int[], etc. (arrays) |
java.util.Iterator java.util.Enumeration java.util.Collection java.lang.Object[], int[], etc. (arrays) java.util.Map (values are extracted) java.lang.Object (added to the end of the destination) |
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 | |
---|---|
ContainerCopier()
Create a new ContainerCopier. |
Method Summary | |
---|---|
protected java.lang.Object |
convertImpl(java.lang.Class destinationClass,
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 void |
copyImpl(java.lang.Object destination,
java.lang.Object source,
java.util.Locale locale,
java.lang.Integer preferredTransformationType)
Implementation of the copy method. |
java.lang.Object |
createReusableSource(java.lang.Class destinationClass,
java.lang.Object source)
NodeCopier.createReusableSource(Class, Object) |
protected java.lang.Class |
determineDestinationContainedType(java.lang.Object destination,
java.lang.Class sourceValueClass)
Deprecated. in favor of fully-specified method |
protected java.lang.Class |
determineDestinationContainedType(java.lang.Object destination,
java.lang.Object sourceValue,
java.lang.Class sourceValueClass,
java.util.Locale locale)
Determine the container element destination type. |
java.util.Map |
getContainedSourceToDestinationTypeMap()
Get the mapping of source to destination container element types. |
protected java.lang.Class[] |
getDestinationClassesImpl()
Transformer.getDestinationClasses() implementation template method. |
Transformer |
getNestedTransformer()
NodeCopier.getNestedTransformer() |
protected java.lang.Class[] |
getSourceClassesImpl()
Transformer.getSourceClasses() implementation template method. |
boolean |
isPreferGrow()
Learn whether this ContainerCopier prefers to grow the destination when possible. |
protected boolean |
isWrappingRuntimeExceptions()
Indicates whether runtime exceptions should be wrapped as TransformationException s. |
protected java.lang.Object |
nestedTransform(java.lang.Class destinationContainedType,
java.lang.Object destinationValue,
java.lang.Object sourceValue,
java.util.Locale locale,
java.lang.Integer preferredTransformationType)
Do a nested transformation. |
protected void |
put(int index,
java.lang.Object destination,
java.lang.Object sourceValue,
java.lang.Class sourceValueClass,
java.util.Locale locale,
java.lang.Integer preferredTransformationType)
Adds an element to the destination object that is from the given index of the source object. |
void |
setContainedSourceToDestinationTypeMap(java.util.Map containedSourceToDestinationMapping)
Set the mapping of source to destination container element types. |
void |
setNestedTransformer(Transformer transformer)
NodeCopier.setNestedTransformer(Transformer) |
void |
setPreferGrow(boolean preferGrow)
Set whether this ContainerCopier prefers to grow the destination when possible. |
Methods inherited from class net.sf.morph.transform.transformers.BaseReflectorTransformer |
---|
getBeanReflector, getContainerReflector, getGrowableContainerReflector, getIndexedContainerReflector, getMutableIndexedContainerReflector, hasReflector |
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 |
---|
public ContainerCopier()
Method Detail |
---|
protected java.lang.Class determineDestinationContainedType(java.lang.Object destination, java.lang.Object sourceValue, java.lang.Class sourceValueClass, java.util.Locale locale)
determineDestinationContainedType(Object, Class)
.
destination
- containersourceValue
- source valuesourceValueClass
- source type, or type source value would be if not null
protected java.lang.Class determineDestinationContainedType(java.lang.Object destination, java.lang.Class sourceValueClass)
destination
- containersourceValueClass
- source type
protected void put(int index, java.lang.Object destination, java.lang.Object sourceValue, java.lang.Class sourceValueClass, java.util.Locale locale, java.lang.Integer preferredTransformationType)
index
- the current index into the container that is being transformeddestination
- the destination container to which values are being copied
from the source containersourceValue
- the value the source object has at the current indexsourceValueClass
- the type of sourceValue, or the type the sourceValue would be
were it not null
locale
- the locale in which the current transformation is taking placepreferredTransformationType
- the preferred transformation type to perform when transforming
the sourceValue for addition into the destinationprotected java.lang.Object nestedTransform(java.lang.Class destinationContainedType, java.lang.Object destinationValue, java.lang.Object sourceValue, java.util.Locale locale, java.lang.Integer preferredTransformationType)
destinationContainedType
- destinationValue
- sourceValue
- locale
- preferredTransformationType
-
protected java.lang.Object convertImpl(java.lang.Class destinationClass, java.lang.Object source, java.util.Locale locale) throws java.lang.Exception
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.
convertImpl
in class BaseTransformer
locale
- the locale in which the conversion should take place. for
converters that are not locale-aware, the local argument can
simply be ignored
java.lang.Exception
protected void copyImpl(java.lang.Object destination, java.lang.Object source, java.util.Locale locale, java.lang.Integer preferredTransformationType) throws TransformationException
copyImpl
in class BaseTransformer
TransformationException
public java.lang.Object createReusableSource(java.lang.Class destinationClass, java.lang.Object source)
NodeCopier.createReusableSource(Class, Object)
createReusableSource
in interface NodeCopier
createReusableSource
in class BaseTransformer
destinationClass
- the destination class to which this source object will be
transformedsource
- a source object that will undergo a transformation by this
copier
protected java.lang.Class[] getDestinationClassesImpl() throws java.lang.Exception
Transformer.getDestinationClasses()
implementation template method.
getDestinationClassesImpl
in class BaseReflectorTransformer
java.lang.Exception
protected java.lang.Class[] getSourceClassesImpl() throws java.lang.Exception
Transformer.getSourceClasses()
implementation template method.
getSourceClassesImpl
in class BaseReflectorTransformer
java.lang.Exception
protected boolean isWrappingRuntimeExceptions()
TransformationException
s. 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).
isWrappingRuntimeExceptions
in class BaseTransformer
true
public Transformer getNestedTransformer()
NodeCopier.getNestedTransformer()
getNestedTransformer
in interface NodeCopier
getNestedTransformer
in class BaseTransformer
public void setNestedTransformer(Transformer transformer)
NodeCopier.setNestedTransformer(Transformer)
setNestedTransformer
in interface NodeCopier
setNestedTransformer
in class BaseTransformer
transformer
- the transformer used to perform nested transformationspublic java.util.Map getContainedSourceToDestinationTypeMap()
net.sf.morph.util.TypeMap}
public void setContainedSourceToDestinationTypeMap(java.util.Map containedSourceToDestinationMapping)
containedSourceToDestinationMapping
- Mapnet.sf.morph.util.TypeMap}
public boolean isPreferGrow()
public void setPreferGrow(boolean preferGrow)
true
; when false
grow vs. mutate will be determined at runtime by the capabilities of the configured
reflector with regard to the copy destination; preferredTransformationType will also
be observed.
preferGrow
- the boolean to setcopyImpl(Object, Object, Locale, Integer)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |