Prashant wrote:
> Hello:
>
> I want to generate a "homogenous" lists of my xs:choice elements.
>
> But, I am a little bit confused by JAXB 1.0.X's treatment of unnamed
> xs:choice groups.
>
> Consider following example which is a modified version of
> "bind-choice" sample shipped with JAXB.
>
> Custom binding:
> <jxb:globalBindings bindingStyle="modelGroupBinding"/>
>
> Schema :
> <xs:element name="FooBar">
> <xs:complexType>
> <xs:sequence>
> <xs:choice>
> * <xs:element name="phoneNumber" type="xs:string"
> minOccures="0" maxOcuurs="unbounded"/>
> <xs:element name="speedDial" type="xs:int" minOccures="0"
> maxOcuurs="unbounded"/>
> * </xs:choice>
> </xs:complexType>
> </xs:element>
>
> Generated FooBar Bean contains
>
> public List getPhoneNumberOrSpeedDial() - elements of list are of type
> PhoneNumberOrSpeedDial
>
> PhoneNumberOrSpeedDial{
>
> getPhoneNumber();
> isSetPhoneNumber();
> isSetSeedDial();
> getSpeedDial();
The default binding in JAXB 1.0 would be a List of PhoneNumber and
SpeedDial,
both instances of javax.xml.bind.Element. The element instance remembers
the element name. The binding above avoids elements by binding choice model
group to a class and having those properties retain the element names.
This binding is described in the JAXB 1.0 Specification in Section 5.9.10.1.
Note that this binding was motivated by Castor's binding of choice model
group.
JAXB 2.0 program annotations have a much improved binding for this example.
It maps to a list of String and Integers. A JAXB programming annotation
maps each
type to an element name. Binding roughly looks like this:
@XmlElements( {_at_XmlElement(type=Integer.class, name="speedDial"),
@XmlElement(type=String.class,
name="phoneNumber")})
List<Object> getPhoneNumberOrSpeedDial();
>
> }
>
> Instead is't it simpler for FooBar to contain methods
>
> List getPhoneNumbers();
> List getSpeedDials();
It is important to retain the order of elements. Order matters in XML
documents.
This JAXB binding would lose any ordering that might have been in XML
document
for the choice model group. Above binding matches following schema, not
a repeating occurance choice model group.
<xs:sequence>
<xs:element name="phoneNumbers" maxOccurs="unbounded"/>
<xs:element name="speedDials" maxOccurs="unbounded"/>
</xs:sequence>
-Joe
> The lists would be empty when phone numbers/speeddials donot occur in
> a XML instance.
>
> What was the rational behind current behavior. Am i missing something
> here ?
>
> Is the treatment better in JAX 2.0 ?
-Joe
>
> -Prashant
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>