admin@glassfish.java.net

Re: Question for Remote Command Developers

From: Lloyd L Chambers <Lloyd.Chambers_at_Sun.COM>
Date: Thu, 10 Apr 2008 11:31:53 -0700

Byron,

Perhaps a String[] would be better for the values list?

And I'm wondering if the following alternatives might be more clear,
and avoid coding things like "true", "false", "1", "0"; we could make
that decision at runtime instead:

public @interface BooleanParam {
    boolean optional() default true;
}

public @interface NumberParam {
    boolean optional() default true;
    long[] legalMin() default MIN_LONG;
    long[] legalMax() default MAX_LONG;
    /** overrides, legalMin(), legalMax() */
    long[] constrainedTo() default [];
}

public @interface EnumParam {
    boolean optional() default true;
    String[] legalValues() default [];
}

I like this better than one generic annotation; they spell out only
what's needed and leave behavior to the runtime, avoiding syntaxes
like "0..10".


Lloyd

On Apr 8, 2008, at 12:20 AM, 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.
>
> --
> Byron Nevins Work 408-276-4089, Home 650-359-1290, Cell 650-784-4123
> - Sun Microsystems, Inc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: admin-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: admin-help_at_glassfish.dev.java.net
>

---
Lloyd L Chambers
lloyd.chambers_at_sun.com
Sun Microsystems, Inc