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 2015/12/09 00:18:34 UTC
svn commit: r1718739 - in /webservices/axiom/branches/AXIOM-476:
aspects/core-aspects/src/main/java/org/apache/axiom/core/
aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/
testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ t...
Author: veithen
Date: Tue Dec 8 23:18:34 2015
New Revision: 1718739
URL: http://svn.apache.org/viewvc?rev=1718739&view=rev
Log:
Fix AXIOM-476 for the Axiom API.
Added:
webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetDescendants.java (with props)
Modified:
webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java
webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/Semantics.java
webservices/axiom/branches/AXIOM-476/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java
webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Modified: webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java?rev=1718739&r1=1718738&r2=1718739&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java (original)
+++ webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java Tue Dec 8 23:18:34 2015
@@ -77,9 +77,8 @@ public abstract class AbstractNodeIterat
} else {
boolean visitChildren = true;
while (true) {
- // TODO: test for CoreContainer instead????
- if (visitChildren && node instanceof CoreElement) {
- CoreChildNode firstChild = ((CoreElement)node).coreGetFirstChild();
+ if (visitChildren && node instanceof CoreParentNode && semantics.isParentNode(node.coreGetNodeType())) {
+ CoreChildNode firstChild = ((CoreParentNode)node).coreGetFirstChild();
if (firstChild != null) {
depth++;
node = firstChild;
Modified: webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/Semantics.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/Semantics.java?rev=1718739&r1=1718738&r2=1718739&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/Semantics.java (original)
+++ webservices/axiom/branches/AXIOM-476/aspects/core-aspects/src/main/java/org/apache/axiom/core/Semantics.java Tue Dec 8 23:18:34 2015
@@ -33,4 +33,15 @@ public interface Semantics {
* exists for these prefixes.
*/
boolean isUseStrictNamespaceLookup();
+
+ /**
+ * Check if the given node type is a parent node type. This determines the set of nodes that are
+ * selected by {@link Axis#DESCENDANTS} and {@link Axis#DESCENDANTS_OR_SELF}.
+ *
+ * @param node
+ * the node type to check
+ * @return {@code true} if the node type is a parent node; {@link false} if the node type is
+ * considered a leaf node type
+ */
+ boolean isParentNode(NodeType nodeType);
}
Modified: webservices/axiom/branches/AXIOM-476/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-476/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java?rev=1718739&r1=1718738&r2=1718739&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-476/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java (original)
+++ webservices/axiom/branches/AXIOM-476/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java Tue Dec 8 23:18:34 2015
@@ -45,6 +45,10 @@ public final class AxiomSemantics implem
return true;
}
+ public boolean isParentNode(NodeType nodeType) {
+ return nodeType == NodeType.DOCUMENT || nodeType == NodeType.NS_AWARE_ELEMENT;
+ }
+
public static final AttributeMatcher ATTRIBUTE_MATCHER = new NSAwareAttributeMatcher(
INSTANCE,
false, // Axiom doesn't support namespace unaware attributes
Modified: webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1718739&r1=1718738&r2=1718739&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Tue Dec 8 23:18:34 2015
@@ -155,6 +155,8 @@ public class OMTestSuiteBuilder extends
}
for (OMContainerFactory cf : getInstances(OMContainerFactory.class)) {
addTest(new org.apache.axiom.ts.om.container.TestAddChildWithIncompleteSibling(metaFactory, cf));
+ addTest(new org.apache.axiom.ts.om.container.TestGetDescendants(metaFactory, cf, true));
+ addTest(new org.apache.axiom.ts.om.container.TestGetDescendants(metaFactory, cf, false));
}
addTest(new org.apache.axiom.ts.om.document.TestAddChildIncomplete(metaFactory));
addTest(new org.apache.axiom.ts.om.document.TestAddChildWithExistingDocumentElement(metaFactory));
Added: webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetDescendants.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetDescendants.java?rev=1718739&view=auto
==============================================================================
--- webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetDescendants.java (added)
+++ webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetDescendants.java Tue Dec 8 23:18:34 2015
@@ -0,0 +1,69 @@
+/*
+ * 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.container;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMComment;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.ts.AxiomTestCase;
+
+public class TestGetDescendants extends AxiomTestCase {
+ private final OMContainerFactory containerFactory;
+ private final boolean includeSelf;
+
+ public TestGetDescendants(OMMetaFactory metaFactory, OMContainerFactory containerFactory, boolean includeSelf) {
+ super(metaFactory);
+ this.containerFactory = containerFactory;
+ containerFactory.addTestParameters(this);
+ this.includeSelf = includeSelf;
+ addTestParameter("includeSelf", includeSelf);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ OMFactory factory = metaFactory.getOMFactory();
+ OMContainer root = containerFactory.create(factory);
+ OMElement child1 = factory.createOMElement("child", null, root);
+ OMText child2 = factory.createOMText(root, "text", OMNode.CDATA_SECTION_NODE);
+ OMText grandchild1 = factory.createOMText(child1, "text");
+ OMComment grandchild2 = factory.createOMComment(child1, "text");
+ Iterator it = root.getDescendants(includeSelf);
+ if (includeSelf) {
+ assertThat(it.hasNext()).isTrue();
+ assertThat(it.next()).isEqualTo(root);
+ }
+ assertThat(it.hasNext()).isTrue();
+ assertThat(it.next()).isEqualTo(child1);
+ assertThat(it.hasNext()).isTrue();
+ assertThat(it.next()).isEqualTo(grandchild1);
+ assertThat(it.hasNext()).isTrue();
+ assertThat(it.next()).isEqualTo(grandchild2);
+ assertThat(it.hasNext()).isTrue();
+ assertThat(it.next()).isEqualTo(child2);
+ assertThat(it.hasNext()).isFalse();
+ }
+}
Propchange: webservices/axiom/branches/AXIOM-476/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/container/TestGetDescendants.java
------------------------------------------------------------------------------
svn:eol-style = native