You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Scott Lamb <sl...@slamb.org> on 2005/07/02 23:04:34 UTC

Collections classes?

How can I get Axis to use the Java Collections classes? I see in  
1.2.1's "What's in this release" section that it says "Automatic two- 
way conversions between Java Collections and SOAP Arrays". I don't  
see any details, though. How do I use this?

Specifically, I'm playing with GoogleSearch.wsdl. The  
GoogleSearchResult class AXIS has getResultElements() and  
setResultElements() methods that deal with plain Java arrays -  
ResultElement[]. I'd prefer collections objects like List or (for  
Java 1.5) List<ResultElement>.

Is this what this snippet is describing? If not, what does it mean?  
And is there any way to do what I want?

Thanks,
Scott

-- 
Scott Lamb <http://www.slamb.org/>


Re: Collections classes?

Posted by Scott Lamb <sl...@slamb.org>.
On 4 Jul 2005, at 08:38, Anne Thomas Manes wrote:
> Actually, a list is a specialization of an array, not the other way
> around. As James says, a list requires more information than an XSD
> type array. An XSD type array has no sense of order or index. It is
> simply a repeating element. There's no metadata included in each of
> the repeating element to indicate indexing or ordering.

Okay, first of all, when I've been describing arrays, I'm talking  
about arrays on the Java side. I've been treating the SOAP side as a  
black box. I know that Axis is capable of producing a Java array,  
which has the same requirements as a Java List. Thus, I don't need to  
know _anything_ about SOAP or XSD to know that you are wrong. The  
ordering information is there. To give a concrete example, when I do  
a google search with their published WSDL, I get my results in order.  
I simply want that to be a with a List<ResultElement> rather than a  
ResultElement[].

Secondly, of course the XSD does not describe ordering. It doesn't  
need to. When you serialize something as a stream of bytes, you're  
always putting them in order. It's called serialization for a reason.  
The order of the array/list/whatever is the order that the objects  
are written in.

> SOAPpy can easily maps things around because Python is a loosely typed
> language. Java is strongly typed and therefore much more strict about
> mapping types.

If it can map it to a Java ResultElement[] in advance, why can't it  
map it to a Java List<ResultElement> in advance? Strong typing is not  
the problem.

> In any case, if you want to map the returned array to a Java
> collection class, then you must write a custom deserializer that does
> so. You also must define a client config file that tells Axis to use
> your custom deserializer.

How would I write this custom deserializer? All the information I've  
seen on the website - and the articles James Black linked to - seem  
to be talking about registering new types: i.e., a "java.foo.Blah <->  
Blah". I want to change how XSD x[] to map to Java List<x> rather  
than Java x[], for all x.

Once I do that, I'll look into more sophisticated collections: Maps,  
Sets. I don't know if that's possible, but I'd like to try.

Scott

-- 
Scott Lamb <http://www.slamb.org/>


Re: Collections classes?

Posted by Anne Thomas Manes <at...@gmail.com>.
Actually, a list is a specialization of an array, not the other way
around. As James says, a list requires more information than an XSD
type array. An XSD type array has no sense of order or index. It is
simply a repeating element. There's no metadata included in each of
the repeating element to indicate indexing or ordering.

SOAPpy can easily maps things around because Python is a loosely typed
language. Java is strongly typed and therefore much more strict about
mapping types.

In any case, if you want to map the returned array to a Java
collection class, then you must write a custom deserializer that does
so. You also must define a client config file that tells Axis to use
your custom deserializer.

Anne

On 7/4/05, Scott Lamb <sl...@slamb.org> wrote:
> On 3 Jul 2005, at 19:09, James Black wrote:
> 
> 
> > Scott Lamb wrote:
> >
> >
> >> I still do not understand. Why can't I serialize a List with exactly
> >> the same XML representation as an array? And deserialize it back to a
> >> List? Why does the other side have to know anything about this?
> >>
> >>
> >
> >  A list has other attributes besides an array, as it has to know
> > something about order and relationships between items.
> >
> 
> This is nonsense. I don't know the intricacies of SOAP or Axis, but I
> know what arrays and lists are.
> 
> A list is an ordered collection of items.
> 
> An array is an indexed collection of items. Indexed implies ordered.
> Thus, an array is a specialization of list. (In Java, there is an
> ArrayList class. A list represented in memory by an array. It
> supports the exact same operations as LinkedList; the only difference
> is the complexity of some operations. I.e., get(int n) is O(1)
> instead of O(n).)
> 
> Their serialization is the same; you'd write an array in order of
> ascending indexes.
> 
> --
> Scott Lamb <http://www.slamb.org/>
> 
> 
>

