You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2008/03/07 14:47:09 UTC

svn commit: r634674 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-tests/src/test/java/org/apache/axiom/om/

Author: scheu
Date: Fri Mar  7 05:47:09 2008
New Revision: 634674

URL: http://svn.apache.org/viewvc?rev=634674&view=rev
Log:
WSCOMMONS-226
Contributor:Rich Scheuerle (Test Raymond Feng)
Contributing unit test and fix for OMSourcedElement serialization error.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SourcedOMElementTestCase.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=634674&r1=634673&r2=634674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Fri Mar  7 05:47:09 2008
@@ -436,8 +436,9 @@
             log.debug("getting XMLStreamReader without caching for " +
                     getPrintableName());
         }
-        if (isExpanded) {
-            return super.getXMLStreamReaderWithoutCaching();
+        if (isExpanded) {         
+            XMLStreamReader reader = super.getXMLStreamReaderWithoutCaching();
+            return reader;
         } else {
             return getDirectReader();
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java?rev=634674&r1=634673&r2=634674&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMStAXWrapper.java Fri Mar  7 05:47:09 2008
@@ -40,6 +40,7 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.EmptyOMLocation;
@@ -193,11 +194,25 @@
             needToThrowEndDocument = true;
         }
 
-        // initaite the next and current nodes
+        // initiate the next and current nodes
         // Note -  navigator is written in such a way that it first
         // returns the starting node at the first call to it
+        // Note - for OMSourcedElements, temporarily set caching
+        // to get the initial navigator nodes
+        boolean resetCache = false;
+        try {
+            if (startNode instanceof OMSourcedElement && 
+                    !cache && builder != null) {
+                builder.setCache(true); // bootstrap the navigator
+                resetCache = true;
+            }
+        } catch(Throwable t) {}
+        
         currentNode = navigator.next();
         updateNextNode();
+        if (resetCache) {
+            builder.setCache(cache); 
+        }
         switchingAllowed = !cache;
     }
 

Added: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SourcedOMElementTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SourcedOMElementTestCase.java?rev=634674&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SourcedOMElementTestCase.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SourcedOMElementTestCase.java Fri Mar  7 05:47:09 2008
@@ -0,0 +1,100 @@
+/*
+ * 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.om;
+
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+
+
+public class SourcedOMElementTestCase extends TestCase {
+    
+    public void testSerialization() throws Exception {
+        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = factory.createSOAPEnvelope();
+        SOAPBody body = factory.createSOAPBody();
+        envelope.addChild(body);
+        OMNamespace ns = factory.createOMNamespace("http://ns1", "d");
+        OMElement payload = factory.createOMElement(new DummySource(), "dummy", ns);
+        payload.setNamespace(ns); // This line will cause NoSuchElementException
+        body.addChild(payload);
+        payload.getBuilder().setCache(false); // Or This line will cause NoSuchElementException
+        StringWriter writer = new StringWriter();
+        envelope.serializeAndConsume(writer);
+        System.out.println(writer);
+    }
+    
+    private static class DummySource implements OMDataSource {
+        private XMLInputFactory factory = XMLInputFactory.newInstance();
+        private XMLStreamReader reader;
+        //private String xml = "<?xml version='1.0'?><d:dummy name='1' xmlns:d='http://ns1'/>";
+        private String xml = "<?xml version='1.0'?><d:dummy name='1' xmlns:d='http://ns1'>hello<mixed/>world</d:dummy>";
+        
+        /**
+         * @see org.apache.axiom.om.OMDataSource#getReader()
+         */
+        public XMLStreamReader getReader() throws XMLStreamException {
+            // TODO Auto-generated method stub
+            return factory.createXMLStreamReader(new StringReader(xml));
+        }
+
+        /**
+         * @see org.apache.axiom.om.OMDataSource#serialize(java.io.OutputStream, org.apache.axiom.om.OMOutputFormat)
+         */
+        public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+            // TODO Auto-generated method stub
+            
+        }
+
+        /**
+         * @see org.apache.axiom.om.OMDataSource#serialize(java.io.Writer, org.apache.axiom.om.OMOutputFormat)
+         */
+        public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+            // TODO Auto-generated method stub
+            
+        }
+
+        /**
+         * @see org.apache.axiom.om.OMDataSource#serialize(javax.xml.stream.XMLStreamWriter)
+         */
+        public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+            // TODO Auto-generated method stub
+            
+        }
+        
+    }
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org