ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1734505 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder: BuildableContext.java BuilderHandler.java Context.java StAXOMBuilder.java UnwrappingContext.java
Date Fri, 11 Mar 2016 08:25:06 GMT
Author: veithen
Date: Fri Mar 11 08:25:05 2016
New Revision: 1734505

URL: http://svn.apache.org/viewvc?rev=1734505&view=rev
Log:
Handle builders for OMSourcedElements in a smarter way.

Added:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
      - copied, changed from r1734484, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
  (with props)
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
  (with props)
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

Copied: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
(from r1734484, webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java)
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java?p2=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java&p1=webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java&r1=1734484&r2=1734505&rev=1734505&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/BuildableContext.java
Fri Mar 11 08:25:05 2016
@@ -22,6 +22,7 @@ import org.apache.axiom.core.Builder;
 import org.apache.axiom.core.CoreCDATASection;
 import org.apache.axiom.core.CoreCharacterDataNode;
 import org.apache.axiom.core.CoreChildNode;
+import org.apache.axiom.core.CoreDocument;
 import org.apache.axiom.core.CoreParentNode;
 import org.apache.axiom.core.InputContext;
 import org.apache.axiom.core.stream.NullXmlHandler;
@@ -40,13 +41,10 @@ import org.apache.axiom.om.impl.intf.Axi
 import org.apache.axiom.om.impl.intf.AxiomNamespaceDeclaration;
 import org.apache.axiom.om.impl.intf.AxiomProcessingInstruction;
 
-final class Context implements InputContext {
+final class BuildableContext extends Context implements InputContext {
     private static final OMNamespace DEFAULT_NS = new OMNamespaceImpl("", "");
     
-    private final BuilderHandler builderHandler;
     final Context parentContext;
-    private final int depth;
-    private Context nestedContext;
 
     public CoreParentNode target;
     
@@ -63,10 +61,9 @@ final class Context implements InputCont
      */
     private int passThroughDepth;
 
-    Context(BuilderHandler builderHandler, Context parentContext, int depth) {
-        this.builderHandler = builderHandler;
+    BuildableContext(BuilderHandler builderHandler, Context parentContext, int depth) {
+        super(builderHandler, depth);
         this.parentContext = parentContext;
-        this.depth = depth;
     }
 
     @Override
@@ -92,16 +89,6 @@ final class Context implements InputCont
         builderHandler.decrementActiveContextCount();
     }
 
-    private Context newContext(CoreParentNode target) {
-        if (nestedContext == null) {
-            nestedContext = new Context(builderHandler, this, depth+1);
-        }
-        nestedContext.target = target;
-        target.coreSetInputContext(nestedContext);
-        builderHandler.incrementActiveContextCount();
-        return nestedContext;
-    }
-    
     private Context endContext() {
         target.coreSetState(CoreParentNode.COMPLETE);
         target.coreSetInputContext(null);
@@ -147,6 +134,19 @@ final class Context implements InputCont
         }
     }
     
+    @Override
+    void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
+            boolean standalone) {
+        CoreDocument document = builderHandler.nodeFactory.createNode(builderHandler.model.getDocumentType());
+        document.coreSetInputEncoding(inputEncoding);
+        document.coreSetXmlVersion(xmlVersion);
+        document.coreSetXmlEncoding(xmlEncoding);
+        document.coreSetStandalone(standalone);
+        document.coreSetInputContext(this);
+        builderHandler.nodeAdded(document);
+        target = document;
+    }
+
     void processDocumentTypeDeclaration(String rootName, String publicId, String systemId,
             String internalSubset) throws StreamException {
         if (passThroughHandler != null) {
@@ -161,31 +161,23 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     Context startElement(String namespaceURI, String localName, String prefix) throws StreamException
{
         if (passThroughHandler != null) {
             passThroughDepth++;
             passThroughHandler.startElement(namespaceURI, localName, prefix);
             return this;
         } else {
-            AxiomElement element;
-            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);
-                builderHandler.root.coreSetInputContext(this);
-                builderHandler.root.coreSetState(CoreParentNode.ATTRIBUTES_PENDING);
-                element = builderHandler.root;
-            } else {
-                element = builderHandler.nodeFactory.createNode(builderHandler.model.determineElementType(
-                        (AxiomContainer)target, depth+1, namespaceURI, localName));
-                element.coreSetState(CoreParentNode.ATTRIBUTES_PENDING);
-                element.initName(localName, ns, false);
-                addChild(element);
-            }
+            AxiomElement element = builderHandler.nodeFactory.createNode(builderHandler.model.determineElementType(
+                    (AxiomContainer)target, depth+1, namespaceURI, localName));
+            element.coreSetState(CoreParentNode.ATTRIBUTES_PENDING);
+            element.initName(localName, builderHandler.nsCache.getOMNamespace(namespaceURI,
prefix), false);
+            addChild(element);
             return newContext(element);
         }
     }
     
