users@jaxb.java.net

Choices with unbounded maxOccurs

From: Michael Figurin <michael.figurin_at_BORLAND.COM>
Date: Sat, 02 Aug 2003 05:00:11 -0600

Hi,

I've applied jaxb to the schema containing a lot of fragments like the
following:

  <xs:complexType name="Base">
   <xs:choice maxOccurs="unbounded">
    <xs:element name="A" type="xs:string"/>
    <xs:element name="B" type="xs:string"/>
   </xs:choice>
  </xs:complexType>


jabx generates code like the following:

  public interface Base {
   interface A extends javax.xml.bind.Element {
    String getValue(); void setValue(String);}
   interface B extends javax.xml.bind.Element {
    String getValue(); void setValue(String);}
   List getAOrB();
  }

I need to look through the list and apply either actionA or actionB to each
child depending on it's type (the ordering between the children elements is
not significant). I guess it's rather typical use case. Some "choice"
constructions contain not just A and B but dozens of child elements. I have
to write a lot of the routine code. Can I customize jaxb code generator in
such a way that jaxb would generate the code more appropriate for my task?

For instance, jaxb could optionally generate interfaces and stub
implementation of the corresponding "visitor" pattern.

Thanks,
Michael