类 AbstractMarshaller
- java.lang.Object
- org.springframework.oxm.support.AbstractMarshaller
- 所有已实现的接口:
Marshaller,Unmarshaller
public abstract class AbstractMarshaller extends Object implements Marshaller, Unmarshaller
Abstract implementation of theMarshallerandUnmarshallerinterface. This implementation inspects the givenSourceorResult, and delegates further handling to overridable template methods.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller
构造器概要
构造器 构造器 说明 AbstractMarshaller()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected DocumentbuildDocument()Build a newDocumentfrom this marshaller'sDocumentBuilderFactory, as a placeholder for a DOM node.protected DocumentBuildercreateDocumentBuilder(DocumentBuilderFactory factory)Create aDocumentBuilderthat this marshaller will use for creating DOM documents when passed an emptyDOMSource.protected DocumentBuilderFactorycreateDocumentBuilderFactory()Create aDocumentBuilderthat this marshaller will use for creating DOM documents when passed an emptyDOMSource.protected XMLReadercreateXmlReader()Create anXMLReaderthat this marshaller will when passed an emptySAXSource.protected StringgetDefaultEncoding()Determine the default encoding to use for marshalling or unmarshalling from a byte stream, ornullif none.booleanisProcessExternalEntities()Return whether XML external entities are allowed.booleanisSupportDtd()Return whether DTD parsing is supported.voidmarshal(Object graph, Result result)Marshals the object graph with the given root into the providedjavax.xml.transform.Result.protected abstract voidmarshalDomNode(Object graph, Node node)Abstract template method for marshalling the given object graph to a DOMNode.protected voidmarshalDomResult(Object graph, DOMResult domResult)Template method for handlingDOMResults.protected abstract voidmarshalOutputStream(Object graph, OutputStream outputStream)Abstract template method for marshalling the given object graph to aOutputStream.protected abstract voidmarshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)Abstract template method for marshalling the given object graph to a SAXContentHandler.protected voidmarshalSaxResult(Object graph, SAXResult saxResult)Template method for handlingSAXResults.protected voidmarshalStaxResult(Object graph, Result staxResult)Template method for handlingStaxResults.protected voidmarshalStreamResult(Object graph, StreamResult streamResult)Template method for handlingStreamResults.protected abstract voidmarshalWriter(Object graph, Writer writer)Abstract template method for marshalling the given object graph to aWriter.protected abstract voidmarshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)Abstract template method for marshalling the given object to a StAXXMLEventWriter.protected abstract voidmarshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter)Abstract template method for marshalling the given object to a StAXXMLStreamWriter.voidsetProcessExternalEntities(boolean processExternalEntities)Indicate whether external XML entities are processed when unmarshalling.voidsetSupportDtd(boolean supportDtd)Indicate whether DTD parsing should be supported.Objectunmarshal(Source source)Unmarshals the given providedjavax.xml.transform.Sourceinto an object graph.protected abstract ObjectunmarshalDomNode(Node node)Abstract template method for unmarshalling from a given DOMNode.protected ObjectunmarshalDomSource(DOMSource domSource)Template method for handlingDOMSources.protected abstract ObjectunmarshalInputStream(InputStream inputStream)Abstract template method for unmarshalling from a givenInputStream.protected abstract ObjectunmarshalReader(Reader reader)Abstract template method for unmarshalling from a givenReader.protected abstract ObjectunmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)Abstract template method for unmarshalling using a given SAXXMLReaderandInputSource.protected ObjectunmarshalSaxSource(SAXSource saxSource)Template method for handlingSAXSources.protected ObjectunmarshalStaxSource(Source staxSource)Template method for handlingStaxSources.protected ObjectunmarshalStreamSource(StreamSource streamSource)Template method for handlingStreamSources.protected abstract ObjectunmarshalXmlEventReader(XMLEventReader eventReader)Abstract template method for unmarshalling from a given StaxXMLEventReader.protected abstract ObjectunmarshalXmlStreamReader(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
falsemeaning 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 theSourcepassed tounmarshal(Source)is aSAXSourceorStreamSource. It has no effect forDOMSourceorStAXSourceinstances.Note: setting this option to
truealso automatically setssetSupportDtd(boolean)totrue.
isProcessExternalEntities
public boolean isProcessExternalEntities()
Return whether XML external entities are allowed.- 另请参阅:
createXmlReader()
buildDocument
protected Document buildDocument()
Build a newDocumentfrom this marshaller'sDocumentBuilderFactory, as a placeholder for a DOM node.
createDocumentBuilderFactory
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException
Create aDocumentBuilderthat this marshaller will use for creating DOM documents when passed an emptyDOMSource.The resulting
DocumentBuilderFactoryis 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 aDocumentBuilderthat this marshaller will use for creating DOM documents when passed an emptyDOMSource.Can be overridden in subclasses, adding further initialization of the builder.
- 参数:
factory- theDocumentBuilderFactorythat the DocumentBuilder should be created with- 返回:
- the
DocumentBuilder - 抛出:
ParserConfigurationException- if thrown by JAXP methods
createXmlReader
protected XMLReader createXmlReader() throws SAXException
Create anXMLReaderthat 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, ornullif 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- ifresultif 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 handlingDOMResults.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 thedomResultis empty- 另请参阅:
marshalDomNode(Object, org.w3c.dom.Node)
marshalStaxResult
protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException
Template method for handlingStaxResults.This implementation delegates to
marshalXMLSteamWriterormarshalXMLEventConsumer, 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 thedomResultis empty- 另请参阅:
marshalDomNode(Object, org.w3c.dom.Node)
marshalSaxResult
protected void marshalSaxResult(Object graph, SAXResult saxResult) throws XmlMappingException
Template method for handlingSAXResults.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 handlingStreamResults.This implementation delegates to
marshalOutputStreamormarshalWriter, 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- ifstreamResultdoes neither contain anOutputStreamnor aWriter
unmarshal
public final Object unmarshal(Source source) throws IOException, XmlMappingException
Unmarshals the given providedjavax.xml.transform.Sourceinto 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- ifsourceis 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 handlingDOMSources.This implementation delegates to
unmarshalDomNode. If the given source is empty, an empty sourceDocumentwill be created as a placeholder.- 参数:
domSource- theDOMSource- 返回:
- the object graph
- 抛出:
XmlMappingException- if the given source cannot be mapped to an objectIllegalArgumentException- if thedomSourceis empty- 另请参阅:
unmarshalDomNode(org.w3c.dom.Node)
unmarshalStaxSource
protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException
Template method for handlingStaxSources.This implementation delegates to
unmarshalXmlStreamReaderorunmarshalXmlEventReader.- 参数:
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 handlingSAXSources.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 handlingStreamSources.This implementation delegates to
unmarshalInputStreamorunmarshalReader.- 参数:
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
Documentnode, aDocumentFragmentnode, or aElementnode. 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- theXMLEventWriterto 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- theXMLStreamWriterto 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 SAXContentHandlerlexicalHandler- 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- theOutputStreamto 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- theWriterto 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- theXMLEventReaderto 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- theXMLStreamReaderto 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 SAXXMLReaderandInputSource.- 参数:
xmlReader- the SAXXMLReaderto 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- theInputStreamStreamto 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- theReaderto read from- 返回:
- the object graph
- 抛出:
XmlMappingException- if the given reader cannot be converted to an objectIOException- if an I/O exception occurs