3

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.)

Tim Büthe
  • 62,884
  • 17
  • 92
  • 129

1 Answers1

1

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.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Thanks for your answer. Yes, I mentioned the reason why they initially not included this. However, I would expect that they could have added some flag to enable Java 5 features. – Tim Büthe Feb 10 '11 at 08:20
  • :( you know what? I thought again and now I think that probably even if this flag does not exist you can fix the problem. I am not sure but typically code generation in jakarta projects is done using velocity. If it is correct the project should contain velocity templates for each type of class. Probably you can change the template that deals with enums? – AlexR Feb 10 '11 at 10:08
  • I don't know if they use velocity, but I could change the class in some post processing doing search-replace operations. The thing is, I would need to all the classes using that enum too. I'm not sure if the whole thing is worth the hustle. – Tim Büthe Feb 11 '11 at 10:09