de.ispsoft.jaxme.jaxb
Class MarshallerImpl

java.lang.Object
  extended byde.ispsoft.jaxme.jaxb.JMManagerFactoryAttachable
      extended byde.ispsoft.jaxme.jaxb.MarshallerImpl
All Implemented Interfaces:
java.lang.Cloneable, Marshaller, java.io.Serializable

public class MarshallerImpl
extends JMManagerFactoryAttachable
implements java.lang.Cloneable, java.io.Serializable, Marshaller

The Marshaller is JaxMe's implementation of the javax.xml.marshal.Marshaller interface. In other words, a Marshaller can write an instance of JMAnyElement to a Writer or a SAX ContentHandler.

JaxMe's Marshallers are built around the concept of an underlying ResourceBundle. Inimport java.util.ResourceBundle; other words, the ResourceBundle specifies JaxMe's behaviour of how an XML document is formatted. The Marshallers setProperty() and getProperty() calls are more or less directly mapped to similar calls of the underlying Resou /**

The Marshaller is JaxMe's implementation of the javax.xml.marshal.Marshaller interface. In other words, a Marshaller can write an instance of JMAnyElement to a Writer or a SAX ContentHandler.

JaxMe's Marshallers are built around the concept of an underlying ResourceBundle. In other words, the ResourceBundle specifies JaxMe's behaviour of how an XML document is formatted. The Marshallers setProperty() and getProperty() calls are more or less directly mapped to similar calls of the underlying ResourceBundle.

The following table lists the properties that are recognized by JaxMe.

Name Type Bean Property Description
jaxb.encoding String Encoding The encoding to choose when serializing into an OutputStream. Defaults to UTF-8, as specified by JAXB.
jaxb.formatted.output Boolean Indentation Whether generated XML documents should be human readable or not. Defaults to true, as specified by JAXB.
jaxme.empty.element.style Integer EmptyElementStyle How to format empty elements. Supported values are
  • new Integer(EMPTY_ELEMENT_STYLE_XML) XML style, as in
    <empty/>
  • new Integer(EMPTY_ELEMENT_STYLE_HTML) HTML style, as in
    <empty></empty>
The default is XML style.
jaxme.format.date java.text.DateFormat DateFormat A format being used to serialize xs:date elements. Defaults to new SimpleDateFormat("yyyy-MM-dd").
jaxme.format.datetime java.text.DateFormat DateTimeFormat A format being used to serialize xs:datetime elements. Defaults to new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").
jaxme.format.time java.text.DateFormat TimeFormat A format being used to serialize xs:time elements. Defaults to new SimpleDateFormat("yyyy-MM-dd").
jaxme.formatted.output.level Integer IndentationLevel Number of blanks to indent a new element, if indentation is turned on (property jaxb.formatted.output). The default is 2.
jaxme.formatted.output.separator String IndentationLineSeparator Line separator to use for new elements, if indentation is turned on (property jaxb.formatted.output). The default is a single line feed ("\n"). Windows users might prefer an additional carriage return before the line feed ("\r\n").
jaxme.declaration Boolean Declaration
DefaultDeclaration
Whether generated XML documents should have a preceeding XML declaration.
jaxme.locale java.util.Locale The Locale to use for formatting values, defaults to java.util.Locale.getDefault().
jaxme.resourcebundle java.util.ResourceBundle The ResourceBundle to use for looking up keys.
jaxme.startDocument Boolean Whether marshal(Object, ContentHandler) should emit startDocument() and endDocument() events or not. Defaults to true.
jaxme.private.* Object All properties whose names start with jaxme.private. are simply stored or fetched. JaxMe doesn't interpret them, they are mainly usefull, if you have added own code to the marshalling process.

Version:
$Id: MarshallerImpl.java,v 1.8 2003/01/10 02:38:59 joe Exp $
Author:
Jochen Wiedmann
See Also:
Serialized Form

Field Summary
static int BUILTIN_INDENTATION_LEVEL
          Builtin default indentation level (2 blanks).
static java.lang.String BUILTIN_INDENTATION_LINE_SEPARATOR
          Builtin default line terminator (Line Feed, no Carriage Return).
static int EMPTY_ELEMENT_STYLE_HTML
          A constant for formatting empty elements like this: <empty></empty> The builtin default is EMPTY_ELEMENT_STYLE_XML.
static int EMPTY_ELEMENT_STYLE_XML
          A constant for formatting empty elements like this: <empty&> This is the builtin default.
 
Fields inherited from class de.ispsoft.jaxme.jaxb.JMManagerFactoryAttachable
BUILTIN_DATE_FORMAT, BUILTIN_DATETIME_FORMAT, BUILTIN_ENCODING, BUILTIN_TIME_FORMAT
 
Constructor Summary
MarshallerImpl()
          Creates a new instance of MarshallerImpl.
 
Method Summary
 boolean getDeclaration()
          Returns whether an XML declaration should be generated or not.
 int getEmptyElementStyle()
          Returns the Marshallers style for formatting empty elements.
 boolean getIndentation()
          Returns the default for using indentation.
 int getIndentationLevel()
          Return the default indentation level.
 java.lang.String getIndentationLineSeparator()
          Returns the default line separator for indentation.
 java.lang.Object getProperty(java.lang.String pName)
          Returns the value of the given property.
 boolean getStartDocument()
          Returns whether marshal(Object, ContentHandler) should emit startDocument() and endDocument() events.
 void marshal(java.lang.Object pObj, org.xml.sax.ContentHandler pHandler)
          Marshal the content tree rooted at obj into SAX2 events.
 void marshal(java.lang.Object pObj, java.io.File pFile)
           
 void marshal(java.lang.Object pObj, org.w3c.dom.Node pNode)
          Marshal the content tree rooted at obj into a DOM tree.
 void marshal(java.lang.Object pObj, java.io.OutputStream pStream)
          Marshal the content tree rooted at obj into an output stream.
 void marshal(java.lang.Object pObj, javax.xml.transform.Result pResult)
          Marshal the content tree rooted at obj into the specified javax.xml.transform.Result.
 void marshal(java.lang.Object pObj, java.io.Writer pWriter)
          Marshal the content tree rooted at obj into a Writer.
 void setDeclaration(boolean pDeclaration)
          Sets whether an XML declaration should be generated or not.
 void setEmptyElementStyle(int pStyle)
          Sets the Marshallers style for formatting empty elements.
 void setIndentation(boolean pIndentation)
          Sets the default for using indentation.
 void setIndentationLevel(int pLevel)
          Sets the default indentation level.
 void setIndentationLineSeparator(java.lang.String pSeparator)
          Sets the default line separator for indentation.
 void setProperty(java.lang.String pName, java.lang.Object pValue)
          Sets the value of the given property.
 void setStartDocument(boolean pStartDocument)
          Sets whether marshal(Object, ContentHandler) should emit startDocument() and endDocument() events.
 
Methods inherited from class de.ispsoft.jaxme.jaxb.JMManagerFactoryAttachable
getDateFormat, getDateFormat, getDateFormatForPattern, getDateTimeFormat, getDateTimeFormat, getEncoding, getFactory, getLocale, getMessageFormat, getNumberFormat, getPrivateProperty, getResourceBundle, getResourceValue, getTimeFormat, getTimeFormat, setDateFormat, setDateTimeFormat, setEncoding, setFactory, setLocale, setPrivateProperty, setResourceBundle, setTimeFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.ispsoft.jaxme.jaxb.Marshaller
getEncoding, setEncoding
 

Field Detail

EMPTY_ELEMENT_STYLE_XML

public static final int EMPTY_ELEMENT_STYLE_XML

A constant for formatting empty elements like this:

   <empty&>
 
This is the builtin default.

See Also:
setEmptyElementStyle(int), EMPTY_ELEMENT_STYLE_HTML, Constant Field Values

EMPTY_ELEMENT_STYLE_HTML

public static final int EMPTY_ELEMENT_STYLE_HTML

A constant for formatting empty elements like this:

   <empty></empty>
 
The builtin default is EMPTY_ELEMENT_STYLE_XML.

See Also:
setEmptyElementStyle(int), EMPTY_ELEMENT_STYLE_XML, Constant Field Values

BUILTIN_INDENTATION_LEVEL

public static final int BUILTIN_INDENTATION_LEVEL

Builtin default indentation level (2 blanks). Ignored, if indentation is disabled.

See Also:
setIndentationLevel(int), Constant Field Values

BUILTIN_INDENTATION_LINE_SEPARATOR

public static final java.lang.String BUILTIN_INDENTATION_LINE_SEPARATOR

Builtin default line terminator (Line Feed, no Carriage Return). Ignored, if indentation is disabled.

See Also:
setIndentationLineSeparator(java.lang.String), Constant Field Values
Constructor Detail

MarshallerImpl

public MarshallerImpl()

Creates a new instance of MarshallerImpl.

Method Detail

setEmptyElementStyle

public void setEmptyElementStyle(int pStyle)

Sets the Marshallers style for formatting empty elements. Defaults to getDefaultEmptyElementStyle(). Can also be set with setProperty("jaxme.empty.element.style", new Integer(EMPTY_ELEMENT_STYLE_XML)).

See Also:
EMPTY_ELEMENT_STYLE_XML

getEmptyElementStyle

public int getEmptyElementStyle()

Returns the Marshallers style for formatting empty elements. Defaults to getDefaultEmptyElementStyle(). Can also be set with setProperty("jaxme.empty.element.style").

See Also:
EMPTY_ELEMENT_STYLE_XML

setIndentation

public void setIndentation(boolean pIndentation)

Sets the default for using indentation. The default is true, according to the JAXB specification. Can also be set with setProperty("jaxb.formatted.output", Boolean.TRUE).


getIndentation

public boolean getIndentation()

Returns the default for using indentation. The default is true, according to the JAXB specification. Can also be fetched with getProperty("jaxb.formatted.output").


setIndentationLevel

public void setIndentationLevel(int pLevel)

Sets the default indentation level. Defaults to BUILTIN_INDENTATION_LEVEL. Ignored, if indentation is disabled. By default indentation is on, due to the JAXB specification. Can also be set with setProperty("jaxme.formatted.output.level", new Integer(pLevel)).

See Also:
getIndentationLevel(), BUILTIN_INDENTATION_LEVEL

getIndentationLevel

public int getIndentationLevel()

Return the default indentation level. Defaults to BUILTIN_INDENTATION_LEVEL. Ignored, if indentation is disabled. By default indentation is on, due to the JAXB specification. Can also be fetched with getProperty("jaxme.formatted.output.level").

See Also:
setIndentationLevel(int), BUILTIN_INDENTATION_LEVEL

setIndentationLineSeparator

public void setIndentationLineSeparator(java.lang.String pSeparator)

Sets the default line separator for indentation. Defaults to BUILTIN_INDENTATION_LINE_SEPARATOR. Ignored, if indentation is disabled. Can also be set with setProperty("jaxme.formatted.output.separator", pSeparator).

See Also:
BUILTIN_INDENTATION_LINE_SEPARATOR, getIndentationLineSeparator(), JMManagerFactoryAttachable.setResourceBundle(java.util.ResourceBundle)

getIndentationLineSeparator

public java.lang.String getIndentationLineSeparator()

Returns the default line separator for indentation. Defaults to getDefaultIndentationLineSeparator(). Ignored, if indentation is disabled. Can also be fetched with getProperty("jaxme.formatted.output.separator").

See Also:
BUILTIN_INDENTATION_LINE_SEPARATOR, setIndentationLineSeparator(java.lang.String), JMManagerFactoryAttachable.getResourceBundle()

setDeclaration

public void setDeclaration(boolean pDeclaration)

Sets whether an XML declaration should be generated or not. Can also be set with setProperty("jaxme.declaration", new Boolean(pDeclaration)).

See Also:
getDeclaration()

getDeclaration

public boolean getDeclaration()

Returns whether an XML declaration should be generated or not. Can also be fetched with getProperty("jaxme.declaration").

See Also:
setDeclaration(boolean)

setStartDocument

public void setStartDocument(boolean pStartDocument)

Sets whether marshal(Object, ContentHandler) should emit startDocument() and endDocument() events. Can also be set with setProperty("jaxme.startDocument", new Boolean(pSuppressStartDocument)). Defaults to false.


getStartDocument

public boolean getStartDocument()

Returns whether marshal(Object, ContentHandler) should emit startDocument() and endDocument() events. Can also be fetched with getProperty("jaxme.startDocument"). Defaults to false.


getProperty

public java.lang.Object getProperty(java.lang.String pName)
                             throws JAXBException,
                                    UnrecognizedPropertyException,
                                    UnsupportedPropertyException

Returns the value of the given property.

Specified by:
getProperty in interface Marshaller
Overrides:
getProperty in class JMManagerFactoryAttachable
Throws:
JAXBException
UnrecognizedPropertyException
UnsupportedPropertyException

setProperty

public void setProperty(java.lang.String pName,
                        java.lang.Object pValue)
                 throws JAXBException,
                        UnrecognizedPropertyException,
                        UnsupportedPropertyException

Sets the value of the given property.

Specified by:
setProperty in interface Marshaller
Overrides:
setProperty in class JMManagerFactoryAttachable
Throws:
JAXBException
UnrecognizedPropertyException
UnsupportedPropertyException

marshal

public void marshal(java.lang.Object pObj,
                    org.xml.sax.ContentHandler pHandler)
             throws JAXBException
Description copied from interface: Marshaller
Marshal the content tree rooted at obj into SAX2 events.

Specified by:
marshal in interface Marshaller
Parameters:
pObj - The content tree to be marshalled.
pHandler - XML will be sent to this handler as SAX2 events.
Throws:
JAXBException - If any unexpected problem occurs during the marshalling.

marshal

public void marshal(java.lang.Object pObj,
                    java.io.Writer pWriter)
             throws JAXBException
Description copied from interface: Marshaller
Marshal the content tree rooted at obj into a Writer.

Specified by:
marshal in interface Marshaller
Parameters:
pObj - The content tree to be marshalled.
pWriter - XML will be sent to this writer.
Throws:
JAXBException - If any unexpected problem occurs during the marshalling.

marshal

public void marshal(java.lang.Object pObj,
                    javax.xml.transform.Result pResult)
             throws JAXBException
Description copied from interface: Marshaller
Marshal the content tree rooted at obj into the specified javax.xml.transform.Result.

All JAXB Providers must at least support DOMResult, SAXResult, and StreamResult. It can support other derived classes of Result as well.

Specified by:
marshal in interface Marshaller
Parameters:
pObj - The content tree to be marshalled.
pResult - XML will be sent to this Result
Throws:
JAXBException - If any unexpected problem occurs during the marshalling.

marshal

public void marshal(java.lang.Object pObj,
                    java.io.OutputStream pStream)
             throws JAXBException
Description copied from interface: Marshaller
Marshal the content tree rooted at obj into an output stream.

Specified by:
marshal in interface Marshaller
Parameters:
pObj - The content tree to be marshalled.
pStream - XML will be added to this stream.
Throws:
JAXBException - If any unexpected problem occurs during the marshalling.

marshal

public void marshal(java.lang.Object pObj,
                    java.io.File pFile)
             throws JAXBException
Throws:
JAXBException

marshal

public void marshal(java.lang.Object pObj,
                    org.w3c.dom.Node pNode)
             throws JAXBException
Description copied from interface: Marshaller
Marshal the content tree rooted at obj into a DOM tree.

Specified by:
marshal in interface Marshaller
Parameters:
pObj - The content tree to be marshalled.
pNode - DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (Document, DocumentFragment, or Element)
Throws:
JAXBException - If any unexpected problem occurs during the marshalling.