You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2005/02/06 06:12:25 UTC

cvs commit: ws-axis/java/src/org/apache/axis/encoding/ser SimpleDeserializer.java SimpleDeserializerFactory.java SimpleSerializer.java

dims        2005/02/05 21:12:25

  Modified:    java/src/org/apache/axis/utils BeanUtils.java
               java/test/wsdl/schema2 build.xml schema2.wsdl
                        Schema2ServiceSoapBindingImpl.java
                        Schema2ServiceTestCase.java
               java/src/org/apache/axis/encoding/ser
                        SimpleDeserializer.java
                        SimpleDeserializerFactory.java
                        SimpleSerializer.java
  Added:       java/test/wsdl/schema2 Document.java
  Log:
  Ability to use a JavaBean (w/o SimpleType interface marker, See test/wsdl/schema2/Document.java for example).
  
  Revision  Changes    Path
  1.24      +16 -1     ws-axis/java/src/org/apache/axis/utils/BeanUtils.java
  
  Index: BeanUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/BeanUtils.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- BeanUtils.java	25 Feb 2004 14:02:48 -0000	1.23
  +++ BeanUtils.java	6 Feb 2005 05:12:24 -0000	1.24
  @@ -256,11 +256,26 @@
   
       public static BeanPropertyDescriptor getAnyContentPD(Class javaType) {
           PropertyDescriptor [] pds = getPropertyDescriptors(javaType);
  +        return getSpecificPD(pds, Constants.ANYCONTENT);
  +    }
  +
  +    public static BeanPropertyDescriptor getSpecificPD(PropertyDescriptor[] pds,
  +                                                       String name) {
           for (int i = 0; i < pds.length; i++) {
               PropertyDescriptor pd = pds[i];
  -            if (pd.getName().equals(Constants.ANYCONTENT))
  +            if (pd.getName().equals(name))
                   return new BeanPropertyDescriptor(pd);
           }
           return null;
       }
  +
  +    public static BeanPropertyDescriptor getSpecificPD(BeanPropertyDescriptor[] pds,
  +                                                       String name) {
  +        for (int i = 0; i < pds.length; i++) {
  +            BeanPropertyDescriptor pd = pds[i];
  +            if (pd.getName().equals(name))
  +                return pd;
  +        }
  +        return null;
  +    }
   }
  
  
  
  1.2       +2 -1      ws-axis/java/test/wsdl/schema2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/wsdl/schema2/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	18 Jan 2005 03:38:02 -0000	1.1
  +++ build.xml	6 Feb 2005 05:12:24 -0000	1.2
  @@ -57,7 +57,7 @@
                  output="${axis.home}/build/work"
                  deployscope="session"
                  serverSide="yes"
  -               skeletonDeploy="yes"
  +               skeletonDeploy="no"
                  typemappingversion="1.3"
                  testcase="yes">
           <mapping namespace="urn:CityBBB" package="test.wsdl.schema2"/>
  @@ -67,6 +67,7 @@
         <fileset dir="${axis.home}/test/wsdl/schema2">
           <include name="*TestCase.java"/>
           <include name="*Impl.java"/>
  +        <include name="Document.java"/>
         </fileset>
       </copy>
   
  
  
  
  1.3       +31 -0     ws-axis/java/test/wsdl/schema2/schema2.wsdl
  
  Index: schema2.wsdl
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/wsdl/schema2/schema2.wsdl,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- schema2.wsdl	19 Jan 2005 21:47:33 -0000	1.2
  +++ schema2.wsdl	6 Feb 2005 05:12:24 -0000	1.3
  @@ -34,6 +34,18 @@
               <element name="Time1" type="xsd:time"/>
               <element name="Date" type="xsd:date"/>
               <element name="Date1" type="xsd:date"/>
  +            <complexType name="Document">
  +                <simpleContent>
  +                    <extension base="string">
  +                        <xsd:attribute
  +                            name="ID"
  +                            type="string"
  +                            xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
  +                    </extension>
  +                </simpleContent>
  +            </complexType>
  +            <element name="EchoDocumentRequest" type="tns1:Document"/>
  +            <element name="EchoDocumentResponse" type="tns1:Document"/>
           </schema>
       </wsdl:types>
       <wsdl:message name="echoDateTestRequest">
  @@ -126,6 +138,12 @@
       <wsdl:message name="echoPositiveIntegerTestRequest">
           <wsdl:part name="PositiveInteger" element="tns1:PositiveInteger"/>
       </wsdl:message>
  +    <wsdl:message name="echoDocumentRequest">
  +        <wsdl:part name="Document" element="tns1:EchoDocumentRequest"/>
  +    </wsdl:message>
  +    <wsdl:message name="echoDocumentResponse">
  +        <wsdl:part name="Document" element="tns1:EchoDocumentResponse"/>
  +    </wsdl:message>
       <wsdl:portType name="Schema2Test">
           <wsdl:operation name="echoLanguageTypeTest" parameterOrder="languageElem">
               <wsdl:input name="echoLanguageTypeTestRequest" message="impl:echoLanguageTypeTestRequest"/>
  @@ -187,6 +205,10 @@
               <wsdl:input name="echoDateTestRequest" message="impl:echoDateTestRequest"/>
               <wsdl:output name="echoDateTestResponse" message="impl:echoDateTestResponse"/>
           </wsdl:operation>
  +        <wsdl:operation name="echoDocument">
  +            <wsdl:input message="impl:echoDocumentRequest"/>
  +            <wsdl:output message="impl:echoDocumentResponse"/>
  +        </wsdl:operation>
       </wsdl:portType>
       <wsdl:binding name="Schema2ServiceSoapBinding" type="impl:Schema2Test">
           <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  @@ -325,6 +347,15 @@
                   <wsdlsoap:body use="literal"/>
               </wsdl:output>
           </wsdl:operation>
  +        <wsdl:operation name="echoDocument">
  +            <wsdlsoap:operation soapAction=""/>
  +            <wsdl:input>
  +                <wsdlsoap:body use="literal"/>
  +            </wsdl:input>
  +            <wsdl:output>
  +                <wsdlsoap:body use="literal"/>
  +            </wsdl:output>
  +        </wsdl:operation>
       </wsdl:binding>
       <wsdl:service name="Schema2Service">
           <wsdl:port name="Schema2Service" binding="impl:Schema2ServiceSoapBinding">
  
  
  
  1.3       +3 -0      ws-axis/java/test/wsdl/schema2/Schema2ServiceSoapBindingImpl.java
  
  Index: Schema2ServiceSoapBindingImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/wsdl/schema2/Schema2ServiceSoapBindingImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Schema2ServiceSoapBindingImpl.java	20 Jan 2005 02:38:11 -0000	1.2
  +++ Schema2ServiceSoapBindingImpl.java	6 Feb 2005 05:12:24 -0000	1.3
  @@ -68,4 +68,7 @@
           return date;
       }
   
  +    public test.wsdl.schema2.Document echoDocument(test.wsdl.schema2.Document document) throws java.rmi.RemoteException {
  +        return document;
  +    }
   }
  
  
  
  1.2       +25 -0     ws-axis/java/test/wsdl/schema2/Schema2ServiceTestCase.java
  
  Index: Schema2ServiceTestCase.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/test/wsdl/schema2/Schema2ServiceTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Schema2ServiceTestCase.java	18 Jan 2005 03:38:02 -0000	1.1
  +++ Schema2ServiceTestCase.java	6 Feb 2005 05:12:24 -0000	1.2
  @@ -349,4 +349,29 @@
           // TBD - validate results
       }
   
  +    public void test16Schema2ServiceEchoDocumentTest() throws Exception {
  +        test.wsdl.schema2.Schema2ServiceSoapBindingStub binding;
  +        try {
  +            binding = (test.wsdl.schema2.Schema2ServiceSoapBindingStub)
  +                          new test.wsdl.schema2.Schema2ServiceLocator().getSchema2Service();
  +        }
  +        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);
  +
  +        // Test operation
  +        Document value = new Document();
  +        value.set_value("XYZ");
  +        value.setID("ID#1");
  +        value = binding.echoDocument(value);
  +        // TBD - validate results
  +        assertEquals("ID#1",value.getID());
  +        assertEquals("XYZ",value.get_value());
  +    }
   }
  
  
  
  1.1                  ws-axis/java/test/wsdl/schema2/Document.java
  
  Index: Document.java
  ===================================================================
  package test.wsdl.schema2;
  
  
  public class Document {
      protected java.lang.String ID;
      protected java.lang.String _value;
      
      public Document() {
      }
      
      public Document(java.lang.String ID, java.lang.String _value) {
          this.ID = ID;
          this._value = _value;
      }
      
      public java.lang.String getID() {
          return ID;
      }
      
      public void setID(java.lang.String ID) {
          this.ID = ID;
      }
      
      public java.lang.String get_value() {
          return _value;
      }
      
      public void set_value(java.lang.String _value) {
          this._value = _value;
      }
  }
  
  
  
  1.43      +32 -26    ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java
  
  Index: SimpleDeserializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- SimpleDeserializer.java	18 Nov 2004 23:39:18 -0000	1.42
  +++ SimpleDeserializer.java	6 Feb 2005 05:12:25 -0000	1.43
  @@ -73,7 +73,7 @@
        * javaType (which could be a java primitive like int.class)
        */
       public SimpleDeserializer(Class javaType, QName xmlType) {
  -        this.xmlType = xmlType;
  +         this.xmlType = xmlType;
           this.javaType = javaType;
           
           init();
  @@ -98,17 +98,17 @@
               if (typeDesc == null) {
                   typeDesc = TypeDesc.getTypeDescForClass(javaType);
               }
  -            // Get the cached propertyDescriptor from the type or 
  -            // generate a fresh one.
  -            if (typeDesc != null) {
  -                propertyMap = typeDesc.getPropertyDescriptorMap();
  -            } else {   
  -                BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, null);
  -                propertyMap = new HashMap();
  -                for (int i = 0; i < pd.length; i++) {
  -                    BeanPropertyDescriptor descriptor = pd[i];
  -                    propertyMap.put(descriptor.getName(), descriptor);
  -                }
  +        }
  +        // Get the cached propertyDescriptor from the type or 
  +        // generate a fresh one.
  +        if (typeDesc != null) {
  +            propertyMap = typeDesc.getPropertyDescriptorMap();
  +        } else {
  +            BeanPropertyDescriptor[] pd = BeanUtils.getPd(javaType, null);
  +            propertyMap = new HashMap();
  +            for (int i = 0; i < pd.length; i++) {
  +                BeanPropertyDescriptor descriptor = pd[i];
  +                propertyMap.put(descriptor.getName(), descriptor);
               }
           }
       }
  @@ -237,11 +237,18 @@
               }
           }
           
  -        if (args == null) {
  -            args = new Object[] { source };
  +        if(constructor.getParameterTypes().length==0){
  +            Object obj = constructor.newInstance(new Object[]{});
  +            obj.getClass().getMethod("set_value", new Class[]{String.class})
  +                    .invoke(obj, new Object[]{source});
  +            return obj;
  +        } else {
  +            if (args == null) {
  +                args = new Object[] { source };
  +            }
  +            
  +            return constructor.newInstance(args);
           }
  -        
  -        return constructor.newInstance(args);
       }
   
       private Object makeBasicValue(String source) throws Exception {
  @@ -336,18 +343,19 @@
           
           this.context = context;
   
  -        // If we have no metadata, we have no attributes.  Q.E.D.
  -        if (typeDesc == null)
  -            return;
  -        
           // loop through the attributes and set bean properties that
           // correspond to attributes
           for (int i=0; i < attributes.getLength(); i++) {
               QName attrQName = new QName(attributes.getURI(i),
                                           attributes.getLocalName(i));
  -            String fieldName = typeDesc.getFieldNameForAttribute(attrQName);
  -            if (fieldName == null)
  -                continue;
  +            
  +            String fieldName = attributes.getLocalName(i);
  +            
  +            if(typeDesc != null) {
  +                typeDesc.getFieldNameForAttribute(attrQName);
  +                if (fieldName == null)
  +                    continue;
  +            } 
               
               // look for the attribute property
               BeanPropertyDescriptor bpd =
  @@ -394,9 +402,7 @@
        * Process any attributes we may have encountered (in onStartElement)
        */ 
       private void setSimpleTypeAttributes() throws SAXException {
  -        // if this isn't a simpleType bean, wont have attributes
  -        if (! SimpleType.class.isAssignableFrom(javaType) ||
  -                attributeMap == null)
  +        if (attributeMap == null)
               return;
           
           // loop through map
  
  
  
  1.13      +6 -1      ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializerFactory.java
  
  Index: SimpleDeserializerFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializerFactory.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SimpleDeserializerFactory.java	6 Jan 2005 18:47:49 -0000	1.12
  +++ SimpleDeserializerFactory.java	6 Feb 2005 05:12:25 -0000	1.13
  @@ -59,7 +59,12 @@
                           javaType.getDeclaredConstructor(STRING_CLASS);
                   }
               } catch (java.lang.NoSuchMethodException e) {
  -                throw new IllegalArgumentException(e.toString());
  +                try {
  +                    constructor = 
  +                        javaType.getDeclaredConstructor(new Class[]{});
  +                } catch (java.lang.NoSuchMethodException ex) {
  +                    throw new IllegalArgumentException(ex.toString());
  +                } 
               } 
           }
       }
  
  
  
  1.36      +33 -28    ws-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java
  
  Index: SimpleSerializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- SimpleSerializer.java	7 Apr 2004 13:00:35 -0000	1.35
  +++ SimpleSerializer.java	6 Feb 2005 05:12:25 -0000	1.36
  @@ -21,7 +21,6 @@
   import org.apache.axis.description.FieldDesc;
   import org.apache.axis.description.TypeDesc;
   import org.apache.axis.encoding.SerializationContext;
  -import org.apache.axis.encoding.SimpleType;
   import org.apache.axis.encoding.SimpleValueSerializer;
   import org.apache.axis.utils.BeanPropertyDescriptor;
   import org.apache.axis.utils.BeanUtils;
  @@ -33,6 +32,8 @@
   
   import javax.xml.namespace.QName;
   import java.io.IOException;
  +import java.beans.PropertyDescriptor;
  +import java.lang.reflect.InvocationTargetException;
   
   /**
    * Serializer for primitives and anything simple whose value is obtained with toString()
  @@ -45,6 +46,7 @@
   
       private BeanPropertyDescriptor[] propertyDescriptor = null;
       private TypeDesc typeDesc = null;
  +    public static final String VALUE_PROPERTY = "_value";
   
       public SimpleSerializer(Class javaType, QName xmlType) {
           this.xmlType = xmlType;
  @@ -62,20 +64,16 @@
       * Initialize the typeDesc and propertyDescriptor array.
       */
       private void init() {
  -        // The typeDesc and propertyDescriptor array are only necessary
  -        // if this class extends SimpleType.
  -        if (SimpleType.class.isAssignableFrom(javaType)) {
  -            // Set the typeDesc if not already set
  -            if (typeDesc == null) {
  -                typeDesc = TypeDesc.getTypeDescForClass(javaType);
  -            }
  -            // Get the cached propertyDescriptor from the type or
  -            // generate a fresh one.
  -            if (typeDesc != null) {
  -                propertyDescriptor = typeDesc.getPropertyDescriptors();
  -            } else {
  -                propertyDescriptor = BeanUtils.getPd(javaType, null);
  -            }
  +        // Set the typeDesc if not already set
  +        if (typeDesc == null) {
  +            typeDesc = TypeDesc.getTypeDescForClass(javaType);
  +        }
  +        // Get the cached propertyDescriptor from the type or
  +        // generate a fresh one.
  +        if (typeDesc != null) {
  +            propertyDescriptor = typeDesc.getPropertyDescriptors();
  +        } else {
  +            propertyDescriptor = BeanUtils.getPd(javaType, null);
           }
       }
   
  @@ -95,8 +93,7 @@
           }
   
           // get any attributes
  -        if (value instanceof SimpleType)
  -            attributes = getObjectAttributes(value, attributes, context);
  +        attributes = getObjectAttributes(value, attributes, context);
   
           String valueStr = null;
           if (value != null) {
  @@ -132,13 +129,20 @@
               return context.qName2String((QName)value);
           }
   
  +        BeanPropertyDescriptor pd = BeanUtils.getSpecificPD(propertyDescriptor, "_value");
  +        if(pd != null) {
  +            try {
  +                return pd.get(value).toString();
  +            } catch (Exception e) {
  +            }
  +        }
           return value.toString();
       }
   
       private Attributes getObjectAttributes(Object value,
                                              Attributes attributes,
                                              SerializationContext context) {
  -        if (typeDesc == null || !typeDesc.hasAttributes())
  +        if (typeDesc != null && !typeDesc.hasAttributes())
               return attributes;
   
           AttributesImpl attrs;
  @@ -158,12 +162,17 @@
                   if (propName.equals("class"))
                       continue;
   
  -                FieldDesc field = typeDesc.getFieldByName(propName);
  -                // skip it if its not an attribute
  -                if (field == null || field.isElement())
  -                    continue;
  -
  -                QName qname = field.getXmlName();
  +                QName qname = null;
  +                if(typeDesc != null) {
  +                    FieldDesc field = typeDesc.getFieldByName(propName);
  +                    // skip it if its not an attribute
  +                    if (field == null || field.isElement())
  +                        continue;
  +                    qname = field.getXmlName();
  +                } else {
  +                    if(propName.equals(VALUE_PROPERTY))
  +                        continue;
  +                }
                   if (qname == null) {
                       qname = new QName("", propName);
                   }
  @@ -212,10 +221,6 @@
        * @see org.apache.axis.wsdl.fromJava.Types
        */
       public Element writeSchema(Class javaType, Types types) throws Exception {
  -        // Let the caller generate WSDL if this is not a SimpleType
  -        if (!SimpleType.class.isAssignableFrom(javaType))
  -            return null;
  -
           // ComplexType representation of SimpleType bean class
           Element complexType = types.createElement("complexType");
           types.writeSchemaTypeDecl(xmlType, complexType);