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(org.apache.xmlbeans.XmlOptions),
XmlOptionsFactoryBeanlogger| Constructor and Description |
|---|
XmlBeansMarshaller() |
| Modifier and Type | Method and Description |
|---|---|
protected XmlMappingException |
convertXmlBeansException(Exception ex,
boolean marshalling)
Convert the given XMLBeans exception to an appropriate exception from the
org.springframework.oxm hierarchy. |
org.apache.xmlbeans.XmlOptions |
getXmlOptions()
Return the
XmlOptions. |
boolean |
isValidating()
Return whether this marshaller should validate in- and outgoing documents.
|
protected void |
marshalDomNode(Object graph,
Node node)
Abstract template method for marshalling the given object graph to a DOM
Node. |
protected void |
marshalOutputStream(Object graph,
OutputStream outputStream)
Abstract template method for marshalling the given object graph to a
OutputStream. |
protected void |
marshalSaxHandlers(Object graph,
ContentHandler contentHandler,
LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAX
ContentHandler. |
protected void |
marshalWriter(Object graph,
Writer writer)
Abstract template method for marshalling the given object graph to a
Writer. |
protected void |
marshalXmlEventWriter(Object graph,
XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAX
XMLEventWriter. |
protected void |
marshalXmlStreamWriter(Object graph,
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(org.apache.xmlbeans.XmlOptions xmlOptions)
Set the
XmlOptions. |
boolean |
supports(Class<?> clazz)
This implementation returns true if the given class is an implementation of
XmlObject. |
protected Object |
unmarshalDomNode(Node node)
Abstract template method for unmarshalling from a given DOM
Node. |
protected Object |
unmarshalInputStream(InputStream inputStream)
Abstract template method for unmarshalling from a given
InputStream. |
protected Object |
unmarshalReader(Reader reader)
Abstract template method for unmarshalling from a given
Reader. |
protected Object |
unmarshalSaxReader(XMLReader xmlReader,
InputSource inputSource)
Abstract template method for unmarshalling using a given SAX
XMLReader
and InputSource. |
protected Object |
unmarshalXmlEventReader(XMLEventReader eventReader)
Abstract template method for unmarshalling from a given Stax
XMLEventReader. |
protected Object |
unmarshalXmlStreamReader(XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given Stax
XMLStreamReader. |
protected void |
validate(org.apache.xmlbeans.XmlObject object)
Validate the given
XmlObject. |
buildDocument, createDocumentBuilder, createDocumentBuilderFactory, createXmlReader, getDefaultEncoding, isProcessExternalEntities, isSupportDtd, marshal, marshalDomResult, marshalSaxResult, marshalStaxResult, marshalStreamResult, setProcessExternalEntities, setSupportDtd, unmarshal, unmarshalDomSource, unmarshalSaxSource, unmarshalStaxSource, unmarshalStreamSourcepublic void setXmlOptions(org.apache.xmlbeans.XmlOptions xmlOptions)
XmlOptions.XmlOptionsFactoryBeanpublic org.apache.xmlbeans.XmlOptions getXmlOptions()
XmlOptions.public void setValidating(boolean validating)
false.public boolean isValidating()
public boolean supports(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 final void marshalDomNode(Object graph, Node node) throws XmlMappingException
AbstractMarshallerNode.
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 AbstractMarshallergraph - 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,
Elementprotected final void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
AbstractMarshallerXMLEventWriter.marshalXmlEventWriter in class AbstractMarshallergraph - the root of the object graph to marshaleventWriter - the XMLEventWriter to write toprotected final void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException
AbstractMarshallerXMLStreamWriter.marshalXmlStreamWriter in class AbstractMarshallergraph - the root of the object graph to marshalstreamWriter - the XMLStreamWriter to write toXmlMappingException - if the given object cannot be marshalled to the DOM nodeprotected final void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException
AbstractMarshallerContentHandler.marshalSaxHandlers in class AbstractMarshallergraph - the root of the object graph to marshalcontentHandler - the SAX ContentHandlerlexicalHandler - the SAX2 LexicalHandler. Can be null.XmlMappingException - if the given object cannot be marshalled to the handlersprotected final void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException
AbstractMarshallerOutputStream.marshalOutputStream in class AbstractMarshallergraph - the root of the object graph to marshaloutputStream - the OutputStream to write toXmlMappingException - if the given object cannot be marshalled to the writerIOException - if an I/O exception occursprotected final void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException
AbstractMarshallerWriter.marshalWriter in class AbstractMarshallergraph - the root of the object graph to marshalwriter - the Writer to write toXmlMappingException - if the given object cannot be marshalled to the writerIOException - if an I/O exception occursprotected final Object unmarshalDomNode(Node node) throws XmlMappingException
AbstractMarshallerNode.unmarshalDomNode in class AbstractMarshallernode - the DOM node that contains the objects to be unmarshalledXmlMappingException - if the given DOM node cannot be mapped to an objectprotected final Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlMappingException
AbstractMarshallerXMLEventReader.unmarshalXmlEventReader in class AbstractMarshallereventReader - the XMLEventReader to read fromXmlMappingException - if the given event reader cannot be converted to an objectprotected final Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException
AbstractMarshallerXMLStreamReader.unmarshalXmlStreamReader in class AbstractMarshallerstreamReader - the XMLStreamReader to read fromXmlMappingException - if the given stream reader cannot be converted to an objectprotected final Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException
AbstractMarshallerXMLReader
and InputSource.unmarshalSaxReader in class AbstractMarshallerxmlReader - the SAX XMLReader to parse withinputSource - the input source to parse fromXmlMappingException - if the given reader and input source cannot be converted to an objectIOException - if an I/O exception occursprotected final Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException
AbstractMarshallerInputStream.unmarshalInputStream in class AbstractMarshallerinputStream - the InputStreamStream to read fromXmlMappingException - if the given stream cannot be converted to an objectIOException - if an I/O exception occursprotected final Object unmarshalReader(Reader reader) throws XmlMappingException, IOException
AbstractMarshallerReader.unmarshalReader in class AbstractMarshallerreader - the Reader to read fromXmlMappingException - if the given reader cannot be converted to an objectIOException - if an I/O exception occursprotected void validate(org.apache.xmlbeans.XmlObject object)
throws ValidationFailureException
XmlObject.object - the xml object to validateValidationFailureException - if the given object is not validprotected XmlMappingException convertXmlBeansException(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