public abstract class AbstractTransformer extends org.mule.runtime.api.meta.AbstractAnnotatedObject implements Transformer
AbstractTransformer is a base class for all transformers. Transformations transform one object into another.ReactiveProcessor.ProcessingType| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
protected MuleContext |
muleContext |
protected String |
name
The name that identifies this transformer.
|
protected List<org.mule.runtime.api.metadata.DataType> |
sourceTypes
A list of supported Class types that the source payload passed into this transformer
|
| 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,
Charset enc) |
protected String |
generateTransformerName() |
String |
getName() |
org.mule.runtime.api.metadata.DataType |
getReturnDataType()
Specifies the return type of the result after this transformer has been executed.
|
List<org.mule.runtime.api.metadata.DataType> |
getSourceDataTypes()
Returns an unmodifiable list of Source types registered on this transformer
|
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(org.mule.runtime.api.metadata.DataType dataType)
Determines if a particular source class can be handled by this transformer
|
boolean |
isSourceDataTypeSupported(org.mule.runtime.api.metadata.DataType dataType,
boolean exactMatch)
Determines whether that data type passed in is supported by this transformer
|
Event |
process(Event event)
Invokes the MessageProcessor.
|
protected void |
registerSourceType(org.mule.runtime.api.metadata.DataType dataType)
Register a supported data type with this transformer.
|
protected Charset |
resolveEncoding(Object src) |
void |
setAllowNullReturn(boolean allowNullReturn) |
void |
setIgnoreBadInput(boolean ignoreBadInput) |
void |
setMuleContext(MuleContext context) |
void |
setName(String string) |
void |
setReturnDataType(org.mule.runtime.api.metadata.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,
Charset enc)
Transforms the supplied data and returns the result
|
protected void |
unregisterSourceType(org.mule.runtime.api.metadata.DataType dataType)
Unregister a supported source type from this transformer
|
getAnnotation, getAnnotations, getLocation, setAnnotationsclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetProcessingTypeprotected MuleContext muleContext
protected final org.slf4j.Logger logger
protected String name
protected final List<org.mule.runtime.api.metadata.DataType> sourceTypes
public AbstractTransformer()
public Event process(Event event) throws org.mule.runtime.api.exception.MuleException
Processorprotected void registerSourceType(org.mule.runtime.api.metadata.DataType dataType)
dataType - the source type to allowprotected void unregisterSourceType(org.mule.runtime.api.metadata.DataType dataType)
dataType - the type to removepublic String getName()
getName in interface org.mule.runtime.api.meta.NamedObjectpublic void setName(String string)
setName in interface org.mule.runtime.api.meta.NameableObjectstring - public void setReturnDataType(org.mule.runtime.api.metadata.DataType type)
TransformerTransformerException will be thrown.setReturnDataType in interface Transformertype - the expected return type for this transformerpublic org.mule.runtime.api.metadata.DataType getReturnDataType()
TransformergetReturnDataType in interface Transformerpublic boolean isAllowNullReturn()
public void setAllowNullReturn(boolean allowNullReturn)
public boolean isSourceDataTypeSupported(org.mule.runtime.api.metadata.DataType dataType)
TransformerisSourceDataTypeSupported in interface TransformerdataType - The DataType to check for compatibilitypublic boolean isSourceDataTypeSupported(org.mule.runtime.api.metadata.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
Transformertransform in interface Transformersrc - 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, Charset enc) throws TransformerException
Transformertransform in interface Transformersrc - 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)
protected abstract Object doTransform(Object src, Charset enc) throws TransformerException
TransformerExceptionpublic void initialise()
throws org.mule.runtime.api.lifecycle.InitialisationException
initialise in interface org.mule.runtime.api.lifecycle.Initialisableorg.mule.runtime.api.lifecycle.InitialisationExceptionpublic void dispose()
dispose in interface org.mule.runtime.api.lifecycle.Disposableprotected String generateTransformerName()
public List<org.mule.runtime.api.metadata.DataType> getSourceDataTypes()
TransformergetSourceDataTypes in interface Transformerpublic boolean isIgnoreBadInput()
TransformerisIgnoreBadInput in interface Transformerpublic void setIgnoreBadInput(boolean ignoreBadInput)
public boolean isAcceptNull()
TransformerisAcceptNull in interface Transformerpublic void setMuleContext(MuleContext context)
setMuleContext in interface MuleContextAwarecontext - the Mule node.Copyright © 2003–2017 MuleSoft, Inc.. All rights reserved.