Class Transformer

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

public abstract class Transformer extends ServiceSupport implements CamelContextAware
Transformer performs message transformation according to the declared data type. org.apache.camel.processor.ContractAdvice looks for a required Transformer and apply if input/output type declared on a route is different from current message type.
  • Constructor Details

    • Transformer

      public Transformer()
    • Transformer

      public 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 String getName()
      Get the transformer name that represents the supported data type model.
      Returns:
    • getFrom

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

      public 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.
      Parameters:
      name - the transformer name
    • setName

      public Transformer setName(String scheme, 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(String from)
      Set 'from' data type.
      Parameters:
      from - 'from' data type
    • setTo

      public Transformer setTo(String to)
      Set 'to' data type.
      Parameters:
      to - 'to' data type
    • getCamelContext

      public 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
    • doStart

      protected void doStart() throws Exception
      Description copied from class: BaseService
      Implementations override this method to support customized start/stop.

      Important: See BaseService.doStop() for more details.

      Overrides:
      doStart in class BaseService
      Throws:
      Exception
      See Also:
    • doStop

      protected void doStop() throws Exception
      Description copied from class: BaseService
      Implementations override this method to support customized start/stop.

      Important: Camel will invoke this BaseService.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

      Overrides:
      doStop in class BaseService
      Throws:
      Exception
      See Also: