com.reverseXSL.transform
Class Transformer

java.lang.Object
  extended by com.reverseXSL.transform.Transformer

public class Transformer
extends java.lang.Object

Executes message transformations, which may comprise a Parsing step and an XSLT step (or only one of, or none at all = pass-through). The Parsing step takes a non-XML file and generates an XML document according to a Parser DEFinition file. The XSLT step transforms the generated XML document into another XML document, else any kind of text-based document format.

Transformation steps are selected and executed as defined in the Mapping Selection Table.

IMPORTANT NOTE: the free software version ignores the XSLT step. Only the Parsing step, when specified, is performed. In this context, any post-parsing XSL transformation shall be invoked via the java API for XML processing (JAXP)

See Also:
factory methods on the means to set the source of meta data, notably the Mapping Selection Table.

Method Summary
 java.lang.StringBuffer getLog()
          get a printable log of the Transformer activities during the last call to transform(InputStream, OutputStream).
 java.lang.String getName()
          get the name of the Mapping Selection Table entry that has just been used to transform the last message.
 Parser.ExceptionListIterator getParserExceptionListIterator()
          Browse the detail, exception per exception with possible nested causes, of the Parser warnings and errors.
 java.lang.String getParserExceptionListXML()
          Returns an XML document representation of all Parser warnings and errors in sequence.
 int getParserExceptionsCount()
          Whenever transform(InputStream, OutputStream) is invoked, it returns the total count of parser exceptions (below thresholds, otherwise an exception would have been thrown).
 int printableTransform(java.io.InputStream in, java.lang.StringBuffer out)
          A variant of transform(InputStream, OutputStream) that guarantees a nice indentation of XML outputs; neutral operation for other brands.
 void reset()
          Reset the Transformer state and free associated resources.
 void setLocalMessageReferences(java.lang.String id, java.util.Date d)
          Impose a fixed message ID and fixed date as message references.
 void setLocalMessageReferences(java.lang.String base, java.text.DecimalFormat df)
          Defines the message ID from a base string that will be followed by a decimal format.
 java.lang.String toString()
           
 int transform(java.io.InputStream in, java.io.OutputStream out)
          Reads a message from the InputStream (till no more bytes are available) and then transforms it according to Parsing and XSL Transformation steps defined in the Mapping Selection Table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getLog

public java.lang.StringBuffer getLog()
get a printable log of the Transformer activities during the last call to transform(InputStream, OutputStream). Parser warnings are also detailed.

Returns:
textual log in a StringBuffer

getName

public java.lang.String getName()
get the name of the Mapping Selection Table entry that has just been used to transform the last message.

Returns:
name or null, in cased no transformation yet performed or no name attached to the selected mapping table entry.

getParserExceptionListIterator

public Parser.ExceptionListIterator getParserExceptionListIterator()
Browse the detail, exception per exception with possible nested causes, of the Parser warnings and errors.

Returns:
a list iterator extending the standard iterator interface

getParserExceptionListXML

public java.lang.String getParserExceptionListXML()
                                           throws javax.xml.transform.TransformerException,
                                                  javax.xml.parsers.ParserConfigurationException
Returns an XML document representation of all Parser warnings and errors in sequence.

Returns:
an XML document as string, compliant with ParserExceptionList.xsd (see docs)
Throws:
javax.xml.transform.TransformerException - (not about ReverseXSL Transformer) when the JAXP libraries fail to build the XML representation of the Exception List
javax.xml.parsers.ParserConfigurationException - (not about ReverseXSL Parser) when the JAXP libraries fail to build the XML representation of the Exception List

getParserExceptionsCount

public int getParserExceptionsCount()
Whenever transform(InputStream, OutputStream) is invoked, it returns the total count of parser exceptions (below thresholds, otherwise an exception would have been thrown). This method simply 'reminds' about the value returned by the last run.

Returns:
total count of parser exceptions as was returned by the last call to transform(InputStream, OutputStream)

printableTransform

