dev@glassfish.java.net

Re: How to use _at_Param String targetName?

From: Ken <ken.cavanaugh_at_oracle.com>
Date: Mon, 18 Oct 2010 14:19:34 -0700

Tom Mueller wrote:
> Most of the list commands that take a target, take the target as an
> operand rather than an option.
What is the difference between operand and option?
>
> Here is the beginning of the list-components command:
>
> @Service(name="list-components")
> @I18n("list.components")
> @Scoped(PerLookup.class)
> @ExecuteOn(value={RuntimeType.DAS})
> @TargetType(value={CommandTarget.DOMAIN, CommandTarget.DAS,
> CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER})
> public class ListComponentsCommand implements AdminCommand {
>
> @Param(optional=true)
> String type = null;
>
> @Param(primary=true, optional=true)
> public String target = "server";
>
> Looking at the differences, the @ExecuteOn should be only for the DAS
> - there is no need to run list commands on instances.
>
> list-components uses the name "target" for the field, rather than
> targetName. Although I would expect your syntax to work, maybe that
> is the problem.
I decided to copy EXACTLY what was present in one of the HTTP listener
commands, and that worked.
I ended up with

    @Param( name="target", optional=true,
        defaultValue=SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)
    String target ;

which seems to work. Maybe optional and/or defaultValue is required?
This is not documented any where
I could find on the wiki. Also, DEFAULT_SERVER_INSTANCE_NAME is marked
as deprecated, so
I'm not sure whether that is appropriate. The wiki page says that all
that is needed is @Param String target,
which would seem to imply that the field name MUST be target.

> Also, does the field need to be public?
No, the injection works fine in any case.

Thanks,

Ken.