dev@glassfish.java.net

Re: How to use _at_Param String targetName?

From: Tom Mueller <tom.mueller_at_oracle.com>
Date: Mon, 18 Oct 2010 16:34:22 -0500

  Please see inline.

On 10/18/2010 4:19 PM, Ken wrote:
> 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?
and option is "--target blah" while an operand is just the argument to
the command with no "--target".
In the code, the operand has "primary=true", and option does not.
>>
>> 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 ;
I would think you would need a "primary=true" here.Check your usage
message. There shouldn't be a "--target" for a list command.
>
> 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.
It's the default so you don't have to list it.
> 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.
That is probably a bug.

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