public int printableTransform(java.io.InputStream in,
                              java.lang.StringBuffer out)
                       throws java.io.IOException,
                              TransformerException,
                              ParserException,
                              javax.xml.parsers.ParserConfigurationException,
                              javax.xml.parsers.FactoryConfigurationError,
                              javax.xml.transform.TransformerFactoryConfigurationError,
                              javax.xml.transform.TransformerException
A variant of transform(InputStream, OutputStream) that guarantees a nice indentation of XML outputs; neutral operation for other brands.

This method is only good for printing the output or displaying it. It is NOT recommended to use it in production as only a subset of the XML standard (good for all regular XML uses but...) is supported in the final formatting. Moreover, this operation inflates the output with a hell of extra space characters.

Parameters:
in - reading input message bytes from FileInputStream, ByteArrayInputStream, StringBufferInputStream, other implementations
out - transformed output is now directed to a StringBuffer (printable!)
Returns:
count of Parser errors (still below thresholds, otherwise an exception is thrown)
Throws:
java.io.IOException
ParserException
TransformerException
javax.xml.transform.TransformerException - (XSLT related)
javax.xml.transform.TransformerFactoryConfigurationError - (XSLT related)
javax.xml.parsers.FactoryConfigurationError - (XSLT related)
javax.xml.parsers.ParserConfigurationException - (XSLT related)
See Also:
TransformerFactory.setParserExceptionThresholds(int, int)

reset

public void reset()
Reset the Transformer state and free associated resources. The transformer state is in any cases reset before each invocation of transform().

The internal counter is not reset.


setLocalMessageReferences

public void setLocalMessageReferences(java.lang.String id,
                                      java.util.Date d)
Impose a fixed message ID and fixed date as message references. Will only apply to the next invocation of Tranformer.transform(). The call must be renewed before every transformation with the next message ID value to be of any use.

The message ID and date will appear in Tranformer traces.

Parameters:
id - message ID as string
d - a java Date for reference

setLocalMessageReferences

public void setLocalMessageReferences(java.lang.String base,
                                      java.text.DecimalFormat df)
Defines the message ID from a base string that will be followed by a decimal format. The transformer increments a local counter (per Transformer) with each invocation, starting at 1. Message IDs take the value: base.concat(decimal_format(internal_counter)).

Set once and applies to all subsequent invocations of Tranformer.transform().

The message ID and date will appear in Tranformer traces.

Parameters:
base - String, to be used as unique tag or thread ID per Transformer
df - decimal format, e.g. new DecimalFormat("00000")

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

transform

public int transform(java.io.InputStream in,
                     java.io.OutputStream out)
              throws java.io.IOException,
                     TransformerException,
                     ParserException,
                     javax.xml.parsers.ParserConfigurationException,
                     javax.xml.parsers.FactoryConfigurationError,
                     javax.xml.transform.TransformerFactoryConfigurationError,
                     javax.xml.transform.TransformerException
Reads a message from the InputStream (till no more bytes are available) and then transforms it according to Parsing and XSL Transformation steps defined in the Mapping Selection Table. (Warning: The free software version ignores any XSL Transformation directive.)

The OutputStream receives the transformed data.

Parameters:
in - reading input message bytes from FileInputStream, ByteArrayInputStream, StringBufferInputStream, other implementations
out - writing transformed output bytes to FileOutputStream, ByteArrayOutputStream, PrintStream, other implementations
Returns:
count of Parser errors (still below thresholds, otherwise an exception is thrown)
Throws:
java.io.IOException
ParserException - (ReverseXSL related) thrown when the tolerance thresholds for Parser exceptions set by TransformerFactory.setParserExceptionThresholds(int, int) have been exceeded, else the DEFinition for the relevant message indicated to throw the exception in case of Parsing failures.
TransformerException - (ReverseXSL related) most likely when the meta-data resources cannot be loaded.
javax.xml.transform.TransformerException - (XSLT related)
javax.xml.transform.TransformerFactoryConfigurationError - (XSLT related)
javax.xml.parsers.FactoryConfigurationError - (XSLT related)
javax.xml.parsers.ParserConfigurationException - (XSLT related)
See Also:
TransformerFactory.setParserExceptionThresholds(int, int)