users@jaxb.java.net

Re: interleave

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 26 Mar 2009 14:57:22 +0100

As you wrote that elements in the settings list can appear in any order, the
list is one "mixed" list, and not two lists. If define your schema so that
you have one list after the other, elements would have to come in two
distinct sequences. In XML schema that would be, e.g.,

<xs:complexType name="SomeType">
    <xs:sequence>
        <xs:element name="one" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
        <xs:element name="two" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

you'll get two list elements in SomeType. If the list is mixed, it cannot be
separated into two lists, as this would make the original order disappear,
and that might be important.

-W


On Wed, Mar 25, 2009 at 7:57 PM, Jason Sachs <jmsachs_at_gmail.com> wrote:

> I am trying to deal with interleaves (elements in a list that can appear in
> any order) in jaxb, and it seems to work a little funny.
>
> I'm working with a RELAX NG schema that looks like this:
>
> <define name='global-protocol-settings'>
> <element name='settings'>
> <interleave>
> <optional>
> <ref name='default-type-options'/>
> </optional>
> <zeroOrMore>
> <ref name='signal-typedef'/>
> </zeroOrMore>
> </interleave>
> </element>
> </define>
>
> ...
>
> <define name='signal-typedef'>
> <element name='typedef'>
> <attribute name='name'>
> <ref name='identifier'/>
> </attribute>
> <ref name='signal-type'/>
> </element>
> </define>
>
> <define name='default-type-options'>
> <element name='default-type'>
> <ref name='signal-type-options'/>
> </element>
> </define>
>
>
> which Trang converts (somewhat incorrectly perhaps; there's only supposed
> to be 1 default-type-options element allowed) to this snippet of XSD:
>
> ♫
> <xs:element name="settings">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element ref="ns1:default-type"/>
> <xs:element ref="ns1:typedef"/>
> </xs:choice>
> </xs:complexType>
> </xs:element>
>
> where "default-type" and "signal-typedef" are both elements.
>
> The Java class for the "settings" element, that jaxb produces, has a
> getDefaultTypeOrTypedef() method that returns a list of elements that are
> "default-type" and "typedef". This is not what I would expect; what I'd like
> is to have a getDefaultType() method and a getTypedef() method and lists of
> the appropriate elements are returned. Is there something I can do to fix
> this?
>