public abstract class AbstractMarshallerImpl extends Object implements Marshaller
Partial default Marshaller implementation.
This class provides a partial default implementation for the Marshaller interface.
The only methods that a JAXB Provider has to implement are marshal(Object, javax.xml.transform.Result), marshal(Object, javax.xml.stream.XMLStreamWriter), and marshal(Object, javax.xml.stream.XMLEventWriter).
MarshallerMarshaller.Listener JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_FRAGMENT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION public AbstractMarshallerImpl()
public final void marshal(Object obj,
OutputStream os)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into an output stream.
marshal in interface Marshaller
obj - The root of content tree to be marshalled.os - XML will be added to this stream.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 obj (or any object reachable from obj). See Marshalling a JAXB element.public void marshal(Object jaxbElement,
File output)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into a file.
marshal in interface Marshaller
jaxbElement - The root of content tree to be marshalled.output - File to be written. If this file already exists, it will be overwritten.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 obj (or any object reachable from obj). See Marshalling a JAXB element.public final void marshal(Object obj,
Writer w)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into a Writer.
marshal in interface Marshaller
obj - The root of content tree to be marshalled.w - 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 obj (or any object reachable from obj). See Marshalling a JAXB element.public final void marshal(Object obj,
ContentHandler handler)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into SAX2 events.
marshal in interface Marshaller
obj - The root of content tree to be marshalled.handler - XML will be sent to this handler as SAX2 events.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 obj (or any object reachable from obj). See Marshalling a JAXB element.public final void marshal(Object obj,
Node node)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into a DOM tree.
marshal in interface Marshaller
obj - 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, or Element)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 Node getNode(Object obj)
throws JAXBException By default, the getNode method is unsupported and throw an UnsupportedOperationException. Implementations that choose to support this method must override this method.
getNode in interface Marshaller
obj - - JAXB Java representation of XML contentJAXBException - If any unexpected problem occursprotected String getEncoding()
Convenience method for getting the current output encoding.
protected void setEncoding(String encoding)
Convenience method for setting the output encoding.
encoding - a valid encoding as specified in the Marshaller class documentationprotected String getSchemaLocation()
Convenience method for getting the current schemaLocation.
protected void setSchemaLocation(String location)
Convenience method for setting the schemaLocation.
location - the schemaLocation valueprotected String getNoNSSchemaLocation()
Convenience method for getting the current noNamespaceSchemaLocation.
protected void setNoNSSchemaLocation(String location)
Convenience method for setting the noNamespaceSchemaLocation.
location - the noNamespaceSchemaLocation valueprotected boolean isFormattedOutput()
Convenience method for getting the formatted output flag.
protected void setFormattedOutput(boolean v)
Convenience method for setting the formatted output flag.
v - value of the formatted output flag.protected boolean isFragment()
Convenience method for getting the fragment flag.
protected void setFragment(boolean v)
Convenience method for setting the fragment flag.
v - value of the fragment flag.protected String getJavaEncoding(String encoding)
throws UnsupportedEncodingException Gets the corresponding Java encoding name from an IANA name. This method is a helper method for the derived class to convert encoding names.
UnsupportedEncodingException - If this implementation couldn't find the Java encoding name.public void setProperty(String name,
Object value)
throws PropertyException Default implementation of the setProperty method handles the four defined properties in Marshaller. If a provider needs to handle additional properties, it should override this method in a derived class.
setProperty in interface Marshaller
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 Object getProperty(String name)
throws PropertyException Default implementation of the getProperty method handles the four defined properties in Marshaller. If a provider needs to support additional provider specific properties, it should override this method in a derived class.
getProperty in interface Marshaller
name - the name of the property to retrievePropertyException - when there is an error retrieving the given property or value property namepublic 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.
getEventHandler in interface Marshaller
JAXBException - if an error was encountered while getting the current event handlerMarshaller.getEventHandler()public void setEventHandler(ValidationEventHandler handler)
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.
setEventHandler in interface Marshaller
handler - the validation event handlerJAXBException - if an error was encountered while setting the event handlerMarshaller.setEventHandler(ValidationEventHandler)public void marshal(Object obj,
XMLEventWriter writer)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into a XMLEventWriter.
marshal in interface Marshaller
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 obj (or any object reachable from obj). See Marshalling a JAXB element.public void marshal(Object obj,
XMLStreamWriter writer)
throws JAXBException Description copied from interface: Marshaller
Marshal the content tree rooted at jaxbElement into a XMLStreamWriter.
marshal in interface Marshaller
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 obj (or any object reachable from obj). See Marshalling a JAXB element.public void setSchema(Schema schema)
Description copied from interface: Marshaller
Specify the JAXP 1.3 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
schema - Schema object to validate marshal operations against or null to disable validationpublic Schema getSchema()
Description copied from interface: Marshaller
Get the JAXP 1.3 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
public void setAdapter(XmlAdapter adapter)
Description copied from interface: Marshaller
Associates a configured instance of XmlAdapter with this marshaller.
This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);.
setAdapter in interface Marshaller
Marshaller.setAdapter(Class,XmlAdapter)public <A extends XmlAdapter> void setAdapter(Class<A> type,
A adapter) Description copied from interface: Marshaller
Associates a configured instance of 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
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)
Description copied from interface: Marshaller
Gets the adapter associated with the specified type. This is the reverse operation of the Marshaller.setAdapter(javax.xml.bind.annotation.adapters.XmlAdapter) method.
getAdapter in interface Marshaller
public void setAttachmentMarshaller(AttachmentMarshaller am)
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.
setAttachmentMarshaller in interface Marshaller
public AttachmentMarshaller getAttachmentMarshaller()
getAttachmentMarshaller in interface Marshaller
public void setListener(Marshaller.Listener listener)
Description copied from interface: 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
listener - an instance of a class that implements Marshaller.Listener
public Marshaller.Listener getListener()
Description copied from interface: Marshaller
Return Marshaller.Listener registered with this Marshaller.
getListener in interface Marshaller
Marshaller.Listener or null if no Listener is registered with this Marshaller.
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.