ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1728942 - in /webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common: Handler.java OMContentHandler.java SAXResultContentHandler.java builder/StAXOMBuilder.java factory/SAXOMBuilder.java
Date Sun, 07 Feb 2016 10:23:24 GMT
Author: veithen
Date: Sun Feb  7 10:23:23 2016
New Revision: 1728942

URL: http://svn.apache.org/viewvc?rev=1728942&view=rev
Log:
Some refactoring and cleanup.

Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.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/factory/SAXOMBuilder.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java?rev=1728942&r1=1728941&r2=1728942&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Handler.java
Sun Feb  7 10:23:23 2016
@@ -18,8 +18,6 @@
  */
 package org.apache.axiom.om.impl.common;
 
-import org.apache.axiom.om.OMElement;
-
 // TODO: transitional interface that should eventually converge with BuilderHandler
 public interface Handler {
     void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, boolean
standalone);
@@ -29,13 +27,16 @@ public interface Handler {
     void createDocumentTypeDeclaration(String rootName, String publicId,
             String systemId, String internalSubset);
 
-    OMElement createOMElement(String localName,
-            String namespaceURI, String prefix, String[] namespaces, int namespaceCount);
+    void startElement(String namespaceURI, String localName, String prefix);
     
     void endElement();
     
     void createAttribute(String namespaceURI, String localName, String prefix, String value,
String type, boolean specified);
     
+    void createNamespaceDeclaration(String prefix, String namespaceURI);
+    
+    void attributesCompleted();
+    
     void createOMText(String text, int type);
     
     void createProcessingInstruction(String piTarget, String piData);

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java?rev=1728942&r1=1728941&r2=1728942&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/OMContentHandler.java
Sun Feb  7 10:23:23 2016
@@ -238,7 +238,10 @@ public final class OMContentHandler impl
                 localName = qName.substring(qName.indexOf(':') + 1);
             int idx = qName.indexOf(':');
             String prefix = idx == -1 ? "" : qName.substring(0, idx);
-            handler.createOMElement(localName, namespaceURI, prefix, namespaces, namespaceCount);
+            handler.startElement(namespaceURI, localName, prefix);
+            for (int i = 0; i < namespaceCount; i++) {
+                handler.createNamespaceDeclaration(namespaces[2*i], namespaces[2*i+1]);
+            }
             namespaceCount = 0;
     
             int j = atts.getLength();
@@ -256,6 +259,7 @@ public final class OMContentHandler impl
                     handler.createAttribute(atts.getURI(i), atts.getLocalName(i), attrPrefix,
atts.getValue(i), atts.getType(i), true);
                 }
             }
+            handler.attributesCompleted();
         }
     }
 

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java?rev=1728942&r1=1728941&r2=1728942&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/SAXResultContentHandler.java
Sun Feb  7 10:23:23 2016
@@ -51,21 +51,9 @@ public final  class SAXResultContentHand
         }
     }
 
-    public OMElement createOMElement(String localName, String namespaceURI,
-            String prefix, String[] namespaces, int namespaceCount) {
+    public void startElement(String namespaceURI, String localName, String prefix) {
         // TODO: inefficient: we should not create a new OMNamespace instance every time
-        OMElement element = factory.createOMElement(localName, factory.createOMNamespace(namespaceURI,
prefix), target);
-        for (int i=0; i<namespaceCount; i++) {
-            String nsPrefix = namespaces[2*i];
-            String nsURI = namespaces[2*i+1];
-            if (nsPrefix.length() == 0) {
-                element.declareDefaultNamespace(nsURI);
-            } else {
-                element.declareNamespace(nsURI, nsPrefix);
-            }
-        }
-        target = element;
-        return element;
+        target = factory.createOMElement(localName, factory.createOMNamespace(namespaceURI,
prefix), target);
     }
 
     public void endElement() {
@@ -89,6 +77,19 @@ public final  class SAXResultContentHand
         attr.setAttributeType(type);
     }
 
+    @Override
+    public void createNamespaceDeclaration(String prefix, String namespaceURI) {
+        if (prefix.isEmpty()) {
+            ((OMElement)target).declareDefaultNamespace(namespaceURI);
+        } else {
+            ((OMElement)target).declareNamespace(namespaceURI, prefix);
+        }
+    }
+
+    @Override
+    public void attributesCompleted() {
+    }
+
     public void createOMText(String text, int type) {
         factory.createOMText(target, text, type);
     }

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=1728942&r1=1728941&r2=1728942&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
Sun Feb  7 10:23:23 2016
@@ -27,7 +27,6 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.builder.Builder;
 import org.apache.axiom.om.impl.builder.CustomBuilder;
 import org.apache.axiom.om.impl.builder.CustomBuilderSupport;
@@ -159,24 +158,6 @@ public class StAXOMBuilder extends Abstr
         return s == null ? "" : s;
     }
     
