I'd like to create two separate JAXB packages from the same XSD where the implementation classes of one package are mutable and the other's are immutable. Naturally, I'd like every pair of implementation classes from the two packages to implement a shared interface.
For example, the following resulting structure would be ideal:
my.model.Model
- Read only interface
my.model.impl.ModelImpl implements my.model.Model
- Mutable implementation
my.model.immutable.Model implements my.model.Model
- Immutable implementation
Creating the interfaces and mutable implementations is simple enough using the generateValueClass="true"
option of the globalBindings
XJB element.
As for the immutable implementation, It doesn't seem that XJC can accomplish this out-of-the-box, and I'd probably need to fork the immutable-xjc plugin for my own purposes.
Writing a XJC plugin which causes generated classes to implement a required interface is easily done (as is hiding the enum classes which are redundant for the immutable package), however, I'm quite stuck in trying change the JAXB model by removing existing fields and adding them with other types. Even given lexicore's useful answer here, it's still not clear to me where such changes should be make on the Codemodel model in order for XJC to pick up those changes and continue as usual, or even if such functionality is possible.
Is a comprehensive guide to using Codemodel in XJC plugins available anywhere?
Or better yet, is there a different way of accomplishing this?