|
||||||||||
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.converters.ConverterDecorator
public class ConverterDecorator
Decorates any Converter so that it implements
DecoratedConverter
. Example usage:
Converter myConverter = new MyConverter(); DecoratedConverter decoratedConverter = new DecoratedConverter(myConverter); // now use decoratedConverter instead of myConverter StringBuffer buffer = decoratedConverter.convert(StringBuffer.class, "no locale needed");
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 |
Constructor Summary | |
---|---|
ConverterDecorator()
Create a new ConverterDecorator. |
|
ConverterDecorator(Converter converter)
Create a new ConverterDecorator. |
|
ConverterDecorator(Converter converter,
java.util.Locale defaultLocale)
Create a new ConverterDecorator. |
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. |
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. |
Converter |
getNestedConverter()
|
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 TransformationException s. |
void |
setDefaultLocale(java.util.Locale defaultLocale)
Set the defaultLocale. |
void |
setDestinationClasses(java.lang.Class[] destinationClasses)
Configures the destinationClasses property of this
transformer. |
void |
setNestedConverter(Converter converter)
|
void |
setSourceClasses(java.lang.Class[] sourceClasses)
Configures the sourceClasses property of this transformer. |
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 |
Constructor Detail |
---|
public ConverterDecorator()
public ConverterDecorator(Converter converter)
converter
- public ConverterDecorator(Converter converter, java.util.Locale defaultLocale)
converter
- defaultLocale
- Method Detail |
---|
public Converter getNestedConverter()
public void setNestedConverter(Converter converter)
converter
- The converter to set.public java.util.Locale getDefaultLocale()
public void setDefaultLocale(java.util.Locale defaultLocale)
defaultLocale
- the Locale to setprotected 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
BaseTransformer.convertImpl(java.lang.Class, java.lang.Object, java.util.Locale)
public void setSourceClasses(java.lang.Class[] sourceClasses)
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.
setSourceClasses
in class BaseTransformer
sourceClasses
- the new sourceClasses
for this transformerBaseTransformer.setSourceClasses(java.lang.Class[])
protected java.lang.Class[] getSourceClassesImpl()
Transformer.getSourceClasses()
implementation template method.
getSourceClassesImpl
in class BaseTransformer
BaseTransformer.getSourceClassesImpl()
public void setDestinationClasses(java.lang.Class[] destinationClasses)
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.
setDestinationClasses
in class BaseTransformer
destinationClasses
- the new destinationClasses
for this transformerBaseTransformer.setDestinationClasses(java.lang.Class[])
protected java.lang.Class[] getDestinationClassesImpl()
Transformer.getDestinationClasses()
implementation template method.
getDestinationClassesImpl
in class BaseTransformer
BaseTransformer.getDestinationClassesImpl()
protected boolean isAutomaticallyHandlingNulls()
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
null
s should be included.
isAutomaticallyHandlingNulls
in class BaseTransformer
null
values will automatically be
converted to null
by this base class before even
calling the subclass's
BaseTransformer.convertImpl(Class, Object, Locale)
methodBaseTransformer.isAutomaticallyHandlingNulls()
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
BaseTransformer.isWrappingRuntimeExceptions()
protected boolean isTransformableImpl(java.lang.Class destinationType, java.lang.Class sourceType) throws java.lang.Exception
Transformer#isTransformable(Class, Class)
that assumes that each
source type can be converted into each destination type.
isTransformableImpl
in class BaseTransformer
destinationType
- the destination type to testsourceType
- the source type to test
TransformationException
- if it could not be determined if sourceType
is transformable into destinationType
java.lang.Exception
protected java.util.Locale getLocale()
org.springframework.context.i18n.LocaleContextHolder
, if Spring
is on the classpath. Otherwise, returns the default Locale by calling
Locale.getDefault()
.
getLocale
in class BaseTransformer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |