Java Enum with XML Beans?

1.5k views Asked by At

When using Apache XML Beans to generate types from xsd:enumeration types, XMLBeans generates custom classes that are not Java 5 enums but some kind of special class to represent the enumeration.

This might be the case, because XMLBeans is older than Java 5 and there were no enums at the time or you still want to keep Java 1.4 compatibility. However, I would like to get "real" enum types, so my question is: Is there a way to generate Java 5 enums with Apache XML Beans?

(Jaxb does this like I want, but I'm not sure if I want to remove XMLBeans and introduce Jaxb just for that detail.)

1

There are 1 answers

3
AlexR On BEST ANSWER

I do not think you can achieve what what you want with XML beans. You even mentioned the reason yourself. I'd recommend you to move to JaxB.

But if you really wish to continue using XML beans I'd suggest you a patch. You can post-process the generated classes and convert them to enums. I did something like that in past using ant tasks. There are ant tasks that know to perform string replacements, so it is not a problem. In worse case you can implement your own task in java. But I believe you do not have. I think that this is the simplest solution.

Good luck.