Class Transformer

All Implemented Interfaces:
AutoCloseable, CamelContextAware, Service, ShutdownableService, HasCamelContext, StatefulService, SuspendableService

public abstract class Transformer extends ServiceSupport implements CamelContextAware
Performs message body transformation between two DataTypes as part of Camel's Transformer contract mechanism.

When a route declares an inputType or outputType, Camel's

invalid reference
org.apache.camel.processor.ContractAdvice
inspects the current message's DataType and looks up a matching Transformer in the TransformerRegistry. If the current type differs from the declared type, the transformer's transform(org.apache.camel.Message, DataType, DataType) method is called automatically, without requiring the route developer to add an explicit conversion step.

Transformers can be registered by annotating a subclass with DataTypeTransformer (the annotation drives automatic registration) or manually via CamelContext.getTransformerRegistry().

See Also:
  • Constructor Details

    • Transformer

      protected Transformer()
    • Transformer

      protected Transformer(String name)
  • Method Details

    • transform

      public abstract void transform(Message message, DataType from, DataType to) throws Exception
      Perform data transformation with specified from/to type.
      Parameters:
      message - message to apply transformation
      from - 'from' data type
      to - 'to' data type
      Throws:
      Exception
    • getName

      public @Nullable String getName()
      Get the transformer name that represents the supported data type model.
    • getFrom

      public @Nullable DataType getFrom()
      Get 'from' data type.
    • getTo

      public @Nullable DataType getTo()
      Get 'to' data type.
    • setName

      public Transformer setName(String name)
      Set the name for this transformer. Usually a combination of scheme and name.
    • setName

      public Transformer setName(@Nullable String scheme, @Nullable String name)
      Set the scheme and/or name for this transformer. When using only a scheme, the transformer applies to all transformations with that scheme.
      Parameters:
      scheme - supported data type scheme
      name - transformer name
    • setFrom

      public Transformer setFrom(@Nullable String from)
      Set 'from' data type.
    • setTo

      public Transformer setTo(@Nullable String to)
      Set 'to' data type.
    • getCamelContext

      public @Nullable CamelContext getCamelContext()
      Description copied from interface: HasCamelContext
      Returns the camel context.
      Specified by:
      getCamelContext in interface HasCamelContext
      Returns:
      the camel context.
    • setCamelContext

      public void setCamelContext(CamelContext context)
      Description copied from interface: CamelContextAware
      Injects the CamelContext
      Specified by:
      setCamelContext in interface CamelContextAware
      Parameters:
      context - the Camel context
    • toString

      public String toString()
      Overrides:
      toString in class Object