Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 25738 invoked from network); 21 Oct 2005 08:42:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Oct 2005 08:42:36 -0000 Received: (qmail 91230 invoked by uid 500); 21 Oct 2005 08:42:32 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 91170 invoked by uid 500); 21 Oct 2005 08:42:31 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 91159 invoked by uid 500); 21 Oct 2005 08:42:31 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 91156 invoked by uid 99); 21 Oct 2005 08:42:31 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 21 Oct 2005 01:42:30 -0700 Received: (qmail 25534 invoked by uid 65534); 21 Oct 2005 08:42:10 -0000 Message-ID: <20051021084210.25531.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r327122 - in /webservices/axis2/trunk/java/modules/codegen: src/org/apache/axis2/databinding/utils/ADBPullParser.java test/org/apache/axis2/databinding/utils/ADBPullParserTest.java Date: Fri, 21 Oct 2005 08:42:10 -0000 To: axis2-cvs@ws.apache.org From: chinthaka@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: chinthaka Date: Fri Oct 21 01:41:57 2005 New Revision: 327122 URL: http://svn.apache.org/viewcvs?rev=327122&view=rev Log: At last, completed ADBPullParser. It can now support arrays within the property list. Array can be Sting[], ADBBean[], Bean[], OMElement[]. Seems we have a small bug in OM, needs to fix that too to make ADBPullParser fully functional for OMElements. 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=327122&r1=327121&r2=327122&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 01:41:57 2005 @@ -63,11 +63,20 @@ // ===== 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; // ============================================== + // + // ===== To be used with Arrays coming within the propery list (except String arrays) ==== + // this is used when we have an array of ADBBeans, OMElements or Beans + private boolean processingComplexArray = false; + private Object[] complexArray; + private QName complexArrayQName; + // ============================================== + // some time arrays can come within the property list array. Following will bes used as the + // index of that array + private int secondArrayIndex = 0; private ParserInformation parserInformation; @@ -107,52 +116,52 @@ * @param properties - this should contain all the stuff that stax events should be generated. * Lets take an example of a bean. *
-     *                                                                                               
-     *                                                                                                      
-     *                                                                                                          FooTwo
-     *                                                                                                          25
-     *                                                                                                          Male
-     *                                                                                                      
-     *                                                                                              
-     *                   

- *

- * so the mapping bean for this is - * class Person { - * String Name; - * Dependent dependentOne; - * } - *

- *

- * class Dependent { - * String name; - * int age; - * String sex; - * } - *

- *

- * So if one needs to generate pull events out of a Person bean, the array he needs - * to pass is like this. - * --------------------------------------------------------------------------------------------------- - * | "Name" | "FooOne" | QName("DependentOne") | Dependent object| null | Array of Dependent objects | - * --------------------------------------------------------------------------------------------------- - * This DependentObject can either be an ADBBean, OMElement or a POJO. If its an ADBBean - * We directly get the pull parser from that. If not we create a reflection based - * pull parser for that java bean. - *

- *

- * This is the how the parsed array should look like - * Key Value - * String String - * QName ADBBean, OMElement, Bean - * String String[] - * QName Object[] - this contains only one type of objects - *

- *

- * This is how the passed attribute array should look like - * Key Value - * null OMAttribute[] - * QName String - *

+ * + * + * FooTwo + * 25 + * Male + * + * + *

+ *

+ * so the mapping bean for this is + * class Person { + * String Name; + * Dependent dependentOne; + * } + *

+ *

+ * class Dependent { + * String name; + * int age; + * String sex; + * } + *

+ *

+ * So if one needs to generate pull events out of a Person bean, the array he needs + * to pass is like this. + * --------------------------------------------------------------------------------------------------- + * | "Name" | "FooOne" | QName("DependentOne") | Dependent object| null | Array of Dependent objects | + * --------------------------------------------------------------------------------------------------- + * This DependentObject can either be an ADBBean, OMElement or a POJO. If its an ADBBean + * We directly get the pull parser from that. If not we create a reflection based + * pull parser for that java bean. + *

+ *

+ * This is the how the parsed array should look like + * Key Value + * String String + * QName ADBBean, OMElement, Bean + * String String[] + * QName Object[] - this contains only one type of objects + *

+ *

