users@jaxb.java.net

Re: global customization in Java-first approach

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 01 Mar 2007 09:45:58 -0800

Levi Purvis wrote:
> Does anyone know of a way to apply global customization patterns in
> the Java-first approach? Or a plug-in point to create an extension
> for this?
>
> For example, lets say I always wanted my schema types to start with a
> capital letter. Currently, I'd do this:
>
> @XmlType(name="Foo")
> class Foo {}
>
> @XmlType(name="Bar")
> class Bar {}
>
> Instead of adding these annotations to every class, I'd rather create
> a "plug-in" that changes the default behavior. Is anything like this
> possible with the Java-first approach?
>
> I'd like to do the same thing with Collections, make them always
> include an implicit @XmlElementWrapper.

Yes. You can implement
com.sun.xml.bind.v2.model.annotation.AnnotationReader, through which the
JAXB RI reads JAXB annotations. Normal implementation of this simply
delegates to the reflection library, but you can have this method return
any annotation you want, so that JAXB RI sees annotations that you
didn't actually place on classes.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com