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 2011/03/27 14:40:05 UTC

svn commit: r1085926 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/ axiom-api/src/test/java/org/apache/axiom/om/impl/ axiom-tests/src/test/java/org/apache/axiom/om/ axiom-testsuite/src/main/java...

Author: veithen
Date: Sun Mar 27 12:40:05 2011
New Revision: 1085926

URL: http://svn.apache.org/viewvc?rev=1085926&view=rev
Log:
AXIOM-358: Make sure that the hasNext() method in OMStAXWrapper/SwitchingWrapper conforms to the StAX specs and returns false if and only if the current event is END_DOCUMENT.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMWrapperTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReader.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java?rev=1085926&r1=1085925&r2=1085926&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/SwitchingWrapper.java Sun Mar 27 12:40:05 2011
@@ -152,8 +152,6 @@ class SwitchingWrapper extends AbstractX
     /** Track depth to ensure we stop generating events when we are done with the root node. */
     int depth = 0;
 
-    private boolean needToThrowEndDocument = false;
-
     // Cache attributes and namespaces. This avoids creating a new Iterator for every call
     // to getAttributeXXX and getNamespaceXXX. A value of -1 indicates that the
     // attributes or namespaces for the current element have not been loaded yet. The
@@ -210,9 +208,6 @@ class SwitchingWrapper extends AbstractX
         this.navigator = new OMNavigator(startNode);
         this.builder = builder;
         this.rootNode = startNode;
-        if (rootNode instanceof OMElement && ((OMElement)rootNode).getParent() instanceof OMDocument) {
-            needToThrowEndDocument = true;
-        }
 
         // initiate the next and current nodes
         // Note - navigator is written in such a way that it first
@@ -944,11 +939,7 @@ class SwitchingWrapper extends AbstractX
      * @throws XMLStreamException
      */
     public boolean hasNext() throws XMLStreamException {
-        if (needToThrowEndDocument) {
-            return !(state == DOCUMENT_COMPLETE);
-        } else {
-            return (state != COMPLETED && currentEvent != END_DOCUMENT);
-        }
+        return currentEvent != END_DOCUMENT;
     }
 
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java?rev=1085926&r1=1085925&r2=1085926&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/DocumentElementExtractor.java Sun Mar 27 12:40:05 2011
@@ -46,6 +46,9 @@ public class DocumentElementExtractor ex
                 case XMLStreamConstants.END_ELEMENT:
                     depth--;
                     break loop;
+                case XMLStreamConstants.START_DOCUMENT:
+                case XMLStreamConstants.END_DOCUMENT:
+                    break loop;
                 default:
                     if (depth > 0) {
                         break loop;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMWrapperTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMWrapperTest.java?rev=1085926&r1=1085925&r2=1085926&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMWrapperTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMWrapperTest.java Sun Mar 27 12:40:05 2011
@@ -72,7 +72,8 @@ public class OMWrapperTest extends TestC
             count ++;
         }
 
-        assertEquals(3, count);
+        // 4 events are produced: START_DOCUMENT, START_ELEMENT, END_ELEMENT and END_DOCUMENT
+        assertEquals(4, count);
         
         
         // Make sure that the wrapper can be closed without failing

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=1085926&r1=1085925&r2=1085926&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 Mar 27 12:40:05 2011
@@ -72,8 +72,10 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestGetFirstChildWithNameOnIncompleteElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetQNameWithoutNamespace(metaFactory));
         for (int i=0; i<conformanceFiles.length; i++) {
-            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], true));
-            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], false));
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], true, false));
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], false, false));
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], true, true));
+            addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReader(metaFactory, conformanceFiles[i], false, true));
         }
         addTest(new org.apache.axiom.ts.om.element.TestIsCompleteAfterAddingIncompleteChild(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestResolveQNameWithDefaultNamespace(metaFactory));

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReader.java?rev=1085926&r1=1085925&r2=1085926&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReader.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReader.java Sun Mar 27 12:40:05 2011
@@ -32,12 +32,16 @@ import org.apache.axiom.ts.om.container.
  * {@link OMElement}) with that of a native StAX parser.
  */
 public class TestGetXMLStreamReader extends GetXMLStreamReaderTestCase {
-    public TestGetXMLStreamReader(OMMetaFactory metaFactory, String file, boolean cache) {
+    private final boolean detached;
+    
+    public TestGetXMLStreamReader(OMMetaFactory metaFactory, String file, boolean cache, boolean detached) {
         super(metaFactory, file, cache);
+        this.detached = detached;
+        setName(getName() + " [detached=" + detached + "]");
     }
     
     protected OMContainer getContainer(OMXMLParserWrapper builder) {
-        return builder.getDocumentElement();
+        return builder.getDocumentElement(detached);
     }
 
     protected XMLStreamReader filter(XMLStreamReader reader) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java?rev=1085926&r1=1085925&r2=1085926&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java Sun Mar 27 12:40:05 2011
@@ -297,6 +297,8 @@ public class XMLStreamReaderComparator e
                 path.removeLast();
             }
             
+            assertSameResult("hasNext");
+            
             int expectedNextEvent;
             try {
                 expectedNextEvent = expected.next();