org.mule.transformer
Class CompositeConverter

java.lang.Object
  extended by org.mule.transformer.CompositeConverter
All Implemented Interfaces:
MuleContextAware, Disposable, Initialisable, NameableObject, NamedObject, MessageProcessor, Converter, Transformer, EndpointAware

public class CompositeConverter
extends Object
implements Converter

Composes many converters to behave as a single one.

When transform(Object) is called each converter in the same order they are included in the composition. The output of a given converter is the input of the next composed converter.


Field Summary
 
Fields inherited from interface org.mule.api.transformer.Converter
DEFAULT_PRIORITY_WEIGHTING, MAX_PRIORITY_WEIGHTING, MIN_PRIORITY_WEIGHTING
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Disposable
PHASE_NAME
 
Constructor Summary
CompositeConverter(Converter... converters)
          Create a new conversion chain using the specified converters
 
Method Summary
 void dispose()
          A lifecycle method where implementor should free up any resources.
 LinkedList<Converter> getConverters()
           
 String getEncoding()
          Return the encoding returned by the transformer (if any).
 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
 int getPriorityWeighting()
          If two or more discoverable transformers are equal, this value can be used to select the correct one
 Class<?> getReturnClass()
          Specifies the Java type of the result after this transformer has been executed.
 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()
          Returns an unmodifiable list of Source types registered on this transformer
 void initialise()
          Method used to perform any initialisation work.
 boolean isAcceptNull()
          Does this transformer allow null input?
 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 isSourceTypeSupported(Class<?> aClass)
          Determines if a particular source class can be handled by this transformer
 MuleEvent process(MuleEvent event)
          Invokes the MessageProcessor.
 void setEndpoint(ImmutableEndpoint ep)
           
 void setMuleContext(MuleContext context)
           
 void setName(String name)
          Sets the name of the object
 void setPriorityWeighting(int weighting)
          If 2 or more discoverable transformers are equal, this value can be used to select the correct one
 void setReturnClass(Class<?> theClass)
          Sets the expected return type for the transformed data.
 void setReturnDataType(DataType<?> type)
          Sets the expected return type for the transformed data.
 Object transform(Object src)
          Transforms the supplied data and returns the result
 Object transform(Object src, String encoding)
          Transforms the supplied data and returns the result
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeConverter

public CompositeConverter(Converter... converters)
Create a new conversion chain using the specified converters

Parameters:
converters - List of converters using to build the chain
Method Detail

isSourceTypeSupported

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

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

isSourceDataTypeSupported

public boolean isSourceDataTypeSupported(DataType<?> dataType)
Description copied from interface: Transformer
Determines if a particular source class can be handled by this transformer

Specified by:
isSourceDataTypeSupported in interface Transformer
Parameters:
dataType - The DataType to check for compatibility
Returns:
true if the transformer supports this type of class or false otherwise

getSourceTypes

public List<Class<?>> getSourceTypes()
Description copied from interface: Transformer
Returns an unmodifiable list of Source types registered on this transformer

Specified by:
getSourceTypes in interface Transformer
Returns:
an unmodifiable list of Source types registered on this transformer

getSourceDataTypes

public List<DataType<?>> getSourceDataTypes()
Description copied from interface: Transformer
Returns an unmodifiable list of Source types registered on this transformer

Specified by:
getSourceDataTypes in interface Transformer
Returns:
an unmodifiable list of Source types registered on this transformer

isAcceptNull

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

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

isIgnoreBadInput

public boolean isIgnoreBadInput()
Description copied from interface: Transformer
By default, Mule will throw an exception if a transformer is invoked with a source object that is not compatible with the transformer. Since transformers are often chained, it is useful to be able to ignore a transformer in the chain and move to the next one.

Specified by:
isIgnoreBadInput in interface Transformer
Returns:
true if the transformer can be ignored if the current source type is not supported, false if an exception should be throw due to an incompatible source type being passed in.

transform

public Object transform(Object src)
                 throws TransformerException
Description copied from interface: Transformer
Transforms the supplied data and returns the result

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

transform

public Object transform(Object src,
                        String encoding)
                 throws TransformerException
Description copied from interface: Transformer
Transforms the supplied data and returns the result

