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 2012/09/23 16:42:26 UTC

svn commit: r1389068 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/...

Author: veithen
Date: Sun Sep 23 14:42:25 2012
New Revision: 1389068

URL: http://svn.apache.org/viewvc?rev=1389068&view=rev
Log:
Ensure that a proper exception is thrown when attempting to access a part of a document that has already been consumed.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterConsume.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterDiscard.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1389068&r1=1389067&r2=1389068&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Sun Sep 23 14:42:25 2012
@@ -505,6 +505,16 @@ public abstract class StAXBuilder implem
         }
         if (!cache) {
             parserAccessed = true;
+            // Mark all containers in the hierarchy as discarded because they can no longer be built
+            OMContainerEx current = target;
+            while (current != null) {
+                current.discarded();
+                if (current instanceof OMElement) {
+                    current = (OMContainerEx)((OMElement)current).getParent();
+                } else {
+                    current = null;
+                }
+            }
             return parser;
         } else {
             throw new IllegalStateException(

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.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/OMContainerHelper.java?rev=1389068&r1=1389067&r2=1389068&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java Sun Sep 23 14:42:25 2012
@@ -20,6 +20,7 @@ package org.apache.axiom.om.impl.common;
 
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.om.NodeUnavailableException;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMSourcedElement;
@@ -169,9 +170,17 @@ public final class OMContainerHelper {
     }
     
     public static OMNode getFirstOMChild(IParentNode that) {
-        OMNode firstChild;
-        while ((firstChild = that.getFirstOMChildIfAvailable()) == null && !that.isComplete()) {
-            buildNext(that);
+        OMNode firstChild = that.getFirstOMChildIfAvailable();
+        if (firstChild == null) {
+            switch (that.getState()) {
+                case IParentNode.DISCARDED:
+                    throw new NodeUnavailableException();
+                case IParentNode.INCOMPLETE:
+                    do {
+                        buildNext(that);
+                    } while (that.getState() == IParentNode.INCOMPLETE
+                            && (firstChild = that.getFirstOMChildIfAvailable()) == null);
+            }
         }
         return firstChild;
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1389068&r1=1389067&r2=1389068&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sun Sep 23 14:42:25 2012
@@ -227,6 +227,8 @@ public class OMTestSuiteBuilder extends 
         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.TestGetFirstOMChildAfterConsume(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestGetFirstOMChildAfterDiscard(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, true));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterConsume.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterConsume.java?rev=1389068&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterConsume.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterConsume.java Sun Sep 23 14:42:25 2012
@@ -0,0 +1,58 @@
+/*
+ * 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.io.StringReader;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.NodeUnavailableException;
+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.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMContainer#getFirstOMChild()} throws the expected
+ * {@link NodeUnavailableException} if the element has been consumed using
+ * {@link OMContainer#getXMLStreamReaderWithoutCaching()}.
+ */
+public class TestGetFirstOMChildAfterConsume extends AxiomTestCase {
+    public TestGetFirstOMChildAfterConsume(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(
+                "<element><!--comment--><a/><!--comment--></element>")).getDocumentElement();
+        XMLStreamReader reader = element.getXMLStreamReaderWithoutCaching();
+        while (reader.hasNext()) {
+            reader.next();
+        }
+        try {
+            element.getFirstOMChild();
+            fail("Expected NodeUnavailableException");
+        } catch (NodeUnavailableException ex) {
+            // Expected
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterConsume.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterDiscard.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterDiscard.java?rev=1389068&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterDiscard.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterDiscard.java Sun Sep 23 14:42:25 2012
@@ -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.io.StringReader;
+
+import org.apache.axiom.om.NodeUnavailableException;
+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.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that {@link OMContainer#getFirstOMChild()} throws the expected
+ * {@link NodeUnavailableException} if the element has been discarded before the first child could
+ * be created.
+ */
+public class TestGetFirstOMChildAfterDiscard extends AxiomTestCase {
+    public TestGetFirstOMChildAfterDiscard(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(
+                "<element><!--comment--><a/><!--comment--></element>")).getDocumentElement();
+        element.discard();
+        try {
+            element.getFirstOMChild();
+            fail("Expected NodeUnavailableException");
+        } catch (NodeUnavailableException ex) {
+            // Expected
+        }
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetFirstOMChildAfterDiscard.java
------------------------------------------------------------------------------
    svn:eol-style = native