javax.xml.bind.helpers
Class AbstractMarshallerImpl

java.lang.Object
  extended by javax.xml.bind.helpers.AbstractMarshallerImpl
All 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 Marshaller.marshal(Object, javax.xml.transform.Result).

Since:
JAXB1.0
Author:
JSR-31
See Also:
Marshaller

Field Summary
 
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  java.lang.String getEncoding()
          Returns the current output encoding.
 ValidationEventHandler getEventHandler()
          Returns an event handler previously registered by the application.
protected  java.lang.String getJavaEncoding(java.lang.String pEncoding)
          Converts the given IANA encoding name into a Java encoding name.
 org.w3c.dom.Node getNode(java.lang.Object obj)
          This method is unsupported in the default implementation and throws an UnsupportedOperationException.
protected  java.lang.String getNoNSSchemaLocation()
          Returns the marshallers "no namespace" schema location.
 java.lang.Object getProperty(java.lang.String pName)
          Public interface to get the properties defined by the Marshaller interface.
protected  java.lang.String getSchemaLocation()
          Returns the marshallers schema location.
protected  boolean isFormattedOutput()
          Returns whether the marshaller will create formatted output or not.
 void marshal(java.lang.Object pObject, org.xml.sax.ContentHandler pHandler)
          Marshals the given JAXB object by emitting SAX events into into the given SAX ContentHandler.
 void marshal(java.lang.Object pObject, org.w3c.dom.Node pNode)
          Marshals the given JAXB object by creating a DOM tree below the given node.
 void marshal(java.lang.Object pObject, java.io.OutputStream pStream)
          Marshals the given JAXB object pObject and serializes it into the byte stream pTarget.
 void marshal(java.lang.Object pObject, java.io.Writer pWriter)
          Marshals the given JAXB object pObject and serializes it into the character stream pTarget.
protected  void setEncoding(java.lang.String pEncoding)
          Sets the current output encoding.
 void setEventHandler(ValidationEventHandler pHandler)
          Allows the application to set an event handler.
protected  void setFormattedOutput(boolean pFormattedOutput)
          Sets whether the marshaller will create formatted output or not.
protected  void setNoNSSchemaLocation(java.lang.String pNoNSSchemaLocation)
          Sets the marshallers "no namespace" schema location.
 void setProperty(java.lang.String pName, java.lang.Object pValue)
          Public interface to set the properties defined by the Marshaller interface.
protected  void setSchemaLocation(java.lang.String pSchemaLocation)
          Sets the marshallers schema location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.xml.bind.Marshaller
marshal
 

Constructor Detail

AbstractMarshallerImpl

public AbstractMarshallerImpl()

Creates a new instance of AbstractMarshallerImpl.

Method Detail

setEventHandler

public void setEventHandler(ValidationEventHandler pHandler)
                     throws JAXBException
Description copied from interface: Marshaller

Allows the application to set an event handler. The event handler will be invoked in case of a validation event.

Note: The ability to register an event handler does not indicate that a JAXB provider is required to validate the objects being marshalled. If you want to ensure, that only valid objects are marshalled, you should perform an explicit validation using a Validator.

Specified by:
setEventHandler in interface Marshaller
Parameters:
pHandler - An application specific event handler or null to revert to the default event handler. The default handler is throwing an exception in case of errors.
Throws:
JAXBException

getEventHandler

public ValidationEventHandler getEventHandler()
                                       throws JAXBException
Description copied from interface: Marshaller

Returns an event handler previously registered by the application. The event handler will be invoked in case of a validation event.

Note: The ability to register an event handler does not indicate that a JAXB provider is required to validate the objects being marshalled. If you want to ensure, that only valid objects are marshalled, you should perform an explicit validation using a Validator.

Specified by:
getEventHandler in interface Marshaller
Returns:
An event handler previously set by the application or the default event handler. The default handler is simply throwing exceptions.
Throws:
JAXBException - An error occurred while getting the event handler.

setProperty

