KickJava   Java API By Example, From Geeks To Geeks.

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


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/TargetCmd.java,v 1.3 2005/12/25 03:45:40 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:40 $
28  */

29  
30 package com.sun.cli.jmx.cmd;
31
32 import javax.management.ObjectName JavaDoc;
33
34 import com.sun.cli.util.stringifier.ArrayStringifier;
35
36 /*
37     Invokes the 'list' commmand on all specified targets
38  */

39 public class TargetCmd extends JMXCmd
40 {
41         public
42     TargetCmd( final CmdEnv env )
43     {
44         super( env );
45     }
46     
47         int
48     getNumRequiredOperands()
49     {
50         // require 1, by default
51
return( 0 );
52     }
53     
54         public String JavaDoc
55     getUsage()
56     {
57         return( CmdStrings.TARGET_HELP.toString() );
58     }
59     
60     
61         void
62     displayExistingTarget()
63     {
64         println( "Targets:\n" + envGet( ENV_TARGET ) );
65     }
66     
67         public static String JavaDoc []
68     getNames( )
69     {
70         return( new String JavaDoc [] { "target", "t" } );
71     }
72     
73         void
74     warnEmptyTargets( final String JavaDoc [] targets )
75         throws Exception JavaDoc
76     {
77         // issue warning if some targets could not be resolved to anything
78
for ( int i = 0; i < targets.length; ++i )
79         {
80             final String JavaDoc target = targets[ i ];
81             
82             final ObjectName JavaDoc [] objects =
83                 getProxy().resolveTargets( new String JavaDoc [] { target } );
84                 
85             if ( objects.length == 0 )
86             {
87                 println( "WARNING: target " +
88                     target + " does not resolve to any objects" );
89             }
90         }
91     }
92     
93         void
94     setTargets( final String JavaDoc [] targets )
95         throws Exception JavaDoc
96     {
97         putEnvTargets( targets );
98         warnEmptyTargets( targets );
99     }
100     
101         void
102     executeInternal()
103         throws Exception JavaDoc
104     {
105         final String JavaDoc [] operands = getOperands();
106         
107         assert( operands != null );
108         
109         if ( operands.length == 0 )
110         {
111             displayExistingTarget();
112         }
113         else
114         {
115             establishProxy();
116             setTargets( operands );
117         }
118     }
119 }
120
121
122
123
Popular Tags