axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r397166 - in /webservices/axis2/trunk/java/modules: adb/src/org/apache/axis2/databinding/utils/ codegen/src/org/apache/axis2/schema/template/ codegen/test-resources/xsd/ codegen/test/org/apache/axis2/schema/populate/other/
Date Wed, 26 Apr 2006 10:19:42 GMT
Author: ajith
Date: Wed Apr 26 03:19:32 2006
New Revision: 397166

URL: http://svn.apache.org/viewcvs?rev=397166&view=rev
Log:
Fixing the minoccurs=0 bug for the sequences
1. Updated the reader state machines to handle the skipping of elements
2. Changed the ADBBeanTemplate.xsl to have modified code for the minOccurs=0 case
3. Updated the PopulateMinOccurs0Test.java to have more test methods

Modified:
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple-minoccurs0.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java?rev=397166&r1=397165&r2=397166&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleArrayReaderStateMachine.java
Wed Apr 26 03:19:32 2006
@@ -30,6 +30,9 @@
     private QName elementNameToTest = null;
     private int currentState = INIT_STATE;
     private boolean nillable = false;
+
+    private boolean canbeAbsent = false;
+
     private List list = new ArrayList();
 
     /**
@@ -44,6 +47,14 @@
         nillable = true;
     }
 
+    public boolean isCanbeAbsent() {
+        return canbeAbsent;
+    }
+
+    public void setCanbeAbsent(boolean canbeAbsent) {
+        this.canbeAbsent = canbeAbsent;
+    }
+
     /**
      * Resets the state machine. Once the reset is called
      * the state machine is good enough for a fresh run
@@ -114,7 +125,18 @@
                     if (elementNameToTest.equals(reader.getName())){
                         currentState = START_ELEMENT_FOUND_STATE;
                     }else{
-                        currentState = STARTED_STATE;
+                        //we found a start element that does not have
+                        //the name of the element
+
+                        currentState = canbeAbsent?
+                                     FINISHED_STATE:
+                                     STARTED_STATE;
+                    }
+                }else if (event==XMLStreamConstants.END_ELEMENT){
+                    // an end element is found at the init state
+                    // we should break the process here ?
+                    if (!elementNameToTest.equals(reader.getName())){
+                        currentState = FINISHED_STATE ;
                     }
                 }
                 break;

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java?rev=397166&r1=397165&r2=397166&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/SimpleElementReaderStateMachine.java
Wed Apr 26 03:19:32 2006
@@ -34,6 +34,11 @@
     private boolean nillable = false;
     private String text="";
     private String errorMessage = "";
+    private boolean elementSkipped = false;
+
+    public boolean isElementSkipped() {
+        return elementSkipped;
+    }
 
     /**
      *
@@ -126,6 +131,11 @@
                     }else{
                         currentState = STARTED_STATE;
                     }
+                }else if (event==XMLStreamConstants.END_ELEMENT){
+                    // an end element is found at the init state
+                    // we should break the process here ?
+                    currentState = FINISHED_STATE ;
+                    elementSkipped = true;
                 }
                 break;
 
@@ -168,13 +178,14 @@
                 break;
 
             case END_ELEMENT_FOUND_STATE:
-                 currentState = FINISHED_STATE;
+                currentState = FINISHED_STATE;
                 break;
 
                 //the element was found to be null and this state was forced.
-                //we are sure here that the parser was at the START_ELEMENT_FOUND_STATE before
-                //being forced. Hence we need to advance the parser upto the end element
and
-                //set the state to be end element found
+                //we are sure here that the parser was at the
+                //START_ELEMENT_FOUND_STATE before
+                //being forced. Hence we need to advance the parser upto the
+                // end element and set the state to be end element found
             case NULLED_STATE:
                 while (event!= XMLStreamConstants.END_ELEMENT){
                     event=reader.next();
@@ -189,83 +200,15 @@
                     }else{
                         //we do NOT handle mixed content
                         currentState = ILLEGAL_STATE;
-                        errorMessage = "Mixed Content " +reader.getText();  //todo I18n this
+                        errorMessage = "Mixed Content " +reader.getText();
                     }
                 }else{
                     currentState = ILLEGAL_STATE;
-                    errorMessage = "Current state is " + currentState ;  //todo I18n this
+                    errorMessage = "Current state is " + currentState ;
                 }
                 break;
         }
 
-//        //start_document found at init
-//        if (event==XMLStreamConstants.START_DOCUMENT && currentState==INIT_STATE){
-//            currentState = STARTED_STATE;
-//            //start element found at init
-//        }else  if (event==XMLStreamConstants.START_ELEMENT  && currentState==INIT_STATE){
-//            if (elementNameToTest.equals(reader.getName())){
-//                currentState = START_ELEMENT_FOUND_STATE;
-//            }else{
-//                currentState = STARTED_STATE;
-//            }
-//            //start element found after started
-//        }else if  (event==XMLStreamConstants.START_ELEMENT  && currentState==STARTED_STATE)
{
-//            if (elementNameToTest.equals(reader.getName())){
-//                currentState = START_ELEMENT_FOUND_STATE;
-//            }
-//            //characteres found after start element
-//        }else if (event==XMLStreamConstants.CHARACTERS && currentState==START_ELEMENT_FOUND_STATE){
-//            currentState  = TEXT_FOUND_STATE;
-//
-//            //characters found - if this is a characters event that was in the correct
place then
-//            //it would have been handled already. we need to check whether this is a ignorable
-//            //whitespace and if not push the state machine to a illegal state.
-//        }else if (event==XMLStreamConstants.CHARACTERS){
-//            if (reader.getText().trim().length()==0){
-//                //the text is empty - don't change the state
-//            }else{
-//                //we do NOT handle mixed content
-//                currentState = ILLEGAL_STATE;
-//                errorMessage = "Mixed Content " +reader.getText();  //todo I18n this
-//            }
-//
-//            //End element  found after starting This means we've found an empty element
like <foo/>
-//        }else if (event==XMLStreamConstants.END_ELEMENT && currentState==START_ELEMENT_FOUND_STATE){
-//            //force the text to be empty!
-//            text = "";
-//
-//            if (elementNameToTest.equals(reader.getName())){
-//                currentState = END_ELEMENT_FOUND_STATE;
-//            }else{
-//                currentState = ILLEGAL_STATE;
-//                errorMessage = "Wrong element name " +reader.getName();  //todo I18n this
-//            }
-//
-//            // end element found after characters
-//        } else if (event==XMLStreamConstants.END_ELEMENT && currentState==TEXT_FOUND_STATE){
-//            if (elementNameToTest.equals(reader.getName())){
-//                currentState = END_ELEMENT_FOUND_STATE;
-//            }else{
-//                currentState = ILLEGAL_STATE;
-//                //set the error message
-//                errorMessage = "Wrong element name " +reader.getName();  //todo I18n this
-//            }
-//
-//            //end has been reached
-//        }else if (currentState==END_ELEMENT_FOUND_STATE) {
-//            currentState = FINISHED_STATE;
-//
-//        }else if (currentState==NULLED_STATE){
-//            while (event!= XMLStreamConstants.END_ELEMENT){
-//                event=reader.next();
-//            }
-//            currentState = END_ELEMENT_FOUND_STATE;
-//            //all other combinations are invalid
-//
-//        }else{
-//            currentState = ILLEGAL_STATE;
-//            errorMessage = "Current state is " + currentState ;  //todo I18n this
-//        }
     }
 
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=397166&r1=397165&r2=397166&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
Wed Apr 26 03:19:32 2006
@@ -925,12 +925,13 @@
                                <xsl:otherwise>
                                    <xsl:variable name="arrayVarName">textArray<xsl:value-of
select="position()"/></xsl:variable>
                                    <xsl:if test="position()>1">
-
-                                   // Move to a start element
-                                   event = reader.getEventType();
-                                   while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT)
{
-                                       event = reader.next();
-                                   }
+                                     <xsl:if test="$min!=0">
+                                       // Move to a start element
+                                       event = reader.getEventType();
+                                       while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT)
{
+                                           event = reader.next();
+                                       }
+                                      </xsl:if>
                                    </xsl:if>
                                   <!-- Start of Array handling of simple types -->
                                    org.apache.axis2.databinding.utils.SimpleArrayReaderStateMachine
<xsl:value-of select="$stateMachineName"/> = new
@@ -941,6 +942,9 @@
                                    <xsl:if test="@nillable">
                                       <xsl:value-of select="$stateMachineName"/>.setNillable();
                                    </xsl:if>
+                                     <xsl:if test="$min=0">
+                                      <xsl:value-of select="$stateMachineName"/>.setCanbeAbsent(true);
+                                   </xsl:if>
                                    <xsl:value-of select="$stateMachineName"/>.read(reader);
                                    java.lang.String[] <xsl:value-of select="$arrayVarName"/>
=
                                                 <xsl:value-of select="$stateMachineName"/>.getTextArray();
@@ -1021,11 +1025,13 @@
                      <!-- start of the simple types handling -->
                      <xsl:otherwise>
                          <xsl:if test="position()>1">
-                             // Move to a start element
-                             event = reader.getEventType();
-                             while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT)
{
-                               event = reader.next();
-                             }
+                             <xsl:if test="$min!=0">
+                                       // Move to a start element
+                                       event = reader.getEventType();
+                                       while (event!= javax.xml.stream.XMLStreamReader.START_ELEMENT)
{
+                                           event = reader.next();
+                                       }
+                              </xsl:if>
                          </xsl:if>
                        org.apache.axis2.databinding.utils.SimpleElementReaderStateMachine
<xsl:value-of select="$stateMachineName"/>
                          = new org.apache.axis2.databinding.utils.SimpleElementReaderStateMachine();
@@ -1037,18 +1043,39 @@
                                <xsl:value-of select="$stateMachineName"/>.setNillable();
                        </xsl:if>
                        <xsl:value-of select="$stateMachineName"/>.read(reader);
-                       object.set<xsl:value-of select="$javaName"/>(
-                         <xsl:choose>
-                             <xsl:when test="@nillable and not(@primitive)">
-                                  <xsl:value-of select="$stateMachineName"/>.getText()==null?null:
-                                    org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of
select="$shortTypeName"/>(
-                                  <xsl:value-of select="$stateMachineName"/>.getText()));
-                             </xsl:when>
-                             <xsl:otherwise>
-                            org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of
select="$shortTypeName"/>(
-                                  <xsl:value-of select="$stateMachineName"/>.getText()));
-                             </xsl:otherwise>
-                         </xsl:choose>
+                       <xsl:choose>
+                           <xsl:when test="$min=0">
+                               if (!<xsl:value-of select="$stateMachineName"/>.isElementSkipped()){
+                                 object.set<xsl:value-of select="$javaName"/>(
+                                   <xsl:choose>
+                                   <xsl:when test="@nillable and not(@primitive)">
+                                       <xsl:value-of select="$stateMachineName"/>.getText()==null?null:
+                                       org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of
select="$shortTypeName"/>(
+                                       <xsl:value-of select="$stateMachineName"/>.getText()));
+                                   </xsl:when>
+                                   <xsl:otherwise>
+                                       org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of
select="$shortTypeName"/>(
+                                       <xsl:value-of select="$stateMachineName"/>.getText()));
+                                   </xsl:otherwise>
+                                 </xsl:choose>
+                             }
+                           </xsl:when>
+                           <xsl:otherwise>
+                             object.set<xsl:value-of select="$javaName"/>(
+                               <xsl:choose>
+                                   <xsl:when test="@nillable and not(@primitive)">
+                                       <xsl:value-of select="$stateMachineName"/>.getText()==null?null:
+                                       org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of
select="$shortTypeName"/>(
+                                       <xsl:value-of select="$stateMachineName"/>.getText()));
+                                   </xsl:when>
+                                   <xsl:otherwise>
+                                       org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of
select="$shortTypeName"/>(
+                                       <xsl:value-of select="$stateMachineName"/>.getText()));
+                                   </xsl:otherwise>
+                               </xsl:choose>
+                           </xsl:otherwise>
+                       </xsl:choose>
+
 
                      </xsl:otherwise>
                       <!-- end of simple type handling -->

Modified: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple-minoccurs0.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple-minoccurs0.xsd?rev=397166&r1=397165&r2=397166&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple-minoccurs0.xsd
(original)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/simple-minoccurs0.xsd
Wed Apr 26 03:19:32 2006
@@ -6,6 +6,7 @@
 				<xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
 				<xs:element name="B" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
 				<xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+				<xs:element name="D" type="xs:string" minOccurs="0" maxOccurs="1"/>
 			</xs:sequence>
 		</xs:complexType>
 	</xs:element>

Modified: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java?rev=397166&r1=397165&r2=397166&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateMinOccurs0Test.java
Wed Apr 26 03:19:32 2006
@@ -31,44 +31,68 @@
 
 public class PopulateMinOccurs0Test extends TestCase {
 
+    /*
+     <xs:element name="A" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
+	 <xs:element name="B" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+	 <xs:element name="C" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
+	 <xs:element name="D" type="xs:string" minOccurs="0" maxOccurs="1"/>
+   */
+
+    // element D is missing
     private String xmlString1 = "<root xmlns=\"http://test.org\">" +
             "<A>I am A</A>" +
             "<B>I am B1</B>" +
             "<B>I am B2</B>" +
