axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/deployment/wsdd WSDDTypeMapping.java
Date Mon, 01 Aug 2005 18:23:29 GMT
dims        2005/08/01 11:23:29

  Modified:    java/src/org/apache/axis/encoding/ser ArraySerializer.java
                        BeanSerializer.java
               java/src/org/apache/axis/wsdl/toJava
                        JavaBeanHelperWriter.java JavaStubWriter.java
               java/src/org/apache/axis/utils JavaUtils.java
               java/src/org/apache/axis/encoding SerializationContext.java
                        TypeMappingImpl.java
               java/src/org/apache/axis/deployment/wsdd
                        WSDDTypeMapping.java
  Added:       java/test/wsdl/axis2098 build.xml deploy.wsdd
                        helloworld.wsdl helloworld.xsd
                        MyServiceTestCase.java MySOAPBindingImpl.java
                        TestHandler.java undeploy.wsdd
  Log:
  Fix and test case for AXIS-2098, AXIS-2103
  - WSDDTypeMapping : Register exact type mapping for primtive type at the server-side. (primitive
type instead of primitive wrapper)
  - JavaStubWriter : Register exact type mapping for schema derived types in the client side.
  - Serialization : Pass the java class to the SerializationContext to determine actual java
type for serialization
  - TypeMappingImpl : find serializer using xml type. (for schema derived types)
  - JavaBeanHelperWriter : write exact type qname for schema ref'ed element. (AXIS-2103)
  
  from Jongjin Choi
  
  Revision  Changes    Path
  1.74      +3 -3      ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java
  
  Index: ArraySerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/ArraySerializer.java,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- ArraySerializer.java	8 Jun 2005 12:54:42 -0000	1.73
  +++ ArraySerializer.java	1 Aug 2005 18:23:28 -0000	1.74
  @@ -415,7 +415,7 @@
                               (serializeAttr == null ?
                               serializeAttr : new AttributesImpl(serializeAttr)),
                               aValue,
  -                            componentTypeQName); // prefered type QName
  +                            componentTypeQName, componentClass); // prefered type QName
                   }
               } else {
                   for (Iterator iterator = list.iterator(); iterator.hasNext();) {
  @@ -426,7 +426,7 @@
                               (serializeAttr == null ?
                               serializeAttr : new AttributesImpl(serializeAttr)),
                               aValue,
  -                            componentTypeQName); // prefered type QName
  +                            componentTypeQName, componentClass); // prefered type QName
                   }
               }
           } else {
  @@ -434,7 +434,7 @@
               for (int index = 0; index < len; index++) {
                   for (int index2 = 0; index2 < dim2Len; index2++) {
                       Object aValue = Array.get(Array.get(value, index), index2);
  -                    context.serialize(elementName, null, aValue, componentTypeQName);
  +                    context.serialize(elementName, null, aValue, componentTypeQName, componentClass);
                   }
               }
           }
  
  
  
  1.90      +7 -4      ws-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
  
  Index: BeanSerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
  retrieving revision 1.89
  retrieving revision 1.90
  diff -u -r1.89 -r1.90
  --- BeanSerializer.java	21 Jul 2005 03:08:40 -0000	1.89
  +++ BeanSerializer.java	1 Aug 2005 18:23:28 -0000	1.90
  @@ -230,7 +230,7 @@
                           context.serialize(qname,
                                             null,
                                             propValue,
  -                                          xmlType);
  +                                          xmlType, javaType);
                       } else {
                           // Collection of properties: serialize each one
                           int j=0;
  @@ -245,7 +245,7 @@
                               }
                               if (j >= 0) {
                                   context.serialize(qname, null,
  -                                                  propValue, xmlType);
  +                                                  propValue, xmlType, propertyDescriptor[i].getType());
                               }
                           }
                       }
  @@ -608,6 +608,7 @@
                           setAttributeProperty(propValue,
                                                qname,
                                                field.getXmlType(), 
  +                                             field.getJavaType(),
                                                attrs,
                                                context);
                       }
  @@ -623,7 +624,9 @@
   
       private void setAttributeProperty(Object propValue,
                                         QName qname,
  -                                      QName xmlType, AttributesImpl attrs,
  +                                      QName xmlType,
  +                                      Class javaType,
  +                                      AttributesImpl attrs,
                                         SerializationContext context) throws Exception {
   
           String namespace = qname.getNamespaceURI();
  @@ -638,7 +641,7 @@
               return;
           }
   
  -        String propString = context.getValueAsString(propValue, xmlType);
  +        String propString = context.getValueAsString(propValue, xmlType, javaType);
   
           attrs.addAttribute(namespace,
                              localName,
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM "file:../../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
  
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
          ant compile
     To execute
          ant run
  
  Author:
    Matt Seibert mseibert@us.ibm.com
  
  Copyright:
    Copyright (c) 2002-2003 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  
  <property name="axis.home" location="../../.." />
  <property name="componentName" value="test/wsdl/axis2098" />
          &properties;
          &paths;
          &taskdefs;
          &taskdefs_post_compile;
          &targets;
  
  <target name="clean">
      <echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}"
