public class XmlBeansMarshaller extends AbstractMarshaller
Marshaller
interface for Apache XMLBeans.
Options can be set by setting the xmlOptions
property.
The XmlOptionsFactoryBean
is provided to easily set up an XmlOptions
instance.
Unmarshalled objects can be validated by setting the validating
property,
or by calling the validate(XmlObject)
method directly. Invalid objects will
result in an ValidationFailureException
.
NOTE: Due to the nature of XMLBeans, this marshaller requires
all passed objects to be of type XmlObject
.
setValidating(boolean)
,
setXmlOptions(XmlOptions)
,
XmlOptionsFactoryBean
Modifier and Type | Class and Description |
---|---|
private static class |
XmlBeansMarshaller.NonClosingInputStream
See SPR-7034
|
private static class |
XmlBeansMarshaller.NonClosingReader |
Modifier and Type | Field and Description |
---|---|
private boolean |
validating |
private XmlOptions |
xmlOptions |
logger
Constructor and Description |
---|
XmlBeansMarshaller() |
Modifier and Type | Method and Description |
---|---|
protected XmlMappingException |
convertXmlBeansException(java.lang.Exception ex,
boolean marshalling)
Convert the given XMLBeans exception to an appropriate exception from the
org.springframework.oxm hierarchy. |
protected java.lang.String |
getDefaultEncoding() |
XmlOptions |
getXmlOptions()
Return the
XmlOptions . |
boolean |
isValidating()
Return whether this marshaller should validate in- and outgoing documents.
|
protected void |
marshalDomNode(java.lang.Object graph,
org.w3c.dom.Node node)
Abstract template method for marshalling the given object graph to a DOM
Node . |
protected void |
marshalOutputStream(java.lang.Object graph,
java.io.OutputStream outputStream)
Abstract template method for marshalling the given object graph to a
OutputStream . |
protected void |
marshalSaxHandlers(java.lang.Object graph,
org.xml.sax.ContentHandler contentHandler,
org.xml.sax.ext.LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAX
ContentHandler . |
protected void |
marshalWriter(java.lang.Object graph,
java.io.Writer writer)
Abstract template method for marshalling the given object graph to a
Writer . |
protected void |
marshalXmlEventWriter(java.lang.Object graph,
javax.xml.stream.XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAX
XMLEventWriter . |
protected void |
marshalXmlStreamWriter(java.lang.Object graph,
javax.xml.stream.XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAX
XMLStreamWriter . |
void |
setValidating(boolean validating)
Set whether this marshaller should validate in- and outgoing documents.
|
void |
setXmlOptions(XmlOptions xmlOptions)
Set the
XmlOptions . |
boolean |
supports(java.lang.Class<?> clazz)
This implementation returns true if the given class is an implementation of
XmlObject . |
protected java.lang.Object |
unmarshalDomNode(org.w3c.dom.Node node)
Abstract template method for unmarshalling from a given DOM
Node . |
protected java.lang.Object |
unmarshalInputStream(java.io.InputStream inputStream)
Abstract template method for unmarshalling from a given
InputStream . |
protected java.lang.Object |
unmarshalReader(java.io.Reader reader)
Abstract template method for unmarshalling from a given
Reader . |
protected java.lang.Object |
unmarshalSaxReader(org.xml.sax.XMLReader xmlReader,
org.xml.sax.InputSource inputSource)
Abstract template method for unmarshalling using a given SAX
XMLReader
and InputSource . |
protected java.lang.Object |
unmarshalXmlEventReader(javax.xml.stream.XMLEventReader eventReader)
Abstract template method for unmarshalling from a given Stax
XMLEventReader . |
protected java.lang.Object |
unmarshalXmlStreamReader(javax.xml.stream.XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given Stax
XMLStreamReader . |
protected void |
validate(XmlObject object)
Validate the given
XmlObject . |
createDocumentBuilder, createDocumentBuilderFactory, createXmlReader, isProcessExternalEntities, marshal, marshalDomResult, marshalSaxResult, marshalStaxResult, marshalStreamResult, setProcessExternalEntities, unmarshal, unmarshalDomSource, unmarshalSaxSource, unmarshalStaxSource, unmarshalStreamSource, unmarshalStreamSourceNoExternalEntitities
public void setXmlOptions(XmlOptions xmlOptions)
XmlOptions
.XmlOptionsFactoryBean
public XmlOptions getXmlOptions()
XmlOptions
.public void setValidating(boolean validating)
false
.public boolean isValidating()
protected java.lang.String getDefaultEncoding()
getDefaultEncoding
in class AbstractMarshaller
null
.public boolean supports(java.lang.Class<?> clazz)
XmlObject
.clazz
- the class that this marshaller is being asked if it can marshaltrue
if this marshaller can indeed marshal instances of the supplied class;
false
otherwiseprotected void marshalDomNode(java.lang.Object graph, org.w3c.dom.Node node) throws XmlMappingException
AbstractMarshaller
Node
.
In practice, node is be a Document
node, a DocumentFragment
node,
or a Element
node. In other words, a node that accepts children.
marshalDomNode
in class AbstractMarshaller
graph
- the root of the object graph to marshalnode
- the DOM node that will contain the result treeXmlMappingException
- if the given object cannot be marshalled to the DOM nodeDocument
,
DocumentFragment
,
Element
protected void marshalXmlEventWriter(java.lang.Object graph, javax.xml.stream.XMLEventWriter eventWriter)
AbstractMarshaller
XMLEventWriter
.marshalXmlEventWriter
in class AbstractMarshaller
graph
- the root of the object graph to marshaleventWriter
- the XMLEventWriter
to write toprotected void marshalXmlStreamWriter(java.lang.Object graph, javax.xml.stream.XMLStreamWriter streamWriter) throws XmlMappingException
AbstractMarshaller
XMLStreamWriter
.marshalXmlStreamWriter
in class AbstractMarshaller
graph
- the root of the object graph to marshalstreamWriter
- the XMLStreamWriter
to write toXmlMappingException
- if the given object cannot be marshalled to the DOM nodeprotected void marshalSaxHandlers(java.lang.Object graph, org.xml.sax.ContentHandler contentHandler, org.xml.sax.ext.LexicalHandler lexicalHandler) throws XmlMappingException
AbstractMarshaller
ContentHandler
.marshalSaxHandlers
in class AbstractMarshaller
graph
- the root of the object graph to marshalcontentHandler
- the SAX ContentHandler
lexicalHandler
- the SAX2 LexicalHandler
. Can be null
.XmlMappingException
- if the given object cannot be marshalled to the handlersprotected void marshalOutputStream(java.lang.Object graph, java.io.OutputStream outputStream) throws XmlMappingException, java.io.IOException
AbstractMarshaller
OutputStream
.marshalOutputStream
in class AbstractMarshaller
graph
- the root of the object graph to marshaloutputStream
- the OutputStream
to write toXmlMappingException
- if the given object cannot be marshalled to the writerjava.io.IOException
- if an I/O exception occursprotected void marshalWriter(java.lang.Object graph, java.io.Writer writer) throws XmlMappingException, java.io.IOException
AbstractMarshaller
Writer
.marshalWriter
in class AbstractMarshaller
graph
- the root of the object graph to marshalwriter
- the Writer
to write toXmlMappingException
- if the given object cannot be marshalled to the writerjava.io.IOException
- if an I/O exception occursprotected java.lang.Object unmarshalDomNode(org.w3c.dom.Node node) throws XmlMappingException
AbstractMarshaller
Node
.unmarshalDomNode
in class AbstractMarshaller
node
- the DOM node that contains the objects to be unmarshalledXmlMappingException
- if the given DOM node cannot be mapped to an objectprotected java.lang.Object unmarshalXmlEventReader(javax.xml.stream.XMLEventReader eventReader) throws XmlMappingException
AbstractMarshaller
XMLEventReader
.unmarshalXmlEventReader
in class AbstractMarshaller
eventReader
- the XMLEventReader
to read fromXmlMappingException
- if the given event reader cannot be converted to an objectprotected java.lang.Object unmarshalXmlStreamReader(javax.xml.stream.XMLStreamReader streamReader) throws XmlMappingException
AbstractMarshaller
XMLStreamReader
.unmarshalXmlStreamReader
in class AbstractMarshaller
streamReader
- the XMLStreamReader
to read fromXmlMappingException
- if the given stream reader cannot be converted to an objectprotected java.lang.Object unmarshalSaxReader(org.xml.sax.XMLReader xmlReader, org.xml.sax.InputSource inputSource) throws XmlMappingException, java.io.IOException
AbstractMarshaller
XMLReader
and InputSource
.unmarshalSaxReader
in class AbstractMarshaller
xmlReader
- the SAX XMLReader
to parse withinputSource
- the input source to parse fromXmlMappingException
- if the given reader and input source cannot be converted to an objectjava.io.IOException
- if an I/O exception occursprotected java.lang.Object unmarshalInputStream(java.io.InputStream inputStream) throws XmlMappingException, java.io.IOException
AbstractMarshaller
InputStream
.unmarshalInputStream
in class AbstractMarshaller
inputStream
- the InputStreamStream
to read fromXmlMappingException
- if the given stream cannot be converted to an objectjava.io.IOException
- if an I/O exception occursprotected java.lang.Object unmarshalReader(java.io.Reader reader) throws XmlMappingException, java.io.IOException
AbstractMarshaller
Reader
.unmarshalReader
in class AbstractMarshaller
reader
- the Reader
to read fromXmlMappingException
- if the given reader cannot be converted to an objectjava.io.IOException
- if an I/O exception occursprotected void validate(XmlObject object) throws ValidationFailureException
XmlObject
.object
- the xml object to validateValidationFailureException
- if the given object is not validprotected XmlMappingException convertXmlBeansException(java.lang.Exception ex, boolean marshalling)
org.springframework.oxm
hierarchy.
A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since XMLBeans itself does not make this distinction in its exception hierarchy.
ex
- XMLBeans Exception that occuredmarshalling
- indicates whether the exception occurs during marshalling (true
),
or unmarshalling (false
)XmlMappingException