org.ikasan.framework.component.transformation
Class XsltTransformer

java.lang.Object
  extended by org.ikasan.framework.component.transformation.XsltTransformer
All Implemented Interfaces:
Transformer, ConfiguredResource<XsltConfiguration>, FlowComponent, ManagedResource

public class XsltTransformer
extends Object
implements Transformer, ManagedResource, ConfiguredResource<XsltConfiguration>

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. It is intended to be threadsafe with respect to the underlying 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 Setter 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...

Author:
Ikasan Development Team
See Also:
ClasspathURIResolver, XsltConfiguration, ExceptionThrowingErrorListener

Constructor Summary
XsltTransformer(TransformerFactory transformerFactory)
          Constructor
 
Method Summary
 XsltConfiguration getConfiguration()
          Set configuration.
 String getConfiguredResourceId()
          Get the id for this configured resource
 ErrorListener getErrorListener()
          Accessor
 Map<String,Object> getExternalResources()
          Accessor
 String getPayloadName()
          Accessor
 Map<String,String> getTransformationParameters()
          Accessor
 XMLReader getXmlReader()
          Accessor
 void onEvent(Event event)
          Transforms or otherwise changes the passed in Event
 void setConfiguration(XsltConfiguration configuration)
          Set configuration.
 void setConfiguredResourceId(String id)
          Set the id for this configured resource
 void setErrorListener(ErrorListener errorListener)
          Mutator
 void setExternalResources(Map<String,Object> externalResources)
          Mutator
 void setPayloadName(String payloadName)
          Mutator for payloadName
protected  void setPayloadParameters(Transformer transformer)
          Creates a parameter list of known fields derived from the Payload and makes these available to the transformer
 void setTransformationParameters(Map<String,String> transformationParameters)
          Mutator
 void setURIResolver(URIResolver resolver)
          Override the default URIResolver provided by transformer library.
 void setXmlReader(XMLReader xmlReader)
          Mutator
 void startManagedResource()
          Provision for starting a managed resource.
 void stopManagedResource()
          Provision for stopping a managed resource.
protected  void transform(Payload payload)
          Transforms the payload content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XsltTransformer

public XsltTransformer(TransformerFactory transformerFactory)
Constructor

Parameters:
transformerFactory - - Transformer Factory to use
Method Detail

getPayloadName

public String getPayloadName()
Accessor

Returns:
payloadName or null if it has not been set

setPayloadName

public void setPayloadName(String payloadName)
Mutator for payloadName

Parameters:
payloadName - - The payload name to set

setURIResolver

public void setURIResolver(URIResolver resolver)
Override the default URIResolver provided by transformer library.

Parameters:
resolver - custom URIResolver implementation

getXmlReader

public XMLReader getXmlReader()
Accessor

Returns:
the xmlReader

setXmlReader

public void setXmlReader(XMLReader xmlReader)
Mutator

Parameters:
xmlReader - the xmlReader to set

getTransformationParameters

public Map<String,String> getTransformationParameters()
Accessor

Returns:
the transformationParameters

setTransformationParameters

public void setTransformationParameters(Map<String,String> transformationParameters)
Mutator

Parameters:
transformationParameters - the transformationParameters to set

getExternalResources

public Map<String,Object> getExternalResources()
Accessor

Returns:
the externalDataBeans

setExternalResources

public void setExternalResources(Map<String,Object> externalResources)
Mutator

Parameters:
externalResources - the externalDataBeans to set

getErrorListener

public ErrorListener getErrorListener()
Accessor

Returns:
the errorListener

setErrorListener

public void setErrorListener(ErrorListener errorListener)
Mutator

Parameters:
errorListener - the errorListener to set

getConfiguredResourceId

public String getConfiguredResourceId()
Description copied from interface: ConfiguredResource
Get the id for this configured resource

Specified by:
getConfiguredResourceId in interface ConfiguredResource<XsltConfiguration>
Returns:

setConfiguredResourceId

public void setConfiguredResourceId(String id)
Description copied from interface: ConfiguredResource
Set the id for this configured resource

Specified by:
setConfiguredResourceId in interface ConfiguredResource<XsltConfiguration>

getConfiguration

public XsltConfiguration getConfiguration()
Description copied from interface: ConfiguredResource
Set configuration.

Specified by:
getConfiguration in interface ConfiguredResource<XsltConfiguration>

setConfiguration

public void setConfiguration(XsltConfiguration configuration)
Description copied from interface: ConfiguredResource
Set configuration.

Specified by:
setConfiguration in interface ConfiguredResource<XsltConfiguration>

onEvent

public void onEvent(Event event)
             throws TransformationException
Description copied from interface: Transformer
Transforms or otherwise changes the passed in Event

Specified by:
onEvent in interface Transformer
Parameters:
event - Event to transform
Throws:
TransformationException - Exception if we could not transform

setPayloadParameters

protected void setPayloadParameters(Transformer transformer)
Creates a parameter list of known fields derived from the Payload and makes these available to the transformer

Parameters:
transformer - - Transformer to set the parameters on

transform

protected void transform(Payload payload)
                  throws TransformerException
Transforms the payload content.

Parameters:
payload - The payload to be transformed
Throws:
TransformerException - if an error occurs while transforming.

startManagedResource

public void startManagedResource()
Description copied from interface: ManagedResource
Provision for starting a managed resource.

Specified by:
startManagedResource in interface ManagedResource

stopManagedResource

public void stopManagedResource()
Description copied from interface: ManagedResource
Provision for stopping a managed resource.

Specified by:
stopManagedResource in interface ManagedResource


Copyright © 2007-2012 Ikasan. All Rights Reserved.