users@jaxb.java.net

Generation of Enum type from NMTOKEN restricted type

From: Kenny MacLeod <kennym_at_kizoom.com>
Date: Mon, 12 Mar 2007 16:38:28 +0000

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

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