Author: veithen Date: Fri Apr 10 22:36:41 2009 New Revision: 764089 URL: http://svn.apache.org/viewvc?rev=764089&view=rev Log: DOOM: Avoid generating unnecessary namespace declaration when creating an element from a QName with null namespace.
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java?rev=764089&r1=764088&r2=764089&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMElementTestBase.java Fri Apr 10 22:36:41 2009 @@ -20,8 +20,6 @@ package org.apache.axiom.om; import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamConstants; @@ -195,20 +193,6 @@ assertSame(element, att2.getOwner()); } - // This methods filters out the ("", "") namespace declaration (empty namespace - // to default). This declaration is present on OMElements produced by DOOM. - // TODO: check if this is not a bug in DOOM - private Iterator getRealAllDeclaredNamespaces(OMElement element) { - List namespaces = new LinkedList(); - for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) { - OMNamespace ns = (OMNamespace)it.next(); - if (!("".equals(ns.getPrefix()) && "".equals(ns.getNamespaceURI()))) { - namespaces.add(ns); - } - } - return namespaces.iterator(); - } - public void testAddAttributeWithoutExistingNamespaceDeclaration() { OMFactory factory = getOMFactory(); OMElement element = factory.createOMElement(new QName("test")); @@ -216,7 +200,7 @@ OMAttribute att = factory.createOMAttribute("test", ns, "test"); element.addAttribute(att); assertEquals(ns, element.findNamespace(ns.getNamespaceURI(), ns.getPrefix())); - Iterator it = getRealAllDeclaredNamespaces(element); + Iterator it = element.getAllDeclaredNamespaces(); assertTrue(it.hasNext()); assertEquals(ns, it.next()); assertFalse(it.hasNext()); @@ -229,7 +213,7 @@ element.declareNamespace(ns); OMAttribute att = factory.createOMAttribute("test", ns, "test"); element.addAttribute(att); - Iterator it = getRealAllDeclaredNamespaces(element); + Iterator it = element.getAllDeclaredNamespaces(); assertTrue(it.hasNext()); assertEquals(ns, it.next()); assertFalse(it.hasNext()); Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=764089&r1=764088&r2=764089&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Fri Apr 10 22:36:41 2009 @@ -202,7 +202,9 @@ public OMElement createOMElement(QName qname, OMContainer parent) throws OMException { NamespaceImpl ns; - if (qname.getPrefix() != null) { + if (qname.getNamespaceURI().length() == 0) { + ns = null; + } else if (qname.getPrefix() != null) { ns = new NamespaceImpl(qname.getNamespaceURI(), qname.getPrefix()); } else { ns = new NamespaceImpl(qname.getNamespaceURI());