public abstract class AbstractTransformer extends AbstractAnnotatedObject implements Transformer
AbstractTransformer
is a base class for all transformers.
Transformations transform one object into another.Modifier and Type | Field and Description |
---|---|
protected String |
encoding |
protected ImmutableEndpoint |
endpoint
The endpoint that this transformer instance is configured on
|
protected Log |
logger |
protected String |
mimeType |
static DataType<MuleMessage> |
MULE_MESSAGE_DATA_TYPE |
protected MuleContext |
muleContext |
protected String |
name
The name that identifies this transformer.
|
protected DataType<?> |
returnType
The return type that will be returned by the
transform(java.lang.Object) method is
called |
protected List<DataType<?>> |
sourceTypes
A list of supported Class types that the source payload passed into this
transformer
|
PHASE_NAME
PHASE_NAME
PROPERTY_NAME
Constructor and Description |
---|
AbstractTransformer()
default constructor required for discovery
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Template method where deriving classes can do any clean up any resources or state
before the object is disposed.
|
protected abstract Object |
doTransform(Object src,
String enc) |
protected String |
generateTransformerName() |
String |
getEncoding()
Return the encoding returned by the transformer (if any).
|
protected String |
getEncoding(Object src) |
ImmutableEndpoint |
getEndpoint()
The endpoint that this transformer is attached to
|
String |
getMimeType()
Return the mime type returned by the transformer (if any).
|
String |
getName()
Gets the name of the object
|
Class<?> |
getReturnClass()
Deprecated.
|
DataType<?> |
getReturnDataType()
Specifies the return type of the result after this transformer has been executed.
|
List<DataType<?>> |
getSourceDataTypes()
Returns an unmodifiable list of Source types registered on this transformer
|
List<Class<?>> |
getSourceTypes()
Deprecated.
|
void |
initialise()
Template method where deriving classes can do any initialisation after the
properties have been set on this transformer
|
boolean |
isAcceptNull()
Does this transformer allow null input?
|
boolean |
isAllowNullReturn() |
protected boolean |
isConsumed(Class<?> srcCls) |
boolean |
isIgnoreBadInput()
By default, Mule will throw an exception if a transformer is invoked with a source object that is not compatible
with the transformer.
|
boolean |
isSourceDataTypeSupported(DataType<?> dataType)
Determines if a particular source class can be handled by this transformer
|
boolean |
isSourceDataTypeSupported(DataType<?> dataType,
boolean exactMatch)
Determines whether that data type passed in is supported by this transformer
|
boolean |
isSourceTypeSupported(Class<?> aClass)
Deprecated.
|
boolean |
isSourceTypeSupported(Class<MuleMessage> aClass,
boolean exactMatch)
|
MuleEvent |
process(MuleEvent event)
Invokes the MessageProcessor.
|
protected void |
registerSourceType(Class<?> aClass)
Deprecated.
use registerSourceType(DataType)
|
protected void |
registerSourceType(DataType<?> dataType)
Register a supported data type with this transformer.
|
void |
setAllowNullReturn(boolean allowNullReturn) |
void |
setEncoding(String encoding) |
void |
setEndpoint(ImmutableEndpoint endpoint) |
void |
setIgnoreBadInput(boolean ignoreBadInput) |
void |
setMimeType(String mimeType) |
void |
setMuleContext(MuleContext context) |
void |
setName(String string)
Sets the name of the object
|
void |
setReturnClass(Class<?> newClass)
Deprecated.
|
void |
setReturnDataType(DataType<?> type)
Sets the expected return type for the transformed data.
|
String |
toString() |
Object |
transform(Object src)
Transforms the supplied data and returns the result
|
Object |
transform(Object src,
String enc)
Transforms the supplied data and returns the result
|
protected void |
unregisterSourceType(Class<?> aClass)
Deprecated.
use unregisterSourceType(DataType)
|
protected void |
unregisterSourceType(DataType<?> dataType)
Unregister a supported source type from this transformer
|
getAnnotation, getAnnotations, setAnnotations
public static final DataType<MuleMessage> MULE_MESSAGE_DATA_TYPE
protected MuleContext muleContext
protected final Log logger
protected DataType<?> returnType
transform(java.lang.Object)
method is
calledprotected String name
protected ImmutableEndpoint endpoint
protected final List<DataType<?>> sourceTypes
protected String mimeType
protected String encoding
public AbstractTransformer()
public MuleEvent process(MuleEvent event) throws MuleException
MessageProcessor
process
in interface MessageProcessor
event
- MuleEvent to be processedMuleException
@Deprecated protected void registerSourceType(Class<?> aClass)
aClass
- the source type to allow@Deprecated protected void unregisterSourceType(Class<?> aClass)
aClass
- the type to removeprotected void registerSourceType(DataType<?> dataType)
dataType
- the source type to allowprotected void unregisterSourceType(DataType<?> dataType)
dataType
- the type to removepublic String getName()
NamedObject
getName
in interface NamedObject
public void setName(String string)
NameableObject
setName
in interface NameableObject
string
- @Deprecated public Class<?> getReturnClass()
Transformer
getReturnClass
in interface Transformer
public void setReturnDataType(DataType<?> type)
Transformer
TransformerException
will be
thrown.
This method supersedes Transformer.getReturnClass()
because it allows Generics information to be associated with the
return type of the transformersetReturnDataType
in interface Transformer
type
- the expected return type for this transformerpublic DataType<?> getReturnDataType()
Transformer
Transformer.getReturnClass()
because it allows Generics information to be associated with the
return type of the transformergetReturnDataType
in interface Transformer
@Deprecated public void setReturnClass(Class<?> newClass)
Transformer
TransformerException
will be
thrown.setReturnClass
in interface Transformer
newClass
- the expected return type classpublic void setMimeType(String mimeType) throws MimeTypeParseException
MimeTypeParseException
public String getMimeType()
Transformer
getMimeType
in interface Transformer
public String getEncoding()
Transformer
getEncoding
in interface Transformer
public void setEncoding(String encoding)
public boolean isAllowNullReturn()
public void setAllowNullReturn(boolean allowNullReturn)
@Deprecated public boolean isSourceTypeSupported(Class<?> aClass)
Transformer
isSourceTypeSupported
in interface Transformer
aClass
- The class to check for compatibilitypublic boolean isSourceDataTypeSupported(DataType<?> dataType)
Transformer
isSourceDataTypeSupported
in interface Transformer
dataType
- The DataType to check for compatibility@Deprecated public boolean isSourceTypeSupported(Class<MuleMessage> aClass, boolean exactMatch)
aClass
- the type to check againstexactMatch
- if the source type on this transformer is open (can be anything) it will return true unless an
exact match is requested using this flagpublic boolean isSourceDataTypeSupported(DataType<?> dataType, boolean exactMatch)
dataType
- the type to check againstexactMatch
- if set to true, this method will look for an exact match to the data type, if false it will look
for a compatible data type.public final Object transform(Object src) throws TransformerException
Transformer
transform
in interface Transformer
src
- the data to transformTransformerException
- if a error occurs transforming the data or if the
expected returnClass isn't the same as the transformed datapublic Object transform(Object src, String enc) throws TransformerException
Transformer
transform
in interface Transformer
src
- the data to transformenc
- the encoding to use by this transformer. many transformations will not need encoding unless
dealing with text so you only need to use this method if yo wish to customize the encodingTransformerException
- if a error occurs transforming the data or if the
expected returnClass isn't the same as the transformed dataprotected boolean isConsumed(Class<?> srcCls)
public ImmutableEndpoint getEndpoint()
Transformer
getEndpoint
in interface Transformer
public void setEndpoint(ImmutableEndpoint endpoint)
setEndpoint
in interface EndpointAware
protected abstract Object doTransform(Object src, String enc) throws TransformerException
TransformerException
public void initialise() throws InitialisationException
initialise
in interface Initialisable
InitialisationException
RecoverableException
- if an error occurs that can be recovered frompublic void dispose()
dispose
in interface Disposable
protected String generateTransformerName()
@Deprecated public List<Class<?>> getSourceTypes()
Transformer
getSourceTypes
in interface Transformer
public List<DataType<?>> getSourceDataTypes()
Transformer
getSourceDataTypes
in interface Transformer
public boolean isIgnoreBadInput()
Transformer
isIgnoreBadInput
in interface Transformer
public void setIgnoreBadInput(boolean ignoreBadInput)
public boolean isAcceptNull()
Transformer
isAcceptNull
in interface Transformer
public void setMuleContext(MuleContext context)
setMuleContext
in interface MuleContextAware
Copyright © 2003–2015 MuleSoft, Inc.. All rights reserved.