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 am...@apache.org on 2007/02/06 12:47:13 UTC

svn commit: r504088 - in /webservices/axis2/trunk/java/modules/adb-codegen: ./ src/org/apache/axis2/schema/template/ src/org/apache/axis2/schema/writer/ test-resources/testsuite/ test/org/apache/axis2/schema/extension/ test/org/apache/axis2/schema/rest...

Author: amilas
Date: Tue Feb  6 03:47:11 2007
New Revision: 504088

URL: http://svn.apache.org/viewvc?view=rev&rev=504088
Log:
fix the test case for restriction to support jdk 1.4
all the static methods move to a seperate factory

Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/maven.xml
    webservices/axis2/trunk/java/modules/adb-codegen/project.xml
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
    webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/restrictions.xsd
    webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/extension/SimpleExtensionTest.java
    webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SimpleRestrictionTest.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/maven.xml?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/maven.xml Tue Feb  6 03:47:11 2007
@@ -199,14 +199,14 @@
         
         <!-- ################################################################### -->
         <!-- All simple derived types xsd -->
-        <!-- <ant:echo>Compiling restrictions.xsd</ant:echo>
+        <ant:echo>Compiling restrictions.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="${testsuite.source.dir}/restrictions.xsd"/>
             <arg file="${schema.generated.src.dir}"/>
-        </java> -->
+        </java> 
 
 
 

