users@jaxb.java.net

Re: JAXB/XJC generated annotations and xs:documentation

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Sat, 9 May 2009 08:09:29 +0200

Hi,

> I have a schema that I'm successfully compiling and using with XJC. I'm
> wondering if I can utilize the schema xs:documentation tags as annotations
> in the generated Java code. For instance, I'd like to see something like the
> following java code from the following schema snippet.
>
> I've attempted to write an xjc plugin that iterates through classes and
> finds documentation via
> ClassOutline.target.getSchemaComponent().getAnnotation().getAnnotation().getDocumentation(),
> but I can't get the lang attribute that way and I can't seem to figure out
> how to do the same thing for fields. I've also looked at the annotate
> commons project, but it only deals with custom appinfo.

Essentially, annotate plugin would do what you want, the only problem
is that you want to parse xs:documentation elements instead of custom
appinfo. So the only thing you have to figure out is how to get
original DOM elements for documentation from XSComponent.
After some checking of code I'd say this is not possible at the
moment. XJC uses its own annotation parser to parse annotations into
BindInfos, documentation is presented by the
com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.Documentation
class.

First problem is that this class only stores mixed content of the
original annotation element, no attributes (say goodbye to xml:lang).
Second problem is that BindInfo converts these contents to string,
there is no way to retrieve the original content (which can be text
and DOM elements).

Both problems can be solved if you extend XJC, but I'm not sure if it worths it.

Bye.
/lexi