ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1484187 - in /webservices/axiom/trunk/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsu...
Date Sat, 18 May 2013 22:02:27 GMT
Author: veithen
Date: Sat May 18 22:02:27 2013
New Revision: 1484187

URL: http://svn.apache.org/r1484187
Log:
AXIOM-288:
* Updated documentation of OMContainer#getXMLStreamReader(boolean).
* Added some test cases that validate that the builder is able to continue building the Axiom
tree after an element has been consumed using getXMLStreamReader.
* Correctly handle calls to close() on the XMLStreamReader returned by getXMLStreamReader.

Added:
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCloseWithoutCaching.java
  (with props)
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestCloseAndContinueBuilding.java
  (with props)
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/sr/TestCloseWithoutCaching.java
  (with props)
Modified:
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
    webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
(original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
Sat May 18 22:02:27 2013
@@ -25,6 +25,8 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.sax.SAXSource;
 
+import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
+import org.apache.axiom.util.stax.xop.XOPEncodingStreamReader;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.DTDHandler;
 import org.xml.sax.ext.DeclHandler;
@@ -274,7 +276,7 @@ public interface OMContainer extends OMS
 
     /**
      * Get a pull parser representation of this information item. This methods creates an
-     * {@link XMLStreamReader} instance that produces a sequence of StAX events for this
element and
+     * {@link XMLStreamReader} instance that produces a sequence of StAX events for this
container and
      * its content. The sequence of events is independent of the state of this element and
the value
      * of the <code>cache</code> parameter, but the side effects of calling this
method and
      * consuming the reader are different:
@@ -305,8 +307,11 @@ public interface OMContainer extends OMS
      * <td><code>false</code></td>
      * <td>The reader will delegate to the underlying parser starting from the event
corresponding
      * to the last information item that has been built. In other words, after synthesizing
a number
-     * of events, the reader will switch to delegation mode. An attempt to access the object
model
-     * afterwards will result in an error.</td>
+     * of events, the reader will switch to delegation mode (also called "pull through" mode).
+     * This will consume the part of the object model from which the reader was requested.
+     * An attempt to access that part of the object model afterwards will result in a
+     * {@link NodeUnavailableException}. Other parts of the object model can be accessed
in a normal
+     * way once the reader has been completely consumed or closed.</td>
      * </tr>
      * </table>
      * <p>
@@ -314,7 +319,7 @@ public interface OMContainer extends OMS
      * {@link XMLStreamReader#close()} method.
      * <p>
      * The returned reader MAY implement the extension defined by
-     * {@link org.apache.axiom.ext.stax.datahandler.DataHandlerReader} and any binary content
will
+     * {@link DataHandlerReader} and any binary content will
      * be reported using this extension. More precisely, if the object model contains an
      * {@link OMText} instance with {@link OMText#isBinary()} returning <code>true</code>
(or
      * would contain such an instance after it has been fully built), then its data will
always be
@@ -327,18 +332,10 @@ public interface OMContainer extends OMS
      * prior to 1.2.9 makes assumptions on the returned reader that should no longer be considered
      * valid:
      * <ul>
-     * <li>Some code assumes that the returned reader is an instance of
-     * {@link org.apache.axiom.om.impl.common.OMStAXWrapper}. While it is true that Axiom
internally uses
-     * this class to synthesize StAX events, it may wrap this instance in another reader
-     * implementation. E.g. depending on the log level, the reader will be wrapped using
-     * {@link org.apache.axiom.om.util.OMXMLStreamReaderValidator}. This was already the
case in
-     * Axiom versions prior to 1.2.9. It should also be noted that instances of
-     * {@link OMSourcedElement} (which extends the present interface) may return a reader
that is
-     * not implemented using {@link org.apache.axiom.om.impl.common.OMStAXWrapper}.</li>
      * <li>Some code uses the {@link OMXMLStreamReader} interface of the returned reader
to switch
      * off MTOM inlining using {@link OMXMLStreamReader#setInlineMTOM(boolean)}. This has
now been
      * deprecated and it is recommended to use
-     * {@link org.apache.axiom.util.stax.xop.XOPEncodingStreamReader} instead.</li>
+     * {@link XOPEncodingStreamReader} instead.</li>
      * <li>Some existing code uses the {@link OMAttachmentAccessor} interface of the
returned
      * reader to fetch attachments using {@link OMAttachmentAccessor#getDataHandler(String)}.
There
      * is no reason anymore to do so:</li>
@@ -353,7 +350,7 @@ public interface OMContainer extends OMS
      * with 1.2.9 this is no longer be the case: as specified above, the sequence of events
is
      * independent of the state of the object model and the value of the <code>cache</code>
      * parameter, and all binary content is reported through the
-     * {@link org.apache.axiom.ext.stax.datahandler.DataHandlerReader} extension.</li>
+     * {@link DataHandlerReader} extension.</li>
      * <li>Finally, it should be noted that {@link OMAttachmentAccessor#getDataHandler(String)}
      * doesn't give access to the attachments in the SwA case (neither in 1.2.9 nor in previous
      * versions).</li>
@@ -361,8 +358,8 @@ public interface OMContainer extends OMS
      * </ul>
      * <p>
      * Code making any of these assumptions should be fixed, so that only {@link XMLStreamReader}
-     * and {@link org.apache.axiom.ext.stax.datahandler.DataHandlerReader} are used (and
if
-     * necessary, {@link org.apache.axiom.util.stax.xop.XOPEncodingStreamReader}).
+     * and {@link DataHandlerReader} are used (and if
+     * necessary, {@link XOPEncodingStreamReader}).
      * 
      * @param cache
      *            indicates if caching should be enabled

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/AbstractWrapper.java
Sat May 18 22:02:27 2013
@@ -35,7 +35,6 @@ import org.apache.axiom.util.stax.XMLStr
 /**
  * Base class for {@link PullSerializerState} implementations that wrap an {@link XMLStreamReader}.
  */
-//TODO: what about the close() method?
 abstract class AbstractWrapper extends PullSerializerState implements CharacterDataReader
{
     protected final XMLStreamReader reader;
     private final PullSerializer serializer;
@@ -116,9 +115,15 @@ abstract class AbstractWrapper extends P
     }
 
     final void next() throws XMLStreamException {
-        if (depth == 0) {
+        if (!doNext()) {
             // We get here if the underlying XMLStreamReader is on the last END_ELEMENT event
             serializer.popState();
+        }
+    }
+    
+    final boolean doNext() throws XMLStreamException {
+        if (depth == 0) {
+            return false;
         } else {
             switch (reader.next()) {
                 case XMLStreamReader.START_ELEMENT:
@@ -128,6 +133,7 @@ abstract class AbstractWrapper extends P
                     depth--;
                     break;
             }
+            return true;
         }
     }
     
@@ -144,10 +150,6 @@ abstract class AbstractWrapper extends P
         return result;
     }
 
-    final void close() throws XMLStreamException {
-        reader.close();
-    }
-
     final Object getProperty(String name) throws IllegalArgumentException {
         return reader.getProperty(name);
     }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/ClosedState.java
Sat May 18 22:02:27 2013
@@ -44,10 +44,6 @@ final class ClosedState extends PullSeri
         return NullCharacterDataReader.INSTANCE;
     }
 
