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/26 10:02:30 UTC

svn commit: r328584 - 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: Wed Oct 26 01:02:11 2005
New Revision: 328584

URL: http://svn.apache.org/viewcvs?rev=328584&view=rev
Log:
Adding one more way of sending out events.
If element, which we get the pull parser. has some text, now the ADBPullParser will generate events for that too. In the property list you need to pass {ADBPullParser.ELEMENT_TEXT, your element text}. The constant is such that it can never come as a name for an XML element (the current constant has two words with a space in the middle).

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=328584&r1=328583&r2=328584&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 Wed Oct 26 01:02:11 2005
@@ -34,6 +34,11 @@
 
 public class ADBPullParser implements XMLStreamReader {
 
+    // this will help to handle Text within the current element.
+    // user should pass the element text to the property list as this ELEMENT_TEXT as the key
+    public static final String ELEMENT_TEXT = "Element Text";
+    private boolean processingElementText = false;
+
     private Object[] properties;
     private Object[] attributes;
     private QName elementQName;
@@ -56,7 +61,7 @@
     private boolean processingADBNameValuePair = false;
     private boolean nameValuePairStartElementProcessed = false;
     private boolean nameValuePairTextProcessed = false;
-    private boolean nameValuePairEndElementProcessed = false;
+    private boolean finishedProcessingNameValuePair = false;
     private ParserInformation tempParserInfo;
     // ==============================================
 
@@ -218,7 +223,7 @@
         }
 
         // now check whether we are processing a complex string array or not
