net.sf.xbus.protocol.xml
Class XSLTTransformer

java.lang.Object
  extended by net.sf.xbus.protocol.xml.XSLTTransformer
All Implemented Interfaces:
Transformer
Direct Known Subclasses:
RecordTypeTransformer

public class XSLTTransformer
extends java.lang.Object
implements Transformer

This is the base class for all transformation between XMLMessages with XSLT stylesheets.

The transformation is done in two steps:

  1. An XSLT stylesheet which name is read from the configuration does the first part of the transformation.
  2. The so-called XBUS_Stylets are processed to fill in extra data into the XML data.

XBUS_Stylets:

XSLT stylesheets lack the possibilty to fill in data to the transformed XML data which cannot be extracted out of the source XML. To fill this gap some defined tags can be included in the transformed XML when the XSLT transformation is done. These tags are replaced in the second step with defined data. The format for XBUS_Stylets is:

      <XBUS_Stylet Name="xxx" Tag="yyy" Key="zzz">
 
The XSLT code to achieve this looks like:
      <xsl:element name="XBUS_Stylet">
          <xsl:attribute name="Name">xxx</xsl:attribute>
          <xsl:attribute name="Tag">yyy</xsl:attribute>
          <xsl:attribute name="Key">zzz</xsl:attribute>
      </xsl:element>
 
The meaning of the attributes is: The values for the attribute Name are defined as follows: If a transformation between XMLMessages can be done directly via a XSLT stylesheet and XBUS_Stylet processing, this class can be used. When extra code is needed for the transformation, it has to be subclassed.


Field Summary
protected static java.lang.String XSL_LOCATION
           
 
Constructor Summary
XSLTTransformer()
           
 
Method Summary
protected  XMLMessageAbstract createMessage(XBUSSystem destination, XMLMessageAbstract source)
          Creates an object which is suitable for sending data to the given system.
protected  javax.xml.transform.Transformer getXSLTransformer(java.lang.String xslFile)
          Returns a Transformer object needed for the XSLT processing.
 void putStyletValue(java.lang.Object key, java.lang.Object value)
          Stores a key/value pair which is used later in the processing of the XBUS_Stylets.
 java.lang.Object transform(java.lang.Object inObject, XBUSSystem source, XBUSSystem destination, Message destinationMessage)
          The transform method is automatically called by the xBus during the routing of messages.
protected  org.w3c.dom.Document transformXML(org.w3c.dom.Document xmlOld, java.lang.String xslFile, Message message)
          Transforms the given XML-data with the given XSL-stylesheet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XSL_LOCATION

protected static final java.lang.String XSL_LOCATION
Constructor Detail

XSLTTransformer

public XSLTTransformer()
Method Detail

transform

public java.lang.Object transform(java.lang.Object inObject,
                                  XBUSSystem source,
                                  XBUSSystem destination,
                                  Message destinationMessage)
                           throws XException
The transform method is automatically called by the xBus during the routing of messages.

Specified by:
transform in interface Transformer
Parameters:
inObject - either the request or response that shall be transformed to another format
source - the XBUSSystem of the message of the inObject
destination - the XBUSSystem of the target message
destinationMessage - the target message eventually contains more information necessary for transforming
Returns:
the transformed Object, written to either the request or response of the target message
Throws:
XException

putStyletValue

public void putStyletValue(java.lang.Object key,
                           java.lang.Object value)
Stores a key/value pair which is used later in the processing of the XBUS_Stylets.


transformXML

protected org.w3c.dom.Document transformXML(org.w3c.dom.Document xmlOld,
                                            java.lang.String xslFile,
                                            Message message)
                                     throws XException
Transforms the given XML-data with the given XSL-stylesheet. After the XSL-transformation the so-called XBUS_Stylets are processed.

Parameters:
xmlOld - the source XML-data
xslFile - the name of the XSL-stylesheet
message - the destination message
Throws:
XException - if something goes wrong

getXSLTransformer

protected javax.xml.transform.Transformer getXSLTransformer(java.lang.String xslFile)
                                                     throws XException
Returns a Transformer object needed for the XSLT processing. The Transformers are cached for every thread and every XSLT stylesheet.

Throws:
XException

createMessage

protected XMLMessageAbstract createMessage(XBUSSystem destination,
                                           XMLMessageAbstract source)
                                    throws XException
Creates an object which is suitable for sending data to the given system. The name of the class is read in the <@link net.sf.xbus.base.core.Configuration>. The returned class must be a subclass of XMLMessage.

Throws:
XException