axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Liao" <Norwaywo...@21cn.com>
Subject ??,?: Deserializing an Array of Beans
Date Wed, 09 Jul 2003 15:54:32 GMT
Hi there,

I think you should use Java2Wsdl tools to generate the local stub. look at the following:

 <complexType name="ServiceSummary">
 	<sequence>
  		<element name="name" nillable="true" type="xsd:string" /> 
  		<element name="id" nillable="true" type="xsd:string" /> 
		<element name="shortDescription" nillable="true" type="xsd:string" /> 
		<element name="wsdlURL" nillable="true" type="xsd:string" /> 
		<element name="publisherID" nillable="true" type="xsd:string" /> 
	</sequence>
  </complexType>
 <complexType name="ArrayOfServiceSummary">
	 <complexContent>
 		<restriction base="soapenc:Array">
			<attribute ref="soapenc:arrayType" wsdl:arrayType="tns:ServiceSummary[]" /> 
		</restriction>
	</complexContent>
  </complexType>

There is a bean type ServiceSummary and its array type ArrayOfServiceSummary. When you use
WSDL2Java tool to generate the stub, it should create a serializable Java bean named
ServiceSummary like this:
/**
 * ServiceSummary.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis WSDL2Java emitter.
 */

package net.xmethods.www.interfaces.query_xsd;

public class ServiceSummary  implements java.io.Serializable {
    private java.lang.String name;
    private java.lang.String id;
    private java.lang.String shortDescription;
    private java.lang.String wsdlURL;
    private java.lang.String publisherID;

    public ServiceSummary() {
    }

    public java.lang.String getName() {
        return name;
    }

    public void setName(java.lang.String name) {
        this.name = name;
    }

    public java.lang.String getId() {
        return id;
    }

    public void setId(java.lang.String id) {
        this.id = id;
    }

    public java.lang.String getShortDescription() {
        return shortDescription;
    }

    public void setShortDescription(java.lang.String shortDescription) {
        this.shortDescription = shortDescription;
    }

    public java.lang.String getWsdlURL() {
        return wsdlURL;
    }

    public void setWsdlURL(java.lang.String wsdlURL) {
        this.wsdlURL = wsdlURL;
    }

    public java.lang.String getPublisherID() {
        return publisherID;
    }

    public void setPublisherID(java.lang.String publisherID) {
        this.publisherID = publisherID;
    }

    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof ServiceSummary)) return false;
        ServiceSummary other = (ServiceSummary) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.name==null && other.getName()==null) || 
             (this.name!=null &&
              this.name.equals(other.getName()))) &&
            ((this.id==null && other.getId()==null) || 
             (this.id!=null &&
              this.id.equals(other.getId()))) &&
            ((this.shortDescription==null && other.getShortDescription()==null) ||

             (this.shortDescription!=null &&
              this.shortDescription.equals(other.getShortDescription()))) &&
            ((this.wsdlURL==null && other.getWsdlURL()==null) || 
             (this.wsdlURL!=null &&
              this.wsdlURL.equals(other.getWsdlURL()))) &&
            ((this.publisherID==null && other.getPublisherID()==null) || 
             (this.publisherID!=null &&
              this.publisherID.equals(other.getPublisherID())));
        __equalsCalc = null;
        return _equals;
    }

    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getName() != null) {
            _hashCode += getName().hashCode();
        }
        if (getId() != null) {
            _hashCode += getId().hashCode();
        }
        if (getShortDescription() != null) {
            _hashCode += getShortDescription().hashCode();
        }
        if (getWsdlURL() != null) {
            _hashCode += getWsdlURL().hashCode();
        }
        if (getPublisherID() != null) {
            _hashCode += getPublisherID().hashCode();
        }
        __hashCodeCalc = false;
        return _hashCode;
    }

    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(ServiceSummary.class);

    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("http://www.xmethods.net/interfaces/query.xsd",
"ServiceSummary"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("name");
        elemField.setXmlName(new javax.xml.namespace.QName("", "name"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("id");
        elemField.setXmlName(new javax.xml.namespace.QName("", "id"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("shortDescription");
        elemField.setXmlName(new javax.xml.namespace.QName("", "shortDescription"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("wsdlURL");
        elemField.setXmlName(new javax.xml.namespace.QName("", "wsdlURL"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("publisherID");
        elemField.setXmlName(new javax.xml.namespace.QName("", "publisherID"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"string"));
        typeDesc.addFieldDesc(elemField);
    }

    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }

    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }

    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType, 
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return 
          new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }

}

Finally, you can use the stub to call service. you will get all you want.
regards
								James




Hi there,

I can't find a solution for deserializing an array of beans in my
client application.

I have a method in my webservice which looks like that:

  public MyBean[] getMyBeans() {
  ...
  }

This mehod returns an array of MyBean objects. When calling this
mehtod from my browser I can see that the array of beans is
correctly serialized. However if I try to request the results from
my client via

  ...
  call.setOperation( "getMyBeans" );
  ...
  MyBean[] allMyBeans = (MyBean[]) call.invoke( new Object[] { } );

I get the following execption:
"No deserializer defined for array type"

Doing the same with an array of primitive type (eg. int) causes no
problem.

I already searched in the message archive but haven't found a
solution for my problem (but others which seemed to have struggled
with the same problem a long time ago).

Any ideas?

Thx.

Andreas
Mime
View raw message