users@jaxb.java.net

Fwd: Annox plugin.

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 10 Mar 2009 08:41:56 +0100

Hi Avihaimar,

> I need to add annotation to some of my complex types.
> Is there a way to add them by customization?

I'm forwarding my answer. There's an "annotate"plugin which can add
arbitrary annotations to your generated classes.

Please see this example:

https://jaxb2-commons.dev.java.net/source/browse/jaxb2-commons/tests/annotate/

Bye.
/lexi





---------- Forwarded message ----------
From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, Mar 10, 2009 at 7:28 AM
Subject: Re: Annox plugin.
To: users_at_hyperjaxb.dev.java.net


Hi,

> Thanks for giving me the lead. However, I am still getting the same error.
> Your help on this is appreciated.

I've attached a small sample schema. See the full example here:

https://jaxb2-commons.dev.java.net/source/browse/jaxb2-commons/tests/annotate/

Basics:
0. Annotate plugin must be activated.
1. You need annox prefix in the list of jaxb:extensionBindingPrefixes:

<xsd:schema
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
       jaxb:version="2.1"
       xmlns:annox="http://annox.dev.java.net"
       jaxb:extensionBindingPrefixes="annox"
       xmlns:jl="http://annox.dev.java.net/java.lang"<xsd:schema
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
       xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
       jaxb:version="2.1"
       xmlns:annox="http://annox.dev.java.net"
       jaxb:extensionBindingPrefixes="annox"
       xmlns:jl="http://annox.dev.java.net/java.lang">
>

2. You need to declare a namespace or namespaces for you target
package. For instance, for java.lang the declaration is like:

xmlns:jl="http://annox.dev.java.net/java.lang"

3. Use

<annox:annotate>
 <myPackagePrefix:LocalClassName .../>
</annox:annotate>

to produce the required annotation. Like

<annox:annotate>
       <jl:SuppressWarnings/>
</annox:annotate>

will generate java.lang.SupressWarnings annotation.

These are the basics.

Now, the most important for you is that what you are trying to do
simply won't work.
What I see here is that you are trying to annotate your FooType with
@XmlTransient annotation:

> <xsd:complexType name="FooType">
> <xsd:annotation>
> <xsd:appinfo>
> <xsd:annotate>
> <jl:XmlTransient/>
> </xsd:annotate>
> </xsd:appinfo>
> </xsd:annotation>
> <!-- ... -->
> </xsd:complexType>
> </xsd:schema>

This won't work. The annotate plugin adds a new annotation, so you'll
just have an additional @XmlTransient annotation in your class. I
think this will just produce a conflict for JAXB and won't work.

What is the business task you are trying to solve?

Bye.
/lexi