ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1734618 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl: common/builder/ intf/ mixin/
Date Fri, 11 Mar 2016 19:30:10 GMT
Author: veithen
Date: Fri Mar 11 19:30:10 2016
New Revision: 1734618

URL: http://svn.apache.org/viewvc?rev=1734618&view=rev
Log:
Get rid of some of the remaining hacks 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/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/AxiomElement.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj

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=1734618&r1=1734617&r2=1734618&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
Fri Mar 11 19:30:10 2016
@@ -52,7 +52,7 @@ final class BuilderHandler implements Xm
     public int depth;
     
     private ArrayList<BuilderListener> listeners;
-    private Queue<Runnable> deferredListenerActions;
+    private Queue<Runnable> deferredActions;
 
     BuilderHandler(NodeFactory nodeFactory, Model model, AxiomSourcedElement root, Builder
builder) {
         this.nodeFactory = nodeFactory;
@@ -78,19 +78,23 @@ final class BuilderHandler implements Xm
             for (int i=0, size=listeners.size(); i<size; i++) {
                 Runnable action = listeners.get(i).nodeAdded(node, depth);
                 if (action != null) {
-                    if (deferredListenerActions == null) {
-                        deferredListenerActions = new LinkedList<Runnable>();
-                    }
-                    deferredListenerActions.add(action);
+                    scheduleDeferredAction(action);
                 }
             }
         }
     }
 
-    void executeDeferredListenerActions() {
-        if (deferredListenerActions != null) {
+    private void scheduleDeferredAction(Runnable action) {
+        if (deferredActions == null) {
+            deferredActions = new LinkedList<Runnable>();
+        }
+        deferredActions.add(action);
+    }
+
+    void executeDeferredActions() {
+        if (deferredActions != null) {
             Runnable action;
-            while ((action = deferredListenerActions.poll()) != null) {
+            while ((action = deferredActions.poll()) != null) {
                 action.run();
             }
         }
@@ -102,7 +106,14 @@ final class BuilderHandler implements Xm
     
     void decrementActiveContextCount() {
         if (--activeContextCount == 0) {
-            builder.close();
+            scheduleDeferredAction(new Runnable() {
+                @Override
+                public void run() {
+                    while (!done) {
+                        builder.next();
+                    }
+                }
+            });
         }
     }
     

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=1734618&r1=1734617&r2=1734618&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
Fri Mar 11 19:30:10 2016
@@ -20,16 +20,16 @@
 package org.apache.axiom.om.impl.common.builder;
 
 import org.apache.axiom.core.NodeFactory;
+import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.ds.custombuilder.CustomBuilder;
 import org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport;
 import org.apache.axiom.om.ds.custombuilder.CustomBuilder.Selector;
 import org.apache.axiom.om.impl.builder.Detachable;
-import org.apache.axiom.om.impl.intf.AxiomElement;
+import org.apache.axiom.om.impl.intf.AxiomDocument;
 import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
 
-import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
 
 import java.io.Closeable;
@@ -119,28 +119,8 @@ public class StAXOMBuilder extends Abstr
         if (builderHandler.done) {
             throw new OMException();
         }
-        int event = helper.next();
-        builderHandler.executeDeferredListenerActions();
-        
-        // TODO: this will fail if there is whitespace before the document element
-        if (event != XMLStreamConstants.START_DOCUMENT && builderHandler.depth ==
0 && builderHandler.document == null && !builderHandler.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
-            // the remaining events until we reach the end of the document. This serves several
purposes:
-            //  * It allows us to detect documents that have an epilog that is not well formed.
-            //  * Many parsers will perform some cleanup when the end of the document is
reached.
-            //    For example, Woodstox will recycle the symbol table if the parser gets
past the
-            //    last END_ELEMENT. This improves performance because Woodstox by default
interns
-            //    all symbols; if the symbol table can be recycled, then this reduces the
number of
-            //    calls to String#intern().
-            //  * If autoClose is set, the parser will be closed so that even more resources
-            //    can be released.
-            while (helper.parserNext() != XMLStreamConstants.END_DOCUMENT) {
-                // Just loop
-            }
-            builderHandler.done = true;
-        }
+        helper.next();
+        builderHandler.executeDeferredActions();
     }
     
     public final OMElement getDocumentElement() {
@@ -148,9 +128,11 @@ public class StAXOMBuilder extends Abstr
     }
 
     public final OMElement getDocumentElement(boolean discardDocument) {
-        OMElement element = getDocument().getOMDocumentElement();
+        OMDocument document = getDocument();
+        OMElement element = document.getOMDocumentElement();
         if (discardDocument) {
-            ((AxiomElement)element).detachAndDiscardParent();
+            element.detach();
+            ((AxiomDocument)document).coreDiscard(false);
             builderHandler.document = null;
         }
         return element;

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java?rev=1734618&r1=1734617&r2=1734618&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
Fri Mar 11 19:30:10 2016
@@ -43,12 +43,15 @@ final class UnwrappingContext extends Co
     }
 
     @Override
-    BuildableContext startElement(String namespaceURI, String localName, String prefix)
+    Context startElement(String namespaceURI, String localName, String prefix)
             throws StreamException {
         root.validateName(prefix, localName, namespaceURI);
         root.initName(localName, builderHandler.nsCache.getOMNamespace(namespaceURI, prefix),
false);
         root.coreSetState(CoreParentNode.ATTRIBUTES_PENDING);
-        return newContext(root);
+        Context nestedContext = newContext(root);
+        // We will basically ignore events in the epilog, so mark this context as inactive
+        builderHandler.decrementActiveContextCount();
+        return nestedContext;
     }
 
     @Override

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/AxiomElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/AxiomElement.java?rev=1734618&r1=1734617&r2=1734618&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/AxiomElement.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/intf/AxiomElement.java
Fri Mar 11 19:30:10 2016
@@ -39,7 +39,5 @@ public interface AxiomElement extends OM
      */
     OMNamespace addNamespaceDeclaration(String uri, String prefix);
     
-    void detachAndDiscardParent();
-    
     void addNamespaceDeclaration(OMNamespace ns);
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj?rev=1734618&r1=1734617&r2=1734618&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/mixin/AxiomElementSupport.aj
Fri Mar 11 19:30:10 2016
@@ -248,12 +248,6 @@ public aspect AxiomElementSupport {
         detach();
     }
     
-    public void AxiomElement.detachAndDiscardParent() {
-        internalUnsetParent(null);
-        coreSetPreviousSibling(null);
-        coreSetNextSibling(null);
-    }
-    
     public <T extends OMElement> void AxiomElement.insertChild(Sequence sequence, int
pos, T newChild, boolean allowReplace) {
         if (!sequence.item(pos).isInstance(newChild)) {
             throw new IllegalArgumentException();



Mime
View raw message