net.sf.morph.transform.copiers
Class TextToContainerCopier

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

public class TextToContainerCopier
extends BaseTransformer
implements DecoratedConverter, DecoratedCopier

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

Since:
Apr 9, 2007
Author:
Matt Sgarlata

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 TransformationExceptions.
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 net.sf.morph.transform.transformers.BaseTransformer
clone, convert, convert, copy, copy, createDefaultReflector, createNewInstance, createNewInstanceImpl, createReusableSource, equals, equals, equalsUnidirectionalTest, getDestinationClasses, getInstantiatingReflector, getLocale, getLog, getNestedTransformer, getReflector, getReflector, getSourceClasses, getTransformableCallCache, getTransformerName, initialize, initializeImpl, isAutomaticallyHandlingNulls, isCachingIsTransformableCalls, isImpreciseTransformation, isImpreciseTransformationImpl, isInitialized, isPerformingLogging, isTransformable, isTransformableImpl, setCachingIsTransformableCalls, setDestinationClasses, setInitialized, setLog, setNestedTransformer, setReflector, setSourceClasses, 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.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

DEFAULT_DELIMITERS

public static final java.lang.String DEFAULT_DELIMITERS
Default delimiters

See Also:
Constant Field Values

DEFAULT_IGNORED_CHARACTERS

public static final java.lang.String DEFAULT_IGNORED_CHARACTERS
Default ignored characters

See Also:
Constant Field Values
Constructor Detail

TextToContainerCopier

public TextToContainerCopier()
Method Detail

convertImpl

protected java.lang.Object convertImpl(java.lang.Class destinationClass,
                                       java.lang.Object source,
                                       java.util.Locale locale)
                                throws java.lang.Exception
The implementation of the 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.

Overrides:
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
Throws:
java.lang.Exception

copyImpl

protected void copyImpl(java.lang.Object destination,
                        java.lang.Object source,
                        java.util.Locale locale,
                        java.lang.Integer preferredTransformationType)
                 throws java.lang.Exception
Implementation of the copy method. By default, this method throws UnsupportedOperationException.

Overrides:
copyImpl in class BaseTransformer
Throws:
java.lang.Exception

getTokenizer

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.

Parameters:
source - the source, as passed in by the user
locale - the locale in which the transformation is to take place
Returns:
a StringTokenizer that can be passed directly to the containerCopier to complete the transformation

removeIgnoredCharacters

protected java.lang.String removeIgnoredCharacters(java.lang.String source,
                                                   java.lang.String ignoredCharacters)
Remove all characters contained in ignoredCharacters from source.

Parameters:
source - the String from which characters are to be removed
ignoredCharacters - the characters to be removed
Returns:
a copy of source, but with all characters contained in ignoredCharacters removed

getDestinationClassesImpl

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

Specified by:
getDestinationClassesImpl in class BaseTransformer
Returns:
Class[]
Throws:
java.lang.Exception

getSourceClassesImpl

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

Specified by:
getSourceClassesImpl in class BaseTransformer
Returns:
Class[]
Throws:
java.lang.Exception

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

getDelimiters

public java.lang.String getDelimiters()
Returns the characters that are used to separate the different elements to be copied to the container.

Returns:
the characters that are used to separate the different elements to be copied to the container.

setDelimiters

public void setDelimiters(java.lang.String delimiters)
Sets the characters that are used to separate the different elements to be copied to the container.

Parameters:
delimiters - the characters that are used to separate the different elements to be copied to the container

getIgnoredCharacters

public java.lang.String getIgnoredCharacters()
Returns characters that are completely ignored in the source.

Returns:
characters that are completely ignored in the source

setIgnoredCharacters

public void setIgnoredCharacters(java.lang.String ignoredCharacters)
Sets the characters that are completely ignored in the source.

Parameters:
ignoredCharacters - the characters that are completely ignored in the source

getTextConverter

public Converter getTextConverter()
Get the text converter used by this TextToContainerCopier.

Returns:
Converter

setTextConverter

public void setTextConverter(Converter textConverter)
Set the text converter used by this TextToContainerCopier.

Parameters:
textConverter -

getContainerCopier

public Copier getContainerCopier()
Get the container copier used by this TextToContainerCopier.

Returns:
Copier

setContainerCopier

public void setContainerCopier(Copier containerCopier)
Set the container copier used by this TextToContainerCopier.

Parameters:
containerCopier -


Copyright © 2004-2008.