Author: veithen
Date: Sun Oct 2 17:42:35 2011
New Revision: 1178207
URL: http://svn.apache.org/viewvc?rev=1178207&view=rev
Log:
Added a proper API for OMDescendantsIterator.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAbstractIterator.java
- copied, changed from r1165002,
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMAbstractIterator.java
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDescendantsIterator.java
- copied, changed from r1165002,
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetDescendants.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.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-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.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-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.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/OMContainer.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1178207&r1=1178206&r2=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
Sun Oct 2 17:42:35 2011
@@ -106,6 +106,18 @@ public interface OMContainer extends OMS
* @see #getChildrenWithName
*/
Iterator getChildren();
+
+ /**
+ * Get an iterator over all descendants of the container. The items are
returned in document
+ * order. Note that attributes and namespace declarations are not
considered descendants.
+ *
+ * @param includeSelf
+ * <code>true</code> if the iterator should also return the
container itself;
+ * <code>false</code> if the first item returned by the
iterator should be the first
+ * child of the container
+ * @return an iterator over the descendants of this container
+ */
+ Iterator getDescendants(boolean includeSelf);
/**
* Gets the first child.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java?rev=1178207&r1=1178206&r2=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java
Sun Oct 2 17:42:35 2011
@@ -23,7 +23,9 @@ import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMNode;
/**
- * Iterator that iterates over all descendants in document order.
+ * @deprecated This type of iterator should always be created using
+ * {@link OMContainer#getDescendants(boolean)}, and this class
should never be
+ * referenced directly. It will be removed in Axiom 1.3.
*/
public class OMDescendantsIterator extends OMAbstractIterator {
private int level;
Copied:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAbstractIterator.java
(from r1165002,
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMAbstractIterator.java)
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAbstractIterator.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAbstractIterator.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMAbstractIterator.java&r1=1165002&r2=1178207&rev=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMAbstractIterator.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMAbstractIterator.java
Sun Oct 2 17:42:35 2011
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.axiom.om.impl.traverse;
+package org.apache.axiom.om.impl.common;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
@@ -25,23 +25,24 @@ import java.util.NoSuchElementException;
import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
/**
* Abstract base class for iterators over sets of OM nodes.
*/
public abstract class OMAbstractIterator implements Iterator {
- private OMNode currentNode;
+ private OMSerializable currentNode;
/**
* The parent of the current node. This is used to detect concurrent
modifications.
*/
private OMContainer currentParent;
- private OMNode nextNode;
+ private OMSerializable nextNode;
private boolean noMoreNodes;
private boolean nextCalled;
- public OMAbstractIterator(OMNode firstNode) {
+ public OMAbstractIterator(OMSerializable firstNode) {
if (firstNode == null) {
noMoreNodes = true;
} else {
@@ -55,7 +56,7 @@ public abstract class OMAbstractIterator
* @param currentNode the predecessor of the node to retrieve
* @return the next node
*/
- protected abstract OMNode getNextNode(OMNode currentNode);
+ protected abstract OMSerializable getNextNode(OMSerializable currentNode);
public boolean hasNext() {
if (noMoreNodes) {
@@ -63,7 +64,7 @@ public abstract class OMAbstractIterator
} else if (nextNode != null) {
return true;
} else {
- if (currentNode.getParent() != currentParent) {
+ if (currentNode instanceof OMNode &&
((OMNode)currentNode).getParent() != currentParent) {
throw new ConcurrentModificationException("The current node
has been removed using a method other than Iterator#remove()");
}
nextNode = getNextNode(currentNode);
@@ -75,7 +76,7 @@ public abstract class OMAbstractIterator
public Object next() {
if (hasNext()) {
currentNode = nextNode;
- currentParent = currentNode.getParent();
+ currentParent = currentNode instanceof OMNode ?
((OMNode)currentNode).getParent() : null;
nextNode = null;
nextCalled = true;
return currentNode;
@@ -90,7 +91,9 @@ public abstract class OMAbstractIterator
}
// Make sure that we know the next node before removing the current one
hasNext();
- currentNode.detach();
+ if (currentNode instanceof OMNode) {
+ ((OMNode)currentNode).detach();
+ }
nextCalled = false;
}
}
Copied:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDescendantsIterator.java
(from r1165002,
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java)
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDescendantsIterator.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDescendantsIterator.java&p1=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java&r1=1165002&r2=1178207&rev=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/traverse/OMDescendantsIterator.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMDescendantsIterator.java
Sun Oct 2 17:42:35 2011
@@ -17,10 +17,11 @@
* under the License.
*/
-package org.apache.axiom.om.impl.traverse;
+package org.apache.axiom.om.impl.common;
import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSerializable;
/**
* Iterator that iterates over all descendants in document order.
@@ -28,11 +29,12 @@ import org.apache.axiom.om.OMNode;
public class OMDescendantsIterator extends OMAbstractIterator {
private int level;
- public OMDescendantsIterator(OMNode firstNode) {
- super(firstNode);
+ public OMDescendantsIterator(OMContainer container, boolean includeSelf) {
+ super(includeSelf ? (OMSerializable)container :
(OMSerializable)container.getFirstOMChild());
+ level = includeSelf ? 0 : 1;
}
- protected OMNode getNextNode(OMNode currentNode) {
+ protected OMSerializable getNextNode(OMSerializable currentNode) {
if (currentNode instanceof OMContainer) {
OMNode firstChild = ((OMContainer)currentNode).getFirstOMChild();
if (firstChild != null) {
@@ -40,15 +42,16 @@ public class OMDescendantsIterator exten
return firstChild;
}
}
- OMNode node = currentNode;
+ OMSerializable node = currentNode;
while (true) {
- OMNode nextSibling = node.getNextOMSibling();
+ if (level == 0) {
+ return null;
+ }
+ OMNode nextSibling = ((OMNode)node).getNextOMSibling();
if (nextSibling != null) {
return nextSibling;
- } else if (level == 0) {
- return null;
} else {
- node = (OMNode)node.getParent();
+ node = ((OMNode)node).getParent();
level--;
}
}
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=1178207&r1=1178206&r2=1178207&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
Sun Oct 2 17:42:35 2011
@@ -30,9 +30,9 @@ import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.common.NamespaceIterator;
import org.apache.axiom.om.impl.common.OMChildElementIterator;
+import org.apache.axiom.om.impl.common.OMDescendantsIterator;
import org.apache.axiom.om.impl.common.OMNamespaceImpl;
import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
-import org.apache.axiom.om.impl.traverse.OMDescendantsIterator;
import org.apache.axiom.om.impl.traverse.OMQNameFilterIterator;
import org.apache.axiom.om.impl.traverse.OMQualifiedNameFilterIterator;
import org.apache.axiom.om.impl.util.EmptyIterator;
@@ -650,8 +650,7 @@ public class ElementImpl extends ParentN
final QName qname = new QName(namespaceURI, localName);
return new NodeListImpl() {
protected Iterator getIterator() {
- return new OMQNameFilterIterator(
- new OMDescendantsIterator(getFirstOMChild()), qname);
+ return new OMQNameFilterIterator(getDescendants(false), qname);
}
};
}
@@ -665,14 +664,14 @@ public class ElementImpl extends ParentN
if (name.equals("*")) {
return new NodeListImpl() {
protected Iterator getIterator() {
- return new OMDescendantsIterator(getFirstOMChild());
+ return getDescendants(false);
}
};
} else {
return new NodeListImpl() {
protected Iterator getIterator() {
return new OMQualifiedNameFilterIterator(
- new OMDescendantsIterator(getFirstOMChild()),
name);
+ getDescendants(false), name);
}
};
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1178207&r1=1178206&r2=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
Sun Oct 2 17:42:35 2011
@@ -34,6 +34,7 @@ import org.apache.axiom.om.impl.builder.
import org.apache.axiom.om.impl.common.OMChildrenLocalNameIterator;
import org.apache.axiom.om.impl.common.OMChildrenNamespaceIterator;
import org.apache.axiom.om.impl.common.OMChildrenQNameIterator;
+import org.apache.axiom.om.impl.common.OMDescendantsIterator;
import org.apache.axiom.om.impl.common.OMStAXWrapper;
import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
import org.apache.axiom.om.impl.jaxp.OMSource;
@@ -96,6 +97,10 @@ public abstract class ParentNode extends
return new OMChildrenIterator(getFirstOMChild());
}
+ public Iterator getDescendants(boolean includeSelf) {
+ return new OMDescendantsIterator(this, includeSelf);
+ }
+
/**
* Returns an iterator of child nodes having a given qname.
*
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=1178207&r1=1178206&r2=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
Sun Oct 2 17:42:35 2011
@@ -31,6 +31,7 @@ import org.apache.axiom.om.impl.OMNodeEx
import org.apache.axiom.om.impl.common.OMChildrenLocalNameIterator;
import org.apache.axiom.om.impl.common.OMChildrenNamespaceIterator;
import org.apache.axiom.om.impl.common.OMChildrenQNameIterator;
+import org.apache.axiom.om.impl.common.OMDescendantsIterator;
import org.apache.axiom.om.impl.common.OMDocumentImplUtil;
import org.apache.axiom.om.impl.jaxp.OMSource;
import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
@@ -196,6 +197,10 @@ public class OMDocumentImpl extends OMSe
return new OMChildrenIterator(getFirstOMChild());
}
+ public Iterator getDescendants(boolean includeSelf) {
+ return new OMDescendantsIterator(this, includeSelf);
+ }
+
/**
* Searches for children with a given QName and returns an iterator to
traverse through the
* OMNodes. The QName can contain any combination of prefix, localname and
URI.
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=1178207&r1=1178206&r2=1178207&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
Sun Oct 2 17:42:35 2011
@@ -39,6 +39,7 @@ import org.apache.axiom.om.impl.common.O
import org.apache.axiom.om.impl.common.OMChildrenLocalNameIterator;
import org.apache.axiom.om.impl.common.OMChildrenNamespaceIterator;
import org.apache.axiom.om.impl.common.OMChildrenQNameIterator;
+import org.apache.axiom.om.impl.common.OMDescendantsIterator;
import org.apache.axiom.om.impl.common.OMNamespaceImpl;
import org.apache.axiom.om.impl.jaxp.OMSource;
import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
@@ -358,6 +359,10 @@ public class OMElementImpl extends OMNod
return new OMChildrenIterator(getFirstOMChild());
}
+ public Iterator getDescendants(boolean includeSelf) {
+ return new OMDescendantsIterator(this, includeSelf);
+ }
+
/**
* Returns a filtered list of children - just the elements.
*
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=1178207&r1=1178206&r2=1178207&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
Sun Oct 2 17:42:35 2011
@@ -875,6 +875,11 @@ public class OMSourcedElementImpl extend
return super.getChildren();
}
+ public Iterator getDescendants(boolean includeSelf) {
+ forceExpand();
+ return super.getDescendants(includeSelf);
+ }
+
/* (non-Javadoc)
* @see org.apache.axiom.om.OMContainer#getFirstOMChild()
*/
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java?rev=1178207&r1=1178206&r2=1178207&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/mtom/MTOMStAXSOAPModelBuilderTest.java
Sun Oct 2 17:42:35 2011
@@ -29,7 +29,6 @@ import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLBuilderFactory;
import org.apache.axiom.om.OMXMLStreamReader;
import org.apache.axiom.om.impl.builder.StAXBuilder;
-import org.apache.axiom.om.impl.traverse.OMDescendantsIterator;
import org.apache.axiom.soap.SOAPModelBuilder;
import org.apache.axiom.util.stax.XMLStreamReaderUtils;
import org.apache.axiom.util.stax.xop.XOPEncodedStream;
@@ -161,7 +160,7 @@ public class MTOMStAXSOAPModelBuilderTes
OMDocument doc = builder.getDocument();
// Find all the binary nodes
List/*<OMText>*/ binaryNodes = new ArrayList();
- for (Iterator it = new OMDescendantsIterator(doc.getFirstOMChild());
it.hasNext(); ) {
+ for (Iterator it = doc.getDescendants(false); it.hasNext(); ) {
OMNode node = (OMNode)it.next();
if (node instanceof OMText) {
OMText text = (OMText)node;
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=1178207&r1=1178206&r2=1178207&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
Sun Oct 2 17:42:35 2011
@@ -141,6 +141,8 @@ public class OMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.om.element.TestGetChildrenWithName2(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetChildrenWithName3(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetChildrenWithName4(metaFactory));
+ addTest(new
org.apache.axiom.ts.om.element.TestGetDescendants(metaFactory, true));
+ addTest(new
org.apache.axiom.ts.om.element.TestGetDescendants(metaFactory, false));
addTest(new
org.apache.axiom.ts.om.element.TestGetFirstChildWithName(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetFirstChildWithNameOnIncompleteElement(metaFactory));
addTest(new
org.apache.axiom.ts.om.element.TestGetNamespacesInScope(metaFactory));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetDescendants.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetDescendants.java?rev=1178207&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetDescendants.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetDescendants.java
Sun Oct 2 17:42:35 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 org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestGetDescendants extends AxiomTestCase {
+ private final boolean includeSelf;
+
+ public TestGetDescendants(OMMetaFactory metaFactory, boolean includeSelf) {
+ super(metaFactory);
+ this.includeSelf = includeSelf;
+ addTestProperty("includeSelf", Boolean.toString(includeSelf));
+ }
+
+ protected void runTest() throws Throwable {
+ OMElement element = AXIOMUtil.stringToOM(metaFactory.getOMFactory(),
+ "<root><a><b><c><d/><e/></c></b><f/></a><g/></root>");
+ // We intentionally get the descendants of <a> so that we can test
containment
+ // (the iterator must never return <g>, which is a sibling of <a>).
+ Iterator it = element.getFirstElement().getDescendants(includeSelf);
+ if (includeSelf) {
+ assertEquals("a", ((OMElement)it.next()).getLocalName());
+ }
+ assertEquals("b", ((OMElement)it.next()).getLocalName());
+ assertEquals("c", ((OMElement)it.next()).getLocalName());
+ assertEquals("d", ((OMElement)it.next()).getLocalName());
+ assertEquals("e", ((OMElement)it.next()).getLocalName());
+ assertEquals("f", ((OMElement)it.next()).getLocalName());
+ assertFalse(it.hasNext());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetDescendants.java
------------------------------------------------------------------------------
svn:eol-style = native