users@jaxb.java.net

Re: Customization help needed

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 23 Feb 2010 20:09:06 +0100

Using reflection, you can analyze the xjc-generated classes. You can use
this technique to generate an additional factory method class where objects
are created using values for all members. Or you can insert the additional
constructor using the technique outlined below.

Adding a hand-written toString() method can be done using the extension
plugin mentioned by David. But you can generate the code based on the
reflected info obtained from the first xjc run, create an external bindings
file containing this code, and re-run xjc.

The same goes for the max/min and similar validations. Reflection should
tell you where such pairs exist, and you can insert the generated code with
the extension plugin in the second xjc run.

-W


On Tue, Feb 23, 2010 at 7:35 PM, Belliveau, Francis - 0995 - MITLL <
belliveau_at_ll.mit.edu> wrote:

> To all who read this: Thanks for trying to help.
>
> I am working on a project that uses XML files to communicate between two
> applications. One application is basically a GUI that interfaces with a
> relational database to create, and reuse, configuration objects for a
> simulation application. JAXB is used to write and read the XML files.
>
> What we seem to need most are some extras in the generated Java classes.
> Most important are:
> 1. A Constructor that has an argument for each member variable.
> 2. A custom toString() method.
>
> Of lesser importance would be additional validation logic.
> For Example: In a “range” class that contained both “max” and “min”
> members, you would not only want to restrict the values allowed for each
> member, but you would also want to restrict the values such that “max>=min”.
>
> I have looked through the entire tutorial and find that this kind of thing
> is totally missing from the “customization” concept. If I could create my
> own tags that took XSLT transforms or something, things would be great.
>
> Having such extensions would greatly reduce our maintenance efforts. Of
> special importance would be to have the constructor(s) generated
> automatically since the JAXB logic knows all the member arguments.
>
> Is there any possibilities for such enhancements?
>
> Thanks,
> Fran
>