SPR-7257 - AbstractMarshaller incorrectly expects DOMResult to already have a node

This commit is contained in:
Arjen Poutsma
2010-06-07 13:15:07 +00:00
parent 0dc29cb2d3
commit f72c431e8a
2 changed files with 43 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -189,7 +189,21 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
* @see #marshalDomNode(Object, org.w3c.dom.Node)
*/
protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException {
Assert.notNull(domResult.getNode(), "DOMResult does not contain Node");
if (domResult.getNode() == null) {
try {
synchronized (this.documentBuilderFactoryMonitor) {
if (this.documentBuilderFactory == null) {
this.documentBuilderFactory = createDocumentBuilderFactory();
}
}
DocumentBuilder documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
domResult.setNode(documentBuilder.newDocument());
}
catch (ParserConfigurationException ex) {
throw new UnmarshallingFailureException(
"Could not create document placeholder for DOMResult: " + ex.getMessage(), ex);
}
}
marshalDomNode(graph, domResult.getNode());
}