Ben Gidley wrote:
> I had a look into writing a plugin to 'move' the annotation from the
> properties to the get method - as this would solve our problem. However I
> can't see a way of removing the existing annotations from the code model -
> only adding new ones.
The current approach, like the one Hanson took a few days ago, is to
take what XJC generated as granted and add more code. CodeModel is
designed for such augmentation. But it's not really designed to remove
the already generated code.
This is where FieldRendererFactory, a recent change to the JAXB RI,
comes into play. Implementing custom FieldRendererFactory allows a
plugin to completely take over the code generation process. XJC will
first build the "Model", which is the blueprint of what generated code
should look like --- such as what classes to generate, what properties
to generate, what are names/types of them, are they map to elements, etc.
FieldRenderers take this blueprint and actually turn them into the
CodeModel tree. So by taking this process over, you can do all sorts of
wildly different code generation, such as
1) moving annotations to methods
2) not generating methods at all and just public fields
Most likely instead of writing FieldRenderers from scratch, we'd like
you to be able to subclass existing code and tweak its behavior. This
change was made recently, so probably many of the FieldRenderers aren't
quite written to allow easy subclassing, but I'm hoping that you can
point those to us, and we can fix them.
I think this approach has a lot of interesting applications, but if this
seems like too big an attempt, we can also try to experiment with
allowing you to remove JAnnotationUse that are on JAnnotatable.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com