|
||||||||||
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.copiers.TextToContainerCopier
public class TextToContainerCopier
Parses text into multiple parts for storage in a container. For example, the
text { 1, 2, 3 }
code be converted into an
Integer[]
array like this:
String str = "{ 1, 2, 3 }"; TextToContainerCopier copier = new TextToContainerCopier(); Integer[] array = (Integer[]) copier.convert(Integer[].class, str);Configuration parameters
ignoredCharacters
characters that are completely ignored
in the source. The default characters (specified by
DEFAULT_IGNORED_CHARACTERS
) are often used as grouping type
characters and probably aren't part of the information to be extracted to the
destination object.delimiter
characters that are used to separate the
different elements to be copied to the container. The default characters are
specified by DEFAULT_DELIMITERS
.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_DELIMITERS
Default delimiters |
static java.lang.String |
DEFAULT_IGNORED_CHARACTERS
Default ignored characters |
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 | |
---|---|
TextToContainerCopier()
|
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. |
Copier |
getContainerCopier()
Get the container copier used by this TextToContainerCopier. |
java.lang.String |
getDelimiters()
Returns the characters that are used to separate the different elements to be copied to the container. |
protected java.lang.Class[] |
getDestinationClassesImpl()
Transformer.getDestinationClasses() implementation template method. |
java.lang.String |
getIgnoredCharacters()
Returns characters that are completely ignored in the source. |
protected java.lang.Class[] |
getSourceClassesImpl()
Transformer.getSourceClasses() implementation template method. |
Converter |
getTextConverter()
Get the text converter used by this TextToContainerCopier. |
protected java.util.Enumeration |
getTokenizer(java.lang.Object source,
java.util.Locale locale)
Constructs a StringTokenizer that can be passed directly to the containerCopier to complete the transformation. |
protected boolean |
isWrappingRuntimeExceptions()
Indicates whether runtime exceptions should be wrapped as TransformationException s. |
protected java.lang.String |
removeIgnoredCharacters(java.lang.String source,
java.lang.String ignoredCharacters)
Remove all characters contained in ignoredCharacters from
source . |
void |
setContainerCopier(Copier containerCopier)
Set the container copier used by this TextToContainerCopier. |
void |
setDelimiters(java.lang.String delimiters)
Sets the characters that are used to separate the different elements to be copied to the container. |
void |
setIgnoredCharacters(java.lang.String ignoredCharacters)
Sets the characters that are completely ignored in the source. |
void |
setTextConverter(Converter textConverter)
Set the text converter used by this TextToContainerCopier. |
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.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 |
Field Detail |
---|
public static final java.lang.String DEFAULT_DELIMITERS
public static final java.lang.String DEFAULT_IGNORED_CHARACTERS
Constructor Detail |
---|
public TextToContainerCopier()
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 void copyImpl(java.lang.Object destination, java.lang.Object source, java.util.Locale locale, java.lang.Integer preferredTransformationType) throws java.lang.Exception
copyImpl
in class BaseTransformer
java.lang.Exception
protected java.util.Enumeration getTokenizer(java.lang.Object source, java.util.Locale locale)
containerCopier
to complete the transformation.
source
- the source, as passed in by the userlocale
- the locale in which the transformation is to take place
containerCopier
to complete the transformationprotected java.lang.String removeIgnoredCharacters(java.lang.String source, java.lang.String ignoredCharacters)
ignoredCharacters
from
source
.
source
- the String from which characters are to be removedignoredCharacters
- the characters to be removed
source
, but with all characters
contained in ignoredCharacters
removedprotected java.lang.Class[] getDestinationClassesImpl() throws java.lang.Exception
Transformer.getDestinationClasses()
implementation template method.
getDestinationClassesImpl
in class BaseTransformer
java.lang.Exception
protected java.lang.Class[] getSourceClassesImpl() throws java.lang.Exception
Transformer.getSourceClasses()
implementation template method.
getSourceClassesImpl
in class BaseTransformer
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 java.lang.String getDelimiters()
public void setDelimiters(java.lang.String delimiters)
delimiters
- the characters that are used to separate the different
elements to be copied to the containerpublic java.lang.String getIgnoredCharacters()
public void setIgnoredCharacters(java.lang.String ignoredCharacters)
ignoredCharacters
- the characters that are completely ignored in the sourcepublic Converter getTextConverter()
public void setTextConverter(Converter textConverter)
textConverter
- public Copier getContainerCopier()
public void setContainerCopier(Copier containerCopier)
containerCopier
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |