axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r397428 - in /webservices/axis2/trunk/java/modules: codegen/ codegen/src/org/apache/axis2/schema/template/ codegen/test-resources/xsd/ codegen/test/org/apache/axis2/schema/populate/other/ xmlbeans/src/org/apache/axis2/xmlbeans/
Date Thu, 27 Apr 2006 05:56:02 GMT
Author: ajith
Date: Wed Apr 26 22:56:01 2006
New Revision: 397428

URL: http://svn.apache.org/viewcvs?rev=397428&view=rev
Log:
1. Fixed the minoccurs=0 issue for complex data types
2. Added a new test case that tests the issue

Added:
    webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/complex-minoccurs0.xsd
    webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/maven.xml
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java

Modified: webservices/axis2/trunk/java/modules/codegen/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/maven.xml?rev=397428&r1=397427&r2=397428&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/codegen/maven.xml Wed Apr 26 22:56:01 2006
@@ -101,6 +101,16 @@
             <arg file="${schema.generated.src.dir}"/>
         </java>
 
+          <!-- complex min occurs 0 xsd -->
+        <ant:echo>Compiling complex-minoccurs0.xsd</ant:echo>
+        <java classname="org.apache.axis2.schema.XSD2Java" fork="true">
+            <jvmarg line="${maven.junit.jvmargs}"/>
+            <classpath refid="maven.dependency.classpath"/>
+            <classpath location="${compiled.classes.dir}"/>
+            <arg file="${schema.source.dir}/complex-minoccurs0.xsd"/>
+            <arg file="${schema.generated.src.dir}"/>
+        </java>
+
         <!-- ################################################################### -->
         <!-- All simple primitive types xsd -->
         <java classname="org.apache.axis2.schema.XSD2Java" fork="true">

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=397428&r1=397427&r2=397428&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 22:56:01 2006
@@ -777,6 +777,7 @@
                    <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
                    <xsl:variable name="listName">list<xsl:value-of select="position()"/></xsl:variable>
                    <xsl:variable name="loopBoolName">loopDone<xsl:value-of select="position()"/></xsl:variable>
+                   <xsl:variable name="skipBoolName">skip<xsl:value-of select="position()"/></xsl:variable>
                    <xsl:variable name="startQname">startQname<xsl:value-of select="position()"/></xsl:variable>
                    <xsl:variable name="stateMachineName">stateMachine<xsl:value-of
select="position()"/></xsl:variable>
                    <xsl:variable name="builderName">builder<xsl:value-of select="position()"/></xsl:variable>
@@ -795,6 +796,8 @@
                                     java.util.ArrayList <xsl:value-of select="$listName"/>
= new java.util.ArrayList();
                                    <!-- Start of Array handling of ADB classes -->
                                     boolean <xsl:value-of select="$loopBoolName"/>=false;
+                                    boolean <xsl:value-of select="$skipBoolName"/>=false;
+
                                     javax.xml.namespace.QName <xsl:value-of select="$startQname"/>
= new javax.xml.namespace.QName(
                                            "<xsl:value-of select="$namespace"/>",
                                            "<xsl:value-of select="$propertyName"/>");
@@ -816,6 +819,7 @@
                                                         (<xsl:value-of select="$propertyType"/>)
                                                         org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
                                                         <xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of
select="$listName"/>));
+                                                <xsl:value-of select="$skipBoolName"/>=true;
                                                 break;
 
                                             </xsl:if>
@@ -827,6 +831,7 @@
 
                                        //Now loop and populate the array
                                        <xsl:value-of select="$loopBoolName"/> = false;
+                                       if (!<xsl:value-of select="$skipBoolName"/>){
                                        while (!<xsl:value-of select="$loopBoolName"/>){
                                            event = reader.getEventType();
                                            if (javax.xml.stream.XMLStreamConstants.START_ELEMENT
== event
@@ -858,6 +863,8 @@
                                       org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
                                       <xsl:value-of select="$basePropertyType"/>.class,<xsl:value-of
select="$listName"/>));
 
+                                   } //end of skip
+
                                    //move to the next event, probably past the last end_element
