users@jaxb.java.net

Re: Identifying anon simple types

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 12:30:46 -0700

Sachith Dhanushka wrote:
> Hi,
>
> I have an anon simple type defined as the following.
>
> <xs:complexType name="bookType">
> <xs:sequence>
> ........
> <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>
> </xs:sequence>
> ..........
> </xs:complexType>
>
> When I generated JAXB2 classes for the above schema, I get the Booktype
> class with bookCategory attribute. The annotation of book category is
>
> @XmlElement(required = true)
> @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
>
> I am writing piece of code to look at the generated
> classes and re-generate the schema. In the case how can I look at the
> above annotations and deduce the anonymous simple type. Annotations
> simply refer to a String adapter class without enums.

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