Top Description Fields Constructors Methods
org.glassfish.jaxb.runtime.v2.runtime

public final Class MarshallerImpl

extends AbstractMarshallerImpl
implements ValidationEventHandler
Class Inheritance
All Implemented Interfaces
jakarta.xml.bind.ValidationEventHandler
Imports
org.glassfish.jaxb.core.marshaller.*, org.glassfish.jaxb.runtime.api.JAXBRIContext, org.glassfish.jaxb.runtime.marshaller.NamespacePrefixMapper, .NioEscapeHandler, org.glassfish.jaxb.runtime.v2.runtime.output.*, org.glassfish.jaxb.runtime.v2.util.FatalAdapter, jakarta.xml.bind.*, jakarta.xml.bind.annotation.adapters.XmlAdapter, jakarta.xml.bind.attachment.AttachmentMarshaller, jakarta.xml.bind.helpers.AbstractMarshallerImpl, org.w3c.dom.Document, .Node, org.xml.sax.SAXException, org.xml.sax.helpers.XMLFilterImpl, javax.xml.namespace.NamespaceContext, javax.xml.stream.XMLEventWriter, .XMLStreamException, .XMLStreamWriter, javax.xml.transform.Result, javax.xml.transform.dom.DOMResult, javax.xml.transform.sax.SAXResult, javax.xml.transform.stream.StreamResult, javax.xml.validation.Schema, .ValidatorHandler, java.io.*, java.net.URI, .URISyntaxException, java.util.logging.Level, .Logger

Implementation of Marshaller interface for the JAXB RI.

Eventually all the marshal methods call into the write method.

Authors
Kohsuke Kawaguchi, Vivek Pandey

Field Summary

Modifier and TypeField and Description
protected static final String
private boolean
c14nSupport

Configured for c14n?

pack-priv final JAXBContextImpl
context

reference to the context that created this object

protected static final String
protected static final String
private CharacterEscapeHandler
escapeHandler

Object that handles character escaping.

private Marshaller.Listener
externalListener

Marshaller.Listener

private String
header

XML BLOB written after the XML declaration.

private String
indent

Indentation string.

protected static final String
private static final Logger
protected static final String
protected static final String
private NamespacePrefixMapper
prefixMapper

Used to assign prefixes to namespace URIs.

private Schema
schema

Non-null if we do the marshal-time validation.

protected final XMLSerializer
private Closeable
private Flushable
protected static final String
protected static final String

Constructor Summary

AccessConstructor and Description
public
MarshallerImpl(JAXBContextImpl c, AssociationMap<XmlNode>
non-null if the marshaller is working inside BinderImpl.
assoc
)

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
protected CharacterEscapeHandler
pack-priv Runnable
createPostInitAction(Result result)

Creates an appropriate post-init action object.

public XmlOutput
createWriter(Writer w, String encoding)

public XmlOutput
public XmlOutput
public XmlOutput
pack-priv XmlOutput
createXmlOutput(Result result)

Creates XmlOutput from the given Result object.

public <A extends XmlAdapter<?, ?>> A
getAdapter(Class<A> type)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getAdapter.

Implements jakarta.xml.bind.Marshaller.getAdapter.

Gets the adapter associated with the specified type.

public AttachmentMarshaller
public JAXBContextImpl
pack-priv CharacterEscapeHandler

Returns:

escape handler
getEscapeHandler
()

Returns escape handler provided with JAXB context parameters.

public Marshaller.Listener
public Object
getProperty(String name)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getProperty.

Implements jakarta.xml.bind.Marshaller.getProperty.

Default implementation of the getProperty method handles the four defined properties in Marshaller.

public Schema
getSchema()

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getSchema.

Implements jakarta.xml.bind.Marshaller.getSchema.

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

public boolean
handleEvent(ValidationEvent event)

Implements jakarta.xml.bind.ValidationEventHandler.handleEvent.

Default error handling behavior fot Marshaller.

public void
marshal(Object obj, OutputStream out, NamespaceContext inscopeNamespace)

