# HG changeset patch # User Sascha L. Teichmann # Date 1366642877 -7200 # Node ID d38004f0c52fc4a432c156d5a93191df424d96ec # Parent efbbfe32e9fe8f3a907d43269a762606be106870 Datacage: Always clone XML template for builders. If the first is not cloned they get interlinked somehow. Feels like a bug in Java's DOM implementation. diff -r efbbfe32e9fe -r d38004f0c52f flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/BuilderPool.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/BuilderPool.java Mon Apr 22 16:18:16 2013 +0200 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/BuilderPool.java Mon Apr 22 17:01:17 2013 +0200 @@ -7,13 +7,9 @@ import java.sql.SQLException; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; - -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; @@ -46,32 +42,29 @@ pool = new ArrayDeque(poolSize); for (int i = 0; i < poolSize; ++i) { - Document doc = i > 0 // Clone all but the first. - ? cloneDocument(document) - : document; - pool.add(new Builder(doc)); + pool.add(new Builder(cloneDocument(document))); } } private final static Document cloneDocument(Document document) { + try { - TransformerFactory tfactory = TransformerFactory.newInstance(); - Transformer xformer = tfactory.newTransformer(); - DOMSource src = new DOMSource(document); - DOMResult dst = new DOMResult(); - xformer.transform(src, dst); - return (Document)dst.getNode(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + Node origRoot = document.getDocumentElement(); + + Document copy = db.newDocument(); + Node copyRoot = copy.importNode(origRoot, true); + copy.appendChild(copyRoot); + + return copy; } - catch (TransformerConfigurationException tce) { - log.error(tce); - } - catch (TransformerException te) { - log.error(te); + catch (ParserConfigurationException pce) { + log.error(pce); } - log.error( - "Returning original DOM document. " + - "This will result in threading errors!"); + log.error("Returning original document. This will lead to threading issues."); return document; }