-        if (processingComplexADBNameValuePair && nameValuePairEndElementProcessed) {
+        if (processingComplexADBNameValuePair && finishedProcessingNameValuePair) {
             // this means we are done with processing one complex string array entry
             // check we have more
             if (complexStringArray.length > ++secondArrayIndex) {
@@ -232,7 +237,7 @@
         }
 
         // check whether we are done with processing a name value pair from an earlier cycle
-        if (processingADBNameValuePair && nameValuePairEndElementProcessed) {
+        if (processingADBNameValuePair && finishedProcessingNameValuePair) {
             processingADBNameValuePair = false;
             currentIndex = currentIndex + 2;
             parserInformation = tempParserInfo;
@@ -291,6 +296,10 @@
 
                 } else if (property instanceof String) {
                     String simplePropertyValue = (String) properties[currentIndex];
+                    if(ELEMENT_TEXT.equals(simplePropertyName)){
+                        // this is element text.
+                        processingElementText = true;
+                    }
                     processingADBNameValuePair = true;
                     return processADBNameValuePair(simplePropertyName, simplePropertyValue);
                 }
@@ -668,18 +677,22 @@
 
     private int processADBNameValuePair(String simplePropertyName, String simplePropertyValue) {
         int event = 0;
-        if (!nameValuePairStartElementProcessed) {
+        if(processingElementText){
+            this.parserInformation.setText(simplePropertyValue);
+            finishedProcessingNameValuePair = true;
+            event = XMLStreamConstants.CHARACTERS;
+        } else if (!nameValuePairStartElementProcessed) {
             event = XMLStreamConstants.START_ELEMENT;
             tempParserInfo = parserInformation;
             parserInformation = new ParserInformation(new QName(simplePropertyName), simplePropertyValue);
             nameValuePairStartElementProcessed = true;
-            nameValuePairEndElementProcessed = false;
+            finishedProcessingNameValuePair = false;
         } else if (nameValuePairStartElementProcessed && !nameValuePairTextProcessed) {
             event = XMLStreamConstants.CHARACTERS;
             nameValuePairTextProcessed = true;
         } else if (nameValuePairTextProcessed) {
             event = XMLStreamConstants.END_ELEMENT;
-            nameValuePairEndElementProcessed = true;
+            finishedProcessingNameValuePair = true;
             nameValuePairStartElementProcessed = false;
             nameValuePairTextProcessed = false;
         }

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=328584&r1=328583&r2=328584&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 Wed Oct 26 01:02:11 2005
@@ -352,16 +352,16 @@
         XMLStreamReader pullParser = ADBPullParser.createPullParser(new QName("OMElementTest"), propertyList.toArray(), null);
         String stringXML = getStringXML(pullParser);
         try {
-           Document actualDom = newDocument(stringXML);
-           Document expectedDocument = newDocument(expectedXML);
-           assertXMLEqual(actualDom, expectedDocument);
-       } catch (ParserConfigurationException e) {
-           fail("Exception in parsing documents " + e);
-       } catch (SAXException e) {
-           fail("Exception in parsing documents " + e);
-       } catch (IOException e) {
-           fail("Exception in parsing documents " + e);
-       }
+            Document actualDom = newDocument(stringXML);
+            Document expectedDocument = newDocument(expectedXML);
+            assertXMLEqual(actualDom, expectedDocument);
+        } catch (ParserConfigurationException e) {
+            fail("Exception in parsing documents " + e);
+        } catch (SAXException e) {
+            fail("Exception in parsing documents " + e);
+        } catch (IOException e) {
+            fail("Exception in parsing documents " + e);
+        }
 
     }
 
@@ -524,6 +524,29 @@
         }
     }
 
+    public void testElementText() {
+
+        String expectedXML = "<ns1:testElementText xmlns:ns1=\"http://testElementText.org\">" +
+                "This is some Text for the element</ns1:testElementText>";
+        try {
+            ArrayList properties = new ArrayList();
+            properties.add(ADBPullParser.ELEMENT_TEXT);
+            properties.add("This is some Text for the element");
+
+            XMLStreamReader pullParser = ADBPullParser.createPullParser(new QName("http://testElementText.org", "testElementText", "ns1"), properties.toArray(), null);
+
+            String actualXML = getStringXML(pullParser);
+
+            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);
+        }
+    }
+
     public void testComplexScenarioOne() {
         /*
            <apache:Project xmlns:axis2="http://ws.apache.org/namespaces/axis2" xmlns:apache="http://www.apache.org/" xmlns:myAttr="mailto:myAttributes@axis2.org" myAttr:name="Apache Axis2">
@@ -611,17 +634,17 @@
         propertyList.add("CurrentRelease");
         propertyList.add("0.92");
 
-        Dependencies xmlModuleDeps = new Dependencies(new String[] {"stax-api.jar", "stax-impl.jar"});
-        Module xmlModule = new Module("xml", "This is the XML object model for Axis2", xmlModuleDeps );
+        Dependencies xmlModuleDeps = new Dependencies(new String[]{"stax-api.jar", "stax-impl.jar"});
+        Module xmlModule = new Module("xml", "This is the XML object model for Axis2", xmlModuleDeps);
         propertyList.add(new QName("http://ws.apache.org/namespaces/axis2", "Module", "axis2"));
         propertyList.add(xmlModule);
 
-        Dependencies coreModuleDeps = new Dependencies(new String[] {"axis2-xml.jar", "axis2-wsdl.jar", "commons-logging.jar"});
-        Module coreModule = new Module("core", "This will handle the main logics of the system", coreModuleDeps );
+        Dependencies coreModuleDeps = new Dependencies(new String[]{"axis2-xml.jar", "axis2-wsdl.jar", "commons-logging.jar"});
+        Module coreModule = new Module("core", "This will handle the main logics of the system", coreModuleDeps);
         propertyList.add(new QName("http://ws.apache.org/namespaces/axis2", "Module", "axis2"));
         propertyList.add(coreModule);
 
-        Object[]  attributes = new Object[]{ new QName("mailto:myAttributes@axis2.org", "name", "myAttr"), "Apache Axis2"};
+        Object[]  attributes = new Object[]{new QName("mailto:myAttributes@axis2.org", "name", "myAttr"), "Apache Axis2"};
 
         XMLStreamReader pullParser = ADBPullParser.createPullParser(new QName("http://www.apache.org/", "Project", "apache"), propertyList.toArray(), attributes);
 //        System.out.println(getStringXML(pullParser));