/>
      <delete dir="${build.dir}/classes/${componentName}"/>
      <delete dir="${build.dir}/work/${componentName}"/>
  </target>
  
  <target name="copy" depends="setenv"/>
  
  <target name="compile" depends="copy">
    <echo message="Compiling test.wsdl.axis2098"/>
      <!-- This tests element qualification.  -->
      <wsdl2java url="${axis.home}/test/wsdl/axis2098/helloworld.wsdl"
                 output="${axis.home}/build/work"
  			   serverSide="no"
  			   testcase="no"
  			   all="true">
          <mapping namespace="http://helloworld.ch/schema/service" package="test.wsdl.axis2098"/>
          <mapping namespace="http://helloworld.ch/schema/types" package="test.wsdl.axis2098"/>
      </wsdl2java>
  
      <copy todir="${build.dir}/work/test/wsdl/axis2098" overwrite="yes">
        <fileset dir="${axis.home}/test/wsdl/axis2098">
          <include name="*TestCase.java"/>
          <include name="*Impl.java"/>
          <include name="*Handler.java"/>
  		<include name="*.wsdd"/> 
        </fileset>
      </copy>
  
      <javac srcdir="${build.dir}/work" destdir="${build.dest}" nowarn="${nowarn}" source="${source}"
fork="${javac.fork}"
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="test/wsdl/axis2098/*.java" />
      </javac>
  
  </target>
  
  <target name="run" >
    <antcall target="execute-Component" />
  </target>
  
  </project>
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/deploy.wsdd
  
  Index: deploy.wsdd
  ===================================================================
  <!-- Use this file to deploy some handlers/chains and services      -->
  <!-- Two ways to do this:                                           -->
  <!--   java org.apache.axis.client.AdminClient deploy.wsdd          -->
  <!--      after the axis server is running                          -->
  <!-- or                                                             -->
  <!--   java org.apache.axis.utils.Admin client|server deploy.wsdd   -->
  <!--      from the same directory that the Axis engine runs         -->
  
  <deployment
      xmlns="http://xml.apache.org/axis/wsdd/"
      xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
  
    <!-- Services from MyService WSDL service -->
  
    <service name="HelloWorld" provider="java:RPC" style="document" use="literal">
        <parameter name="wsdlTargetNamespace" value="http://helloworld.ch/schema/service"/>
        <parameter name="wsdlServiceElement" value="MyService"/>
        <parameter name="schemaQualified" value="http://helloworld.ch/schema/types"/>
        <parameter name="wsdlServicePort" value="HelloWorld"/>
        <parameter name="className" value="test.wsdl.axis2098.MySOAPBindingImpl"/>
        <parameter name="wsdlPortType" value="MyPort"/>
        <parameter name="typeMappingVersion" value="1.2"/>
        <operation name="helloWorld" qname="HelloWorld" returnQName="retNS:MyResponse"
xmlns:retNS="http://helloworld.ch/schema/types" returnType="rtns:MyResponseType" xmlns:rtns="http://helloworld.ch/schema/types"
>
          <parameter qname="pns:MyRequest" xmlns:pns="http://helloworld.ch/schema/types"
