ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1147425 - 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...
Date Sat, 16 Jul 2011 13:16:35 GMT
Author: veithen
Date: Sat Jul 16 13:16:34 2011
New Revision: 1147425

URL: http://svn.apache.org/viewvc?rev=1147425&view=rev
Log:
Clarified the behavior of OMElement#declareNamespace with respect to generated namespace prefixes
and resynchronized the LLOM and DOOM implementations.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix1.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java
  (with props)
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=1147425&r1=1147424&r2=1147425&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
Sat Jul 16 13:16:34 2011
@@ -92,8 +92,7 @@ public interface OMElement extends OMNod
      * @param uri    The namespace to declare in the current scope.  The caller is expected
to
      *               ensure that the URI is a valid namespace name.
      * @param prefix The prefix to associate with the given namespace. The caller is expected
to
-     *               ensure that this is a valid XML prefix. If "" is given, first this will
check
-     *               for an existing namespace with the same uri. If not found, a prefix
will be
+     *               ensure that this is a valid XML prefix. If "" is given, a prefix will
be
      *               auto-generated.
      * @return Returns the created namespace information item.
      * @see #declareNamespace(OMNamespace)
@@ -118,9 +117,13 @@ public interface OMElement extends OMNod
 
     /**
      * Declares a namespace with the element as its scope.
-     *
-     * @param namespace The namespace to declare.
-     * @return Returns the namespace parameter passed.
+     * 
+     * @param namespace
+     *            The namespace to declare. If the prefix specified by the {@link OMNamespace}
+     *            object is <code>null</code>, then a prefix will be generated.
+     * @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.
      * @see #declareNamespace(String, String)
      * @see #findNamespace(String, String)
      * @see #getAllDeclaredNamespaces()

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=1147425&r1=1147424&r2=1147425&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 Jul 16 13:16:34 2011
@@ -741,7 +741,7 @@ public class ElementImpl extends ParentN
      * @see org.apache.axiom.om.OMElement#declareNamespace(String, String)
      */
     public OMNamespace declareNamespace(String uri, String prefix) {
-        if (prefix == null) {
+        if ("".equals(prefix)) {
             prefix = OMSerializerUtil.getNextNSPrefix();
         }
         

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=1147425&r1=1147424&r2=1147425&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 Jul 16 13:16:34 2011
@@ -366,8 +366,9 @@ public class OMElementImpl extends OMNod
      * @return Returns namespace.
      */
     public OMNamespace declareNamespace(String uri, String prefix) {
-        if ("".equals(prefix))
+        if ("".equals(prefix)) {
             prefix = OMSerializerUtil.getNextNSPrefix();
+        }
         OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
         return declareNamespace(ns);
     }

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=1147425&r1=1147424&r2=1147425&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
Sat Jul 16 13:16:34 2011
@@ -83,6 +83,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.TestDeclareNamespaceWithGeneratedPrefix1(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestDeclareNamespaceWithGeneratedPrefix2(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetAllAttributes1(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetAllAttributes2(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetAllDeclaredNamespaces(metaFactory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix1.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix1.java?rev=1147425&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix1.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix1.java
Sat Jul 16 13:16:34 2011
@@ -0,0 +1,53 @@
+/*
+ * 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 java.util.Iterator;
+
+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 that {@link OMElement#declareNamespace(OMNamespace)} generates a new prefix if the
prefix
+ * specified in the {@link OMNamespace} object is <code>null</code>.
+ */
+public class TestDeclareNamespaceWithGeneratedPrefix1 extends AxiomTestCase {
+    public TestDeclareNamespaceWithGeneratedPrefix1(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new QName("test"));
+        OMNamespace ns = element.declareNamespace(factory.createOMNamespace("urn:ns", null));
+        assertEquals("urn:ns", ns.getNamespaceURI());
+        assertNotNull(ns.getPrefix());
+        assertTrue(ns.getPrefix().length() > 0);
+        Iterator it = element.getAllDeclaredNamespaces();
+        assertTrue(it.hasNext());
+        OMNamespace ns2 = (OMNamespace)it.next();
+        assertEquals(ns, ns2);
+        assertFalse(it.hasNext());
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java?rev=1147425&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java
Sat Jul 16 13:16:34 2011
@@ -0,0 +1,53 @@
+/*
+ * 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 java.util.Iterator;
+
+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 that {@link OMElement#declareNamespace(String, String)} generates a new prefix if
the
+ * specified prefix is empty.
+ */
+public class TestDeclareNamespaceWithGeneratedPrefix2 extends AxiomTestCase {
+    public TestDeclareNamespaceWithGeneratedPrefix2(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = factory.createOMElement(new QName("test"));
+        OMNamespace ns = element.declareNamespace("urn:ns", "");
+        assertEquals("urn:ns", ns.getNamespaceURI());
+        assertNotNull(ns.getPrefix());
+        assertTrue(ns.getPrefix().length() > 0);
+        Iterator it = element.getAllDeclaredNamespaces();
+        assertTrue(it.hasNext());
+        OMNamespace ns2 = (OMNamespace)it.next();
+        assertEquals(ns, ns2);
+        assertFalse(it.hasNext());
+    }
+}

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



Mime
View raw message