Class ThreadSafeXsltConverter<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 ThreadSafeXsltConverter<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 a Thread Safe 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 threadsafe! It create a converter per thread.It also 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 XsltConverter.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 XsltConverter.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

      • ThreadSafeXsltConverter

        public ThreadSafeXsltConverter​(javax.xml.transform.TransformerFactory transformerFactory)
        Constructor
        Parameters:
        transformerFactory -
    • Method Detail

      • convert

        public TARGET convert​(SOURCE s)
                       throws org.ikasan.spec.component.transformation.TransformationException
        Specified by:
        convert in interface org.ikasan.spec.component.transformation.Converter<SOURCE,​TARGET>
        Throws:
        org.ikasan.spec.component.transformation.TransformationException
      • 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>
      • getConfiguration

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

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

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

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

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

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

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

        public java.util.Map<java.lang.String,​java.lang.String> getTransformationParameters()
      • setTransformationParameters

        public void setTransformationParameters​(java.util.Map<java.lang.String,​java.lang.String> transformationParameters)
      • getXmlReader

        public org.xml.sax.XMLReader getXmlReader()
      • setXmlReader

        public void setXmlReader​(org.xml.sax.XMLReader xmlReader)
      • getErrorListener

        public javax.xml.transform.ErrorListener getErrorListener()
      • setErrorListener

        public void setErrorListener​(javax.xml.transform.ErrorListener errorListener)
      • getURIResolver

        public javax.xml.transform.URIResolver getURIResolver()
      • setURIResolver

        public void setURIResolver​(javax.xml.transform.URIResolver uriResolver)
      • getConfigurationParameterConverter

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

        public void setConfigurationParameterConverter​(org.ikasan.spec.component.transformation.Converter<XsltConverterConfiguration,​java.util.Map<java.lang.String,​java.lang.String>> configurationParameterConverter)
      • 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)
      • setXmlExtractor

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

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