users@jaxb.java.net

Re: Multiple internal lists for xs:choice mapping?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 16 Aug 2005 10:59:23 -0700

The attached FilterList class allows you to do what you want.

Given a heterogeneous list of B,C,D, and E, it gives a live updatable
view limited to just one type. You'd do:

   List list = obj.getBorCorDorE();
   List bList = new FilterList(list,B.class);

bList and list shared the underlying storage, so any change you made on
one side is going to be visible on the other side.

I have a few utility code like this, and I'm wondering where to put
them. If other people are interested in contributing those little code
pieces, maybe we should have the jaxb-utils project.

Brian Sam-Bodden wrote:
> Hi,
> I have a schema with an element A which has a complexType using xs:choice as follows:
>
> <xs:element name="A">
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element ref="B"/>
> <xs:element ref="C"/>
> <xs:element ref="D"/>
> <xs:element ref="E"/>
> </xs:choice>
> <xs:attribute name="name" type="xs:string"/>
> <xs:attribute name="id" type="xs:string"/>
> <xs:attribute name="parent-name" type="xs:string"/>
> <xs:attribute name="parent-id" type="xs:string"/>
> </xs:complexType>
> </xs:element>
>
> Of course the generated Java code for ModelType contains code like:
>
> List getBOrCOrDOrE();
>
> What I would like to do is have 4 separate List objects for B, C, D, and E.
>
> e.g.
>
> List getBs();
> List getCs();
> List getDs();
> List getEs();
>
> Is this possible?
>
> Thanks.
>
> Brian
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com