Sun GlassFish Enterprise Server v3 Prelude Add-On Component Development Guide

Adding Message Text Strings to an asadmin Command

A message text string provides useful information to the user about an asadmin command or a parameter.

To provide internationalization support for the text string of a command or parameter, annotate the declaration of the command or parameter with the org.glassfish.api.I18n annotation. The @I18n annotation identifies the resource from the resource bundle that is associated with your implementation.

To add message text strings to an asadmin command, create a plain text file that is named LocalStrings.properties to contain the strings. Define each string on a separate line of the file as follows:

key=string
key

A key that maps the string to a command or a parameter. The format to use for key depends on the target to which the key applies and whether the target is annotated with the @I18n annotation. See the following table.

Target 

Format 

Command or parameter with the @I18n annotation

command-name.command.resource-name

Command without the @I18n annotation

command-name.command

Parameter without the @I18n annotation

command-name.command.param-name

The replaceable parts of these formats are as follows:

command-name

The name of the command.

resource-name

The name of the resource that is specified in the@I18n annotation.

param-name

The name of the parameter.

string

A string without quotes that contains the text of the message.


Note –

To display the message strings to users, you must provide code in your implementation of the execute method to display the text. For more information about implementing the execute method, see Enabling an asadmin Command to Run.



Example 4–3 Adding Message Strings to an asadmin Command

This example shows the code for adding message strings to the create-mycontainer command as follows:

The addition of the parameters originator, description, enabled and containername to the command is shown in Example 4–2.

package com.example.mycontainer;

import org.glassfish.api.admin.AdminCommand;
...
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.jvnet.hk2.annotations.Service;
...
import org.jvnet.hk2.annotations.Scoped;
import org.jvnet.hk2.component.PerLookup;

/**
 * Sample command
 */
@Service(name="create-mycontainer")
@Scoped(PerLookup.class)
public Class CreateMycontainer implements AdminCommand {

    …

    @Param
    String originator;

    @Param(name="description", optional=true)
    @I18n("mydesc")
    String mycontainerDescription
   
    @Param (acceptableValues="true,false", defaultValue="false", optional=true)
    String enabled
    
    @Param(primary=true)
    String containername;
 …

}

The following message text strings are defined in the file LocalStrings.properties for use by the command:

create-mycontainer.command=Creates a custom container
create-mycontainer.command.originator=The originator of the container 
create-mycontainer.command.mydesc=A description of the container
create-mycontainer.command.enabled=Whether the container is enabled or disabled
create-mycontainer.command.containername=The container name