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 2016/02/26 00:40:47 UTC

svn commit: r1732399 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder: BuilderHandler.java Context.java StAXOMBuilder.java

Author: veithen
Date: Thu Feb 25 23:40:47 2016
New Revision: 1732399

URL: http://svn.apache.org/viewvc?rev=1732399&view=rev
Log:
Avoid using getParent in the builder. This will eventually allow us to detach nodes without building them.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
      - copied, changed from r1731428, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java
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

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=1732399&r1=1732398&r2=1732399&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 Thu Feb 25 23:40:47 2016
@@ -27,26 +27,11 @@ import java.util.Queue;
 import javax.xml.stream.XMLStreamConstants;
 
 import org.apache.axiom.core.Builder;
-import org.apache.axiom.core.CoreCharacterDataNode;
 import org.apache.axiom.core.CoreNode;
 import org.apache.axiom.core.CoreParentNode;
 import org.apache.axiom.core.NodeFactory;
 import org.apache.axiom.core.stream.XmlHandler;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.impl.common.AxiomSemantics;
-import org.apache.axiom.om.impl.common.OMNamespaceImpl;
-import org.apache.axiom.om.impl.intf.AxiomAttribute;
-import org.apache.axiom.om.impl.intf.AxiomCDATASection;
-import org.apache.axiom.om.impl.intf.AxiomCharacterDataNode;
-import org.apache.axiom.om.impl.intf.AxiomChildNode;
-import org.apache.axiom.om.impl.intf.AxiomComment;
-import org.apache.axiom.om.impl.intf.AxiomContainer;
-import org.apache.axiom.om.impl.intf.AxiomDocType;
 import org.apache.axiom.om.impl.intf.AxiomDocument;
