users@jaxb.java.net

Re: JAXB generated Java Model + JXPath

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 03 Aug 2005 08:53:05 -0700

Aleksei Valikov wrote:
>> What is a beatiful way to get this information ?
>
> I have researched the possibility of applying JXPath to JAXB-generated
> classes few month ago and I'm glad that someone follows the same route.
> That would be a very nice extension. ;)

+1.

But I recommend Prashant to consider it for 2.0. It's a lot easier to do
this with 2.0. For example ...

> Here's a small roadmap for you.
>
> The information about mapping between elements/attributes and
> classes/properties is almost unavailable after the schema is compiled.
> Therefore you'll have to write an add-on (a CodeAugmenter, actually) to
> generate your very custom NodePointer, NodeIterator and
> NodePointerFactory implementations alongside with classes generated by JAXB.

With 2.0 everything necessary is already capture in annotation. You just
need to use them. You can even rely on RI's internal data model instead
of parsing annotations on your own.



> CodeAugmenters are provided with AnnotatedGrammar object instance, which
> is richly filled with information on what is what. JAXB organizes the
> processed schema as a tree of expressions and the easiest way to
> traverse the tree (while generating Node** things you need) is to use
> visitors, for instance ExpressionVisitor and JavaItemVisitor. They have
> methods like onElement(ElementExp exp), where ElementExp will carry the
> information you actually need to understand how was this element
> actually called in the schema. From the other side, you have also
> onClass/onField where you get ClassItem and FieldItem. Having these
> objects you may determine how is this schema construct represented with
> classes or properties.

In 2.0 this is rather different, and I'm hoping that it's easier with 2.0.

There's also a little documentation at
http://weblogs.java.net/blog/kohsuke/archive/2005/06/writing_a_plugi.html




-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com