+ * This is how the passed attribute array should look like + * Key Value + * null OMAttribute[] + * QName String + * * @return XMLStreamReader */ public static XMLStreamReader createPullParser(QName adbBeansQName, Object[] properties, Object[] attributes) { @@ -184,9 +193,24 @@ throw new XMLStreamException("End of elements has already been reached. Can not go beyond that"); } + // check we can still get events from the child pull parser if (accessingChildPullParser) { + + // if there are some stuff available proceed with that if (childPullParser.hasNext()) { return childPullParser.next(); + } else if (processingComplexArray) { + // check we are processing an array which was sent inside the property list + if (complexArray.length > ++secondArrayIndex) { + // seems we have some more to process + getPullParser(complexArray[secondArrayIndex], complexArrayQName); + return this.next(); + } else { + processingComplexArray = false; + accessingChildPullParser = false; + currentIndex += 2; + } + } else { accessingChildPullParser = false; currentIndex += 2; @@ -194,14 +218,14 @@ } // now check whether we are processing a complex string array or not - if(processingComplexADBNameValuePair && nameValuePairEndElementProcessed){ + if (processingComplexADBNameValuePair && nameValuePairEndElementProcessed) { // this means we are done with processing one complex string array entry // check we have more - if(complexStringArray.length > ++secondArrayIndex){ + if (complexStringArray.length > ++secondArrayIndex) { // we have some more to process processingADBNameValuePair = true; return processADBNameValuePair(complexStringArrayName, complexStringArray[secondArrayIndex]); - }else{ + } else { // completed looking at all the entries. Now go forward with normal entries, if any. processingComplexADBNameValuePair = false; } @@ -236,15 +260,14 @@ Object o = properties[currentIndex - 1]; if (o instanceof QName) { Object object = properties[currentIndex]; - if (object instanceof ADBBean) { - ADBBean adbBean = (ADBBean) object; - ADBPullParser adbPullParser = (ADBPullParser) adbBean.getPullParser((QName) o); - adbPullParser.setNamespaceMap(this.namespaceMap); - childPullParser = adbPullParser; - } else if (object instanceof OMElement) { - childPullParser = ((OMElement) object).getXMLStreamReader(); + if (object instanceof Object[]) { + secondArrayIndex = 0; + complexArray = (Object[]) object; + complexArrayQName = (QName) o; + getPullParser(complexArray[secondArrayIndex], complexArrayQName); + processingComplexArray = true; } else { - childPullParser = BeanSerializerUtil.getPullParser(object, (QName) o); + getPullParser(object, (QName) o); } accessingChildPullParser = true; return this.next(); @@ -276,6 +299,20 @@ } } + } + + private XMLStreamReader getPullParser(Object object, QName qname) { + if (object instanceof ADBBean) { + ADBBean adbBean = (ADBBean) object; + ADBPullParser adbPullParser = (ADBPullParser) adbBean.getPullParser(qname); + adbPullParser.setNamespaceMap(this.namespaceMap); + childPullParser = adbPullParser; + } else if (object instanceof OMElement) { + childPullParser = ((OMElement) object).getXMLStreamReader(); + } else { + childPullParser = BeanSerializerUtil.getPullParser(object, qname); + } + return childPullParser; } private void handleNamespacesAndAttributes() { 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=327122&r1=327121&r2=327122&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 01:41:57 2005 @@ -445,6 +445,69 @@ } + public void testComplexObjectArrayScenario() { + + String expectedXML = "" + + "Some Text" + + "" + + "FooTwo" + + "25" + + "Male" + + "" + + "" + + "FooTwo" + + "25" + + "Male" + + "" + + "" + + "FooTwo" + + "25" + + "Male" + + "" + + "" + + "FooTwo" + + "25" + + "Male" + + "" + + "" + + "FooTwo" + + "25" + + "Male" + + "" + + "Some More Text<" + + "/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); + + ADBBean[] adbBeans = new ADBBean[4]; + for (int i = 0; i < 4; i++) { + adbBeans[i] = new DummyADBBean(); + } + propertyList.add(new QName("AdditionalDependent")); + propertyList.add(adbBeans); + + 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); + } + } + private String getStringXML(XMLStreamReader reader) { OMElement omelement = new StAXOMBuilder(reader).getDocumentElement(); return omelement.toString();