admin@glassfish.java.net

Re: Default Values and _at_Param

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Tue, 18 May 2010 13:58:33 -0500

On 5/18/10 1:15 PM, Bill Shannon wrote:
> I looked into adding support to ParamModel for getting these default
> values from the fields, but it was just too big of a change. Right
> now the model has all the information it needs without reference to
> an instance of the class, changing that started to get pretty ugly.
> I wasn't happy with the result, so I gave up.
My from the hip idea was to do something like

instance = clazz.newInstance();
for each field :
     param = field.getAnnotation(Param.class)
     value =
     if (param.defaultValue == null):
         param.defaultValue = field.get(instance)

Roughly. Seems like we could do that when building up the ParamModel
and not have to keep the instance around, but I've though on that only
fairly abstractly. However...
> The simple answer is that you have to put the default value in the
> annotation. I know, I know, I don't like it either, but I like it
> better than the alternative I came up with. Maybe you can do better...
This is certainly the easier solution, even if it is more work up
front. At some point, someone is going to touch all of the Param usages
to add the camelCaseName attribute we decided upon last week, so it
would be fairly trivial to add this additional, minor change. There's a
good chance the REST team will get to do a lot of that, so I don't mind
suggesting the extra work. :)

Any other thoughts? Jerome?

-- 
Jason Lee
Senior Member of Technical Staff
GlassFish Administration Console
Oracle Corporation
Phone x31197/+1 405-343-1964
Blog http://blogs.steeplesoft.com