public void setProperty(java.lang.String pName,
                        java.lang.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
Parameters:
pName - The property name.
Throws:
PropertyException - Unknown property name

getProperty

public java.lang.Object getProperty(java.lang.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
Parameters:
pName - The property name.
Throws:
PropertyException - Unknown property name

getEncoding

protected java.lang.String getEncoding()

Returns the current output encoding.

Returns:
The current encoding, by default "UTF-8".
See Also:
Marshaller.JAXB_ENCODING

getJavaEncoding

protected java.lang.String getJavaEncoding(java.lang.String pEncoding)
                                    throws java.io.UnsupportedEncodingException

Converts the given IANA encoding name into a Java encoding name. This is a helper method for derived subclasses.

Throws:
java.io.UnsupportedEncodingException

setEncoding

protected void setEncoding(java.lang.String pEncoding)

Sets the current output encoding.

See Also:
Marshaller.JAXB_ENCODING

setSchemaLocation

protected void setSchemaLocation(java.lang.String pSchemaLocation)

Sets the marshallers schema location. Defaults to null.

See Also:
Marshaller.JAXB_SCHEMA_LOCATION

getSchemaLocation

protected java.lang.String getSchemaLocation()

Returns the marshallers schema location. Defaults to null.

See Also:
Marshaller.JAXB_SCHEMA_LOCATION

setNoNSSchemaLocation

protected void setNoNSSchemaLocation(java.lang.String pNoNSSchemaLocation)

Sets the marshallers "no namespace" schema location. Defaults to null.

See Also:
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION

getNoNSSchemaLocation

protected java.lang.String getNoNSSchemaLocation()

Returns the marshallers "no namespace" schema location. Defaults to null.

See Also:
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION

setFormattedOutput

protected void setFormattedOutput(boolean pFormattedOutput)

Sets whether the marshaller will create formatted output or not. By default it does.

See Also:
Marshaller.JAXB_FORMATTED_OUTPUT

isFormattedOutput

protected boolean isFormattedOutput()

Returns whether the marshaller will create formatted output or not. By default it does.

See Also:
Marshaller.JAXB_FORMATTED_OUTPUT

marshal

public final void marshal(java.lang.Object pObject,
                          java.io.OutputStream pStream)
                   throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object pObject and serializes it into the byte stream pTarget. Note, that serialization into a byte stream demands the use of an encoding. It may be required to set the parameter Marshaller.JAXB_ENCODING. By default the created output is formatted, which may be turned off using Marshaller.JAXB_FORMATTED_OUTPUT.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pStream - The output byte stream.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested IOException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_ENCODING, Marshaller.JAXB_FORMATTED_OUTPUT, Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public final void marshal(java.lang.Object pObject,
                          java.io.Writer pWriter)
                   throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object pObject and serializes it into the character stream pTarget. Unlike serialization to a byte stream, an encoding is not required, but a Marshaller may use the encoding whether to escape a character or not. Use of the Marshaller.JAXB_ENCODING property is still recommended. By default the created output is formatted, which may be turned off using Marshaller.JAXB_FORMATTED_OUTPUT.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pWriter - The output character stream.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested IOException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_ENCODING, Marshaller.JAXB_FORMATTED_OUTPUT, Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public final void marshal(java.lang.Object pObject,
                          org.xml.sax.ContentHandler pHandler)
                   throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object by emitting SAX events into into the given SAX ContentHandler. This includes the events ContentHandler.startDocument() and ContentHandler.endDocument().

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB Object being marshalled.
pHandler - The target event handler.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested SAXException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

marshal

public final void marshal(java.lang.Object pObject,
                          org.w3c.dom.Node pNode)
                   throws JAXBException
Description copied from interface: Marshaller

Marshals the given JAXB object by creating a DOM tree below the given node.

Specified by:
marshal in interface Marshaller
Parameters:
pObject - The JAXB object being marshalled.
pNode - The target node. This node must be ready to accept a child element. For example, it may be a Document, a DocumentFragment, or an Element.
Throws:
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested DOMException.
MarshalException - Whereever possible, one should prefer the MarshalException over the JAXBException.
See Also:
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

getNode

public org.w3c.dom.Node getNode(java.lang.Object obj)
                         throws JAXBException

This method is unsupported in the default implementation and throws an UnsupportedOperationException.

Specified by:
getNode in interface Marshaller
Parameters:
obj - The JAXB object being viewed.
Throws:
java.lang.UnsupportedOperationException - This method is not available in the default implementation.
JAXBException - An unexpected problem occurred. This may be used, for example, to throw a nested DOMException.