Author: veithen
Date: Sat Apr 11 16:58:53 2009
New Revision: 764219

URL: http://svn.apache.org/viewvc?rev=764219&view=rev
Log:
Fixed an issue with OMElement#addAttribute and masked namespace declarations.

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/ElementImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.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=764219&r1=764218&r2=764219&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
 Sat Apr 11 16:58:53 2009
@@ -218,4 +218,38 @@
         assertEquals(ns, it.next());
         assertFalse(it.hasNext());
     }
+
+    /**
+     * Test checking that {...@link OMElement#addAttribute(OMAttribute)} 
correctly generates a
+     * new namespace declaration if an equivalent namespace declaration exists 
but is masked.
+     * The test attempts to create the following XML:
+     * <pre>
+     * &lt;a xmlns:p="urn:ns1">
+     *   &lt;b xmlns:p="urn:ns2">
+     *     &lt;c xmlns:p="urn:ns1" p:attr="test"/>
+     *   &lt;/b>
+     * &lt;/a></pre>
+     * It only explicitly creates the namespace declarations on 
<tt>&lt;a></tt> and
+     * <tt>&lt;b></tt>. When adding the attribute to <tt>&lt;c></tt>, Axiom 
must generate
+     * a new namespace declaration because the declaration on <tt>&lt;a></tt> 
is masked
+     * by the one on <tt>&lt;b></tt>.
+     * <p>
+     * Note that because of WSTX-202, Axiom will not be able to serialize the 
resulting XML.
+     */
+    public void testAddAttributeWithMaskedNamespaceDeclaration() {
+        OMFactory factory = getOMFactory();
+        OMNamespace ns1 = factory.createOMNamespace("urn:ns1", "p");
+        OMNamespace ns2 = factory.createOMNamespace("urn:ns2", "p");
+        OMElement element1 = factory.createOMElement(new QName("a"));
+        element1.declareNamespace(ns1);
+        OMElement element2 = factory.createOMElement(new QName("b"), element1);
+        element2.declareNamespace(ns2);
+        OMElement element3 = factory.createOMElement(new QName("c"), element2);
+        OMAttribute att = factory.createOMAttribute("attr", ns1, "test");
+        element3.addAttribute(att);
+        Iterator it = element3.getAllDeclaredNamespaces();
+        assertTrue(it.hasNext());
+        assertEquals(ns1, it.next());
+        assertFalse(it.hasNext());
+    }
 }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=764219&r1=764218&r2=764219&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
 Sat Apr 11 16:58:53 2009
@@ -688,8 +688,8 @@
         OMNamespace namespace = attr.getNamespace();
         if (namespace != null && namespace.getNamespaceURI() != null
                 && !"".equals(namespace.getNamespaceURI())
-                && this.findNamespace(namespace.getNamespaceURI(), namespace
-                .getPrefix()) == null) {
+                && 
!namespace.getNamespaceURI().equals(this.findNamespaceURI(namespace
+                .getPrefix()))) {
             this.declareNamespace(namespace.getNamespaceURI(), 
namespace.getPrefix());
         }
 

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=764219&r1=764218&r2=764219&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
 Sat Apr 11 16:58:53 2009
@@ -593,7 +593,7 @@
         String nsPrefix;
         if (namespace != null && (nsURI = namespace.getNamespaceURI()) != null 
&&
                 !"".equals(nsURI) &&
-                this.findNamespace(nsURI, (nsPrefix = namespace.getPrefix())) 
== null) {
+                !nsURI.equals(this.findNamespaceURI(nsPrefix = 
namespace.getPrefix()))) {
             this.declareNamespace(nsURI, nsPrefix);
         }
 


Reply via email to