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 16:13:59 -0500

Sorry bad examples.

Thanks. I got it working so far. Now that I have the default value and
the JFieldVar I want to init, I just need set the JExpression so that it
works with all primitive and class types such as:

protected int myInt = 0;
protected String test = "testvalue";
protected BigInteger bigInt = new BigInteger("0");
protected Double myDouble = Double.valueOf("0");

Etc.

I think you indicated that TypeUse.createConstant could do this for me?
Or will it be more complicated than this? Could you please give me an
example of how to use this method?

JExpression createConstant(JCodeModel codeModel,
                           String lexical,
                           org.relaxng.datatype.ValidationContext
context)

I'm not sure how to value the parameters. I think I can get the
JCodeModel from Outline.getCodeModel() and the String is probably the
default value? I'm not sure how to obtain or create the
ValidationContext.

I could always try to build the code using JExpr.ref() if it cannot be
done easily.


> -----Original Message-----
> From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
> Sent: Thursday, September 08, 2005 12:51 PM
> To: users_at_jaxb.dev.java.net
> Subject: Re: Plugin to change JAXB 2.0 default values behavior
>
>
> 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
>


  _____

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