Class XsltConverter<SOURCE,TARGET>
- java.lang.Object
-
- org.ikasan.component.converter.xml.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 anEvent'sPayloads, transforming them using the supplied style sheet. This implementation is notable for the following reasons:- This implementaiton is not threadsafe! It creates a
Transformeras 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. - Is is intended to be capable of transforming non-xml
Payloads through the configuration of a content specificXMLReader; e.g. anXMLReaderimplementation capable of reading fixed length flat files can be setter-injected thus allowing flat file (fixed length) payloads to be directly transformed with XSLT. SeesetXmlReader(XMLReader) - 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) - Rather than relying on the default
ErrorListenerthis transformer supplies its own implementation designed to propagate the exceptions thrown for parse time errors and warnings. This can be overridden by usingsetErrorListener(ErrorListener). - The ability to configure its properties at runtime through implementation of
ConfiguredResourcecontract. The configuration object allows for configuring use of translets (compiling a stylesheet) and the stylesheet's location - 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:importand/orxsl:includeelements, then a customURIResolverimplementation capable of loading resources from classpath must be set on constructor-injectedTransformerFactory. Also, if any of stylesheets load files usingdocument()function, the customeURIResolvermust also be set on theTransformerobject created. This dictated byjavax.xml.transformAPI peculiar design!
- Author:
- Ikasan Development Team
- See Also:
XsltConverterConfiguration,ExceptionThrowingErrorListener
-
-
Constructor Summary
Constructors Constructor Description XsltConverter(javax.xml.transform.TransformerFactory transformerFactory)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TARGETconvert(SOURCE source)Transforms the payload content.protected javax.xml.transform.SourcecreateSourceXml(java.lang.String xml)Extract a payload's content into a XML sourceXsltConverterConfigurationgetConfiguration()java.lang.StringgetConfiguredResourceId()javax.xml.transform.ErrorListenergetErrorListener()Accessorjava.util.Map<java.lang.String,java.lang.Object>getExternalResources()TargetCreator<SOURCE,TARGET>getTargetCreator()java.util.Map<java.lang.String,java.lang.String>getTransformationParameters()Accessororg.xml.sax.XMLReadergetXmlReader()AccessorbooleanisCriticalOnStartup()voidsetConfiguration(XsltConverterConfiguration configuration)voidsetConfigurationParameterConverter(org.ikasan.spec.component.transformation.Converter<XsltConverterConfiguration,java.util.Map<java.lang.String,java.lang.String>> configurationParameterConverter)voidsetConfiguredResourceId(java.lang.String configuredResourceId)voidsetCriticalOnStartup(boolean arg0)voidsetErrorListener(javax.xml.transform.ErrorListener errorListener)MutatorvoidsetExternalResources(java.util.Map<java.lang.String,java.lang.Object> externalResources)voidsetManagedResourceRecoveryManager(org.ikasan.spec.management.ManagedResourceRecoveryManager arg0)voidsetParameterExtractor(org.ikasan.spec.component.transformation.Converter<java.lang.Object,java.util.Map<java.lang.String,java.lang.String>> parameterExtractor)voidsetTargetCreator(TargetCreator<SOURCE,TARGET> targetCreator)voidsetTransformationParameters(java.util.Map<java.lang.String,java.lang.String> transformationParameters)MutatorvoidsetURIResolver(javax.xml.transform.URIResolver resolver)Override the defaultURIResolverprovided by transformer library.voidsetXmlExtractor(org.ikasan.spec.component.transformation.Converter<java.lang.Object,java.lang.String> xmlExtractor)voidsetXmlReader(org.xml.sax.XMLReader xmlReader)MutatorvoidstartManagedResource()voidstopManagedResource()
-
-
-
Method Detail
-
setURIResolver
public void setURIResolver(javax.xml.transform.URIResolver resolver)
Override the defaultURIResolverprovided by transformer library.- Parameters:
resolver- customURIResolverimplementation
-
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:
setConfigurationin interfaceorg.ikasan.spec.configuration.Configured<SOURCE>
-
convert
public TARGET convert(SOURCE source) throws org.ikasan.spec.component.transformation.TransformationException
Transforms the payload content.- Specified by:
convertin interfaceorg.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:
stopManagedResourcein interfaceorg.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:
startManagedResourcein interfaceorg.ikasan.spec.management.ManagedResource
-
getConfiguration
public XsltConverterConfiguration getConfiguration()
- Specified by:
getConfigurationin interfaceorg.ikasan.spec.configuration.Configured<SOURCE>
-
getConfiguredResourceId
public java.lang.String getConfiguredResourceId()
- Specified by:
getConfiguredResourceIdin interfaceorg.ikasan.spec.configuration.ConfiguredResource<SOURCE>
-
setConfiguredResourceId
public void setConfiguredResourceId(java.lang.String configuredResourceId)
- Specified by:
setConfiguredResourceIdin interfaceorg.ikasan.spec.configuration.ConfiguredResource<SOURCE>
-
isCriticalOnStartup
public boolean isCriticalOnStartup()
- Specified by:
isCriticalOnStartupin interfaceorg.ikasan.spec.management.ManagedResource
-
setCriticalOnStartup
public void setCriticalOnStartup(boolean arg0)
- Specified by:
setCriticalOnStartupin interfaceorg.ikasan.spec.management.ManagedResource
-
setManagedResourceRecoveryManager
public void setManagedResourceRecoveryManager(org.ikasan.spec.management.ManagedResourceRecoveryManager arg0)
- Specified by:
setManagedResourceRecoveryManagerin interfaceorg.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)
-
getTargetCreator
public TargetCreator<SOURCE,TARGET> getTargetCreator()
-
setTargetCreator
public void setTargetCreator(TargetCreator<SOURCE,TARGET> targetCreator)
-
setConfigurationParameterConverter
public void setConfigurationParameterConverter(org.ikasan.spec.component.transformation.Converter<XsltConverterConfiguration,java.util.Map<java.lang.String,java.lang.String>> configurationParameterConverter)
-
-