You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2005/10/18 06:30:37 UTC

svn commit: r326025 - 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: Mon Oct 17 21:30:15 2005
New Revision: 326025

URL: http://svn.apache.org/viewcvs?rev=326025&view=rev
Log:
BookMark : Completed fixing attribute events support with a test case. Namespace support is not there for attributes. It seems bit complex o handle in this instance. Keeping that as a TODO.
Moving on to Array serialization ...

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=326025&r1=326024&r2=326025&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 Mon Oct 17 21:30:15 2005
@@ -36,8 +36,9 @@
     private QName elementQName;
 
     private boolean isHandlingDocumentElement;
+    private boolean isStartDocumentThrown = false;
+    private boolean isEndDocumentThrown = false;
 
-    
 
     // Every parser can contain a reference to a pull parser of one of its children
     private ADBPullParser childPullParser;
@@ -81,37 +82,37 @@
      * @param properties    - this should contain all the stuff that stax events should be generated.
      *                      Lets take an example of a bean.
      *                      <pre> <Person>
-     *                                                                                                                                                                                                                                                                                                           <Name>FooOne</Name>
-     *                                                                                                                                                                                                                                                                                                           <DependentOne>
-     *                                                                                                                                                                                                                                                                                                               <Name>FooTwo</Name>
-     *                                                                                                                                                                                                                                                                                                               <Age>25</Age>
-     *                                                                                                                                                                                                                                                                                                               <Sex>Male</Sex>
-     *                                                                                                                                                                                                                                                                                                           </DependentOne>
-     *                                                                                                                                                                                                                                                                                                       </Person>
+     *                                                                                                                                                                                                                                                                                                                                <Name>FooOne</Name>
+     *                                                                                                                                                                                                                                                                                                                                <DependentOne>
+     *                                                                                                                                                                                                                                                                                                                                    <Name>FooTwo</Name>
+     *                                                                                                                                                                                                                                                                                                                                    <Age>25</Age>
+     *                                                                                                                                                                                                                                                                                                                                    <Sex>Male</Sex>
+     *                                                                                                                                                                                                                                                                                                                                </DependentOne>
+     *                                                                                                                                                                                                                                                                                                                            </Person>
      *                      <p/>
-     *                                                                                                                                                                                                                                                                                                       so the mapping bean for this is
-     *                                                                                                                                                                                                                                                                                                       class Person {
-     *                                                                                                                                                                                                                                                                                                           String Name;
-     *                                                                                                                                                                                                                                                                                                           Dependent dependentOne;
-     *                                                                                                                                                                                                                                                                                                       }
+     *                                                                                                                                                                                                                                                                                                                            so the mapping bean for this is
+     *                                                                                                                                                                                                                                                                                                                            class Person {
+     *                                                                                                                                                                                                                                                                                                                                String Name;
+     *                                                                                                                                                                                                                                                                                                                                Dependent dependentOne;
+     *                                                                                                                                                                                                                                                                                                                            }
      *                      <p/>
-     *                                                                                                                                                                                                                                                                                                       class Dependent {
-     *                                                                                                                                                                                                                                                                                                           String name;
-     *                                                                                                                                                                                                                                                                                                           int age;
-     *                                                                                                                                                                                                                                                                                                           String sex;
-     *                                                                                                                                                                                                                                                                                                       }
+     *                                                                                                                                                                                                                                                                                                                            class Dependent {
+     *                                                                                                                                                                                                                                                                                                                                String name;
+     *                                                                                                                                                                                                                                                                                                                                int age;
+     *                                                                                                                                                                                                                                                                                                                                String sex;
+     *                                                                                                                                                                                                                                                                                                                            }
      *                      <p/>
-     *                                                                                                                                                                                                                                                                                                       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|
-     *                                                                                                                                                                                                                                                                                                       ---------------------------------------------------------------
-     *                                                                                                                                                                                                                                                                                                       Remember "Name" and "FooOne" MUST be strings and DependentOne SHOULD be
-     *                                                                                                                                                                                                                                                                                                       QName.
-     *                                                                                                                                                                                                                                                                                                       This DependentObject can either be an ADBBean 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.
-     *                                                                                                                                                                                                                                                                                   </pre>
+     *                                                                                                                                                                                                                                                                                                                            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|
+     *                                                                                                                                                                                                                                                                                                                            ---------------------------------------------------------------
+     *                                                                                                                                                                                                                                                                                                                            Remember "Name" and "FooOne" MUST be strings and DependentOne SHOULD be
+     *                                                                                                                                                                                                                                                                                                                            QName.
+     *                                                                                                                                                                                                                                                                                                                            This DependentObject can either be an ADBBean 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.
+     *                                                                                                                                                                                                                                                                                                        </pre>
      * @param attributes    - this will contain an array of OMAttributes
      * @return XMLStreamReader
      */
@@ -141,7 +142,19 @@
         // currentIndex is always ahead one step from the location of the array which is currently being processed.
         // so when you check for completeness you have to check for currentIndex >= array length + 2
 