Specified by:
transform in interface Transformer
Parameters:
src - the data to transform
encoding - 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 encoding
Returns:
the transformed data
Throws:
TransformerException - if a error occurs transforming the data or if the expected returnClass isn't the same as the transformed data

setReturnClass

public void setReturnClass(Class<?> theClass)
Description copied from interface: Transformer
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 Transformer
Parameters:
theClass - the expected return type class

getReturnClass

public Class<?> getReturnClass()
Description copied from interface: Transformer
Specifies the Java type of the result after this transformer has been executed. Mule will use this to validate the return type but also allow users to perform automatic transformations based on the source type of the object to transform and this return type.

Specified by:
getReturnClass in interface Transformer
Returns:
the excepted return type from this transformer

setReturnDataType

public void setReturnDataType(DataType<?> type)
Description copied from interface: Transformer
Sets the expected return type for the transformed data. If the transformed data is not of this class type a TransformerException will be thrown.

This method supersedes Transformer.getReturnClass() because it allows Generics information to be associated with the return type of the transformer

Specified by:
setReturnDataType in interface Transformer
Parameters:
type - the expected return type for this transformer

getReturnDataType

public DataType<?> getReturnDataType()
Description copied from interface: Transformer
Specifies the return type of the result after this transformer has been executed. Mule will use this to validate the return type but also allow users to perform automatic transformations based on the source type of the object to transform and this return type.

This method supersedes Transformer.getReturnClass() because it allows Generics information to be associated with the return type of the transformer

Specified by:
getReturnDataType in interface Transformer
Returns:
the excepted return type for this transformer

getMimeType

public String getMimeType()
Description copied from interface: Transformer
Return the mime type returned by the transformer (if any).

Specified by:
getMimeType in interface Transformer

getEncoding

public String getEncoding()
Description copied from interface: Transformer
Return the encoding returned by the transformer (if any).

Specified by:
getEncoding in interface Transformer

getEndpoint

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

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

dispose

public void dispose()
Description copied from interface: Disposable
A lifecycle method where implementor should free up any resources. If an exception is thrown it should just be logged and processing should continue. This method should not throw Runtime exceptions.

Specified by:
dispose in interface Disposable

setEndpoint

public void setEndpoint(ImmutableEndpoint ep)
Specified by:
setEndpoint in interface EndpointAware

initialise

public void initialise()
                throws InitialisationException
Description copied from interface: Initialisable
Method used to perform any initialisation work. If a fatal error occurs during initialisation an InitialisationException should be thrown, causing the Mule instance to shutdown. If the error is recoverable, say by retrying to connect, a RecoverableException should be thrown. There is no guarantee that by throwing a Recoverable exception that the Mule instance will not shut down.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException - if a fatal error occurs causing the Mule instance to shutdown
RecoverableException - if an error occurs that can be recovered from

process

public MuleEvent process(MuleEvent event)
                  throws MuleException
Description copied from interface: MessageProcessor
Invokes the MessageProcessor.

Specified by:
process in interface MessageProcessor
Parameters:
event - MuleEvent to be processed
Returns:
optional response MuleEvent
Throws:
MuleException

setMuleContext

public void setMuleContext(MuleContext context)
Specified by:
setMuleContext in interface MuleContextAware

setName

public void setName(String name)
Description copied from interface: NameableObject
Sets the name of the object

Specified by:
setName in interface NameableObject
Parameters:
name - the name of the object

getName

public String getName()
Description copied from interface: NamedObject
Gets the name of the object

Specified by:
getName in interface NamedObject
Returns:
the name of the object

getPriorityWeighting

public int getPriorityWeighting()
Description copied from interface: Converter
If two or more discoverable transformers are equal, this value can be used to select the correct one

Specified by:
getPriorityWeighting in interface Converter
Returns:
the priority weighting for this transformer. This is a value between Converter.MIN_PRIORITY_WEIGHTING and Converter.MAX_PRIORITY_WEIGHTING.

setPriorityWeighting

public void setPriorityWeighting(int weighting)
Description copied from interface: Converter
If 2 or more discoverable transformers are equal, this value can be used to select the correct one

Specified by:
setPriorityWeighting in interface Converter
Parameters:
weighting - the priority weighting for this transformer. This is a value between Converter.MIN_PRIORITY_WEIGHTING and Converter.MAX_PRIORITY_WEIGHTING.

getConverters

public LinkedList<Converter> getConverters()


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.