-            "<C>I am B2</C>" +
-            "<C>I am B2</C>" +
+            "<C>I am C1</C>" +
+            "<C>I am C2</C>" +
             "</root>";
 
+    //B elements are missing
     private String xmlString2 = "<root xmlns=\"http://test.org\">" +
             "<A>I am A</A>" +
             "<C>I am B2</C>" +
             "<C>I am B2</C>" +
+            "<D>I am D1</D>" +
+            "</root>";
+
+    //Only A is present
+    private String xmlString3 = "<root xmlns=\"http://test.org\">" +
+            "<A>I am A</A>" +
             "</root>";
 
-    public void testPopulate1() throws Exception{
-        populateAndAssert(xmlString1,2);
+
+    public void testPopulate1() throws Exception {
+        populateAndAssert(xmlString1, 2, "b");
+        populateAndAssert(xmlString1, 2, "c");
+    }
+
+    public void testPopulate2() throws Exception {
+        populateAndAssert(xmlString2, 0, "b");
+        populateAndAssert(xmlString2, 2, "c");
     }
 
-     public void testPopulate2() throws Exception{
-         populateAndAssert(xmlString2,0);
+    public void testPopulate3() throws Exception {
+        populateAndAssert(xmlString3, 0, "b");
+        populateAndAssert(xmlString3, 1, "a");
     }
 
-    private void populateAndAssert(String s,int expectedCount) throws XMLStreamException,
ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException,
IntrospectionException {
+    private void populateAndAssert(String s, int expectedCount, String itemtoTest) throws
XMLStreamException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException, IntrospectionException {
         XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(s.getBytes()));
         Class clazz = Class.forName("org.test.Root");
         Class innerClazz = clazz.getDeclaredClasses()[0];
-        Method parseMethod = innerClazz.getMethod("parse",new Class[]{XMLStreamReader.class});
-        Object obj = parseMethod.invoke(null,new Object[]{reader});
+        Method parseMethod = innerClazz.getMethod("parse", new Class[]{XMLStreamReader.class});
+        Object obj = parseMethod.invoke(null, new Object[]{reader});
 
         assertNotNull(obj);
 
         Object stringArray = null;
-        BeanInfo beanInfo =  Introspector.getBeanInfo(obj.getClass());
+        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
         PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
         Method readMethod;
+
         for (int i = 0; i < propertyDescriptors.length; i++) {
             PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
-            if ("b".equals(propertyDescriptor.getDisplayName())){
+            if (itemtoTest.equals(propertyDescriptor.getDisplayName())) {
                 readMethod = propertyDescriptor.getReadMethod();
                 stringArray = readMethod.invoke(obj, null);
                 break;
@@ -76,10 +100,9 @@
         }
 
         assertNotNull(stringArray);
-        String[] array = (String[])stringArray;
-        assertEquals(array.length,expectedCount);
+        String[] array = (String[]) stringArray;
+        assertEquals(array.length, expectedCount);
     }
-
 
 
 }



Mime
View raw message