类 AbstractMarshaller
- java.lang.Object
- org.springframework.oxm.support.AbstractMarshaller
- 所有已实现的接口:
Marshaller
,Unmarshaller
public abstract class AbstractMarshaller extends Object implements Marshaller, Unmarshaller
Abstract implementation of theMarshaller
andUnmarshaller
interface. This implementation inspects the givenSource
orResult
, and delegates further handling to overridable template methods.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
构造器概要
构造器 构造器 说明 AbstractMarshaller()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected Document
buildDocument()
Build a newDocument
from this marshaller'sDocumentBuilderFactory
, as a placeholder for a DOM node.protected DocumentBuilder
createDocumentBuilder(DocumentBuilderFactory factory)
Create aDocumentBuilder
that this marshaller will use for creating DOM documents when passed an emptyDOMSource
.protected DocumentBuilderFactory
createDocumentBuilderFactory()
Create aDocumentBuilder
that this marshaller will use for creating DOM documents when passed an emptyDOMSource
.protected XMLReader
createXmlReader()
Create anXMLReader
that this marshaller will when passed an emptySAXSource
.protected String
getDefaultEncoding()
Determine the default encoding to use for marshalling or unmarshalling from a byte stream, ornull
if none.boolean
isProcessExternalEntities()
Return whether XML external entities are allowed.boolean
isSupportDtd()
Return whether DTD parsing is supported.void
marshal(Object graph, Result result)
Marshals the object graph with the given root into the providedjavax.xml.transform.Result
.protected abstract void
marshalDomNode(Object graph, Node node)
Abstract template method for marshalling the given object graph to a DOMNode
.protected void
marshalDomResult(Object graph, DOMResult domResult)
Template method for handlingDOMResult
s.protected abstract void
marshalOutputStream(Object graph, OutputStream outputStream)
Abstract template method for marshalling the given object graph to aOutputStream
.protected abstract void
marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAXContentHandler
.protected void
marshalSaxResult(Object graph, SAXResult saxResult)
Template method for handlingSAXResult
s.protected void
marshalStaxResult(Object graph, Result staxResult)
Template method for handlingStaxResult
s.protected void
marshalStreamResult(Object graph, StreamResult streamResult)
Template method for handlingStreamResult
s.protected abstract void
marshalWriter(Object graph, Writer writer)
Abstract template method for marshalling the given object graph to aWriter
.protected abstract void
marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAXXMLEventWriter
.protected abstract void
marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAXXMLStreamWriter
.void
setProcessExternalEntities(boolean processExternalEntities)
Indicate whether external XML entities are processed when unmarshalling.void
setSupportDtd(boolean supportDtd)
Indicate whether DTD parsing should be supported.Object
unmarshal(Source source)
Unmarshals the given providedjavax.xml.transform.Source
into an object graph.protected abstract Object
unmarshalDomNode(Node node)
Abstract template method for unmarshalling from a given DOMNode
.protected Object
unmarshalDomSource(DOMSource domSource)
Template method for handlingDOMSource
s.protected abstract Object
unmarshalInputStream(InputStream inputStream)
Abstract template method for unmarshalling from a givenInputStream
.protected abstract Object
unmarshalReader(Reader reader)
Abstract template method for unmarshalling from a givenReader
.protected abstract Object
unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
Abstract template method for unmarshalling using a given SAXXMLReader
andInputSource
.protected Object
unmarshalSaxSource(SAXSource saxSource)
Template method for handlingSAXSource
s.protected Object
unmarshalStaxSource(Source staxSource)
Template method for handlingStaxSource
s.protected Object
unmarshalStreamSource(StreamSource streamSource)
Template method for handlingStreamSource
s.protected abstract Object
unmarshalXmlEventReader(XMLEventReader eventReader)
Abstract template method for unmarshalling from a given StaxXMLEventReader
.protected abstract Object
unmarshalXmlStreamReader(XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given StaxXMLStreamReader
.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.oxm.Marshaller
supports
从接口继承的方法 org.springframework.oxm.Unmarshaller
supports
构造器详细资料
AbstractMarshaller
public AbstractMarshaller()
方法详细资料
setSupportDtd
public void setSupportDtd(boolean supportDtd)
Indicate whether DTD parsing should be supported.Default is
false
meaning that DTD is disabled.
isSupportDtd
public boolean isSupportDtd()
Return whether DTD parsing is supported.
setProcessExternalEntities
public void setProcessExternalEntities(boolean processExternalEntities)
Indicate whether external XML entities are processed when unmarshalling.Default is
false
, meaning that external entities are not resolved. Note that processing of external entities will only be enabled/disabled when theSource
passed tounmarshal(Source)
is aSAXSource
orStreamSource
. It has no effect forDOMSource
orStAXSource
instances.Note: setting this option to
true
also automatically setssetSupportDtd(boolean)
totrue
.
isProcessExternalEntities
public boolean isProcessExternalEntities()
Return whether XML external entities are allowed.- 另请参阅:
createXmlReader()
buildDocument
protected Document buildDocument()
Build a newDocument
from this marshaller'sDocumentBuilderFactory
, as a placeholder for a DOM node.
createDocumentBuilderFactory
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException
Create aDocumentBuilder
that this marshaller will use for creating DOM documents when passed an emptyDOMSource
.The resulting
DocumentBuilderFactory
is cached, so this method will only be called once.- 返回:
- the DocumentBuilderFactory
- 抛出:
ParserConfigurationException
- if thrown by JAXP methods
createDocumentBuilder
protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory) throws ParserConfigurationException
Create aDocumentBuilder
that this marshaller will use for creating DOM documents when passed an emptyDOMSource
.Can be overridden in subclasses, adding further initialization of the builder.
- 参数:
factory
- theDocumentBuilderFactory
that the DocumentBuilder should be created with- 返回:
- the
DocumentBuilder
- 抛出:
ParserConfigurationException
- if thrown by JAXP methods
createXmlReader
protected XMLReader createXmlReader() throws SAXException
Create anXMLReader
that this marshaller will when passed an emptySAXSource
.- 返回:
- the XMLReader
- 抛出:
SAXException
- if thrown by JAXP methods
getDefaultEncoding
protected String getDefaultEncoding()
Determine the default encoding to use for marshalling or unmarshalling from a byte stream, ornull
if none.The default implementation returns
null
.
marshal
public final void marshal(Object graph, Result result) throws IOException, XmlMappingException
Marshals the object graph with the given root into the providedjavax.xml.transform.Result
.This implementation inspects the given result, and calls
marshalDomResult
,marshalSaxResult
, ormarshalStreamResult
.- 指定者:
marshal
在接口中Marshaller
- 参数:
graph
- the root of the object graph to marshalresult
- the result to marshal to- 抛出:
IOException
- if an I/O exception occursXmlMappingException
- if the given object cannot be marshalled to the resultIllegalArgumentException
- ifresult
if neither aDOMResult
, aSAXResult
, nor aStreamResult
- 另请参阅:
marshalDomResult(Object, javax.xml.transform.dom.DOMResult)
,marshalSaxResult(Object, javax.xml.transform.sax.SAXResult)
,marshalStreamResult(Object, javax.xml.transform.stream.StreamResult)
marshalDomResult
protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException
Template method for handlingDOMResult
s.This implementation delegates to
marshalDomNode
.- 参数:
graph
- the root of the object graph to marshaldomResult
- theDOMResult
- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the resultIllegalArgumentException
- if thedomResult
is empty- 另请参阅:
marshalDomNode(Object, org.w3c.dom.Node)
marshalStaxResult
protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException
Template method for handlingStaxResult
s.This implementation delegates to
marshalXMLSteamWriter
ormarshalXMLEventConsumer
, depending on what is contained in theStaxResult
.- 参数:
graph
- the root of the object graph to marshalstaxResult
- a JAXP 1.4StAXSource
- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the resultIllegalArgumentException
- if thedomResult
is empty- 另请参阅:
marshalDomNode(Object, org.w3c.dom.Node)
marshalSaxResult
protected void marshalSaxResult(Object graph, SAXResult saxResult) throws XmlMappingException
Template method for handlingSAXResult
s.This implementation delegates to
marshalSaxHandlers
.- 参数:
graph
- the root of the object graph to marshalsaxResult
- theSAXResult
- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the result- 另请参阅:
marshalSaxHandlers(Object, org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler)
marshalStreamResult
protected void marshalStreamResult(Object graph, StreamResult streamResult) throws XmlMappingException, IOException
Template method for handlingStreamResult
s.This implementation delegates to
marshalOutputStream
ormarshalWriter
, depending on what is contained in theStreamResult
- 参数:
graph
- the root of the object graph to marshalstreamResult
- theStreamResult
- 抛出:
IOException
- if an I/O Exception occursXmlMappingException
- if the given object cannot be marshalled to the resultIllegalArgumentException
- ifstreamResult
does neither contain anOutputStream
nor aWriter
unmarshal
public final Object unmarshal(Source source) throws IOException, XmlMappingException
Unmarshals the given providedjavax.xml.transform.Source
into an object graph.This implementation inspects the given result, and calls
unmarshalDomSource
,unmarshalSaxSource
, orunmarshalStreamSource
.- 指定者:
unmarshal
在接口中Unmarshaller
- 参数:
source
- the source to marshal from- 返回:
- the object graph
- 抛出:
IOException
- if an I/O Exception occursXmlMappingException
- if the given source cannot be mapped to an objectIllegalArgumentException
- ifsource
is neither aDOMSource
, aSAXSource
, nor aStreamSource
- 另请参阅:
unmarshalDomSource(javax.xml.transform.dom.DOMSource)
,unmarshalSaxSource(javax.xml.transform.sax.SAXSource)
,unmarshalStreamSource(javax.xml.transform.stream.StreamSource)
unmarshalDomSource
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException
Template method for handlingDOMSource
s.This implementation delegates to
unmarshalDomNode
. If the given source is empty, an empty sourceDocument
will be created as a placeholder.- 参数:
domSource
- theDOMSource
- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given source cannot be mapped to an objectIllegalArgumentException
- if thedomSource
is empty- 另请参阅:
unmarshalDomNode(org.w3c.dom.Node)
unmarshalStaxSource
protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException
Template method for handlingStaxSource
s.This implementation delegates to
unmarshalXmlStreamReader
orunmarshalXmlEventReader
.- 参数:
staxSource
- theStaxSource
- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given source cannot be mapped to an object
unmarshalSaxSource
protected Object unmarshalSaxSource(SAXSource saxSource) throws XmlMappingException, IOException
Template method for handlingSAXSource
s.This implementation delegates to
unmarshalSaxReader
.- 参数:
saxSource
- theSAXSource
- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given source cannot be mapped to an objectIOException
- if an I/O Exception occurs- 另请参阅:
unmarshalSaxReader(org.xml.sax.XMLReader, org.xml.sax.InputSource)
unmarshalStreamSource
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException
Template method for handlingStreamSource
s.This implementation delegates to
unmarshalInputStream
orunmarshalReader
.- 参数:
streamSource
- theStreamSource
- 返回:
- the object graph
- 抛出:
IOException
- if an I/O exception occursXmlMappingException
- if the given source cannot be mapped to an object
marshalDomNode
protected abstract void marshalDomNode(Object graph, Node node) throws XmlMappingException
Abstract template method for marshalling the given object graph to a DOMNode
.In practice, node is be a
Document
node, aDocumentFragment
node, or aElement
node. In other words, a node that accepts children.- 参数:
graph
- the root of the object graph to marshalnode
- the DOM node that will contain the result tree- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the DOM node- 另请参阅:
Document
,DocumentFragment
,Element
marshalXmlEventWriter
protected abstract void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException
Abstract template method for marshalling the given object to a StAXXMLEventWriter
.- 参数:
graph
- the root of the object graph to marshaleventWriter
- theXMLEventWriter
to write to- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the DOM node
marshalXmlStreamWriter
protected abstract void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException
Abstract template method for marshalling the given object to a StAXXMLStreamWriter
.- 参数:
graph
- the root of the object graph to marshalstreamWriter
- theXMLStreamWriter
to write to- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the DOM node
marshalSaxHandlers
protected abstract void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException
Abstract template method for marshalling the given object graph to a SAXContentHandler
.- 参数:
graph
- the root of the object graph to marshalcontentHandler
- the SAXContentHandler
lexicalHandler
- the SAX2LexicalHandler
. Can benull
.- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the handlers
marshalOutputStream
protected abstract void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException
Abstract template method for marshalling the given object graph to aOutputStream
.- 参数:
graph
- the root of the object graph to marshaloutputStream
- theOutputStream
to write to- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the writerIOException
- if an I/O exception occurs
marshalWriter
protected abstract void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException
Abstract template method for marshalling the given object graph to aWriter
.- 参数:
graph
- the root of the object graph to marshalwriter
- theWriter
to write to- 抛出:
XmlMappingException
- if the given object cannot be marshalled to the writerIOException
- if an I/O exception occurs
unmarshalDomNode
protected abstract Object unmarshalDomNode(Node node) throws XmlMappingException
Abstract template method for unmarshalling from a given DOMNode
.- 参数:
node
- the DOM node that contains the objects to be unmarshalled- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given DOM node cannot be mapped to an object
unmarshalXmlEventReader
protected abstract Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlMappingException
Abstract template method for unmarshalling from a given StaxXMLEventReader
.- 参数:
eventReader
- theXMLEventReader
to read from- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given event reader cannot be converted to an object
unmarshalXmlStreamReader
protected abstract Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException
Abstract template method for unmarshalling from a given StaxXMLStreamReader
.- 参数:
streamReader
- theXMLStreamReader
to read from- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given stream reader cannot be converted to an object
unmarshalSaxReader
protected abstract Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException
Abstract template method for unmarshalling using a given SAXXMLReader
andInputSource
.- 参数:
xmlReader
- the SAXXMLReader
to parse withinputSource
- the input source to parse from- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given reader and input source cannot be converted to an objectIOException
- if an I/O exception occurs
unmarshalInputStream
protected abstract Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException
Abstract template method for unmarshalling from a givenInputStream
.- 参数:
inputStream
- theInputStreamStream
to read from- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given stream cannot be converted to an objectIOException
- if an I/O exception occurs
unmarshalReader
protected abstract Object unmarshalReader(Reader reader) throws XmlMappingException, IOException
Abstract template method for unmarshalling from a givenReader
.- 参数:
reader
- theReader
to read from- 返回:
- the object graph
- 抛出:
XmlMappingException
- if the given reader cannot be converted to an objectIOException
- if an I/O exception occurs