users@jaxb.java.net

Re: using annox plugin from within .xjb file

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Fri, 26 Jun 2009 21:44:36 +0200

Hi,

> I'm trying to use the annox plugin to generate some custom java annotations
> for classes generated from a schema. However, unlike all the samples, I
> can't change the particular schema - I have to use the .xjb file to make
> custom bindings. I tried to do the "java.lang" sample that is floating
> around, but I can't even get that to work. Here's some snippets:
>
> <jaxb:bindings
>    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    jaxb:version="2.1"
>    xmlns:annox="http://annox.dev.java.net"
>    jaxb:extensionBindingPrefixes="annox"
>    xmlns:jl="http://annox.dev.java.net/java.lang">
>
> <jaxb:bindings schemaLocation="testschema.xsd" node="/xs:schema">
> <jaxb:bindings node="//xs:element[@name='testnode']">
> <annox:annotate>
> <jl:SuppressWarnings />
> </annox:annotate>
> </jaxb:bindings>
> </jaxb:bindings>
>
> I get:
>      [xjc] [ERROR] Unsupported binding namespace
> "http://annox.dev.java.net/java.lang". Perhaps you meant
> "http://annox.dev.java.net"?
>      [xjc]   line 15 of file:/path/to/testschema.xsd (this is the line that
> has the <xs:element name="testnode">)
>
> Has anyone else run into this issue?

Me.

The problem is that XJC has a bug.

XJC is very restictive, when it comes to customizations. XJC plugins
have to declare namespaces and names of customization elements.
However, theoretically customization elements may have arbitrary
sub-elements, XJC is not supposed to control that. This is indeed so
when customization elements are declared in the schema directly. But
if literaly the same customization elements are declared in bindings
file, XJC complains about unsupported binding namespaces. It's clearly
an inconsistency and I am pretty sure it's just a bug with processing
of binding files.

However, until the bug is fixed (and, ahm, reported first :)), there's
a workaround, You can use annox:annotate/_at_annox:class attribute to
specify the annotation class. I'm attaching and example. This is far
not that elegant as with namespace/package mappings, but this works.

Bye.
/lexi