Re: Collections classes?

Posted by Scott Lamb <sl...@slamb.org>.
On 3 Jul 2005, at 19:09, James Black wrote:


> Scott Lamb wrote:
>
>
>> I still do not understand. Why can't I serialize a List with exactly
>> the same XML representation as an array? And deserialize it back to a
>> List? Why does the other side have to know anything about this?
>>
>>
>
>  A list has other attributes besides an array, as it has to know
> something about order and relationships between items.
>

This is nonsense. I don't know the intricacies of SOAP or Axis, but I  
know what arrays and lists are.

A list is an ordered collection of items.

An array is an indexed collection of items. Indexed implies ordered.  
Thus, an array is a specialization of list. (In Java, there is an  
ArrayList class. A list represented in memory by an array. It  
supports the exact same operations as LinkedList; the only difference  
is the complexity of some operations. I.e., get(int n) is O(1)  
instead of O(n).)

Their serialization is the same; you'd write an array in order of  
ascending indexes.

-- 
Scott Lamb <http://www.slamb.org/>



Re: Collections classes?

Posted by James Black <jb...@ieee.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott Lamb wrote:
> I still do not understand. Why can't I serialize a List with exactly 
> the same XML representation as an array? And deserialize it back to a 
> List? Why does the other side have to know anything about this?

 A list has other attributes besides an array, as it has to know
something about order and relationships between items.

> 
>>   C does not easily know how to deal with some of the collection  types.
> 
> 
> How is that relevant?

  Because webservices specs were designed to be language independent,
and so it is relevant in that if C can't handle something, then that
feature must be language dependent. If you are writing a webservice that
is only going to be used by Java clients, you could just use RMI instead
of webservices, and then you can pass whatever you want.

> Forget the other side of the transaction. I want to make an isolated 
> change.
> 
> These links you gave me seem focused on registering a new type and 
> providing a way to serialize/deserialize it. I want to change how 
> arrays are serialized.

  The you will need to write a custom serializer/deserializer, since
Axis doesn't provide one for you.

- --
Corruptisima republica plurimae leges. [The more corrupt a republic, the
more laws.]
Tacitus from Annals III, 116AD
Blogs: http://jamesruminations.blogspot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCyJpqJ/zyYkX46joRAltkAJ9AkKl1r3DFYreDrIpC07Fs4mVcpgCdFjS6
AOhizXnMSnCPNMouV8pIQpQ=
=1fEY
-----END PGP SIGNATURE-----

Re: Collections classes?

Posted by Scott Lamb <sl...@slamb.org>.
On 3 Jul 2005, at 01:30, James Black wrote:

> --Since SOAP was written to work with a large number of languages, it
> has to be able to work with a common denominator, what can all of  
> these
> languages work with.

I still do not understand. Why can't I serialize a List with exactly  
the same XML representation as an array? And deserialize it back to a  
List? Why does the other side have to know anything about this?

>   C does not easily know how to deal with some of the collection  
> types.

How is that relevant?

>   You can look at http://docs.pushtotest.com/axisdocs/user-guide.html
> for some information on writing a custom serializer/deserializer, then
> you can get your server and client to send collections across,  
> perhaps.

Forget the other side of the transaction. I want to make an isolated  
change.

These links you gave me seem focused on registering a new type and  
providing a way to serialize/deserialize it. I want to change how  
arrays are serialized.

-- 
Scott Lamb <http://www.slamb.org/>


Re: Collections classes?

Posted by James Black <jb...@ieee.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott Lamb wrote:
> 
> It's not as trivial when you have an entire graph of these objects to 
> deal with. It's certainly possible, but I don't understand why Axis 
> can't just give me what I want rather than requiring me to construct  an
> entirely new object graph and then discard then one that it gave me.
> 

  Since SOAP was written to work with a large number of languages, it
has to be able to work with a common denominator, what can all of these
languages work with.

  C does not easily know how to deal with some of the collection types.

  You can look at http://docs.pushtotest.com/axisdocs/user-guide.html
