users@jaxb.java.net

Can't get choiceContentProperty to work with jwsdp-1.5/jaxb

From: Prasad Chodavarapu <chprasad_at_hotmail.com>
Date: Mon, 24 Jan 2005 03:01:52 -0500

Hi All:
Let me explain the problem with the help of an example schema shown below.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
        jxb:version="1.0">

   <xs:annotation>
     <xs:appinfo>
       <jxb:globalBindings
         choiceContentProperty="true"
         bindingStyle="modelGroupBinding"/>

       <jxb:schemaBindings>
         <jxb:package name="com.test"/>
       </jxb:schemaBindings>
     </xs:appinfo>
   </xs:annotation>

   <xs:element name="Foo" type="AChoice"/>

   <xs:complexType name="AChoice">
     <xs:choice>
       <xs:element name="A" type="xs:int"/>
       <xs:element name="B" type="xs:string"/>
     </xs:choice>
   </xs:complexType>
</xs:schema>

The AChoice interface generated by jaxb bundled with jwsdp-1.5 looks as
follows:

public interface AChoice {

  int getA();
  void setA(int value);

  java.lang.String getB();
  void setB(java.lang.String value);
}

The problem with this generated interface is that there's no way to tell if
it A or B that's choosen. I can turn on "generateIsSetMethod" in the
globalBindings but that results in a ton of extra methods everywhere.

What I'm hoping to generate is a method named getContent() as shown in the
example under section 5.9.10.1 of the jaxb 1.0 spec. Or a getAOrB() method
like the ones I've seen being generated for enumerated attributes in some
versions of jaxb-RI. If I can do that, I can check the type of the Obejct
returned by getContent() to figure out if it's A or B that's set. My
attempts to do so by setting choiceContentProperty="true" and
bindingStyle="modelGroupBinding" didn't yield what I was expecting. In fact,
these customizations made no difference what so ever in the generated code.

Please let me know if this is a know issue with or without workarounds or if
I'm missing something.

Thanks in advance
prasad

ps: I've been using jaxb-RT extensively since the 1.0 beta days and I've
always loved it. I've not really tapped into the power of jaxb customization
though as there aren't many examples of real-life customization and as the
spec is quite dry.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net