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 "David L. Cole" <DL...@cmsenergy.com> on 2002/03/27 01:53:25 UTC

Collection Ser/Des

I have a method which returns a Collection. Below is the generated client
stub which accurately shows it will return a Collection.
However, the actual object typ of resp is Object[]. This causes a
ClassCastException.
    public java.util.Collection retrieveContractListForAsset() throws
java.rmi.RemoteException{
        if (super.cachedEndpoint == null) {
            throw new org.apache.axis.NoEndPointException();
        }
        com.rbs.base.client.remote.RBSCall call = getCall();
        call.setReturnType(new javax.xml.rpc.namespace.QName
("http://util.java", "Collection"));
        call.setUseSOAPAction(true);
        call.setSOAPActionURI("");
        call.setOperationStyle("rpc");
        call.setOperationName(new javax.xml.rpc.namespace.QName
("http://business.agreement.rbs.com", "retrieveContractListForAsset"));

        Object resp = call.invoke(new Object[] {});

        if (resp instanceof java.rmi.RemoteException) {
            throw (java.rmi.RemoteException)resp;
        }
        else {
             return (java.util.Collection) resp;
        }
    }

Currently to fix the problem, I modify the return line to the following:

             return (java.util.Collection)java.util.Arrays.asList((Object
[])resp);

The only side effect from this is that the client which called the method
should new a collection and pass in the return value from the stub
into the constructor which will copy the collection contents to the new
collection object.

i.e Collection col = new Vector( returnFromStubMethod);
or Collection col = new ArrayList( returnFromStubMethod);

Is there any plan to fix the stub generation or alternate suggestions?
Thanks,

David Cole