|
||||||||||
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.TextConverter
public class TextConverter
Converts text types (String
,
StringBuffer
and Character
,
char[]
and byte[]
from one type to another.
Empty Strings, StringBuffers with lengths of zero and empty character and
byte arrays are converted to null
Characters, and non-empty
Strings and StringBuffers are converted to Characters by returning the first
character in the String or StringBuffer. CharSequence is handled in this way:
an explicit request for CharSequence yields a String. Other CharSequence
implementations are handled if they have a public constructor that accepts
a String argument.
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 | |
---|---|
TextConverter()
|
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 java.lang.Class[] |
getDestinationClassesImpl()
Transformer.getDestinationClasses() implementation template method. |
protected java.lang.Class[] |
getSourceClassesImpl()
Transformer.getSourceClasses() implementation template method. |
boolean |
isAllowStringAsChar()
Learn whether string-to-char type conversions are allowed. |
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. |
boolean |
isEmptyNull()
Learn whether null values return as empty strings. |
protected boolean |
isImpreciseTransformationImpl(java.lang.Class destinationClass,
java.lang.Class sourceClass)
Implementation of isImpreciseTransformation |
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. |
void |
setAllowStringAsChar(boolean allowStringAsChar)
Set whether string-to-char type conversions are allowed. |
void |
setEmptyNull(boolean emptyNull)
Set whether null values return as empty strings. |
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 |
Methods inherited from interface net.sf.morph.transform.ImpreciseTransformer |
---|
isImpreciseTransformation |
Constructor Detail |
---|
public TextConverter()
Method Detail |
---|
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 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 boolean isImpreciseTransformationImpl(java.lang.Class destinationClass, java.lang.Class sourceClass)
isImpreciseTransformationImpl
in class BaseTransformer
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)
methodprotected java.lang.Class[] getSourceClassesImpl() throws java.lang.Exception
Transformer.getSourceClasses()
implementation template method.
getSourceClassesImpl
in class BaseTransformer
java.lang.Exception
protected java.lang.Class[] getDestinationClassesImpl() throws java.lang.Exception
Transformer.getDestinationClasses()
implementation template method.
getDestinationClassesImpl
in class BaseTransformer
java.lang.Exception
public boolean isEmptyNull()
null
values return as empty strings.
public void setEmptyNull(boolean emptyNull)
null
values return as empty strings.
emptyNull
- booleanpublic boolean isAllowStringAsChar()
public void setAllowStringAsChar(boolean allowStringAsChar)
true
.
allowStringAsChar
- the boolean to set
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |