org.apache.ws.jaxme.impl
Class JMMarshallerImpl

java.lang.Object
  extended by org.apache.ws.jaxme.impl.JMControllerImpl
      extended by org.apache.ws.jaxme.impl.JMMarshallerImpl
All Implemented Interfaces:
Marshaller, JMMarshaller

public class JMMarshallerImpl
extends JMControllerImpl
implements JMMarshaller

Version:
$Id: JMMarshallerImpl.java 231712 2004-01-24 22:14:39Z jochen $
Author:
Jochen Wiedmann

Field Summary
static java.lang.String DEFAULT_JAXB_ENCODING
          Default value for Marshaller.JAXB_ENCODING: UTF-8.
static java.lang.String DEFAULT_JAXME_INDENTATION_SEPARATOR
          Default value for JAXME_INDENTATION_SEPARATOR: "\n" (Line Feed)
static java.lang.String DEFAULT_JAXME_INDENTATION_STRING
          Default value for JAXME_INDENTATION_STRING: " " (two blanks)
static java.lang.String JAXME_INDENTATION_SEPARATOR
          Property name for setting the String used as a line separator in the formatted output.
static java.lang.String JAXME_INDENTATION_STRING
          Property name for setting the String used to indent the formatted output by one level: "jaxme.indentation.string".
static java.lang.String JAXME_XML_DECLARATION
          Property name for choosing whether the marshalled output should contain an XML declaration.
static java.lang.String JAXME_XML_WRITER
          Property name for a SAX ContentHandler which is able to marshal a SAX stream into a character stream.
 
Fields inherited from class org.apache.ws.jaxme.impl.JMControllerImpl
eventHandler, JAXME_DATATYPE_CONVERTER, JAXME_FORMAT_DATE, JAXME_FORMAT_DATETIME, JAXME_FORMAT_TIME, JAXME_PRIVATE
 
Fields inherited from interface javax.xml.bind.Marshaller
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION
 
Constructor Summary
JMMarshallerImpl()
           
 
Method Summary
 java.lang.String getEncoding()
          Returns the controllers encoding; to be used in marshalling.
 boolean getIndentation()
          Returns whether XML documents generated by the controller ought to be formatted.
 java.lang.String getIndentationSeparator()
          Returns the string used as a line separator.
 java.lang.String getIndentationString()
          Returns the string used to indent one level.
 org.w3c.dom.Node getNode(java.lang.Object contentTree)
          Returns a DOM view of the given JAXB object.
 java.lang.Object getProperty(java.lang.String pProperty)
          Returns the value of the marshaller property pName.
 boolean getXmlDeclaration()
          Returns whether the methods marshal(Object, Writer) and marshal(Object, OutputStream) ought to emit an XML declaration.
 java.lang.Class getXMLWriterClass()
          Returns the controllers class implementing XMLWriter.
 void marshal(java.lang.Object pObject, org.xml.sax.ContentHandler pHandler)
          Marshals the given JAXB object by emitting SAX events into into the given SAX ContentHandler.
 void marshal(java.lang.Object pObject, org.w3c.dom.Node pNode)
          Marshals the given JAXB object by creating a DOM tree below the given node.
 void marshal(java.lang.Object pObject, java.io.OutputStream pStream)
          Marshals the given JAXB object pObject and serializes it into the byte stream pTarget.
 void marshal(java.lang.Object pObject, javax.xml.transform.Result pResult)
          Marshals the given JAXB object pObject to the Result pTarget.
 void marshal(java.lang.Object pObject, java.io.Writer pWriter)
          Marshals the given JAXB object pObject and serializes it into the character stream pTarget.
 void setEncoding(java.lang.String pEncoding)
          Sets the controllers encoding; to be used in marshalling.
 void setIndentation(boolean pIndentation)
          Sets whether XML documents generated by the controller ought to be formatted.
 void setIndentationSeparator(java.lang.String pStr)
          Sets the string used as a line separator.
 void setIndentationString(java.lang.String pStr)
          Sets the string used to indent one level.
 void setProperty(java.lang.String pProperty, java.lang.Object pValue)
          Sets the marshaller property pName to the value pValue.
 void setXmlDeclaration(boolean pDeclaration)
          Sets whether the methods marshal(Object, Writer) and marshal(Object, OutputStream) ought to emit an XML declaration.
 void setXMLWriterClass(java.lang.Class pClass)
          Sets the controllers class implementing XMLWriter.
 
Methods inherited from class org.apache.ws.jaxme.impl.JMControllerImpl
getDatatypeConverter, getDateFormat, getDateTimeFormat, getEventHandler, getJAXBContextImpl, getTimeFormat, setDatatypeConverter, setDateFormat, setDateTimeFormat, setEventHandler, setJAXBContextImpl, setTimeFormat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.ws.jaxme.JMMarshaller
getDatatypeConverter, getJAXBContextImpl, setJAXBContextImpl
 
