Saturday, April 14, 2012

JAXB Custom XJC Plugin Limitations

I recently attempted to write my own JAXB XJC plugin which I thought would solve some schema derived code generation enhancements that I wanted to implement. It turns out Custom XJC Plugins are worthless beyond adding code to already defined generated classes or adding new classes. It turns out plugins are only invoked after the schema has been parsed into a schema model (Outline) and after all the JAXB classes have been generated in memory (CodeModel). While it is possible to remove fields from an existing class and perhaps even remove methods one cannot completely redefine a class because the schema and code models have been finalized by the time the plugin is invoked. Instead of having a plugin that could interact with the models at various phases it seems XJC plugins were an afterthought. Additionally I found the XJC code difficult to decipher albeit mapping one typed language to another one is not easy. I can now clearly see why the JAXB project has bugs that have not been addressed in six years. Beyond generating simply utility methods on generated classes expect no further value from writing an XJC Plugin.

No comments:

Post a Comment