users@jaxb.java.net

Re: Generation of Enum type from NMTOKEN restricted type

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 13 Mar 2007 09:49:44 -0700

Kenny MacLeod wrote:
> I have a schema with a number of similar complex type defintions, all of
> which are intended to have XJC turn them into java5 enums. However,
> only some of them are generating enums, the rest are being bound as raw
> Strings.
>
> The only difference I can spot is that the type that aren't binding have
> values which start with numeric characters. Does XJC treat these
> differently?

Yes.

> This would be understandable, since you java5 enum values
> can't start with a number, but why doesn't XJC use @XmlEnumValue to map
> these values to mutated java type names?

Mapping a simple type is enum is not always necessarily helpful, and
generally speaking we refrain from making up names from nowhere. So I
think the spec just decided to avoid doing that.

You can use:

   <globalBindings typesafeEnumMemberName="generateName" />

to force XJC to generate names. But beware what it generates...

>
> Here is an example type:
>
> <xsd:simpleType name="ReportTypeEnumeration">
> <xsd:restriction base="xsd:NMTOKEN">
> <xsd:enumeration value="27_0"/>
> <xsd:enumeration value="unknown"/>
> <xsd:enumeration value="27_1"/>
> <xsd:enumeration value="incident"/>
> <xsd:enumeration value="27_1_Alias_1"/>
> <xsd:enumeration value="general"/>
> <xsd:enumeration value="2_27_1_Alias_2"/>
> <xsd:enumeration value="operator"/>
> <xsd:enumeration value="2_27_1_Alias_3"/>
> <xsd:enumeration value="network"/>
> <xsd:enumeration value="27_3"/>
> <xsd:enumeration value="route"/>
> <xsd:enumeration value="27_2"/>
> <xsd:enumeration value="stationTerminal"/>
> <xsd:enumeration value="27_2_Alias_1"/>
> <xsd:enumeration value="stopPoint"/>
> <xsd:enumeration value="27_2_Alias_2"/>
> <xsd:enumeration value="connectionLink"/>
> <xsd:enumeration value="27_2_Alias_3"/>
> <xsd:enumeration value="point"/>
> <xsd:enumeration value="27_4"/>
> <xsd:enumeration value="individualService"/>
> <xsd:enumeration value="27_255"/>
> <xsd:enumeration value="undefined"/>
> </xsd:restriction>
> </xsd:simpleType>
>
>
> Could XJC be altered to generate java5 enum types like:
>
> @XmlEnumValue("27_0")
> X_27_0
>
>
> kenny
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com