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 2011/07/21 14:12:08 UTC

svn commit: r1149140 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/ axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/...

Author: veithen
Date: Thu Jul 21 12:12:06 2011
New Revision: 1149140

URL: http://svn.apache.org/viewvc?rev=1149140&view=rev
Log:
AXIOM-372: OMFactory should throw an exception if an attempt is made to create a prefixed element with an empty namespace name.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElementWithInvalidNamespace.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/OMElementCreator.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java?rev=1149140&r1=1149139&r2=1149140&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java Thu Jul 21 12:12:06 2011
@@ -47,6 +47,8 @@ public interface OMFactory {
      * @param ns
      *            the namespace, or <code>null</code> if the element has no namespace
      * @return the newly created element
+     * @throws IllegalArgumentException
+     *             if an attempt is made to create a prefixed element with an empty namespace name
      */
     OMElement createOMElement(String localName, OMNamespace ns);
 
@@ -60,6 +62,8 @@ public interface OMFactory {
      *            {@link #createOMElement(String, OMNamespace)}
      * @return the newly created element
      * @throws OMException
+     * @throws IllegalArgumentException
+     *             if an attempt is made to create a prefixed element with an empty namespace name
      */
     OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent)
             throws OMException;
@@ -107,7 +111,8 @@ public interface OMFactory {
      *            the namespace prefix, or <code>null</code> if a prefix should be generated
      * @return the newly created OMElement.
      * @throws IllegalArgumentException
-     *             if <code>namespaceURI</code> is <code>null</code>
+     *             if <code>namespaceURI</code> is <code>null</code> or if an attempt is made to
+     *             create a prefixed element with an empty namespace name
      */
     OMElement createOMElement(String localName,
                                      String namespaceURI,
@@ -127,6 +132,8 @@ public interface OMFactory {
      *            {@link #createOMElement(QName)}
      * @return Returns the new OMElement
      * @throws OMException if there's a namespace mapping problem
+     * @throws IllegalArgumentException
+     *             if an attempt is made to create a prefixed element with an empty namespace name
      */
     OMElement createOMElement(QName qname, OMContainer parent) throws OMException;
 
@@ -142,6 +149,8 @@ public interface OMFactory {
      * @return the new element
      * @throws OMException
      *             TODO: when???
+     * @throws IllegalArgumentException
+     *             if an attempt is made to create a prefixed element with an empty namespace name
      */
     OMElement createOMElement(QName qname) throws OMException;
 

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=1149140&r1=1149139&r2=1149140&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 Thu Jul 21 12:12:06 2011
@@ -222,6 +222,9 @@ public class OMDOMFactory implements OMF
             throws OMException {
         NamespaceImpl ns;
         if (qname.getNamespaceURI().length() == 0) {
+            if (qname.getPrefix().length() > 0) {
+                throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
+            }
             ns = null;
         } else if (qname.getPrefix() != null) {
             ns = new NamespaceImpl(qname.getNamespaceURI(), qname.getPrefix());

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1149140&r1=1149139&r2=1149140&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Thu Jul 21 12:12:06 2011
@@ -31,6 +31,7 @@ import org.apache.axiom.ts.om.element.Te
 import org.apache.axiom.ts.om.element.TestSetNamespace;
 import org.apache.axiom.ts.om.element.TestSetTextQName;
 import org.apache.axiom.ts.om.factory.TestCreateOMElementWithGeneratedPrefix;
+import org.apache.axiom.ts.om.factory.TestCreateOMElementWithInvalidNamespace;
 import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
 import org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnChild;
 
@@ -78,6 +79,9 @@ public class OMImplementationTest extend
         builder.exclude(TestGetChildrenWithName4.class);
         builder.exclude(TestSetNamespace.class);
         
+        // TODO: Need to fix AXIOM-373 first
+        builder.exclude(TestCreateOMElementWithInvalidNamespace.class);
+        
         return builder.build();
     }
 }

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=1149140&r1=1149139&r2=1149140&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 Thu Jul 21 12:12:06 2011
@@ -177,6 +177,8 @@ public class OMElementImpl extends OMNod
             if (ns != null) {
                 this.ns = ns;
             }
+        } else if (qname.getPrefix().length() > 0) {
+            throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
         }
         return ns;
     }
@@ -187,6 +189,11 @@ public class OMElementImpl extends OMNod
      * @return Returns namespace.
      */
     private OMNamespace handleNamespace(OMNamespace ns) {
+        String namespaceURI = ns.getNamespaceURI();
+        String prefix = ns.getPrefix();
+        if (ns.getNamespaceURI().length() == 0 && prefix != null && prefix.length() > 0) {
+            throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
+        }
         OMNamespace namespace = findNamespace(ns.getNamespaceURI(),
                                               ns.getPrefix());
         if (namespace == null) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1149140&r1=1149139&r2=1149140&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Thu Jul 21 12:12:06 2011
@@ -99,6 +99,9 @@ public class OMLinkedListImplFactory imp
         if (namespaceURI == null) {
             throw new IllegalArgumentException("namespaceURI must not be null");
         } else if (namespaceURI.length() == 0) {
+            if (prefix != null && prefix.length() > 0) {
+                throw new IllegalArgumentException("Cannot create a prefixed element with an empty namespace name");
+            }
             return createOMElement(localName, null);
         } else {
             return createOMElement(localName, createOMNamespace(namespaceURI, prefix));

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1149140&r1=1149139&r2=1149140&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Thu Jul 21 12:12:06 2011
@@ -160,6 +160,7 @@ public class OMTestSuiteBuilder extends 
                 addTest(new org.apache.axiom.ts.om.factory.TestCreateOMElementWithDefaultNamespace(metaFactory, creator));
             }
             addTest(new org.apache.axiom.ts.om.factory.TestCreateOMElementWithGeneratedPrefix(metaFactory, creator));
+            addTest(new org.apache.axiom.ts.om.factory.TestCreateOMElementWithInvalidNamespace(metaFactory, creator));
             addTest(new org.apache.axiom.ts.om.factory.TestCreateOMElementWithNonDefaultNamespace(metaFactory, creator));
             addTest(new org.apache.axiom.ts.om.factory.TestCreateOMElementWithoutNamespace(metaFactory, creator));
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/OMElementCreator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/OMElementCreator.java?rev=1149140&r1=1149139&r2=1149140&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/OMElementCreator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/OMElementCreator.java Thu Jul 21 12:12:06 2011
@@ -22,6 +22,7 @@ import javax.xml.namespace.QName;
 
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
 
 public abstract class OMElementCreator {
     public static final OMElementCreator[] INSTANCES = new OMElementCreator[] {
@@ -47,14 +48,14 @@ public abstract class OMElementCreator {
             public OMElement createOMElement(OMFactory factory, String localName,
                     String namespaceURI, String prefix) {
                 return factory.createOMElement(localName,
-                        namespaceURI.length() == 0 ? null : factory.createOMNamespace(namespaceURI, prefix));
+                        getOMNamespace(factory, namespaceURI, prefix));
             }
         },
         new OMElementCreator("String,OMNamespace,OMContainer", true) {
             public OMElement createOMElement(OMFactory factory, String localName,
                     String namespaceURI, String prefix) {
                 return factory.createOMElement(localName,
-                        namespaceURI.length() == 0 ? null : factory.createOMNamespace(namespaceURI, prefix), null);
+                        getOMNamespace(factory, namespaceURI, prefix), null);
             }
         },
         new OMElementCreator("String,String,String", true) {
@@ -83,4 +84,14 @@ public abstract class OMElementCreator {
 
     public abstract OMElement createOMElement(OMFactory factory, String localName,
             String namespaceURI, String prefix);
+    
+    static OMNamespace getOMNamespace(OMFactory factory, String namespaceURI, String prefix) {
+        if (prefix == null) {
+            return factory.createOMNamespace(namespaceURI, null);
+        } else if (prefix.length() == 0 && namespaceURI.length() == 0) {
+            return null;
+        } else {
+            return factory.createOMNamespace(namespaceURI, prefix);
+        }
+    }
 }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElementWithInvalidNamespace.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElementWithInvalidNamespace.java?rev=1149140&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElementWithInvalidNamespace.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElementWithInvalidNamespace.java Thu Jul 21 12:12:06 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.factory;
+
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMFactory} forbids creating prefixed elements with an empty namespace name.
+ * Neither XML 1.0 nor XML 1.1 allow binding a prefix to the empty namespace name.
+ */
+public class TestCreateOMElementWithInvalidNamespace extends AxiomTestCase {
+    private final OMElementCreator variant;
+    
+    public TestCreateOMElementWithInvalidNamespace(OMMetaFactory metaFactory, OMElementCreator variant) {
+        super(metaFactory);
+        this.variant = variant;
+        addTestProperty("variant", variant.getName());
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        try {
+            variant.createOMElement(factory, "test", "", "p");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            // Expected
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/factory/TestCreateOMElementWithInvalidNamespace.java
------------------------------------------------------------------------------
    svn:eol-style = native