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 21:44:25 UTC

svn commit: r1149334 - 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/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/m...

Author: veithen
Date: Thu Jul 21 19:44:23 2011
New Revision: 1149334

URL: http://svn.apache.org/viewvc?rev=1149334&view=rev
Log:
AXIOM-372: Make sure that an exception is thrown if an attempt is made to bind a prefix to the empty namespace name.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid1.java
      - copied, changed from r1149320, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid2.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceInvalid.java   (with props)
Removed:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.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
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java?rev=1149334&r1=1149333&r2=1149334&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMElement.java Thu Jul 21 19:44:23 2011
@@ -90,9 +90,6 @@ public interface OMElement extends OMNod
     
     /**
      * Creates a namespace in the current element scope.
-     * <p>
-     * Note that this method allows to bind a prefix to the empty namespace URI. However, this will
-     * result in an error if the element is serialized as XML 1.0.
      *
      * @param uri    The namespace to declare in the current scope.  The caller is expected to
      *               ensure that the URI is a valid namespace name.
@@ -100,6 +97,8 @@ public interface OMElement extends OMNod
      *               ensure that this is a valid XML prefix. If "" is given, a prefix will be
      *               auto-generated.
      * @return Returns the created namespace information item.
+     * @throws IllegalArgumentException
+     *             if an attempt is made to bind a prefix to the empty namespace name
      * @see #declareNamespace(OMNamespace)
      * @see #findNamespace(String, String)
      * @see #getAllDeclaredNamespaces()
@@ -122,9 +121,6 @@ public interface OMElement extends OMNod
 
     /**
      * Declares a namespace with the element as its scope.
-     * <p>
-     * Note that this method allows to bind a prefix to the empty namespace URI. However, this will
-     * result in an error if the element is serialized as XML 1.0.
      * 
      * @param namespace
      *            The namespace to declare. If the prefix specified by the {@link OMNamespace}
@@ -132,6 +128,8 @@ public interface OMElement extends OMNod
      * @return The declared namespace, which will be equal to the {@link OMNamespace} object passed
      *         as parameter, except if the prefix was <code>null</code>, in which case the return
      *         value contains the generated prefix.
+     * @throws IllegalArgumentException
+     *             if an attempt is made to bind a prefix to the empty namespace name
      * @see #declareNamespace(String, String)
      * @see #findNamespace(String, String)
      * @see #getAllDeclaredNamespaces()
@@ -397,6 +395,8 @@ public interface OMElement extends OMNod
      * 
      * @param namespace
      *            the new namespace for this element
+     * @throws IllegalArgumentException
+     *             if an attempt is made to bind a prefix to the empty namespace name
      */
     void setNamespace(OMNamespace namespace);
 

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=1149334&r1=1149333&r2=1149334&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 Thu Jul 21 19:44:23 2011
@@ -742,6 +742,9 @@ public class ElementImpl extends ParentN
                 prefix = OMSerializerUtil.getNextNSPrefix();
                 namespace = new NamespaceImpl(namespace.getNamespaceURI(), prefix);
             }
+            if (prefix.length() > 0 && namespace.getNamespaceURI().length() == 0) {
+                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);

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=1149334&r1=1149333&r2=1149334&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 19:44:23 2011
@@ -419,6 +419,9 @@ public class OMElementImpl extends OMNod
             prefix = OMSerializerUtil.getNextNSPrefix();
             namespace = new OMNamespaceImpl(namespace.getNamespaceURI(), prefix);
         }
+        if (prefix.length() > 0 && namespace.getNamespaceURI().length() == 0) {
+            throw new IllegalArgumentException("Cannot bind a prefix to the empty namespace name");
+        }
         namespaces.put(prefix, namespace);
         return namespace;
     }

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=1149334&r1=1149333&r2=1149334&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 19:44:23 2011
@@ -85,7 +85,8 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestDeclareDefaultNamespace1(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestDeclareDefaultNamespace2(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespace1(metaFactory));
-        addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceInvalid(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceInvalid1(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceInvalid2(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceWithGeneratedPrefix1(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceWithGeneratedPrefix2(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestFindNamespaceURIWithPrefixUndeclaring(metaFactory));
@@ -152,6 +153,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSerializeAndConsumeWithIncompleteDescendant(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetNamespace(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestSetNamespaceInvalid(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetNamespaceWithMatchingBindingInScope(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetText(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestSetTextQName(metaFactory));

Copied: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid1.java (from r1149320, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid1.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid1.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java&r1=1149320&r2=1149334&rev=1149334&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid1.java Thu Jul 21 19:44:23 2011
@@ -21,27 +21,25 @@ package org.apache.axiom.ts.om.element;
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.ts.AxiomTestCase;
 
 /**
  * Tests Axiom's behavior when {@link OMElement#declareNamespace(String, String)} is used to add a
- * namespace declaration that binds a prefix to an empty namespace URI. This is forbidden by XML 1.0
- * and should result in an error when serializing the document.
+ * namespace declaration that binds a prefix to an empty namespace URI. This is forbidden by both
+ * XML 1.0 and XML 1.1.
  */
-public class TestDeclareNamespaceInvalid extends AxiomTestCase {
-    public TestDeclareNamespaceInvalid(OMMetaFactory metaFactory) {
+public class TestDeclareNamespaceInvalid1 extends AxiomTestCase {
+    public TestDeclareNamespaceInvalid1(OMMetaFactory metaFactory) {
         super(metaFactory);
     }
 
     protected void runTest() throws Throwable {
         OMElement element = metaFactory.getOMFactory().createOMElement(new QName("test"));
-        element.declareNamespace("", "ns");
         try {
-            element.toString();
-            fail("Expected OMException");
-        } catch (OMException ex) {
+            element.declareNamespace("", "ns");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
             // Expected
         }
     }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid2.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid2.java?rev=1149334&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid2.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceInvalid2.java Thu Jul 21 19:44:23 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.element;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests Axiom's behavior when {@link OMElement#declareNamespace(OMNamespace)} is used to add a
+ * namespace declaration that binds a prefix to an empty namespace URI. This is forbidden by both
+ * XML 1.0 and XML 1.1.
+ */
+public class TestDeclareNamespaceInvalid2 extends AxiomTestCase {
+    public TestDeclareNamespaceInvalid2(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new QName("test"));
+        OMNamespace ns = factory.createOMNamespace("", "ns");
+        try {
+            element.declareNamespace(ns);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            // Expected
+        }
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceInvalid.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceInvalid.java?rev=1149334&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceInvalid.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestSetNamespaceInvalid.java Thu Jul 21 19:44:23 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.element;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMElement#setNamespace(OMNamespace)} when the argument
+ * binds a prefix to the empty namespace name.
+ */
+public class TestSetNamespaceInvalid extends AxiomTestCase {
+    public TestSetNamespaceInvalid(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new QName("test"));
+        OMNamespace ns = factory.createOMNamespace("", "p");
+        try {
+            element.setNamespace(ns);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException ex) {
+            // Expected;
+        }
+    }
+}

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