Tyler
Tyler

Reputation: 121

How to write an XJC plugin that replaces JClass implementations for types

I have an xsd with some very large enums - if I allow XJC to generate actual Java enums for these types, I run into the problem described here:

Does an Enum Class containing 2000+1 Enum Constants hit any limit?

I do not have control over the xsd, so my solution so far has been to add a binding for XJC to use a String instead of an enum for the type, but this has the obvious downsides that it lacks enforced schema compliance and referencing specific enum values in code is challenging.

I started trying to write an XJC plugin to implement the type as a class with a bunch of static constants, but the documentation on XJC plugins is scant and as far as I can tell, the Outline that I have access to in the run method of the Plugin interface doesn't allow you to replace the JClass associated with a type. It seems like this plugin step might be too late in the process, and that I need to intervene during bean generation somehow, but I don't know what I need to implement and bind to make that happen.

Upvotes: 0

Views: 27

Answers (1)

Rick O'Sullivan
Rick O'Sullivan

Reputation: 476

This postProcessModel(Model model) method is an example that shows how to process the XJC model at an earlier stage.

Upvotes: 0

Related Questions