Given the following xml snippet:
<colors>
<color name="red" favorite="true" />
<color name="green" favorite="false" />
<color name="blue" favorite="false" />
</colors>
I'd like to be able to generate both a class (with jaxb via xsd), but also an enumeration of all known colors. Both the class and the enumeration should implement the same interface.
Interface:
public interface IColor {
String getName();
boolean isFavorite();
}
Class:
public class Color implements IColor {
// *snip*
}
Enumeration:
public enum ColorType implements IColor {
RED("red", true),
GREEN("green", false),
BLUE("blue", false);
private ColorType(String name, boolean isFavorite) {
// *snip*
}
}
I have found some articles that talk about generating classes that implement an interface, e.g. here, but I can't find anything about generating the enumeration. Even worse, I have no idea how to combine both.
Just to clarify where this crazy idea is coming from: The generated class could be used for product code (actually, preferably the interface would be used wherever possible), and the enumeration could be used for testing.
So far I've written some custom code that creates the enumeration manually using Sun's CodeModel, but I'm thinking there should be a smarter way of doing this, no?