Class XsltConverter<SOURCE,​TARGET>

  • All Implemented Interfaces:
    org.ikasan.spec.component.transformation.Converter<SOURCE,​TARGET>, org.ikasan.spec.configuration.Configured<XsltConverterConfiguration>, org.ikasan.spec.configuration.ConfiguredResource<XsltConverterConfiguration>, org.ikasan.spec.management.ManagedResource

    public class XsltConverter<SOURCE,​TARGET>
    extends java.lang.Object
    implements org.ikasan.spec.component.transformation.Converter<SOURCE,​TARGET>, org.ikasan.spec.configuration.ConfiguredResource<XsltConverterConfiguration>, org.ikasan.spec.management.ManagedResource
    /** This class is an XSLT Transformer component that acts on all an Event's Payloads, transforming them using the supplied style sheet. This implementation is notable for the following reasons:
    1. This implementaiton is not threadsafe! It creates a Transformer as a new instance is created for every payload. Each instance of this class will associate to one and only one style sheet during its life, and as such instances will be good for only one type of transformation only.


    2. Is is intended to be capable of transforming non-xml Payloads through the configuration of a content specific XMLReader; e.g. an XMLReader implementation capable of reading fixed length flat files can be setter-injected thus allowing flat file (fixed length) payloads to be directly transformed with XSLT. See setXmlReader(XMLReader)


    3. It is designed to allow a set of externally sourced (injected) java objects to be supplied scoped to the underlying transformer. This allows for such function as database calls from the XSLT to be supported indirectly through the injection of externally managed supporting beans. See setExternalResources(Map)


    4. Rather than relying on the default ErrorListener this transformer supplies its own implementation designed to propagate the exceptions thrown for parse time errors and warnings. This can be overridden by using setErrorListener(ErrorListener)
    5. .

    6. The ability to configure its properties at runtime through implementation of ConfiguredResource contract. The configuration object allows for configuring use of translets (compiling a stylesheet) and the stylesheet's location


    7. Configured stylesheets can either be loaded off of application's classpath, file system, web server ..etc. However, mixing them is not possible.

    Gotchas to be aware of...

    • When loading stylehsheets off of classpath, if the stylesheet tries to embed other stylesheets via xsl:import and/or xsl:include elements, then a custom URIResolver implementation capable of loading resources from classpath must be set on constructor-injected TransformerFactory. Also, if any of stylesheets load files using document()function, the custome URIResolver must also be set on the Transformer object created. This dictated by javax.xml.transform API peculiar design!
    Author:
    Ikasan Development Team
    See Also:
    XsltConverterConfiguration, ExceptionThrowingErrorListener
    • Constructor Detail

      • XsltConverter

        public XsltConverter​(javax.xml.transform.TransformerFactory transformerFactory)
        Constructor
        Parameters:
        transformerFactory - - Transformer Factory to use
    • Method Detail

      • setURIResolver

        public void setURIResolver​(javax.xml.transform.URIResolver resolver)
        Override the default URIResolver provided by transformer library.
        Parameters:
        resolver - custom URIResolver implementation
      • getXmlReader

        public org.xml.sax.XMLReader getXmlReader()
        Accessor
        Returns:
        the xmlReader
      • setXmlReader

        public void setXmlReader​(org.xml.sax.XMLReader xmlReader)
        Mutator
        Parameters:
        xmlReader - the xmlReader to set
      • getTransformationParameters

        public java.util.Map<java.lang.String,​java.lang.String> getTransformationParameters()
        Accessor
        Returns:
        the transformationParameters
      • setTransformationParameters

        public void setTransformationParameters​(java.util.Map<java.lang.String,​java.lang.String> transformationParameters)
        Mutator
        Parameters:
        transformationParameters - the transformationParameters to set
      • setConfiguration

        public void setConfiguration​(XsltConverterConfiguration configuration)
        Specified by:
        setConfiguration in interface org.ikasan.spec.configuration.Configured<SOURCE>
      • convert

        public TARGET convert​(SOURCE source)
                       throws org.ikasan.spec.component.transformation.TransformationException
        Transforms the payload content.
        Specified by:
        convert in interface org.ikasan.spec.component.transformation.Converter<SOURCE,​TARGET>
        Parameters:
        source - The payload to be transformed
        Throws:
        javax.xml.transform.TransformerException - if an error occurs while transforming.
        org.ikasan.spec.component.transformation.TransformationException
      • stopManagedResource

        public void stopManagedResource()
        Specified by:
        stopManagedResource in interface org.ikasan.spec.management.ManagedResource
      • createSourceXml

        protected javax.xml.transform.Source createSourceXml​(java.lang.String xml)
        Extract a payload's content into a XML source
        Parameters:
        xml - a payload whose content is valid xml
        Returns:
        input xml as SAXSource
      • startManagedResource

        public void startManagedResource()
        Specified by:
        startManagedResource in interface org.ikasan.spec.management.ManagedResource
      • getConfiguration

        public XsltConverterConfiguration getConfiguration()
        Specified by:
        getConfiguration in interface org.ikasan.spec.configuration.Configured<SOURCE>
      • getConfiguredResourceId

        public java.lang.String getConfiguredResourceId()
        Specified by:
        getConfiguredResourceId in interface org.ikasan.spec.configuration.ConfiguredResource<SOURCE>
      • setConfiguredResourceId

        public void setConfiguredResourceId​(java.lang.String configuredResourceId)
        Specified by:
        setConfiguredResourceId in interface org.ikasan.spec.configuration.ConfiguredResource<SOURCE>
      • isCriticalOnStartup

        public boolean isCriticalOnStartup()
        Specified by:
        isCriticalOnStartup in interface org.ikasan.spec.management.ManagedResource
      • setCriticalOnStartup

        public void setCriticalOnStartup​(boolean arg0)
        Specified by:
        setCriticalOnStartup in interface org.ikasan.spec.management.ManagedResource
      • setManagedResourceRecoveryManager

        public void setManagedResourceRecoveryManager​(org.ikasan.spec.management.ManagedResourceRecoveryManager arg0)
        Specified by:
        setManagedResourceRecoveryManager in interface org.ikasan.spec.management.ManagedResource
      • setXmlExtractor

        public void setXmlExtractor​(org.ikasan.spec.component.transformation.Converter<java.lang.Object,​java.lang.String> xmlExtractor)
      • getErrorListener

        public javax.xml.transform.ErrorListener getErrorListener()
        Accessor
        Returns:
        the errorListener
      • setErrorListener

        public void setErrorListener​(javax.xml.transform.ErrorListener errorListener)
        Mutator
        Parameters:
        errorListener - the errorListener to set
      • getExternalResources

        public java.util.Map<java.lang.String,​java.lang.Object> getExternalResources()
      • setExternalResources

        public void setExternalResources​(java.util.Map<java.lang.String,​java.lang.Object> externalResources)
      • setParameterExtractor

        public void setParameterExtractor​(org.ikasan.spec.component.transformation.Converter<java.lang.Object,​java.util.Map<java.lang.String,​java.lang.String>> parameterExtractor)
      • setConfigurationParameterConverter

        public void setConfigurationParameterConverter​(org.ikasan.spec.component.transformation.Converter<XsltConverterConfiguration,​java.util.Map<java.lang.String,​java.lang.String>> configurationParameterConverter)