Top Description Fields Constructors Methods
jakarta.xml.bind.helpers

public abstract Class AbstractMarshallerImpl

extends Object
implements Marshaller
Class Inheritance
All Implemented Interfaces
jakarta.xml.bind.Marshaller
Imports
jakarta.xml.bind.JAXBException, .Marshaller, .PropertyException, .ValidationEventHandler, jakarta.xml.bind.annotation.adapters.XmlAdapter, jakarta.xml.bind.attachment.AttachmentMarshaller, javax.xml.stream.XMLEventWriter, .XMLStreamWriter, javax.xml.transform.dom.DOMResult, javax.xml.transform.sax.SAXResult, javax.xml.transform.stream.StreamResult, javax.xml.validation.Schema, java.io.UnsupportedEncodingException, .File, .OutputStream, .FileOutputStream, .BufferedOutputStream, .IOException

Partial default Marshaller implementation.

This class provides a partial default implementation for the jakarta.xml.bind.Marshaller interface.

The only methods that a Jakarta XML Binding Provider has to implement are marshal(Object, javax.xml.transform.Result), marshal(Object, javax.xml.stream.XMLStreamWriter), and marshal(Object, javax.xml.stream.XMLEventWriter).

Author
Since
1.6, JAXB 1.0
See Also
jakarta.xml.bind.Marshaller

Field Summary

Modifier and TypeField and Description
pack-priv static String[]
private String
encoding

store the value of the encoding property.

private ValidationEventHandler
eventHandler

handler that will be used to process errors and warnings during marshal

private boolean
formattedOutput

store the value of the formattedOutput property.

private boolean
fragment

store the value of the fragment property.

private String
noNSSchemaLocation

store the value of the noNamespaceSchemaLocation property.

private String
schemaLocation

store the value of the schemaLocation property.

Constructor Summary

AccessConstructor and Description
protected
AbstractMarshallerImpl()

Do-nothing constructor for the derived classes.

Method Summary

Modifier and TypeMethod and Description
private void
checkBoolean(String name, Object value)

private void
checkNotNull(Object o1, String o1Name, Object o2, String o2Name)

private void
checkString(String name, Object value)

public <A extends XmlAdapter<?, ?>> A
getAdapter(Class<A>
The type of the adapter. The specified instance will be used when jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value() refers to this type.
type
)

Implements jakarta.xml.bind.Marshaller.getAdapter.

Gets the adapter associated with the specified type.
public AttachmentMarshaller
protected String

Returns:

the current encoding or "UTF-8" if it hasn't been set.
getEncoding
()

Convenience method for getting the current output encoding.

public ValidationEventHandler
getEventHandler()

Implements jakarta.xml.bind.Marshaller.getEventHandler.

Return the current event handler or the default event handler if one hasn't been set.
protected String
getJavaEncoding(String encoding)

Gets the corresponding Java encoding name from an IANA name.

public Marshaller.Listener
getListener()

Implements jakarta.xml.bind.Marshaller.getListener.

Return Listener registered with this Marshaller.

public Node
getNode(Object
- Jakarta XML Binding Java representation of XML content
obj
)

Implements jakarta.xml.bind.Marshaller.getNode.

By default, the getNode method is unsupported and throw an java.lang.UnsupportedOperationException.
protected String

Returns:

the current noNamespaceSchemaLocation or null if it hasn't been set
getNoNSSchemaLocation
()

Convenience method for getting the current noNamespaceSchemaLocation.

public Object
getProperty(String
the name of the property to retrieve
name
)

Implements jakarta.xml.bind.Marshaller.getProperty.

Default implementation of the getProperty method handles the four defined properties in Marshaller.
public Schema
getSchema()

Implements jakarta.xml.bind.Marshaller.getSchema.

Get the JAXP Schema object being used to perform marshal-time validation.
protected String

Returns:

the current schemaLocation or null if it hasn't been set
getSchemaLocation
()

Convenience method for getting the current schemaLocation.

protected boolean

Returns:

the current value of the formatted output flag or false if it hasn't been set.
isFormattedOutput
()

Convenience method for getting the formatted output flag.

protected boolean

Returns:

the current value of the fragment flag or false if it hasn't been set.
isFragment
()

Convenience method for getting the fragment flag.

