public abstract class AbstractTransformer extends AbstractComponent 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<DataType> |
sourceTypes
A list of supported Class types that the source payload passed into this transformer
|
LOCATION_KEY, ROOT_CONTAINER_NAME_KEY
PHASE_NAME
PHASE_NAME
ANNOTATIONS_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,
Charset enc) |
boolean |
equals(Object obj) |
protected String |
generateTransformerName() |
String |
getName()
Gets the name of the object
|
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
|
int |
hashCode() |
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
|
CoreEvent |
process(CoreEvent event)
Invokes the MessageProcessor.
|
protected void |
registerSourceType(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)
Sets the name of the object
|
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,
Charset enc)
Transforms the supplied data and returns the result
|
protected void |
unregisterSourceType(DataType dataType)
Unregister a supported source type from this transformer
|
getAnnotation, getAnnotations, getLocation, getRootContainerLocation, setAnnotations
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getProcessingType
protected MuleContext muleContext
protected final org.slf4j.Logger logger
protected String name
public AbstractTransformer()
public CoreEvent process(CoreEvent event) throws MuleException
Processor
process
in interface Processor
event
- MuleEvent to be processedMuleException
protected 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
- public void setReturnDataType(DataType type)
Transformer
TransformerException
will be thrown.setReturnDataType
in interface Transformer
type
- the expected return type for this transformerpublic DataType getReturnDataType()
Transformer
getReturnDataType
in interface Transformer
public boolean isAllowNullReturn()
public void setAllowNullReturn(boolean allowNullReturn)
public boolean isSourceDataTypeSupported(DataType dataType)
Transformer
isSourceDataTypeSupported
in interface Transformer
dataType
- The DataType to check for compatibilitypublic 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, Charset 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)
protected abstract Object doTransform(Object src, Charset enc) throws TransformerException
TransformerException
public void initialise() throws InitialisationException
initialise
in interface Initialisable
InitialisationException
Disposable
public void dispose()
dispose
in interface Disposable
protected String generateTransformerName()
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
context
- the Mule node.Copyright © 2018. All rights reserved.