Methods inherited from interface javax.xml.bind.Marshaller
getEventHandler, setEventHandler
 

Field Detail

DEFAULT_JAXB_ENCODING

public static final java.lang.String DEFAULT_JAXB_ENCODING

Default value for Marshaller.JAXB_ENCODING: UTF-8.

See Also:
Constant Field Values

DEFAULT_JAXME_INDENTATION_STRING

public static final java.lang.String DEFAULT_JAXME_INDENTATION_STRING

Default value for JAXME_INDENTATION_STRING: " " (two blanks)

See Also:
Constant Field Values

DEFAULT_JAXME_INDENTATION_SEPARATOR

public static final java.lang.String DEFAULT_JAXME_INDENTATION_SEPARATOR

Default value for JAXME_INDENTATION_SEPARATOR: "\n" (Line Feed)

See Also:
Constant Field Values

JAXME_INDENTATION_STRING

public static final java.lang.String JAXME_INDENTATION_STRING

Property name for setting the String used to indent the formatted output by one level: "jaxme.indentation.string". Defaults to DEFAULT_JAXME_INDENTATION_STRING.

See Also:
setIndentationString(java.lang.String), getIndentationString(), Constant Field Values

JAXME_INDENTATION_SEPARATOR

public static final java.lang.String JAXME_INDENTATION_SEPARATOR

Property name for setting the String used as a line separator in the formatted output. "jaxme.indentation.separator"

See Also:
setIndentationSeparator(java.lang.String), getIndentationSeparator(), Constant Field Values

JAXME_XML_DECLARATION

public static final java.lang.String JAXME_XML_DECLARATION

Property name for choosing whether the marshalled output should contain an XML declaration. The methods marshal(Object, OutputStream) and marshal(Object, Writer) recognize requests for XML declarations.

See Also:
setXmlDeclaration(boolean), getXmlDeclaration(), Constant Field Values

JAXME_XML_WRITER

public static final java.lang.String JAXME_XML_WRITER

Property name for a SAX ContentHandler which is able to marshal a SAX stream into a character stream. The property value is an instance of Class implementing XMLWriter.

See Also:
Constant Field Values
Constructor Detail

JMMarshallerImpl

public JMMarshallerImpl()
Method Detail

setEncoding

public void setEncoding(java.lang.String pEncoding)
                 throws PropertyException

Sets the controllers encoding; to be used in marshalling. Defaults to DEFAULT_JAXB_ENCODING.

Parameters:
pEncoding - Suggested encoding or null to restore the default
Throws:
PropertyException

getEncoding

public java.lang.String getEncoding()

Returns the controllers encoding; to be used in marshalling. Defaults to DEFAULT_JAXB_ENCODING.


setXMLWriterClass

public void setXMLWriterClass(java.lang.Class pClass)
                       throws PropertyException

Sets the controllers class implementing XMLWriter. Defaults to XMLWriterImpl.

Parameters:
pClass - A class implementing XMLWriterImpl or null to restore the default.
Throws:
PropertyException

getXMLWriterClass

public java.lang.Class getXMLWriterClass()

Returns the controllers class implementing XMLWriter. Defaults to XMLWriterImpl.


setIndentation

public void setIndentation(boolean pIndentation)

Sets whether XML documents generated by the controller ought to be formatted. Defaults to true.


getIndentation

public boolean getIndentation()

Returns whether XML documents generated by the controller ought to be formatted. Defaults to true.


setXmlDeclaration

public void setXmlDeclaration(boolean pDeclaration)

Sets whether the methods marshal(Object, Writer) and marshal(Object, OutputStream) ought to emit an XML declaration.


getXmlDeclaration

public boolean getXmlDeclaration()

Returns whether the methods marshal(Object, Writer) and marshal(Object, OutputStream) ought to emit an XML declaration.


setIndentationString

public void setIndentationString(java.lang.String pStr)

Sets the string used to indent one level. Defaults to DEFAULT_JAXME_INDENTATION_STRING. Equivalent to setProperty(JAXME_INDENTATION_STRING, pStr).

See Also:
DEFAULT_JAXME_INDENTATION_STRING, setProperty(java.lang.String, java.lang.Object), getProperty(java.lang.String)

getIndentationString

public java.lang.String getIndentationString()

Returns the string used to indent one level. Defaults to DEFAULT_JAXME_INDENTATION_STRING. Equivalent to getProperty(JAXME_INDENTATION_STRING).

See Also:
DEFAULT_JAXME_INDENTATION_STRING, setProperty(java.lang.String, java.lang.Object), getProperty(java.lang.String)

setIndentationSeparator

public void setIndentationSeparator(java.lang.String pStr)

