Class JAXBMarshaller
- java.lang.Object
-
- org.eclipse.persistence.jaxb.JAXBMarshaller
-
- All Implemented Interfaces:
Marshaller
public class JAXBMarshaller extends java.lang.Object implements Marshaller
INTERNAL:Purpose:To Provide an implementation of the JAXB 2.0 Marshaller Interface
Responsibilities:
- Provide a JAXB wrapper on the XMLMarshaller API
- Perform Object to XML Conversions
This implementation of the JAXB 2.1/2.2 Marshaller interface provides the required functionality by acting as a thin wrapper on the existing XMLMarshaller API.
- See Also:
Marshaller
,MarshallerProperties
,XMLMarshaller
- Author:
- mmacivor
- Since:
- Oracle TopLink 11.1.1.0.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.xml.bind.Marshaller
Marshaller.Listener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
XML_JAVATYPE_ADAPTERS
-
Fields inherited from interface javax.xml.bind.Marshaller
JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_FRAGMENT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION
-
-
Constructor Summary
Constructors Constructor Description JAXBMarshaller(XMLMarshaller newXMLMarshaller, JAXBContext jaxbContext)
This constructor initializes various settings on the XML marshaller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description XmlAdapter
getAdapter(java.lang.Class javaClass)
Gets the adapter associated with the specified type.AttachmentMarshaller
getAttachmentMarshaller()
java.util.Set<ConstraintViolationWrapper<java.lang.Object>>
getConstraintViolations()
Returns constraint violations stored in the underlyingJAXBBeanValidator
instance.ValidationEventHandler
getEventHandler()
Return the current event handler or the default event handler if one hasn't been set.JAXBContext
getJaxbContext()
Marshaller.Listener
getListener()
ReturnMarshaller.Listener
registered with thisMarshaller
.org.w3c.dom.Node
getNode(java.lang.Object object)
Get a DOM tree view of the content tree(Optional).java.lang.Object
getProperty(java.lang.String key)
Get a property from the JAXBMarshaller.javax.xml.validation.Schema
getSchema()
Get the JAXP 1.3Schema
object being used to perform marshal-time validation.XMLMarshaller
getXMLMarshaller()
void
marshal(java.lang.Object object, java.io.File file)
Marshal the content tree rooted atjaxbElement
into a file.void
marshal(java.lang.Object object, java.io.OutputStream outputStream)
Marshal the content tree rooted atjaxbElement
into an output stream.void
marshal(java.lang.Object object, java.io.Writer writer)
Marshal the content tree rooted atjaxbElement
into a Writer.void
marshal(java.lang.Object object, javax.xml.stream.XMLEventWriter eventWriter)
Marshal the content tree rooted atjaxbElement
into aXMLEventWriter
.void
marshal(java.lang.Object object, javax.xml.stream.XMLEventWriter eventWriter, TypeMappingInfo type)
void
marshal(java.lang.Object object, javax.xml.stream.XMLStreamWriter streamWriter)
Marshal the content tree rooted atjaxbElement
into aXMLStreamWriter
.void
marshal(java.lang.Object object, javax.xml.stream.XMLStreamWriter streamWriter, TypeMappingInfo type)
void
marshal(java.lang.Object object, javax.xml.transform.Result result)
Marshal the content tree rooted atjaxbElement
into the specifiedjavax.xml.transform.Result
.void
marshal(java.lang.Object object, javax.xml.transform.Result result, TypeMappingInfo type)
void
marshal(java.lang.Object object, MarshalRecord record)
void
marshal(java.lang.Object object, MarshalRecord record, TypeMappingInfo type)
void
marshal(java.lang.Object object, org.w3c.dom.Node node)
Marshal the content tree rooted atjaxbElement
into a DOM tree.void
marshal(java.lang.Object object, org.xml.sax.ContentHandler contentHandler)
Marshal the content tree rooted atjaxbElement
into SAX2 events.void
setAdapter(java.lang.Class javaClass, XmlAdapter adapter)
Associates a configured instance ofXmlAdapter
with this marshaller.void
setAdapter(XmlAdapter adapter)
Associates a configured instance ofXmlAdapter
with this marshaller.void
setAttachmentMarshaller(AttachmentMarshaller attachmentMarshaller)
Associate a context that enables binary data within an XML document to be transmitted as XML-binary optimized attachment.void
setEventHandler(ValidationEventHandler newValidationEventHandler)
Allow an application to register a validation event handler.void
setListener(Marshaller.Listener listener)
Register marshal event callbackMarshaller.Listener
with thisMarshaller
.void
setMarshalCallbacks(java.util.Map callbacks)
void
setProperty(java.lang.String key, java.lang.Object value)
Set a property on the JAXBMarshaller.void
setSchema(javax.xml.validation.Schema schema)
Specify the JAXP 1.3Schema
object that should be used to validate subsequent marshal operations against.
-
-
-
Field Detail
-
XML_JAVATYPE_ADAPTERS
public static final java.lang.String XML_JAVATYPE_ADAPTERS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JAXBMarshaller
public JAXBMarshaller(XMLMarshaller newXMLMarshaller, JAXBContext jaxbContext)
This constructor initializes various settings on the XML marshaller.- Parameters:
newXMLMarshaller
- xml marshallerjaxbContext
- jaxb context
-
-
Method Detail
-
getAdapter
public XmlAdapter getAdapter(java.lang.Class javaClass)
Description copied from interface:Marshaller
Gets the adapter associated with the specified type. This is the reverse operation of theMarshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter)
method.- Specified by:
getAdapter
in interfaceMarshaller
-
getAttachmentMarshaller
public AttachmentMarshaller getAttachmentMarshaller()
- Specified by:
getAttachmentMarshaller
in interfaceMarshaller
-
getEventHandler
public ValidationEventHandler getEventHandler() throws JAXBException
Description copied from interface:Marshaller
Return the current event handler or the default event handler if one hasn't been set.- Specified by:
getEventHandler
in interfaceMarshaller
- Returns:
- the current ValidationEventHandler or the default event handler if it hasn't been set
- Throws:
JAXBException
- if an error was encountered while getting the current event handler
-
getListener
public Marshaller.Listener getListener()
Description copied from interface:Marshaller
Return
Marshaller.Listener
registered with thisMarshaller
.- Specified by:
getListener
in interfaceMarshaller
- Returns:
- registered
Marshaller.Listener
ornull
if no Listener is registered with this Marshaller.
-
getNode
public org.w3c.dom.Node getNode(java.lang.Object object) throws JAXBException
Description copied from interface:Marshaller
Get a DOM tree view of the content tree(Optional). If the returned DOM tree is updated, these changes are also visible in the content tree. UseMarshaller.marshal(Object, org.w3c.dom.Node)
to force a deep copy of the content tree to a DOM representation.- Specified by:
getNode
in interfaceMarshaller
- Parameters:
object
- - JAXB Java representation of XML content- Returns:
- the DOM tree view of the contentTree
- Throws:
JAXBException
- If any unexpected problem occurs
-
getProperty
public java.lang.Object getProperty(java.lang.String key) throws PropertyException
Get a property from the JAXBMarshaller. Attempting to get any unsupported property will result in a javax.xml.bind.PropertyException- Specified by:
getProperty
in interfaceMarshaller
- Parameters:
key
- the name of the property to retrieve- Returns:
- the value of the requested property
- Throws:
PropertyException
- when there is an error retrieving the given property or value property name- See Also:
MarshallerProperties
-
getSchema
public javax.xml.validation.Schema getSchema()
Description copied from interface:Marshaller
Get the JAXP 1.3Schema
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.- Specified by:
getSchema
in interfaceMarshaller
- Returns:
- the Schema object being used to perform marshal-time validation or null if not present.
-
marshal
public void marshal(java.lang.Object object, org.xml.sax.ContentHandler contentHandler) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into SAX2 events.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The root of content tree to be marshalled.contentHandler
- XML will be sent to this handler as SAX2 events.- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, javax.xml.stream.XMLEventWriter eventWriter) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into aXMLEventWriter
.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The content tree rooted at jaxbElement to be marshalled.eventWriter
- XML will be sent to this writer.- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, javax.xml.stream.XMLEventWriter eventWriter, TypeMappingInfo type) throws JAXBException
- Throws:
JAXBException
-
marshal
public void marshal(java.lang.Object object, org.w3c.dom.Node node) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into a DOM tree.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The content tree to be marshalled.node
- DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (Document
,DocumentFragment
, orElement
)- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, java.io.OutputStream outputStream) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into an output stream.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The root of content tree to be marshalled.outputStream
- XML will be added to this stream.- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, java.io.File file) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into a file.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The root of content tree to be marshalled.file
- File to be written. If this file already exists, it will be overwritten.- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, javax.xml.transform.Result result) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into the specifiedjavax.xml.transform.Result
.All JAXB Providers must at least support
DOMResult
,SAXResult
, andStreamResult
. It can support other derived classes ofResult
as well.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The root of content tree to be marshalled.result
- XML will be sent to this Result- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, javax.xml.transform.Result result, TypeMappingInfo type) throws JAXBException
- Throws:
JAXBException
-
marshal
public void marshal(java.lang.Object object, javax.xml.stream.XMLStreamWriter streamWriter) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into aXMLStreamWriter
.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The content tree to be marshalled.streamWriter
- XML will be sent to this writer.- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, javax.xml.stream.XMLStreamWriter streamWriter, TypeMappingInfo type) throws JAXBException
- Throws:
JAXBException
-
marshal
public void marshal(java.lang.Object object, java.io.Writer writer) throws JAXBException
Description copied from interface:Marshaller
Marshal the content tree rooted atjaxbElement
into a Writer.- Specified by:
marshal
in interfaceMarshaller
- Parameters:
object
- The root of content tree to be marshalled.writer
- XML will be sent to this writer.- Throws:
JAXBException
- If any unexpected problem occurs during the marshalling.MarshalException
- If theValidationEventHandler
returns false from itshandleEvent
method or theMarshaller
is unable to marshaljaxbElement
(or any object reachable fromjaxbElement
). See Marshalling a JAXB element.
-
marshal
public void marshal(java.lang.Object object, MarshalRecord record) throws JAXBException
- Throws:
JAXBException
-
marshal
public void marshal(java.lang.Object object, MarshalRecord record, TypeMappingInfo type) throws JAXBException
- Throws:
JAXBException
-
setAdapter
public void setAdapter(java.lang.Class javaClass, XmlAdapter adapter)
Description copied from interface:Marshaller
Associates a configured instance ofXmlAdapter
with this marshaller.Every marshaller internally maintains a
Map
<Class
,XmlAdapter
>, which it uses for marshalling classes whose fields/methods are annotated withXmlJavaTypeAdapter
.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.- Specified by:
setAdapter
in interfaceMarshaller
- Parameters:
javaClass
- The type of the adapter. The specified instance will be used whenXmlJavaTypeAdapter.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.
-
setAdapter
public void setAdapter(XmlAdapter adapter)
Description copied from interface:Marshaller
Associates a configured instance ofXmlAdapter
with this marshaller.This is a convenience method that invokes
setAdapter(adapter.getClass(),adapter);
.- Specified by:
setAdapter
in interfaceMarshaller
- See Also:
Marshaller.setAdapter(Class,XmlAdapter)
-
setAttachmentMarshaller
public void setAttachmentMarshaller(AttachmentMarshaller attachmentMarshaller)
Description copied from interface: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.
- Specified by:
setAttachmentMarshaller
in interfaceMarshaller
-
setEventHandler
public void setEventHandler(ValidationEventHandler newValidationEventHandler) throws JAXBException
Description copied from interface:Marshaller
Allow an application to register a validation event handler.The validation event handler will be called by the JAXB Provider if any validation errors are encountered during calls to any of the marshal API's. If the client application does not register a validation event handler before invoking one of the marshal methods, then validation events will be handled by the default event handler which will terminate the marshal operation after the first error or fatal error is encountered.
Calling this method with a null parameter will cause the Marshaller to revert back to the default default event handler.
- Specified by:
setEventHandler
in interfaceMarshaller
- Parameters:
newValidationEventHandler
- the validation event handler- Throws:
JAXBException
- if an error was encountered while setting the event handler
-
setListener
public void setListener(Marshaller.Listener listener)
Description copied from interface:Marshaller
Register marshal event callback
Marshaller.Listener
with thisMarshaller
.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
.- Specified by:
setListener
in interfaceMarshaller
- Parameters:
listener
- an instance of a class that implementsMarshaller.Listener
-
setMarshalCallbacks
public void setMarshalCallbacks(java.util.Map callbacks)
-
setProperty
public void setProperty(java.lang.String key, java.lang.Object value) throws PropertyException
Set a property on the JAXBMarshaller. Attempting to set any unsupported property will result in a javax.xml.bind.PropertyException- Specified by:
setProperty
in interfaceMarshaller
- Parameters:
key
- 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 set- Throws:
PropertyException
- when there is an error processing the given property or value- See Also:
MarshallerProperties
-
setSchema
public void setSchema(javax.xml.validation.Schema schema)
Description copied from interface:Marshaller
Specify the JAXP 1.3Schema
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
.- Specified by:
setSchema
in interfaceMarshaller
- Parameters:
schema
- Schema object to validate marshal operations against or null to disable validation
-
getJaxbContext
public JAXBContext getJaxbContext()
-
getXMLMarshaller
public XMLMarshaller getXMLMarshaller()
-
getConstraintViolations
public java.util.Set<ConstraintViolationWrapper<java.lang.Object>> getConstraintViolations()
Returns constraint violations stored in the underlyingJAXBBeanValidator
instance.- Returns:
- set of constraint violations from last unmarshal
-
-