com.codestreet.messageforge
Class ConverterXML

java.lang.Object
  extended bycom.codestreet.messageforge.Converter
      extended bycom.codestreet.messageforge.ConverterXML

public abstract class ConverterXML
extends Converter

Converter class for XML. This class provides the methods for marshalling a RMapMessage to XML and for unmarshalling XML to RMapMessage

Author:
Jawaid Hakim.

Constructor Summary
ConverterXML()
           
 
Method Summary
static void closeStartTag(java.io.Writer writer, boolean newLines)
          Write the close of an open tag to the specified writer.
static void closeTag(java.io.Writer writer, boolean newLines)
          Write the close of an open tag to the specified writer.
static void closeTag(java.io.Writer writer, java.lang.String tag, int indentLevel, java.lang.String indent, boolean newLines)
          Close the close of an open tag to the specified writer.
static java.lang.String getEncoding()
          Gets the output encoding.
static void main(java.lang.String[] args)
           
static int marshal(boolean skipJMSSupported, boolean skipDeclaration, int indentLevel, java.lang.String xmlTag, RMapMessage source, java.io.Writer target)
          Convert a message object to XML and write to specified target writer.
static java.lang.String marshal(boolean skipJMSSupported, RMapMessage source)
          Convert a message object to XML.
static java.lang.String marshal(RMapMessage source)
          Convert a message object to XML.
static void marshal(RMapMessage source, java.io.File target)
          Convert a message object to XML and write to specified File.
static void marshal(RMapMessage source, java.io.OutputStream target)
          Convert a message object to XML and write to specified OutputStream.
static void marshal(RMapMessage source, java.io.Writer target)
          Convert a message object to XML and write to specified target writer.
static void openTag(java.io.Writer writer, java.lang.String tag, int indentLevel, java.lang.String indent)
          Write an open tag to the specified writer.
static void setEncoding(java.lang.String encoding)
          Sets the output encoding.
static void setExpandEmptyElements(boolean expandEmptyElements)
          This will set whether empty elements are expanded from to .
static void setIndent(java.lang.String indent)
          This will set the indent String to use; this is usually a String of empty spaces.
static void setNewlines(boolean newLines)
          This will set whether newlines are printed with the generated XML.
static void setOmitDeclaration(boolean omitDeclaration)
          This will set whether the XML declaration ( ) is written with the XML.
static void setOmitEncoding(boolean omitEncoding)
          This will set whether the XML declaration ( ) includes the encoding of the document.
static void setXmlValidation(boolean validate, java.lang.String[] schemas)
          This will set whether XML validation occurs when parsing.
static RMapMessage unmarshal(org.jdom.Element root)
          Create a message object from specified Element.
static RMapMessage unmarshal(java.io.File source)
          Create a message object from specified File.
static RMapMessage unmarshal(java.io.InputStream source)
          Create a message object from specified InputStream.
static RMapMessage unmarshal(java.io.Reader source)
          Create a message object from specified Reader.
static RMapMessage unmarshal(java.lang.String source)
          Create a message object from XML.
static RMapMessage unmarshal(java.lang.String source, RMapMessage target)
          Create a message object from specified Element.
static RMapMessage unmarshal(java.net.URL source)
          Create a message object from specified URL.
static void writeAttribute(java.io.Writer writer, java.lang.String name, java.lang.String val)
          Write an attribute to the specified writer.
static void writeAttribute(java.io.Writer writer, java.lang.String name0, java.lang.String value0, java.lang.String name1, java.lang.String value1)
          Write up to three attributes to the specified writer.
static void writeDeclaration(java.io.Writer writer)
          Write the XML version/encoding to specified writer.
 
Methods inherited from class com.codestreet.messageforge.Converter
createMsgObject, createMsgObject, dateToDouble, dateToLong, dateToStr, getBeanValidator, getLenient, getVersion, setBeanValidator, setDateFromDouble, setDateFromLong, setDateFromStr, setDefaultFactory, setMaximumFractionDigits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConverterXML

public ConverterXML()
Method Detail

setXmlValidation

public static void setXmlValidation(boolean validate,
                                    java.lang.String[] schemas)
                             throws ConverterException
This will set whether XML validation occurs when parsing.

Parameters:
validate - true if validation will occur, otherwise false.
schemas - Set of XML schemas to use for validation. Each schema must be specified as an URL. For example, http://www.w3.org/2001/12/soap-envelope soap-envelope.xsd.
Throws:
ConverterException

setExpandEmptyElements

public static void setExpandEmptyElements(boolean expandEmptyElements)
This will set whether empty elements are expanded from to .

Parameters:
expandEmptyElements - boolean indicating whether or not empty elements should be expanded.

setIndent

public static void setIndent(java.lang.String indent)
This will set the indent String to use; this is usually a String of empty spaces. If you pass null, or the empty string (""), then no indentation will happen.

Parameters:
indent - String to use for indentation.

setEncoding

public static void setEncoding(java.lang.String encoding)
Sets the output encoding. The name should be an accepted XML encoding.

Parameters:
encoding - the encoding format. Use XML-style names like UTF-8 or ISO-8859-1 or US-ASCII

getEncoding

public static java.lang.String getEncoding()
Gets the output encoding.

See Also:
setEncoding(String)

setOmitDeclaration

public static void setOmitDeclaration(boolean omitDeclaration)
This will set whether the XML declaration ( ) is written with the XML.

Parameters:
omitDeclaration - Flag indicating whether or not the XML declaration should be written.

setOmitEncoding

public static void setOmitEncoding(boolean omitEncoding)
This will set whether the XML declaration ( ) includes the encoding of the document. It is common to omit this in uses such as WML and other wireless device protocols.

