users@jaxb.java.net

Re: JAXB generated Java Model + JXPath

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 09 Aug 2005 15:51:41 +0200

Hi.

> Seem to have run into some rought weather with RTFS on JAXB RI 1.0.
> Well I did get my CodeAugmenter to be picked up by XJC task.

Maybe you should first try annotations in JAXB 2.0. My knowledge is a
bit shallow there.

>> 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.
>
> So if I understand this correctly, from the AnnotatedGrammer you can get
> list of JavaItem. Each JavaItem contains information on
> GeneratedCodeModel. But How can one access the corresponding
> JavaItemVisitor that has the information on the Schema that was
> responsible for this JavaItem ?

Few hints for you.

Iterate over generated classes:

     final ClassItem[] classItems = grammar.getClasses();
     for (int index = 0; index < classItems.length; index++) {
       final ClassItem classItem = classItems[index];
       final ClassContext classContext =
generatorContext.getClassContext(classItem);
       // ....
     }

Traverse the tree of the class item model:

classItem.visit(new MyVisitor());

Get the fields contained in the class item:

final FieldUse[] fields = classItem.getDeclaredFieldUses();

It might be enough for you to iterate over class items and fields
contained in them. Take a look at the i18n add-on in jaxbcommons.

Bye.
/lexi