Marshals to OutputStream with the given in-scope namespaces taken into account.

public void
public void
public void
marshal(Object obj, XmlOutput output)

public void
marshal(Object target, Result result)

Implements jakarta.xml.bind.Marshaller.marshal.

Marshal the content tree rooted at jaxbElement into the specified javax.xml.transform.Result.

private void
private void
prewrite(XmlOutput out, boolean fragment, Runnable postInitAction)

public <A extends XmlAdapter<?, ?>> void
setAdapter(Class<A> type, A adapter)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setAdapter.

Implements jakarta.xml.bind.Marshaller.setAdapter.

Associates a configured instance of XmlAdapter with this marshaller.

public void
setAttachmentMarshaller(AttachmentMarshaller am)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setAttachmentMarshaller.

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.

public void
public void
setProperty(String name, Object value)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setProperty.

Implements jakarta.xml.bind.Marshaller.setProperty.

Default implementation of the setProperty method handles the four defined properties in Marshaller.

public void
setSchema(Schema s)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setSchema.

Implements jakarta.xml.bind.Marshaller.setSchema.

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

private void
write(Object obj, XmlOutput out, Runnable postInitAction)

All the marshal method invocation eventually comes down to this call.

Inherited from jakarta.xml.bind.helpers.AbstractMarshallerImpl:
getEncodinggetEventHandlergetJavaEncodinggetNodegetNoNSSchemaLocationgetSchemaLocationisFormattedOutputisFragmentmarshalmarshalmarshalmarshalmarshalsetAdaptersetEncodingsetEventHandlersetFormattedOutputsetFragmentsetNoNSSchemaLocationsetSchemaLocation

Field Detail

C14Nback to summary
protected static final String C14N
c14nSupportback to summary
private boolean c14nSupport

Configured for c14n?

contextback to summary
pack-priv final JAXBContextImpl context

reference to the context that created this object

ENCODING_HANDLERback to summary
protected static final String ENCODING_HANDLER
ENCODING_HANDLER2back to summary
protected static final String ENCODING_HANDLER2
escapeHandlerback to summary
private CharacterEscapeHandler escapeHandler

Object that handles character escaping.

externalListenerback to summary
private Marshaller.Listener externalListener

Marshaller.Listener

indentback to summary
private String indent

Indentation string. Default is four whitespaces.

INDENT_STRINGback to summary
protected static final String INDENT_STRING
LOGGERback to summary
private static final Logger LOGGER
OBJECT_IDENTITY_CYCLE_DETECTIONback to summary
protected static final String OBJECT_IDENTITY_CYCLE_DETECTION
PREFIX_MAPPERback to summary
protected static final String PREFIX_MAPPER
prefixMapperback to summary
private NamespacePrefixMapper prefixMapper

Used to assign prefixes to namespace URIs.

schemaback to summary
private Schema schema

Non-null if we do the marshal-time validation.

serializerback to summary
protected final XMLSerializer serializer
toBeClosedback to summary
private Closeable toBeClosed
toBeFlushedback to summary
private Flushable toBeFlushed
XML_HEADERSback to summary
protected static final String XML_HEADERS
XMLDECLARATIONback to summary
protected static final String XMLDECLARATION

Constructor Detail

MarshallerImplback to summary
public MarshallerImpl(JAXBContextImpl c, AssociationMap<XmlNode> assoc)
Parameters
assoc:AssociationMap<XmlNode>

non-null if the marshaller is working inside BinderImpl.

Method Detail

checkBooleanback to summary
private void checkBoolean(String name, Object value) throws PropertyException

Hides jakarta.xml.bind.helpers.AbstractMarshallerImpl.checkBoolean.

checkStringback to summary
private void checkString(String name, Object value) throws PropertyException

Hides jakarta.xml.bind.helpers.AbstractMarshallerImpl.checkString.

cleanUpback to summary
private void cleanUp()
createEscapeHandlerback to summary
protected CharacterEscapeHandler createEscapeHandler(String encoding)
createPostInitActionback to summary
pack-priv Runnable createPostInitAction(Result result)

