axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Keese <bi...@tech.beacon-it.co.jp>
Subject Re: xsd:choice (and WSDL2Java)
Date Mon, 28 Feb 2005 00:33:30 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-2022-JP"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hmm, too bad.&nbsp;&nbsp; I looked at using Castor too.&nbsp; I think Castor's
generated code works, although the generated classes are cumbersome to
use because you need to do if / else if / else if blocks to find out
what kind of element is in the choice node.&nbsp; (They are changing that
now, though.)&nbsp; Eventually I just wrote my own serializer/deserializer.<br>
<br>
Michael Thome wrote:
<blockquote cite="mid421F6A2F.60207@bbn.com" type="cite">
  <meta content="text/html;charset=ISO-2022-JP"
 http-equiv="Content-Type">
  <title></title>
Down the rat hole we go...<br>
  <br>
At first glance, the below looked like it was going to work, but the
serialization/deserialization code emitted by wsdl2java with this
approach incorrectly turns the groups into named elements!&nbsp;&nbsp; This
leaves us in a state where the deserializer (for instance) recognizes a
different language that what the schema specifies.&nbsp; For example:<br>
if your schema has:<br>
&lt;element name="filter" type="FilterList"/&gt;<br>
then a validating parser will except:<br>
&lt;filter&gt;&lt;or/&gt;&lt;and/&gt;&lt;or/&gt;&lt;/filter&gt;<br>
but the wsdl2java generated code will only accept:<br>
&lt;filter&gt;&lt;FilterElement&gt;&lt;or/&gt;&lt;/FilterElement&gt;&lt;FilterElement&gt;&lt;and/&gt;&lt;/FilterElement&gt;&lt;FilterElement&gt;&lt;or/&gt;&lt;/FilterElement&gt;&lt;filter&gt;<br>
  <br>
sigh.<br>
  <br>
Michael Thome wrote:
  <blockquote cite="mid421F5530.4010600@bbn.com" type="cite">
    <meta content="text/html;charset=ISO-2022-JP"
 http-equiv="Content-Type">
    <title></title>
OK - I *think* I have a solution.&nbsp; The following seems to allow me to
(a) avoid changing the document syntax, (b) validation/parsing works
properly, and (c) wsdl2java seems to generate sane code.&nbsp; The cost is
some minimal extra complexity in the schema and an extra generated java
class.<br>
    <br>
    <blockquote><tt>&lt;complexType name="FilterList"&gt;</tt><br>
      <tt>&nbsp; &lt;sequence&gt;</tt><br>
      <tt>&nbsp;&nbsp;&nbsp; &lt;group ref="FilterElement" minOccurs="0"
maxOccurs="unbounded"/&gt;</tt><br>
      <tt>&nbsp; &lt;/sequence&gt;</tt><br>
      <tt>&lt;/complexType&gt;</tt><br>
      <br>
      <tt>&lt;group name="FilterElement"&gt;</tt><br>
      <tt>&nbsp; &lt;choice&gt;</tt><br>
      <tt>&nbsp;&nbsp;&nbsp; &lt;element name="and" type="query:AndFilter"/&gt;</tt><br>
      <tt>&nbsp;&nbsp;&nbsp; &lt;element name="or" type="query:OrFilter"/&gt;</tt><br>
      <tt>&nbsp;&nbsp;&nbsp; &lt;element name="not" type="query:NotFilter"/&gt;</tt><br>
      <tt>&nbsp; &lt;/choice&gt;</tt><br>
      <tt>&lt;/group&gt;</tt><br>
    </blockquote>
    <br>
Essentially, wsdl2java ignores min/max on sequence and choice (and
probably any), but does the right thing when applied to element and
group refs.<br>
    <br>
You'll get an intermediate class, of course, leaving you with something
like:<br>
    <blockquote><tt>class FilterList {<br>
&nbsp; FilterElement[] filterElement;<br>
}<br>
class FilterElement {<br>
&nbsp; AndFilter andFilter;<br>
&nbsp; OrFilter orFilter;<br>
&nbsp; NotFilter notFilter;<br>
}<br>
      </tt></blockquote>
At first glance, at least, this seems to be a reasonable match for the
intent.<br>
    <br>
    <br>
Michael Thome wrote:
    <blockquote cite="mid421F3FF5.8070004@bbn.com" type="cite">
      <meta content="text/html;charset=ISO-2022-JP"
 http-equiv="Content-Type">
      <title></title>
Ack - you are correct.&nbsp; I only looked at the generated code (which
looks fine) and tried validating against an example that turned out to
be too simple.<br>
      <br>
Now I don't know... Any workaround would be extremely welcome, as I
need this to work, also.<br>
      <br>
I really don't want to have to put more tags in, e.g. What ought to
work is something like:<br>
      <blockquote>
        <pre wrap=""><tt>&lt;complexType name="FilterList"&gt;
  &lt;sequence&gt;
    &lt;element name="bogus" </tt><tt>minOccurs="1" maxOccurs="unbounded"</tt><tt>&gt;
      &lt;complexType&gt;
       &nbsp;&lt;choice&gt;
          &lt;element name="and" type="query:AndFilter"</tt><tt>/&gt;
          &lt;element name="or" type="query:OrFilter"</tt><tt>/&gt;
          &lt;element name="not" type="query:NotFilter"</tt><tt>/&gt;
        &lt;/choice&gt;
       &lt;/complexType&gt;
    &lt;/element&gt;
  &lt;/sequence&gt;
