Method from org.springframework.oxm.AbstractMarshaller Detail: |
protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory) throws ParserConfigurationException {
return factory.newDocumentBuilder();
}
Create a DocumentBuilder that this marshaller will use for creating DOM documents when passed an
empty DOMSource . Can be overridden in subclasses, adding further initialization of the builder. |
protected DocumentBuilderFactory createDocumentBuilderFactory() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
return factory;
}
Create a DocumentBuilder that this marshaller will use for creating DOM documents when passed an
empty DOMSource . The resulting DocumentBuilderFactory is cached, so this method will
only be called once. |
protected XMLReader createXmlReader() throws SAXException {
return XMLReaderFactory.createXMLReader();
}
Create a XMLReader that this marshaller will when passed an empty SAXSource . |
public final void marshal(Object graph,
Result result) throws XmlMappingException, IOException {
if (result instanceof DOMResult) {
marshalDomResult(graph, (DOMResult) result);
}
else if (TraxUtils.isStaxResult(result)) {
marshalStaxResult(graph, result);
}
else if (result instanceof SAXResult) {
marshalSaxResult(graph, (SAXResult) result);
}
else if (result instanceof StreamResult) {
marshalStreamResult(graph, (StreamResult) result);
}
else {
throw new IllegalArgumentException("Unknown Result type: " + result.getClass());
}
}
Marshals the object graph with the given root into the provided javax.xml.transform.Result .
This implementation inspects the given result, and calls marshalDomResult ,
marshalSaxResult , or marshalStreamResult . |
abstract protected void marshalDomNode(Object graph,
Node node) throws XmlMappingException
Abstract template method for marshalling the given object graph to a DOM Node .
In practice, node is be a Document node, a DocumentFragment node, or a
Element node. In other words, a node that accepts children. |
protected void marshalDomResult(Object graph,
DOMResult domResult) throws XmlMappingException {
Assert.notNull(domResult.getNode(), "DOMResult does not contain Node");
marshalDomNode(graph, domResult.getNode());
}
Template method for handling DOMResult s. This implementation defers to marshalDomNode . |
abstract protected void marshalOutputStream(Object graph,
OutputStream outputStream) throws XmlMappingException, IOException
Abstract template method for marshalling the given object graph to a OutputStream . |
abstract protected void marshalSaxHandlers(Object graph,
ContentHandler contentHandler,
LexicalHandler lexicalHandler) throws XmlMappingException
Abstract template method for marshalling the given object graph to a SAX ContentHandler . |
protected void marshalSaxResult(Object graph,
SAXResult saxResult) throws XmlMappingException {
ContentHandler contentHandler = saxResult.getHandler();
Assert.notNull(contentHandler, "ContentHandler not set on SAXResult");
LexicalHandler lexicalHandler = saxResult.getLexicalHandler();
marshalSaxHandlers(graph, contentHandler, lexicalHandler);
}
Template method for handling SAXResult s. This implementation defers to
marshalSaxHandlers . |
protected void marshalStaxResult(Object graph,
Result staxResult) throws XmlMappingException {
XMLStreamWriter streamWriter = TraxUtils.getXMLStreamWriter(staxResult);
if (streamWriter != null) {
marshalXmlStreamWriter(graph, streamWriter);
}
else {
XMLEventWriter eventWriter = TraxUtils.getXMLEventWriter(staxResult);
if (eventWriter != null) {
marshalXmlEventWriter(graph, eventWriter);
}
else {
throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer");
}
}
}
Template method for handling StaxResult s. This implementation defers to
marshalXMLSteamWriter , or marshalXMLEventConsumer , depending on what is contained in
the StaxResult . |
protected void marshalStreamResult(Object graph,
StreamResult streamResult) throws XmlMappingException, IOException {
if (streamResult.getOutputStream() != null) {
marshalOutputStream(graph, streamResult.getOutputStream());
}
else if (streamResult.getWriter() != null) {
marshalWriter(graph, streamResult.getWriter());
}
else {
throw new IllegalArgumentException("StreamResult contains neither OutputStream nor Writer");
}
}
Template method for handling StreamResult s. This implementation defers to
marshalOutputStream , or marshalWriter , depending on what is contained in the
StreamResult |
abstract protected void marshalWriter(Object graph,
Writer writer) throws XmlMappingException, IOException
Abstract template method for marshalling the given object graph to a Writer . |
abstract protected void marshalXmlEventWriter(Object graph,
XMLEventWriter eventWriter) throws XmlMappingException
Abstract template method for marshalling the given object to a StAX XMLEventWriter . |
abstract protected void marshalXmlStreamWriter(Object graph,
XMLStreamWriter streamWriter) throws XmlMappingException
Abstract template method for marshalling the given object to a StAX XMLStreamWriter . |
public final Object unmarshal(Source source) throws XmlMappingException, IOException {
if (source instanceof DOMSource) {
return unmarshalDomSource((DOMSource) source);
}
else if (TraxUtils.isStaxSource(source)) {
return unmarshalStaxSource(source);
}
else if (source instanceof SAXSource) {
return unmarshalSaxSource((SAXSource) source);
}
else if (source instanceof StreamSource) {
return unmarshalStreamSource((StreamSource) source);
}
else {
throw new IllegalArgumentException("Unknown Source type: " + source.getClass());
}
}
Unmarshals the given provided javax.xml.transform.Source into an object graph.
This implementation inspects the given result, and calls unmarshalDomSource ,
unmarshalSaxSource , or unmarshalStreamSource . |
abstract protected Object unmarshalDomNode(Node node) throws XmlMappingException
Abstract template method for unmarshalling from a given DOM Node . |
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {
if (domSource.getNode() == null) {
try {
if (documentBuilderFactory == null) {
documentBuilderFactory = createDocumentBuilderFactory();
}
DocumentBuilder documentBuilder = createDocumentBuilder(documentBuilderFactory);
domSource.setNode(documentBuilder.newDocument());
}
catch (ParserConfigurationException ex) {
throw new UnmarshallingFailureException(
"Could not create document placeholder for DOMSource: " + ex.getMessage(), ex);
}
}
return unmarshalDomNode(domSource.getNode());
}
Template method for handling DOMSource s. This implementation defers to
unmarshalDomNode . If the given source is empty, an empty source Document will be
created as a placeholder. |
abstract protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException
Abstract template method for unmarshalling from a given InputStream . |
abstract protected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException
Abstract template method for unmarshalling from a given Reader . |
abstract protected Object unmarshalSaxReader(XMLReader xmlReader,
InputSource inputSource) throws XmlMappingException, IOException
Abstract template method for unmarshalling using a given SAX XMLReader and
InputSource . |
protected Object unmarshalSaxSource(SAXSource saxSource) throws XmlMappingException, IOException {
if (saxSource.getXMLReader() == null) {
try {
saxSource.setXMLReader(createXmlReader());
}
catch (SAXException ex) {
throw new UnmarshallingFailureException("Could not create XMLReader for SAXSource: " + ex.getMessage(),
ex);
}
}
if (saxSource.getInputSource() == null) {
saxSource.setInputSource(new InputSource());
}
return unmarshalSaxReader(saxSource.getXMLReader(), saxSource.getInputSource());
}
Template method for handling SAXSource s. This implementation defers to
unmarshalSaxReader . |
protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException {
XMLStreamReader streamReader = TraxUtils.getXMLStreamReader(staxSource);
if (streamReader != null) {
return unmarshalXmlStreamReader(streamReader);
}
else {
XMLEventReader eventReader = TraxUtils.getXMLEventReader(staxSource);
if (eventReader != null) {
return unmarshalXmlEventReader(eventReader);
}
else {
throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader");
}
}
}
Template method for handling StaxSource s. This implementation defers to
unmarshalXmlStreamReader , or unmarshalXmlEventReader . |
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
if (streamSource.getInputStream() != null) {
return unmarshalInputStream(streamSource.getInputStream());
}
else if (streamSource.getReader() != null) {
return unmarshalReader(streamSource.getReader());
}
else {
throw new IllegalArgumentException("StreamSource contains neither InputStream nor Reader");
}
}
Template method for handling StreamSource s. This implementation defers to
unmarshalInputStream , or unmarshalReader . |
abstract protected Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlMappingException
Abstract template method for unmarshalling from a given Stax XMLEventReader . |
abstract protected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException
Abstract template method for unmarshalling from a given Stax XMLStreamReader . |