Hi there,
When compiling the following simpleType with the XJC compile (from the JAXB package)...
<xs:simpleType name="test">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumClass/>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="4">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumMember name="FOUR"/>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="6">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumMember name="SIX"/>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
I end up with the following enum in Java (import statements and comments removed)
@XmlEnum
public enum Test {
@XmlEnumValue("4")
FOUR("4"),
@XmlEnumValue("6")
SIX("6");
private final String value;
Test(String v) {
value = v;
}
public String value() {
return value;
}
public static Test fromValue(String v) {
for (Test c: Test.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v.toString());
}
}
This is exactly what I want... except for the public String value()
method. I would expect the method to be called public String getValue()
according to Sun's naming conventions. That way I can easily use it in a JSP-page using EL. Now I have to work my way around it.
Does anybody have any experience in further tweaking the XJC compilation to a more useful enumeration with a getValue()
method, instead of a value()
method? Or can I add a method or something?
P.S. This occurred in v2.0.3 of JAXB. I downloaded the latest version v2.1.8 and it's the same there...