KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > cmdui > commands > MBeansHandler


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.cmdui.commands;
17
18 import org.jmanage.cmdui.CommandHandler;
19 import org.jmanage.cmdui.HandlerContext;
20 import org.jmanage.cmdui.CommandConstants;
21 import org.jmanage.cmdui.util.Out;
22 import org.jmanage.cmdui.util.CommandUtils;
23 import org.jmanage.core.services.ServiceFactory;
24 import org.jmanage.core.services.ConfigurationService;
25
26 import java.util.List JavaDoc;
27
28 /**
29  *
30  * date: Feb 21, 2005
31  * @author Rakesh Kalra
32  */

33 public class MBeansHandler implements CommandHandler {
34
35     /**
36      * Lists configured mbeans for the given application
37      *
38      * @param context
39      * @return true if the command was handled properly; false otherwise
40      */

41     public boolean execute(HandlerContext context) {
42         String JavaDoc[] args = context.getCommand().getArgs();
43         if(args.length != 1){
44             usage();
45             return false;
46         }
47
48         String JavaDoc appName = args[0];
49
50         ConfigurationService configService =
51                 ServiceFactory.getConfigurationService();
52         List JavaDoc mbeanDataList =
53                 configService.getConfiguredMBeans(
54                         context.getServiceContext(appName));
55         assert mbeanDataList != null;
56         CommandUtils.printMBeans(mbeanDataList);
57         return true;
58     }
59
60     public String JavaDoc getShortHelp() {
61         return "Lists configured mbeans for the given application";
62     }
63
64     public void help() {
65         Out.println(getShortHelp());
66         Out.println("Usage:");
67         Out.println(CommandConstants.MBEANS + " <application name>");
68     }
69
70     private void usage(){
71         Out.println("Invalid arguments");
72         help();
73     }
74 }
75
Popular Tags