KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > cmdui > Main


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;
17
18 import org.jmanage.core.services.ServiceFactory;
19 import org.jmanage.core.util.JManageProperties;
20 import org.jmanage.core.util.Loggers;
21
22 import java.util.logging.Logger JavaDoc;
23 import java.util.logging.LogManager JavaDoc;
24 import java.util.logging.ConsoleHandler JavaDoc;
25
26 /**
27  *
28  * jmanage -username admin -password 123456 -url <jmanage-url> <command> <command args>
29  * <p>
30  * commands:
31  * <p>
32  * <li>apps
33  * <li>mbeans &lt;appName&gt; [filter expression]
34  * <li>cmbeans &lt;appName&gt;
35  * <li>info &lt;appName&gt;/&lt;mbeanName[configured name or object name]&gt;
36  * <li>execute &lt;appName&gt;/&lt;mbeanName&gt;/&lt;operationName&gt; [args]
37  * <li>print &lt;appName&gt;/&lt;mbeanName&gt;/attributeName1 [attributeName2]
38  * <li>get &lt;appName&gt;/&lt;mbeanName&gt; &lt;attributeName&gt; newValue
39  * <li>set &lt;appName&gt;/&lt;mbeanName&gt; &lt;attributeName&gt; newValue
40  * <li>setattrs &lt;appName&gt;/&lt;mbeanName&gt; &lt;attributeName&gt;=newValue ...
41  *
42  * TODO:
43  *
44  * serverinfo
45  * register
46  * unregister
47  *
48  *
49  * date: Feb 4, 2005
50  * @author Rakesh Kalra
51  */

52 public class Main {
53
54     private static final Logger JavaDoc logger = Loggers.getLogger(Main.class);
55
56     static{
57         /* initialize ServiceFactory */
58         if(JManageProperties.getJManageURL() == null){
59             /* run the factory in local mode */
60             ServiceFactory.init(ServiceFactory.MODE_LOCAL);
61         }else{
62             ServiceFactory.init(ServiceFactory.MODE_REMOTE);
63         }
64     }
65
66     public static void main(String JavaDoc[] args)
67         throws Exception JavaDoc {
68
69         Command command = Command.get(args);
70
71         /* setup logging */
72         setLogging(command);
73
74         /* authenticate the user */
75         if(command.isAuthRequired()){
76             if(!command.authenticate()){
77                 System.out.println("Authentication failed.");
78                 return;
79             }
80         }
81
82         if(command.getName() == null){
83             /* get into the prompt mode */
84             PromptMode promptMode = new PromptMode(command);
85             promptMode.start();
86         }else{
87             /* execute command */
88             command.execute();
89         }
90     }
91
92     private static void setLogging(Command command){
93         LogManager JavaDoc logManager = LogManager.getLogManager();
94         logManager.reset();
95         /* set the log level on the root logger */
96         Logger JavaDoc rootLogger = Logger.getLogger("");
97         rootLogger.setLevel(command.getLogLevel());
98         ConsoleHandler JavaDoc consoleHandler = new ConsoleHandler JavaDoc();
99         consoleHandler.setLevel(command.getLogLevel());
100         rootLogger.addHandler(consoleHandler);
101
102         logger.fine("Log level=" + command.getLogLevel());
103     }
104 }
105
Popular Tags