users@jaxb.java.net

RE: Plugin to change JAXB 2.0 default values behavior

From: Scott Allan <sallan1000_at_aol.com>
Date: Thu, 8 Sep 2005 12:26:17 -0500

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.

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";

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 couldn't find a class called CElementProperty in the docs. I assume
you meant CElementPropertyInfo which has the getTypes() method. 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.

I see that CTypeRef has a getDefaultValue() method and CTypeInfo has a
createConstant method. It looks like I can get CTypeInfo from
CPropertyInfo.ref() but I how do I obtain CElementPropertyInfo to get
the default value?

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?

> I think what you'd want to do with your plugin is to look for all
> CElementProperty-s in the model, find those which only have
> one CTypeRef
> in CElementProperty.getTypes(), propagate its
> CTypeRef.defaultValue to
> CPropertyInfo.defaultValue.
>
> The string default value can be turned into a JExpression by using
> TypeUse.createConstant.
>
>



  _____

<< ella for Spam Control >> has removed 26855 Spam messages and set
aside 2 Newsletters for me
You can use it too - and it's FREE! www.ellaforspam.com