cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r726631 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/staxutils/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/
Date Mon, 15 Dec 2008 07:20:22 GMT
Author: dkulp
Date: Sun Dec 14 23:20:22 2008
New Revision: 726631

URL: http://svn.apache.org/viewvc?rev=726631&view=rev
Log:
Performance change to streamreader to not use indexes for next nodes for DOM, use getNextSibling.

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java?rev=726631&r1=726630&r2=726631&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/AbstractDOMStreamReader.java
Sun Dec 14 23:20:22 2008
@@ -28,7 +28,6 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.w3c.dom.Document;
 
 /**
  * Abstract logic for creating XMLStreamReader from DOM documents. Its works
@@ -37,45 +36,47 @@
  * @see ElementAdapter }
  * @author <a href="mailto:tsztelak@gmail.com">Tomasz Sztelak</a>
  */
-public abstract class AbstractDOMStreamReader implements XMLStreamReader {
+public abstract class AbstractDOMStreamReader<T, I> implements XMLStreamReader {
     protected int currentEvent = XMLStreamConstants.START_DOCUMENT;
 
     private Map properties = new HashMap();
 
-    private FastStack<ElementFrame> frames = new FastStack<ElementFrame>();
+    private FastStack<ElementFrame<T, I>> frames = new FastStack<ElementFrame<T,
I>>();
 
-    private ElementFrame frame;
+    private ElementFrame<T, I> frame;
 
     
     /**
      *     
      */
-    public static class ElementFrame {
-        Object element;
+    public static class ElementFrame<T, I> {
+        T element;
+        I currentChild;
 
         boolean started;
-
         boolean ended;
-
-        int currentChild = -1;
-
+        
         int currentAttribute = -1;
-
         int currentNamespace = -1;
 
-        int currentElement = -1;
         List<String> uris;
         List<String> prefixes;
         List<Object> attributes;
         List<Object> allAttributes;
 
-        final ElementFrame parent;
+        final ElementFrame<T, I> parent;
+        
+        public ElementFrame(T element, ElementFrame<T, I> parent) {
+            this.element = element;
+            this.parent = parent;
+        }
         
-        public ElementFrame(Object element, ElementFrame parent) {
+        public ElementFrame(T element, ElementFrame<T, I> parent, I ch) {
             this.element = element;
             this.parent = parent;
+            this.currentChild = ch;
         }
-        public ElementFrame(Document doc) {
+        public ElementFrame(T doc) {
             this.element = doc;
             parent = null;
             started = true;
@@ -85,22 +86,28 @@
             allAttributes = Collections.emptyList();
         }
         
-        public Object getElement() {
+        public T getElement() {
             return element;
         }
 
+        public I getCurrentChild() {
+            return currentChild;
+        }
+        public void setCurrentChild(I o) {
+            currentChild = o;
+        }
 
     }
 
     /**
      * @param element
      */
-    public AbstractDOMStreamReader(ElementFrame frame) {
+    public AbstractDOMStreamReader(ElementFrame<T, I> frame) {
         this.frame = frame;
         frames.push(this.frame);
     }
 
-    protected ElementFrame getCurrentFrame() {
+    protected ElementFrame<T, I> getCurrentFrame() {
         return frame;
     }
 
@@ -122,7 +129,7 @@
         if (frame.ended) {
             frames.pop();
             if (!frames.empty()) {
-                frame = (ElementFrame)frames.peek();
+                frame = frames.peek();
             } else {
                 currentEvent = END_DOCUMENT;
                 return currentEvent;
@@ -138,13 +145,11 @@
         } else if (frame.currentNamespace < getNamespaceCount() - 1) {
             frame.currentNamespace++;
             currentEvent = NAMESPACE;
-        } else if (frame.currentChild < getChildCount() - 1) {
-            frame.currentChild++;
-
-            currentEvent = moveToChild(frame.currentChild);
+        } else if (hasMoreChildren()) {
+            currentEvent = nextChild();
 
             if (currentEvent == START_ELEMENT) {
-                ElementFrame newFrame = getChildFrame(frame.currentChild);
+                ElementFrame<T, I> newFrame = getChildFrame();
                 newFrame.started = true;
                 frame = newFrame;
                 frames.push(this.frame);
@@ -160,17 +165,15 @@
         return currentEvent;
     }
 
-    protected void newFrame(ElementFrame newFrame) {
+    protected void newFrame(ElementFrame<T, I> newFrame) {
     }
 
     protected void endElement() {
     }
 
-    protected abstract int moveToChild(int currentChild);
-
-    protected abstract ElementFrame getChildFrame(int currentChild);
-
-    protected abstract int getChildCount();
+    protected abstract boolean hasMoreChildren();
+    protected abstract int nextChild();
+    protected abstract ElementFrame<T, I> getChildFrame();
 
     /*
      * (non-Javadoc)

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java?rev=726631&r1=726630&r2=726631&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamReader.java
Sun Dec 14 23:20:22 2008
@@ -36,7 +36,7 @@
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.staxutils.AbstractDOMStreamReader.ElementFrame;
 
-public class W3CDOMStreamReader extends AbstractDOMStreamReader {
+public class W3CDOMStreamReader extends AbstractDOMStreamReader<Node, Node> {
     private Node content;
 
     private Document document;
@@ -47,13 +47,13 @@
      * @param element
      */
     public W3CDOMStreamReader(Element element) {
-        super(new ElementFrame(element, null));
+        super(new ElementFrame<Node, Node>(element, null));
         newFrame(getCurrentFrame());
                 
         this.document = element.getOwnerDocument();
     }
     public W3CDOMStreamReader(Document doc) {
-        super(new ElementFrame(doc));
+        super(new ElementFrame<Node, Node>(doc));
         this.document = doc;
     }
 
@@ -71,7 +71,7 @@
      * collection.
      */
     @Override
-    protected final void newFrame(ElementFrame frame) {
+    protected final void newFrame(ElementFrame<Node, Node> frame) {
         Node element = getCurrentNode();
         frame.uris = new ArrayList<String>();
         frame.prefixes = new ArrayList<String>();
@@ -133,22 +133,29 @@
     }
 
     @Override
-    protected ElementFrame getChildFrame(int currentChild) {
-        return new ElementFrame(getCurrentNode().getChildNodes().item(currentChild), getCurrentFrame());
+    protected ElementFrame<Node, Node> getChildFrame() {
+        return new ElementFrame<Node, Node>(getCurrentFrame().currentChild, 
+                                getCurrentFrame());
     }
 
     @Override
-    protected int getChildCount() {
-        return getCurrentNode().getChildNodes().getLength();
+    protected boolean hasMoreChildren() {
+        if (getCurrentFrame().currentChild == null) {
+            return getCurrentNode().getFirstChild() != null;            
+        }
+        return ((Node)getCurrentFrame().currentChild).getNextSibling() != null;
     }
 
     @Override
-    protected int moveToChild(int currentChild) {
-        content = getCurrentNode().getFirstChild();
-        while (currentChild > 0 && content != null) {
-            content = content.getNextSibling();
-            --currentChild;
+    protected int nextChild() {
+        ElementFrame<Node, Node> frame = getCurrentFrame();
+        if (frame.currentChild == null) {
+            content = getCurrentNode().getFirstChild();            
+        } else {
+            content = ((Node)frame.currentChild).getNextSibling();
         }
+        
+        frame.currentChild = content;
         switch (content.getNodeType()) {
         case Node.ELEMENT_NODE:
             return START_ELEMENT;
@@ -169,7 +176,7 @@
     public String getElementText() throws XMLStreamException {
         String result = DOMUtils.getContent(content);
 
-        ElementFrame frame = getCurrentFrame();
+        ElementFrame<Node, Node> frame = getCurrentFrame();
         frame.ended = true;
         currentEvent = END_ELEMENT;
         endElement();
@@ -180,7 +187,7 @@
 
     @Override
     public String getNamespaceURI(String prefix) {
-        ElementFrame frame = getCurrentFrame();
+        ElementFrame<Node, Node> frame = getCurrentFrame();
 
         while (null != frame) {
             int index = frame.prefixes.indexOf(prefix);

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java?rev=726631&r1=726630&r2=726631&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/stax/JDOMStreamReader.java
Sun Dec 14 23:20:22 2008
@@ -45,7 +45,7 @@
  * 
  * @author <a href="mailto:tsztelak@gmail.com">Tomasz Sztelak</a>
  */
-public class JDOMStreamReader extends AbstractDOMStreamReader {
+public class JDOMStreamReader extends AbstractDOMStreamReader<Element, Integer> {
 
     private Content content;
 
@@ -62,7 +62,7 @@
      * @param element
      */
     public JDOMStreamReader(Element element) {
-        super(new ElementFrame(element, null));
+        super(new ElementFrame<Element, Integer>(element, null, -1));
 
         namespaceContext = new JDOMNamespaceContext();
         setupNamespaces(element);
@@ -182,21 +182,28 @@
     }
 
     public Element getCurrentElement() {
-        return (Element)getCurrentFrame().getElement();
+        return getCurrentFrame().getElement();
     }
 
     @Override
-    protected ElementFrame getChildFrame(int currentChild) {
-        return new ElementFrame(getCurrentElement().getContent(currentChild), getCurrentFrame());
+    protected ElementFrame<Element, Integer> getChildFrame() {
+        int currentChild = getCurrentFrame().getCurrentChild();
+        return new ElementFrame<Element, Integer>((Element)getCurrentElement().getContent(currentChild),
+                                                  getCurrentFrame(),
+                                                  -1);
     }
 
     @Override
-    protected int getChildCount() {
-        return getCurrentElement().getContentSize();
+    protected boolean hasMoreChildren() {
+        int currentChild = getCurrentFrame().getCurrentChild();
+        return currentChild < (getCurrentElement().getContentSize() - 1);
     }
 
     @Override
-    protected int moveToChild(int currentChild) {
+    protected int nextChild() {
+        int currentChild = getCurrentFrame().getCurrentChild();
+        currentChild++;
+        getCurrentFrame().setCurrentChild(currentChild);
         this.content = getCurrentElement().getContent(currentChild);
 
         if (content instanceof Text) {



Mime
View raw message