KickJava   Java API By Example, From Geeks To Geeks.

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


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

29  
30 package com.sun.cli.jmx.cmd;
31
32
33 import com.sun.cli.jmx.support.InspectRequest;
34 import com.sun.cli.jmx.support.InspectResult;
35 import com.sun.cli.jmx.support.CLISupportMBeanProxy;
36 import com.sun.cli.util.stringifier.*;
37
38 public class InspectCmd extends JMXCmd
39 {
40         public
41     InspectCmd( final CmdEnv env )
42     {
43         super( env );
44         
45         mStringifier = new SmartStringifier( "\n\n", false );
46     }
47     
48         public String JavaDoc
49     getUsage()
50     {
51         return( CmdStrings.INSPECT_HELP.toString() );
52     }
53     
54         int
55     getNumRequiredOperands()
56     {
57         // require 1, by default
58
return( 0 );
59     }
60     
61     
62     static private final String JavaDoc OPTIONS_INFO =
63         "all summary constructors attributes,1 operations,1 notifications,1 nodescription";
64         
65     
66         ArgHelper.OptionsInfo
67     getOptionInfo()
68         throws ArgHelper.IllegalOptionException
69     {
70         return( new ArgHelperOptionsInfo( OPTIONS_INFO ) );
71     }
72     
73     
74         void
75     handle_inspect( String JavaDoc [] targets, final InspectRequest request)
76         throws Exception JavaDoc
77     {
78         final InspectResult [] results = getProxy().mbeanInspect( request, targets );
79         
80         if ( results.length == 0 )
81         {
82             println( "<nothing inspected>" );
83         }
84         else
85         {
86             final String JavaDoc msg = ArrayStringifier.stringify( results, "\n\n");
87             println( msg );
88         }
89     }
90     
91         void
92     handle_inspect( final String JavaDoc [] targets )
93         throws Exception JavaDoc
94     {
95         final InspectRequest request = new InspectRequest( true );
96         
97         request.includeDescription = ! getBoolean( "noDescription", Boolean.TRUE ).booleanValue();
98             
99         if ( getBoolean( "all", Boolean.FALSE ).booleanValue() )
100         {
101             // should already be setup to get everything
102
}
103         else
104         {
105             request.includeSummary = getBoolean( "summary", Boolean.TRUE ).booleanValue();
106             request.constructors = getBoolean( "constructors", Boolean.FALSE ).booleanValue();
107         
108             request.attrs = getString( "attributes", null );
109             request.operations = getString( "operations", null );
110             request.notifications = getString( "notifications", null );
111         }
112         
113         handle_inspect( targets, request );
114     }
115     
116         void
117     handle_ops( final String JavaDoc [] targets )
118         throws Exception JavaDoc
119     {
120         final InspectRequest request = new InspectRequest( false );
121         request.operations = "*";
122         
123         handle_inspect( targets, request );
124     }
125     
126         void
127     handle_attrs( final String JavaDoc [] targets )
128         throws Exception JavaDoc
129     {
130         final InspectRequest request = new InspectRequest( false );
131         request.attrs = "*";
132         
133         handle_inspect( targets, request );
134     }
135     
136     
137         public static String JavaDoc []
138     getNames( )
139     {
140         return( new String JavaDoc [] { "inspect", "i", "ops", "attrs" } );
141     }
142     
143         void
144     executeInternal()
145         throws Exception JavaDoc
146     {
147         final String JavaDoc cmd = getCmdNameAsInvoked();
148         final String JavaDoc [] targets = getTargets();
149         
150         if ( targets == null )
151         {
152             printError( "No targets have been specified" );
153             return;
154         }
155         
156         establishProxy();
157         if ( cmd.equalsIgnoreCase( "inspect" ) )
158         {
159             handle_inspect( targets );
160         }
161         else if ( cmd.equalsIgnoreCase( "ops" ) )
162         {
163             handle_ops( targets );
164         }
165         else if ( cmd.equalsIgnoreCase( "attrs" ) )
166         {
167             handle_attrs( targets );
168         }
169     }
170 }
171
172
Popular Tags