users@jaxb.java.net

Re: Edit the generated Code

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Mon, 16 Oct 2006 15:48:15 +0200

Hi.

> I'm pretty new in using JAXB, and I have some questions about developing
> using JAXB.
> The problem I met is, the XSD file I used, is still keep changing.
> This makes difficult to edit the JAXB generated Code, while when the XSD
> file is updated, all the changes I made, would be replaced by the
> generated code?
>
> My question is:
> How do people usually develop using JAXB? Do the altering the generated
> Code? Or simply creating a subclass of the generated classes, and
> altering the subclasses?
>
> The solution which I took so far, is by subclassing it in another
> package. But still found some problem when generating the XML files,
> while the JAXBElement created from the Object factory is from the
> package of the generated classes (not the subclasses which I expected).
>
> Can anybody share the experience in developing using JAXB?

My two cents.

Cent one: I generate a lot of things with addons/plugins. Once you master them,
you can really do things that MDA/UML tools could even not dream of.

Cent two: apart from subclassing your class from the schema-derived class (like
you sketched out above) you can also subclass _the_ schema-derived class _from_
your class. This way the object factory will still create instances of generated
classes, but they will bear the inherited functionality from your base classes
that they extend.

I prefer not to edit generated code, never. Sometimes I use JAXB annotations
just manually on my hand-written classes, but I never edit the generated code.

Bye.
/lexi