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 2012/07/13 20:33:30 UTC

svn commit: r1361322 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/

Author: veithen
Date: Fri Jul 13 18:33:30 2012
New Revision: 1361322

URL: http://svn.apache.org/viewvc?rev=1361322&view=rev
Log:
Fixed a regression in Axis2 caused by the recent StAX(OM)Builder changes.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1361322&r1=1361321&r2=1361322&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Fri Jul 13 18:33:30 2012
@@ -604,20 +604,23 @@ public abstract class StAXBuilder implem
 
     protected abstract OMDocument createDocument();
     
+    protected void createDocumentIfNecessary() {
+        if (document == null && parser.getEventType() == XMLStreamReader.START_DOCUMENT) {
+            document = createDocument();
+            if (charEncoding != null) {
+                document.setCharsetEncoding(charEncoding);
+            }
+            document.setXMLVersion(parser.getVersion());
+            document.setXMLEncoding(parser.getCharacterEncodingScheme());
+            document.setStandalone(parser.isStandalone() ? "yes" : "no");
+            target = (OMContainerEx)document;
+        }
+    }
+    
     public OMDocument getDocument() {
+        createDocumentIfNecessary();
         if (document == null) {
-            if (parser.getEventType() == XMLStreamReader.START_DOCUMENT) {
-                document = createDocument();
-                if (charEncoding != null) {
-                    document.setCharsetEncoding(charEncoding);
-                }
-                document.setXMLVersion(parser.getVersion());
-                document.setXMLEncoding(parser.getCharacterEncodingScheme());
-                document.setStandalone(parser.isStandalone() ? "yes" : "no");
-                target = (OMContainerEx)document;
-            } else {
-                throw new UnsupportedOperationException("There is no document linked to this builder");
-            }
+            throw new UnsupportedOperationException("There is no document linked to this builder");
         }
         return document;
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1361322&r1=1361321&r2=1361322&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Fri Jul 13 18:33:30 2012
@@ -183,6 +183,7 @@ public class StAXOMBuilder extends StAXB
                 if (done) {
                     throw new OMException();
                 }
+                createDocumentIfNecessary();
                 int token = parserNext();
                 if (!cache) {
                     return token;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1361322&r1=1361321&r2=1361322&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Fri Jul 13 18:33:30 2012
@@ -87,6 +87,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.builder.TestGetDocumentElementWithIllFormedDocument(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestInvalidXML(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestIOExceptionInGetText(metaFactory));
+        addTest(new org.apache.axiom.ts.om.builder.TestNextBeforeGetDocumentElement(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestReadAttachmentBeforeRootPartComplete(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestRootPartStreaming(metaFactory));
         addTest(new org.apache.axiom.ts.om.builder.TestStandaloneConfiguration(metaFactory));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java?rev=1361322&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java Fri Jul 13 18:33:30 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.builder;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that the builder works correctly if {@link OMXMLParserWrapper#next()} is called before
+ * {@link OMXMLParserWrapper#getDocumentElement()}.
+ */
+public class TestNextBeforeGetDocumentElement extends AxiomTestCase {
+    public TestNextBeforeGetDocumentElement(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(),
+                new StringReader("<root>text</root>"));
+        assertEquals(XMLStreamReader.START_ELEMENT, builder.next());
+        assertEquals(XMLStreamReader.CHARACTERS, builder.next());
+        OMElement element = builder.getDocumentElement();
+        assertEquals("root", element.getLocalName());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java
------------------------------------------------------------------------------
    svn:eol-style = native