Creates an appropriate post-init action object.

createWriterback to summary
public XmlOutput createWriter(Writer w, String encoding)
createWriterback to summary
public XmlOutput createWriter(Writer w)
createWriterback to summary
public XmlOutput createWriter(OutputStream os) throws JAXBException
createWriterback to summary
public XmlOutput createWriter(OutputStream os, String encoding) throws JAXBException
createXmlOutputback to summary
pack-priv XmlOutput createXmlOutput(Result result) throws JAXBException

Creates XmlOutput from the given Result object.

getAdapterback to summary
public <A extends XmlAdapter<?, ?>> A getAdapter(Class<A> type)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getAdapter.

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.

Annotations
@Override
getAttachmentMarshallerback to summary
public AttachmentMarshaller getAttachmentMarshaller()

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getAttachmentMarshaller.

Implements jakarta.xml.bind.Marshaller.getAttachmentMarshaller.

Annotations
@Override
getContextback to summary
public JAXBContextImpl getContext()
getEscapeHandlerback to summary
pack-priv CharacterEscapeHandler getEscapeHandler()

Returns escape handler provided with JAXB context parameters.

Returns:CharacterEscapeHandler

escape handler

getListenerback to summary
public Marshaller.Listener getListener()

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getListener.

Implements jakarta.xml.bind.Marshaller.getListener.

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

Return Listener registered with this Marshaller.

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

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.getProperty.

Implements jakarta.xml.bind.Marshaller.getProperty.

Doc from jakarta.xml.bind.helpers.AbstractMarshallerImpl.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.

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()

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.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.

Annotations
@Override
handleEventback to summary
public boolean handleEvent(ValidationEvent event)

Implements jakarta.xml.bind.ValidationEventHandler.handleEvent.

Default error handling behavior fot Marshaller.

Annotations
@Override
marshalback to summary
public void marshal(Object obj, OutputStream out, NamespaceContext inscopeNamespace) throws JAXBException

Marshals to OutputStream with the given in-scope namespaces taken into account.

Since
2.1.5
marshalback to summary
public void marshal(Object obj, XMLStreamWriter writer) throws JAXBException

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.marshal.

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.

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

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.marshal.

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.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
marshalback to summary
public void marshal(Object obj, XmlOutput output) throws JAXBException
marshalback to summary
public void marshal(Object target, Result result) throws JAXBException

Implements jakarta.xml.bind.Marshaller.marshal.

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

Marshal the content tree rooted at jaxbElement into the specified javax.xml.transform.Result.

All Jakarta XML Binding Providers must at least support javax.xml.transform.dom.DOMResult, javax.xml.transform.sax.SAXResult, and javax.xml.transform.stream.StreamResult. It can support other derived classes of Result as well.

Annotations
@Override
Exceptions
JAXBException:
If any unexpected problem occurs during the marshalling.
postwriteback to summary
private void postwrite() throws IOException, SAXException, XMLStreamException
prewriteback to summary
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException
setAdapterback to summary
public <A extends XmlAdapter<?, ?>> void setAdapter(Class<A> type, A adapter)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setAdapter.

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.

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

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setAttachmentMarshaller.

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.

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

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setListener.

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.

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

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setProperty.

Implements jakarta.xml.bind.Marshaller.setProperty.

Doc from jakarta.xml.bind.helpers.AbstractMarshallerImpl.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.

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 s)

Overrides jakarta.xml.bind.helpers.AbstractMarshallerImpl.setSchema.

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.

Annotations
@Override
writeback to summary
protected <T> void write(Name rootTagName, JaxBeanInfo<T> bi, T obj, XmlOutput out, Runnable postInitAction) throws JAXBException

Used by BridgeImpl to write an arbitrary object as a fragment.

writeback to summary
private void write(Object obj, XmlOutput out, Runnable postInitAction) throws JAXBException

All the marshal method invocation eventually comes down to this call.