Author: veithen
Date: Thu Apr 12 18:12:36 2012
New Revision: 1325417

URL: http://svn.apache.org/viewvc?rev=1325417&view=rev
Log:
Fixed a bug in the cloneNode implementation for ElementImpl.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1325417&r1=1325416&r2=1325417&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
 Thu Apr 12 18:12:36 2012
@@ -60,6 +60,8 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.element.TestAttributes3(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAttributes4(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestCloneNode(dbf));
+        addTest(new 
org.apache.axiom.ts.dom.element.TestCloneNodeWithAttributes(dbf, true));
+        addTest(new 
org.apache.axiom.ts.dom.element.TestCloneNodeWithAttributes(dbf, false));
         addTest(new 
org.apache.axiom.ts.dom.element.TestGetElementsByTagName(dbf));
         addTest(new 
org.apache.axiom.ts.dom.element.TestGetElementsByTagNameNS(dbf));
         addTest(new 
org.apache.axiom.ts.dom.element.TestGetElementsByTagNameRecursive(dbf));

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java?rev=1325417&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java
 Thu Apr 12 18:12:36 2012
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that {@link Node#cloneNode(boolean)} correctly clones the attributes 
of an element.
+ */
+public class TestCloneNodeWithAttributes extends DOMTestCase {
+    private final boolean deep;
+    
+    public TestCloneNodeWithAttributes(DocumentBuilderFactory dbf, boolean 
deep) {
+        super(dbf);
+        this.deep = deep;
+        addTestProperty("deep", String.valueOf(deep));
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        Element element = document.createElementNS("urn:ns1", "p:elem");
+        element.setAttributeNS(null, "attr1", "value1");
+        element.setAttributeNS("urn:ns2", "q:attr2", "value2");
+        Element clone = (Element)element.cloneNode(deep);
+        // TODO: this doesn't work with DOOM yet
+//        assertEquals(2, clone.getAttributes().getLength());
+        Attr attr1 = clone.getAttributeNodeNS(null, "attr1");
+        Attr attr2 = clone.getAttributeNodeNS("urn:ns2", "attr2");
+        assertNotNull(attr1);
+        assertNotNull(attr2);
+        assertSame(clone, attr1.getOwnerElement());
+        assertSame(clone, attr2.getOwnerElement());
+        assertEquals("value1", attr1.getValue());
+        assertEquals("value2", attr2.getValue());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java?rev=1325417&r1=1325416&r2=1325417&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
 Thu Apr 12 18:12:36 2012
@@ -29,7 +29,7 @@ import java.util.Vector;
 public class AttributeMap implements NamedNodeMap {
     private Vector nodes;
 
-    private ParentNode ownerNode;
+    private ElementImpl ownerNode;
 
     //
     // Data
@@ -41,7 +41,7 @@ public class AttributeMap implements Nam
 
     private final static short HASDEFAULTS = 0x1 << 2;
                             
-    AttributeMap(ParentNode ownerNode) {
+    AttributeMap(ElementImpl ownerNode) {
         this.ownerNode = ownerNode;
     }
 
@@ -227,8 +227,8 @@ public class AttributeMap implements Nam
      * the nodes contained in the map.
      */
 
-    public AttributeMap cloneMap(NodeImpl ownerNode) {
-        AttributeMap newmap = new AttributeMap((ParentNode) ownerNode);
+    public AttributeMap cloneMap(ElementImpl ownerNode) {
+        AttributeMap newmap = new AttributeMap(ownerNode);
         newmap.hasDefaults(hasDefaults());
         newmap.cloneContent(this);
         return newmap;
@@ -245,10 +245,11 @@ public class AttributeMap implements Nam
                 }
                 nodes.setSize(size);
                 for (int i = 0; i < size; ++i) {
-                    NodeImpl n = (NodeImpl) srcnodes.elementAt(i);
-                    NodeImpl clone = (NodeImpl) n.cloneNode(true);
+                    AttrImpl n = (AttrImpl) srcnodes.elementAt(i);
+                    AttrImpl clone = (AttrImpl) n.cloneNode(true);
                     clone.isSpecified(n.isSpecified());
                     nodes.setElementAt(clone, i);
+                    clone.setOwnerElement(ownerNode);
                 }
             }
         }


Reply via email to