public abstract class

AbstractMarshaller

extends Object
implements Marshaller Unmarshaller
java.lang.Object
   ↳ org.springframework.oxm.support.AbstractMarshaller
Known Direct Subclasses

Class Overview

Abstract implementation of the Marshaller and Unmarshaller interface. This implementation inspects the given Source or Result, and defers further handling to overridable template methods.

Summary

Fields
protected final Log logger Logger available to subclasses.
Public Constructors
AbstractMarshaller()
Public Methods
final void marshal(Object graph, Result result)
Marshals the object graph with the given root into the provided javax.xml.transform.Result.
final Object unmarshal(Source source)
Unmarshals the given provided javax.xml.transform.Source into an object graph.
Protected Methods
DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory)
Create a DocumentBuilder that this marshaller will use for creating DOM documents when passed an empty DOMSource.
DocumentBuilderFactory createDocumentBuilderFactory()
Create a DocumentBuilder that this marshaller will use for creating DOM documents when passed an empty DOMSource.
XMLReader createXmlReader()
Create a XMLReader that this marshaller will when passed an empty SAXSource.
abstract void marshalDomNode(Object graph, Node node)
Abstract template method for marshalling the given object graph to a DOM Node.
void marshalDomResult(Object graph, DOMResult domResult)
Template method for handling DOMResults.
abstract void marshalOutputStream(Object graph, OutputStream outputStream)
Abstract template method for marshalling the given object graph to a OutputStream.
abstract void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAX ContentHandler.
void marshalSaxResult(Object graph, SAXResult saxResult)
Template method for handling SAXResults.
void marshalStaxResult(Object graph, Result staxResult)
Template method for handling StaxResults.
void marshalStreamResult(Object graph, StreamResult streamResult)
Template method for handling StreamResults.
abstract void marshalWriter(Object graph, Writer writer)
Abstract template method for marshalling the given object graph to a Writer.
abstract void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAX XMLEventWriter.
abstract void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAX XMLStreamWriter.
abstract Object unmarshalDomNode(Node node)
Abstract template method for unmarshalling from a given DOM Node.
Object unmarshalDomSource(DOMSource domSource)
Template method for handling DOMSources.
abstract Object unmarshalInputStream(InputStream inputStream)
Abstract template method for unmarshalling from a given InputStream.
abstract Object unmarshalReader(Reader reader)
Abstract template method for unmarshalling from a given Reader.
abstract Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
Abstract template method for unmarshalling using a given SAX XMLReader and InputSource.
Object unmarshalSaxSource(SAXSource saxSource)
Template method for handling SAXSources.
Object unmarshalStaxSource(Source staxSource)
Template method for handling StaxSources.
Object unmarshalStreamSource(StreamSource streamSource)
Template method for handling StreamSources.
abstract Object unmarshalXmlEventReader(XMLEventReader eventReader)
Abstract template method for unmarshalling from a given Stax XMLEventReader.
abstract Object unmarshalXmlStreamReader(XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given Stax XMLStreamReader.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.oxm.Marshaller
From interface org.springframework.oxm.Unmarshaller

Fields

protected final Log logger

Logger available to subclasses.

Public Constructors

public AbstractMarshaller ()

Public Methods

public final void marshal (Object graph, Result result)

Marshals the object graph with the given root into the provided javax.xml.transform.Result.

This implementation inspects the given result, and calls marshalDomResult, marshalSaxResult, or marshalStreamResult.

Parameters
graph the root of the object graph to marshal
result the result to marshal to
Throws
IOException if an I/O exception occurs
XmlMappingException if the given object cannot be marshalled to the result
IllegalArgumentException if result if neither a DOMResult, a SAXResult, nor a StreamResult

public final Object unmarshal (Source source)

Unmarshals the given provided javax.xml.transform.Source into an object graph.

This implementation inspects the given result, and calls unmarshalDomSource, unmarshalSaxSource, or unmarshalStreamSource.

Parameters
source the source to marshal from
Returns
  • the object graph
Throws
IOException if an I/O Exception occurs
XmlMappingException if the given source cannot be mapped to an object
IllegalArgumentException if source is neither a DOMSource, a SAXSource, nor a StreamSource

Protected Methods

protected DocumentBuilder createDocumentBuilder (DocumentBuilderFactory factory)

Create a DocumentBuilder that this marshaller will use for creating DOM documents when passed an empty DOMSource.

Can be overridden in subclasses, adding further initialization of the builder.

Parameters
factory the DocumentBuilderFactory that the DocumentBuilder should be created with
Returns
  • the DocumentBuilder
Throws
ParserConfigurationException if thrown by JAXP methods

protected DocumentBuilderFactory createDocumentBuilderFactory ()

Create a DocumentBuilder that this marshaller will use for creating DOM documents when passed an empty DOMSource.

The resulting DocumentBuilderFactory is cached, so this method will only be called once.

Returns
  • the DocumentBuilderFactory
Throws
ParserConfigurationException if thrown by JAXP methods

protected XMLReader createXmlReader ()

Create a XMLReader that this marshaller will when passed an empty SAXSource.

Returns
  • the XMLReader
Throws
SAXException if thrown by JAXP methods

protected abstract void marshalDomNode (Object graph, Node node)

Abstract template method for marshalling the given object graph to a DOM Node.

In practice, node is be a Document node, a DocumentFragment node, or a Element node. In other words, a node that accepts children.

Parameters
graph the root of the object graph to marshal
node the DOM node that will contain the result tree
Throws
XmlMappingException if the given object cannot be marshalled to the DOM node
See Also
  • org.w3c.dom.Document
  • org.w3c.dom.DocumentFragment
  • Element

protected void marshalDomResult (Object graph, DOMResult domResult)

Template method for handling DOMResults.

This implementation delegates to marshalDomNode.

Parameters
graph the root of the object graph to marshal
domResult the DOMResult
Throws
XmlMappingException if the given object cannot be marshalled to the result
IllegalArgumentException if the domResult is empty

protected abstract void marshalOutputStream (Object graph, OutputStream outputStream)

Abstract template method for marshalling the given object graph to a OutputStream.

Parameters
graph the root of the object graph to marshal
outputStream the OutputStream to write to
Throws
XmlMappingException if the given object cannot be marshalled to the writer
IOException if an I/O exception occurs

protected abstract void marshalSaxHandlers (Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)

Abstract template method for marshalling the given object graph to a SAX ContentHandler.

Parameters
graph the root of the object graph to marshal
contentHandler the SAX ContentHandler
lexicalHandler the SAX2 LexicalHandler. Can be null.
Throws
XmlMappingException if the given object cannot be marshalled to the handlers

protected void marshalSaxResult (Object graph, SAXResult saxResult)

Template method for handling SAXResults.

This implementation delegates to marshalSaxHandlers.

Parameters
graph the root of the object graph to marshal
saxResult the SAXResult
Throws
XmlMappingException if the given object cannot be marshalled to the result

protected void marshalStaxResult (Object graph, Result staxResult)

Template method for handling StaxResults.

This implementation delegates to marshalXMLSteamWriter or marshalXMLEventConsumer, depending on what is contained in the StaxResult.

Parameters
graph the root of the object graph to marshal
staxResult a Spring org.springframework.util.xml.StaxSource or JAXP 1.4 StAXSource
Throws
XmlMappingException if the given object cannot be marshalled to the result
IllegalArgumentException if the domResult is empty

protected void marshalStreamResult (Object graph, StreamResult streamResult)

Template method for handling StreamResults.

This implementation delegates to marshalOutputStream or marshalWriter, depending on what is contained in the StreamResult

Parameters
graph the root of the object graph to marshal
streamResult the StreamResult
Throws
IOException if an I/O Exception occurs
XmlMappingException if the given object cannot be marshalled to the result
IllegalArgumentException if streamResult does neither contain an OutputStream nor a Writer

protected abstract void marshalWriter (Object graph, Writer writer)

Abstract template method for marshalling the given object graph to a Writer.

Parameters
graph the root of the object graph to marshal
writer the Writer to write to
Throws
XmlMappingException if the given object cannot be marshalled to the writer
IOException if an I/O exception occurs

protected abstract void marshalXmlEventWriter (Object graph, XMLEventWriter eventWriter)

Abstract template method for marshalling the given object to a StAX XMLEventWriter.

Parameters
graph the root of the object graph to marshal
eventWriter the XMLEventWriter to write to
Throws
XmlMappingException if the given object cannot be marshalled to the DOM node

protected abstract void marshalXmlStreamWriter (Object graph, XMLStreamWriter streamWriter)

Abstract template method for marshalling the given object to a StAX XMLStreamWriter.

Parameters
graph the root of the object graph to marshal
streamWriter the XMLStreamWriter to write to
Throws
XmlMappingException if the given object cannot be marshalled to the DOM node

protected abstract Object unmarshalDomNode (Node node)

Abstract template method for unmarshalling from a given DOM Node.

Parameters
node the DOM node that contains the objects to be unmarshalled
Returns
  • the object graph
Throws
XmlMappingException if the given DOM node cannot be mapped to an object

protected Object unmarshalDomSource (DOMSource domSource)

Template method for handling DOMSources.

This implementation delegates to unmarshalDomNode. If the given source is empty, an empty source Document will be created as a placeholder.

Parameters
domSource the DOMSource
Returns
  • the object graph
Throws
XmlMappingException if the given source cannot be mapped to an object
IllegalArgumentException if the domSource is empty

protected abstract Object unmarshalInputStream (InputStream inputStream)

Abstract template method for unmarshalling from a given InputStream.

Parameters
inputStream the InputStreamStream to read from
Returns
  • the object graph
Throws
XmlMappingException if the given stream cannot be converted to an object
IOException if an I/O exception occurs

protected abstract Object unmarshalReader (Reader reader)

Abstract template method for unmarshalling from a given Reader.

Parameters
reader the Reader to read from
Returns
  • the object graph
Throws
XmlMappingException if the given reader cannot be converted to an object
IOException if an I/O exception occurs

protected abstract Object unmarshalSaxReader (XMLReader xmlReader, InputSource inputSource)

Abstract template method for unmarshalling using a given SAX XMLReader and InputSource.

Parameters
xmlReader the SAX XMLReader to parse with
inputSource the input source to parse from
Returns
  • the object graph
Throws
XmlMappingException if the given reader and input source cannot be converted to an object
IOException if an I/O exception occurs

protected Object unmarshalSaxSource (SAXSource saxSource)

Template method for handling SAXSources.

This implementation delegates to unmarshalSaxReader.

Parameters
saxSource the SAXSource
Returns
  • the object graph
Throws
XmlMappingException if the given source cannot be mapped to an object
IOException if an I/O Exception occurs

protected Object unmarshalStaxSource (Source staxSource)

Template method for handling StaxSources.

This implementation delegates to unmarshalXmlStreamReader or unmarshalXmlEventReader.

Parameters
staxSource the StaxSource
Returns
  • the object graph
Throws
XmlMappingException if the given source cannot be mapped to an object

protected Object unmarshalStreamSource (StreamSource streamSource)

Template method for handling StreamSources.

This implementation defers to unmarshalInputStream or unmarshalReader.

Parameters
streamSource the StreamSource
Returns
  • the object graph
Throws
IOException if an I/O exception occurs
XmlMappingException if the given source cannot be mapped to an object

protected abstract Object unmarshalXmlEventReader (XMLEventReader eventReader)

Abstract template method for unmarshalling from a given Stax XMLEventReader.

Parameters
eventReader the XMLEventReader to read from
Returns
  • the object graph
Throws
XmlMappingException if the given event reader cannot be converted to an object

protected abstract Object unmarshalXmlStreamReader (XMLStreamReader streamReader)

Abstract template method for unmarshalling from a given Stax XMLStreamReader.

Parameters
streamReader the XMLStreamReader to read from
Returns
  • the object graph
Throws
XmlMappingException if the given stream reader cannot be converted to an object