类 JibxMarshaller
- java.lang.Object
- org.springframework.oxm.support.AbstractMarshaller
- org.springframework.oxm.jibx.JibxMarshaller
- 所有已实现的接口:
InitializingBean
,Marshaller
,Unmarshaller
public class JibxMarshaller extends AbstractMarshaller implements InitializingBean
Implementation of theMarshaller
andUnmarshaller
interfaces for JiBX.The typical usage will be to set the
targetClass
and optionally thebindingName
property on this bean.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma
- 另请参阅:
IMarshallingContext
,IUnmarshallingContext
字段概要
从类继承的字段 org.springframework.oxm.support.AbstractMarshaller
logger
构造器概要
构造器 构造器 说明 JibxMarshaller()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.XmlMappingException
convertJibxException(org.jibx.runtime.JiBXException ex, boolean marshalling)
Convert the givenJiBXException
to an appropriate exception from theorg.springframework.oxm
hierarchy.protected org.jibx.runtime.IMarshallingContext
createMarshallingContext()
Create a newIMarshallingContext
, configured with the correct indentation.protected org.jibx.runtime.IUnmarshallingContext
createUnmarshallingContext()
Create a newIUnmarshallingContext
.protected String
getDefaultEncoding()
Determine the default encoding to use for marshalling or unmarshalling from a byte stream, ornull
if none.protected void
marshalDomNode(Object graph, Node node)
Abstract template method for marshalling the given object graph to a DOMNode
.protected void
marshalOutputStream(Object graph, OutputStream outputStream)
Abstract template method for marshalling the given object graph to aOutputStream
.protected void
marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAXContentHandler
.protected void
marshalWriter(Object graph, Writer writer)
Abstract template method for marshalling the given object graph to aWriter
.protected void
marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAXXMLEventWriter
.protected void
marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAXXMLStreamWriter
.void
setBindingName(String bindingName)
Set the optional binding name for this instance.void
setDocTypeInternalSubset(String docTypeInternalSubset)
Set the internal subset Id for the DTD declaration written when marshalling.void
setDocTypePublicId(String docTypePublicId)
Set the public id for the DTD declaration written when marshalling.void
setDocTypeRootElementName(String docTypeRootElementName)
Set the root element name for the DTD declaration written when marshalling.void
setDocTypeSystemId(String docTypeSystemId)
Set the system id for the DTD declaration written when marshalling.void
setEncoding(String encoding)
Set the document encoding using for marshalling.void
setIndent(int indent)
Set the number of nesting indent spaces.void
setStandalone(Boolean standalone)
Set the document standalone flag for marshalling.void
setTargetClass(Class<?> targetClass)
Set the target class for this instance.void
setTargetPackage(String targetPackage)
Set the target package for this instance.boolean
supports(Class<?> clazz)
Indicate whether this marshaller can marshal instances of the supplied type.protected Object
unmarshalDomNode(Node node)
Abstract template method for unmarshalling from a given DOMNode
.protected Object
unmarshalInputStream(InputStream inputStream)
Abstract template method for unmarshalling from a givenInputStream
.protected Object
unmarshalReader(Reader reader)
Abstract template method for unmarshalling from a givenReader
.protected Object
unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
Abstract template method for unmarshalling using a given SAXXMLReader
andInputSource
.protected Object
unmarshalXmlEventReader(XMLEventReader eventReader)
Abstract template method for unmarshalling from a given StaxXMLEventReader
.protected Object
unmarshalXmlStreamReader(XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given StaxXMLStreamReader
.从类继承的方法 org.springframework.oxm.support.AbstractMarshaller
buildDocument, createDocumentBuilder, createDocumentBuilderFactory, createXmlReader, isProcessExternalEntities, isSupportDtd, marshal, marshalDomResult, marshalSaxResult, marshalStaxResult, marshalStreamResult, setProcessExternalEntities, setSupportDtd, unmarshal, unmarshalDomSource, unmarshalSaxSource, unmarshalStaxSource, unmarshalStreamSource
构造器详细资料
JibxMarshaller
public JibxMarshaller()
方法详细资料
setTargetClass
public void setTargetClass(Class<?> targetClass)
Set the target class for this instance. Setting either this property or thetargetPackage
property is required.If this property is set,
targetPackage
is ignored.
setTargetPackage
public void setTargetPackage(String targetPackage)
Set the target package for this instance. Setting either this property or thetargetClass
property is required.If
targetClass
is set, this property is ignored.
setBindingName
public void setBindingName(String bindingName)
Set the optional binding name for this instance.
setIndent
public void setIndent(int indent)
Set the number of nesting indent spaces. Default is-1
, i.e. no indentation.
setEncoding
public void setEncoding(String encoding)
Set the document encoding using for marshalling. Default is UTF-8.
getDefaultEncoding
protected String getDefaultEncoding()
从类复制的说明:AbstractMarshaller
Determine the default encoding to use for marshalling or unmarshalling from a byte stream, ornull
if none.The default implementation returns
null
.
setStandalone
public void setStandalone(Boolean standalone)
Set the document standalone flag for marshalling. By default, this flag is not present.
setDocTypeRootElementName
public void setDocTypeRootElementName(String docTypeRootElementName)
Set the root element name for the DTD declaration written when marshalling. By default, this isnull
(i.e. no DTD declaration is written).If set to a value, the system ID or public ID also need to be set.
setDocTypeSystemId
public void setDocTypeSystemId(String docTypeSystemId)
Set the system id for the DTD declaration written when marshalling. By default, this isnull
. Only used when the root element also has been set.Set either this property or
docTypePublicId
, not both.
setDocTypePublicId
public void setDocTypePublicId(String docTypePublicId)
Set the public id for the DTD declaration written when marshalling. By default, this isnull
. Only used when the root element also has been set.Set either this property or
docTypeSystemId
, not both.
setDocTypeInternalSubset
public void setDocTypeInternalSubset(String docTypeInternalSubset)
Set the internal subset Id for the DTD declaration written when marshalling. By default, this isnull
. Only used when the root element also has been set.
afterPropertiesSet
public void afterPropertiesSet() throws org.jibx.runtime.JiBXException
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
- 抛出:
org.jibx.runtime.JiBXException
supports
public boolean supports(Class<?> clazz)
从接口复制的说明:Marshaller
Indicate whether this marshaller can marshal instances of the supplied type.- 指定者:
supports
在接口中Marshaller
- 指定者:
supports
在接口中Unmarshaller
- 参数:
clazz
- the class that this marshaller is being asked if it can marshal- 返回:
true
if this marshaller can indeed marshal instances of the supplied class;false
otherwise
marshalOutputStream
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException
从类复制的说明:AbstractMarshaller
Abstract template method for marshalling the given object graph to aOutputStream
.- 指定者:
marshalOutputStream
在类中AbstractMarshaller
- 参数:
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 void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException
从类复制的说明:AbstractMarshaller
Abstract template method for marshalling the given object graph to aWriter
.- 指定者:
marshalWriter
在类中AbstractMarshaller
- 参数:
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
marshalDomNode
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException
从类复制的说明:AbstractMarshaller
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.- 指定者:
marshalDomNode
在类中AbstractMarshaller
- 参数:
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 void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
从类复制的说明:AbstractMarshaller
Abstract template method for marshalling the given object to a StAXXMLEventWriter
.- 指定者:
marshalXmlEventWriter
在类中AbstractMarshaller
- 参数:
graph
- the root of the object graph to marshaleventWriter
- theXMLEventWriter
to write to
marshalXmlStreamWriter
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException
从类复制的说明:AbstractMarshaller
Abstract template method for marshalling the given object to a StAXXMLStreamWriter
.- 指定者:
marshalXmlStreamWriter
在类中AbstractMarshaller
- 参数:
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 void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException
从类复制的说明:AbstractMarshaller
Abstract template method for marshalling the given object graph to a SAXContentHandler
.- 指定者:
marshalSaxHandlers
在类中AbstractMarshaller
- 参数:
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
unmarshalXmlEventReader
protected Object unmarshalXmlEventReader(XMLEventReader eventReader)
从类复制的说明:AbstractMarshaller
Abstract template method for unmarshalling from a given StaxXMLEventReader
.- 指定者:
unmarshalXmlEventReader
在类中AbstractMarshaller
- 参数:
eventReader
- theXMLEventReader
to read from- 返回:
- the object graph
unmarshalXmlStreamReader
protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader)
从类复制的说明:AbstractMarshaller
Abstract template method for unmarshalling from a given StaxXMLStreamReader
.- 指定者:
unmarshalXmlStreamReader
在类中AbstractMarshaller
- 参数:
streamReader
- theXMLStreamReader
to read from- 返回:
- the object graph
unmarshalInputStream
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException
从类复制的说明:AbstractMarshaller
Abstract template method for unmarshalling from a givenInputStream
.- 指定者:
unmarshalInputStream
在类中AbstractMarshaller
- 参数:
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 Object unmarshalReader(Reader reader) throws XmlMappingException, IOException
从类复制的说明:AbstractMarshaller
Abstract template method for unmarshalling from a givenReader
.- 指定者:
unmarshalReader
在类中AbstractMarshaller
- 参数:
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
unmarshalDomNode
protected Object unmarshalDomNode(Node node) throws XmlMappingException
从类复制的说明:AbstractMarshaller
Abstract template method for unmarshalling from a given DOMNode
.- 指定者:
unmarshalDomNode
在类中AbstractMarshaller
- 参数:
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
unmarshalSaxReader
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException
从类复制的说明:AbstractMarshaller
Abstract template method for unmarshalling using a given SAXXMLReader
andInputSource
.- 指定者:
unmarshalSaxReader
在类中AbstractMarshaller
- 参数:
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
createMarshallingContext
protected org.jibx.runtime.IMarshallingContext createMarshallingContext() throws org.jibx.runtime.JiBXException
Create a newIMarshallingContext
, configured with the correct indentation.- 返回:
- the created marshalling context
- 抛出:
org.jibx.runtime.JiBXException
- in case of errors
createUnmarshallingContext
protected org.jibx.runtime.IUnmarshallingContext createUnmarshallingContext() throws org.jibx.runtime.JiBXException
Create a newIUnmarshallingContext
.- 返回:
- the created unmarshalling context
- 抛出:
org.jibx.runtime.JiBXException
- in case of errors
convertJibxException
public XmlMappingException convertJibxException(org.jibx.runtime.JiBXException ex, boolean marshalling)
Convert the givenJiBXException
to an appropriate exception from theorg.springframework.oxm
hierarchy.A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since JiBX itself does not make this distinction in its exception hierarchy.
- 参数:
ex
-JiBXException
that occurredmarshalling
- indicates whether the exception occurs during marshalling (true
), or unmarshalling (false
)- 返回:
- the corresponding
XmlMappingException