users@jaxb.java.net

Re: XML element polymorphism??

From: Malachi de AElfweald <malachi_at_EOTI.ORG>
Date: Wed, 23 Jul 2003 12:30:49 -0600

Hmmm. I'm having a hard time getting this to work. With JWSDP1, I used to specify the annotation for each element, and it created a seperate get method for each. I prefer the new way, where one method gets them all, but can't seem to change the method name...

The following snippet is creating the method:
   List getNewOrCancelOrModify()
....
 <xsd:complexType name="taskmanIntf">
  <xsd:choice minOccurs="1" maxOccurs="unbounded">
   <xsd:annotation>
    <xsd:appinfo>
     <jaxb:property name="tasks"/>
    </xsd:appinfo>
   </xsd:annotation>
   <xsd:element name="new" type="newTask"/>
   <xsd:element name="cancel" type="cancelTask"/>
   <xsd:element name="modify" type="modifyTask"/>
   <xsd:element name="query" type="queryTask"/>
   <xsd:element name="results" type="queryResults"/>
  </xsd:choice>
 </xsd:complexType>



On Mon, 2 Jun 2003 08:30:55 -0700, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM> wrote:
>I think one possibility is to define your schema as:
>
><xsd:complexType name="MTXFile">
> <xsd:sequence>
> <xsd:element name="minVersion" type="xsd:int" />
> <xsd:choice>
> <xs:annotation><xsd:appinfo>
> <jaxb:property name="Matrix" />
> </xsd:appinfo></xsd:annotation>
> <xsd:element name="matrix2DGrid" type="Matrix2DGrid" />
> <xsd:element name="matrix3DGrid" type="Matrix3DGrid" />
> ...
> </xsd:choice>
> </xsd:sequence>
></xsd:complexType>
>
>The property customization will map the choice into a single property,
>so you can just say:
>
> mtxFile.setMatrix( new Matrix3DGrid() );
>
>or
>
> mtxFile.setMatrix( new Matrix2DGrid() );