dev@jaxb.java.net

Re: Migrating a large JAXB v1.x project to JAXB v2.x & interfaces

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 16 Nov 2006 11:19:37 +0100

Hi.

> Hi. I've read through the FAQ, the specification, and a bunch of the
> mailing list archives. I realize that the JAXB v1.x generated
> interfaces were done away with, and I understand the motivation. Still,
> there's this small matter of a few thousand references to those
> interfaces in our existing code base. It's just not practical to
> migrate them all right now.
>
> At least as a transitional step, I'd like to generate those interfaces
> just so the code compiles and work can continue identifying the
> feasibility of moving to JAXB2. A plug-in seems to be the approach to
> take. Currently I have a development project open where I have a
> skeletal plugin that just prints out stuff like the target directory for
> class generation, the class type name and it's package name. Ok, good
> so far. Here's what I (think I) still need to do:
>
> 1) Set an additional interface for each generated class. Assuming "co"
> is a ClassOutline instance, this seems to work:
>
> co.implClass._implements(MyNewInterface.class);
>
> Unfortunately that only works for interface classes that already exist.
> Since I'm generating them dynamically, that doesn't work too well. I
> see there's an overloaded method that takes a JClass, but the means for
> creating one is sending me in circles.
>
> Question 1: How can I specify the name of an interface for a JAXB
> generated class when that interface does not exist? I'd like to be able
> to specify the interface simply as a String if possible.

codeModel.ref("com.acme.foo.MyNonExistingClass");

If the class does not exist (i.e. can't be loaded with Class.forName(...)) then
you'll get the JDirectClass instance, which is a valid JClass.

But since I guess you'll be actually _generating_ the interface with the code
model, just use the generate interface (this will be of the JDefinedClass).

> 2) In order to generate the interface, I need to know the public methods
> of each generated class. Any pointers on how I can retrieve that
> information starting w/a ClassOutline instance?

Ehm... what's w/a?

Well, you can get a collection of methods from JDefinedClass (these are the
classes generated with this code model i.e. produced by JAXB):

myDefinedClass.methods()

will get you a collection of JMethod instances. JMethod has a number of further
public methods to give you name, param types etc.

If you wish, take a look at one of my plugins:

https://hyperjaxb3.dev.java.net/source/browse/hyperjaxb3/tools/src/main/java/org/jvnet/hyperjaxb3/plugin/

They'll get you clues to your questions.

Bye.
/lexi