ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1728847 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/ testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/
Date Sat, 06 Feb 2016 15:18:01 GMT
Author: veithen
Date: Sat Feb  6 15:18:00 2016
New Revision: 1728847

URL: http://svn.apache.org/viewvc?rev=1728847&view=rev
Log:
Simplify document creation in StAXOMBuilder.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java?rev=1728847&r1=1728846&r2=1728847&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
Sat Feb  6 15:18:00 2016
@@ -95,6 +95,14 @@ public final class BuilderHandler {
         }
     }
 
+    public AxiomDocument getDocument() {
+        if (root != null) {
+            throw new UnsupportedOperationException("There is no document linked to this
builder");
+        } else {
+            return document;
+        }
+    }
+    
     private void addChild(AxiomChildNode node) {
         target.addChild(node, true);
         postProcessNode(node);

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java?rev=1728847&r1=1728846&r2=1728847&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/StAXOMBuilder.java
Sat Feb  6 15:18:00 2016
@@ -37,6 +37,7 @@ import org.apache.axiom.om.impl.builder.
 import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
 import org.apache.axiom.om.impl.builder.Detachable;
 import org.apache.axiom.om.impl.intf.AxiomContainer;
+import org.apache.axiom.om.impl.intf.AxiomDocument;
 import org.apache.axiom.om.impl.intf.AxiomElement;
 import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
 import org.apache.axiom.om.impl.intf.TextContent;
@@ -129,12 +130,15 @@ public class StAXOMBuilder extends Abstr
      */
     private Exception parserException;
     
-    private int lookAheadToken = -1;
+    private int lookAheadToken = XMLStreamReader.START_DOCUMENT;
 
     protected StAXOMBuilder(NodeFactory nodeFactory, XMLStreamReader parser,
             boolean autoClose, Detachable detachable, Closeable closeable, Model model, PayloadSelector
payloadSelector,
             AxiomSourcedElement root) {
         super(nodeFactory, model, root);
+        if (parser.getEventType() != XMLStreamReader.START_DOCUMENT) {
+            throw new IllegalStateException("The XMLStreamReader must be positioned on a
START_DOCUMENT event");
+        }
         this.parser = parser;
         this.autoClose = autoClose;
         this.detachable = detachable;
@@ -464,18 +468,12 @@ public class StAXOMBuilder extends Abstr
         return old;
     }
     
-    private void createDocumentIfNecessary() {
-        if (handler.document == null && parser.getEventType() == XMLStreamReader.START_DOCUMENT)
{
-            handler.startDocument(charEncoding, parser.getVersion(), parser.getCharacterEncodingScheme(),
parser.isStandalone());
-        }
-    }
-    
     public final OMDocument getDocument() {
-        createDocumentIfNecessary();
-        if (handler.document == null) {
-            throw new UnsupportedOperationException("There is no document linked to this
builder");
+        AxiomDocument document;
+        while ((document = handler.getDocument()) == null) {
+            next();
         }
-        return handler.document;
+        return document;
     }
 
     public final String getCharsetEncoding() {
@@ -556,7 +554,6 @@ public class StAXOMBuilder extends Abstr
             if (handler.done) {
                 throw new OMException();
             }
-            createDocumentIfNecessary();
             int token = parserNext();
             if (!handler.cache) {
                 return token;
@@ -565,6 +562,9 @@ public class StAXOMBuilder extends Abstr
             // Note: if autoClose is enabled, then the parser may be null at this point
             
             switch (token) {
+                case XMLStreamConstants.START_DOCUMENT:
+                    handler.startDocument(charEncoding, parser.getVersion(), parser.getCharacterEncodingScheme(),
parser.isStandalone());
+                    break;
                 case XMLStreamConstants.START_ELEMENT: {
                     createNextOMElement();
                     break;
@@ -598,7 +598,8 @@ public class StAXOMBuilder extends Abstr
                     throw new OMException();
             }
             
-            if (handler.target == null && !handler.done) {
+            // TODO: this will fail if there is whitespace before the document element
+            if (token != XMLStreamConstants.START_DOCUMENT && handler.target == null
&& !handler.done) {
                 // We get here if the document has been discarded (by getDocumentElement(true)
                 // or because the builder is linked to an OMSourcedElement) and
                 // we just processed the END_ELEMENT event for the root element. In this
case, we consume

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java?rev=1728847&r1=1728846&r2=1728847&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java
(original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/builder/TestNextBeforeGetDocumentElement.java
Sat Feb  6 15:18:00 2016
@@ -40,8 +40,9 @@ public class TestNextBeforeGetDocumentEl
     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());
+        while (builder.next() != XMLStreamReader.CHARACTERS) {
+            // Just loop
+        }
         OMElement element = builder.getDocumentElement();
         assertEquals("root", element.getLocalName());
     }



Mime
View raw message