You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/12/20 16:55:27 UTC

svn commit: r1424548 [3/5] - in /webservices/axiom/branches/AXIOM-201: ./ etc/ legal/ modules/axiom-all/ modules/axiom-api/ modules/axiom-api/src/main/java/org/apache/axiom/om/ modules/axiom-api/src/main/java/org/apache/axiom/om/dom/ modules/axiom-api/...

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java Thu Dec 20 15:55:24 2012
@@ -18,12 +18,28 @@
  */
 package org.apache.axiom.ts.dom;
 
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.axiom.testutils.conformance.ConformanceTestFile;
 import org.apache.axiom.testutils.suite.TestSuiteBuilder;
 
 public class DOMTestSuiteBuilder extends TestSuiteBuilder {
+    private static final QName[] validAttrQNames = new QName[] {
+        new QName("urn:ns2", "attr", "q"),
+        new QName("", "attr", ""),
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "ns", XMLConstants.XMLNS_ATTRIBUTE),
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, ""),
+    };
+    
+    private static final QName[] invalidAttrQNames = new QName[] {
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "attr", ""),
+        new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "attr", "p"),
+        new QName("urn:test", "p", XMLConstants.XMLNS_ATTRIBUTE),
+        new QName("", XMLConstants.XMLNS_ATTRIBUTE, ""),
+    };
+    
     private final DocumentBuilderFactory dbf;
     
     public DOMTestSuiteBuilder(DocumentBuilderFactory dbf) {
@@ -37,6 +53,8 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.attr.TestGetChildNodes(dbf));
         addTest(new org.apache.axiom.ts.dom.attr.TestGetFirstChild(dbf));
         addTest(new org.apache.axiom.ts.dom.attr.TestGetValueWithMultipleChildren(dbf));
+        addTest(new org.apache.axiom.ts.dom.attr.TestLookupNamespaceURI(dbf));
+        addTest(new org.apache.axiom.ts.dom.attr.TestLookupNamespaceURIWithoutOwnerElement(dbf));
         addTest(new org.apache.axiom.ts.dom.attr.TestSetPrefixNotNullWithNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.attr.TestSetPrefixNotNullWithoutNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.builder.TestParseURI(dbf));
@@ -50,7 +68,12 @@ public class DOMTestSuiteBuilder extends
             addTest(new org.apache.axiom.ts.dom.document.TestCloneNode(dbf, conformanceFiles[i]));
         }
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttribute(dbf));
-        addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf));
+        for (int i=0; i<validAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf, validAttrQNames[i]));
+        }
+        for (int i=0; i<invalidAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNSInvalid(dbf, invalidAttrQNames[i]));
+        }
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNSWithoutNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateCDATASection(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateElement(dbf));
@@ -62,6 +85,8 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.document.TestDocumentSiblings(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestGetDomConfigDefaults(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestGetOwnerDocument(dbf));
+        addTest(new org.apache.axiom.ts.dom.document.TestLookupNamespaceURI(dbf));
+        addTest(new org.apache.axiom.ts.dom.document.TestLookupNamespaceURIWithEmptyDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestNormalizeDocumentNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestTransformerWithIdentityStylesheet(dbf, org.apache.xalan.processor.TransformerFactoryImpl.class));
         addTest(new org.apache.axiom.ts.dom.document.TestTransformerWithIdentityStylesheet(dbf, net.sf.saxon.TransformerFactoryImpl.class));
@@ -69,6 +94,7 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.document.TestTransformerWithStylesheet(dbf, net.sf.saxon.TransformerFactoryImpl.class));
         addTest(new org.apache.axiom.ts.dom.document.TestValidator(dbf));
         addTest(new org.apache.axiom.ts.dom.documentfragment.TestCloneNode(dbf));
