users@jaxb.java.net

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

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 25 Jan 2005 09:12:08 -0800

Prasad Chodavarapu wrote:
> 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.

choiceContentProperty="true" and bindingStyle="modelGroupBinding" should
have produced the getContent() method that satisfies your needs.

I'll try your schema, but meanwhile please file a bug.


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

In 2.0, we'll just generate:

        class AChoice {
                @XmlElement Integer a;
                @XmlElement String b;
                public Integer getA() { return a; }
                public void setA(Integer v) { a=v; }
                ...
        }

and you can add any methods you like, including:

        class AChoice {
                Object getContent() {
                  return (a!=null)?a:b;
                }
                ...
        }

and it will still work.

> 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.

Have you looked at the samples in the distribution? Did it not help?

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net