type="tns:MyRequestType" xmlns:tns="http://helloworld.ch/schema/types"/>
        </operation>
        <parameter name="allowedMethods" value="helloWorld"/>
        <parameter name="scope" value="Session"/>
  
        <requestFlow>
            <handler type="java:test.wsdl.axis2098.TestHandler"/>
        </requestFlow>
  
        <responseFlow>
            <handler type="java:test.wsdl.axis2098.TestHandler"/>
        </responseFlow>
  
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:StringType"
          type="java:java.lang.String"
          serializer="org.apache.axis.encoding.ser.SimpleSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.SimpleDeserializerFactory"
          encodingStyle=""
        />
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:LogicType"
          type="java:boolean"
          serializer="org.apache.axis.encoding.ser.SimpleSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.SimpleDeserializerFactory"
          encodingStyle=""
        />
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:>StringElem"
          type="java:java.lang.String"
          serializer="org.apache.axis.encoding.ser.SimpleSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.SimpleDeserializerFactory"
          encodingStyle=""
        />
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:MyRequestType"
          type="java:test.wsdl.axis2098.MyRequestType"
          serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
          encodingStyle=""
        />
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:RestrictionType"
          type="java:test.wsdl.axis2098.RestrictionType"
          serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
          encodingStyle=""
        />
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:XsiTestType"
          type="java:test.wsdl.axis2098.XsiTestType"
          serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
          encodingStyle=""
        />
        <typeMapping
          xmlns:ns="http://helloworld.ch/schema/types"
          qname="ns:MyResponseType"
          type="java:test.wsdl.axis2098.MyResponseType"
          serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
          deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
          encodingStyle=""
        />
    </service>
  </deployment>
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/helloworld.wsdl
  
  Index: helloworld.wsdl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <wsdl:definitions
      xmlns:tns="http://helloworld.ch/schema/service"
      xmlns:types="http://helloworld.ch/schema/types"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
      targetNamespace="http://helloworld.ch/schema/service"
      name="SalaryDeclarationService">
  
      <wsdl:types>
          <xs:schema
              targetNamespace="http://helloworld.ch/schema/types"
              xmlns:xs="http://www.w3.org/2001/XMLSchema"
              elementFormDefault="qualified" attributeFormDefault="unqualified">
              <xs:include schemaLocation="./helloworld.xsd"/>
          </xs:schema>
      </wsdl:types>
  
      <wsdl:message name="HelloWorldRequest">
          <wsdl:part name="body" element="types:MyRequest"/>
      </wsdl:message>
      <wsdl:message name="HelloWorldResponse">
          <wsdl:part name="body" element="types:MyResponse"/>
      </wsdl:message>
  
      <wsdl:portType name="MyPort">
          <wsdl:operation name="HelloWorld">
              <wsdl:input message="tns:HelloWorldRequest"/>
              <wsdl:output message="tns:HelloWorldResponse"/>
          </wsdl:operation>
      </wsdl:portType>
  
      <wsdl:binding name="MySOAPBinding" type="tns:MyPort">
          <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
          <wsdl:operation name="HelloWorld">
              <soap:operation style="document"/>
              <wsdl:input>
                  <soap:body use="literal"/>
              </wsdl:input>
              <wsdl:output>
                  <soap:body use="literal"/>
              </wsdl:output>
          </wsdl:operation>
      </wsdl:binding>
  
      <wsdl:service name="MyService">
          <wsdl:port name="HelloWorld" binding="tns:MySOAPBinding">
              <soap:address location="http://localhost:8080/axis/services/HelloWorld"/>
          </wsdl:port>
      </wsdl:service>
  </wsdl:definitions>
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/helloworld.xsd
  
  Index: helloworld.xsd
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <xs:schema
      targetNamespace="http://helloworld.ch/schema/types"
      xmlns:tns="http://helloworld.ch/schema/types"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified"
      attributeFormDefault="unqualified"
      version="0.1">
  
      <xs:element name="MyRequest" type="tns:MyRequestType"/>
  
      <xs:element name="MyResponse" type="tns:MyResponseType"/>
  
      <xs:complexType name="MyRequestType">
          <xs:sequence>
              <xs:element name="Helloworld" type="tns:XsiTestType"/>
          </xs:sequence>
      </xs:complexType>
  
      <xs:complexType name="MyResponseType">
          <xs:sequence>
              <xs:element name="Helloworld" type="tns:XsiTestType"/>
          </xs:sequence>
      </xs:complexType>
  
      <xs:complexType name="XsiTestType">
          <xs:sequence>
              <!-- simple -->
              <xs:element name="Logic" type="tns:LogicType"/>
              <xs:element name="String" type="tns:StringType"/>
              <!-- complex -->
              <xs:element name="Restriction" type="tns:RestrictionType"/>
              <xs:element ref="tns:StringElem"/>
          </xs:sequence>
      </xs:complexType>
  
      <xs:simpleType name="LogicType">
          <xs:restriction base="xs:boolean">
              <xs:pattern value="true"/>
              <xs:pattern value="false"/>
          </xs:restriction>
      </xs:simpleType>
  
      <xs:simpleType name="StringType">
          <xs:restriction base="xs:string">
              <xs:minLength value="10"/>
          </xs:restriction>
      </xs:simpleType>
  
      <xs:complexType name="BaseType" abstract="true" >
          <xs:sequence>
              <xs:element name="FirstName" type="xs:string" minOccurs="0" nillable="false"/>
              <xs:element name="LastName" type="xs:string"/>
          </xs:sequence>
      </xs:complexType>
  
      <xs:complexType name="RestrictionType">
          <xs:complexContent>
              <xs:restriction base="tns:BaseType">
                  <xs:sequence>
                      <xs:element name="LastName" type="xs:string"/>
                  </xs:sequence>
              </xs:restriction>
          </xs:complexContent>
      </xs:complexType>
      
      <xs:element name="StringElem">
      	<xs:simpleType>
      		<xs:restriction base="xs:string">
      			<xs:minLength value="3"/>
      			<xs:maxLength value="4"/>
      		</xs:restriction>
      	</xs:simpleType>
      </xs:element>
  </xs:schema>
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/MyServiceTestCase.java
  
  Index: MyServiceTestCase.java
  ===================================================================
  /**
   * MyServiceTestCase.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis 1.3 Jul 05, 2005 (04:50:41 KST) WSDL2Java emitter.
   */
  
  package test.wsdl.axis2098;
  
  public class MyServiceTestCase extends junit.framework.TestCase {
      public MyServiceTestCase(java.lang.String name) {
          super(name);
      }
  
      public void testHelloWorldWSDL() throws Exception {
          javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
          java.net.URL url = new java.net.URL(new test.wsdl.axis2098.MyServiceLocator().getHelloWorldAddress()
+ "?WSDL");
          javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.axis2098.MyServiceLocator().getServiceName());
          assertTrue(service != null);
      }
  
      public void test1HelloWorldHelloWorld() throws Exception {
          test.wsdl.axis2098.MySOAPBindingStub binding;
          try {
              binding = (test.wsdl.axis2098.MySOAPBindingStub)
                            new test.wsdl.axis2098.MyServiceLocator().getHelloWorld();
  
          }
          catch (javax.xml.rpc.ServiceException jre) {
              if(jre.getLinkedCause()!=null)
                  jre.getLinkedCause().printStackTrace();
              throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught:
" + jre);
          }
          assertNotNull("binding is null", binding);
  
          // Time out after a minute
          binding.setTimeout(60000);
  
  		// Thread.sleep(10*1000);
  
  		MyRequestType request = new MyRequestType();
  
          // Test operation
          MyResponseType value = null;
  
  		XsiTestType test = new XsiTestType();
  
          test.setString("Hello World --------------------------!");
  
          //  Will give a validation error: cvc-elt.4.3: Type 'xsd:boolean' is not validly
derived from the type definition, 'LogicType', of element 'Logic'.
          // It will add a xsi:type boolean but should not: <Logic xsi:type="xsd:boolean">true</Logic>
          test.setLogic(true);
  
          RestrictionType r = new RestrictionType();
          // r.setFirstName("Hello"); //we do not set this but  <firstName xsi:nil="true"/>
is still sent over the wire
          r.setLastName("World");
          test.setRestriction(r);
          
          test.setStringElem("String Ref");
  
          request.setHelloworld(test);
  
          // Invoke webservice
          MyResponseType response = binding.helloWorld(request);
  
          System.out.println("Response from the webservice:");
          System.out.println("\t"+response.getHelloworld());
          // TBD - validate results
      }
  
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/MySOAPBindingImpl.java
  
  Index: MySOAPBindingImpl.java
  ===================================================================
  package test.wsdl.axis2098;
  
  public class MySOAPBindingImpl implements test.wsdl.axis2098.MyPort {
  
      public test.wsdl.axis2098.MyResponseType helloWorld(test.wsdl.axis2098.MyRequestType
body)
              throws java.rmi.RemoteException {
  
          MyResponseType resp = new MyResponseType();
          resp.setHelloworld(body.getHelloworld());
          return resp;
      }
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/TestHandler.java
  
  Index: TestHandler.java
  ===================================================================
  package test.wsdl.axis2098;
  
  import java.io.ByteArrayOutputStream;
  
  import org.apache.axis.AxisFault;
  import org.apache.axis.MessageContext;
  import org.apache.axis.handlers.BasicHandler;
  
  public class TestHandler extends BasicHandler {
      public void invoke(MessageContext msgContext) throws AxisFault {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
  		
          try {
              msgContext.getCurrentMessage().writeTo(baos);
          } catch (Exception e) {
              throw new AxisFault("exception", e);
          }
          String msg = baos.toString();
          System.out.println("msg = " + msg);
          if (msg.indexOf("xsi:type") >= 0) {
              throw new AxisFault("message contains xsi:type");
          }
      }
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/axis2098/undeploy.wsdd
  
  Index: undeploy.wsdd
  ===================================================================
  <undeployment name="test" xmlns="http://xml.apache.org/axis/wsdd/">
    <service name="HelloWorld"/>
  </undeployment>
  
  
  
  1.53      +10 -1     ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java
  
  Index: JavaBeanHelperWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- JavaBeanHelperWriter.java	29 Apr 2005 13:54:50 -0000	1.52
  +++ JavaBeanHelperWriter.java	1 Aug 2005 18:23:29 -0000	1.53
  @@ -18,6 +18,7 @@
   import org.apache.axis.utils.Messages;
   import org.apache.axis.wsdl.symbolTable.ContainedAttribute;
   import org.apache.axis.utils.JavaUtils;
  +import org.apache.axis.wsdl.symbolTable.DefinedElement;
   import org.apache.axis.wsdl.symbolTable.DefinedType;
   import org.apache.axis.wsdl.symbolTable.ElementDecl;
   import org.apache.axis.wsdl.symbolTable.SchemaUtils;
  @@ -335,7 +336,15 @@
                           // be a SOAP array derived type.  In this case, use
                           // the refType's QName for the metadata.
                           elemType = elemType.getRefType();
  -                    } else {
  +                    } else if (elemType.getClass() == DefinedElement.class
  +                            && elemType.getRefType() != null) {
  +                        // If we have a DefinedElement which references other element
  +                        //  (eg. <element ref="aRefEleme"/>)
  +                        // use the refType's QName for the metadata (which can be anonymous
type.)
  +                        // see the schema of test/wsdl/axis2098
  +                        elemType = elemType.getRefType();
  +                    }                    
  +                    else {
                           // Otherwise, use the first non-Collection type we
                           // encounter up the ref chain.
                           while (elemType instanceof CollectionTE) {
  
  
  
  1.155     +4 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
  
  Index: JavaStubWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- JavaStubWriter.java	1 Aug 2005 03:16:45 -0000	1.154
  +++ JavaStubWriter.java	1 Aug 2005 18:23:29 -0000	1.155
  @@ -993,8 +993,10 @@
               pw.println("            cachedSerFactories.add(enumsf);");
               pw.println("            cachedDeserFactories.add(enumdf);");
           } else if (type.isSimpleType()) {
  -            pw.println("            cachedSerFactories.add(simplesf);");
  -            pw.println("            cachedDeserFactories.add(simpledf);");
  +            pw.println("            cachedSerFactories.add(org.apache.axis.encoding.ser.BaseSerializerFactory.createFactory("
+
  +                    "org.apache.axis.encoding.ser.SimpleSerializerFactory.class, cls, qName));");
  +            pw.println("            cachedDeserFactories.add(org.apache.axis.encoding.ser.BaseDeserializerFactory.createFactory("
+
  +                    "org.apache.axis.encoding.ser.SimpleDeserializerFactory.class, cls,
qName));");
           } else if (type.getBaseType() != null) {
   
               // serializers are not required for types derived from base types
  
  
  
  1.120     +21 -0     ws-axis/java/src/org/apache/axis/utils/JavaUtils.java
  
  Index: JavaUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/JavaUtils.java,v
  retrieving revision 1.119
  retrieving revision 1.120
  diff -u -r1.119 -r1.120
  --- JavaUtils.java	27 Jul 2005 02:46:47 -0000	1.119
  +++ JavaUtils.java	1 Aug 2005 18:23:29 -0000	1.120
  @@ -139,6 +139,27 @@
           
           return null;
       }
  +    
  +    public static Class getPrimitiveClassFromName(String primitive) {
  +        if (primitive.equals("int"))
  +            return int.class;
  +        else if (primitive.equals("short"))
  +            return short.class;
  +        else if (primitive.equals("boolean"))
  +            return boolean.class;
  +        else if (primitive.equals("byte"))
  +            return byte.class;
  +        else if (primitive.equals("long"))
  +            return long.class;
  +        else if (primitive.equals("double"))
  +            return double.class;
  +        else if (primitive.equals("float"))
  +            return float.class;
  +        else if (primitive.equals("char"))
  +            return char.class;
  +        
  +        return null;
  +    }
   
       /*
            * Any builtin type that has a constructor that takes a String is a basic
  
  
  
  1.112     +111 -9    ws-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- SerializationContext.java	21 Jul 2005 02:08:00 -0000	1.111
  +++ SerializationContext.java	1 Aug 2005 18:23:29 -0000	1.112
  @@ -675,7 +675,7 @@
                             Attributes attributes,
                             Object value)
           throws IOException {
  -        serialize(elemQName, attributes, value, null, null, null);
  +        serialize(elemQName, attributes, value, null, null, null, null);
       }
   
       /**
  @@ -694,13 +694,42 @@
        * @param elemQName is the QName of the element
        * @param attributes are additional attributes
        * @param value is the object to serialize
  +     * @param xmlType is the qname of the type or null.
  +     * @deprecated use serialize(QName, Attributes, Object, QName, Class) instead
        */
       public void serialize(QName elemQName,
                             Attributes attributes,
                             Object value,
                             QName xmlType)
           throws IOException {
  -        serialize(elemQName, attributes, value, xmlType, null, null);
  +        serialize(elemQName, attributes, value, xmlType, null, null, null);
  +    }
  +    
  +    /**
  +     * Serialize the indicated value as an element with the name
  +     * indicated by elemQName.
  +     * The attributes are additional attribute to be serialized on the element.
  +     * The value is the object being serialized.  (It may be serialized
  +     * directly or serialized as an mult-ref'd item)
  +     * The value is an Object, which may be a wrapped primitive, the
  +     * javaType is the actual unwrapped object type.
  +     * The xmlType is the QName of the type that is used to set
  +     * xsi:type.  If not specified, xsi:type is set by using the javaType to
  +     * find an appopriate xmlType from the TypeMappingRegistry.
  +     * Null values and the xsi:type flag will be sent or not depending 
  +     * on previous configuration of this SerializationContext.
  +     * @param elemQName is the QName of the element
  +     * @param attributes are additional attributes
  +     * @param value is the object to serialize
  +     * @param xmlType is the qname of the type or null.
  +     * @param javaType is the java type of the value
  +     */
  +    public void serialize(QName elemQName,
  +                          Attributes attributes,
  +                          Object value,
  +                          QName xmlType, Class javaType)
  +        throws IOException {
  +        serialize(elemQName, attributes, value, xmlType, javaType, null, null);
       }
   
       /**
  @@ -734,7 +763,7 @@
                             Boolean sendType)
           throws IOException
       {
  -        serialize( elemQName, attributes, value, xmlType, 
  +        serialize( elemQName, attributes, value, xmlType, null, 
                      (sendNull) ? Boolean.TRUE : Boolean.FALSE, 
                      sendType);
       }
  @@ -765,6 +794,40 @@
                             QName xmlType,
                             Boolean sendNull,
                             Boolean sendType)
  +        throws IOException 
  +    {
  +        serialize(elemQName, attributes, value, xmlType, null, sendNull, sendType);
  +        
  +    }
  +    
  +    /**
  +     * Serialize the indicated value as an element with the name
  +     * indicated by elemQName.
  +     * The attributes are additional attribute to be serialized on the element.
  +     * The value is the object being serialized.  (It may be serialized
  +     * directly or serialized as an mult-ref'd item)
  +     * The value is an Object, which may be a wrapped primitive.
  +     * The xmlType (if specified) is the QName of the type that is used to set
  +     * xsi:type.
  +     * The sendNull flag indicates whether to end an element with an xsi:nil="true" attribute
for null
  +     * variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
  +     * The sendType flag indicates whether the xsi:type flag should be sent
  +     * (default is true).
  +     * @param elemQName is the QName of the element
  +     * @param attributes are additional attributes
  +     * @param value is the object to serialize
  +     * @param xmlType is the qname of the type or null.
  +     * @param javaType is the java type of the value
  +     * @param sendNull determines whether to send null values.
  +     * @param sendType determines whether to set xsi:type attribute.
  +     */
  +    public void serialize(QName elemQName,
  +                          Attributes attributes,
  +                          Object value,
  +                          QName xmlType,
  +                          Class javaClass,
  +                          Boolean sendNull,
  +                          Boolean sendType)
           throws IOException
       {
           boolean sendXSITypeCache = sendXSIType;
  @@ -810,7 +873,7 @@
   
                       //Allow an the attachment to do its own serialization.
                       serializeActual(elemQName, attributes, value,
  -                                    xmlType, sendType);
  +                                    xmlType, javaClass, sendType);
   
                       //No need to add to mulitRefs. Attachment data stream handled by
                       // the message;
  @@ -861,7 +924,7 @@
                               attrs.setAttributes(attributes);
                           attrs.addAttribute("", Constants.ATTR_ID, "id", "CDATA",
                                              id);
  -                        serializeActual(elemQName, attrs, value, xmlType, sendType);
  +                        serializeActual(elemQName, attrs, value, xmlType, javaClass, sendType);
                           this.sendNull = sendNullCache;
                           return;
                       }
  @@ -912,7 +975,7 @@
                   forceSer = null;
   
               // Actually serialize the value.  (i.e. not an href like above)
  -            serializeActual(elemQName, attributes, value, xmlType, sendType);
  +            serializeActual(elemQName, attributes, value, xmlType, javaClass, sendType);
           } finally {
               sendXSIType = sendXSITypeCache;
           }
  @@ -989,6 +1052,7 @@
                   // ascertain the type in these circumstances (though Axis does).
                   serialize(multirefQName, attrs2, mri.value,
                             mri.xmlType,
  +                          null,
                             this.sendNull,
                             Boolean.TRUE);   // mri.sendType
               }
  @@ -1363,6 +1427,7 @@
                                   Attributes attributes,
                                   Object value,
                                   QName xmlType,
  +                                Class javaClass,
                                   Boolean sendType)
           throws IOException
       {
  @@ -1370,7 +1435,6 @@
               sendType.booleanValue();
   
           if (value != null) {
  -            Class javaType = value.getClass();
               TypeMapping tm = getTypeMapping();
   
               if (tm == null) {
  @@ -1393,6 +1457,9 @@
   
               // Try getting a serializer for the prefered xmlType
               QNameHolder actualXMLType = new QNameHolder();
  +                        
  +            Class javaType = getActualJavaClass(xmlType, javaClass, value);
  +                        
               Serializer ser = getSerializer(javaType, xmlType,
                                              actualXMLType);
   
  @@ -1407,7 +1474,10 @@
                       if(!isEncoded()) {
                           if (Constants.isSOAP_ENC(actualXMLType.value.getNamespaceURI()))
{
                               // Don't write SOAP_ENC types (i.e. Array) if we're not using
encoding
  -                        } else {
  +                        } else if (javaType.isPrimitive() && javaClass != null
&& JavaUtils.getWrapperClass(javaType) == javaClass) {
  +                            // Don't write xsi:type when serializing primitive wrapper
value as primitive type.
  +                        }
  +                        else {
                               if(!(javaType.isArray() && xmlType != null &&
Constants.isSchemaXSD(xmlType.getNamespaceURI())) ) {
                                   writeXMLType = actualXMLType.value;
                               }
  @@ -1437,6 +1507,36 @@
           }
           // !!! Write out a generic null, or get type info from somewhere else?
       }
  +    
  +    /**
  +     * Returns the java class for serialization. 
  +     * If the xmlType is xsd:anyType or javaType is array or javaType is java.lang.Object
  +     * the java class for serialization is the class of obj.
  +     * If the obj is not array and the obj's class does not match with the javaType,
  +     * the java class for serialization is the javaType.
  +     * Otherwise, the java class for serialization is the obj's class.
  +     * 
  +     * @param xmlType    the qname of xml type
  +     * @param javaType   the java class from serializer 
  +     * @param obj        the object to serialize
  +     * @return the java class for serialization
  +     */
  +    private Class getActualJavaClass(QName xmlType, Class javaType, Object obj) {
  +        Class cls = obj.getClass();
  +        
  +        if ((xmlType != null 
  +                    && Constants.isSchemaXSD(xmlType.getNamespaceURI()) &&
"anyType".equals(xmlType.getLocalPart()))
  +                || (javaType != null 
  +                        && (javaType.isArray() || javaType == Object.class))) {
  +            return cls;
  +        }
  +        
  +        if (javaType != null && cls != javaType && !cls.isArray()) {
  +            return javaType;
  +        }
  +        
  +        return cls;
  +    }
   
       private Serializer getSerializerFromClass(Class javaType, QName qname) {
           
  @@ -1565,8 +1665,10 @@
           return ser;
       }
   
  -    public String getValueAsString(Object value, QName xmlType) throws IOException {
  +    public String getValueAsString(Object value, QName xmlType, Class javaClass) throws
IOException {
           Class cls = value.getClass();
  +        cls = getActualJavaClass(xmlType, javaClass, value);
  +        
           Serializer ser = getSerializer(cls, xmlType, null);
           
           // The java type is an array, but we need a simple type.
  
  
  
  1.67      +14 -0     ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
  
  Index: TypeMappingImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- TypeMappingImpl.java	1 Aug 2005 03:16:45 -0000	1.66
  +++ TypeMappingImpl.java	1 Aug 2005 18:23:29 -0000	1.67
  @@ -340,6 +340,20 @@
               }
           }
           
  +        // find serializer with xmlType
  +        if (sf == null && !javaType.isArray() 
  +                && !Constants.isSchemaXSD(xmlType.getNamespaceURI()) 
  +                && !Constants.isSOAP_ENC(xmlType.getNamespaceURI())) {
  +            Pair pair2 = (Pair) qName2Pair.get(xmlType);
  +            if (pair2 != null && pair2.javaType != null 
  +                    && !pair2.javaType.isArray()                         // for
array
  +                    && (javaType.isAssignableFrom(pair2.javaType) || 
  +                       (pair2.javaType.isPrimitive() && javaType == JavaUtils.getWrapperClass(pair2.javaType))))
      // for derived type (xsd:restriction) 
  +            {
  +                sf = (javax.xml.rpc.encoding.SerializerFactory) pair2SF.get(pair2);
  +            }
  +        }
  +        
           return sf;
       }
       
  
  
  
  1.40      +2 -2      ws-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTypeMapping.java
  
  Index: WSDDTypeMapping.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTypeMapping.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- WSDDTypeMapping.java	13 Jun 2005 14:25:37 -0000	1.39
  +++ WSDDTypeMapping.java	1 Aug 2005 18:23:29 -0000	1.40
  @@ -177,8 +177,8 @@
               }
               String loadName = JavaUtils.getLoadableClassName(typeQName.getLocalPart());
               if (JavaUtils.getWrapper(loadName) != null) {
  -                // in case of a primitive type by use its corresponding wrapper class.

  -                loadName = "java.lang." + JavaUtils.getWrapper(loadName);
  +                Class cls = JavaUtils.getPrimitiveClassFromName(loadName);
  +                return cls;
               }
               return ClassUtils.forName(loadName);
           }
  
  
  

Mime
View raw message