public class JMMarshallerImpl extends JMControllerImpl implements JMMarshaller
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_JAXB_ENCODING
Default value for
Marshaller.JAXB_ENCODING . |
static java.lang.String |
DEFAULT_JAXME_INDENTATION_SEPARATOR
Default value for
JAXME_INDENTATION_SEPARATOR . |
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.
|
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. |
eventHandler, JAXME_DATATYPE_CONVERTER, JAXME_FORMAT_DATE, JAXME_FORMAT_DATETIME, JAXME_FORMAT_TIME, JAXME_PRIVATE
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION
Constructor and Description |
---|
JMMarshallerImpl() |
Modifier and Type | Method and Description |
---|---|
javax.xml.bind.annotation.adapters.XmlAdapter |
getAdapter(java.lang.Class type) |
javax.xml.bind.attachment.AttachmentMarshaller |
getAttachmentMarshaller() |
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.
|
Listener |
getListener() |
org.w3c.dom.Node |
getNode(java.lang.Object contentTree)
Returns a DOM view of the given JAXB object.
|
java.lang.String |
getNoNamespaceSchemaLocation()
Returns the schema location.
|
java.lang.Object |
getProperty(java.lang.String pProperty)
Returns the value for property
pProperty . |
javax.xml.validation.Schema |
getSchema() |
java.lang.String |
getSchemaLocation()
Returns the schema location.
|
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 jaxbElement,
java.io.File output) |
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 |
marshal(java.lang.Object jaxbElement,
javax.xml.stream.XMLEventWriter writer) |
void |
marshal(java.lang.Object jaxbElement,
javax.xml.stream.XMLStreamWriter writer) |
void |
setAdapter(java.lang.Class type,
javax.xml.bind.annotation.adapters.XmlAdapter adapter) |
void |
setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter adapter) |
void |
setAttachmentMarshaller(javax.xml.bind.attachment.AttachmentMarshaller am) |
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 |
setListener(Listener listener) |
void |
setNoNamespaceSchemaLocation(java.lang.String pValue)
Sets the schema location without namespace.
|
void |
setProperty(java.lang.String pProperty,
java.lang.Object pValue)
Sets the property
pProperty to the value
pValue . |
void |
setSchema(javax.xml.validation.Schema schema) |
void |
setSchemaLocation(java.lang.String pValue)
Sets the schema location.
|
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 . |
getDatatypeConverter, getDateFormat, getDateTimeFormat, getEventHandler, getJAXBContextImpl, getTimeFormat, setDatatypeConverter, setDateFormat, setDateTimeFormat, setEventHandler, setJAXBContextImpl, setTimeFormat
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDatatypeConverter, getJAXBContextImpl, setJAXBContextImpl
getEventHandler, setEventHandler
public static final java.lang.String DEFAULT_JAXB_ENCODING
Marshaller.JAXB_ENCODING
.
(UTF-8 encoding)public static final java.lang.String DEFAULT_JAXME_INDENTATION_STRING
JAXME_INDENTATION_STRING
: Two blanks.public static final java.lang.String DEFAULT_JAXME_INDENTATION_SEPARATOR
JAXME_INDENTATION_SEPARATOR
.
("\n", Line Feed)public static final java.lang.String JAXME_INDENTATION_STRING
DEFAULT_JAXME_INDENTATION_STRING
.public static final java.lang.String JAXME_INDENTATION_SEPARATOR
public static final java.lang.String JAXME_XML_DECLARATION
marshal(Object, OutputStream)
and
marshal(Object, Writer)
recognize
requests for XML declarations.public static final java.lang.String JAXME_XML_WRITER
ContentHandler
which is able to
marshal a SAX stream into a character stream. The property value is
an instance of Class
implementing XMLWriter
.public void setEncoding(java.lang.String pEncoding) throws PropertyException
DEFAULT_JAXB_ENCODING
.pEncoding
- Suggested encoding or null to restore
the defaultPropertyException
public java.lang.String getEncoding()
DEFAULT_JAXB_ENCODING
.public void setXMLWriterClass(java.lang.Class pClass) throws PropertyException
XMLWriter
.
Defaults to XMLWriterImpl
.pClass
- A class implementing XMLWriterImpl
or
null to restore the default.PropertyException
public java.lang.Class getXMLWriterClass()
Returns the controllers class implementing XMLWriter
.
Defaults to XMLWriterImpl
.
public void setIndentation(boolean pIndentation)
Sets whether XML documents generated by the controller ought to be formatted. Defaults to true.
public boolean getIndentation()
Returns whether XML documents generated by the controller ought to be formatted. Defaults to true.
public void setXmlDeclaration(boolean pDeclaration)
Sets whether the methods marshal(Object, Writer)
and marshal(Object, OutputStream)
ought to emit an
XML declaration.
public boolean getXmlDeclaration()
Returns whether the methods marshal(Object, Writer)
and marshal(Object, OutputStream)
ought to emit an
XML declaration.
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)
.
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)
.
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)
.
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)
.
public void setSchemaLocation(java.lang.String pValue) throws PropertyException
Sets the schema location. The marshaller will use this to
create an attribute xsi:schemaLocation
. Equivalent
to setProperty(JAXB_SCHEMA_LOCATION, pValue)
.
Defaults to null, in which case the attribute isn't created.
public java.lang.String getSchemaLocation()
Returns the schema location. The marshaller will use this to
create an attribute xsi:schemaLocation
. Equivalent
to setProperty(JAXB_SCHEMA_LOCATION, pValue)
.
Defaults to null, in which case the attribute isn't created.
public void setNoNamespaceSchemaLocation(java.lang.String pValue) throws PropertyException
Sets the schema location without namespace. The marshaller
will use this to create an attribute xsi:noNamespaceSchemaLocation
.
Equivalent to setProperty(JAXB_NO_NAMESPACE_SCHEMA_LOCATION,
pValue)
. Defaults to null, in which case the attribute isn't
created.
public java.lang.String getNoNamespaceSchemaLocation()
Returns the schema location. The marshaller will use this to
create an attribute xsi:noNamespaceSchemaLocation
. Equivalent
to setProperty(JAXB_SCHEMA_LOCATION, pValue)
.
Defaults to null, in which case the attribute isn't created.
public void setProperty(java.lang.String pProperty, java.lang.Object pValue) throws PropertyException
JMControllerImpl
pProperty
to the value
pValue
.setProperty
in interface Marshaller
setProperty
in class JMControllerImpl
pProperty
- The property name.PropertyException
- An error occurred while processing the property.public java.lang.Object getProperty(java.lang.String pProperty) throws PropertyException
JMControllerImpl
pProperty
.getProperty
in interface Marshaller
getProperty
in class JMControllerImpl
pProperty
- The property name.PropertyException
- An error occurred while processing the property.public void marshal(java.lang.Object pObject, java.io.OutputStream pStream) throws JAXBException
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
.
marshal
in interface Marshaller
pObject
- The JAXB object being marshalled.pStream
- The output byte stream.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
.Marshaller.JAXB_ENCODING
,
Marshaller.JAXB_FORMATTED_OUTPUT
,
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION
,
Marshaller.JAXB_SCHEMA_LOCATION
public void marshal(java.lang.Object pObject, org.xml.sax.ContentHandler pHandler) throws JAXBException
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()
.
marshal
in interface Marshaller
pObject
- The JAXB Object being marshalled.pHandler
- The target event handler.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
.Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION
,
Marshaller.JAXB_SCHEMA_LOCATION
public void marshal(java.lang.Object pObject, java.io.Writer pWriter) throws JAXBException
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
.
marshal
in interface Marshaller
pObject
- The JAXB object being marshalled.pWriter
- The output character stream.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
.Marshaller.JAXB_ENCODING
,
Marshaller.JAXB_FORMATTED_OUTPUT
,
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION
,
Marshaller.JAXB_SCHEMA_LOCATION
public void marshal(java.lang.Object pObject, org.w3c.dom.Node pNode) throws JAXBException
Marshaller
Marshals the given JAXB object by creating a DOM tree below the given node.
marshal
in interface Marshaller
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
.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
.Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION
,
Marshaller.JAXB_SCHEMA_LOCATION
public void marshal(java.lang.Object pObject, javax.xml.transform.Result pResult) throws JAXBException
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.
marshal
in interface Marshaller
pObject
- The JAXB object being marshalled.pResult
- The Result
being created.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
.Marshaller.JAXB_SCHEMA_LOCATION
,
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION
public org.w3c.dom.Node getNode(java.lang.Object contentTree) throws JAXBException
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.
getNode
in interface Marshaller
contentTree
- The JAXB object being viewed.JAXBException
- An unexpected problem occurred. This may be used,
for example, to throw a nested DOMException
.public void marshal(java.lang.Object jaxbElement, java.io.File output) throws JAXBException
JAXBException
public void marshal(java.lang.Object jaxbElement, javax.xml.stream.XMLStreamWriter writer) throws JAXBException
JAXBException
public void marshal(java.lang.Object jaxbElement, javax.xml.stream.XMLEventWriter writer) throws JAXBException
JAXBException
public void setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter adapter)
public void setAdapter(java.lang.Class type, javax.xml.bind.annotation.adapters.XmlAdapter adapter)
public javax.xml.bind.annotation.adapters.XmlAdapter getAdapter(java.lang.Class type)
public void setAttachmentMarshaller(javax.xml.bind.attachment.AttachmentMarshaller am)
public javax.xml.bind.attachment.AttachmentMarshaller getAttachmentMarshaller()
public void setSchema(javax.xml.validation.Schema schema)
public javax.xml.validation.Schema getSchema()
public void setListener(Listener listener)
public Listener getListener()