-        if (currentIndex >= properties.length + 2) {
+        if (isHandlingDocumentElement && !isStartDocumentThrown) {
+            isStartDocumentThrown = true;
+            return XMLStreamConstants.START_DOCUMENT;
+        }
+
+        // terminate condition.
+        // if properties are set check we have traversed all of them. If there are no properties, then
+        // check whether we have already thrown the END Element.
+        if ( ( properties != null &&  currentIndex >= properties.length + 2) || (properties == null && isEndElementFinished)) {
+            if (isHandlingDocumentElement && isEndDocumentThrown) {
+                isEndDocumentThrown = true;
+                return XMLStreamConstants.END_DOCUMENT;
+            }
             throw new XMLStreamException("End of elements has already been reached. Can not go beyond that");
         }
 
@@ -165,7 +178,7 @@
             currentIndex++;
             parserInformation = new ParserInformation(this.elementQName);
             return XMLStreamConstants.START_ELEMENT;
-        } else if (properties.length + 1 == currentIndex) {
+        } else if ( properties == null || properties.length + 1 == currentIndex) {
             // this is the end of this element
             currentIndex++;
             isEndElementFinished = true;
@@ -292,7 +305,7 @@
     public String getAttributeNamespace(int i) {
         if (accessingChildPullParser) {
             return childPullParser.getAttributeNamespace(i);
-        } else if (attributes != null && attributes.length >= i) {
+        } else if (attributes != null && attributes.length >= i && attributes[i].getNamespace() != null) {
             return attributes[i].getNamespace().getName();
         }
         return null;
@@ -407,7 +420,8 @@
     }
 
     public String getEncoding() {
-        throw new UnsupportedOperationException("Yet to be implemented !!");
+        // https://stax-utils.dev.java.net/nonav/javadoc/api/javax/xml/stream/XMLStreamReader.html#getEncoding()
+        return null;
     }
 
     public Location getLocation() {
@@ -415,11 +429,13 @@
     }
 
     public String getVersion() {
-        throw new UnsupportedOperationException("Yet to be implemented !!");
+        // https://stax-utils.dev.java.net/nonav/javadoc/api/javax/xml/stream/XMLStreamReader.html#getVersion()
+        return null;
     }
 
     public boolean isStandalone() {
-        throw new UnsupportedOperationException("Yet to be implemented !!");
+        // https://stax-utils.dev.java.net/nonav/javadoc/api/javax/xml/stream/XMLStreamReader.html#isStandalone()
+        return false;
     }
 
     public boolean standaloneSet() {
@@ -427,7 +443,8 @@
     }
 
     public String getCharacterEncodingScheme() {
-        throw new UnsupportedOperationException("Yet to be implemented !!");
+        // https://stax-utils.dev.java.net/nonav/javadoc/api/javax/xml/stream/XMLStreamReader.html#getCharacterEncodingScheme()
+        return null;
     }
 
     public String getPITarget() {

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=326025&r1=326024&r2=326025&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 Mon Oct 17 21:30:15 2005
@@ -2,7 +2,10 @@
 
 import junit.framework.TestCase;
 import org.apache.axis2.databinding.ADBBean;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMAttribute;
 import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -286,23 +289,31 @@
         }
     }
 
-//    public void testAttributes() throws XMLStreamException {
-//        OMFactory factory = OMAbstractFactory.getOMFactory();
-//        QName elementQName = new QName("http://ec.org/software", "Employee", "emp");
+    public void testAttributes() throws XMLStreamException {
+
+        String expectedXML = "<emp:Employee xmlns:emp=\"http://ec.org/software\" Attr2=\"Value 2\" " +
+                "Attr3=\"Value 3\" Attr1=\"Value 1\" Attr5=\"Value 5\" Attr4=\"Value 4\"></emp:Employee>";
+
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        QName elementQName = new QName("http://ec.org/software", "Employee", "emp");
 //        OMNamespace attrNS = factory.createOMNamespace("mailto:whoever@whatever.com", "attr");
-//        OMAttribute[] attribute = new OMAttribute[5];
-//
-//        for (int i = 0; i < 5; i++) {
-//            attribute[i] = factory.createOMAttribute("Attr" + i + 1, attrNS, "Value " + i + 1);
-//        }
-//
-//        String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, attribute));
-//        System.out.println(stringXML);
-//
-//    }
+        OMAttribute[] attribute = new OMAttribute[5];
+
+        for (int i = 0; i < 5; i++) {
+            attribute[i] = factory.createOMAttribute("Attr" + (i + 1), null, "Value " + (i + 1));
+        }
+
+        String stringXML = getStringXML(ADBPullParser.createPullParser(elementQName, null, attribute, true));
+        assertEquals(stringXML, expectedXML);
 
-    private String getStringXML(XMLStreamReader reader) throws XMLStreamException {
+    }
+
+    private String getStringXML(XMLStreamReader reader) {
         OMElement omelement = new StAXOMBuilder(reader).getDocumentElement();
-        return omelement.toStringWithConsume();
+        return omelement.toString();
+    }
+
+    public void testArrays(){
+
     }
 }