Sets the string used as a line separator. Defaults to DEFAULT_JAXME_INDENTATION_SEPARATOR. Equivalent to setProperty(JAXME_INDENTATION_SEPARATOR, pStr).

See Also:
DEFAULT_JAXME_INDENTATION_SEPARATOR, setProperty(java.lang.String, java.lang.Object), getProperty(java.lang.String)

getIndentationSeparator

public java.lang.String getIndentationSeparator()

Returns the string used as a line separator. Defaults to DEFAULT_JAXME_INDENTATION_SEPARATOR. Equivalent to getProperty(JAXME_INDENTATION_SEPARATOR).

See Also:
DEFAULT_JAXME_INDENTATION_SEPARATOR, setProperty(java.lang.String, java.lang.Object), getProperty(java.lang.String)

setProperty

public void setProperty(java.lang.String pProperty,
                        java.lang.Object pValue)
                 throws PropertyException
Description copied from interface: Marshaller

Sets the marshaller property pName to the value pValue. Note, that the value type depends on the property being set. For example, the property Marshaller.JAXB_ENCODING requires a string, but the property Marshaller.JAXB_FORMATTED_OUTPUT requires a Boolean.

Specified by:
setProperty in interface Marshaller
Overrides:
setProperty in class JMControllerImpl
Parameters:
pProperty - The property name.
Throws:
PropertyException - An error occurred while processing the property.

getProperty

public java.lang.Object getProperty(java.lang.String pProperty)
                             throws PropertyException
Description copied from interface: Marshaller

Returns the value of the marshaller property pName. Note, that the value type depends on the property being set. For example, the property Marshaller.JAXB_ENCODING requires a string, but the property Marshaller.JAXB_FORMATTED_OUTPUT requires a Boolean.

Specified by:
getProperty in interface Marshaller
Overrides:
getProperty in class JMControllerImpl
Parameters:
pProperty - The property name.
Throws:
PropertyException - An error occurred while processing the property.

marshal

public void marshal(java.lang.Object pObject,
                    java.io.OutputStream pStream)
             throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object pObject and serializes it into the byte stream pTarget. Note, that serialization into a byte stream demands the use of an encoding. It may be required to set the parameter Marshaller.JAXB_ENCODING. By default the created output is formatted, which may be turned off using Marshaller.JAXB_FORMATTED_OUTPUT.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pStream - The output byte stream.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested IOException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_ENCODING, Marshaller.JAXB_FORMATTED_OUTPUT, Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public void marshal(java.lang.Object pObject,
                    org.xml.sax.ContentHandler pHandler)
             throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object by emitting SAX events into into the given SAX ContentHandler. This includes the events ContentHandler.startDocument() and ContentHandler.endDocument().

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB Object being marshalled.
pHandler - The target event handler.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested SAXException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public void marshal(java.lang.Object pObject,
                    java.io.Writer pWriter)
             throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object pObject and serializes it into the character stream pTarget. Unlike serialization to a byte stream, an encoding is not required, but a Marshaller may use the encoding whether to escape a character or not. Use of the Marshaller.JAXB_ENCODING property is still recommended. By default the created output is formatted, which may be turned off using Marshaller.JAXB_FORMATTED_OUTPUT.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pWriter - The output character stream.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested IOException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_ENCODING, Marshaller.JAXB_FORMATTED_OUTPUT, Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public void marshal(java.lang.Object pObject,
                    org.w3c.dom.Node pNode)
             throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object by creating a DOM tree below the given node.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pNode - The target node. This node must be ready to accept a child element. For example, it may be a Document, a DocumentFragment, or an Element.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested DOMException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public void marshal(java.lang.Object pObject,
                    javax.xml.transform.Result pResult)
             throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object pObject to the Result pTarget. All JAXB provider must support DOMResult, SAXResult, and StreamResult, which can easily be mapped to Marshaller.marshal(Object, org.w3c.dom.Node), Marshaller.marshal(Object, org.xml.sax.ContentHandler), Marshaller.marshal(Object,java.io.OutputStream), or Marshaller.marshal(Object,java.io.Writer). The use of a Result as a target isn't portable beyond these subinterfaces.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pResult - The Result being created.
Throws:
JAXBException - An unexcpected problem occurred. This may be used, for example, to throw a nested IOException.
MarshalException - Whereever possible, one should throw a MarshalException, and not a JAXBException.
See Also:
Marshaller.JAXB_SCHEMA_LOCATION, Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION

getNode

public org.w3c.dom.Node getNode(java.lang.Object contentTree)
                         throws JAXBException
Description copied from interface: Marshaller

Returns a DOM view of the given JAXB object. This view is life in the sense that modifications of its DOM tree will trigger updates on the original JAXB object.

Note: This is an optional feature and not supported by all JAXB providers.

Specified by:
getNode in interface Marshaller
Parameters:
contentTree - The JAXB object being viewed.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested DOMException.