You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2011/09/07 18:43:02 UTC

svn commit: r1166257 - /axis/axis2/java/rampart/trunk/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java

Author: veithen
Date: Wed Sep  7 16:43:02 2011
New Revision: 1166257

URL: http://svn.apache.org/viewvc?rev=1166257&view=rev
Log:
Prefer adoptNode over importNode in order to avoid making unnecessary copies of DOM trees.

Modified:
    axis/axis2/java/rampart/trunk/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java

Modified: axis/axis2/java/rampart/trunk/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/rampart/trunk/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java?rev=1166257&r1=1166256&r2=1166257&view=diff
==============================================================================
--- axis/axis2/java/rampart/trunk/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java (original)
+++ axis/axis2/java/rampart/trunk/modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java Wed Sep  7 16:43:02 2011
@@ -808,6 +808,25 @@ public class RampartUtil {
         return id;
     }
     
+    /**
+     * Change the owner document of the given node. The method first attempts to move the node using
+     * {@link Document#adoptNode(Node)}. If that fails, it will import the node into the target
+     * document using {@link Document#importNode(Node, boolean)}.
+     * 
+     * @param targetDocument
+     *            the target document
+     * @param node
+     *            the node to adopt or import
+     * @return the adopted or imported node
+     */
+    public static Node adoptNode(Document targetDocument, Node node) {
+        Node result = targetDocument.adoptNode(node);
+        if (result == null) {
+            result = targetDocument.importNode(node, true);
+        }
+        return result;
+    }
+    
     public static Element appendChildToSecHeader(RampartMessageData rmd,
             OMElement elem) {
         return appendChildToSecHeader(rmd, (Element)elem);
@@ -816,8 +835,7 @@ public class RampartUtil {
     public static Element appendChildToSecHeader(RampartMessageData rmd,
             Element elem) {
         Element secHeaderElem = rmd.getSecHeader().getSecurityHeader();
-        Node node = secHeaderElem.getOwnerDocument().importNode(
-                        elem, true);
+        Node node = adoptNode(secHeaderElem.getOwnerDocument(), elem);
         return (Element)secHeaderElem.appendChild(node);
     }