javax.xml.bind.helpers

Class AbstractMarshallerImpl

Implemented Interfaces:
Marshaller

public abstract class AbstractMarshallerImpl
extends java.lang.Object
implements Marshaller

Default implementation of a Marshaller. The JAXB provider needs to implement only javax.xml.bind.Marshaller.marshal(Object, javax.xml.transform.Result).
Author:
JSR-31
Since:
JAXB1.0
See Also:
Marshaller

Fields inherited from interface javax.xml.bind.Marshaller

JAXB_ENCODING, JAXB_FORMATTED_OUTPUT, JAXB_NO_NAMESPACE_SCHEMA_LOCATION, JAXB_SCHEMA_LOCATION

Constructor Summary

AbstractMarshallerImpl()
Creates a new instance of AbstractMarshallerImpl.

Method Summary

protected String
getEncoding()
Returns the current output encoding.
ValidationEventHandler
getEventHandler()
protected String
getJavaEncoding(String pEncoding)
Converts the given IANA encoding name into a Java encoding name.
protected String
getNoNSSchemaLocation()
Returns the marshallers "no namespace" schema location.
Node
getNode(Object obj)
This method is unsupported in the default implementation and throws an UnsupportedOperationException.
Object
getProperty(String pName)
Public interface to get the properties defined by the Marshaller interface.
protected String
getSchemaLocation()
Returns the marshallers schema location.
protected boolean
isFormattedOutput()
Returns whether the marshaller will create formatted output or not.
void
marshal(Object pObject, ContentHandler pHandler)
void
marshal(Object pObject, Node pNode)
void
marshal(Object pObject, OutputStream pStream)
void
marshal(Object pObject, Writer pWriter)
protected void
setEncoding(String pEncoding)
Sets the current output encoding.
void
setEventHandler(ValidationEventHandler pHandler)
protected void
setFormattedOutput(boolean pFormattedOutput)
Sets whether the marshaller will create formatted output or not.
protected void
setNoNSSchemaLocation(String pNoNSSchemaLocation)
Sets the marshallers "no namespace" schema location.
void
setProperty(String pName, Object pValue)
Public interface to set the properties defined by the Marshaller interface.
protected void
setSchemaLocation(String pSchemaLocation)
Sets the marshallers schema location.

Constructor Details

AbstractMarshallerImpl

public AbstractMarshallerImpl()
Creates a new instance of AbstractMarshallerImpl.

Method Details

getEncoding

protected String getEncoding()
Returns the current output encoding.
Returns:
The current encoding, by default "UTF-8".

getEventHandler

public ValidationEventHandler getEventHandler()
            throws JAXBException
Specified by:
getEventHandler in interface Marshaller

getJavaEncoding

protected String getJavaEncoding(String pEncoding)
            throws UnsupportedEncodingException
Converts the given IANA encoding name into a Java encoding name. This is a helper method for derived subclasses.

getNoNSSchemaLocation

protected String getNoNSSchemaLocation()
Returns the marshallers "no namespace" schema location. Defaults to null.

getNode

public Node getNode(Object obj)
            throws JAXBException
This method is unsupported in the default implementation and throws an UnsupportedOperationException.
Specified by:
getNode in interface Marshaller

getProperty

public Object getProperty(String pName)
            throws PropertyException
Public interface to get the properties defined by the Marshaller interface. Works by invocation of getEncoding(), isFormattedOutput(), getNoNSSchemaLocation(), and getSchemaLocation() internally.

If you want to support additional properties, you have to override this method in a subclass.

Specified by:
getProperty in interface Marshaller
Throws:
PropertyException - Unknown property name

getSchemaLocation

protected String getSchemaLocation()
Returns the marshallers schema location. Defaults to null.

isFormattedOutput

protected boolean isFormattedOutput()
Returns whether the marshaller will create formatted output or not. By default it does.

marshal

public final void marshal(Object pObject,
                          ContentHandler pHandler)
            throws JAXBException
Specified by:
marshal in interface Marshaller

marshal

public final void marshal(Object pObject,
                          Node pNode)
            throws JAXBException
Specified by:
marshal in interface Marshaller

marshal

public final void marshal(Object pObject,
                          OutputStream pStream)
            throws JAXBException
Specified by:
marshal in interface Marshaller

marshal

public final void marshal(Object pObject,
                          Writer pWriter)
            throws JAXBException
Specified by:
marshal in interface Marshaller

setEncoding

protected void setEncoding(String pEncoding)
Sets the current output encoding.

setEventHandler

public void setEventHandler(ValidationEventHandler pHandler)
            throws JAXBException
Specified by:
setEventHandler in interface Marshaller

setFormattedOutput

protected void setFormattedOutput(boolean pFormattedOutput)
Sets whether the marshaller will create formatted output or not. By default it does.

setNoNSSchemaLocation

protected void setNoNSSchemaLocation(String pNoNSSchemaLocation)
Sets the marshallers "no namespace" schema location. Defaults to null.

setProperty

public void setProperty(String pName,
                        Object pValue)
            throws PropertyException
Public interface to set the properties defined by the Marshaller interface. Works by invocation of setEncoding(String), setFormattedOutput(boolean), setNoNSSchemaLocation(String), and setSchemaLocation(String) internally.

If you want to support additional properties, you have to override this method in a subclass.

Specified by:
setProperty in interface Marshaller
Throws:
PropertyException - Unknown property name

setSchemaLocation

protected void setSchemaLocation(String pSchemaLocation)
Sets the marshallers schema location. Defaults to null.