KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > actions > app > MBeanListAction


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.webui.actions.app;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.jmanage.core.data.MBeanData;
22 import org.jmanage.core.services.MBeanService;
23 import org.jmanage.core.services.ServiceFactory;
24 import org.jmanage.webui.actions.BaseAction;
25 import org.jmanage.webui.forms.MBeanQueryForm;
26 import org.jmanage.webui.util.*;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30 import java.util.*;
31
32 /**
33  *
34  * date: Jun 10, 2004
35  * @author Rakesh Kalra
36  */

37 public class MBeanListAction extends BaseAction {
38
39     public ActionForward execute(WebContext context,
40                                  ActionMapping mapping,
41                                  ActionForm actionForm,
42                                  HttpServletRequest JavaDoc request,
43                                  HttpServletResponse JavaDoc response)
44             throws Exception JavaDoc {
45
46         MBeanQueryForm queryForm = (MBeanQueryForm)actionForm;
47         final String JavaDoc queryObjectName = queryForm.getObjectName();
48         MBeanService mbeanService = ServiceFactory.getMBeanService();
49         List mbeanDataList = mbeanService.queryMBeans(Utils.getServiceContext(context),
50                 queryObjectName);
51
52         Map domainToObjectNameListMap = new TreeMap();
53         ObjectNameTuple tuple = new ObjectNameTuple();
54         for(Iterator it=mbeanDataList.iterator(); it.hasNext();){
55             MBeanData mbeanData = (MBeanData)it.next();
56             tuple.setObjectName(mbeanData.getName());
57             String JavaDoc domain = tuple.getDomain();
58             String JavaDoc name = tuple.getName();
59             Set objectNameList = (Set)domainToObjectNameListMap.get(domain);
60             if(objectNameList == null){
61                 objectNameList = new TreeSet();
62                 domainToObjectNameListMap.put(domain, objectNameList);
63             }
64             objectNameList.add(name);
65         }
66
67         request.setAttribute("domainToObjectNameListMap", domainToObjectNameListMap);
68         /*set current page for navigation*/
69         request.setAttribute(RequestAttributes.NAV_CURRENT_PAGE, "Query");
70         return mapping.findForward(Forwards.SUCCESS);
71     }
72
73     private static class ObjectNameTuple{
74         String JavaDoc domain;
75         String JavaDoc name;
76
77         void setObjectName(String JavaDoc canonicalName){
78             int index = canonicalName.indexOf(":");
79             domain = canonicalName.substring(0, index);
80             name = canonicalName.substring(index + 1);
81         }
82
83         String JavaDoc getName(){
84             return name;
85         }
86         String JavaDoc getDomain(){
87             return domain;
88         }
89     }
90 }
91
Popular Tags