event
                                    if (reader.getEventType()== javax.xml.stream.XMLStreamConstants.END_ELEMENT){
                                       reader.next();
@@ -960,11 +967,26 @@
 
                     <!-- start of adb handling-->
                      <xsl:when test="@ours">
-
+                         <xsl:if test="$min=0">
+                           if (new javax.xml.namespace.QName(
+                                   "<xsl:value-of select="$namespace"/>",
+                                   "<xsl:value-of select="$propertyName"/>").equals(
+                             reader.getName())){
+                         </xsl:if>
                          object.set<xsl:value-of select="$javaName"/>(
                          <xsl:value-of select="$propertyType"/>.Factory.parse(reader));
-
-
+                         <xsl:if test="$min=0">
+                          }
+                         </xsl:if>
+
+                          //go one more step if the parser is resting at the end element

+                          if (reader.getEventType()==javax.xml.stream.XMLStreamConstants.END_ELEMENT
+                            &amp;&amp; new javax.xml.namespace.QName(
+                                    "<xsl:value-of select="$namespace"/>",
+                                   "<xsl:value-of select="$propertyName"/>").
+                            equals(reader.getName())){
+                            reader.next();
+                        }
                      </xsl:when>
 
                      <!-- start of any handling. Any can also be @default so we need to

Added: webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/complex-minoccurs0.xsd
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/complex-minoccurs0.xsd?rev=397428&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/complex-minoccurs0.xsd
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test-resources/xsd/complex-minoccurs0.xsd
Wed Apr 26 22:56:01 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           elementFormDefault="qualified"
+           attributeFormDefault="unqualified"
+           targetNamespace="http://test1.org"
+           xmlns:tns="http://test1.org">
+	<xs:element name="root">
+		<xs:complexType>
+			<xs:sequence>
+				<xs:element name="city" type="xs:string"/>
+				<xs:element name="person" type="tns:personType" minOccurs="0"/>
+				<xs:element name="address" type="tns:addressType" minOccurs="0" maxOccurs="unbounded"/>
+			</xs:sequence>
+		</xs:complexType>
+	</xs:element>
+    <xs:complexType name="personType">
+        <xs:sequence>
+            <xs:element name="name" type="xs:string"/>
+            <xs:element name="age" type="xs:int"/>
+        </xs:sequence>
+    </xs:complexType>
+    <xs:complexType name="addressType">
+        <xs:sequence>
+            <xs:element name="streetName" type="xs:string"/>
+            <xs:element name="streetNo" type="xs:int"/>
+        </xs:sequence>
+    </xs:complexType>
+</xs:schema>

Added: webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java?rev=397428&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/test/org/apache/axis2/schema/populate/other/PopulateComplexMinOccurs0Test.java
Wed Apr 26 22:56:01 2006
@@ -0,0 +1,136 @@
+package org.apache.axis2.schema.populate.other;
+
+import junit.framework.TestCase;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import java.beans.IntrospectionException;
+import java.beans.BeanInfo;
+import java.beans.PropertyDescriptor;
+import java.beans.Introspector;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.io.ByteArrayInputStream;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class PopulateComplexMinOccurs0Test  extends TestCase {
+
+
+
+    // all are present
+    private String xmlString1 = "<root xmlns=\"http://test1.org\">" +
+            "<city>Colombo</city>" +
+            "<person>" +
+            "<name>Amy</name>" +
+            "<age>10</age>" +
+            "</person>" +
+            "<address>" +
+            "<streetName>My Street</streetName>" +
+            "<streetNo>1</streetNo>" +
+            "</address>" +
+            "</root>";
+
+
+
+    //person element is missing
+    private String xmlString2 = "<root xmlns=\"http://test1.org\">" +
+            "<city>Colombo</city>" +
+            "<address>" +
+            "<streetName>My Street</streetName>" +
+            "<streetNo>1</streetNo>" +
+            "</address>" +
+            "</root>";
+
+    //Only city is present
+    private String xmlString3 = "<root xmlns=\"http://test1.org\">" +
+            "<city>Colombo</city>" +
+            "</root>";
+
+
+    // all are present with two addresses
+    private String xmlString4 = "<root xmlns=\"http://test1.org\">" +
+            "<city>Colombo</city>" +
+            "<person>" +
+            "<name>Amy</name>" +
+            "<age>10</age>" +
+            "</person>" +
+            "<address>" +
+            "<streetName>My Street</streetName>" +
+            "<streetNo>1</streetNo>" +
+            "</address>" +
+            "<address>" +
+            "<streetName>My Street2</streetName>" +
+            "<streetNo>2</streetNo>" +
+            "</address>" +
+            "</root>";
+    public void testPopulate1() throws Exception {
+        populateAndAssert(xmlString1, 1, true);
+    }
+
+    public void testPopulate2() throws Exception {
+        populateAndAssert(xmlString2, 1, false);
+    }
+
+    public void testPopulate3() throws Exception {
+        populateAndAssert(xmlString3, 0, false);
+    }
+
+    public void testPopulate4() throws Exception {
+        populateAndAssert(xmlString4, 2, true);
+    }
+
+    private void populateAndAssert(String s,
+                                   int expectedAddressCount,
+                                   boolean personPresent) throws XMLStreamException, ClassNotFoundException,
NoSuchMethodException, IllegalAccessException, InvocationTargetException, IntrospectionException
{
+        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(s.getBytes()));
+        Class clazz = Class.forName("org.test1.Root");
+        Class innerClazz = clazz.getDeclaredClasses()[0];
+        Method parseMethod = innerClazz.getMethod("parse", new Class[]{XMLStreamReader.class});
+        Object obj = parseMethod.invoke(null, new Object[]{reader});
+
+        assertNotNull(obj);
+
+        Object personObject = null;
+        Object addressObject = null;
+        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 ("person".equals(propertyDescriptor.getDisplayName())) {
+                readMethod = propertyDescriptor.getReadMethod();
+                personObject = readMethod.invoke(obj, null);
+
+                if (personPresent)
+                    assertNotNull(personObject);
+                else
+                    assertNull(personObject);
+            }else if ("address".equals(propertyDescriptor.getDisplayName())) {
+                readMethod = propertyDescriptor.getReadMethod();
+                addressObject = readMethod.invoke(obj, null);
+
+                Object[] objArray = (Object[])addressObject;
+                assertEquals(expectedAddressCount,objArray.length);
+            }
+        }
+
+
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java?rev=397428&r1=397427&r2=397428&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
(original)
+++ webservices/axis2/trunk/java/modules/xmlbeans/src/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
Wed Apr 26 22:56:01 2006
@@ -62,6 +62,8 @@
 
 import javax.xml.namespace.QName;
 
+import com.ibm.wsdl.util.xml.DOM2Writer;
+
 /**
  * Framework-linked code used by XMLBeans data binding support. This is accessed
  * via reflection from the XMLBeans code generation extension when XMLBeans data
@@ -108,7 +110,7 @@
             JavaTypeMapper mapper = new JavaTypeMapper();
             Map nameSpacesMap = cgconfig.getAxisService().getNameSpacesMap();
 
-            //process all the schemas and make a list of all of them for
+            // process all the schemas and make a list of all of them for
             // resolving entities
             for (int i = 0; i < schemas.size(); i++) {
                 XmlSchema schema = (XmlSchema) schemas.get(i);



Mime
View raw message