-    void close() throws XMLStreamException {
-        // no-op
-    }
-
     Object getProperty(String name) throws IllegalArgumentException {
         return null;
     }

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/EndDocumentState.java
Sat May 18 22:02:27 2013
@@ -65,11 +65,6 @@ final class EndDocumentState extends Pul
         throw new IllegalStateException();
     }
 
-    void close() throws XMLStreamException {
-        // TODO Auto-generated method stub
-        
-    }
-
     Object getProperty(String name) throws IllegalArgumentException {
         // TODO Auto-generated method stub
         return null;

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/Navigator.java
Sat May 18 22:02:27 2013
@@ -500,20 +500,6 @@ final class Navigator extends PullSerial
         return null;
     }
 
-    void close() throws XMLStreamException {
-        try {
-            // If there is a builder, it controls its parser
-            if (builder != null && builder instanceof StAXBuilder) {
-                StAXBuilder staxBuilder = (StAXBuilder) builder;
-                staxBuilder.close();
-            }
-        } finally {
-            // Note that as a side effect of this instruction, the Navigator instance
-            // will become unreachable and the parser can be GC'd or reused.
-            serializer.switchState(ClosedState.INSTANCE);
-        }
-    }
-
     boolean hasNext() throws XMLStreamException {
         return currentEvent != END_DOCUMENT;
     }
