users@jax-ws.java.net

XML Schema generation for collections

From: Dmytro Rud <unixoid_at_web.de>
Date: Sat, 5 Nov 2005 22:48:45 +0100 (CET)

Hi!

There is a method:

===
@WebMethod
public Vector<String> batchConvert( Vector<String> firstCurrencyNames,
                                    Vector<String> secondCurrencyNames,
                                    Vector<Double> rates,
                                    Vector<Double> amounts )
===

The newest nightly build (JAXWS_SI_20051104) generates the following XML
Schema for its parameters and return value:

===
<xs:schema targetNamespace="http://dmytropc.cs.uni-magdeburg.de/WS/service2" version="1.0">
  <xs:element type="ns1:batchConvert" name="batchConvert"/>
    <xs:complexType name="batchConvert">
      <xs:sequence>
        <xs:element type="xs:anyType" minOccurs="0" name="arg0" maxOccurs="unbounded"/>
        <xs:element type="xs:anyType" minOccurs="0" name="arg1" maxOccurs="unbounded"/>
        <xs:element type="xs:anyType" minOccurs="0" name="arg2" maxOccurs="unbounded"/>
        <xs:element type="xs:anyType" minOccurs="0" name="arg3" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  <xs:element type="ns2:batchConvertResponse" name="batchConvertResponse"/>
    <xs:complexType name="batchConvertResponse">
      <xs:sequence>
        <xs:element type="xs:anyType" minOccurs="0" name="return" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  <xs:element type="ns3:BadBatchException" name="BadBatchException"/>
</xs:schema>
===

And the signature of the proxy method generated by wsimport is

===
    public List<Object> batchConvert(
        @WebParam(name = "arg0", targetNamespace = "")
        List<Object> arg0,
        @WebParam(name = "arg1", targetNamespace = "")
        List<Object> arg1,
        @WebParam(name = "arg2", targetNamespace = "")
        List<Object> arg2,
        @WebParam(name = "arg3", targetNamespace = "")
        List<Object> arg3)

===

Thus the return value of batchConvert() needs to be casted to
List<String> by the client.

But earlier versions of JAX-WS used more proper data types (xs:string
and xs:double) for elements of sequences and it was accordingly possible
to use List<String> in clients without any need to casting.

I suppose there is a way to customize the XML Schema generation in order
to get more appropriate data types, but IMHO it would be better if
JAX-WS were returned to its old behavior and tried to choose proper data
types by default. Wouldn't it?

-- 
        rnd.