axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r291574 - in /webservices/axis2/trunk/java/modules/xml: src/org/apache/axis2/om/impl/llom/ src/org/apache/axis2/om/impl/llom/builder/ test/org/apache/axis2/om/ test/org/apache/axis2/om/impl/serializer/
Date Mon, 26 Sep 2005 07:07:59 GMT
Author: ajith
Date: Mon Sep 26 00:07:36 2005
New Revision: 291574

URL: http://svn.apache.org/viewcvs?rev=291574&view=rev
Log:
Fixing the serializing cache problem. The primary cause was a missing 'if' in the StAXBuilder.java
class.

Modified:
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXBuilder.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/StaxParserTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/serializer/OMSerializerTest.java

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
Mon Sep 26 00:07:36 2005
@@ -238,9 +238,7 @@
 
     /**
      * This will give the next sibling. This can be an OMAttribute for OMAttribute or OMText
or OMELement for others.
-     *
      * @throws org.apache.axis2.om.OMException
-     *
      * @throws OMException
      */
     public OMNode getNextSibling() throws OMException {
@@ -555,6 +553,10 @@
         if ((builder == null) && !cache) {
             throw new UnsupportedOperationException(
                     "This element was not created in a manner to be switched");
+        }
+        if (builder.isCompleted() && !cache){
+               throw new UnsupportedOperationException(
+                    "The parser is already consumed!");
         }
         return new OMStAXWrapper(builder, this, cache);
     }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
Mon Sep 26 00:07:36 2005
@@ -24,6 +24,7 @@
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamReader;
 import java.util.Iterator;
 
 public class OMSerializerUtil {
@@ -195,7 +196,8 @@
                streamingOMSerializer.serialize(element.getXMLStreamReader(),
                 omOutput);
         }else{
-            streamingOMSerializer.serialize(element.getXMLStreamReaderWithoutCaching(),
+            XMLStreamReader xmlStreamReaderWithoutCaching = element.getXMLStreamReaderWithoutCaching();
+            streamingOMSerializer.serialize(xmlStreamReaderWithoutCaching,
                 omOutput);
         }
     }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java
Mon Sep 26 00:07:36 2005
@@ -828,11 +828,8 @@
                 try {
                     parser = (XMLStreamReader) builder.getParser();
                 } catch (Exception e) {
-                    throw new UnsupportedOperationException(
-                            "incompatible parser found!");                         
+                   throw new XMLStreamException("problem accessing the parser",e);
                 }
