Author: gdaniels
Date: Wed Mar 28 06:25:17 2007
New Revision: 523314

URL: http://svn.apache.org/viewvc?view=rev&rev=523314
Log:
Fix https://issues.apache.org/jira/browse/WSCOMMONS-141

Also introduce an equals(Object) override, and add a test.  Someone with 
greater Maven-fu than I have will hopefully help to get unit tests in this 
module working.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/NamespaceTest.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml?view=diff&rev=523314&r1=523313&r2=523314
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/pom.xml Wed Mar 
28 06:25:17 2007
@@ -25,6 +25,10 @@
             <artifactId>mail</artifactId>
         </dependency>
         <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
         </dependency>
@@ -33,4 +37,16 @@
             <artifactId>stax-api</artifactId>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <includes>
+                        <include>**/*Test.java</include>
+                    </includes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?view=diff&rev=523314&r1=523313&r2=523314
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
 Wed Mar 28 06:25:17 2007
@@ -191,14 +191,16 @@
     public Element createElementNS(String ns, String qualifiedName)
             throws DOMException {
 
+        if (ns == null) ns = "";
+
         String localName = DOMUtil.getLocalName(qualifiedName);
         String prefix = DOMUtil.getPrefix(qualifiedName);
 
-        if (ns != null && (prefix != null || "".equals(prefix))) {
+        if (prefix != null || "".equals(prefix)) {
             this.checkQName(prefix, localName);
         }
 
-        NamespaceImpl namespace = new NamespaceImpl(ns, prefix == null ? "" : 
prefix);
+        NamespaceImpl namespace = new NamespaceImpl(ns, prefix);
         return new ElementImpl(this, localName, namespace, this.factory);
     }
 

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceImpl.java?view=diff&rev=523314&r1=523313&r2=523314
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NamespaceImpl.java
 Wed Mar 28 06:25:17 2007
@@ -21,15 +21,20 @@
 
     private String nsUri;
 
-    private String nsPrefix;
+    private String nsPrefix = "";
 
     public NamespaceImpl(String uri) {
+        if (uri == null) {
+            throw new IllegalArgumentException("Namespace URI may not be 
null");
+        }
         this.nsUri = uri;
     }
 
     public NamespaceImpl(String uri, String prefix) {
         this(uri);
-        this.nsPrefix = prefix;
+        if (prefix != null) {
+            this.nsPrefix = prefix;
+        }
     }
 
     /*
@@ -39,14 +44,21 @@
      *      java.lang.String)
      */
     public boolean equals(String uri, String prefix) {
-        return (this.nsUri == uri && this.nsPrefix == prefix);
+        return (nsUri.equals(uri) && nsPrefix.equals(prefix));
+    }
+
+    public boolean equals(Object obj) {
+        if (!(obj instanceof OMNamespace)) return false;
+        OMNamespace other = (OMNamespace)obj;
+        return (nsUri.equals(other.getNamespaceURI()) &&
+                nsPrefix.equals(other.getPrefix()));
     }
 
     /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.axiom.om.OMNamespace#getPrefix()
-     */
+    * (non-Javadoc)
+    *
+    * @see org.apache.axiom.om.OMNamespace#getPrefix()
+    */
     public String getPrefix() {
         return this.nsPrefix;
     }

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/NamespaceTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/NamespaceTest.java?view=auto&rev=523314
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/NamespaceTest.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/test/org/apache/axiom/om/impl/dom/NamespaceTest.java
 Wed Mar 28 06:25:17 2007
@@ -0,0 +1,43 @@
+package org.apache.axiom.om.impl.dom;
+
+import junit.framework.TestCase;
+/*
+ * Copyright 2007 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class NamespaceTest extends TestCase {
+    public void testEquals() throws Exception {
+        boolean goodResult = false;
+        NamespaceImpl ns1;
+        NamespaceImpl ns2;
+
+        try {
+            new NamespaceImpl(null);
+        } catch (IllegalArgumentException e) {
+            // Caught null, good.
+            goodResult = true;
+        }
+        if (!goodResult)
+            fail("Null namespace allowed!");
+
+        String URI1 = "http://testuri1";;
+        String URI2 = "http://";;
+        ns1 = new NamespaceImpl(URI1);
+        ns2 = new NamespaceImpl("http://testuri1";);
+        URI2 = URI2 + "testuri1";  // Make sure the strings don't intern to 
the same place
+        assertTrue(ns1.equals(URI2, ""));
+        assertTrue(ns1.equals(ns2));
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to