KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > cmd > CmdStrings


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin-cli/cli-api/src/java/com/sun/cli/jmx/cmd/CmdStrings.java,v 1.3 2005/12/25 03:45:32 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:32 $
28  */

29  
30 package com.sun.cli.jmx.cmd;
31
32 import java.lang.reflect.Field JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import com.sun.cli.util.StringSource;
35
36 /*
37     Gets strings from CmdStrings class
38  */

39 final class CmdStringsSource implements StringSource
40 {
41     CmdStringsSource()
42     {
43     }
44     
45     
46         public String JavaDoc
47     getString( String JavaDoc id )
48     {
49         final String JavaDoc value = CmdStrings.getFieldValue( id );
50         
51         return( value );
52     }
53     
54         public String JavaDoc
55     getString( String JavaDoc id, String JavaDoc defaultValue )
56     {
57         String JavaDoc value = CmdStrings.getFieldValue( id );
58         
59         if ( value == null )
60         {
61             value = defaultValue;
62         }
63         return( value );
64     }
65 }
66
67 public final class CmdStrings
68 {
69     private static final CmdStringsSource GETTER = new CmdStringsSource();
70     private final static String JavaDoc SYNTAX_DELIM = "\n\n";
71     private final static String JavaDoc CMD_DELIM = "";
72     
73     
74     public static final class CmdHelp
75     {
76         private final String JavaDoc mID;
77         private final String JavaDoc mName;
78         
79             private
80         CmdHelp( String JavaDoc id )
81         {
82             mID = id;
83             mName = id.toLowerCase( );
84         }
85         
86             private
87         CmdHelp( String JavaDoc id, String JavaDoc name )
88         {
89             mID = id;
90             mName = name;
91         }
92         
93             public String JavaDoc
94         getName()
95         {
96             return( mName );
97         }
98         
99             public String JavaDoc
100         getSynopsis()
101         {
102             return( GETTER.getString( mID + "_SYNOPSIS" ) );
103         }
104         
105             public String JavaDoc
106         getSyntax()
107         {
108             return( GETTER.getString( mID + "_SYNTAX" ) );
109         }
110         
111             public String JavaDoc
112         getText()
113         {
114             return( GETTER.getString( mID + "_TEXT" ) );
115         }
116         
117             public String JavaDoc
118         toString()
119         {
120             return( CMD_DELIM + getSynopsis() + CMD_DELIM + SYNTAX_DELIM + getSyntax() + SYNTAX_DELIM + getText() );
121         }
122     }
123     
124     public final static CmdHelp GET_HELP = new CmdHelp( "GET" );
125     public final static CmdHelp SET_HELP = new CmdHelp( "SET" );
126     public final static CmdHelp FIND_HELP = new CmdHelp( "FIND" );
127     public final static CmdHelp INSPECT_HELP = new CmdHelp( "INSPECT" );
128     public final static CmdHelp INVOKE_HELP = new CmdHelp( "INVOKE" );
129     public final static CmdHelp CREATE_HELP = new CmdHelp( "CREATE" );
130     public final static CmdHelp DELETE_HELP = new CmdHelp( "DELETE" );
131     public final static CmdHelp COUNT_HELP = new CmdHelp( "COUNT" );
132     public final static CmdHelp DOMAINS_HELP = new CmdHelp( "DOMAINS" );
133     public final static CmdHelp SETENV_HELP = new CmdHelp( "SETENV" );
134     
135     public final static CmdHelp TARGET_HELP = new CmdHelp( "TARGET" );
136     public final static CmdHelp CONFIGURE_HELP = new CmdHelp( "CONFIGURE" );
137     //public final static CmdHelp LIST_HELP = new CmdHelp( "LIST" );
138
public final static CmdHelp CONNECT_HELP = new CmdHelp( "CONNECT" );
139     public final static CmdHelp LISTEN_HELP = new CmdHelp( "LISTEN" );
140     
141     public final static CmdHelp CREATE_ALIAS_HELP = new CmdHelp( "CREATE_ALIAS", "create-alias" );
142     public final static CmdHelp DELETE_ALIAS_HELP = new CmdHelp( "DELETE_ALIAS", "delete-alias" );
143     public final static CmdHelp RESOLVE_ALIAS_HELP = new CmdHelp( "RESOLVE_ALIAS", "resolve-alias" );
144     public final static CmdHelp LIST_ALIASES_HELP = new CmdHelp( "LIST_ALIASES", "list-aliases" );
145     public final static CmdHelp SOURCE_HELP = new CmdHelp( "SOURCE", "source" );
146     
147     public final static CmdHelp HELP_HELP = new CmdHelp( "HELP" );
148     
149     
150     private final static CmdHelp [] ALL_HELP = _getAllHelp();
151     
152     
153         public static CmdHelp []
154     getAllHelp()
155     {
156         return( ALL_HELP );
157     }
158     
159         private static CmdHelp []
160     _getAllHelp()
161     {
162         final Field JavaDoc [] fields = CmdStrings.class.getFields();
163         
164         final ArrayList JavaDoc list = new ArrayList JavaDoc();
165         
166         for( int i = 0; i < fields.length; ++i )
167         {
168             final Field JavaDoc field = fields[ i ];
169             
170             if ( field.getName().endsWith( "_HELP" ) )
171             {
172                 try
173                 {
174                     final CmdHelp help = (CmdHelp)field.get( CmdStrings.class );
175                     
176                     list.add( help );
177                 }
178                 catch( IllegalAccessException JavaDoc e )
179                 {
180                     System.err.println( "can't access field: " + field.getName() );
181                 }
182             }
183         }
184         
185         final CmdHelp [] cmdHelps = new CmdHelp [ list.size() ];
186         list.toArray( cmdHelps );
187         
188         return( cmdHelps );
189     }
190     
191         public static CmdHelp
192     getHelp( String JavaDoc cmd )
193     {
194         CmdHelp help = null;
195         
196         for( int i = 0; i < ALL_HELP.length; ++i )
197         {
198             if ( ALL_HELP[ i ].getName().equalsIgnoreCase( cmd ) )
199             {
200                 help = ALL_HELP[ i ];
201                 break;
202             }
203         }
204         
205         return( help );
206     }
207     
208     public final static String JavaDoc USAGE = "USAGE: ";
209     public final static String JavaDoc NO_SUCH_COMMAND = "No such command: ";
210     
211     //-------------------- private fields ------------------------------
212

213         static String JavaDoc
214     getFieldValue( String JavaDoc name )
215     {
216         String JavaDoc result = null;
217         
218         try
219         {
220             final Field JavaDoc field = CmdStrings.class.getDeclaredField( name );
221             
222             result = (String JavaDoc)field.get( CmdStrings.class );
223         }
224         catch( Exception JavaDoc e )
225         {
226             result = name;
227         }
228         
229         return( result );
230     }
231     
232     // generic JMX commands
233
private final static String JavaDoc GET_SYNOPSIS = "get: display one or more attributes on the specified target(s).";
234     private final static String JavaDoc GET_SYNTAX = "get attr[,attr]* [target]+";
235     private final static String JavaDoc GET_TEXT =
236 "Specify the attributes in a comma-separated list. " +
237 "The following special targets are also available:\n"+
238 "* all attributes\n" +
239 "*r all read-only attributes\n" +
240 "*w all writeable attributes\n" +
241 "\n'get' Examples: \n" +
242 "get * * -- gets all attributes on all MBeans\n" +
243 "get Count,Timeout MyMBean -- gets the Count and Timeout attributes on the MBean 'MyMBean'\n";
244     
245     
246     private final static String JavaDoc SET_SYNOPSIS = "set: set one or more attributes on the specified target(s)";
247     private final static String JavaDoc SET_SYNTAX = "set attr=value[,attr=value]* [target]+";
248     private final static String JavaDoc SET_TEXT =
249 "Specify a comma-separated list of name-value pairs.\n" +
250 "\n'set' Examples: \n" +
251 "set Timeout=10,Count=20 MyMBean -- sets the Timeout attribute to 10 and Count attribute to 20 " +
252 "on the MBean 'MyMBean'\n";
253     
254     
255     private final static String JavaDoc FIND_SYNOPSIS = "find: display MBeans matching name, pattern, or alias";
256     private final static String JavaDoc FIND_SYNTAX = "find [--regex <expr> | --java-regex <expr>] [--current ] [--add] [--remove] [target]*";
257     private final static String JavaDoc FIND_TEXT =
258 "Specify 0 or more names/patterns/aliases. All matching MBeans will be displayed with their fully-qualified " +
259 "names. If no targets are specified or '*' is specified, then all MBeans are displayed.\n" +
260 "\nExamples:\n" +
261 "\nfind -- displays all MBeans" +
262 "\nfind :* -- displays all MBeans in the default domain" +
263 "\nfind type=test -- displays all MBeans whose ObjectName contains the property 'type' with value 'test'\n" +
264 "\nfind --regex n*=test* *:* -- displays all MBeans whose ObjectName contains a property whose name starts with 'n' and whose value starts with 'test'\n" +
265 "\n\nOptions:\n" +
266 "current -- display the results of the last find\n" +
267 "add -- add the results of this invocation to the current set\n" +
268 "remove -- remove the results of this invocation from the current set\n" +
269 "regex -- utilize a regular expression for MBean Property name(s) or value(s)\n" +
270 "\nNote on regex--the syntax used is that as documented in java.util.regex\n" +
271 "";
272     
273     private final static String JavaDoc INSPECT_SYNOPSIS= "inspect: display attributes, operations, constructors, etc";
274     private final static String JavaDoc INSPECT_SYNTAX = "inspect [--all ] [--summary] [--nodescription] " +
275         "--attributes=[attr]+] [--operations=[op]+ ] [--constructors] [--notifications=[notif]+] [target]+";
276     private final static String JavaDoc INSPECT_TEXT =
277 "One or more targets may be specified. The output will be displayed for each resulting MBean. " +
278 "The following options are available:\n" +
279 "--all display all available information\n" +
280 "--summary display a summary only\n" +
281 "--nodescription omit descriptions (avoids clutter if there are none)\n" +
282 "--attrs display the specified attributes (* = all attributes)\n" +
283 "--operations display the specified operations (* = all operations)\n" +
284 "--constructors display all available constructors\n" +
285 "--notifications display the specified notifications (* = all notifications)\n";
286
287         
288     private final static String JavaDoc INVOKE_SYNOPSIS = "invoke: invokes an MBean operation";
289     private final static String JavaDoc INVOKE_SYNTAX = "" +
290             "cmd:[arg-value[,arg-value]*] [target]+\n" +
291             " cmd:arg-name=arg-value[,arg-name=arg-value]* [target]+";
292     private final static String JavaDoc INVOKE_TEXT =
293 "The invoke operation is unusual in that no special command is entered. Instead, the MBean operation name is used " +
294 "directly with a special syntax.\n\n" +
295 "There are two forms of invocation--Ordered and Named. Ordered invocation requires the parameters in " +
296 "the correct order as a comma-separated list. " +
297 "Named invocation relies on an operation's parameter names, which may or may not be " +
298 "available for some MBeans. You can use the 'inspect' command to see if parameter names are available for an MBean." +
299 "\nNamed invocation also works for operations taking a Properties object; excess parameters are supplied to the " +
300 "operation in the Properties object.\n\n" +
301 "All forms of invocation use the MBeanInfo to determine the correct match for an operation. " +
302 "For an operation to be available for invocation, it must restrict its use of data " +
303 "types to the following:\n" +
304 " char, byte, short, int, long, float, double\n" +
305 " Character, Byte, Short, Integer, Long, Float, Double, Number, BigNumber\n" +
306 " String, Object, Properties\n" +
307 " [] all arrays of the above types\n\n" +
308 "Type-casts may be used, but are rarely needed. Use a type cast to force a number to a String or int to Integer, etc. " +
309 "\n\nArrays are denoted using curly braces, and may be nested. Examples of arrays:\n" +
310 " {1,2,3}\n" +
311 " {hello,there}\n" +
312 " {hello,1,there,2}\n" +
313 " {{1,2},{3,4}}\n" +
314 "\nIf a type-cast is applied to an array, then all elements of that array must be compatible with it. The following type-cast " +
315 "forces the value to be converted to an array of String (which would match 'String []' in an operation):\n" +
316 " (String){1,2,3}\n" +
317 "\nStrings may be quoted with the double-quote character \". This is not required, but can be useful to force a value's type " +
318 "to be a String.\n";
319
320     private final static String JavaDoc CREATE_SYNOPSIS = "create: create and register an MBean";
321     private final static String JavaDoc CREATE_SYNTAX =
322 "create --class=<classame> [--args=<args>] <name>";
323     private final static String JavaDoc CREATE_TEXT =
324 "TBD";
325
326     private final static String JavaDoc COUNT_SYNOPSIS = "count: count the number of registered MBeans";
327     private final static String JavaDoc COUNT_SYNTAX = "count";
328     private final static String JavaDoc COUNT_TEXT = "TBD";
329
330     private final static String JavaDoc DOMAINS_SYNOPSIS = "domains: display the available domains";
331     private final static String JavaDoc DOMAINS_SYNTAX = "domains";
332     private final static String JavaDoc DOMAINS_TEXT = "TBD";
333
334     private final static String JavaDoc SOURCE_SYNOPSIS = "source: read commands file a file";
335     private final static String JavaDoc SOURCE_SYNTAX = "source <filename>";
336     private final static String JavaDoc SOURCE_TEXT = "TBD";
337
338
339
340     private final static String JavaDoc DELETE_SYNOPSIS = "delete: unregister an MBean";
341     private final static String JavaDoc DELETE_SYNTAX =
342 "delete <fully-qualified-name>";
343     private final static String JavaDoc DELETE_TEXT =
344 "TBD";
345
346
347     private final static String JavaDoc LISTEN_SYNOPSIS = "listen: listen for notifications";
348     private final static String JavaDoc LISTEN_SYNTAX =
349 "listen [ --stop | --pause ] [--file=filename] target [[target]+]";
350     private final static String JavaDoc LISTEN_TEXT =
351 "Listens for notifications emitted from the specified targets. " +
352 "If neither stop nor pause is specified, then listening starts. Output is emitted to the console unless a file is specified.";
353     
354     
355     /*
356     // generic invocations
357     private final static String LIST_SYNOPSIS = "list: invokes the list() operation on the specified target(s)";
358     private final static String LIST_SYNTAX = "list [target]+";
359     private final static String LIST_TEXT =
360 "This command is equivalent to 'list: <targets>', but has some additional advantages. First, it may supply superior output " +
361 "formatting. Second, it may be invoked without targets. This mplicitly invokes list() on all MBeans.";
362     
363 */

364
365     // built-ins
366
private final static String JavaDoc TARGET_SYNOPSIS = "target: displays or sets the target MBean(s)";
367     private final static String JavaDoc TARGET_SYNTAX = "target [[target]+]";
368     private final static String JavaDoc TARGET_TEXT =
369 "With no arguments, displays the current target(s). Otherwise, the targets are taken as specified.";
370
371     private final static String JavaDoc SETENV_SYNOPSIS = "setenv: sets a jmxadmin variable";
372     private final static String JavaDoc SETENV_SYNTAX = "setenv [name=value | name]";
373     private final static String JavaDoc SETENV_TEXT =
374 "setenv -- displays all environment variables\n" +
375 "setenv name=value -- sets variable 'name' to 'value'\n" +
376 "setenv name -- removes variable 'name'\n" +
377 "\nNote: variables persist across invocations of jmxadmin. However, they are neither imported " +
378 "nor exported to/from the shell.\n" +
379 "";
380
381     private final static String JavaDoc CONFIGURE_SYNOPSIS = "configure: configure jmxadmin";
382     private final static String JavaDoc CONFIGURE_SYNTAX = "configure | show-config | add-provider <classname> | " +
383                                                         "remove-provider <classname> | " +
384                                                         "add-cmd <classname> | remove-cmd <classname>";
385     private final static String JavaDoc CONFIGURE_TEXT =
386 "The configure command can be invoked with various names, each of which functions as its own command.\n\n" +
387 "The possible invocation names are:\n" +
388 "configure: display this help\n" +
389 "add-provider -- add the JSR 160 provider with the specified classname\n" +
390 "remove-provider -- remove the JSR 160 provider with the specified classname\n" +
391 "add-cmd -- add a new command with the specified classname\n" +
392 "remove-cmd -- remove the command with the specified classname\n" +
393 "";
394
395     
396     // built-ins
397
private final static String JavaDoc CONNECT_SYNOPSIS = "connect: connect to an MBeanServer";
398     private final static String JavaDoc CONNECT_SYNTAX =
399 "(1) connect [--host h] --port p [--protocol prot] [--user u] [--password-file f] [--options key=value[,key=value]*] [name]\n" +
400 "(2) connect <name>\n" +
401 "(3) connect\n" +
402 "(4) connect --list\n";
403     private final static String JavaDoc CONNECT_TEXT =
404 "Connects to the specified host and port with optional username and password and protocol.\n" +
405 "Several variants of this command are available:\n" +
406 "(1) Makes a connection to the specified server and associates the name with it (if specified).\n" +
407 "(2) Same as (1), but uses <name> to lookup the connection parameters.\n" +
408 "(3) Makes a connection to the default server.\n" +
409 "(4) Lists the active connections.\n" +
410 "\nNotes:\n" +
411 "If --host is not specified, then localhost is used.\n" +
412 "If --protocol is not specified, the jmxmp is used. \n" +
413 "If user and password-file are not specified, no user and password are used." +
414 "Additional options as name/value pairs may be specified and will be passed to the JMX connector " +
415 "as additional configuration data.\n" +
416 "\nThe file specified by --password-file should be of the following format:\n" +
417 "user1=password1\n" +
418 "user2=password2\n" +
419 "...\n" +
420 "In this case, the --user option is required, and will be used to lookup the password in the file." +
421 "";
422
423     
424     // alias commands
425
private final static String JavaDoc CREATE_ALIAS_SYNOPSIS = "create-alias: creates a persistent alias for an MBean name or pattern";
426     private final static String JavaDoc CREATE_ALIAS_SYNTAX = "create-alias [--replace] [name=value]+";
427     private final static String JavaDoc CREATE_ALIAS_TEXT =
428 "Creates an alias for the specified value. No interpretation is given to the value supplied when creating an alias. However, " +
429 "an alias must ultimately resolve to an ObjectName or ObjectName pattern. Aliases may contain other aliases in any combination " +
430 "with ObjectNames. The only restriction is that the space character is reserved as a delimiter. Therefore, ObjectNames " +
431 "containing spaces may not be aliased.\n\n" +
432 "Once created, an alias may be used anywhere an ObjectName may be used. Aliases are persisted in the file system local to where " +
433 "the CLISupportMBean is running.\n\n" +
434 "create-alias Examples: \n" +
435 " create-alias test=:type=test,name=TestStandard\n" +
436 " create-alias system=system:*\n" +
437 " create-alias all-test=*:type=test\n" +
438 "";
439     
440     private final static String JavaDoc DELETE_ALIAS_SYNOPSIS = "delete-alias: deletes a persistent alias";
441     private final static String JavaDoc DELETE_ALIAS_SYNTAX = "delete-alias [name]+";
442     private final static String JavaDoc DELETE_ALIAS_TEXT = "Deletes an existing alias or aliases.";
443     
444     private final static String JavaDoc RESOLVE_ALIAS_SYNOPSIS = "resolve-alias: display the value of an alias";
445     private final static String JavaDoc RESOLVE_ALIAS_SYNTAX = "resolve-alias [name]+";
446     private final static String JavaDoc RESOLVE_ALIAS_TEXT =
447 "The alias value is displayed. A recursive option is planned.";
448     
449     private final static String JavaDoc LIST_ALIASES_SYNOPSIS = "list-aliases: display aliases";
450     private final static String JavaDoc LIST_ALIASES_SYNTAX = "list-aliases";
451     private final static String JavaDoc LIST_ALIASES_TEXT = "Aliases are listed, along with their values.";
452     
453     
454     // other
455
private final static String JavaDoc HELP_SYNOPSIS = "help: displays help";
456     private final static String JavaDoc HELP_SYNTAX = "help [cmd]*";
457     private final static String JavaDoc HELP_TEXT =
458 "To see all commands, type 'help'. To see help for a particular command, " +
459 "type 'help cmd'.";
460     
461 }
462
463
Popular Tags