Sorry for the delay in response.
Sachith Dhanushka wrote:
> Hi,
>
> I am trying to look at a set of JAXB2 generated classes using JAXB2
> reflection library and generate a schema
> model. The schema model is specific to the project I am working now.
>
> 1. In doing so, I have a problem in identifying Choice vs MinOccurrs=0. Say
> for exmapl I see a class which has two properties, both having
> required=false (or required attribute is not annotated). How can I know
> whether I should put these two attributes under a Choice element in the
> schema or put under Sequence and set MinOccurrs=0?
Accroding to the JAXB spec, two properties never get grouped by a
choice. It's always sequence with two optional properties.
> Can I assume both are semantically correct?
No. They are different constraints.
> 2. Again I start with a schema which has a simple type defined to define a
> restriction. How can I deduce this by looking at the generated JAXB2 code?
> Take for example following schema fragment.
>
> <xs:element name="bookCategory">
> <xs:simpleType>
> <xs:restriction base="xs:NCName">
> <xs:enumeration value="magazine" />
> <xs:enumeration value="novel" />
> <xs:enumeration value="fiction" />
> <xs:enumeration value="other" />
> </xs:restriction>
> </xs:simpleType>
> </xs:element>
>
> Having generated code for this I can only see following.
>
> @XmlElement(required = true)
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
> protected String bookCategory;
>
> How can I deduce the restriction by looking at this java code?
You can't. Schema compilation doesn't always capture the full original
schema. It's bit like trying to translate from English to Japanese back
to English. When you do that, the sentence will be surprisingly different.
If you'd like to retain those information, you perhaps need to write a
plugin and capture them into your own annotation that your schema
generator can then read.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com