+        addTest(new org.apache.axiom.ts.dom.documentfragment.TestLookupNamespaceURI(dbf));
         addTest(new org.apache.axiom.ts.dom.documenttype.TestWithParser1(dbf));
         addTest(new org.apache.axiom.ts.dom.documenttype.TestWithParser2(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAppendChild(dbf));
@@ -93,26 +119,38 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.element.TestGetTextContent(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestInsertBefore(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestInsertBeforeWithDocumentFragment(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestLookupNamespaceURIExplicit(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestLookupNamespaceURIImplicit(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveAttributeNotOwner(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveFirstChild(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveLastChild(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestRemoveSingleChild(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildCyclic(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf, false));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirst(dbf, true));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildFirstWithDocumentFragment(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLast(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLast(dbf, false));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLast(dbf, true));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildLastWithDocumentFragment(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddle(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddle(dbf, false));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddle(dbf, true));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildMiddleWithDocumentFragment(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildNotFound(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildNullNewChild(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf, false));
+        addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildSingle(dbf, true));
         addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSInUse(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSReplace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeWrongDocument(dbf));
-        addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf));
+        for (int i=0; i<validAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf, validAttrQNames[i], "value"));
+        }
+        addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNSExisting(dbf));
+        for (int i=0; i<invalidAttrQNames.length; i++) {
+            addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNSInvalid(dbf, invalidAttrQNames[i]));
+        }
         addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithoutNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNull(dbf));
@@ -125,6 +163,8 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.text.TestGetWholeText(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestGetWholeTextWithCDATASection(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestGetWholeTextWithComment(dbf));
+        addTest(new org.apache.axiom.ts.dom.text.TestLookupNamespaceURIWithNSDeclInScope(dbf));
+        addTest(new org.apache.axiom.ts.dom.text.TestLookupNamespaceURIWithoutParent(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestSetPrefix(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestSplitText(dbf));
     }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java Thu Dec 20 15:55:24 2012
@@ -18,22 +18,29 @@
  */
 package org.apache.axiom.ts.dom.document;
 
+import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.axiom.ts.dom.DOMTestCase;
+import org.apache.axiom.ts.dom.DOMUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 
 public class TestCreateAttributeNS extends DOMTestCase {
-    public TestCreateAttributeNS(DocumentBuilderFactory dbf) {
+    private final QName qname;
+    
+    public TestCreateAttributeNS(DocumentBuilderFactory dbf, QName qname) {
         super(dbf);
+        this.qname = qname;
+        addTestProperty("ns", qname.getNamespaceURI());
+        addTestProperty("name", DOMUtils.getQualifiedName(qname));
     }
 
     protected void runTest() throws Throwable {
-        String localName = "attrIdentifier";
-        String uri = "http://ws.apache.org/axis2/ns";
-        String prefix = "axis2";
-        String name = prefix + ":" + localName;
+        String localName = qname.getLocalPart();
+        String uri = DOMUtils.getNamespaceURI(qname);
+        String prefix = DOMUtils.getPrefix(qname);
+        String name = DOMUtils.getQualifiedName(qname);
 
         Document doc = dbf.newDocumentBuilder().newDocument();
 
@@ -46,6 +53,8 @@ public class TestCreateAttributeNS exten
         assertEquals(name, attr.getName());
 
         // Check defaults
+        assertSame(doc, attr.getOwnerDocument());
+        assertNull(attr.getOwnerElement());
         assertNull(attr.getFirstChild());
         assertEquals("", attr.getValue());
     }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirst.java Thu Dec 20 15:55:24 2012
@@ -20,7 +20,6 @@ package org.apache.axiom.ts.dom.element;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.apache.axiom.ts.dom.DOMTestCase;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -30,28 +29,26 @@ import org.w3c.dom.NodeList;
  * Tests the behavior of {@link Node#replaceChild(Node, Node)}. This test covers the case where the
  * child being replaced is the first child (which uses a different code path in DOOM).
  */
-public class TestReplaceChildFirst extends DOMTestCase {
-    public TestReplaceChildFirst(DocumentBuilderFactory dbf) {
-        super(dbf);
+public class TestReplaceChildFirst extends ReplaceChildTestCase {
+    public TestReplaceChildFirst(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+        super(dbf, newChildHasSiblings);
     }
 
-    protected void runTest() throws Throwable {
-        Document doc = dbf.newDocumentBuilder().newDocument();
+    protected void runTest(Document doc, Node newChild) {
         Element parent = doc.createElementNS(null, "parent");
         Element child1 = doc.createElementNS(null, "child1");
         Element child2 = doc.createElementNS(null, "child2");
         parent.appendChild(child1);
         parent.appendChild(child2);
-        Element replacementChild = doc.createElementNS(null, "replacement");
-        parent.replaceChild(replacementChild, child1);
-        assertSame(replacementChild, parent.getFirstChild());
+        parent.replaceChild(newChild, child1);
+        assertSame(newChild, parent.getFirstChild());
         assertSame(child2, parent.getLastChild());
-        assertNull(replacementChild.getPreviousSibling());
-        assertSame(child2, replacementChild.getNextSibling());
-        assertSame(replacementChild, child2.getPreviousSibling());
+        assertNull(newChild.getPreviousSibling());
+        assertSame(child2, newChild.getNextSibling());
+        assertSame(newChild, child2.getPreviousSibling());
         NodeList children = parent.getChildNodes();
         assertEquals(2, children.getLength());
-        assertSame(replacementChild, children.item(0));
+        assertSame(newChild, children.item(0));
         assertSame(child2, children.item(1));
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildFirstWithDocumentFragment.java Thu Dec 20 15:55:24 2012
@@ -66,5 +66,8 @@ public class TestReplaceChildFirstWithDo
         assertNull(fragment.getFirstChild());
         assertNull(fragment.getLastChild());
         assertEquals(0, fragment.getChildNodes().getLength());
+        
+        assertSame(x, element.getFirstChild());
+        assertSame(b, element.getLastChild());
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLast.java Thu Dec 20 15:55:24 2012
@@ -20,7 +20,6 @@ package org.apache.axiom.ts.dom.element;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.apache.axiom.ts.dom.DOMTestCase;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -30,28 +29,26 @@ import org.w3c.dom.NodeList;
  * Tests the behavior of {@link Node#replaceChild(Node, Node)}. This test covers the case where the
  * child being replaced is the last child (which uses a different code path in DOOM).
  */
-public class TestReplaceChildLast extends DOMTestCase {
-    public TestReplaceChildLast(DocumentBuilderFactory dbf) {
-        super(dbf);
+public class TestReplaceChildLast extends ReplaceChildTestCase {
+    public TestReplaceChildLast(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+        super(dbf, newChildHasSiblings);
     }
 
-    protected void runTest() throws Throwable {
-        Document doc = dbf.newDocumentBuilder().newDocument();
+    protected void runTest(Document doc, Node newChild) {
         Element parent = doc.createElementNS(null, "parent");
         Element child1 = doc.createElementNS(null, "child1");
         Element child2 = doc.createElementNS(null, "child2");
         parent.appendChild(child1);
         parent.appendChild(child2);
-        Element replacementChild = doc.createElementNS(null, "replacement");
-        parent.replaceChild(replacementChild, child2);
+        parent.replaceChild(newChild, child2);
         assertSame(child1, parent.getFirstChild());
-        assertSame(replacementChild, parent.getLastChild());
-        assertSame(child1, replacementChild.getPreviousSibling());
-        assertNull(replacementChild.getNextSibling());
-        assertSame(replacementChild, child1.getNextSibling());
+        assertSame(newChild, parent.getLastChild());
+        assertSame(child1, newChild.getPreviousSibling());
+        assertNull(newChild.getNextSibling());
+        assertSame(newChild, child1.getNextSibling());
         NodeList children = parent.getChildNodes();
         assertEquals(2, children.getLength());
         assertSame(child1, children.item(0));
-        assertSame(replacementChild, children.item(1));
+        assertSame(newChild, children.item(1));
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildLastWithDocumentFragment.java Thu Dec 20 15:55:24 2012
@@ -66,5 +66,8 @@ public class TestReplaceChildLastWithDoc
         assertNull(fragment.getFirstChild());
         assertNull(fragment.getLastChild());
         assertEquals(0, fragment.getChildNodes().getLength());
+        
+        assertSame(a, element.getFirstChild());
+        assertSame(y, element.getLastChild());
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddle.java Thu Dec 20 15:55:24 2012
@@ -20,7 +20,6 @@ package org.apache.axiom.ts.dom.element;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.apache.axiom.ts.dom.DOMTestCase;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -30,13 +29,12 @@ import org.w3c.dom.NodeList;
  * Tests the behavior of {@link Node#replaceChild(Node, Node)}. This test covers the case where the
  * child being replaced is neither the first nor the last child.
  */
-public class TestReplaceChildMiddle extends DOMTestCase {
-    public TestReplaceChildMiddle(DocumentBuilderFactory dbf) {
-        super(dbf);
+public class TestReplaceChildMiddle extends ReplaceChildTestCase {
+    public TestReplaceChildMiddle(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+        super(dbf, newChildHasSiblings);
     }
 
-    protected void runTest() throws Throwable {
-        Document doc = dbf.newDocumentBuilder().newDocument();
+    protected void runTest(Document doc, Node newChild) {
         Element parent = doc.createElementNS(null, "parent");
         Element child1 = doc.createElementNS(null, "child1");
         Element child2 = doc.createElementNS(null, "child2");
@@ -44,12 +42,11 @@ public class TestReplaceChildMiddle exte
         parent.appendChild(child1);
         parent.appendChild(child2);
         parent.appendChild(child3);
-        Element replacementChild = doc.createElementNS(null, "replacement");
-        parent.replaceChild(replacementChild, child2);
+        parent.replaceChild(newChild, child2);
         NodeList children = parent.getChildNodes();
         assertEquals(3, children.getLength());
         assertSame(child1, children.item(0));
-        assertSame(replacementChild, children.item(1));
+        assertSame(newChild, children.item(1));
         assertSame(child3, children.item(2));
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildMiddleWithDocumentFragment.java Thu Dec 20 15:55:24 2012
@@ -69,5 +69,8 @@ public class TestReplaceChildMiddleWithD
         assertNull(fragment.getFirstChild());
         assertNull(fragment.getLastChild());
         assertEquals(0, fragment.getChildNodes().getLength());
+        
+        assertSame(a, element.getFirstChild());
+        assertSame(c, element.getLastChild());
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestReplaceChildSingle.java Thu Dec 20 15:55:24 2012
@@ -20,7 +20,6 @@ package org.apache.axiom.ts.dom.element;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.apache.axiom.ts.dom.DOMTestCase;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -30,18 +29,18 @@ import org.w3c.dom.NodeList;
  * Tests the behavior of {@link Node#replaceChild(Node, Node)}. This test covers the case where the
  * child being replaced is the only child.
  */
-public class TestReplaceChildSingle extends DOMTestCase {
-    public TestReplaceChildSingle(DocumentBuilderFactory dbf) {
-        super(dbf);
+public class TestReplaceChildSingle extends ReplaceChildTestCase {
+    public TestReplaceChildSingle(DocumentBuilderFactory dbf, boolean newChildHasSiblings) {
+        super(dbf, newChildHasSiblings);
     }
 
-    protected void runTest() throws Throwable {
-        Document doc = dbf.newDocumentBuilder().newDocument();
+    protected void runTest(Document doc, Node newChild) {
         Element parent = doc.createElementNS(null, "parent");
         Element oldChild = doc.createElementNS(null, "oldChild");
         parent.appendChild(oldChild);
-        Element newChild = doc.createElementNS(null, "newChild");
         parent.replaceChild(newChild, oldChild);
+        assertSame(newChild, parent.getFirstChild());
+        assertSame(newChild, parent.getLastChild());
         NodeList children = parent.getChildNodes();
         assertEquals(1, children.getLength());
         assertSame(newChild, children.item(0));

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestSetAttributeNS.java Thu Dec 20 15:55:24 2012
@@ -18,30 +18,43 @@
  */
 package org.apache.axiom.ts.dom.element;
 
+import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.axiom.ts.dom.DOMTestCase;
+import org.apache.axiom.ts.dom.DOMUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 
 public class TestSetAttributeNS extends DOMTestCase {
-    public TestSetAttributeNS(DocumentBuilderFactory dbf) {
+    private final QName qname;
+    private final String value;
+    
+    public TestSetAttributeNS(DocumentBuilderFactory dbf, QName qname, String value) {
         super(dbf);
+        this.qname = qname;
+        this.value = value;
+        addTestProperty("ns", qname.getNamespaceURI());
+        addTestProperty("name", DOMUtils.getQualifiedName(qname));
     }
 
     protected void runTest() throws Throwable {
         Document document = dbf.newDocumentBuilder().newDocument();
         Element element = document.createElementNS("urn:ns1", "p:element");
-        element.setAttributeNS("urn:ns2", "q:attr", "value");
+        element.setAttributeNS(DOMUtils.getNamespaceURI(qname), DOMUtils.getQualifiedName(qname), value);
+        assertTrue(element.hasAttributes());
         NamedNodeMap attributes = element.getAttributes();
         assertEquals(1, attributes.getLength());
         Attr attr = (Attr)attributes.item(0);
-        assertEquals("urn:ns2", attr.getNamespaceURI());
-        assertEquals("q", attr.getPrefix());
-        assertEquals("attr", attr.getLocalName());
-        assertEquals("value", attr.getValue());
-        assertSame(attr, element.getAttributeNodeNS("urn:ns2", "attr"));
+        assertSame(document, attr.getOwnerDocument());
+        assertSame(element, attr.getOwnerElement());
+        assertEquals(DOMUtils.getNamespaceURI(qname), attr.getNamespaceURI());
+        assertEquals(DOMUtils.getPrefix(qname), attr.getPrefix());
+        assertEquals(qname.getLocalPart(), attr.getLocalName());
+        assertEquals(DOMUtils.getQualifiedName(qname), attr.getName());
+        assertEquals(value, attr.getValue());
+        assertSame(attr, element.getAttributeNodeNS(DOMUtils.getNamespaceURI(qname), qname.getLocalPart()));
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/test/java/org/apache/axiom/ts/dom/XercesTest.java Thu Dec 20 15:55:24 2012
@@ -23,6 +23,7 @@ import javax.xml.parsers.DocumentBuilder
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.axiom.ts.dom.document.TestLookupNamespaceURIWithEmptyDocument;
 import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;
 
 public class XercesTest extends TestCase {
@@ -30,6 +31,10 @@ public class XercesTest extends TestCase
         DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl();
         dbf.setNamespaceAware(true);
         DOMTestSuiteBuilder builder = new DOMTestSuiteBuilder(dbf);
+        
+        // XERCESJ-1582
+        builder.exclude(TestLookupNamespaceURIWithEmptyDocument.class);
+        
         return builder.build();
     }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml Thu Dec 20 15:55:24 2012
@@ -22,7 +22,7 @@
     <parent>
         <groupId>org.apache.ws.commons.axiom</groupId>
         <artifactId>axiom-parent</artifactId>
-        <version>1.2.14-SNAPSHOT</version>
+        <version>1.2.15-SNAPSHOT</version>
         <relativePath>../axiom-parent/pom.xml</relativePath>
     </parent>
     <artifactId>axiom-dom</artifactId>

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java Thu Dec 20 15:55:24 2012
@@ -34,6 +34,7 @@ import org.w3c.dom.Node;
 import org.w3c.dom.Text;
 import org.w3c.dom.TypeInfo;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -108,9 +109,10 @@ public class AttrImpl extends RootNode i
         this(ownerDocument, factory);
         this.localName = name;
         //If this is a default namespace attr
-        if (OMConstants.XMLNS_NS_PREFIX.equals(name)) {
+        if (XMLConstants.XMLNS_ATTRIBUTE.equals(name)) {
+            // TODO: this looks wrong; if the attribute name is "xmlns", then the prefix shouldn't be "xmlns"
             this.namespace = new OMNamespaceImpl(
-                    OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX);
+                    XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
         }
         this.type = OMConstants.XMLATTRTYPE_CDATA;
     }
@@ -139,7 +141,7 @@ public class AttrImpl extends RootNode i
     public String getNodeName() {
         return (this.namespace != null
                 && !"".equals(this.namespace.getPrefix()) &&
-                !(OMConstants.XMLNS_NS_PREFIX.equals(this.localName)))
+                !(XMLConstants.XMLNS_ATTRIBUTE.equals(this.localName)))
                 ? this.namespace.getPrefix() + ":" + this.localName
                 : this.localName;
     }
@@ -207,10 +209,10 @@ public class AttrImpl extends RootNode i
     // /
     public String getName() {
         if (this.namespace != null) {
-            if ((OMConstants.XMLNS_NS_PREFIX.equals(this.localName))) {
+            if ((XMLConstants.XMLNS_ATTRIBUTE.equals(this.localName))) {
                 return this.localName;
-            } else if (OMConstants.XMLNS_NS_URI.equals(this.namespace.getNamespaceURI())) {
-                return OMConstants.XMLNS_NS_PREFIX + ":" + this.localName;
+            } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(this.namespace.getNamespaceURI())) {
+                return XMLConstants.XMLNS_ATTRIBUTE + ":" + this.localName;
             } else if (this.namespace.getPrefix().equals("")) {
                 return this.localName;
             } else {
@@ -322,10 +324,7 @@ public class AttrImpl extends RootNode i
 
     final void checkInUse() {
         if (owner instanceof ElementImpl) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.INUSE_ATTRIBUTE_ERR,
-                    null);
-            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.INUSE_ATTRIBUTE_ERR);
         }
     }
 
@@ -493,4 +492,9 @@ public class AttrImpl extends RootNode i
     public final Node getNextSibling() {
         return null;
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        Element ownerElement = getOwnerElement();
+        return ownerElement == null ? null : ownerElement.lookupNamespaceURI(specifiedPrefix);
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java Thu Dec 20 15:55:24 2012
@@ -19,7 +19,6 @@
 
 package org.apache.axiom.om.impl.dom;
 
-import org.apache.axiom.om.OMCloneOptions;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -78,9 +77,7 @@ public class AttributeMap implements Nam
 
         int i = findNamePoint(name, 0);
         if (i < 0) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR, null);
-            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
         }
 
         NodeImpl n = (NodeImpl) nodes.elementAt(i);
@@ -94,9 +91,7 @@ public class AttributeMap implements Nam
 
         int i = findNamePoint(namespaceURI, name);
         if (i < 0) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR, null);
-            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
         }
 
         NodeImpl n = (NodeImpl) nodes.elementAt(i);
@@ -110,11 +105,7 @@ public class AttributeMap implements Nam
 
         ownerNode.checkSameOwnerDocument(attribute);
         if (attribute.getNodeType() != Node.ATTRIBUTE_NODE) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    DOMException.HIERARCHY_REQUEST_ERR,
-                    null);
-            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
         }
 
         AttrImpl attr = (AttrImpl) attribute;
@@ -122,10 +113,7 @@ public class AttributeMap implements Nam
             if (attr.getOwnerElement() != this.ownerNode) // the owner must be
                 // the owner of this
                 // list
-                throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
-                                       DOMMessageFormatter.formatMessage(
-                                               DOMMessageFormatter.DOM_DOMAIN,
-                                               DOMException.INUSE_ATTRIBUTE_ERR, null));
+                throw DOMUtil.newDOMException(DOMException.INUSE_ATTRIBUTE_ERR);
             else
                 return attr; // No point adding the 'same' attr again to the
             // same element
@@ -167,20 +155,14 @@ public class AttributeMap implements Nam
     /** Almost a copy of the Xerces impl. */
     Node setAttribute(Node attribute, boolean useDomSemantics) throws DOMException {
         if (attribute.getNodeType() != Node.ATTRIBUTE_NODE) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.HIERARCHY_REQUEST_ERR,
-                    null);
-            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
         }
 
         AttrImpl attr = (AttrImpl) attribute;
         if (attr.getOwnerElement() != null) { // If the attribute is owned then:
             //the owner must be the owner of this list
             if (attr.getOwnerElement() != this.ownerNode)
-                throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
-                                       DOMMessageFormatter.formatMessage(
-                                               DOMMessageFormatter.DOM_DOMAIN,
-                                               DOMException.INUSE_ATTRIBUTE_ERR, null));
+                throw DOMUtil.newDOMException(DOMException.INUSE_ATTRIBUTE_ERR);
             else
                 return attr; // No point adding the 'same' attr again to the
             // same element
@@ -216,26 +198,6 @@ public class AttributeMap implements Nam
         return previous;
     }
 
-    void cloneContent(OMCloneOptions options, AttributeMap srcmap) {
-        Vector srcnodes = srcmap.nodes;
-        if (srcnodes != null) {
-            int size = srcnodes.size();
-            if (size != 0) {
-                if (nodes == null) {
-                    nodes = new Vector(size);
-                }
-                nodes.setSize(size);
-                for (int i = 0; i < size; ++i) {
-                    AttrImpl n = (AttrImpl) srcnodes.elementAt(i);
-                    AttrImpl clone = (AttrImpl)n.clone(options, null, true, false);
-                    clone.isSpecified(n.isSpecified());
-                    nodes.setElementAt(clone, i);
-                    clone.setOwnerElement(ownerNode, true);
-                }
-            }
-        }
-    }
-
     /**
      * From org.apache.xerces.dom.NamedNodeMapImpl
      * <p/>

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java Thu Dec 20 15:55:24 2012
@@ -62,10 +62,7 @@ public abstract class CharacterImpl exte
 
         int length = this.textValue.length();
         if (offset < 0 || offset > length - 1 || count < 0) {
-            throw new DOMException(DOMException.INDEX_SIZE_ERR,
-                                   DOMMessageFormatter.formatMessage(
-                                           DOMMessageFormatter.DOM_DOMAIN, DOMException.INDEX_SIZE_ERR,
-                                           null));
+            throw DOMUtil.newDOMException(DOMException.INDEX_SIZE_ERR);
         } else {
 
             int end = Math.min(count + offset, length);
@@ -90,10 +87,7 @@ public abstract class CharacterImpl exte
         int length = this.getLength();
 
         if (offset < 0 || offset > length - 1) {
-            throw new DOMException(DOMException.INDEX_SIZE_ERR,
-                                   DOMMessageFormatter.formatMessage(
-                                           DOMMessageFormatter.DOM_DOMAIN,
-                                           DOMException.INDEX_SIZE_ERR, null));
+            throw DOMUtil.newDOMException(DOMException.INDEX_SIZE_ERR);
         }
 
         this.textValue = (new StringBuilder(textValue)).insert(offset, data).toString();
@@ -112,10 +106,7 @@ public abstract class CharacterImpl exte
      */
     public String substringData(int offset, int count) throws DOMException {
         if (offset < 0 || offset > this.getLength() || count < 0) {
-            throw new DOMException(DOMException.INDEX_SIZE_ERR,
-                                   DOMMessageFormatter.formatMessage(
-                                           DOMMessageFormatter.DOM_DOMAIN,
-                                           DOMException.INDEX_SIZE_ERR, null));
+            throw DOMUtil.newDOMException(DOMException.INDEX_SIZE_ERR);
         }
 
         int end = Math.min(count + offset, textValue.length());

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMUtil.java Thu Dec 20 15:55:24 2012
@@ -19,6 +19,10 @@
 
 package org.apache.axiom.om.impl.dom;
 
+import javax.xml.XMLConstants;
+
+import org.w3c.dom.DOMException;
+
 /** Utility class for the OM-DOM implementation */
 class DOMUtil {
 
@@ -28,19 +32,7 @@ class DOMUtil {
         return true;
     }
 
-    /**
-     * @deprecated please use isQualifiedName
-     * @param value
-     * @return
-     */
-    public static boolean isValidChras(String value) {
-        // TODO check for valid characters
-        // throw new UnsupportedOperationException("TODO");
-        return true;
-    }
-
-    public static boolean isValidNamespace(String namespaceURI,
-                                           String qualifiedname) {
+    public static void validateAttrNamespace(String namespaceURI, String localName, String prefix) {
         // TODO check for valid namespace
         /**
          * if the qualifiedName has a prefix and the namespaceURI is null, if
@@ -49,9 +41,21 @@ class DOMUtil {
          * qualifiedName, or its prefix, is "xmlns" and the namespaceURI is
          * different from " http://www.w3.org/2000/xmlns/".
          */
-        // throw new UnsupportedOperationException("TODO");
-        // temporary fix
-        return true;
+        
+        if (namespaceURI == null) {
+            if (localName.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
+            }
+        } else if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+            if (prefix != null && !prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)
+                    || prefix == null && !localName.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
+            }
+        } else {
+            if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
+            }
+        }
     }
 
     /**
@@ -73,4 +77,9 @@ class DOMUtil {
         int idx = qualifiedName.indexOf(':');
         return idx == -1 ? null : qualifiedName.substring(0, idx);
     }
+    
+    public static DOMException newDOMException(short code) {
+        throw new DOMException(code, DOMMessageFormatter.formatMessage(
+                DOMMessageFormatter.DOM_DOMAIN, code, null));
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java Thu Dec 20 15:55:24 2012
@@ -121,4 +121,8 @@ public class DocumentFragmentImpl extend
     public void removeChildren() {
         OMContainerHelper.removeChildren(this);
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        return null;
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Thu Dec 20 15:55:24 2012
@@ -20,7 +20,6 @@
 package org.apache.axiom.om.impl.dom;
 
 import org.apache.axiom.om.OMCloneOptions;
-import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
@@ -52,6 +51,7 @@ import org.w3c.dom.NodeList;
 import org.w3c.dom.ProcessingInstruction;
 import org.w3c.dom.Text;
 
+import javax.xml.XMLConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import java.io.OutputStream;
@@ -122,10 +122,7 @@ public class DocumentImpl extends RootNo
 
     public Attr createAttribute(String name) throws DOMException {
         if (!DOMUtil.isQualifiedName(name)) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.INVALID_CHARACTER_ERR,
-                    null);
-            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.INVALID_CHARACTER_ERR);
         }
         return new AttrImpl(this, name, this.factory);
     }
@@ -134,18 +131,18 @@ public class DocumentImpl extends RootNo
             throws DOMException {
         String localName = DOMUtil.getLocalName(qualifiedName);
         String prefix = DOMUtil.getPrefix(qualifiedName);
+        DOMUtil.validateAttrNamespace(namespaceURI, localName, prefix);
 
-        if (!OMConstants.XMLNS_NS_PREFIX.equals(localName)) {
+        if (!XMLConstants.XMLNS_ATTRIBUTE.equals(localName)) {
             this.checkQName(prefix, localName);
-        } else {
-            return this.createAttribute(localName);
         }
 
         OMNamespace namespace;
         if (namespaceURI == null) {
             namespace = null;
         } else {
-            namespace = new OMNamespaceImpl(namespaceURI, prefix == null ? "" : prefix);
+            namespace = new OMNamespaceImpl(namespaceURI,
+                    prefix == null && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI) ? "" : prefix);
         }
         return new AttrImpl(this, localName, namespace, this.factory);
     }
@@ -288,7 +285,7 @@ public class DocumentImpl extends RootNo
                         Attr attr = (Attr) sourceAttrs.item(index);
                         if (attr.getNamespaceURI() != null
                                 && !attr.getNamespaceURI().equals(
-                                OMConstants.XMLNS_NS_URI)) {
+                                XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
                             Attr newAttr = (Attr) importNode(attr, true);
                             newElement.setAttributeNodeNS(newAttr);
                         } else { // if (attr.getLocalName() == null) {
@@ -308,7 +305,7 @@ public class DocumentImpl extends RootNo
                     newNode = createAttribute(importedNode.getNodeName());
                 } else {
                     //Check whether it is a default ns decl
-                    if (OMConstants.XMLNS_NS_PREFIX.equals(importedNode.getNodeName())) {
+                    if (XMLConstants.XMLNS_ATTRIBUTE.equals(importedNode.getNodeName())) {
                         newNode = createAttribute(importedNode.getNodeName());
                     } else {
                         String ns = importedNode.getNamespaceURI();
@@ -346,12 +343,8 @@ public class DocumentImpl extends RootNo
                 throw new UnsupportedOperationException("TODO : Implement handling of org.w3c.dom.Node type == " + type );
 
             case Node.DOCUMENT_NODE: // Can't import document nodes
-            default: { // Unknown node type
-                String msg = DOMMessageFormatter.formatMessage(
-                        DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_SUPPORTED_ERR, null);
-                throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
-            }
-
+            default:
+                throw DOMUtil.newDOMException(DOMException.NOT_SUPPORTED_ERR);
         }
 
         // If deep, replicate and attach the kids.
@@ -468,11 +461,7 @@ public class DocumentImpl extends RootNo
         // check that both prefix and local part match NCName
         if ((prefix != null && !XMLChar.isValidNCName(prefix))
                 || !XMLChar.isValidNCName(local)) {
-            // REVISIT: add qname parameter to the message
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.INVALID_CHARACTER_ERR,
-                    null);
-            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.INVALID_CHARACTER_ERR);
         }
     }
 
@@ -633,4 +622,10 @@ public class DocumentImpl extends RootNo
     public final void removeChildren() {
         OMContainerHelper.removeChildren(this);
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        Element documentElement = getDocumentElement();
+        return documentElement == null ? null
+                : documentElement.lookupNamespaceURI(specifiedPrefix);
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Thu Dec 20 15:55:24 2012
@@ -44,12 +44,14 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.TypeInfo;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
@@ -59,7 +61,6 @@ import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 
 /** Implementation of the org.w3c.dom.Element and org.apache.axiom.om.Element interfaces. */
@@ -98,14 +99,8 @@ public class ElementImpl extends ParentN
 
     private AttributeMap attributes;
 
-    private HashMap namespaces;
-
     private static final EmptyIterator EMPTY_ITERATOR = new EmptyIterator();
 
-    private static final OMNamespace XMLNS_NAMESPACE_WITH_PREFIX = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX);
-    
-    private static final OMNamespace XMLNS_NAMESPACE_WITHOUT_PREFIX = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, null);
-    
     public ElementImpl(ParentNode parentNode, String localName, OMNamespace ns, OMXMLParserWrapper builder,
                        OMFactory factory, boolean generateNSDecl) {
         super(factory);
@@ -259,13 +254,6 @@ public class ElementImpl extends ParentN
      * @see org.w3c.dom.Element#removeAttribute(String)
      */
     public void removeAttribute(String name) throws DOMException {
-        if (name.startsWith(OMConstants.XMLNS_NS_PREFIX)) {
-            String namespacePrefix = DOMUtil.getLocalName(name);
-            if (this.findNamespaceURI(namespacePrefix) != null) {
-                this.removeNamespace(namespacePrefix);
-            }
-        }
-
         if (this.attributes != null) {
             this.attributes.removeNamedItem(name);
         }
@@ -279,13 +267,7 @@ public class ElementImpl extends ParentN
      */
     public void removeAttributeNS(String namespaceURI, String localName)
             throws DOMException {
-        if (OMConstants.XMLNS_NS_URI.equals(namespaceURI)) {
-            //look in the ns list
-            if (this.namespaces != null) {
-                this.namespaces.remove(DOMUtil.getLocalName(localName));
-            }
-
-        } else if (this.attributes != null) {
+        if (this.attributes != null) {
             this.attributes.removeNamedItemNS(namespaceURI, localName);
         }
     }
@@ -297,9 +279,7 @@ public class ElementImpl extends ParentN
      */
     public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
         if (oldAttr.getOwnerElement() != this) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR, null);
-            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
         }
         attributes.remove((AttrImpl)oldAttr, true);
         return oldAttr;
@@ -367,21 +347,8 @@ public class ElementImpl extends ParentN
      * @see org.w3c.dom.Element#getAttributeNodeNS(String, String)
      */
     public Attr getAttributeNodeNS(String namespaceURI, String localName) {
-
-        if (OMConstants.XMLNS_NS_URI.equals(namespaceURI)) {
-            OMNamespace ns = this.findNamespaceURI(localName);
-            String nsuri = ns != null ? ns.getNamespaceURI() : "";
-
-            AttrImpl namespaceAttr = new AttrImpl(ownerDocument(),
-                                                  localName, nsuri, this.factory);
-            OMNamespaceImpl xmlNs = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, null);
-            namespaceAttr.setOMNamespace(xmlNs);
-            return namespaceAttr;
-        }
-
         return (this.attributes == null) ? null : (Attr) this.attributes
                 .getNamedItemNS(namespaceURI, localName);
-
     }
 
     /**
@@ -397,14 +364,14 @@ public class ElementImpl extends ParentN
         // check whether the attr is in use
         attrImpl.checkInUse();
 
-        if (attr.getNodeName().startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
+        if (attr.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
             // This is a ns declaration
             this.declareNamespace(attr.getNodeValue(), DOMUtil
                     .getLocalName(attr.getName()));
 
             //Don't add this to attr list, since its a namespace
             return attr;
-        } else if (attr.getNodeName().equals(OMConstants.XMLNS_NS_PREFIX)) {
+        } else if (attr.getNodeName().equals(XMLConstants.XMLNS_ATTRIBUTE)) {
             this.declareDefaultNamespace(attr.getValue());
 
             //Don't add this to attr list, since its a namespace
@@ -426,15 +393,12 @@ public class ElementImpl extends ParentN
     public void setAttribute(String name, String value) throws DOMException {
         // Check for invalid charaters
         if (!DOMUtil.isQualifiedName(name)) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.INVALID_CHARACTER_ERR,
-                    null);
-            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+            throw DOMUtil.newDOMException(DOMException.INVALID_CHARACTER_ERR);
         }
-        if (name.startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
+        if (name.startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")) {
             // This is a ns declaration
             this.declareNamespace(value, DOMUtil.getLocalName(name));
-        } else if (name.equals(OMConstants.XMLNS_NS_PREFIX)) {
+        } else if (name.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
             this.declareDefaultNamespace(value);
         } else {
             this.setAttributeNode(new AttrImpl(ownerDocument(), name, value,
@@ -444,43 +408,34 @@ public class ElementImpl extends ParentN
     }
 
     public Attr setAttributeNodeNS(Attr attr) throws DOMException {
-        return setAttributeNodeNS(attr, true);
+        return setAttributeNodeNS(attr, true, false);
     }
     
-    private Attr setAttributeNodeNS(Attr attr, boolean useDomSemantics) throws DOMException {
-
-        // Check whether the attr is a namespace declaration
-        // if so add a namespace NOT an attribute
-        if (attr.getNamespaceURI() != null
-                && attr.getNamespaceURI().equals(OMConstants.XMLNS_NS_URI)) {
-            this.declareNamespace(attr.getName(), attr.getValue());
-            return attr;
-        } else {
-            AttrImpl attrImpl = (AttrImpl) attr;
-
-            if (useDomSemantics) {
-                checkSameOwnerDocument(attr);
-            }
+    private Attr setAttributeNodeNS(Attr attr, boolean useDomSemantics, boolean generateNSDecl) throws DOMException {
+        AttrImpl attrImpl = (AttrImpl) attr;
 
-            // check whether the attr is in use
-            attrImpl.checkInUse();
+        if (useDomSemantics) {
+            checkSameOwnerDocument(attr);
+        }
 
-            if (this.attributes == null) {
-                this.attributes = new AttributeMap(this);
-            }
+        // check whether the attr is in use
+        attrImpl.checkInUse();
 
-            // handle the namespaces
-            if (!useDomSemantics && attr.getNamespaceURI() != null
-                    && findNamespace(attr.getNamespaceURI(), attr.getPrefix())
-                    == null) {
-                // TODO checkwhether the same ns is declared with a different
-                // prefix and remove it
-                this.declareNamespace(new OMNamespaceImpl(attr.getNamespaceURI(),
-                                                        attr.getPrefix()));
-            }
+        if (this.attributes == null) {
+            this.attributes = new AttributeMap(this);
+        }
 
-            return (Attr) this.attributes.setAttribute(attr, useDomSemantics);
+        // handle the namespaces
+        if (generateNSDecl && attr.getNamespaceURI() != null
+                && findNamespace(attr.getNamespaceURI(), attr.getPrefix())
+                == null) {
+            // TODO checkwhether the same ns is declared with a different
+            // prefix and remove it
+            this.declareNamespace(new OMNamespaceImpl(attr.getNamespaceURI(),
+                                                    attr.getPrefix()));
         }
+
+        return (Attr) this.attributes.setAttribute(attr, useDomSemantics);
     }
 
     /**
@@ -490,87 +445,37 @@ public class ElementImpl extends ParentN
      */
     public void setAttributeNS(String namespaceURI, String qualifiedName,
                                String value) throws DOMException {
-
-        if (namespaceURI != null && !"".equals(namespaceURI)) {
-            if (namespaceURI.equals(OMConstants.XMLNS_NS_URI)) {
-                this.declareNamespace(value, DOMUtil
-                        .getLocalName(qualifiedName));
-            } else {
-                AttrImpl attr = new AttrImpl(ownerDocument(), DOMUtil
-                        .getLocalName(qualifiedName), value, this.factory);
-                attr.setOMNamespace(new OMNamespaceImpl(namespaceURI, DOMUtil
-                        .getPrefix(qualifiedName)));
-
-                this.setAttributeNodeNS(attr);
-            }
-        } else {
-            // When the namespace is null, the attr name given better not be
-            // a qualified name
-            // But anyway check and set it
-            this.setAttribute(DOMUtil.getLocalName(qualifiedName), value);
-        }
-
-    }
-
-    private OMAttribute addAttribute(String namespaceURI, String qualifiedName,
-                                     String value) throws DOMException {
-        if (!DOMUtil.isQualifiedName(qualifiedName)) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN, DOMException.INVALID_CHARACTER_ERR ,
-                    null);
-            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
-        }
-
-        if (this.attributes == null) {
-            this.attributes = new AttributeMap(this);
+        
+        if (namespaceURI != null && namespaceURI.length() == 0) {
+            namespaceURI = null;
         }
-        if (namespaceURI != null) {
-            if (!DOMUtil.isValidNamespace(namespaceURI, qualifiedName)) {
-                String msg = DOMMessageFormatter.formatMessage(
-                        DOMMessageFormatter.DOM_DOMAIN, DOMException.NAMESPACE_ERR, null);
-                throw new DOMException(DOMException.NAMESPACE_ERR, msg);
-            }
-            // Check whether there's an existing Attr with same local name and
-            // namespace URI
-            String localName = DOMUtil.getLocalName(qualifiedName);
-            Attr attributeNode = this.getAttributeNodeNS(namespaceURI, localName);
-            if (attributeNode != null) {
-                AttrImpl tempAttr = ((AttrImpl) attributeNode);
-                tempAttr.setOMNamespace(new OMNamespaceImpl(namespaceURI, DOMUtil
-                        .getPrefix(qualifiedName)));
-                tempAttr.setAttributeValue(value);
-                this.attributes.setNamedItem(tempAttr);
-                return tempAttr;
-            } else {
-                OMNamespaceImpl ns = new OMNamespaceImpl(namespaceURI, DOMUtil
-                        .getPrefix(qualifiedName));
-                AttrImpl attr = new AttrImpl((DocumentImpl) this
-                        .getOwnerDocument(), localName, ns, value, this.factory);
-                this.attributes.setNamedItem(attr);
-                return attr;
-            }
+        String localName = DOMUtil.getLocalName(qualifiedName);
+        String prefix = DOMUtil.getPrefix(qualifiedName);
+        DOMUtil.validateAttrNamespace(namespaceURI, localName, prefix);
+        
+        AttrImpl attr = (AttrImpl)getAttributeNodeNS(namespaceURI, localName);
+        if (attr != null) {
+            attr.setPrefix(prefix);
+            attr.setValue(value);
         } else {
-            Attr attributeNode = this.getAttributeNode(qualifiedName);
-            if (attributeNode != null) {
-                AttrImpl tempAttr = ((AttrImpl) attributeNode);
-                tempAttr.setAttributeValue(value);
-                this.attributes.setNamedItem(tempAttr);
-                return tempAttr;
+            if (namespaceURI != null) {
+                attr = new AttrImpl(ownerDocument(), localName, value, this.factory);
+                attr.setOMNamespace(new OMNamespaceImpl(namespaceURI, prefix));
+    
+                this.setAttributeNodeNS(attr);
             } else {
-                AttrImpl attr = new AttrImpl((DocumentImpl) this
-                        .getOwnerDocument(), qualifiedName, value, this.factory);
-                this.attributes.setNamedItem(attr);
-                return attr;
+                // When the namespace is null, the attr name given better not be
+                // a qualified name
+                // But anyway check and set it
+                this.setAttribute(localName, value);
             }
         }
+
     }
 
     /** Returns whether this element contains any attribute or not. */
     public boolean hasAttributes() {
-        // DOM represents namespace declarations as attributes; therefore
-        // we need to check both "attributes" and "namespaces"
-        return attributes != null && attributes.getLength() > 0
-                || namespaces != null && !namespaces.isEmpty();
+        return attributes != null && attributes.getLength() > 0;
     }
 
     /*
@@ -640,7 +545,7 @@ public class ElementImpl extends ParentN
             }
         }
 
-        this.setAttributeNodeNS((Attr) attr, false);
+        this.setAttributeNodeNS((Attr) attr, false, true);
         return attr;
     }
 
@@ -660,12 +565,8 @@ public class ElementImpl extends ParentN
     }
 
     public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        OMNamespace ns = new OMNamespaceImpl(uri, prefix);
-        namespaces.put(prefix, ns);
-        return ns;
+        setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, uri);
+        return new OMNamespaceImpl(uri, prefix);
     }
 
     /**
@@ -674,10 +575,6 @@ public class ElementImpl extends ParentN
      * @see org.apache.axiom.om.OMElement#declareNamespace (org.apache.axiom.om.OMNamespace)
      */
     public OMNamespace declareNamespace(OMNamespace namespace) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-
         if (namespace != null) {
             String prefix = namespace.getPrefix();
             if (prefix == null) {
@@ -688,18 +585,15 @@ public class ElementImpl extends ParentN
                 throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace name");
             }
 
-            if (!namespace.getPrefix().startsWith(OMConstants.XMLNS_NS_PREFIX)) {
-                namespaces.put(namespace.getPrefix(), namespace);
+            if (!namespace.getPrefix().startsWith(XMLConstants.XMLNS_ATTRIBUTE)) {
+                setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, namespace.getNamespaceURI());
             }
         }
         return namespace;
     }
 
     public void undeclarePrefix(String prefix) {
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        namespaces.put(prefix, new OMNamespaceImpl("", prefix));
+        setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, "");
     }
 
     public OMNamespace declareNamespace(String uri, String prefix) {
@@ -719,20 +613,15 @@ public class ElementImpl extends ParentN
                     "the namespace information of the element");
         }
 
-        OMNamespaceImpl ns = new OMNamespaceImpl(uri, "");
-        if (namespaces == null) {
-            this.namespaces = new HashMap(5);
-        }
-        namespaces.put("", ns);
-        return ns;
+        setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, uri);
+        return new OMNamespaceImpl(uri, "");
     }
 
     public OMNamespace getDefaultNamespace() {
-        if (namespaces != null) {
-            OMNamespaceImpl defaultNS = (OMNamespaceImpl) namespaces.get("");
-            if (defaultNS != null) {
-                return defaultNS.getNamespaceURI().length() == 0 ? null : defaultNS;
-            }
+        Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
+        if (decl != null) {
+            String uri = decl.getValue();
+            return uri.length() == 0 ? null : new OMNamespaceImpl(uri, "");
         }
 
         ParentNode parentNode = parentNode();
@@ -778,23 +667,24 @@ public class ElementImpl extends ParentN
     }
 
     public OMNamespace findNamespaceURI(String prefix) {
-        OMNamespace ns = this.namespaces == null ?
-                null :
-                (OMNamespace) this.namespaces.get(prefix);
-
-        if (ns == null) {
-            ParentNode parentNode = parentNode();
-            if (parentNode instanceof OMElement) {
-                // try with the parent
-                return ((OMElement)parentNode).findNamespaceURI(prefix);
-            } else {
-                return null;
+        if (attributes != null) {
+            Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : prefix);
+            if (decl != null) {
+                String namespaceURI = decl.getValue();
+                if (prefix != null && prefix.length() > 0 && namespaceURI.length() == 0) {
+                    // Prefix undeclaring case (XML 1.1 only)
+                    return null;
+                } else {
+                    return new OMNamespaceImpl(namespaceURI, prefix);
+                }
             }
-        } else if (prefix != null && prefix.length() > 0 && ns.getNamespaceURI().length() == 0) {
-            // Prefix undeclaring case (XML 1.1 only)
-            return null;
+        }
+        ParentNode parentNode = parentNode();
+        if (parentNode instanceof OMElement) {
+            // try with the parent
+            return ((OMElement)parentNode).findNamespaceURI(prefix);
         } else {
-            return ns;
+            return null;
         }
     }
 
@@ -805,7 +695,9 @@ public class ElementImpl extends ParentN
     private OMNamespace findDeclaredNamespace(String uri, String prefix) {
 
         if (uri == null) {
-            return namespaces == null ? null : (OMNamespace)namespaces.get(prefix);
+            Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
+                    prefix.length() == 0 ? XMLConstants.XMLNS_ATTRIBUTE : prefix);
+            return decl == null ? null : new OMNamespaceImpl(decl.getValue(), prefix);
         }
         // If the prefix is available and uri is available and its the xml
         // namespace
@@ -814,24 +706,23 @@ public class ElementImpl extends ParentN
             return new OMNamespaceImpl(uri, prefix);
         }
 
-        if (namespaces == null) {
-            return null;
-        }
-
         if (prefix == null || "".equals(prefix)) {
-            Iterator namespaceListIterator = namespaces.values().iterator();
-            while (namespaceListIterator.hasNext()) {
-                OMNamespace omNamespace = (OMNamespace) namespaceListIterator.next();
-                String nsURI = omNamespace.getNamespaceURI();
-                if (nsURI != null && nsURI.equals(uri)) {
-                    return omNamespace;
+            for (int i=0; i<attributes.getLength(); i++) {
+                Attr attr = (Attr)attributes.item(i);
+                if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
+                    String declaredUri = attr.getValue();
+                    if (declaredUri.equals(uri)) {
+                        return new OMNamespaceImpl(uri, attr.getPrefix() == null ? "" : attr.getLocalName());
+                    }
                 }
             }
-
         } else {
-            OMNamespace namespace = (OMNamespace) namespaces.get(prefix);
-            if (namespace != null && uri.equals(namespace.getNamespaceURI())) {
-                return namespace;
+            Attr decl = (Attr)attributes.getNamedItemNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix);
+            if (decl != null) {
+                String declaredUri = decl.getValue();
+                if (declaredUri.equals(uri)) {
+                    return new OMNamespaceImpl(uri, prefix);
+                }
             }
         }
 
@@ -1037,10 +928,7 @@ public class ElementImpl extends ParentN
 
     /** @see org.apache.axiom.om.OMElement#getAllDeclaredNamespaces() */
     public Iterator getAllDeclaredNamespaces() throws OMException {
-        if (namespaces == null) {
-            return EMPTY_ITERATOR;
-        }
-        return namespaces.values().iterator();
+        return new NSDeclIterator(attributes);
     }
 
     public Iterator getNamespacesInScope() {
@@ -1060,7 +948,7 @@ public class ElementImpl extends ParentN
         for (int i = 0; i < attributes.getLength(); i++) {
             OMAttribute item = (OMAttribute) attributes.getItem(i);
             if (item.getNamespace() == null
-                    || !(item.getNamespace() != null && OMConstants.XMLNS_NS_URI
+                    || !(item.getNamespace() != null && XMLConstants.XMLNS_ATTRIBUTE_NS_URI
                     .equals(item.getNamespace().getNamespaceURI()))) {
                 list.add(item);
             }
@@ -1120,18 +1008,11 @@ public class ElementImpl extends ParentN
         } else {
             clone = new ElementImpl(targetParent, localName, namespace, null, factory, namespaceRepairing);
         }
-        for (Iterator it = getAllDeclaredNamespaces(); it.hasNext(); ) {
-            OMNamespace ns = (OMNamespace)it.next();
-            clone.declareNamespace(ns);
-        }
-        clone.attributes.cloneContent(options, attributes);
-        if (namespaceRepairing) {
-            for (Iterator it = getAllAttributes(); it.hasNext(); ) {
-                OMNamespace ns = ((OMAttribute)it.next()).getNamespace();
-                if (ns != null) {
-                    clone.declareNamespace(ns);
-                }
-            }
+        for (int i=0, l=attributes.getLength(); i<l; i++) {
+            AttrImpl attr = (AttrImpl)attributes.item(i);
+            AttrImpl clonedAttr = (AttrImpl)attr.clone(options, null, true, false);
+            clonedAttr.isSpecified(attr.isSpecified());
+            clone.setAttributeNodeNS(clonedAttr, false, namespaceRepairing && !XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI()));
         }
         return clone;
     }
@@ -1150,36 +1031,7 @@ public class ElementImpl extends ParentN
 
     /** Returns the set of attributes of this node and the namespace declarations available. */
     public NamedNodeMap getAttributes() {
-        AttributeMap attributeMap = new AttributeMap(this);
-
-        // Add the set of existing attrs
-        for (int i = 0; i < this.attributes.getLength(); i++) {
-            attributeMap.addItem((Attr) this.attributes.getItem(i));
-        }
-
-        // Add the NS declarations
-        if (this.namespaces != null) {
-            Iterator nsDecls = this.namespaces.keySet().iterator();
-            while (nsDecls.hasNext()) {
-                String prefix = (String) nsDecls.next();
-                if (prefix != null){
-
-                    OMNamespace ns = (OMNamespace)this.namespaces.get(prefix);
-                    
-                    if ("".equals(prefix)) {
-                        AttrImpl attr = new AttrImpl(ownerDocument(), "xmlns", ns.getNamespaceURI(), this.factory);
-                        attr.setOMNamespace(XMLNS_NAMESPACE_WITHOUT_PREFIX);
-                        attributeMap.addItem(attr);
-                    } else {
-                        AttrImpl attr = new AttrImpl(ownerDocument(), prefix, ns.getNamespaceURI(), this.factory);
-                        attr.setOMNamespace(XMLNS_NAMESPACE_WITH_PREFIX);
-                        attributeMap.addItem(attr);
-                    }
-                }
-            }
-        }
-
-        return attributeMap;
+        return attributes;
     }
 
     /**
@@ -1194,22 +1046,6 @@ public class ElementImpl extends ParentN
         return (ns != null) ? ns.getNamespaceURI() : null;
     }
 
-    /**
-     * Removes a declared namespace given its prefix.
-     *
-     * @param prefix
-     * @return Returns whether the namespace relevant to the given prefix was removed or not
-     */
-    public boolean removeNamespace(String prefix) {
-        Object ns = this.namespaces.get(prefix);
-        if (ns != null) {
-            this.namespaces.remove(prefix);
-            return true;
-        } else {
-            return false;
-        }
-    }
-
     public void discard() throws OMException {
         OMElementImplUtil.discard(this);
     }
@@ -1222,11 +1058,7 @@ public class ElementImpl extends ParentN
         //find the attr
         AttrImpl tempAttr = (AttrImpl) this.getAttributeNode(name);
         if (tempAttr == null) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    DOMException.NOT_FOUND_ERR, null);
-            throw new DOMException(DOMException.NOT_FOUND_ERR,
-                                   msg);
+            throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
         }
 
         this.updateIsId(isId, tempAttr);
@@ -1237,11 +1069,7 @@ public class ElementImpl extends ParentN
         //find the attr
         AttrImpl tempAttr = (AttrImpl) this.getAttributeNodeNS(namespaceURI, localName);
         if (tempAttr == null) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    DOMException.NOT_FOUND_ERR, null);
-            throw new DOMException(DOMException.NOT_FOUND_ERR,
-                                   msg);
+            throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
         }
 
         this.updateIsId(isId, tempAttr);
@@ -1260,11 +1088,7 @@ public class ElementImpl extends ParentN
         }
 
         if (tempAttr == null) {
-            String msg = DOMMessageFormatter.formatMessage(
-                    DOMMessageFormatter.DOM_DOMAIN,
-                    DOMException.NOT_FOUND_ERR, null);
-            throw new DOMException(DOMException.NOT_FOUND_ERR,
-                                   msg);
+            throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
         }
 
         this.updateIsId(isId, tempAttr);
@@ -1375,4 +1199,41 @@ public class ElementImpl extends ParentN
     public final void removeChildren() {
         OMContainerHelper.removeChildren(this);
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        String namespace = this.getNamespaceURI();
+        String prefix = this.getPrefix();
+        // First check for namespaces implicitly defined by the namespace prefix/URI of the element
+        // TODO: although the namespace != null condition conforms to the specs, it is likely incorrect; see XERCESJ-1586
+        if (namespace != null
+                && (prefix == null && specifiedPrefix == null
+                        || prefix != null && prefix.equals(specifiedPrefix))) {
+            return namespace;
+        }
+        // looking in attributes
+        if (this.hasAttributes()) {
+            NamedNodeMap map = this.getAttributes();
+            int length = map.getLength();
+            for (int i = 0; i < length; i++) {
+                Node attr = map.item(i);
+                namespace = attr.getNamespaceURI();
+                if (namespace != null && namespace.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
+                    // At this point we know that either the prefix of the attribute is null and
+                    // the local name is "xmlns" or the prefix is "xmlns" and the local name is the
+                    // namespace prefix declared by the namespace declaration. We check that constraint
+                    // when the attribute is created.
+                    String attrPrefix = attr.getPrefix();
+                    if ((specifiedPrefix == null && attrPrefix == null)
+                            || (specifiedPrefix != null && attrPrefix != null
+                                    && attr.getLocalName().equals(specifiedPrefix))) {
+                        String value = attr.getNodeValue();
+                        return value.length() > 0 ? value : null;
+                    }
+                }
+            }
+        }
+        // looking in ancestor
+        ParentNode parent = parentNode();
+        return parent == null || parent instanceof Document ? null : parent.lookupNamespaceURI(specifiedPrefix);
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java Thu Dec 20 15:55:24 2012
@@ -27,6 +27,7 @@ import org.apache.axiom.om.impl.common.I
 import org.apache.axiom.om.impl.common.IParentNode;
 import org.apache.axiom.om.impl.common.OMNodeHelper;
 import org.w3c.dom.DOMException;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
@@ -70,30 +71,19 @@ public abstract class LeafNode extends N
     }
 
     public final Node appendChild(Node newChild) throws DOMException {
-        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-                DOMMessageFormatter.formatMessage(
-                        DOMMessageFormatter.DOM_DOMAIN,
-                        DOMException.HIERARCHY_REQUEST_ERR, null));
+        throw DOMUtil.newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
     }
 
     public final Node removeChild(Node oldChild) throws DOMException {
-        throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessageFormatter
-                .formatMessage(DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR,
-                               null));
+        throw DOMUtil.newDOMException(DOMException.NOT_FOUND_ERR);
     }
 
     public final Node insertBefore(Node newChild, Node refChild) throws DOMException {
-        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-                               DOMMessageFormatter.formatMessage(
-                                       DOMMessageFormatter.DOM_DOMAIN,
-                                       DOMException.HIERARCHY_REQUEST_ERR, null));
+        throw DOMUtil.newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
     }
 
     public final Node replaceChild(Node newChild, Node oldChild) throws DOMException {
-        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-                               DOMMessageFormatter.formatMessage(
-                                       DOMMessageFormatter.DOM_DOMAIN,
-                                       DOMException.HIERARCHY_REQUEST_ERR, null));
+        throw DOMUtil.newDOMException(DOMException.HIERARCHY_REQUEST_ERR);
     }
 
     final NodeImpl clone(OMCloneOptions options, ParentNode targetParent, boolean deep, boolean namespaceRepairing) {
@@ -144,4 +134,12 @@ public abstract class LeafNode extends N
     public final IParentNode getIParentNode() {
         return parentNode();
     }
+
+    public final String lookupNamespaceURI(String specifiedPrefix) {
+        ParentNode parent = parentNode();
+        // Note: according to the DOM specs, we need to delegate the lookup if the parent
+        // is an element or an entity reference. However, since we don't support entity
+        // references fully, we only check for elements.
+        return parent instanceof Element ? parent.lookupNamespaceURI(specifiedPrefix) : null;
+    }
 }

Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeHelper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeHelper.java?rev=1424548&r1=1424547&r2=1424548&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeHelper.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamedNodeHelper.java Thu Dec 20 15:55:24 2012
@@ -32,11 +32,7 @@ public final class NamedNodeHelper {
         OMNamespace ns = node.getNamespace();
         if (ns == null) {
             if (prefix.length() > 0) {
-                String msg = DOMMessageFormatter.formatMessage(
-                        DOMMessageFormatter.DOM_DOMAIN,
-                        DOMException.NAMESPACE_ERR,
-                        null);
-                throw new DOMException(DOMException.NAMESPACE_ERR, msg);
+                throw DOMUtil.newDOMException(DOMException.NAMESPACE_ERR);
             } else {
                 // No need to set a new OMNamespace in this case
             }