[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] XML attribute mapping to Java 5 Enum
|
For the ones interested in Java 5 enum conversion. We did this as follows:
We added an afterload method that adds an EnumTypeConverter.
It is important that the value of in the type attribute in XML matches
the name of the Java enum.
By the way, is this the only way to do this? We couldn't find a way to
get this done in the workbench.
See below for the details.
public static void valueAfterLoader(ClassDescriptor valueDescriptor) {
//enum conversion
DatabaseMapping mapping =
valueDescriptor.getMappingForAttributeName("type");
EnumTypeConverter converter = new EnumTypeConverter(mapping,
ValueType.class, false);
((XMLDirectMapping) mapping).setConverter(converter);
}
XML:
<Value type="Maximum" value="80"/>
public enum ValueType {
Maximum("Maximum"), Minimum("Minimum"), Nominal("Nominal");
private final String description;
private ValueType(String description) {
this.description = description;
}
public String value() {
return description;
}
public String toString() {
return description;
}
}