KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Out;
21 import org.jmanage.core.services.ConfigurationService;
22 import org.jmanage.core.services.ServiceFactory;
23 import org.jmanage.core.data.ApplicationConfigData;
24
25 import java.util.List JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 /**
29  *
30  * date: Feb 4, 2005
31  * @author Rakesh Kalra
32  */

33 public class ListApplicationsHandler implements CommandHandler {
34
35     public boolean execute(HandlerContext context) {
36
37         ConfigurationService configService =
38                 ServiceFactory.getConfigurationService();
39         List JavaDoc appConfigList = configService.getAllApplications(
40                 context.getServiceContext());
41         for(Iterator JavaDoc it=appConfigList.iterator(); it.hasNext();){
42             ApplicationConfigData appConfig = (ApplicationConfigData)it.next();
43             if(appConfig.isCluster()){
44                 Out.println(appConfig.getName() + " [cluster]");
45                 for(Iterator JavaDoc it2=appConfig.getChildApplications().iterator();it2.hasNext();){
46                     Out.print("+ ");
47                     printApplication((ApplicationConfigData)it2.next());
48                 }
49             }else{
50                 printApplication(appConfig);
51             }
52         }
53         return true;
54     }
55
56     private void printApplication(ApplicationConfigData appConfig){
57         assert !appConfig.isCluster();
58         Out.print(appConfig.getName());
59         Out.println(" [" + appConfig.getType() + "]" +
60                         "\t" + appConfig.getURL() +
61                         "\t" + appConfig.getUsername());
62     }
63
64     public String JavaDoc getShortHelp() {
65         return "Lists all configured applications in jManage";
66     }
67
68     public void help() {
69         Out.println(getShortHelp());
70     }
71 }
72
Popular Tags