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/22 21:15:15 UTC
svn commit: r1149695 - 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: Fri Jul 22 19:15:14 2011
New Revision: 1149695
URL: http://svn.apache.org/viewvc?rev=1149695&view=rev
Log:
AXIOM-375: Deprecated the usage of OMElement#declareNamespace(String,String) with prefix="".
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix3.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
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.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=1149695&r1=1149694&r2=1149695&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 Fri Jul 22 19:15:14 2011
@@ -94,8 +94,10 @@ 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, a prefix will be
- * auto-generated.
+ * ensure that this is a valid XML prefix. If <code>null</code> or the empty
+ * string is given, a prefix will be auto-generated. <b>Please note that using the
+ * empty string for this purpose is deprecated and will no longer be supported in
+ * Axiom 1.3.</b>
* @return Returns the created namespace information item.
* @throws IllegalArgumentException
* if an attempt is made to bind a prefix to the empty namespace name
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=1149695&r1=1149694&r2=1149695&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 Fri Jul 22 19:15:14 2011
@@ -36,6 +36,8 @@ import org.apache.axiom.om.impl.traverse
import org.apache.axiom.om.impl.traverse.OMQualifiedNameFilterIterator;
import org.apache.axiom.om.impl.util.EmptyIterator;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
@@ -57,6 +59,8 @@ import java.util.Iterator;
public class ElementImpl extends ParentNode implements Element, OMElement,
OMConstants {
+ private static final Log log = LogFactory.getLog(ElementImpl.class);
+
private int lineNumber;
protected OMNamespace namespace;
@@ -767,6 +771,7 @@ public class ElementImpl extends ParentN
*/
public OMNamespace declareNamespace(String uri, String prefix) {
if ("".equals(prefix)) {
+ log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty 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=1149695&r1=1149694&r2=1149695&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 Fri Jul 22 19:15:14 2011
@@ -206,7 +206,7 @@ public class OMElementImpl extends OMNod
OMNamespace namespace = findNamespace(namespaceURI,
prefix);
if (namespace == null) {
- namespace = declareNamespace(namespaceURI, prefix);
+ namespace = declareNamespace(namespaceURI, prefix.length() > 0 ? prefix : null);
}
return namespace;
}
@@ -377,6 +377,7 @@ public class OMElementImpl extends OMNod
*/
public OMNamespace declareNamespace(String uri, String prefix) {
if ("".equals(prefix)) {
+ log.warn("Deprecated usage of OMElement#declareNamespace(String,String) with empty prefix");
prefix = OMSerializerUtil.getNextNSPrefix();
}
OMNamespaceImpl ns = new OMNamespaceImpl(uri, 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=1149695&r1=1149694&r2=1149695&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 Fri Jul 22 19:15:14 2011
@@ -89,6 +89,7 @@ public class OMTestSuiteBuilder extends
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.TestDeclareNamespaceWithGeneratedPrefix3(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestFindNamespaceURIWithPrefixUndeclaring(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetAllAttributes1(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetAllAttributes2(metaFactory));
Modified: 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=1149695&r1=1149694&r2=1149695&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix2.java Fri Jul 22 19:15:14 2011
@@ -30,7 +30,8 @@ import org.apache.axiom.ts.AxiomTestCase
/**
* Tests that {@link OMElement#declareNamespace(String, String)} generates a new prefix if the
- * specified prefix is empty.
+ * specified prefix is empty. Note that this behavior will change in Axiom 1.3 (see
+ * <a href="https://issues.apache.org/jira/browse/AXIOM-373">AXIOM-373</a>).
*/
public class TestDeclareNamespaceWithGeneratedPrefix2 extends AxiomTestCase {
public TestDeclareNamespaceWithGeneratedPrefix2(OMMetaFactory metaFactory) {
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix3.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix3.java?rev=1149695&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix3.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDeclareNamespaceWithGeneratedPrefix3.java Fri Jul 22 19:15:14 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 <code>null</code>.
+ */
+public class TestDeclareNamespaceWithGeneratedPrefix3 extends AxiomTestCase {
+ public TestDeclareNamespaceWithGeneratedPrefix3(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", 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/TestDeclareNamespaceWithGeneratedPrefix3.java
------------------------------------------------------------------------------
svn:eol-style = native