admin@glassfish.java.net

Re: Question for Remote Command Developers

From: Byron Nevins <Byron.Nevins_at_Sun.COM>
Date: Tue, 08 Apr 2008 09:52:25 -0700
Agreed about boolean -- except there is no hope it will work right - without a LOT of work.
"right" in this case means V2 behavior:

  1. option appears with no value (currently impossible in v3) --> true
  2. option has "true" or "false" --> true/false
  3. option has "anything-else" --> error

The guts of the implementation will do a Boolean.parseBoolean(value) -- and case 3 won't be detected.
It should and will be done though. 
I was pretty happy that I could figure out how to bend injection to my will and handle it this way for now.


-------
That's a good idea about the range and it is easy to do in CommandRunner at least.  acceptableValue is simply an annotation with any String -- it was pre-existing in Param.  We can put any sort of String we want in there.

Jerome Dochez wrote:

On Apr 8, 2008, at 7:43 AM, Prashanth Abbagani wrote:
This will be useful. But for boolean parameters, can we encourage the developers to declare the param as boolean type (as against String), and you implicitly validate the option value for (true or false).

right, I like the feature but not the example...

we should have
@Param(optional=true)
Boolean enabled

and let the system figure out the conversion (constructor with String paramerter).

having said that, the acceptableValues is interesting for other things, and could/ should be enhanced to support range :
like
@Param(acceptableValues="0..100")
Integer numberOfThreads;

Jerome

Byron Nevins wrote:
I've implemented, but not checked in yet, support for validating param values against an acceptable list of values.
This is immediately useful for boolean parameters -- we want 'booleanOptionX=garbage'  to be a hard error rather than just silently setting it to false.

Are there other use cases for "acceptableValues" in Remote Commands?

E.g.

before:
@Param(optional=true)
  String enabled = Boolean.TRUE.toString();

after:
  @Param(optional=true, acceptableValues="true,false")
  String enabled = Boolean.TRUE.toString();

At injection time -- if the parameter has a value -- then it is compared against the comma separated list of acceptable values.
If it does not match any of them -- an Exception is thrown before the execute() method is called.


---------------------------------------------------------------------
To unsubscribe, e-mail: admin-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: admin-help@glassfish.dev.java.net



---------------------------------------------------------------------
To unsubscribe, e-mail: admin-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: admin-help@glassfish.dev.java.net


-- 
Byron Nevins Work 408-276-4089, Home 650-359-1290, Cell 650-784-4123 - Sun Microsystems, Inc.