+    @Override
     Context endElement() throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.endElement();
@@ -195,6 +187,7 @@ final class Context implements InputCont
         }
     }
 
+    @Override
     void processAttribute(String namespaceURI, String localName, String prefix, String value,
String type, boolean specified) throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.processAttribute(namespaceURI, localName, prefix, value, type,
specified);
@@ -210,6 +203,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException
{
         if (passThroughHandler != null) {
             passThroughHandler.processNamespaceDeclaration(prefix, namespaceURI);
@@ -224,6 +218,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     void attributesCompleted() throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.attributesCompleted();
@@ -232,6 +227,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     void processCharacterData(Object data, boolean ignorable) throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.processCharacterData(data, ignorable);
@@ -245,6 +241,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     Context startProcessingInstruction(String piTarget) throws StreamException {
         if (passThroughHandler != null) {
             passThroughDepth++;
@@ -258,6 +255,7 @@ final class Context implements InputCont
         }
     }
 
+    @Override
     Context endProcessingInstruction() throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.endProcessingInstruction();
@@ -267,6 +265,7 @@ final class Context implements InputCont
         }
     }
 
+    @Override
     Context startComment() throws StreamException {
         if (passThroughHandler != null) {
             passThroughDepth++;
@@ -279,6 +278,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     Context endComment() throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.endComment();
@@ -288,6 +288,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     Context startCDATASection() throws StreamException {
         if (passThroughHandler != null) {
             passThroughDepth++;
@@ -300,6 +301,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     Context endCDATASection() throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.endCDATASection();
@@ -309,6 +311,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     void processEntityReference(String name, String replacementText) throws StreamException
{
         if (passThroughHandler != null) {
             passThroughHandler.processEntityReference(name, replacementText);
@@ -320,6 +323,7 @@ final class Context implements InputCont
         }
     }
     
+    @Override
     void completed() throws StreamException {
         if (passThroughHandler != null) {
             passThroughHandler.completed();

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=1734505&r1=1734504&r2=1734505&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 08:25:05 2016
@@ -35,9 +35,9 @@ import org.apache.axiom.om.impl.intf.Axi
 final class BuilderHandler implements XmlHandler {
     final NodeFactory nodeFactory;
     final Model model;
-    final AxiomSourcedElement root;
     final Builder builder;
     final OMNamespaceCache nsCache = new OMNamespaceCache();
+    private final Context rootContext;
     public Context context;
     private int activeContextCount;
     // returns the state of completion
@@ -57,9 +57,9 @@ final class BuilderHandler implements Xm
     BuilderHandler(NodeFactory nodeFactory, Model model, AxiomSourcedElement root, Builder
builder) {
         this.nodeFactory = nodeFactory;
         this.model = model;
-        this.root = root;
         this.builder = builder;
-        context = new Context(this, null, 0);
+        rootContext = root == null ? new BuildableContext(this, null, 0) : new UnwrappingContext(this,
root);
+        context = rootContext;
         activeContextCount = 1;
     }
 
@@ -71,6 +71,9 @@ final class BuilderHandler implements Xm
     }
     
     void nodeAdded(CoreNode node) {
+        if (node instanceof AxiomDocument) {
+            document = (AxiomDocument)node;
+        }
         if (listeners != null) {
             for (int i=0, size=listeners.size(); i<size; i++) {
                 Runnable action = listeners.get(i).nodeAdded(node, depth);
@@ -108,7 +111,7 @@ final class BuilderHandler implements Xm
     }
     
     AxiomDocument getDocument() {
-        if (root != null) {
+        if (rootContext instanceof UnwrappingContext) {
             throw new UnsupportedOperationException("There is no document linked to this
builder");
         } else {
             return document;
@@ -116,16 +119,7 @@ final class BuilderHandler implements Xm
     }
     
     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.coreSetInputContext(context);
-            nodeAdded(document);
-            context.target = document;
-        }
+        context.startDocument(inputEncoding, xmlVersion, xmlEncoding, standalone);
     }
     
     @Override

Added: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.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?rev=1734505&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
(added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
Fri Mar 11 08:25:05 2016
@@ -0,0 +1,76 @@
+/*
+ * 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.impl.common.builder;
+
+import org.apache.axiom.core.CoreParentNode;
+import org.apache.axiom.core.stream.StreamException;
+
+abstract class Context {
+    protected final BuilderHandler builderHandler;
+    protected final int depth;
+    private BuildableContext nestedContext;
+
+    Context(BuilderHandler builderHandler, int depth) {
+        this.builderHandler = builderHandler;
+        this.depth = depth;
+    }
+
+    protected final BuildableContext newContext(CoreParentNode target) {
+        if (nestedContext == null) {
+            nestedContext = new BuildableContext(builderHandler, this, depth+1);
+        }
+        nestedContext.target = target;
+        target.coreSetInputContext(nestedContext);
+        builderHandler.incrementActiveContextCount();
+        return nestedContext;
+    }
+    
+    abstract void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
boolean standalone);
+    
+    abstract void processDocumentTypeDeclaration(String rootName, String publicId, String
systemId,
+            String internalSubset) throws StreamException;
+    
+    abstract Context startElement(String namespaceURI, String localName, String prefix) throws
StreamException;
+    
+    abstract Context endElement() throws StreamException;
+    
+    abstract void processAttribute(String namespaceURI, String localName, String prefix,
String value, String type, boolean specified) throws StreamException;
+    
+    abstract void processNamespaceDeclaration(String prefix, String namespaceURI) throws
StreamException;
+    
+    abstract void attributesCompleted() throws StreamException;
+    
+    abstract void processCharacterData(Object data, boolean ignorable) throws StreamException;
+    
+    abstract Context startProcessingInstruction(String piTarget) throws StreamException;
+    
+    abstract Context endProcessingInstruction() throws StreamException;
+    
+    abstract Context startComment() throws StreamException;
+    
+    abstract Context endComment() throws StreamException;
+    
+    abstract Context startCDATASection() throws StreamException;
+    
+    abstract Context endCDATASection() throws StreamException;
+    
+    abstract void processEntityReference(String name, String replacementText) throws StreamException;
+    
+    abstract void completed() throws StreamException;
+}

Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/Context.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1734505&r1=1734504&r2=1734505&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 08:25:05 2016
@@ -74,7 +74,7 @@ public class StAXOMBuilder extends Abstr
     }
     
     public final String getCharsetEncoding() {
-        return builderHandler.document.getCharsetEncoding();
+        return builderHandler.getDocument().getCharsetEncoding();
     }
 
     public final void close() {

Added: 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=1734505&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
(added)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
Fri Mar 11 08:25:05 2016
@@ -0,0 +1,132 @@
+/*
+ * 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.impl.common.builder;
+
+import org.apache.axiom.core.CoreParentNode;
+import org.apache.axiom.core.stream.StreamException;
+import org.apache.axiom.om.impl.intf.AxiomSourcedElement;
+
+final class UnwrappingContext extends Context {
+    private final AxiomSourcedElement root;
+    
+    UnwrappingContext(BuilderHandler builderHandler, AxiomSourcedElement root) {
+        super(builderHandler, 0);
+        this.root = root;
+    }
+
+    @Override
+    void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
+            boolean standalone) {
+    }
+
+    @Override
+    void processDocumentTypeDeclaration(String rootName, String publicId, String systemId,
+            String internalSubset) throws StreamException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    BuildableContext 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);
+    }
+
+    @Override
+    BuildableContext endElement() throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    void processAttribute(String namespaceURI, String localName, String prefix, String value,
+            String type, boolean specified) throws StreamException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException
{
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    void attributesCompleted() throws StreamException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    void processCharacterData(Object data, boolean ignorable) throws StreamException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    BuildableContext startProcessingInstruction(String piTarget) throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    BuildableContext endProcessingInstruction() throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    BuildableContext startComment() throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    BuildableContext endComment() throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    BuildableContext startCDATASection() throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    BuildableContext endCDATASection() throws StreamException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    void processEntityReference(String name, String replacementText) throws StreamException
{
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    void completed() throws StreamException {
+        // TODO Auto-generated method stub
+        
+    }
+}

Propchange: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/builder/UnwrappingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message