You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/10/12 06:43:40 UTC

svn commit: r314783 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/ src/org/apache/axis2/databinding/utils/ test/org/apache/axis2/databinding/utils/

Author: chinthaka
Date: Tue Oct 11 21:43:23 2005
New Revision: 314783

URL: http://svn.apache.org/viewcvs?rev=314783&view=rev
Log:
Improving the pull parser code.
 - removed the unnecessary ADBNameValuePair class to remove unnecessary object creation. For this I had to flatten the property list array.
 - changed the property list container to an Array from ArrayList

Removed:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/ADBNameValuePair.java
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/DummyADBBean.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java?rev=314783&r1=314782&r2=314783&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/databinding/utils/ADBPullParser.java Tue Oct 11 21:43:23 2005
@@ -1,7 +1,6 @@
 package org.apache.axis2.databinding.utils;
 
 import org.apache.axis2.databinding.ADBBean;
-import org.apache.axis2.databinding.ADBNameValuePair;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
@@ -9,7 +8,6 @@
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import java.util.ArrayList;
 
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -29,7 +27,7 @@
 
 public class ADBPullParser implements XMLStreamReader {
 
-    private ArrayList propertyList;
+    private Object[] properties;
     private QName elementQName;
 
     private ADBPullParser childPullParser;
@@ -39,7 +37,7 @@
     // ===== To be used this ADBBean =============
     private boolean isEndElementFinished = false;
 
-    // ===== To be used with ADBNameValuePair ====
+    // ===== To be used with Simple Name Value pair ====
     private boolean processingADBNameValuePair = false;
     private boolean nameValuePairStartElementProcessed = false;
     private boolean nameValuePairTextProcessed = false;
@@ -52,13 +50,13 @@
     private int currentIndex = 0;
 
 
-    private ADBPullParser(ArrayList propertyList, QName elementQName) {
-        this.propertyList = propertyList;
+    private ADBPullParser(Object[] properties, QName elementQName) {
+        this.properties = properties;
         this.elementQName = elementQName;
     }
 
-    public static XMLStreamReader createPullParser(ArrayList propertyList, QName adbBeansQName) {
-        return new ADBPullParser(propertyList, adbBeansQName);
+    public static XMLStreamReader createPullParser(Object[] properties, QName adbBeansQName) {
+        return new ADBPullParser(properties, adbBeansQName);
     }
 
     public boolean isCompleted() {
@@ -104,7 +102,7 @@
 
     public int next() throws XMLStreamException {
         int event = 0;
-        if (currentIndex >= propertyList.size() + 2) {
+        if (currentIndex >= properties.length + 2) {
             throw new XMLStreamException("End of elements has already been reached. Can not go beyond that");
         }
 
@@ -113,13 +111,13 @@
                 return childPullParser.next();
             } else {
                 accessingChildPullParser = false;
-                currentIndex++;
+                currentIndex += 2;
             }
         }
 
         if(processingADBNameValuePair && nameValuePairEndElementProcessed){
             processingADBNameValuePair = false;
-            currentIndex++;
+            currentIndex = currentIndex + 2;
             parserInformation = tempParserInfo;
         }
 
@@ -128,37 +126,37 @@
             currentIndex++;
             parserInformation = new ParserInformation(this.elementQName);
             return XMLStreamConstants.START_ELEMENT;
-        } else if (propertyList.size() + 1 == currentIndex) {
+        } else if (properties.length + 1 == currentIndex) {
             // this is the end of this element
             currentIndex++;
             isEndElementFinished = true;
             return XMLStreamConstants.END_ELEMENT;
         } else {
             if (processingADBNameValuePair) {
-                return processADBNameValuePair(null);
+                return processADBNameValuePair(null, null);
             }
-            Object o = propertyList.get(currentIndex - 1);
-            if (o instanceof ADBBean) {
-                ADBBean adbBean = (ADBBean) o;
+            Object o = properties[currentIndex - 1];
+            if (o == null) {
+                ADBBean adbBean = (ADBBean) properties[currentIndex];
                 childPullParser = (ADBPullParser) adbBean.getPullParser();
                 accessingChildPullParser = true;
                 return this.next();
-            } else if (o instanceof ADBNameValuePair) {
-                ADBNameValuePair adbNameValuePair = (ADBNameValuePair) o;
+            } else {
+                String simplePropertyName = (String) o;
+                String simplePropertyValue = (String) properties[currentIndex];
                 processingADBNameValuePair = true;
-                return processADBNameValuePair(adbNameValuePair);
+                return processADBNameValuePair(simplePropertyName, simplePropertyValue);
             }
         }
 
-        return event;
     }
 
-    private int processADBNameValuePair(ADBNameValuePair nameValuePair) {
+    private int processADBNameValuePair(String simplePropertyName, String simplePropertyValue) {
         int event = 0;
-        if (nameValuePair != null) {
+        if (!nameValuePairStartElementProcessed) {
             event = XMLStreamConstants.START_ELEMENT;
             tempParserInfo = parserInformation;
-            parserInformation = new ParserInformation(new QName(nameValuePair.getName()), nameValuePair.getValue());
+            parserInformation = new ParserInformation(new QName(simplePropertyName), simplePropertyValue);
             nameValuePairStartElementProcessed = true;
             nameValuePairEndElementProcessed = false;
         } else if (nameValuePairStartElementProcessed && !nameValuePairTextProcessed) {

Modified: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java?rev=314783&r1=314782&r2=314783&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/databinding/utils/ADBPullParserTest.java Tue Oct 11 21:43:23 2005
@@ -2,7 +2,6 @@
 
 import junit.framework.TestCase;
 import org.apache.axis2.databinding.ADBBean;
-import org.apache.axis2.databinding.ADBNameValuePair;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -48,15 +47,18 @@
                     "<ThirdRelease>0.92</ThirdRelease></Releases><Organization>Apache</Organization>" +
                     "</Project>";
 
-            ADBNameValuePair adbNameValuePair;
             ArrayList propertyList = new ArrayList();
-            propertyList.add(new ADBNameValuePair("Name", "Axis2"));
+            propertyList.add("Name");
+            propertyList.add("Axis2");
+            propertyList.add(null);
             propertyList.add(new DummyADBBean());
+            propertyList.add(null);
             propertyList.add(new DummyADBBean());
-            propertyList.add(new ADBNameValuePair("Organization", "Apache"));
+            propertyList.add("Organization");
+            propertyList.add("Apache");
 
             QName projectQName = new QName("Project");
-            XMLStreamReader pullParser = ADBPullParser.createPullParser(propertyList, projectQName);
+            XMLStreamReader pullParser = ADBPullParser.createPullParser(propertyList.toArray(), projectQName);
 //            while (pullParser.hasNext()) {
 //                int eventCode = pullParser.next();
 //                System.out.println(eventCode + ":" + getEventString(eventCode));
@@ -85,7 +87,10 @@
                 }
             }
 
-            assertEquals(exptectedXML, buff.toString());
+
+            String s = buff.toString();
+            System.out.println("s = " + s);
+            assertEquals(exptectedXML, s);
         } catch (XMLStreamException e) {
             log.error("Parser Error " + e);
         }
@@ -148,14 +153,16 @@
     public class DummyADBBean implements ADBBean {
 
         public XMLStreamReader getPullParser() {
-            ADBNameValuePair adbNameValuePair;
             ArrayList propertyList = new ArrayList();
-            propertyList.add(new ADBNameValuePair("FirstRelease", "0.90"));
-            propertyList.add(new ADBNameValuePair("SecondRelease", "0.91"));
-            propertyList.add(new ADBNameValuePair("ThirdRelease", "0.92"));
+            propertyList.add("FirstRelease");
+            propertyList.add("0.90");
+            propertyList.add("SecondRelease");
+            propertyList.add("0.91");
+            propertyList.add("ThirdRelease");
+            propertyList.add("0.92");
 
             QName releasesQName = new QName("Releases");
-            return ADBPullParser.createPullParser(propertyList, releasesQName);
+            return ADBPullParser.createPullParser(propertyList.toArray(), releasesQName);
         }
     }
 }