-    /**
-     * Method processAttributes.
-     *
-     * @param node
-     */
-    private void processAttributes(OMElement node) {
-        int attribCount = parser.getAttributeCount();
-        for (int i = 0; i < attribCount; i++) {
-            handler.createAttribute(
-                    normalize(parser.getAttributeNamespace(i)),
-                    parser.getAttributeLocalName(i),
-                    normalize(parser.getAttributePrefix(i)),
-                    parser.getAttributeValue(i),
-                    parser.getAttributeType(i),
-                    parser.isAttributeSpecified(i));
-        }
-    }
-
     private void createOMText(int textType) {
         if (textType == XMLStreamConstants.CHARACTERS && dataHandlerReader != null
&& dataHandlerReader.isBinary()) {
             TextContent data;
@@ -591,9 +572,8 @@ public class StAXOMBuilder extends Abstr
     /**
      * Creates a new OMElement using either a CustomBuilder or 
      * the default Builder mechanism.
-     * @return TODO
      */
-    private OMNode createNextOMElement() {
+    private void createNextOMElement() {
         String namespaceURI = normalize(parser.getNamespaceURI());
         String localName = parser.getLocalName();
         String prefix = normalize(parser.getPrefix());
@@ -609,9 +589,26 @@ public class StAXOMBuilder extends Abstr
         }
         if (newElement == null) {
             newElement = handler.startElement(namespaceURI, localName, prefix);
-            populateOMElement(newElement);
+            for (int i = 0, count = parser.getNamespaceCount(); i < count; i++) {
+                handler.createNamespaceDeclaration(
+                        normalize(parser.getNamespacePrefix(i)),
+                        normalize(parser.getNamespaceURI(i)));
+            }
+            for (int i = 0, count = parser.getAttributeCount(); i < count; i++) {
+                handler.createAttribute(
+                        normalize(parser.getAttributeNamespace(i)),
+                        parser.getAttributeLocalName(i),
+                        normalize(parser.getAttributePrefix(i)),
+                        parser.getAttributeValue(i),
+                        parser.getAttributeType(i),
+                        parser.isAttributeSpecified(i));
+            }
+            handler.attributesCompleted();
+            Location location = parser.getLocation();
+            if (location != null) {
+                newElement.setLineNumber(location.getLineNumber());
+            }
         }
-        return newElement;
     }
     
     private OMElement createWithCustomBuilder(CustomBuilder customBuilder) {
@@ -654,25 +651,6 @@ public class StAXOMBuilder extends Abstr
         return node;
     }
     
-    /**
-     * Populate element with data from parser START_ELEMENT event. This is used when the
source of
-     * data for an element needs to be parsed on demand. The supplied element must already
be set to
-     * the proper name and namespace.
-     *
-     * @param node element to be populated
-     */
-    private void populateOMElement(OMElement node) {
-        // create the namespaces
-        processNamespaceData(node);
-        // fill in the attributes
-        processAttributes(node);
-        handler.attributesCompleted();
-        Location location = parser.getLocation();
-        if(location != null) {
-            node.setLineNumber(location.getLineNumber());
-        }
-    }
-
     private void createDTD() throws OMException {
         DTDReader dtdReader;
         try {
@@ -738,20 +716,6 @@ public class StAXOMBuilder extends Abstr
     }
 
     /**
-     * Method processNamespaceData.
-     *
-     * @param node
-     */
-    private void processNamespaceData(OMElement node) {
-        int namespaceCount = parser.getNamespaceCount();
-        for (int i = 0; i < namespaceCount; i++) {
-            handler.createNamespaceDeclaration(
-                    normalize(parser.getNamespacePrefix(i)),
-                    normalize(parser.getNamespaceURI(i)));
-        }
-    }
-
-    /**
      * Pushes the virtual parser ahead one token.
      * If a look ahead token was calculated it is returned.
      * @return next token

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java?rev=1728942&r1=1728941&r2=1728942&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/factory/SAXOMBuilder.java
Sun Feb  7 10:23:23 2016
@@ -20,13 +20,11 @@
 package org.apache.axiom.om.impl.common.factory;
 
 import org.apache.axiom.core.NodeFactory;
-import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.impl.common.Handler;
 import org.apache.axiom.om.impl.common.OMContentHandler;
 import org.apache.axiom.om.impl.common.builder.AbstractPushBuilder;
 import org.apache.axiom.om.impl.common.builder.Model;
-import org.apache.axiom.om.impl.intf.AxiomElement;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
@@ -83,15 +81,8 @@ public final class SAXOMBuilder extends
         handler.createDocumentTypeDeclaration(rootName, publicId, systemId, internalSubset);
     }
 
-    public OMElement createOMElement(String localName,
-            String namespaceURI, String prefix, String[] namespaces, int namespaceCount)
{
-        AxiomElement element = handler.startElement(namespaceURI, localName, prefix);
-        for (int i = 0; i < namespaceCount; i++) {
-            handler.createNamespaceDeclaration(namespaces[2*i], namespaces[2*i+1]);
-        }
-        // TODO: not entirely correct, but should work
-        handler.attributesCompleted();
-        return element;
+    public void startElement(String namespaceURI, String localName, String prefix) {
+        handler.startElement(namespaceURI, localName, prefix);
     }
 
     public void endElement() {
@@ -129,4 +120,12 @@ public final class SAXOMBuilder extends
     public void createAttribute(String namespaceURI, String localName, String prefix, String
value, String type, boolean specified) {
         handler.createAttribute(namespaceURI, localName, prefix, value, type, specified);
     }
+
+    public void createNamespaceDeclaration(String prefix, String namespaceURI) {
+        handler.createNamespaceDeclaration(prefix, namespaceURI);
+    }
+
+    public void attributesCompleted() {
+        handler.attributesCompleted();
+    }
 }



Mime
View raw message