-import org.apache.axiom.om.impl.intf.AxiomElement;
-import org.apache.axiom.om.impl.intf.AxiomEntityReference;
-import org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration;
-import org.apache.axiom.om.impl.intf.AxiomProcessingInstruction;
 import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -54,14 +39,12 @@ import org.apache.commons.logging.LogFac
 public final class BuilderHandler implements XmlHandler {
     private static final Log log = LogFactory.getLog(BuilderHandler.class);
     
-    private static final OMNamespace DEFAULT_NS = new OMNamespaceImpl("", "");
-    
-    private final NodeFactory nodeFactory;
-    private final Model model;
-    private final AxiomSourcedElement root;
-    private final Builder builder;
-    private final OMNamespaceCache nsCache = new OMNamespaceCache();
-    public AxiomContainer target;
+    final NodeFactory nodeFactory;
+    final Model model;
+    final AxiomSourcedElement root;
+    final Builder builder;
+    final OMNamespaceCache nsCache = new OMNamespaceCache();
+    public Context context;
     // returns the state of completion
     public boolean done;
     // keeps the state of the cache
@@ -75,8 +58,6 @@ public final class BuilderHandler implem
      */
     public int depth;
     
-    private Object pendingCharacterData;
-    
     /**
      * Stores the stack trace of the code that caused a node to be discarded or consumed. This is
      * only used if debug logging was enabled when builder was created.
@@ -91,6 +72,7 @@ public final class BuilderHandler implem
         this.model = model;
         this.root = root;
         this.builder = builder;
+        context = new Context(this, null, 0);
     }
 
     public void addListener(BuilderListener listener) {
@@ -100,7 +82,7 @@ public final class BuilderHandler implem
         listeners.add(listener);
     }
     
-    private void nodeAdded(CoreNode node) {
+    void nodeAdded(CoreNode node) {
         if (listeners != null) {
             for (int i=0, size=listeners.size(); i<size; i++) {
                 Runnable action = listeners.get(i).nodeAdded(node, depth);
@@ -135,19 +117,6 @@ public final class BuilderHandler implem
         }
     }
     
-    private void addChild(AxiomChildNode node) {
-        if (pendingCharacterData != null) {
-            AxiomCharacterDataNode cdataNode = nodeFactory.createNode(AxiomCharacterDataNode.class);
-            cdataNode.coreSetCharacterData(pendingCharacterData);
-            target.coreAppendChild(cdataNode, true);
-            pendingCharacterData = null;
-        }
-        target.coreAppendChild(node, true);
-        if (!(node instanceof CoreCharacterDataNode)) {
-            nodeAdded(node);
-        }
-    }
-    
     public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, boolean standalone) {
         if (root == null) {
             document = nodeFactory.createNode(model.getDocumentType());
@@ -157,131 +126,68 @@ public final class BuilderHandler implem
             document.coreSetStandalone(standalone);
             document.coreSetBuilder(builder);
             nodeAdded(document);
-            target = document;
+            context.target = document;
         }
     }
     
     public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId,
             String internalSubset) {
         model.validateEventType(XMLStreamConstants.DTD);
-        AxiomDocType node = nodeFactory.createNode(AxiomDocType.class);
-        node.coreSetRootName(rootName);
-        node.coreSetPublicId(publicId);
-        node.coreSetSystemId(systemId);
-        node.coreSetInternalSubset(internalSubset);
-        addChild(node);
+        context.processDocumentTypeDeclaration(rootName, publicId, systemId, internalSubset);
     }
     
     public void startElement(String namespaceURI, String localName, String prefix) {
         depth++;
-        AxiomElement element;
-        OMNamespace ns = nsCache.getOMNamespace(namespaceURI, prefix);
-        if (depth == 1 && root != null) {
-            root.validateName(prefix, localName, namespaceURI);
-            root.initName(localName, ns, false);
-            element = root;
-        } else {
-            element = nodeFactory.createNode(model.determineElementType(
-                    target, depth, namespaceURI, localName));
-            element.coreSetBuilder(builder);
-            element.coreSetState(CoreParentNode.ATTRIBUTES_PENDING);
-            element.initName(localName, ns, false);
-            addChild(element);
-        }
-        target = element;
+        context = context.startElement(namespaceURI, localName, prefix);
     }
     
     public void endElement() {
-        target.setComplete(true);
-        if (pendingCharacterData != null) {
-            target.coreSetCharacterData(pendingCharacterData, null);
-            pendingCharacterData = null;
-        }
+        context = context.endElement();
         depth--;
-        if (depth == 0) {
-            // This is relevant for OMSourcedElements and for the case where the document has been discarded
-            // using getDocumentElement(true). In these cases, this will actually set target to null. In all
-            // other cases, this will have the same effect as the instruction in the else clause.
-            target = document;
-        } else {
-            target = (AxiomContainer)((AxiomElement)target).getParent();
-        }
     }
 
     public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) {
-        OMNamespace ns = nsCache.getOMNamespace(namespaceURI, prefix);
-        AxiomAttribute attr = nodeFactory.createNode(AxiomAttribute.class);
-        attr.internalSetLocalName(localName);
-        attr.coreSetCharacterData(value, AxiomSemantics.INSTANCE);
-        attr.internalSetNamespace(ns);
-        attr.coreSetType(type);
-        attr.coreSetSpecified(specified);
-        ((AxiomElement)target).coreAppendAttribute(attr);
+        context.processAttribute(namespaceURI, localName, prefix, value, type, specified);
     }
     
     public void processNamespaceDeclaration(String prefix, String namespaceURI) {
-        OMNamespace ns = nsCache.getOMNamespace(namespaceURI, prefix);
-        if (ns == null) {
-            ns = DEFAULT_NS;
-        }
-        AxiomNamespaceDeclaration decl = nodeFactory.createNode(AxiomNamespaceDeclaration.class);
-        decl.setDeclaredNamespace(ns);
-        ((AxiomElement)target).coreAppendAttribute(decl);
+        context.processNamespaceDeclaration(prefix, namespaceURI);
     }
     
     public void attributesCompleted() {
-        target.coreSetState(CoreParentNode.INCOMPLETE);
+        context.attributesCompleted();
     }
     
     public void processCharacterData(Object data, boolean ignorable) {
-        if (!ignorable && pendingCharacterData == null && target.coreGetFirstChildIfAvailable() == null) {
-            pendingCharacterData = data;
-        } else {
-            AxiomCharacterDataNode node = nodeFactory.createNode(AxiomCharacterDataNode.class);
-            node.coreSetCharacterData(data);
-            node.coreSetIgnorable(ignorable);
-            addChild(node);
-        }
+        context.processCharacterData(data, ignorable);
     }
     
     public void processProcessingInstruction(String piTarget, String piData) {
         model.validateEventType(XMLStreamConstants.PROCESSING_INSTRUCTION);
-        AxiomProcessingInstruction node = nodeFactory.createNode(AxiomProcessingInstruction.class);
-        node.coreSetTarget(piTarget);
-        node.coreSetCharacterData(piData, AxiomSemantics.INSTANCE);
-        addChild(node);
+        context.processProcessingInstruction(piTarget, piData);
     }
 
     public void processComment(String content) {
         model.validateEventType(XMLStreamConstants.COMMENT);
-        AxiomComment node = nodeFactory.createNode(AxiomComment.class);
-        node.coreSetCharacterData(content, AxiomSemantics.INSTANCE);
-        addChild(node);
+        context.processComment(content);
     }
     
     public void processCDATASection(String content) {
         model.validateEventType(XMLStreamConstants.CDATA);
-        AxiomCDATASection node = nodeFactory.createNode(AxiomCDATASection.class);
-        node.coreSetCharacterData(content, AxiomSemantics.INSTANCE);
-        addChild(node);
+        context.processCDATASection(content);
     }
     
     public void processEntityReference(String name, String replacementText) {
         model.validateEventType(XMLStreamConstants.ENTITY_REFERENCE);
-        AxiomEntityReference node = nodeFactory.createNode(AxiomEntityReference.class);
-        node.coreSetName(name);
-        node.coreSetReplacementText(replacementText);
-        addChild(node);
+        context.processEntityReference(name, replacementText);
     }
     
     public void endDocument() {
         if (depth != 0) {
             throw new IllegalStateException();
         }
-        if (document != null) {
-            document.setComplete(true);
-        }
-        target = null;
+        context.endDocument();
+        context = null;
         done = true;
     }
 }

Copied: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java (from r1731428, 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/Context.java?p2=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java&p1=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuilderHandler.java&r1=1731428&r2=1732399&rev=1732399&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/Context.java Thu Feb 25 23:40:47 2016
@@ -18,20 +18,8 @@
  */
 package org.apache.axiom.om.impl.common.builder;
 
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Queue;
-
-import javax.xml.stream.XMLStreamConstants;
-
-import org.apache.axiom.core.Builder;
 import org.apache.axiom.core.CoreCharacterDataNode;
-import org.apache.axiom.core.CoreNode;
 import org.apache.axiom.core.CoreParentNode;
-import org.apache.axiom.core.NodeFactory;
-import org.apache.axiom.core.stream.XmlHandler;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.common.AxiomSemantics;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
@@ -42,129 +30,53 @@ import org.apache.axiom.om.impl.intf.Axi
 import org.apache.axiom.om.impl.intf.AxiomComment;
 import org.apache.axiom.om.impl.intf.AxiomContainer;
 import org.apache.axiom.om.impl.intf.AxiomDocType;
-import org.apache.axiom.om.impl.intf.AxiomDocument;
 import org.apache.axiom.om.impl.intf.AxiomElement;
 import org.apache.axiom.om.impl.intf.AxiomEntityReference;
 import org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration;
 import org.apache.axiom.om.impl.intf.AxiomProcessingInstruction;
-import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
-public final class BuilderHandler implements XmlHandler {
-    private static final Log log = LogFactory.getLog(BuilderHandler.class);
-    
+public final class Context {
     private static final OMNamespace DEFAULT_NS = new OMNamespaceImpl("", "");
     
-    private final NodeFactory nodeFactory;
-    private final Model model;
-    private final AxiomSourcedElement root;
-    private final Builder builder;
-    private final OMNamespaceCache nsCache = new OMNamespaceCache();
+    private final BuilderHandler builderHandler;
+    final Context parentContext;
+    private final int depth;
+    private Context nestedContext;
+
     public AxiomContainer target;
-    // returns the state of completion
-    public boolean done;
-    // keeps the state of the cache
-    public boolean cache = true;
-    public AxiomDocument document;
-    
-    /**
-     * Tracks the depth of the node identified by {@link #target}. By definition, the document has
-     * depth 0. Note that if caching is disabled, then this depth may be different from the actual
-     * depth reached by the underlying parser.
-     */
-    public int depth;
     
     private Object pendingCharacterData;
     
-    /**
-     * Stores the stack trace of the code that caused a node to be discarded or consumed. This is
-     * only used if debug logging was enabled when builder was created.
-     */
-    public Map<CoreParentNode,Throwable> discardTracker = log.isDebugEnabled() ? new LinkedHashMap<CoreParentNode,Throwable>() : null;
-    
-    private ArrayList<BuilderListener> listeners;
-    private Queue<Runnable> deferredListenerActions;
-
-    public BuilderHandler(NodeFactory nodeFactory, Model model, AxiomSourcedElement root, Builder builder) {
-        this.nodeFactory = nodeFactory;
-        this.model = model;
-        this.root = root;
-        this.builder = builder;
-    }
-
-    public void addListener(BuilderListener listener) {
-        if (listeners == null) {
-            listeners = new ArrayList<BuilderListener>();
-        }
-        listeners.add(listener);
-    }
-    
-    private void nodeAdded(CoreNode node) {
-        if (listeners != null) {
-            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);
-                }
-            }
-        }
+    public Context(BuilderHandler builderHandler, Context parentContext, int depth) {
+        this.builderHandler = builderHandler;
+        this.parentContext = parentContext;
+        this.depth = depth;
     }
 
-    void executeDeferredListenerActions() {
-        if (deferredListenerActions != null) {
-            Runnable action;
-            while ((action = deferredListenerActions.poll()) != null) {
-                action.run();
-            }
-        }
-    }
-    
-    public boolean isCompleted() {
-        return done;
-    }
-    
-    public AxiomDocument getDocument() {
-        if (root != null) {
-            throw new UnsupportedOperationException("There is no document linked to this builder");
-        } else {
-            return document;
+    private Context newContext(AxiomContainer target) {
+        if (nestedContext == null) {
+            nestedContext = new Context(builderHandler, this, depth+1);
         }
+        nestedContext.target = target;
+        return nestedContext;
     }
     
     private void addChild(AxiomChildNode node) {
         if (pendingCharacterData != null) {
-            AxiomCharacterDataNode cdataNode = nodeFactory.createNode(AxiomCharacterDataNode.class);
+            AxiomCharacterDataNode cdataNode = builderHandler.nodeFactory.createNode(AxiomCharacterDataNode.class);
             cdataNode.coreSetCharacterData(pendingCharacterData);
             target.coreAppendChild(cdataNode, true);
             pendingCharacterData = null;
         }
         target.coreAppendChild(node, true);
         if (!(node instanceof CoreCharacterDataNode)) {
-            nodeAdded(node);
-        }
-    }
-    
-    public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, boolean standalone) {
-        if (root == null) {
-            document = nodeFactory.createNode(model.getDocumentType());
-            document.coreSetInputEncoding(inputEncoding);
-            document.coreSetXmlVersion(xmlVersion);
-            document.coreSetXmlEncoding(xmlEncoding);
-            document.coreSetStandalone(standalone);
-            document.coreSetBuilder(builder);
-            nodeAdded(document);
-            target = document;
+            builderHandler.nodeAdded(node);
         }
     }
     
     public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId,
             String internalSubset) {
-        model.validateEventType(XMLStreamConstants.DTD);
-        AxiomDocType node = nodeFactory.createNode(AxiomDocType.class);
+        AxiomDocType node = builderHandler.nodeFactory.createNode(AxiomDocType.class);
         node.coreSetRootName(rootName);
         node.coreSetPublicId(publicId);
         node.coreSetSystemId(systemId);
@@ -172,45 +84,37 @@ public final class BuilderHandler implem
         addChild(node);
     }
     
-    public void startElement(String namespaceURI, String localName, String prefix) {
-        depth++;
+    public Context startElement(String namespaceURI, String localName, String prefix) {
         AxiomElement element;
-        OMNamespace ns = nsCache.getOMNamespace(namespaceURI, prefix);
-        if (depth == 1 && root != null) {
-            root.validateName(prefix, localName, namespaceURI);
-            root.initName(localName, ns, false);
-            element = root;
+        OMNamespace ns = builderHandler.nsCache.getOMNamespace(namespaceURI, prefix);
+        if (depth == 0 && builderHandler.root != null) {
+            builderHandler.root.validateName(prefix, localName, namespaceURI);
+            builderHandler.root.initName(localName, ns, false);
+            element = builderHandler.root;
         } else {
-            element = nodeFactory.createNode(model.determineElementType(
-                    target, depth, namespaceURI, localName));
-            element.coreSetBuilder(builder);
+            element = builderHandler.nodeFactory.createNode(builderHandler.model.determineElementType(
+                    target, depth+1, namespaceURI, localName));
+            element.coreSetBuilder(builderHandler.builder);
             element.coreSetState(CoreParentNode.ATTRIBUTES_PENDING);
             element.initName(localName, ns, false);
             addChild(element);
         }
-        target = element;
+        return newContext(element);
     }
     
-    public void endElement() {
+    public Context endElement() {
         target.setComplete(true);
         if (pendingCharacterData != null) {
             target.coreSetCharacterData(pendingCharacterData, null);
             pendingCharacterData = null;
         }
-        depth--;
-        if (depth == 0) {
-            // This is relevant for OMSourcedElements and for the case where the document has been discarded
-            // using getDocumentElement(true). In these cases, this will actually set target to null. In all
-            // other cases, this will have the same effect as the instruction in the else clause.
-            target = document;
-        } else {
-            target = (AxiomContainer)((AxiomElement)target).getParent();
-        }
+        target = null;
+        return parentContext;
     }
 
     public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) {
-        OMNamespace ns = nsCache.getOMNamespace(namespaceURI, prefix);
-        AxiomAttribute attr = nodeFactory.createNode(AxiomAttribute.class);
+        OMNamespace ns = builderHandler.nsCache.getOMNamespace(namespaceURI, prefix);
+        AxiomAttribute attr = builderHandler.nodeFactory.createNode(AxiomAttribute.class);
         attr.internalSetLocalName(localName);
         attr.coreSetCharacterData(value, AxiomSemantics.INSTANCE);
         attr.internalSetNamespace(ns);
@@ -220,11 +124,11 @@ public final class BuilderHandler implem
     }
     
     public void processNamespaceDeclaration(String prefix, String namespaceURI) {
-        OMNamespace ns = nsCache.getOMNamespace(namespaceURI, prefix);
+        OMNamespace ns = builderHandler.nsCache.getOMNamespace(namespaceURI, prefix);
         if (ns == null) {
             ns = DEFAULT_NS;
         }
-        AxiomNamespaceDeclaration decl = nodeFactory.createNode(AxiomNamespaceDeclaration.class);
+        AxiomNamespaceDeclaration decl = builderHandler.nodeFactory.createNode(AxiomNamespaceDeclaration.class);
         decl.setDeclaredNamespace(ns);
         ((AxiomElement)target).coreAppendAttribute(decl);
     }
@@ -237,7 +141,7 @@ public final class BuilderHandler implem
         if (!ignorable && pendingCharacterData == null && target.coreGetFirstChildIfAvailable() == null) {
             pendingCharacterData = data;
         } else {
-            AxiomCharacterDataNode node = nodeFactory.createNode(AxiomCharacterDataNode.class);
+            AxiomCharacterDataNode node = builderHandler.nodeFactory.createNode(AxiomCharacterDataNode.class);
             node.coreSetCharacterData(data);
             node.coreSetIgnorable(ignorable);
             addChild(node);
@@ -245,30 +149,26 @@ public final class BuilderHandler implem
     }
     
     public void processProcessingInstruction(String piTarget, String piData) {
-        model.validateEventType(XMLStreamConstants.PROCESSING_INSTRUCTION);
-        AxiomProcessingInstruction node = nodeFactory.createNode(AxiomProcessingInstruction.class);
+        AxiomProcessingInstruction node = builderHandler.nodeFactory.createNode(AxiomProcessingInstruction.class);
         node.coreSetTarget(piTarget);
         node.coreSetCharacterData(piData, AxiomSemantics.INSTANCE);
         addChild(node);
     }
 
     public void processComment(String content) {
-        model.validateEventType(XMLStreamConstants.COMMENT);
-        AxiomComment node = nodeFactory.createNode(AxiomComment.class);
+        AxiomComment node = builderHandler.nodeFactory.createNode(AxiomComment.class);
         node.coreSetCharacterData(content, AxiomSemantics.INSTANCE);
         addChild(node);
     }
     
     public void processCDATASection(String content) {
-        model.validateEventType(XMLStreamConstants.CDATA);
-        AxiomCDATASection node = nodeFactory.createNode(AxiomCDATASection.class);
+        AxiomCDATASection node = builderHandler.nodeFactory.createNode(AxiomCDATASection.class);
         node.coreSetCharacterData(content, AxiomSemantics.INSTANCE);
         addChild(node);
     }
     
     public void processEntityReference(String name, String replacementText) {
-        model.validateEventType(XMLStreamConstants.ENTITY_REFERENCE);
-        AxiomEntityReference node = nodeFactory.createNode(AxiomEntityReference.class);
+        AxiomEntityReference node = builderHandler.nodeFactory.createNode(AxiomEntityReference.class);
         node.coreSetName(name);
         node.coreSetReplacementText(replacementText);
         addChild(node);
@@ -278,10 +178,9 @@ public final class BuilderHandler implem
         if (depth != 0) {
             throw new IllegalStateException();
         }
-        if (document != null) {
-            document.setComplete(true);
+        if (target != null) {
+            target.setComplete(true);
         }
         target = null;
-        done = true;
     }
 }

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=1732399&r1=1732398&r2=1732399&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 Thu Feb 25 23:40:47 2016
@@ -104,20 +104,20 @@ public class StAXOMBuilder extends Abstr
     
     public final void discard(CoreParentNode container) {
         int targetElementLevel = builderHandler.depth;
-        AxiomContainer current = builderHandler.target;
-        while (current != container) {
+        Context current = builderHandler.context;
+        while (current.target != container) {
             targetElementLevel--;
-            current = (AxiomContainer)((OMElement)current).getParent();
+            current = current.parentContext;
         }
         if (targetElementLevel == 0 || targetElementLevel == 1 && builderHandler.document == null) {
             close();
-            current = builderHandler.target;
+            current = builderHandler.context;
             while (true) {
-                discarded(current);
-                if (current == container) {
+                discarded(current.target);
+                if (current.target == container) {
                     break;
                 }
-                current = (AxiomContainer)((OMElement)current).getParent();
+                current = current.parentContext;
             }
             return;
         }
@@ -131,9 +131,9 @@ public class StAXOMBuilder extends Abstr
                     if (skipDepth > 0) {
                         skipDepth--;
                     } else {
-                        discarded(builderHandler.target);
-                        boolean found = container == builderHandler.target;
-                        builderHandler.target = (AxiomContainer)((OMElement)builderHandler.target).getParent();
+                        discarded(builderHandler.context.target);
+                        boolean found = container == builderHandler.context.target;
+                        builderHandler.context = builderHandler.context.parentContext;
                         builderHandler.depth--;
                         if (found) {
                             break loop;
@@ -144,11 +144,11 @@ public class StAXOMBuilder extends Abstr
                     if (skipDepth != 0 || builderHandler.depth != 0) {
                         throw new OMException("Unexpected END_DOCUMENT");
                     }
-                    if (builderHandler.target != builderHandler.document) {
+                    if (builderHandler.context.target != builderHandler.document) {
                         throw new OMException("Called discard for an element that is not being built by this builder");
                     }
-                    discarded(builderHandler.target);
-                    builderHandler.target = null;
+                    discarded(builderHandler.context.target);
+                    builderHandler.context = null;
                     builderHandler.done = true;
                     break loop;
             }
@@ -214,16 +214,16 @@ public class StAXOMBuilder extends Abstr
         if (!builderHandler.cache) {
             parserAccessed = true;
             // Mark all containers in the hierarchy as discarded because they can no longer be built
-            AxiomContainer current = builderHandler.target;
+            Context current = builderHandler.context;
             while (builderHandler.depth > 0) {
-                discarded(current);
-                current = (AxiomContainer)((OMElement)current).getParent();
+                discarded(current.target);
+                current = current.parentContext;
                 builderHandler.depth--;
             }
-            if (current != null && current == builderHandler.document) {
-                discarded(current);
+            if (current != null && current.target == builderHandler.document) {
+                discarded(current.target);
             }
-            builderHandler.target = null;
+            builderHandler.context = null;
             return helper.parser;
         } else {
             throw new IllegalStateException(
@@ -245,34 +245,34 @@ public class StAXOMBuilder extends Abstr
     // This method expects that the parser is currently positioned on the
     // end event corresponding to the container passed as parameter
     public final void reenableCaching(CoreParentNode container) {
-        AxiomContainer current = builderHandler.target;
+        Context current = builderHandler.context;
         while (true) {
-            discarded(current);
+            discarded(current.target);
             if (builderHandler.depth == 0) {
-                if (current != container || current != builderHandler.document) {
+                if (current.target != container || current.target != builderHandler.document) {
                     throw new IllegalStateException();
                 }
                 break;
             }
             builderHandler.depth--;
-            if (current == container) {
+            if (current.target == container) {
                 break;
             }
-            current = (AxiomContainer)((OMElement)current).getParent();
+            current = current.parentContext;
         }
         // Note that at this point current == container
         if (container == builderHandler.document) {
-            builderHandler.target = null;
+            builderHandler.context = null;
             builderHandler.done = true;
         } else if (builderHandler.depth == 0 && builderHandler.document == null) {
             // Consume the remaining event; for the rationale, see StAXOMBuilder#next()
             while (helper.parserNext() != XMLStreamConstants.END_DOCUMENT) {
                 // Just loop
             }
-            builderHandler.target = null;
+            builderHandler.context = null;
             builderHandler.done = true;
         } else {
-            builderHandler.target = (AxiomContainer)((OMElement)container).getParent();
+            builderHandler.context = builderHandler.context.parentContext;
         }
         if (log.isDebugEnabled()) {
             log.debug("Caching re-enabled; new element level: " + builderHandler.depth + "; done=" + builderHandler.done);
@@ -349,7 +349,7 @@ public class StAXOMBuilder extends Abstr
         builderHandler.executeDeferredListenerActions();
         
         // TODO: this will fail if there is whitespace before the document element
-        if (event != XMLStreamConstants.START_DOCUMENT && builderHandler.target == null && !builderHandler.done) {
+        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
@@ -398,6 +398,6 @@ public class StAXOMBuilder extends Abstr
     }
 
     public final AxiomContainer getTarget() {
-        return builderHandler.target;
+        return builderHandler.context.target;
     }
 }