for some information on writing a custom serializer/deserializer, then
you can get your server and client to send collections across, perhaps.

  I haven't looked through it too carefully, but on a quick glance, this
site may be useful:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.easerver_5.2/html/easws/easwsp29.htm

- --
Corruptisima republica plurimae leges. [The more corrupt a republic, the
more laws.]
Tacitus from Annals III, 116AD
Blogs: http://jamesruminations.blogspot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCx6ITJ/zyYkX46joRAhziAJ4oe1DoPUuyJCr/bRkwpDzHt5pG5QCfZB6w
nGV4icdIhoyRDoC5Na7ujPY=
=tjZG
-----END PGP SIGNATURE-----

Re: Collections classes?

Posted by Scott Lamb <sl...@slamb.org>.
On 2 Jul 2005, at 21:28, James Black wrote:
>> How can I get Axis to use the Java Collections classes? I see in
>> 1.2.1's "What's in this release" section that it says "Automatic two-
>> way conversions between Java Collections and SOAP Arrays". I  
>> don't  see
>> any details, though. How do I use this?
>>
>> Specifically, I'm playing with GoogleSearch.wsdl. The
>> GoogleSearchResult class AXIS has getResultElements() and
>> setResultElements() methods that deal with plain Java arrays -
>> ResultElement[]. I'd prefer collections objects like List or (for   
>> Java
>> 1.5) List<ResultElement>.
>>
>> Is this what this snippet is describing? If not, what does it  
>> mean?  And
>> is there any way to do what I want?
>>
>
>   What benefits would you get by sending the extra data that a
> collection would require?

I'm not proposing a change to the WSDL or to what is sent over the wire.

>   If you send it as an array, and then the client can decide which way
> to use the data, so if a hashmap would make sense for the client,  
> it can
> be stored that way, but, not all clients have collection apis. For
> example, if you use gsoap and a C client, you would need to use  
> arrays.

I'm asking if there's a way I can influence the Java representations  
of SOAP data - both Java types fed into axis and Java types returned  
from it.

Can I get a List<Foo> (an ArrayList<Foo>, perhaps) out of axis rather  
than a Foo[]? And a Map<Foo,Bar> rather than a KeyValueBean[] or  
whatever?

Since you bring up other language implementations, how about SOAPpy:  
It can deal with Python dictionaries natively. Can Axis do that? If  
not, why is it possible for SOAPpy and not Axis?

>   It is trivial to insert the array into a collection, and is simpler
> and more interoperative to transfer arrays of items around than to try
> to pass collections.

It's not as trivial when you have an entire graph of these objects to  
deal with. It's certainly possible, but I don't understand why Axis  
can't just give me what I want rather than requiring me to construct  
an entirely new object graph and then discard then one that it gave me.

-- 
Scott Lamb <http://www.slamb.org/>


Re: Collections classes?

Posted by James Black <jb...@ieee.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott Lamb wrote:
> How can I get Axis to use the Java Collections classes? I see in 
> 1.2.1's "What's in this release" section that it says "Automatic two-
> way conversions between Java Collections and SOAP Arrays". I don't  see
> any details, though. How do I use this?
> 
> Specifically, I'm playing with GoogleSearch.wsdl. The 
> GoogleSearchResult class AXIS has getResultElements() and 
> setResultElements() methods that deal with plain Java arrays - 
> ResultElement[]. I'd prefer collections objects like List or (for  Java
> 1.5) List<ResultElement>.
> 
> Is this what this snippet is describing? If not, what does it mean?  And
> is there any way to do what I want?

  What benefits would you get by sending the extra data that a
collection would require?

  If you send it as an array, and then the client can decide which way
to use the data, so if a hashmap would make sense for the client, it can
be stored that way, but, not all clients have collection apis. For
example, if you use gsoap and a C client, you would need to use arrays.

  It is trivial to insert the array into a collection, and is simpler
and more interoperative to transfer arrays of items around than to try
to pass collections.


- --
Corruptisima republica plurimae leges. [The more corrupt a republic, the
more laws.]
Tacitus from Annals III, 116AD
Blogs: http://jamesruminations.blogspot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFCx2mJJ/zyYkX46joRAjsFAJ0XNDuwiBBp33R9i0zEyqRxk0cfCQCcC/K9
8PZcU0ml5TZP2AKPgPBVBlM=
=o8qj
-----END PGP SIGNATURE-----