Skip Navigation Links | |
Exit Print View | |
Oracle GlassFish Server 3.1 Add-On Component Development Guide |
1. Introduction to the Development Environment for GlassFish Server Add-On Components
3. Extending the Administration Console
4. Extending the asadmin Utility
About the Administrative Command Infrastructure of GlassFish Server
Representing an asadmin Subcommand as a Java Class
Specifying the Name of an asadmin Subcommand
Ensuring That an AdminCommand Implementation Is Stateless
Example of Adding an asadmin Subcommand
Adding Parameters to an asadmin Subcommand
Representing a Parameter of an asadmin Subcommand
Identifying a Parameter of an asadmin Subcommand
Specifying Whether a Parameter Is an Option or an Operand
Specifying the Name of an Option
Specifying the Long Form of an Option Name
Specifying the Short Form of an Option Name
Specifying the Acceptable Values of a Parameter
Specifying the Default Value of a Parameter
Specifying Whether a Parameter Is Required or Optional
Example of Adding Parameters to an asadmin Subcommand
Making asadmin Subcommands Cluster-Aware
Specifying asadmin Subcommand Execution
Subcommand Preprocessing and Postprocessing
Running a Command from Another Command
Enabling an asadmin Subcommand to Run
Setting the Context of an asadmin Subcommand
Changing the Brand in the GlassFish Server CLI
Examples of Extending the asadmin Utility
Implementing Create, Delete, and List Commands Using Annotations
Using Multiple Command Annotations
5. Adding Monitoring Capabilities
6. Adding Configuration Data for a Component
7. Adding Container Capabilities
8. Creating a Session Persistence Module
9. Packaging, Integrating, and Delivering an Add-On Component
A message text string provides useful information to the user about an asadmin subcommand or a parameter.
To provide internationalization support for the text string of a subcommand or parameter, annotate the declaration of the subcommand 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 subcommand, 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
A key that maps the string to a subcommand 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.
|
The name of the subcommand.
The name of the resource that is specified in the@I18n annotation.
The name of the parameter.
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 Subcommand to Run.
Example 4-3 Adding Message Strings to an asadmin Subcommand
This example shows the code for adding message strings to the create-mycontainer subcommand as follows:
The create-mycontainer subcommand is associated with the message Creates a custom container. No internationalization support is provided for this message.
The --originator parameter is associated with the message The originator of the container. No internationalization support is provided for this message.
The --description parameter is associated with the message that is contained in the resource mydesc, for which internationalization is provided. This resource contains the message text A description of the container.
The --enabled parameter is associated with the message Whether the container is enabled or disabled. No internationalization support is provided for this message.
The --containername parameter is associated with the message The container name. No internationalization support is provided for this message.
The addition of the parameters originator, description, enabled and containername to the subcommand 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 subcommand */ @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 subcommand:
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