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/11/24 00:45:09 UTC
svn commit: r1205664 - 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: Wed Nov 23 23:45:08 2011
New Revision: 1205664
URL: http://svn.apache.org/viewvc?rev=1205664&view=rev
Log:
AXIOM-398: Normalize the return value of getNamespace for OMElement and OMSourcedElement instances.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetNamespaceNormalized.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamedInformationItem.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-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.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/TestGetNamespaceNormalized.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamedInformationItem.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamedInformationItem.java?rev=1205664&r1=1205663&r2=1205664&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamedInformationItem.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMNamedInformationItem.java Wed Nov 23 23:45:08 2011
@@ -43,7 +43,9 @@ public interface OMNamedInformationItem
* Get the namespace this information item is part of.
*
* @return the namespace of this information item, or <code>null</code> if the information item
- * has no namespace
+ * has no namespace (note that this implies that the method never returns an
+ * {@link OMNamespace} object with both prefix and namespace URI set to the empty
+ * string)
*/
OMNamespace getNamespace();
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=1205664&r1=1205663&r2=1205664&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 Wed Nov 23 23:45:08 2011
@@ -177,7 +177,7 @@ public class ElementImpl extends ParentN
if (defaultNamespace != null && defaultNamespace.getNamespaceURI().length() > 0) {
declareDefaultNamespace("");
}
- return ns; // TODO: actually this should be null if we want to normalize the OMNamespace (see AXIOM-398)
+ return null;
} else {
OMNamespace namespace = findNamespace(namespaceURI, prefix);
if (namespace == null) {
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=1205664&r1=1205663&r2=1205664&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 Wed Nov 23 23:45:08 2011
@@ -194,7 +194,7 @@ public class OMElementImpl extends OMNod
if (defaultNamespace != null && defaultNamespace.getNamespaceURI().length() > 0) {
declareDefaultNamespace("");
}
- return ns; // TODO: actually this should be null if we want to normalize the OMNamespace (see AXIOM-398)
+ return null;
} else {
OMNamespace namespace = findNamespace(namespaceURI, prefix);
if (namespace == null) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1205664&r1=1205663&r2=1205664&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Wed Nov 23 23:45:08 2011
@@ -82,6 +82,16 @@ public class OMSourcedElementImpl extend
private XMLStreamReader readerFromDS = null; // Reader from DataSource
+ private static OMNamespace normalize(OMNamespace ns) {
+ // TODO: the ns.getPrefix() == null case actually doesn't make sense for a sourced element!
+ return ns == null || (ns.getPrefix() == null || ns.getPrefix().length() == 0) && ns.getNamespaceURI().length() == 0 ? null : ns;
+ }
+
+ private static OMNamespace getOMNamespace(QName qName) {
+ return qName.getNamespaceURI().length() == 0 ? null
+ : new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
+ }
+
/**
* Constructor.
*
@@ -98,13 +108,13 @@ public class OMSourcedElementImpl extend
if (!isExpanded) {
if (!isLossyPrefix(dataSource)) {
// Believe the prefix and create a normal OMNamespace
- definedNamespace = ns;
+ definedNamespace = normalize(ns);
} else {
// Create a deferred namespace that forces an expand to get the prefix
definedNamespace = new DeferredNamespace(ns.getNamespaceURI());
}
} else {
- definedNamespace = ns;
+ definedNamespace = normalize(ns);
}
}
@@ -123,13 +133,13 @@ public class OMSourcedElementImpl extend
if (!isExpanded) {
if (!isLossyPrefix(dataSource)) {
// Believe the prefix and create a normal OMNamespace
- definedNamespace = new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
+ definedNamespace = getOMNamespace(qName);
} else {
// Create a deferred namespace that forces an expand to get the prefix
definedNamespace = new DeferredNamespace(qName.getNamespaceURI());
}
} else {
- definedNamespace = new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
+ definedNamespace = getOMNamespace(qName);
}
}
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=1205664&r1=1205663&r2=1205664&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 Wed Nov 23 23:45:08 2011
@@ -158,7 +158,8 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestGetFirstChildWithNameOnIncompleteElement(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceContext(metaFactory, false));
addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceContext(metaFactory, true));
- addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceNormalized(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceNormalized(metaFactory, true));
+ addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceNormalized(metaFactory, false));
addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceNormalizedWithParser(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetNamespaceNormalizedWithSAXSource(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetNamespacesInScope(metaFactory));
@@ -277,6 +278,8 @@ public class OMTestSuiteBuilder extends
if (supportsOMSourcedElement) {
addTest(new org.apache.axiom.ts.om.sourcedelement.TestComplete(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestExpand(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized(metaFactory));
+ addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetNamespaceNormalized2(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetTextAsStreamWithNonDestructiveOMDataSource(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1DefaultPrefix(metaFactory));
addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1QualifiedPrefix(metaFactory));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetNamespaceNormalized.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetNamespaceNormalized.java?rev=1205664&r1=1205663&r2=1205664&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetNamespaceNormalized.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetNamespaceNormalized.java Wed Nov 23 23:45:08 2011
@@ -22,6 +22,7 @@ import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMMetaFactory;
import org.apache.axiom.om.OMNamedInformationItem;
+import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.ts.AxiomTestCase;
/**
@@ -31,18 +32,27 @@ import org.apache.axiom.ts.AxiomTestCase
* versions of Axiom returned a non null value in this case to work around an issue in the
* serialization code.
* <p>
+ * The test is executed twice: once with a <code>null</code> {@link OMNamespace} and once with an
+ * {@link OMNamespace} object with prefix and namespace URI set to the empty string. The expected
+ * result is the same in both cases.
+ * <p>
* This is a regression test for <a
* href="https://issues.apache.org/jira/browse/AXIOM-398">AXIOM-398</a>.
*/
public class TestGetNamespaceNormalized extends AxiomTestCase {
- public TestGetNamespaceNormalized(OMMetaFactory metaFactory) {
+ private final boolean useNull;
+
+ public TestGetNamespaceNormalized(OMMetaFactory metaFactory, boolean useNull) {
super(metaFactory);
+ this.useNull = useNull;
+ addTestProperty("useNull", String.valueOf(useNull));
}
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMElement parent = factory.createOMElement("parent", "urn:test", "");
- OMElement child = factory.createOMElement("child", null);
+ OMNamespace ns = useNull ? null : factory.createOMNamespace("", "");
+ OMElement child = factory.createOMElement("child", ns);
parent.addChild(child);
assertNull(child.getNamespace());
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetNamespaceNormalized.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetNamespaceNormalized.java?rev=1205664&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetNamespaceNormalized.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetNamespaceNormalized.java Wed Nov 23 23:45:08 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.sourcedelement;
+
+import org.apache.axiom.om.OMDataSource;
+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.om.OMSourcedElement;
+import org.apache.axiom.om.ds.CharArrayDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMElement#getNamespace()} returns <code>null</code> even if an
+ * {@link OMNamespace} object with empty prefix and namespace URI was passed to
+ * {@link OMFactory#createOMElement(OMDataSource, String, OMNamespace)}.
+ * <p>
+ * This is a regression test for <a
+ * href="https://issues.apache.org/jira/browse/AXIOM-398">AXIOM-398</a>.
+ */
+public class TestGetNamespaceNormalized extends AxiomTestCase {
+ public TestGetNamespaceNormalized(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace("", "");
+ OMSourcedElement element = factory.createOMElement(new CharArrayDataSource(
+ "<element>content</element>".toCharArray()), "element", ns);
+ // This actually returns the "declared" namespace because the sourced element is not
+ // expanded yet. Nevertheless the value should have been normalized to null.
+ assertNull(element.getNamespace());
+ // Now expand the element and check getNamespace() again
+ element.getFirstOMChild();
+ assertNull(element.getNamespace());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetNamespaceNormalized.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java?rev=1205664&r1=1205663&r2=1205664&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName1Unqualified.java Wed Nov 23 23:45:08 2011
@@ -51,8 +51,7 @@ public class TestName1Unqualified extend
// Test getting the namespace, localpart and prefix. This should used not result in expansion
assertTrue(element.getLocalName().equals("library"));
- assertTrue(element.getNamespace().getNamespaceURI().equals(""));
- assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertNull(element.getNamespace());
// Serialize and cache. This should cause expansion and update the name to match the testDocument string
StringWriter writer = new StringWriter();
@@ -62,8 +61,7 @@ public class TestName1Unqualified extend
String result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
- assertTrue(element.getNamespace().getNamespaceURI().equals(""));
- assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertNull(element.getNamespace());
assertTrue(element.getDefaultNamespace() == null ||
element.getDefaultNamespace().getNamespaceURI().length() == 0);
assertTrue(result.indexOf("xmlns=") <
@@ -78,8 +76,7 @@ public class TestName1Unqualified extend
result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
- assertTrue(element.getNamespace().getNamespaceURI().equals(""));
- assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertNull(element.getNamespace());
assertTrue(result.indexOf("xmlns=") <
0);// Make sure that the serialized string does not contain default prefix declaration
assertTrue(element.getDefaultNamespace() == null ||
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java?rev=1205664&r1=1205663&r2=1205664&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestName2Unqualified.java Wed Nov 23 23:45:08 2011
@@ -51,8 +51,7 @@ public class TestName2Unqualified extend
// Test getting the namespace, localpart and prefix. This should used not result in expansion
assertTrue(element.getLocalName().equals("library"));
- assertTrue(element.getNamespace().getNamespaceURI().equals(""));
- assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertNull(element.getNamespace());
// Serialize and consume. This should not cause expansion and currently won't update
// the name of the element.
@@ -63,8 +62,7 @@ public class TestName2Unqualified extend
String result = writer.toString();
assertTrue(element.getLocalName().equals("library"));
- assertTrue(element.getNamespace().getNamespaceURI().equals(""));
- assertTrue(element.getNamespace().getPrefix().equals(""));
+ assertNull(element.getNamespace());
assertTrue(result.indexOf("xmlns=") <
0);// Make sure that the serialized string does not contain default prefix declaration