public final void
marshal(Object
The root of content tree to be marshalled.
obj
,
OutputStream
XML will be added to this stream.
os
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into an output stream.
public void
marshal(Object
The root of content tree to be marshalled.
jaxbElement
,
File
File to be written. If this file already exists, it will be overwritten.
output
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a file.
public final void
marshal(Object
The root of content tree to be marshalled.
obj
,
Writer
XML will be sent to this writer.
w
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a Writer.
public final void
marshal(Object
The root of content tree to be marshalled.
obj
,
ContentHandler
XML will be sent to this handler as SAX2 events.
handler
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into SAX2 events.
public final void
marshal(Object
The content tree to be marshalled.
obj
,
Node
DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (org.w3c.dom.Document, org.w3c.dom.DocumentFragment, or org.w3c.dom.Element)
node
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a DOM tree.
public void
marshal(Object
The content tree rooted at jaxbElement to be marshalled.
obj
,
XMLEventWriter
XML will be sent to this writer.
writer
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a javax.xml.stream.XMLEventWriter.
public void
marshal(Object
The content tree to be marshalled.
obj
,
XMLStreamWriter
XML will be sent to this writer.
writer
)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a javax.xml.stream.XMLStreamWriter.
public <A extends XmlAdapter<?, ?>> void
setAdapter(A
The instance of the adapter to be used. If null, it will un-register the current adapter set for this type.
adapter
)

Implements jakarta.xml.bind.Marshaller.setAdapter.

Associates a configured instance of XmlAdapter with this marshaller.
public <A extends XmlAdapter<?, ?>> void
setAdapter(Class<A>
The type of the adapter. The specified instance will be used when jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value() refers to this type.
type
,
A
The instance of the adapter to be used. If null, it will un-register the current adapter set for this type.
adapter
)

Implements jakarta.xml.bind.Marshaller.setAdapter.

Associates a configured instance of XmlAdapter with this marshaller.
public void
setAttachmentMarshaller(AttachmentMarshaller
the attachment marshaller to be set
am
)

Implements jakarta.xml.bind.Marshaller.setAttachmentMarshaller.

Associate a context that enables binary data within an XML document to be transmitted as XML-binary optimized attachment.
protected void
setEncoding(String
a valid encoding as specified in the Marshaller class documentation
encoding
)

Convenience method for setting the output encoding.

public void
setEventHandler(ValidationEventHandler
the validation event handler
handler
)

Implements jakarta.xml.bind.Marshaller.setEventHandler.

Allow an application to register a validation event handler.
protected void
setFormattedOutput(boolean
value of the formatted output flag.
v
)

Convenience method for setting the formatted output flag.

protected void
setFragment(boolean
value of the fragment flag.
v
)

Convenience method for setting the fragment flag.

public void
setListener(Marshaller.Listener
an instance of a class that implements Listener
listener
)

Implements jakarta.xml.bind.Marshaller.setListener.

Register marshal event callback Listener with this Marshaller.

protected void
setNoNSSchemaLocation(String
the noNamespaceSchemaLocation value
location
)

Convenience method for setting the noNamespaceSchemaLocation.

public void
setProperty(String
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.
name
,
Object
the value of the property to be set
value
)

Implements jakarta.xml.bind.Marshaller.setProperty.

Default implementation of the setProperty method handles the four defined properties in Marshaller.
public void
setSchema(Schema
Schema object to validate marshal operations against or null to disable validation
schema
)

Implements jakarta.xml.bind.Marshaller.setSchema.

Specify the JAXP Schema object that should be used to validate subsequent marshal operations against.
protected void
setSchemaLocation(String
the schemaLocation value
location
)

Convenience method for setting the schemaLocation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aliasesback to summary
pack-priv static String[] aliases
encodingback to summary
private String encoding

store the value of the encoding property.

eventHandlerback to summary
private ValidationEventHandler eventHandler

handler that will be used to process errors and warnings during marshal

formattedOutputback to summary
private boolean formattedOutput

store the value of the formattedOutput property.

fragmentback to summary
private boolean fragment

store the value of the fragment property.

noNSSchemaLocationback to summary
private String noNSSchemaLocation

store the value of the noNamespaceSchemaLocation property.

schemaLocationback to summary
private String schemaLocation

store the value of the schemaLocation property.

Constructor Detail

AbstractMarshallerImplback to summary
protected AbstractMarshallerImpl()

Do-nothing constructor for the derived classes.

Method Detail

checkBooleanback to summary
private void checkBoolean(String name, Object value) throws PropertyException
checkNotNullback to summary
private void checkNotNull(Object o1, String o1Name, Object o2, String o2Name)
checkStringback to summary
private void checkString(String name, Object value) throws PropertyException
getAdapterback to summary
public <A extends XmlAdapter<?, ?>> A getAdapter(Class<A> type)

Implements jakarta.xml.bind.Marshaller.getAdapter.

Doc from jakarta.xml.bind.Marshaller.getAdapter.

Gets the adapter associated with the specified type. This is the reverse operation of the setAdapter method.

Parameters
<A>
the type of the adapter
type:Class<A>

The type of the adapter. The specified instance will be used when jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value() refers to this type.

Returns:A

The adapter associated with the specified type.

Annotations
@Override
getAttachmentMarshallerback to summary
public AttachmentMarshaller getAttachmentMarshaller()

Implements jakarta.xml.bind.Marshaller.getAttachmentMarshaller.

Annotations
@Override
getEncodingback to summary
protected String getEncoding()

Convenience method for getting the current output encoding.

Returns:String

the current encoding or "UTF-8" if it hasn't been set.

getEventHandlerback to summary
public ValidationEventHandler getEventHandler() throws JAXBException

Implements jakarta.xml.bind.Marshaller.getEventHandler.

Doc from jakarta.xml.bind.Marshaller.getEventHandler.

Return the current event handler or the default event handler if one hasn't been set.

Returns:ValidationEventHandler

the current ValidationEventHandler or the default event handler if it hasn't been set

Annotations
@Override
Exceptions
JAXBException:
if an error was encountered while getting the current event handler
See Also
jakarta.xml.bind.Marshaller#getEventHandler()
getJavaEncodingback to summary
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.

Exceptions
UnsupportedEncodingException:
If this implementation couldn't find the Java encoding name.
getListenerback to summary
public Marshaller.Listener getListener()

Implements jakarta.xml.bind.Marshaller.getListener.

Doc from jakarta.xml.bind.Marshaller.getListener.

Return Listener registered with this Marshaller.

Returns:Marshaller.Listener

registered Listener or null if no Listener is registered with this Marshaller.

Annotations
@Override
getNodeback to summary
public Node getNode(Object obj) throws JAXBException

Implements jakarta.xml.bind.Marshaller.getNode.

By default, the getNode method is unsupported and throw an java.lang.UnsupportedOperationException. Implementations that choose to support this method must override this method.

Parameters
obj:Object

Doc from jakarta.xml.bind.Marshaller.getNode.

- Jakarta XML Binding Java representation of XML content

Returns:Node

Doc from jakarta.xml.bind.Marshaller.getNode.

the DOM tree view of the contentTree

Annotations
@Override
Exceptions
JAXBException:

Doc from jakarta.xml.bind.Marshaller.getNode.

If any unexpected problem occurs

getNoNSSchemaLocationback to summary
protected String getNoNSSchemaLocation()

Convenience method for getting the current noNamespaceSchemaLocation.

Returns:String

the current noNamespaceSchemaLocation or null if it hasn't been set

getPropertyback to summary
public Object getProperty(String name) throws PropertyException

Implements jakarta.xml.bind.Marshaller.getProperty.

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.

Parameters
name:String

Doc from jakarta.xml.bind.Marshaller.getProperty.

the name of the property to retrieve

Returns:Object

Doc from jakarta.xml.bind.Marshaller.getProperty.

the value of the requested property

Annotations
@Override
Exceptions
PropertyException:

Doc from jakarta.xml.bind.Marshaller.getProperty.

when there is an error retrieving the given property or value property name

getSchemaback to summary
public Schema getSchema()

Implements jakarta.xml.bind.Marshaller.getSchema.

Doc from jakarta.xml.bind.Marshaller.getSchema.

Get the JAXP 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.

Returns:Schema

the Schema object being used to perform marshal-time validation or null if not present.

Annotations
@Override
getSchemaLocationback to summary
protected String getSchemaLocation()

Convenience method for getting the current schemaLocation.

Returns:String

the current schemaLocation or null if it hasn't been set

isFormattedOutputback to summary
protected boolean isFormattedOutput()

Convenience method for getting the formatted output flag.

Returns:boolean

the current value of the formatted output flag or false if it hasn't been set.

isFragmentback to summary
protected boolean isFragment()

Convenience method for getting the fragment flag.

Returns:boolean

the current value of the fragment flag or false if it hasn't been set.

marshalback to summary
public final void marshal(Object obj, OutputStream os) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into an output stream.

Parameters
obj:Object

The root of content tree to be marshalled.

os:OutputStream

XML will be added to this stream.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public void marshal(Object jaxbElement, File output) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a file.

Parameters
jaxbElement:Object

The root of content tree to be marshalled.

output:File

File to be written. If this file already exists, it will be overwritten.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public final void marshal(Object obj, Writer w) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a Writer.

Parameters
obj:Object

The root of content tree to be marshalled.

w:Writer

XML will be sent to this writer.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public final void marshal(Object obj, ContentHandler handler) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into SAX2 events.

Parameters
obj:Object

The root of content tree to be marshalled.

handler:ContentHandler

XML will be sent to this handler as SAX2 events.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public final void marshal(Object obj, Node node) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a DOM tree.

Parameters
obj:Object

The content tree to be marshalled.

node:Node

DOM nodes will be added as children of this node. This parameter must be a Node that accepts children (org.w3c.dom.Document, org.w3c.dom.DocumentFragment, or org.w3c.dom.Element)

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public void marshal(Object obj, XMLEventWriter writer) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a javax.xml.stream.XMLEventWriter.

Parameters
obj:Object

The content tree rooted at jaxbElement to be marshalled.

writer:XMLEventWriter

XML will be sent to this writer.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public void marshal(Object obj, XMLStreamWriter writer) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

Doc from jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into a javax.xml.stream.XMLStreamWriter.

Parameters
obj:Object

The content tree to be marshalled.

writer:XMLStreamWriter

XML will be sent to this writer.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
setAdapterback to summary
public <A extends XmlAdapter<?, ?>> void setAdapter(A adapter)

Implements jakarta.xml.bind.Marshaller.setAdapter.

Doc from jakarta.xml.bind.Marshaller.setAdapter.

Associates a configured instance of XmlAdapter with this marshaller.

This is a convenience method that invokes setAdapter(adapter.getClass(),adapter);.

Parameters
<A>
the type of the adapter
adapter:A

The instance of the adapter to be used. If null, it will un-register the current adapter set for this type.

Annotations
@Override
@SuppressWarnings:unchecked
setAdapterback to summary
public <A extends XmlAdapter<?, ?>> void setAdapter(Class<A> type, A adapter)

Implements jakarta.xml.bind.Marshaller.setAdapter.

Doc from jakarta.xml.bind.Marshaller.setAdapter.

Associates a configured instance of XmlAdapter with this marshaller.

Every marshaller internally maintains a java.util.Map<Class,XmlAdapter>, which it uses for marshalling classes whose fields/methods are annotated with jakarta.xml.bind.annotation.adapters.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.

Parameters
<A>
the type of the adapter
type:Class<A>

The type of the adapter. The specified instance will be used when jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter#value() refers to this type.

adapter:A

The instance of the adapter to be used. If null, it will un-register the current adapter set for this type.

Annotations
@Override
setAttachmentMarshallerback to summary
public void setAttachmentMarshaller(AttachmentMarshaller am)

Implements jakarta.xml.bind.Marshaller.setAttachmentMarshaller.

Doc from jakarta.xml.bind.Marshaller.setAttachmentMarshaller.

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.

Parameters
am:AttachmentMarshaller

the attachment marshaller to be set

Annotations
@Override
setEncodingback to summary
protected void setEncoding(String encoding)

Convenience method for setting the output encoding.

Parameters
encoding:String

a valid encoding as specified in the Marshaller class documentation

setEventHandlerback to summary
public void setEventHandler(ValidationEventHandler handler) throws JAXBException

Implements jakarta.xml.bind.Marshaller.setEventHandler.

Doc from jakarta.xml.bind.Marshaller.setEventHandler.

Allow an application to register a validation event handler.

The validation event handler will be called by the Jakarta XML Binding 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.

Parameters
handler:ValidationEventHandler

the validation event handler

Annotations
@Override
Exceptions
JAXBException:
if an error was encountered while setting the event handler
See Also
jakarta.xml.bind.Marshaller#setEventHandler(ValidationEventHandler)
setFormattedOutputback to summary
protected void setFormattedOutput(boolean v)

Convenience method for setting the formatted output flag.

Parameters
v:boolean

value of the formatted output flag.

setFragmentback to summary
protected void setFragment(boolean v)

Convenience method for setting the fragment flag.

Parameters
v:boolean

value of the fragment flag.

setListenerback to summary
public void setListener(Marshaller.Listener listener)

Implements jakarta.xml.bind.Marshaller.setListener.

Doc from jakarta.xml.bind.Marshaller.setListener.

Register marshal event callback 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.

Parameters
listener:Marshaller.Listener

an instance of a class that implements Listener

Annotations
@Override
setNoNSSchemaLocationback to summary
protected void setNoNSSchemaLocation(String location)

Convenience method for setting the noNamespaceSchemaLocation.

Parameters
location:String

the noNamespaceSchemaLocation value

setPropertyback to summary
public void setProperty(String name, Object value) throws PropertyException

Implements jakarta.xml.bind.Marshaller.setProperty.

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.

Parameters
name:String

Doc from jakarta.xml.bind.Marshaller.setProperty.

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:Object

Doc from jakarta.xml.bind.Marshaller.setProperty.

the value of the property to be set

Annotations
@Override
Exceptions
PropertyException:

Doc from jakarta.xml.bind.Marshaller.setProperty.

when there is an error processing the given property or value

setSchemaback to summary
public void setSchema(Schema schema)

Implements jakarta.xml.bind.Marshaller.setSchema.

Doc from jakarta.xml.bind.Marshaller.setSchema.

Specify the JAXP 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.

Parameters
schema:Schema

Schema object to validate marshal operations against or null to disable validation

Annotations
@Override
setSchemaLocationback to summary
protected void setSchemaLocation(String location)

Convenience method for setting the schemaLocation.

Parameters
location:String

the schemaLocation value