Parameters:
omitEncoding - Flag indicating whether or not the XML declaration should indicate the document encoding.

setNewlines

public static void setNewlines(boolean newLines)
This will set whether newlines are printed with the generated XML.

Parameters:
newLines - true indicates new lines should be printed, else new lines are ignored (compacted).

marshal

public static java.lang.String marshal(RMapMessage source)
                                throws ConverterException
Convert a message object to XML.

Parameters:
source - Message object.
Returns:
XML representation of the message object.
Throws:
ConverterException

marshal

public static java.lang.String marshal(boolean skipJMSSupported,
                                       RMapMessage source)
                                throws ConverterException
Convert a message object to XML.

Parameters:
skipJMSSupported - If true then fields that are natively supported by JMS MapMessage are not marshalled.
source - Message object.
Returns:
XML representation of the message object. If none of the fields were marshalled, then null if returned.
Throws:
ConverterException

marshal

public static void marshal(RMapMessage source,
                           java.io.File target)
                    throws ConverterException
Convert a message object to XML and write to specified File.

Parameters:
source - Message object.
target - Target output file.
Throws:
ConverterException

marshal

public static void marshal(RMapMessage source,
                           java.io.OutputStream target)
                    throws ConverterException
Convert a message object to XML and write to specified OutputStream.

Parameters:
source - Message object.
target - Target output stream.
Throws:
ConverterException

marshal

public static void marshal(RMapMessage source,
                           java.io.Writer target)
                    throws ConverterException
Convert a message object to XML and write to specified target writer.

Parameters:
source - Message object.
target - Target writer.
Throws:
ConverterException

marshal

public static int marshal(boolean skipJMSSupported,
                          boolean skipDeclaration,
                          int indentLevel,
                          java.lang.String xmlTag,
                          RMapMessage source,
                          java.io.Writer target)
                   throws ConverterException
Convert a message object to XML and write to specified target writer.

Parameters:
skipJMSSupported - If true then fields that are natively supported by JMS MapMessage are skipped.
skipDeclaration - If true then the XML declaration is not written.
indentLevel - Indentation level.
xmlTag - XML tag for the top level element.
source - Message object.
target - Target writer.
Returns:
Number of fields that were marshalled.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(java.lang.String source)
                             throws ConverterException
Create a message object from XML.

Parameters:
source - Source XML.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(java.io.Reader source)
                             throws ConverterException
Create a message object from specified Reader.

Parameters:
source - Source Reader.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(java.io.InputStream source)
                             throws ConverterException
Create a message object from specified InputStream.

Parameters:
source - Source InputStream.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(java.io.File source)
                             throws ConverterException
Create a message object from specified File.

Parameters:
source - Source File.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(java.net.URL source)
                             throws ConverterException
Create a message object from specified URL.

Parameters:
source - Source URL.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(org.jdom.Element root)
                             throws ConverterException
Create a message object from specified Element.

Parameters:
root - Source Element.
Throws:
ConverterException

unmarshal

public static RMapMessage unmarshal(java.lang.String source,
                                    RMapMessage target)
                             throws ConverterException
Create a message object from specified Element.

Parameters:
source - Source XML.
target - Target message object.
Throws:
ConverterException

openTag

public static final void openTag(java.io.Writer writer,
                                 java.lang.String tag,
                                 int indentLevel,
                                 java.lang.String indent)
                          throws java.io.IOException
Write an open tag to the specified writer. This is used to start a XML element.

Parameters:
writer - Writer.
tag - Tag.
indentLevel - Indentation level.
indent - Indentation.
Throws:
java.io.IOException

closeTag

public static final void closeTag(java.io.Writer writer,
                                  boolean newLines)
                           throws java.io.IOException
Write the close of an open tag to the specified writer. This is used to close a XML element that has no content.

Parameters:
writer - Writer.
newLines - A newline is written if true.
Throws:
java.io.IOException

closeTag

public static final void closeTag(java.io.Writer writer,
                                  java.lang.String tag,
                                  int indentLevel,
                                  java.lang.String indent,
                                  boolean newLines)
                           throws java.io.IOException
Close the close of an open tag to the specified writer. This is used to close a XML element that has content.

Parameters:
writer - Writer.
tag - Tag.
indentLevel - Indentation level.
indent - Indentation.
Throws:
java.io.IOException

closeStartTag

public static final void closeStartTag(java.io.Writer writer,
                                       boolean newLines)
                                throws java.io.IOException
Write the close of an open tag to the specified writer. This is used to close an element that has content.

Parameters:
writer - Writer.
newLines - A newline is written if true.
Throws:
java.io.IOException

writeAttribute

public static final void writeAttribute(java.io.Writer writer,
                                        java.lang.String name0,
                                        java.lang.String value0,
                                        java.lang.String name1,
                                        java.lang.String value1)
                                 throws java.io.IOException
Write up to three attributes to the specified writer. If any attribute name is null then that attribute is skipped.

Parameters:
writer - Writer.
name0 - First attribute name.
value0 - First attribute value.
name1 - Second attribute name.
value1 - Second attribute value.
Throws:
java.io.IOException

writeAttribute

public static final void writeAttribute(java.io.Writer writer,
                                        java.lang.String name,
                                        java.lang.String val)
                                 throws java.io.IOException
Write an attribute to the specified writer.

Parameters:
writer - Writer.
name - Attribute name.
val - Attribute value.
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)

writeDeclaration

public static final void writeDeclaration(java.io.Writer writer)
                                   throws java.io.IOException
Write the XML version/encoding to specified writer.

Parameters:
writer - Writer.
Throws:
java.io.IOException


Copyright © 2003-2006 CodeStreet. All Rights Reserved.