@@ -911,8 +897,6 @@ final class Navigator extends PullSerial
     }
 
     void released() throws XMLStreamException {
-        // TODO Auto-generated method stub
-        
     }
 
     void restored() throws XMLStreamException {

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializer.java
Sat May 18 22:02:27 2013
@@ -73,7 +73,12 @@ public final class PullSerializer extend
      */
     void switchState(PullSerializerState newState) throws XMLStreamException {
         PullSerializerState oldState = state;
+        PullSerializerState savedState = this.savedState;
         state = newState;
+        this.savedState = null;
+        if (savedState != null) {
+            savedState.released();
+        }
         oldState.released();
     }
     
@@ -99,12 +104,13 @@ public final class PullSerializer extend
      * @throws XMLStreamException 
      */
     void popState() throws XMLStreamException {
+        PullSerializerState savedState = this.savedState;
         if (savedState == null) {
             throw new IllegalStateException();
         }
+        this.savedState = null;
         switchState(savedState);
-        savedState = null;
-        state.restored();
+        savedState.restored();
     }
 
     OMDataSource getDataSource() {
@@ -139,7 +145,7 @@ public final class PullSerializer extend
     }
 
     public void close() throws XMLStreamException {
-        state.close();
+        switchState(ClosedState.INSTANCE);
     }
 
     public Object getProperty(String name) {

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullSerializerState.java
Sat May 18 22:02:27 2013
@@ -87,8 +87,6 @@ abstract class PullSerializerState {
      */
     abstract int nextTag() throws XMLStreamException ;
 
-    abstract void close() throws XMLStreamException;
-
     abstract Object getProperty(String name) throws IllegalArgumentException;
 
     abstract String getVersion();

Modified: webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
(original)
+++ webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/serializer/pull/PullThroughWrapper.java
Sat May 18 22:02:27 2013
@@ -22,6 +22,7 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 
 final class PullThroughWrapper extends AbstractWrapper {
@@ -35,6 +36,15 @@ final class PullThroughWrapper extends A
     }
 
     void released() throws XMLStreamException {
-        builder.reenableCaching(container);
+        if (container instanceof OMDocument) {
+            // No need to reenable caching; just close the builder
+            builder.close();
+        } else {
+            // Consume remaining events so that we can reenable caching
+            while (doNext()) {
+                // Just loop
+            }
+            builder.reenableCaching(container);
+        }
     }
 }

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
(original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
Sat May 18 22:02:27 2013
@@ -161,6 +161,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.document.TestSetOMDocumentElementReplace(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.sr.TestCharacterDataReaderFromParser(metaFactory,
true));
         addTest(new org.apache.axiom.ts.om.document.sr.TestCharacterDataReaderFromParser(metaFactory,
false));
+        addTest(new org.apache.axiom.ts.om.document.sr.TestCloseWithoutCaching(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReader(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReaderFromParser(metaFactory,
false, true));
         addTest(new org.apache.axiom.ts.om.document.sr.TestDTDReaderFromParser(metaFactory,
true, true));
@@ -346,6 +347,8 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestWriteTextToWithNonTextNodes(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.sr.TestClose(metaFactory, true));
         addTest(new org.apache.axiom.ts.om.element.sr.TestClose(metaFactory, false));
+        addTest(new org.apache.axiom.ts.om.element.sr.TestCloseAndContinueBuilding(metaFactory,
true));
+        addTest(new org.apache.axiom.ts.om.element.sr.TestCloseAndContinueBuilding(metaFactory,
false));
         for (int i=0; i<builderFactories.length; i++) {
             BuilderFactory bf = builderFactories[i];
             addTest(new org.apache.axiom.ts.om.element.sr.TestCommentEvent(metaFactory, bf,
true));
@@ -528,6 +531,9 @@ public class OMTestSuiteBuilder extends 
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestWrappedTextNodeOMDataSourceFromReader(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestWriteTextToWithNonDestructiveOMDataSource(metaFactory));
             addTest(new org.apache.axiom.ts.om.sourcedelement.sr.TestGetName(metaFactory));
+            for (int events = 0; events < 7; events++) {
+                addTest(new org.apache.axiom.ts.om.sourcedelement.sr.TestCloseWithoutCaching(metaFactory,
events));
+            }
         }
         addTest(new org.apache.axiom.ts.om.pi.TestDigest(metaFactory));
         addTest(new org.apache.axiom.ts.om.text.TestBase64StreamingWithGetSAXSource(metaFactory));

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCloseWithoutCaching.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCloseWithoutCaching.java?rev=1484187&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCloseWithoutCaching.java
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCloseWithoutCaching.java
Sat May 18 22:02:27 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.document.sr;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.commons.io.input.CountingInputStream;
+
+/**
+ * Tests the behavior of {@link XMLStreamReader#close()} on the {@link XMLStreamReader} returned
by
+ * a call {@link OMContainer#getXMLStreamReaderWithoutCaching()} on an {@link OMDocument}
created by
+ * a builder. In that case, closing the reader is expected to close the builder without parsing
the
+ * rest of the document.
+ */
+public class TestCloseWithoutCaching extends AxiomTestCase {
+    public TestCloseWithoutCaching(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        Writer writer = new OutputStreamWriter(baos, "UTF-8");
+        writer.write("<root><a>");
+        for (int i=0; i<20000; i++) {
+            writer.write('a');
+        }
+        writer.write("</a></root>");
+        writer.close();
+        CountingInputStream in = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
+        OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
in).getDocument();
+        XMLStreamReader reader = doc.getXMLStreamReaderWithoutCaching();
+        reader.next();
+        reader.next();
+        int count = in.getCount();
+        reader.close();
+        assertEquals(count, in.getCount());
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/sr/TestCloseWithoutCaching.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java?rev=1484187&r1=1484186&r2=1484187&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
(original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderOnNonRootElement.java
Sat May 18 22:02:27 2013
@@ -20,11 +20,20 @@ package org.apache.axiom.ts.om.element;
 
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.axiom.om.OMContainer;
 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;
 
+/**
+ * Tests that {@link OMContainer#getXMLStreamReader(boolean)} produces the correct sequence
of
+ * events when called on an {@link OMElement} that is not the root element. Also tests that
the rest
+ * of the document can be built after consuming the {@link XMLStreamReader}.
+ * <p>
+ * This is a regression test for
+ * <a href="https://issues.apache.org/jira/browse/AXIOM-288">AXIOM-288</a>.
+ */
 public class TestGetXMLStreamReaderOnNonRootElement extends AxiomTestCase {
     private final boolean cache;
     
@@ -36,10 +45,9 @@ public class TestGetXMLStreamReaderOnNon
 
     protected void runTest() throws Throwable {
         OMElement root = AXIOMUtil.stringToOM(metaFactory.getOMFactory(),
-                "<a><b><c/></b></a>");
-        OMElement child = (OMElement)root.getFirstOMChild();
-        XMLStreamReader stream = cache ? child.getXMLStreamReader()
-                : child.getXMLStreamReaderWithoutCaching();
+                "<a><b><c/></b><d>content</d></a>");
+        OMElement b = (OMElement)root.getFirstOMChild();
+        XMLStreamReader stream = b.getXMLStreamReader(cache);
         assertEquals(XMLStreamReader.START_DOCUMENT, stream.getEventType());
         assertEquals(XMLStreamReader.START_ELEMENT, stream.next());
         assertEquals("b", stream.getLocalName());
@@ -48,6 +56,8 @@ public class TestGetXMLStreamReaderOnNon
         assertEquals(XMLStreamReader.END_ELEMENT, stream.next());
         assertEquals(XMLStreamReader.END_ELEMENT, stream.next());
         assertEquals(XMLStreamReader.END_DOCUMENT, stream.next());
+        OMElement d = (OMElement)b.getNextOMSibling();
+        assertEquals("content", d.getText());
         root.close(false);
     }
 }

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestCloseAndContinueBuilding.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestCloseAndContinueBuilding.java?rev=1484187&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestCloseAndContinueBuilding.java
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/sr/TestCloseAndContinueBuilding.java
Sat May 18 22:02:27 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.sr;
+
+import java.io.StringReader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the rest of a document can still be built after calling
+ * {@link OMContainer#getXMLStreamReader(boolean)} and closing the returned {@link XMLStreamReader}.
+ * A call to {@link XMLStreamReader#close()} must not close the builder in this case.
+ * <p>
+ * This is a regression test for
+ * <a href="https://issues.apache.org/jira/browse/AXIOM-288">AXIOM-288</a>.
+ */
+public class TestCloseAndContinueBuilding extends AxiomTestCase {
+    private final boolean cache;
+    
+    public TestCloseAndContinueBuilding(OMMetaFactory metaFactory, boolean cache) {
+        super(metaFactory);
+        this.cache = cache;
+        addTestParameter("cache", cache);
+    }
+
+    protected void runTest() throws Throwable {
+        OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
new StringReader(
+                "<root><a><b>some text</b></a><c>content</c></root>")).getDocumentElement();
+        OMElement a = (OMElement)root.getFirstOMChild();
+        XMLStreamReader reader = a.getXMLStreamReader(cache);
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        assertEquals(new QName("b"), reader.getName());
+        reader.close();
+        assertFalse(root.isComplete());
+        OMElement c = (OMElement)a.getNextOMSibling();
+        assertEquals("content", c.getText());
+    }
+}

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

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/sr/TestCloseWithoutCaching.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/sr/TestCloseWithoutCaching.java?rev=1484187&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/sr/TestCloseWithoutCaching.java
(added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/sr/TestCloseWithoutCaching.java
Sat May 18 22:02:27 2013
@@ -0,0 +1,57 @@
+/*
+ * 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.sourcedelement.sr;
+
+import javax.xml.stream.XMLStreamReader;
+
+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.ds.AbstractPullOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource;
+
+/**
+ * Tests that calling {@link XMLStreamReader#close()} on an {@link XMLStreamReader} returned
by
+ * {@link OMContainer#getXMLStreamReaderWithoutCaching()} for an OM tree containing an
+ * {@link AbstractPullOMDataSource} closes all readers requested from the data source.
+ */
+public class TestCloseWithoutCaching extends AxiomTestCase {
+    private final int events;
+    
+    public TestCloseWithoutCaching(OMMetaFactory metaFactory, int events) {
+        super(metaFactory);
+        this.events = events;
+        addTestParameter("events", events);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMElement root = factory.createOMElement("root", null);
+        PullOMDataSource ds = new PullOMDataSource("<child>content</child>");
+        root.addChild(factory.createOMElement(ds));
+        XMLStreamReader reader = root.getXMLStreamReaderWithoutCaching();
+        for (int i=0; i<events; i++) {
+            reader.next();
+        }
+        reader.close();
+        assertFalse(ds.hasUnclosedReaders());
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/sr/TestCloseWithoutCaching.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message