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/21 09:50:06 UTC

svn commit: r327115 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/utils/ADBPullParser.java test/org/apache/axis2/databinding/utils/ADBPullParserTest.java

Author: chinthaka
Date: Fri Oct 21 00:49:48 2005
New Revision: 327115

URL: http://svn.apache.org/viewcvs?rev=327115&view=rev
Log:
Adding supporting of array of strings in to the propertyList with a test case. Now one can add an array of string as the value to the property list that you pass in to the ADBPull parser.
One more to come .... Adding of an array of objects.

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=327115&r1=327114&r2=327115&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 Fri Oct 21 00:49:48 2005
@@ -60,6 +60,16 @@
     private ParserInformation tempParserInfo;
     // ==============================================
 
+    // ===== To be used with Simple Name Value pair ====
+    // this is used when we have an array of Strings
+    private boolean processingComplexADBNameValuePair = false;
+    private int secondArrayIndex = 0;
+    private String[] complexStringArray;
+    private String complexStringArrayName;
+    // ==============================================
+
+
+
     private ParserInformation parserInformation;
 
     // a pointer to the children list of current location
@@ -183,7 +193,21 @@
             }
         }
 
+        // now check whether we are processing a complex string array or not
+        if(processingComplexADBNameValuePair && nameValuePairEndElementProcessed){
+            // this means we are done with processing one complex string array entry
+            // check we have more
+            if(complexStringArray.length > ++secondArrayIndex){
+                // we have some more to process
+                processingADBNameValuePair = true;
+                return processADBNameValuePair(complexStringArrayName, complexStringArray[secondArrayIndex]);
+            }else{
+                // completed looking at all the entries. Now go forward with normal entries, if any.
+                processingComplexADBNameValuePair = false;
+            }
+        }
 
+        // check whether we are done with processing a name value pair from an earlier cycle
         if (processingADBNameValuePair && nameValuePairEndElementProcessed) {
             processingADBNameValuePair = false;
             currentIndex = currentIndex + 2;
@@ -225,18 +249,21 @@
                 accessingChildPullParser = true;
                 return this.next();
             } else if (o instanceof String) {
+
+                // TODO : Chinthaka this is not finished.
                 Object property = properties[currentIndex];
                 String simplePropertyName = (String) o;
 
                 if (property instanceof String[]) {
-                    String[] stringArray = (String[]) property;
 
-                    // lets create an array out of this and create a pull parser out of this
-                    String[] propertyArray = new String[stringArray.length * 2];
-                    for (int i = 0; i < stringArray.length; i++) {
-                        propertyArray[i] = simplePropertyName;
-                        propertyArray[i + 1] = stringArray[i];
-                    }
+                    complexStringArrayName = simplePropertyName;
+                    complexStringArray = (String[]) property;
+                    secondArrayIndex = 0;
+                    processingComplexADBNameValuePair = true;
+
+                    // use the simple name value pair processing recursively
+                    processingADBNameValuePair = true;
+                    return processADBNameValuePair(simplePropertyName, complexStringArray[secondArrayIndex]);
 
                 } else if (property instanceof String) {
                     String simplePropertyValue = (String) properties[currentIndex];

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=327115&r1=327114&r2=327115&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 Fri Oct 21 00:49:48 2005
@@ -271,7 +271,7 @@
             attribute[i] = factory.createOMAttribute("Attr" + (i + 1), null, "Value " + (i + 1));
         }
 
-        String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, new Object[] {null, attribute}));
+        String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, new Object[]{null, attribute}));
         try {
             Document actualDom = newDocument(stringXML);
             Document expectedDocument = newDocument(expectedXML);
@@ -304,7 +304,7 @@
             attribute[i] = factory.createOMAttribute("Attr" + (i + 1), attrNS, "Value " + (i + 1));
         }
 
-        String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, new Object[] {null, attribute}));
+        String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, new Object[]{null, attribute}));
         try {
             Document actualDom = newDocument(stringXML);
             Document expectedDocument = newDocument(expectedXML);
@@ -349,7 +349,7 @@
 
     }
 
-    public void testAttributeArray(){
+    public void testAttributeArray() {
 
         String expectedXML = "<ns1:TestAttributeArray xmlns:ns1=\"http://testAttributeArray.org\" " +
                 "xmlns:attrNS=\"mailto:whoever@whatever.com\" xmlns:myAttr=\"http://www.axis2.net\" " +
@@ -358,7 +358,6 @@
                 "<Foo>Some Text</Foo><Dependent><Name>FooTwo</Name><Age>25</Age><Sex>Male</Sex>" +
                 "</Dependent></ns1:TestAttributeArray>";
 
-
         // lets first have some properties
         ArrayList propertyList = new ArrayList();
         propertyList.add("Foo");
@@ -388,12 +387,61 @@
         try {
             assertXMLEqual(newDocument(expectedXML), newDocument(actualXML));
         } catch (ParserConfigurationException e) {
-            fail("Error has occurred "+ e);
+            fail("Error has occurred " + e);
         } catch (SAXException e) {
-            fail("Error has occurred "+ e);
+            fail("Error has occurred " + e);
         } catch (IOException e) {
-            fail("Error has occurred "+ e);
+            fail("Error has occurred " + e);
         }
+
+    }
+
+    public void testComplexStringArrayScenario() {
+
+        String expectedXML = "<ns1:TestComplexStringArrayScenario xmlns:ns1=\"http://testComplexStringArrayScenario.org\">" +
+                "<Foo>Some Text</Foo>" +
+                "<Dependent>" +
+                "<Name>FooTwo</Name>" +
+                "<Age>25</Age>" +
+                "<Sex>Male</Sex>" +
+                "</Dependent>" +
+                "<StringInfo>Some Text 0</StringInfo>" +
+                "<StringInfo>Some Text 1</StringInfo>" +
+                "<StringInfo>Some Text 2</StringInfo>" +
+                "<StringInfo>Some Text 3</StringInfo>" +
+                "<Bar>Some More Text</Bar>" +
+                "</ns1:TestComplexStringArrayScenario>";
+
+        ArrayList propertyList = new ArrayList();
+        propertyList.add("Foo");
+        propertyList.add("Some Text");
+        propertyList.add(new QName("Dependent"));
+        DummyADBBean dummyBean = new DummyADBBean();
+        propertyList.add(dummyBean);
+
+        String[] stringArray = new String[4];
+        for (int i = 0; i < 4; i++) {
+            stringArray[i] = "Some Text " + i;
+        }
+        propertyList.add("StringInfo");
+        propertyList.add(stringArray);
+
+        propertyList.add("Bar");
+        propertyList.add("Some More Text");
+
+        XMLStreamReader pullParser = ADBPullParser.createPullParser(new QName("http://testComplexStringArrayScenario.org", "TestComplexStringArrayScenario", "ns1"), propertyList.toArray(), null);
+        String actualXML = getStringXML(pullParser);
+
+        try {
+            assertXMLEqual(newDocument(expectedXML), newDocument(actualXML));
+        } catch (ParserConfigurationException e) {
+            fail("Error has occurred " + e);
+        } catch (SAXException e) {
+            fail("Error has occurred " + e);
+        } catch (IOException e) {
+            fail("Error has occurred " + e);
+        }
+
 
     }