users@jaxb.java.net

Re: Plugin to change JAXB 2.0 default values behavior

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 08 Sep 2005 10:50:49 -0700

Scott Allan wrote:
> I am trying to build this into my ejb3 plugin and when I get it working,
> I will create a separate plugin just for the defaults. I'll let you
> know when they are ready to be published.

OK.

> My goal is to have an annotation in the schema at the class level such
> as <ejb3:setDefaults/> which would tell the plugin to check for default
> values and set them in the beans such as:
> protected String test="testvalue";

If you make it a separate plugin, you can make it so that the said
functionality is available just by turning on the command line switch
without using any annotation. This functionality doesn't have much to do
with EJB3.

> Forgive me for not completely understanding the CodeModel hierarchy, but
> I would think your suggestion would force me to look at all of the
> properties for every class in the Model and not just the ones in the
> class I annotated.

I didn't realize that you are looking for doing it at the class level.
But the basic approach would be the same --- instead of looking at all
CPropertyInfos, now you just look at those CPropertyInfos that belong to
CClassInfos with <ejb3:setDefaults/> annotation.

> I couldn't find a class called CElementProperty in the docs. I assume
> you meant CElementPropertyInfo which has the getTypes() method.

Sorry, yes.

> But I
> could not figure out how to get that from the Model or Outline or
> ClassOutline or CClassInfo, or CPropertyInfo, or JDefinedClass, etc. I
> would think there should be some way to connect CPropertyInfo to
> CElementPropertyInfo.

CElementPropertyInfo is a sub type of CPropertyInfo. So you can iterate
CPropertyInfos of a class, check if they are CElementPropertyInfo.


> I do have another question that I've been meaning to ask, is there a
> way to have a global plugin annotation, such as global bindings, that
> applies to all classes and all elements or do the plugin annotations
> have to be at least on the class level? Does Model.customizations() do
> this or is that a way to read all the class and property customizations?

Ah, another good point. I think the Model class itself needs to
implement CCustomizable.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com