You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2008/05/27 16:37:13 UTC
svn commit: r660532 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
axiom-tests/src/test/java/org/apache/axiom/om/impl/traverse/OMChildrenWithQNameIteratorTest.java
Author: scheu
Date: Tue May 27 07:37:09 2008
New Revision: 660532
URL: http://svn.apache.org/viewvc?rev=660532&view=rev
Log:
WSCOMMONS-351
Contributor:Rich Scheuerle
Contributing patch which uses legacy behavior of getChildrenAsName to prevent customer breakage.
Added a verification test.
Modified:
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-tests/src/test/java/org/apache/axiom/om/impl/traverse/OMChildrenWithQNameIteratorTest.java
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=660532&r1=660531&r2=660532&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 Tue May 27 07:37:09 2008
@@ -37,6 +37,7 @@
import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
import org.apache.axiom.om.impl.traverse.OMChildElementIterator;
import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
+import org.apache.axiom.om.impl.traverse.OMChildrenLegacyQNameIterator;
import org.apache.axiom.om.impl.traverse.OMChildrenLocalNameIterator;
import org.apache.axiom.om.impl.traverse.OMChildrenNamespaceIterator;
import org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator;
@@ -214,15 +215,28 @@
* @throws OMException
*/
public Iterator getChildrenWithName(QName elementQName) {
- return new OMChildrenQNameIterator(getFirstOMChild(),
- elementQName);
+ OMNode firstChild = getFirstOMChild();
+ Iterator it = new OMChildrenQNameIterator(firstChild, elementQName);
- // The semantics of this call was changed.
- // The original sematics had a looser definition of QName equality.
- // To get this original functionality use:
- /*
- return new OMChildrenLegacyQNameIterator(getFirstOMChild(), elementQName);
- */
+ // The getChidrenWithName method used to tolerate an empty namespace
+ // and interpret that as getting any element that matched the local
+ // name. There are custmers of axiom that have hard-coded dependencies
+ // on this semantic.
+ // The following code falls back to this legacy behavior only if
+ // (a) elementQName has no namespace, (b) the new iterator finds no elements
+ // and (c) there are children.
+ if (elementQName.getNamespaceURI().length() == 0 &&
+ firstChild != null &&
+ !it.hasNext()) {
+ if (log.isDebugEnabled()) {
+ log.debug("There are no child elements that match the unqualifed name: " +
+ elementQName);
+ log.debug("Now looking for child elements that have the same local name.");
+ }
+ it = new OMChildrenLegacyQNameIterator(getFirstOMChild(), elementQName);
+ }
+
+ return it;
}
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/traverse/OMChildrenWithQNameIteratorTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/traverse/OMChildrenWithQNameIteratorTest.java?rev=660532&r1=660531&r2=660532&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/traverse/OMChildrenWithQNameIteratorTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/traverse/OMChildrenWithQNameIteratorTest.java Tue May 27 07:37:09 2008
@@ -31,6 +31,10 @@
public class OMChildrenWithQNameIteratorTest extends TestCase {
+ private final String NS_A = "urn://a";
+ private final String NS_B = "urn://b";
+ private final String NS_C = "urn://c";
+
public OMChildrenWithQNameIteratorTest(String testName) {
super(testName);
}
@@ -43,7 +47,7 @@
Iterator childrenIter = documentElement.getChildrenWithName(new QName("http://test.ws.org", "Employee", "test"));
- int childCount = getChidrenCount(childrenIter);
+ int childCount = getChildrenCount(childrenIter);
assertEquals("Iterator must return 1 child with the given qname", childCount, 1);
}
@@ -68,8 +72,54 @@
e.setText("Apache Developer");
return documentElement;
}
+
+ public void testGetChildrenWithQName() {
+
+ // Create a document with 2 children, each named "sample" but
+ // have different namespaces.
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace a = factory.createOMNamespace(NS_A, "a");
+ OMNamespace b = factory.createOMNamespace(NS_B, "b");
+
+ OMElement documentElement = factory.createOMElement("Document", a);
+ factory.createOMElement("sample", a, documentElement);
+ factory.createOMElement("sample", b, documentElement);
+
+
+ // Test for fully qualified names
+ QName qName = new QName(NS_A, "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 1);
+ qName = new QName(NS_B, "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 1);
+ qName = new QName(NS_C, "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 0);
+
+ // Test for QName with no namespace.
+ // The original Axiom implementation interpretted this as a wildcard.
+ // In order to not break existing code, this should return 2
+ qName = new QName("", "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 2);
+
+ // Now add an unqualified sample element to the documentElement
+ factory.createOMElement("sample", null, documentElement);
+
+
+ // Repeat the tests
+ qName = new QName(NS_A, "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 1);
+ qName = new QName(NS_B, "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 1);
+ qName = new QName(NS_C, "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 0);
+
+ // Since there actually is an unqualified element child, the most accurate
+ // interpretation of getChildrenWithName should be to return this one
+ // child
+ qName = new QName("", "sample");
+ assertTrue(getChildrenCount(documentElement.getChildrenWithName(qName)) == 1);
+ }
- private int getChidrenCount(Iterator childrenIter) {
+ private int getChildrenCount(Iterator childrenIter) {
int childCount = 0;
while (childrenIter.hasNext()) {
childrenIter.next();