Class XPathTransformer

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, InitializingBean, ApplicationContextAware, ExpressionCapable, NamedComponent, GenericTransformer<Message<?>,Message<?>>, Transformer

public class XPathTransformer extends AbstractTransformer
Transformer implementation that evaluates an XPath expression against the inbound Message payload and returns a Message whose payload is the result of that evaluation. Prior to evaluation, the payload may be converted by the configured XmlPayloadConverter instance. The default converter type is DefaultXmlPayloadConverter.

The evaluation result type will depend on either the enumeration value provided to setEvaluationType(XPathEvaluationType) or the presence of a NodeMapper, which takes precedence. If no NodeMapper or evaluation type is configured explicitly, the default evaluation type is XPathEvaluationType.STRING_RESULT.

Since:
2.0
Author:
Mark Fisher
  • Constructor Details

    • XPathTransformer

      public XPathTransformer(String expression)
      Create an XPathTransformer that will create an XPath expression from the given String to be evaluated against converted inbound Message payloads.
      Parameters:
      expression - The expression.
    • XPathTransformer

      public XPathTransformer(XPathExpression expression)
      Create an XPathTransformer that will evaluate the given XPathExpression against converted inbound Message payloads.
      Parameters:
      expression - The expression.
  • Method Details

    • setEvaluationType

      public void setEvaluationType(XPathEvaluationType evaluationType)
      Specify the expected XPathEvaluationType. The default is XPathEvaluationType.STRING_RESULT.
      Parameters:
      evaluationType - The evaluation type.
    • setNodeMapper

      public void setNodeMapper(NodeMapper<?> nodeMapper)
      Set a NodeMapper to use for generating the result object. By default the NodeMapper is null, but if explicitly set, type determination is the responsibility of the NodeMapper, taking precedence over any configured evaluationType.
      Parameters:
      nodeMapper - The node mapper.
    • setConverter

      public void setConverter(XmlPayloadConverter converter)
      Specify the XmlPayloadConverter to use when converting a Message payload prior to XPath evaluation.
      Parameters:
      converter - The payload converter.
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class IntegrationObjectSupport
    • doTransform

      protected Object doTransform(Message<?> message)
      Description copied from class: AbstractTransformer
      Subclasses must implement this method to provide the transformation logic. If the return value is itself a Message, it will be used as the result. Otherwise, any non-null return value will be used as the payload of the result Message.
      Specified by:
      doTransform in class AbstractTransformer
      Parameters:
      message - The message.
      Returns:
      The result of the transformation.