org.mule.transformers
Class AbstractTransformer

java.lang.Object
  extended by org.mule.transformers.AbstractTransformer
All Implemented Interfaces:
Cloneable, Initialisable, UMOBaseTransformer, UMOTransformer
Direct Known Subclasses:
AbstractCompressionTransformer, AbstractEncryptionTransformer, AbstractEventAwareTransformer, AbstractEventTransformer, AbstractJmsTransformer, AbstractXmlTransformer, Base64Decoder, Base64Encoder, ByteArrayToHexString, ByteArrayToSerializable, ByteArrayToString, ChatStringToString, CreditProfileXmlToCreditProfile, EmailMessageToString, ErrorMessageToException, ErrorMessageToExceptionBean, ExceptionBeanToErrorMessage, ExceptionToString, FileToByteArray, GetBeanProperty, HexStringToByteArray, HttpClientMethodResponseToObject, HttpRequestToNameString, HttpResponseToString, JXPathExtractor, LoanQuoteRequestToCreditProfileArgs, MapLookup, MimeMessageToRfc822ByteArray, NameStringToChatString, NoActionTransformer, ObjectArrayToString, ObjectToFruitLover, ObjectToRemoteInvocationResultTransformer, ObjectToRemoteInvocationTransformer, ObjectToString, Rfc822ByteArraytoMimeMessage, StdinToNameString, StringToByteArray, StringToNameString, StringToObjectArray, XmlEntityDecoder, XmlEntityEncoder, XmlPrettyPrinter

public abstract class AbstractTransformer
extends Object
implements UMOTransformer

AbstractTransformer is a base class for all transformers. Transformations transform one object into another.


Field Summary
protected static int DEFAULT_TRUNCATE_LENGTH
           
protected  UMOImmutableEndpoint endpoint
          The endpoint that this transformer instance is configured on
protected  Log logger
          logger used by this class
protected  String name
          The name that identifies this transformer.
protected  UMOTransformer nextTransformer
          This is the following transformer in the chain of transformers.
protected  Class returnClass
          The return type that will be returned by the transform(java.lang.Object) method is called
protected  List sourceTypes
          A list of supported Class types that the source payload passed into this transformer
 
Constructor Summary
AbstractTransformer()
          default constructor required for discovery
 
Method Summary
protected  Object checkReturnClass(Object object)
           
 Object clone()
           
protected abstract  Object doTransform(Object src, String encoding)
           
protected  String generateTransformerName()
           
 UMOImmutableEndpoint getEndpoint()
          The endpoint that this transformer is attached to
 Class getFinalReturnClass()
          Will return the return type for the last transformer in the chain
 String getName()
           
 UMOTransformer getNextTransformer()
          Transformers can be chained together and invoked in a series
 Class getReturnClass()
           
 void initialise()
          Template method were deriving classes can do any initialisation after the properties have been set on this transformer
 boolean isAcceptNull()
          Does this transformer allow null input?
 boolean isIgnoreBadInput()
           
 boolean isSourceTypeSupported(Class aClass)
          Determines if a particular source class can be handled by this transformer
 boolean isSourceTypeSupported(Class aClass, boolean exactMatch)
           
protected  Object nextTransform(Object result)
          Safely call the next transformer in chain, if any.
protected  void registerSourceType(Class aClass)
           
 void setEndpoint(UMOImmutableEndpoint endpoint)
          Sets the endpoint associated with with this connector
 void setIgnoreBadInput(boolean ignoreBadInput)
           
 void setName(String string)
           
 void setNextTransformer(UMOTransformer nextTransformer)
          Transformers can be chained together and invoked in a series
 void setReturnClass(Class newClass)
          Sets the expected return type for the transformed data.
 String toString()
           
 Object transform(Object src)
          Transforms the object.
protected  void unregisterSourceType(Class aClass)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TRUNCATE_LENGTH

protected static final int DEFAULT_TRUNCATE_LENGTH
See Also:
Constant Field Values

logger

protected final Log logger
logger used by this class


returnClass

protected Class returnClass
The return type that will be returned by the transform(java.lang.Object) method is called


name

protected String name
The name that identifies this transformer. If none is set the class name of the transformer is used


endpoint

protected UMOImmutableEndpoint endpoint
The endpoint that this transformer instance is configured on


sourceTypes

protected final List sourceTypes
A list of supported Class types that the source payload passed into this transformer


nextTransformer

protected UMOTransformer nextTransformer
This is the following transformer in the chain of transformers.

Constructor Detail

AbstractTransformer

public AbstractTransformer()
default constructor required for discovery

Method Detail

checkReturnClass

protected Object checkReturnClass(Object object)
                           throws TransformerException
Throws:
TransformerException

registerSourceType

protected void registerSourceType(Class aClass)

unregisterSourceType

protected void unregisterSourceType(Class aClass)

getName

public String getName()
Specified by:
getName in interface UMOBaseTransformer
Returns:
transformer name

setName

public void setName(String string)
Specified by:
setName in interface UMOBaseTransformer
Parameters:
string -

getReturnClass

public Class getReturnClass()
Specified by:
getReturnClass in interface UMOTransformer
Returns:
the exceptedreturn type

setReturnClass

public void setReturnClass(Class newClass)
Description copied from interface: UMOTransformer
Sets the expected return type for the transformed data. If the transformed data is not of this class type a TransformerException will be thrown.

Specified by:
setReturnClass in interface UMOTransformer
Parameters:
newClass - the expected return type class

isSourceTypeSupported

public boolean isSourceTypeSupported(Class aClass)
Description copied from interface: UMOTransformer
Determines if a particular source class can be handled by this transformer

Specified by:
isSourceTypeSupported in interface UMOTransformer
Parameters:
aClass - The class to check for compatability
Returns:
true if the transformer supports this types of class or false otherwise

isSourceTypeSupported

public boolean isSourceTypeSupported(Class aClass,
                                     boolean exactMatch)

transform

public final Object transform(Object src)
                       throws TransformerException
Transforms the object.

Specified by:
transform in interface UMOTransformer
Parameters:
src - The source object to transform.
Returns:
The transformed object
Throws:
TransformerException - if a error occurs transforming the data or if the expected returnClass isn't the same as the transformed data

getEndpoint

public UMOImmutableEndpoint getEndpoint()
Description copied from interface: UMOBaseTransformer
The endpoint that this transformer is attached to

Specified by:
getEndpoint in interface UMOBaseTransformer
Returns:
the endpoint associated with the transformer

setEndpoint

public void setEndpoint(UMOImmutableEndpoint endpoint)
Description copied from interface: UMOBaseTransformer
Sets the endpoint associated with with this connector

Specified by:
setEndpoint in interface UMOBaseTransformer
Parameters:
endpoint - sets the endpoint associated with the transfromer

doTransform

protected abstract Object doTransform(Object src,
                                      String encoding)
                               throws TransformerException
Throws:
TransformerException

getNextTransformer

public UMOTransformer getNextTransformer()
Description copied from interface: UMOTransformer
Transformers can be chained together and invoked in a series

Specified by:
getNextTransformer in interface UMOTransformer
Returns:
the next transformer to invoke after this one

setNextTransformer

public void setNextTransformer(UMOTransformer nextTransformer)
Description copied from interface: UMOTransformer
Transformers can be chained together and invoked in a series

Specified by:
setNextTransformer in interface UMOTransformer
Parameters:
nextTransformer - the next transforer to invoke

clone

public Object clone()
             throws CloneNotSupportedException
Specified by:
clone in interface UMOBaseTransformer
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getFinalReturnClass

public Class getFinalReturnClass()
Will return the return type for the last transformer in the chain

Returns:
the last transformers return type

initialise

public void initialise()
                throws InitialisationException
Template method were deriving classes can do any initialisation after the properties have been set on this transformer

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException
RecoverableException - if an error occurs that can be recovered from

generateTransformerName

protected String generateTransformerName()

isIgnoreBadInput

public boolean isIgnoreBadInput()

setIgnoreBadInput

public void setIgnoreBadInput(boolean ignoreBadInput)

toString

public String toString()
Overrides:
toString in class Object

isAcceptNull

public boolean isAcceptNull()
Description copied from interface: UMOTransformer
Does this transformer allow null input?

Specified by:
isAcceptNull in interface UMOTransformer
Returns:
true if this transformer can accept null input

nextTransform

protected Object nextTransform(Object result)
                        throws TransformerException
Safely call the next transformer in chain, if any.

Throws:
TransformerException


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.