Return-Path: X-Original-To: apmail-ws-commits-archive@minotaur.apache.org Delivered-To: apmail-ws-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4788A9A2F for ; Sun, 23 Sep 2012 14:43:11 +0000 (UTC) Received: (qmail 75152 invoked by uid 500); 23 Sep 2012 14:43:11 -0000 Delivered-To: apmail-ws-commits-archive@ws.apache.org Received: (qmail 75121 invoked by uid 500); 23 Sep 2012 14:43:11 -0000 Mailing-List: contact commits-help@ws.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ws.apache.org Delivered-To: mailing list commits@ws.apache.org Received: (qmail 75113 invoked by uid 99); 23 Sep 2012 14:43:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Sep 2012 14:43:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Sep 2012 14:43:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 86FB6238896F; Sun, 23 Sep 2012 14:42:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/... Date: Sun, 23 Sep 2012 14:42:26 -0000 To: commits@ws.apache.org From: veithen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120923144226.86FB6238896F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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( + "")).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( + "")).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