public final class MarshallerImpl extends AbstractMarshallerImpl implements ValidationEventHandler
Marshaller
interface for the JAXB RI.
Eventually all the marshal(java.lang.Object, java.io.OutputStream, javax.xml.namespace.NamespaceContext)
methods call into
the write(com.sun.xml.bind.v2.runtime.Name, com.sun.xml.bind.v2.runtime.JaxBeanInfo<T>, T, com.sun.xml.bind.v2.runtime.output.XmlOutput, java.lang.Runnable)
method.
Marshaller.Listener
Modifier and Type | Field and Description |
---|---|
protected static String |
C14N |
protected static String |
ENCODING_HANDLER |
protected static String |
ENCODING_HANDLER2 |
protected static String |
INDENT_STRING |
protected static String |
OBJECT_IDENTITY_CYCLE_DETECTION |
protected static String |
PREFIX_MAPPER |
protected XMLSerializer |
serializer |
protected static String |
XML_HEADERS |
protected static String |
XMLDECLARATION |
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_FRAGMENT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION
Constructor and Description |
---|
MarshallerImpl(JAXBContextImpl c,
AssociationMap assoc) |
Modifier and Type | Method and Description |
---|---|
protected CharacterEscapeHandler |
createEscapeHandler(String encoding) |
XmlOutput |
createWriter(OutputStream os) |
XmlOutput |
createWriter(OutputStream os,
String encoding) |
XmlOutput |
createWriter(Writer w) |
XmlOutput |
createWriter(Writer w,
String encoding) |
<A extends XmlAdapter> |
getAdapter(Class<A> type)
Gets the adapter associated with the specified type.
|
AttachmentMarshaller |
getAttachmentMarshaller() |
JAXBContextImpl |
getContext() |
Marshaller.Listener |
getListener()
Return
Marshaller.Listener registered with this Marshaller . |
Object |
getProperty(String name)
Default implementation of the getProperty method handles
the four defined properties in Marshaller.
|
Schema |
getSchema()
Get the JAXP 1.3
Schema object
being used to perform marshal-time validation. |
boolean |
handleEvent(ValidationEvent event)
Default error handling behavior fot
Marshaller . |
void |
marshal(Object obj,
OutputStream out,
NamespaceContext inscopeNamespace)
Marshals to
OutputStream with the given in-scope namespaces
taken into account. |
void |
marshal(Object target,
Result result)
Marshal the content tree rooted at
jaxbElement into the specified
javax.xml.transform.Result . |
void |
marshal(Object obj,
XMLEventWriter writer)
Marshal the content tree rooted at
jaxbElement into a
XMLEventWriter . |
void |
marshal(Object obj,
XmlOutput output) |
void |
marshal(Object obj,
XMLStreamWriter writer)
Marshal the content tree rooted at
jaxbElement into a
XMLStreamWriter . |
<A extends XmlAdapter> |
setAdapter(Class<A> type,
A adapter)
Associates a configured instance of
XmlAdapter with this marshaller. |
void |
setAttachmentMarshaller(AttachmentMarshaller am)
Associate a context that enables binary data within an XML document
to be transmitted as XML-binary optimized attachment.
|
void |
setListener(Marshaller.Listener listener)
Register marshal event callback
Marshaller.Listener with this Marshaller . |
void |
setProperty(String name,
Object value)
Default implementation of the setProperty method handles
the four defined properties in Marshaller.
|
void |
setSchema(Schema s)
Specify the JAXP 1.3
Schema
object that should be used to validate subsequent marshal operations
against. |
protected <T> void |
write(Name rootTagName,
JaxBeanInfo<T> bi,
T obj,
XmlOutput out,
Runnable postInitAction)
Used by
BridgeImpl to write an arbitrary object as a fragment. |
getEncoding, getEventHandler, getJavaEncoding, getNode, getNoNSSchemaLocation, getSchemaLocation, isFormattedOutput, isFragment, marshal, marshal, marshal, marshal, marshal, setAdapter, setEncoding, setEventHandler, setFormattedOutput, setFragment, setNoNSSchemaLocation, setSchemaLocation
protected final XMLSerializer serializer
protected static final String INDENT_STRING
protected static final String PREFIX_MAPPER
protected static final String ENCODING_HANDLER
protected static final String ENCODING_HANDLER2
protected static final String XMLDECLARATION
protected static final String XML_HEADERS
protected static final String C14N
protected static final String OBJECT_IDENTITY_CYCLE_DETECTION
public MarshallerImpl(JAXBContextImpl c, AssociationMap assoc)
assoc
- non-null if the marshaller is working inside BinderImpl
.public JAXBContextImpl getContext()
public void marshal(Object obj, OutputStream out, NamespaceContext inscopeNamespace) throws JAXBException
OutputStream
with the given in-scope namespaces
taken into account.JAXBException
public void marshal(Object obj, XMLStreamWriter writer) throws JAXBException
Marshaller
jaxbElement
into a
XMLStreamWriter
.marshal
in interface Marshaller
marshal
in class AbstractMarshallerImpl
obj
- The content tree to be marshalled.writer
- XML will be sent to this writer.JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Marshaller
is unable to marshal jaxbElement
(or any
object reachable from jaxbElement
). See
Marshalling a JAXB element.public void marshal(Object obj, XMLEventWriter writer) throws JAXBException
Marshaller
jaxbElement
into a
XMLEventWriter
.marshal
in interface Marshaller
marshal
in class AbstractMarshallerImpl
obj
- The content tree rooted at jaxbElement to be marshalled.writer
- XML will be sent to this writer.JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Marshaller
is unable to marshal jaxbElement
(or any
object reachable from jaxbElement
). See
Marshalling a JAXB element.public void marshal(Object obj, XmlOutput output) throws JAXBException
JAXBException
public void marshal(Object target, Result result) throws JAXBException
Marshaller
jaxbElement
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.
marshal
in interface Marshaller
target
- The root of content tree to be marshalled.result
- XML will be sent to this ResultJAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If the ValidationEventHandler
returns false from its handleEvent
method or the
Marshaller
is unable to marshal jaxbElement
(or any
object reachable from jaxbElement
). See
Marshalling a JAXB element.protected final <T> void write(Name rootTagName, JaxBeanInfo<T> bi, T obj, XmlOutput out, Runnable postInitAction) throws JAXBException
BridgeImpl
to write an arbitrary object as a fragment.JAXBException
protected CharacterEscapeHandler createEscapeHandler(String encoding)
public XmlOutput createWriter(OutputStream os) throws JAXBException
JAXBException
public XmlOutput createWriter(OutputStream os, String encoding) throws JAXBException
JAXBException
public Object getProperty(String name) throws PropertyException
AbstractMarshallerImpl
getProperty
in interface Marshaller
getProperty
in class AbstractMarshallerImpl
name
- the name of the property to retrievePropertyException
- when there is an error retrieving the given property or value
property namepublic void setProperty(String name, Object value) throws PropertyException
AbstractMarshallerImpl
setProperty
in interface Marshaller
setProperty
in class AbstractMarshallerImpl
name
- the name of the property to be set. This value can either
be specified using one of the constant fields or a user
supplied string.value
- the value of the property to be setPropertyException
- when there is an error processing the given
property or valuepublic <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter)
Marshaller
XmlAdapter
with this marshaller.
Every marshaller internally maintains a
Map
<Class
,XmlAdapter
>,
which it uses for marshalling classes whose fields/methods are annotated
with XmlJavaTypeAdapter
.
This method allows applications to use a configured instance of XmlAdapter
.
When an instance of an adapter is not given, a marshaller will create
one by invoking its default constructor.
setAdapter
in interface Marshaller
setAdapter
in class AbstractMarshallerImpl
type
- The type of the adapter. The specified instance will be used when
XmlJavaTypeAdapter.value()
refers to this type.adapter
- The instance of the adapter to be used. If null, it will un-register
the current adapter set for this type.public <A extends XmlAdapter> A getAdapter(Class<A> type)
Marshaller
Marshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)
method.getAdapter
in interface Marshaller
getAdapter
in class AbstractMarshallerImpl
public void setAttachmentMarshaller(AttachmentMarshaller am)
Marshaller
Associate a context that enables binary data within an XML document to be transmitted as XML-binary optimized attachment. The attachment is referenced from the XML document content model by content-id URIs(cid) references stored within the xml document.
setAttachmentMarshaller
in interface Marshaller
setAttachmentMarshaller
in class AbstractMarshallerImpl
public AttachmentMarshaller getAttachmentMarshaller()
getAttachmentMarshaller
in interface Marshaller
getAttachmentMarshaller
in class AbstractMarshallerImpl
public Schema getSchema()
Marshaller
Schema
object
being used to perform marshal-time validation. If there is no
Schema set on the marshaller, then this method will return null
indicating that marshal-time validation will not be performed.getSchema
in interface Marshaller
getSchema
in class AbstractMarshallerImpl
public void setSchema(Schema s)
Marshaller
Schema
object that should be used to validate subsequent marshal operations
against. Passing null into this method will disable validation.
This method allows the caller to validate the marshalled XML as it's marshalled.
Initially this property is set to null
.
setSchema
in interface Marshaller
setSchema
in class AbstractMarshallerImpl
s
- Schema object to validate marshal operations against or null to disable validationpublic boolean handleEvent(ValidationEvent event)
Marshaller
.handleEvent
in interface ValidationEventHandler
event
- the encapsulated validation event information. It is a
provider error if this parameter is null.UnmarshalException
,
ValidationException
, or MarshalException
.public Marshaller.Listener getListener()
Marshaller
Return Marshaller.Listener
registered with this Marshaller
.
getListener
in interface Marshaller
getListener
in class AbstractMarshallerImpl
Marshaller.Listener
or null
if no Listener is registered with this Marshaller.public void setListener(Marshaller.Listener listener)
Marshaller
Register marshal event callback Marshaller.Listener
with this Marshaller
.
There is only one Listener per Marshaller. Setting a Listener replaces the previous set Listener.
One can unregister current Listener by setting listener to null
.
setListener
in interface Marshaller
setListener
in class AbstractMarshallerImpl
listener
- an instance of a class that implements Marshaller.Listener
Copyright © 2019 JBoss by Red Hat. All rights reserved.