You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by aj...@apache.org on 2005/03/10 14:02:44 UTC

svn commit: r156945 - in webservices/axis/trunk/java/modules/om/src: java/org/apache/axis/om/impl/llom/OMElementImpl.java java/org/apache/axis/om/impl/llom/OMStAXWrapper.java test/org/apache/axis/om/StaxParserTest.java

Author: ajith
Date: Thu Mar 10 05:02:42 2005
New Revision: 156945

URL: http://svn.apache.org/viewcvs?view=rev&rev=156945
Log:
Added a new test case to check the compliancy of the parser and modified the OMStaxWrapper to generate an end document event at the end and an start document event at the beginning

Added:
    webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/StaxParserTest.java
Modified:
    webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java
    webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java

Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java?view=diff&r1=156944&r2=156945
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMElementImpl.java Thu Mar 10 05:02:42 2005
@@ -738,7 +738,7 @@
     private void serializeNormal(XMLStreamWriter writer, boolean cache)
             throws XMLStreamException {
         serializeStartpart(writer);
-        OMNode firstChild = getFirstChild();
+        OMNode firstChild = getFirstChild();//todo
         if (firstChild != null) {
             firstChild.serialize(writer, cache);
         }

Modified: webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java?view=diff&r1=156944&r2=156945
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java (original)
+++ webservices/axis/trunk/java/modules/om/src/java/org/apache/axis/om/impl/llom/OMStAXWrapper.java Thu Mar 10 05:02:42 2005
@@ -79,21 +79,11 @@
      * Field NAVIGABLE
      */
     private static final short NAVIGABLE = 0;
-
-    /**
-     * Field SWITCH_AT_NEXT
-     */
     private static final short SWITCH_AT_NEXT = 1;
-
-    /**
-     * Field COMPLETED
-     */
     private static final short COMPLETED = 2;
-
-    /**
-     * Field SWITCHED
-     */
     private static final short SWITCHED = 3;
+    private static final short DOCUMENT_COMPLETE = 4;
+
 
     /**
      * Field state
@@ -102,8 +92,9 @@
 
     /**
      * Field currentEvent
+     * Default set to START_DOCUMENT
      */
-    private int currentEvent = 0;
+    private int currentEvent = START_DOCUMENT;
 
     // SwitchingAllowed is set to false by default
     // this means that unless the user explicitly states
@@ -763,7 +754,7 @@
      * @throws XMLStreamException
      */
     public boolean hasNext() throws XMLStreamException {
-        return !(state == COMPLETED);
+        return !(state == DOCUMENT_COMPLETE);
     }
 
     /**
@@ -809,15 +800,19 @@
      */
     public int next() throws XMLStreamException {
         switch (state) {
+            case DOCUMENT_COMPLETE:
+                throw new XMLStreamException("End of the document reached");
             case COMPLETED:
-                throw new OMStreamingException("Parser completed!");
+                state = DOCUMENT_COMPLETE;
+                currentEvent = END_DOCUMENT;
+                break;
             case SWITCH_AT_NEXT:
                 state = SWITCHED;
 
                 // load the parser
                 try {
                     parser = (XMLStreamReader) builder.getParser();
-                } catch (ClassCastException e) {
+                } catch (Exception e) {
                     throw new UnsupportedOperationException(
                             "incompatible parser found!");
                 }
@@ -881,6 +876,7 @@
             if (!switchingAllowed) {
                 if (navigator.isCompleted()) {
                     nextNode = null;
+
                 } else {
                     builder.next();
                     navigator.step();
@@ -910,7 +906,7 @@
             }
         } else {
             state = (currentEvent == END_DOCUMENT)
-                    ? COMPLETED
+                    ? DOCUMENT_COMPLETE
                     : state;
         }
     }

Added: webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/StaxParserTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/StaxParserTest.java?view=auto&rev=156945
==============================================================================
--- webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/StaxParserTest.java (added)
+++ webservices/axis/trunk/java/modules/om/src/test/org/apache/axis/om/StaxParserTest.java Thu Mar 10 05:02:42 2005
@@ -0,0 +1,93 @@
+package org.apache.axis.om;
+
+import org.apache.axis.om.impl.llom.factory.OMXMLBuilderFactory;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.io.ByteArrayInputStream;
+
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.
+*
+*  Aim of this test is to check the compatibilty of the stax parser implementation
+*/
+public class StaxParserTest extends AbstractTestCase {
+
+    XMLStreamReader parser1;
+    XMLStreamReader parser2;
+    XMLStreamReader parser3;
+    String xmlDocument = "<purchase-order xmlns=\"http://openuri.org/easypo\">\n" +
+            "  <customer>\n" +
+            "    <name>Gladys Kravitz</name>\n" +
+            "    <address>Anytown, PA</address>\n" +
+            "  </customer>\n" +
+            "  <date>2005-03-06T14:06:12.697+06:00</date>\n" +
+            "</purchase-order>";
+
+    public StaxParserTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        //make the parsers
+        parser1 = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(xmlDocument.getBytes()));
+
+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMFactory.newInstance(),
+                XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(xmlDocument.getBytes())));
+        parser2 = builder.getDocumentElement().getPullParser(false);
+
+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(OMFactory.newInstance(),
+                XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(xmlDocument.getBytes())));
+        parser3 = builder.getDocumentElement().getPullParser(true);
+        
+    }
+
+    public void xtestParserEvents() throws Exception{
+
+        assertEquals(parser1.getEventType(),parser2.getEventType());
+
+        while(parser1.hasNext()){
+            int parser1Event = parser1.next();
+            int parser2Event = parser2.next();
+            assertEquals(parser1Event,parser2Event);
+        }
+
+
+    }
+
+    public void testParserEvents2() throws Exception{
+        while(parser1.hasNext()){
+            int parser1Event = parser1.getEventType();
+            int parser2Event = parser2.getEventType();
+            parser1.next();
+            parser2.next();
+            assertEquals(parser1Event,parser2Event);
+        }
+
+
+    }
+}
+//     public void testParserEvents2() throws Exception{
+//
+//        System.out.println("parser2 initial = " + parser2.getEventType());
+//        while(parser2.hasNext()){
+//            System.out.println(" event "+ parser2.next() + parser2.getLocalName());
+//        }
+
+
+//}
+
+
+