Modified: webservices/axis2/trunk/java/modules/adb-codegen/project.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/project.xml?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/project.xml (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/project.xml Tue Feb  6 03:47:11 2007
@@ -152,9 +152,6 @@
         <sourceDirectory>src</sourceDirectory>
         <unitTestSourceDirectory>test</unitTestSourceDirectory>
         <unitTest>
-            <excludes>
-		<exclude>**/*SimpleRestrictionTest.java</exclude>
-	    </excludes>
             <includes>
                 <include>**/*Test.java</include>
             </includes>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl Tue Feb  6 03:47:11 2007
@@ -95,8 +95,9 @@
 
 
         <xsl:for-each select="property">
-            <!-- Write only the NOT inherited properties-->
-            <xsl:if test="not(@inherited) or ($simple and $extension)">
+            <!-- Write only the NOT inherited properties
+            but we have to generate two specital methods for simple type restriction and extenesions -->
+            <xsl:if test="not(@inherited) or ($simple and $extension) or ($simple and $restriction)">
 
             <xsl:variable name="propertyType"><xsl:value-of select="@type"></xsl:value-of></xsl:variable>
             <xsl:variable name="propertyName"><xsl:value-of select="@name"></xsl:value-of></xsl:variable>
@@ -279,44 +280,7 @@
                             </xsl:for-each>
 
                                 public <xsl:value-of select="$propertyType"/> getValue() { return <xsl:value-of select="$varName" />;}
-                                public static <xsl:value-of select="$name"/> fromValue(<xsl:value-of select="$propertyType"/> value)
-                                      throws java.lang.IllegalArgumentException {
-                                    <xsl:value-of select="$name"/> enumeration = (<xsl:value-of select="$name"/>)
-                                <xsl:choose>
-                                           <xsl:when test="@primitive">
-                                             _table_.get(value + "");
-                                           </xsl:when>
-                                           <xsl:otherwise>
-                                               _table_.get(value);
-                                           </xsl:otherwise>
-                                       </xsl:choose>
 
-                                    if (enumeration==null) throw new java.lang.IllegalArgumentException();
-                                    return enumeration;
-                                }
-                                public static <xsl:value-of select="$name"/> fromString(java.lang.String value,java.lang.String namespaceURI)
-                                      throws java.lang.IllegalArgumentException {
-                                    try {
-                                       <xsl:choose>
-                                           <xsl:when test="@primitive">
-                                             return fromValue(org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(value));
-                                           </xsl:when>
-                                           <xsl:otherwise>
-                                               <xsl:choose>
-                                                   <xsl:when test="$propertyType='javax.xml.namespace.QName'">
-                                                       return fromValue(new <xsl:value-of select="$propertyType"/>(namespaceURI,value));
-                                                   </xsl:when>
-                                                   <xsl:otherwise>
-                                                       return fromValue(new <xsl:value-of select="$propertyType"/>(value));
-                                                   </xsl:otherwise>
-                                               </xsl:choose>
-                                           </xsl:otherwise>
-                                       </xsl:choose>
-
-                                    } catch (java.lang.Exception e) {
-                                        throw new java.lang.IllegalArgumentException();
-                                    }
-                                }
                                 public boolean equals(java.lang.Object obj) {return (obj == this);}
                                 public int hashCode() { return toString().hashCode();}
                                 public java.lang.String toString() {
@@ -546,22 +510,6 @@
                          <!-- generate from string and to string methods for
                           simple types to be ued in attribute handling -->
                         <xsl:if test="$simple and not(@attribute) and not(enumFacet)">
-                            public static <xsl:value-of select="$name"/> fromString(String value,
-                                                                java.lang.String namespaceURI){
-                                <xsl:value-of select="$name"/> returnValue = new  <xsl:value-of select="$name"/>();
-                                <xsl:choose>
-                                    <xsl:when test="$propertyType='javax.xml.namespace.QName'">
-                                        returnValue.set<xsl:value-of select="$javaName"/>(
-                                            org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(value,namespaceURI));
-                                    </xsl:when>
-                                    <xsl:otherwise>
-                                        returnValue.set<xsl:value-of select="$javaName"/>(
-                                            org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(value));
-                                    </xsl:otherwise>
-                                </xsl:choose>
-
-                                return returnValue;
-                            }
 
                             public java.lang.String toString(){
                                 <xsl:choose>
@@ -589,7 +537,6 @@
         <xsl:if test="$union and $simple">
             <!-- generate class for a union type -->
 
-
               public void setObject(java.lang.Object object){
                   <xsl:for-each select="memberType">
                       <xsl:if test="position() > 1">} else </xsl:if>
@@ -601,24 +548,6 @@
                       }
               }
 
-              public static <xsl:value-of select="$name"/> fromString(javax.xml.stream.XMLStreamReader xmlStreamReader,
-                                                     java.lang.String namespaceURI,
-                                                     java.lang.String type) {
-
-                    <xsl:value-of select="$name"/> object = null;
-                    try {
-                        if ("http://www.w3.org/2001/XMLSchema".equals(namespaceURI)) {
-                            object = new <xsl:value-of select="$name"/>();
-                            object.setObject(xmlStreamReader, namespaceURI, type);
-                        } else {
-                            object.setObject(<xsl:value-of select="$mapperClass"/>.getTypeObject(namespaceURI, type, xmlStreamReader));
-                        }
-                        return object;
-                    } catch (java.lang.Exception e) {
-                        throw new RuntimeException("Error in parsing value");
-                    }
-                }
-
         </xsl:if>
 
      /**
@@ -1857,6 +1786,97 @@
       */
     public static class Factory{
 
+        <!-- generate some utility factory methods here we must add these methods to a factory class
+         since otherwise it gives a compilation exception in jdk 1.4 -->
+        <xsl:if test="$union and $simple">
+            <!-- generate methods for a union type -->
+              public static <xsl:value-of select="$name"/> fromString(javax.xml.stream.XMLStreamReader xmlStreamReader,
+                                                     java.lang.String namespaceURI,
+                                                     java.lang.String type) {
+
+                    <xsl:value-of select="$name"/> object = null;
+                    try {
+                        if ("http://www.w3.org/2001/XMLSchema".equals(namespaceURI)) {
+                            object = new <xsl:value-of select="$name"/>();
+                            object.setObject(xmlStreamReader, namespaceURI, type);
+                        } else {
+                            object.setObject(<xsl:value-of select="$mapperClass"/>.getTypeObject(namespaceURI, type, xmlStreamReader));
+                        }
+                        return object;
+                    } catch (java.lang.Exception e) {
+                        throw new RuntimeException("Error in parsing value");
+                    }
+               }
+        </xsl:if>
+
+        <xsl:for-each select="property">
+            <xsl:variable name="propertyType"><xsl:value-of select="@type"></xsl:value-of></xsl:variable>
+            <xsl:variable name="javaName"><xsl:value-of select="@javaname"></xsl:value-of></xsl:variable>
+            <xsl:variable name="shortTypeNameUncapped"  select="@shorttypename"/>
+            <xsl:variable name="shortTypeName"
+               select="concat(translate( substring($shortTypeNameUncapped, 1, 1 ),'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ), substring($shortTypeNameUncapped, 2, string-length($shortTypeNameUncapped)))" />
+
+            <xsl:if test="$simple and not(@attribute) and not(enumFacet)">
+                public static <xsl:value-of select="$name"/> fromString(String value,
+                                                    java.lang.String namespaceURI){
+                    <xsl:value-of select="$name"/> returnValue = new  <xsl:value-of select="$name"/>();
+                    <xsl:choose>
+                        <xsl:when test="$propertyType='javax.xml.namespace.QName'">
+                            returnValue.set<xsl:value-of select="$javaName"/>(
+                                org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(value,namespaceURI));
+                        </xsl:when>
+                        <xsl:otherwise>
+                            returnValue.set<xsl:value-of select="$javaName"/>(
+                                org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(value));
+                        </xsl:otherwise>
+                    </xsl:choose>
+
+                    return returnValue;
+                }
+
+            </xsl:if>
+            <xsl:if test="enumFacet">
+                public static <xsl:value-of select="$name"/> fromValue(<xsl:value-of select="$propertyType"/> value)
+                      throws java.lang.IllegalArgumentException {
+                    <xsl:value-of select="$name"/> enumeration = (<xsl:value-of select="$name"/>)
+                <xsl:choose>
+                           <xsl:when test="@primitive">
+                             _table_.get(value + "");
+                           </xsl:when>
+                           <xsl:otherwise>
+                               _table_.get(value);
+                           </xsl:otherwise>
+                       </xsl:choose>
+
+                    if (enumeration==null) throw new java.lang.IllegalArgumentException();
+                    return enumeration;
+                }
+                public static <xsl:value-of select="$name"/> fromString(java.lang.String value,java.lang.String namespaceURI)
+                      throws java.lang.IllegalArgumentException {
+                    try {
+                       <xsl:choose>
+                           <xsl:when test="@primitive">
+                             return fromValue(org.apache.axis2.databinding.utils.ConverterUtil.convertTo<xsl:value-of select="$shortTypeName"/>(value));
+                           </xsl:when>
+                           <xsl:otherwise>
+                               <xsl:choose>
+                                   <xsl:when test="$propertyType='javax.xml.namespace.QName'">
+                                       return fromValue(new <xsl:value-of select="$propertyType"/>(namespaceURI,value));
+                                   </xsl:when>
+                                   <xsl:otherwise>
+                                       return fromValue(new <xsl:value-of select="$propertyType"/>(value));
+                                   </xsl:otherwise>
+                               </xsl:choose>
+                           </xsl:otherwise>
+                       </xsl:choose>
+
+                    } catch (java.lang.Exception e) {
+                        throw new java.lang.IllegalArgumentException();
+                    }
+                }
+            </xsl:if>
+
+        </xsl:for-each>
 
         /**
         * static method to create the object
@@ -1913,7 +1933,7 @@
                     <xsl:choose>
                         <xsl:when test="$union">
                             java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
-                            return <xsl:value-of select="$name"/>.fromString(reader,nsUri,type);
+                            return <xsl:value-of select="$name"/>.Factory.fromString(reader,nsUri,type);
                         </xsl:when>
                         <xsl:otherwise>
                             if (!"<xsl:value-of select="$originalName"/>".equals(type)){
@@ -1985,12 +2005,12 @@
                                                     prefix = <xsl:value-of select="$attribName"/>.substring(0, <xsl:value-of select="$attribName"/>.indexOf(":"));
                                                     namespaceuri = reader.getNamespaceURI(prefix);
                                                     object.set<xsl:value-of select="$javaName"/>(
-                                                        <xsl:value-of select="@type"/>.fromString(<xsl:value-of select="$attribName"/>,namespaceuri));
+                                                        <xsl:value-of select="@type"/>.Factory.fromString(<xsl:value-of select="$attribName"/>,namespaceuri));
                                                 } else {
                                                     // this seems to be not a qname send and empty namespace incase of it is
                                                     // check is done in fromString method
                                                     object.set<xsl:value-of select="$javaName"/>(
-                                                        <xsl:value-of select="@type"/>.fromString(<xsl:value-of select="$attribName"/>,""));
+                                                        <xsl:value-of select="@type"/>.Factory.fromString(<xsl:value-of select="$attribName"/>,""));
                                                 }
                                             </xsl:when>
                                             <xsl:otherwise>
@@ -2618,11 +2638,11 @@
                                             // this seems to be a Qname so find the namespace and send
                                             prefix = content.substring(0, content.indexOf(":"));
                                             namespaceuri = reader.getNamespaceURI(prefix);
-                                            object = <xsl:value-of select="$name"/>.fromString(content,namespaceuri);
+                                            object = <xsl:value-of select="$name"/>.Factory.fromString(content,namespaceuri);
                                         } else {
                                             // this seems to be not a qname send and empty namespace incase of it is
                                             // check is done in fromString method
-                                            object = <xsl:value-of select="$name"/>.fromString(content,"");
+                                            object = <xsl:value-of select="$name"/>.Factory.fromString(content,"");
                                         }
                                         <!-- set the attribute values here since onbject is not initalized yet -->
                                         <xsl:for-each select="../property[@attribute]">

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java Tue Feb  6 03:47:11 2007
@@ -582,8 +582,9 @@
                               Element rootElt, ArrayList propertyNames, Map typeMap,
                               boolean isInherited) throws SchemaCompilationException {
         // we should add parent class details only if it is
-        // an extension
-        if (!metainf.isRestriction() && metainf.getParent() != null) {
+        // an extension or simple restriction
+        // should not in complex restrictions
+        if (metainf.getParent() != null && (!metainf.isRestriction() || (metainf.isRestriction() && metainf.isSimple()))) {
             populateInfo(metainf.getParent(), model, rootElt, propertyNames,
                     typeMap, true);
         }
@@ -621,7 +622,9 @@
             qNames.add(qName[i]);
         }
         //adding missing QNames to the end, including elements & attributes.
-        if (metainf.isRestriction()) {
+        // for the simple types we have already add the parent elements
+        // it is almost consider as an extension
+        if (metainf.isRestriction() && !metainf.isSimple()) {
             addMissingQNames(metainf, qNames, missingQNames);
         }
         QName name;

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/restrictions.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/restrictions.xsd?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/restrictions.xsd (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test-resources/testsuite/restrictions.xsd Tue Feb  6 03:47:11 2007
@@ -16,4 +16,22 @@
         <xsd:attribute name="versionID" type="tns:NormalizedStringType" use="optional"></xsd:attribute>
     </xsd:complexType>
     <xsd:element name="SimpleRestriction" type="tns:BusinessObjectDocumentType"/>
+
+    <!-- complext type restriction -->
+    <xsd:complexType name="BaseRestrictionType">
+        <xsd:sequence>
+            <xsd:element name="baseTypeElement1" minOccurs="0" type="xsd:string"/>
+            <xsd:element name="baseTypeElement2" minOccurs="0" type="xsd:int"/>
+        </xsd:sequence>
+    </xsd:complexType>
+    <xsd:complexType name="ParentRestrictionType">
+        <xsd:complexContent>
+            <xsd:restriction base="tns:BaseRestrictionType">
+                <xsd:sequence>
+                    <xsd:element name="baseTypeElement1" type="xsd:string"/>
+                    <xsd:element name="baseTypeElement2" type="xsd:int"/>
+                </xsd:sequence>
+            </xsd:restriction>
+        </xsd:complexContent>
+    </xsd:complexType>
 </xsd:schema>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/extension/SimpleExtensionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/extension/SimpleExtensionTest.java?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/extension/SimpleExtensionTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/extension/SimpleExtensionTest.java Tue Feb  6 03:47:11 2007
@@ -35,9 +35,9 @@
         fullName.setMiddle("chinthaka");
         fullName.setLast("suriarachchi");
         fullName.setLanguage(new Language("singhala"));
-        fullName.setAttribute1(BaseType.fromString(BaseType._s1,""));
+        fullName.setAttribute1(BaseType.Factory.fromString(BaseType._s1,""));
 
-        fullName.setAttribute2(SimpleType.fromString("ATTRIBUTE",""));
+        fullName.setAttribute2(SimpleType.Factory.fromString("ATTRIBUTE",""));
 
         OMElement omElement = fullName.getOMElement(FullName.MY_QNAME, OMAbstractFactory.getSOAP11Factory());
         try {

Modified: webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SimpleRestrictionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SimpleRestrictionTest.java?view=diff&rev=504088&r1=504087&r2=504088
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SimpleRestrictionTest.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SimpleRestrictionTest.java Tue Feb  6 03:47:11 2007
@@ -16,25 +16,22 @@
 package org.apache.axis2.schema.restriction;
 
 import junit.framework.TestCase;
-/*
-import org.tempuri.SimpleRestriction;
-import org.tempuri.BusinessObjectDocumentType;
-import org.tempuri.NormalizedStringType;
-import org.apache.axis2.databinding.types.NormalizedString;
-import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axis2.databinding.types.NormalizedString;
+import org.tempuri.BusinessObjectDocumentType;
+import org.tempuri.NormalizedStringType;
+import org.tempuri.SimpleRestriction;
 
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayInputStream;
-*/
+
 
 public class SimpleRestrictionTest extends TestCase {
 
-    
     public void testSimpleRestriction() {
-        /*   
+
         SimpleRestriction simpleRestriction = new SimpleRestriction();
         BusinessObjectDocumentType businessObjectDocumentType = new BusinessObjectDocumentType();
         simpleRestriction.setSimpleRestriction(businessObjectDocumentType);
@@ -51,13 +48,13 @@
         try {
             String omElementString = omElement.toStringWithConsume();
             System.out.println("OM Element ==>" + omElement);
-            XMLStreamReader xmlReader =  StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
+            XMLStreamReader xmlReader = StAXUtils.createXMLStreamReader(new ByteArrayInputStream(omElementString.getBytes()));
             SimpleRestriction newSimpleRestriction = SimpleRestriction.Factory.parse(xmlReader);
-            assertEquals(newSimpleRestriction.getSimpleRestriction().getVersionID().toString(),"versionID");
-            assertEquals(newSimpleRestriction.getSimpleRestriction().getReleaseID().toString(),"releaseID");
+            assertEquals(newSimpleRestriction.getSimpleRestriction().getVersionID().toString(), "versionID");
+            assertEquals(newSimpleRestriction.getSimpleRestriction().getReleaseID().toString(), "releaseID");
         } catch (Exception e) {
             assertFalse(true);
-        }*/
+        }
 
 
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org