-//                log.info(
-//                        "Switching to the Real Stax parser to generated the future events");
 
                 if ((currentEvent == START_DOCUMENT) &&
                         (currentEvent == parser.getEventType())) {

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXBuilder.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXBuilder.java
Mon Sep 26 00:07:36 2005
@@ -344,6 +344,10 @@
      * @return
      */
     public Object getParser() {
+        if (parserAccessed){
+            throw new UnsupportedOperationException(
+                    "Parser already accessed!");  
+        }
         if (!cache) {
             parserAccessed = true;
             return parser;

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
Mon Sep 26 00:07:36 2005
@@ -45,7 +45,7 @@
      * Field document
      */
 
-    private boolean doDebug = false;
+    private boolean doDebug = true;
 
     /**
      * Constructor StAXOMBuilder

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/StaxParserTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/StaxParserTest.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/StaxParserTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/StaxParserTest.java
Mon Sep 26 00:07:36 2005
@@ -18,10 +18,7 @@
 
 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
 
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.*;
 import java.io.ByteArrayInputStream;
 import java.util.Iterator;
 
@@ -67,8 +64,8 @@
         parser3 =
                 builder2.getDocumentElement().getXMLStreamReaderWithoutCaching();
 
-       //parser4 is another instance of our parser accessing the same stream as parser3.
-       // Note - The implementation returns a *new* instance but with reference to
+        //parser4 is another instance of our parser accessing the same stream as parser3.
+        // Note - The implementation returns a *new* instance but with reference to
         //the same underlying stream!
         parser4 = builder2.getDocumentElement().getXMLStreamReaderWithoutCaching();
 
@@ -131,7 +128,7 @@
         //consume the parser. this should force the xml stream to be exhausted without
         //building the tree
         while(originalParser.hasNext()){
-           originalParser.next();
+            originalParser.next();
         }
 
         //try to find the children of the document element. This should produce an
@@ -139,8 +136,8 @@
         Iterator childElements = documentElement.getChildElements();
         try {
             while (childElements.hasNext()) {
-               childElements.next();
-               fail("The stream should've been consumed by now!");
+                childElements.next();
+                fail("The stream should've been consumed by now!");
             }
         } catch (Exception e) {
             //if we are here without failing, then we are successful
@@ -150,36 +147,71 @@
 
     public void testParserBehaviorCaching() throws Exception{
 
-           OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(
-                   OMAbstractFactory.getSOAP11Factory(),
-                   XMLInputFactory.newInstance().createXMLStreamReader(
-                           new ByteArrayInputStream(xmlDocument.getBytes())));
-
-           OMElement documentElement = builder2.getDocumentElement();
-           XMLStreamReader originalParser =
-                   documentElement.getXMLStreamReader();
-
-           //consume the parser. this should force the xml stream to be exhausted but the
-           //tree to be fully built
-           while(originalParser.hasNext()){
-              originalParser.next();
-           }
-
-           //try to find the children of the document element. This should *NOT* produce
an
-           //error even when the underlying stream is fully consumed , the object tree is
already complete
-           Iterator childElements = documentElement.getChildElements();
-           int count = 0;
-           try {
-               while (childElements.hasNext()) {
-                 childElements.next();
-                 count++;
-               }
-           } catch (Exception e) {
-               fail("The object tree needs to be built and traversing the children is to
be a success!");
-           }
+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(
+                OMAbstractFactory.getSOAP11Factory(),
+                XMLInputFactory.newInstance().createXMLStreamReader(
+                        new ByteArrayInputStream(xmlDocument.getBytes())));
+
+        OMElement documentElement = builder2.getDocumentElement();
+        XMLStreamReader originalParser =
+                documentElement.getXMLStreamReader();
+
+        //consume the parser. this should force the xml stream to be exhausted but the
+        //tree to be fully built
+        while(originalParser.hasNext()){
+            originalParser.next();
+        }
+
+        //try to find the children of the document element. This should *NOT* produce an
+        //error even when the underlying stream is fully consumed , the object tree is already
complete
+        Iterator childElements = documentElement.getChildElements();
+        int count = 0;
+        try {
+            while (childElements.hasNext()) {
+                childElements.next();
+                count++;
+            }
+        } catch (Exception e) {
+            fail("The object tree needs to be built and traversing the children is to be
a success!");
+        }
 
         assertEquals("Number of elements need to be 2",count,2);
-       }
+    }
+
+
+    public void testParserBehaviorNonCaching2() throws Exception{
+
+        OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(
+                OMAbstractFactory.getSOAP11Factory(),
+                XMLInputFactory.newInstance().createXMLStreamReader(
+                        new ByteArrayInputStream(xmlDocument.getBytes())));
+
+        OMElement documentElement = builder2.getDocumentElement();
+
+        XMLStreamReader originalParser =
+                documentElement.getXMLStreamReaderWithoutCaching();
+
+        //consume the parser. this should force the xml stream to be exhausted without
+        //building the tree
+        while(originalParser.hasNext()){
+            originalParser.next();
+        }
+
+        //try to find the children of the document element. This should produce an
+        //error since the underlying stream is fully consumed without building the object
tree
+        Iterator childElements = documentElement.getChildElements();
+        try {
+            XMLStreamWriter writer =
+                    XMLOutputFactory.newInstance().
+                            createXMLStreamWriter(System.out);
+            documentElement.serialize(writer);
+            fail("Stream should be consumed by now");
+        }catch(XMLStreamException e){
+           //wea re cool
+        } catch (Exception e) {
+           fail("This should throw an XMLStreamException");
+        }
+    }
 
 }
 

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/serializer/OMSerializerTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/serializer/OMSerializerTest.java?rev=291574&r1=291573&r2=291574&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/serializer/OMSerializerTest.java
(original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/serializer/OMSerializerTest.java
Mon Sep 26 00:07:36 2005
@@ -24,10 +24,7 @@
 import org.apache.axis2.soap.SOAPBody;
 import org.apache.axis2.soap.SOAPEnvelope;
 
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.*;
 import java.io.File;
 import java.io.FileReader;
 
@@ -43,14 +40,14 @@
     protected void setUp() throws Exception {
         reader =
                 XMLInputFactory.newInstance().
-                createXMLStreamReader(
-                        new FileReader(
-                                getTestResourceFile("soap/soapmessage.xml")));
+                        createXMLStreamReader(
+                                new FileReader(
+                                        getTestResourceFile("soap/soapmessage.xml")));
         tempFile = File.createTempFile("temp", "xml");
 //        writer =
 //                XMLOutputFactory.newInstance().
 //                        createXMLStreamWriter(new FileOutputStream(tempFile));
-         writer =
+        writer =
                 XMLOutputFactory.newInstance().
                         createXMLStreamWriter(System.out);
     }
@@ -59,6 +56,8 @@
         StreamingOMSerializer serializer = new StreamingOMSerializer();
         //serializer.setNamespacePrefixStack(new Stack());
         serializer.serialize(reader, writer);
+        writer.flush();
+
 
     }
 
@@ -69,14 +68,26 @@
         SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
         StreamingOMSerializer serializer = new StreamingOMSerializer();
         serializer.serialize(env.getXMLStreamReaderWithoutCaching(), writer);
+        writer.flush();
     }
 
     public void testElementPullStream1WithCacheOff() throws Exception {
         OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(
                 OMAbstractFactory.getSOAP11Factory(),
                 reader);
+
         SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
         env.serialize(writer);
+        writer.flush();
+
+        //now we should not be able to serilaize anything ! this should throw
+        //an error
+        try {
+           env.serialize(writer);
+           fail();
+        } catch (XMLStreamException e) {
+
+        }
     }
 
     public void testElementPullStream2() throws Exception {
@@ -88,10 +99,10 @@
         StreamingOMSerializer serializer = new StreamingOMSerializer();
         serializer.serialize(body.getXMLStreamReaderWithoutCaching(),
                 writer);
+        writer.flush();
     }
 
     protected void tearDown() throws Exception {
-        writer.flush();
         tempFile.delete();
     }
 }



Mime
View raw message