&lt;/complexType&gt;

</tt></pre>
      </blockquote>
but the I'd have to do:<br>
      <blockquote>
        <pre wrap=""><tt>&lt;list&gt;
  &lt;bogus&gt;&lt;and/&gt;&lt;/bogus&gt;
  &lt;bogus&gt;&lt;or/&gt;&lt;/bogus&gt;
  &lt;bogus&gt;&lt;and/&gt;&lt;/bogus&gt;
&lt;/list&gt;
</tt></pre>
      </blockquote>
      <br>
Ugh.<br>
      <br>
Bill Keese wrote:
      <blockquote cite="mid421E6D65.5040000@tech.beacon-it.co.jp"
 type="cite">
        <meta content="text/html;charset=ISO-2022-JP"
 http-equiv="Content-Type">
Mik,<br>
        <br>
Thanks for the answer.&nbsp; But I think your work around won't permit data
like this:<br>
        <br>
&nbsp; &lt;list&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;and&gt;...&lt;/and&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;or&gt;...&lt;/or&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;not&gt;...&lt;/not&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;and&gt;...&lt;/and&gt;<br>
&nbsp; &lt;/list&gt;<br>
        <br>
Ie, I want to make lists containing different kinds of elements.&nbsp; With
your solution I'm restricted to a list containing one type of
element.&nbsp;&nbsp;&nbsp;&nbsp; (Or to put it another way - I want something
like a java
Collection)<br>
        <br>
Michael Thome wrote:
        <blockquote cite="mid421DF026.3070506@bbn.com" type="cite">
          <meta content="text/html;charset=ISO-2022-JP"
 http-equiv="Content-Type">
          <title></title>
Having just gone through a similar exercise:<br>
1. I think the correct approach ought to be to attach the min/max
attributes to the choice rather than to the sequence - e.g. you want a
single sequence of any number of a choice of {and,or,not} elements, not
any number of sequences of a single choice. <br>
2. but: although both can be used perfectly fine with the expected
documents and validation, wsdl2java appears to silently ignore min/max
attributes on non-element declarations.<br>
3. A search of Jira shows several relevant outstanding bugs: <br>
          <a class="moz-txt-link-freetext"
 href="http://issues.apache.org/jira/browse/AXIS-236">http://issues.apache.org/jira/browse/AXIS-236</a><br>
          <a class="moz-txt-link-freetext"
 href="http://issues.apache.org/jira/browse/AXIS-600">http://issues.apache.org/jira/browse/AXIS-600</a><br>
          <br>
Until fixed, I think the only way to work around the problem is by
putting the min/maxOccurs on the elements, e.g:<br>
          <blockquote>
            <pre wrap=""><tt>&lt;complexType name="FilterList"&gt;
  &lt;sequence&gt;
    &lt;choice&gt;
      &lt;element name="and" type="query:AndFilter"</tt><tt> minOccurs="1"
maxOccurs="unbounded"</tt><tt>/&gt;
      &lt;element name="or" type="query:OrFilter"</tt><tt> minOccurs="1" maxOccurs="unbounded"</tt><tt>/&gt;
      &lt;element name="not" type="query:NotFilter"</tt><tt> minOccurs="1"
maxOccurs="unbounded"</tt><tt>/&gt;
    &lt;/choice&gt;
  &lt;/sequence&gt;
&lt;/complexType&gt;
</tt></pre>
          </blockquote>
cheers,<br>
&nbsp;&nbsp;&nbsp; mik<br>
          <br>
          <br>
Bill Keese wrote:
          <blockquote cite="mid421AF096.2090008@tech.beacon-it.co.jp"
 type="cite">
            <pre wrap="">It looks like WSDL2Java doesn't support xsd:choice for Axis
1.2. Can
anyone confirm/deny this?

I had a declaration like this:
&lt;complexType name="FilterList"&gt;
&lt;sequence minOccurs="1" maxOccurs="unbounded"&gt;
&lt;choice&gt;
&lt;element name="and" type="query:AndFilter"/&gt;
&lt;element name="or" type="query:OrFilter"/&gt;
&lt;element name="not" type="query:NotFilter"/&gt;
&lt;/choice&gt;
&lt;/sequence&gt;
&lt;/complexType&gt;

I expected the generated java code to look like this:
class FilterList {
Filters[] filters;
}

But instead it's a strange class like below. The problem w/the class
below is that you can't have a FilterList containing two or more "and"
nodes.

public class FilterList implements java.io.Serializable {
private jp.co.beacon_it.inicio.client.soap.schema.query.AndFilter and;
private jp.co.beacon_it.inicio.client.soap.schema.query.OrFilter or;
private jp.co.beacon_it.inicio.client.soap.schema.query.NotFilter not;
...
}
  </pre>
          </blockquote>
        </blockquote>
      </blockquote>
    </blockquote>
  </blockquote>
</blockquote>
</body>
</html>

Mime
View raw message