KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > mbean > ListMBeanOperationsAction


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ListMBeanOperationsAction.java,v 1.8 2005/03/15 14:45:29 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.mbean;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.Comparator JavaDoc;
32
33 import javax.management.MBeanInfo JavaDoc;
34 import javax.management.MBeanOperationInfo JavaDoc;
35 import javax.management.MBeanParameterInfo JavaDoc;
36 import javax.management.ObjectName JavaDoc;
37 import javax.servlet.ServletException JavaDoc;
38 import javax.servlet.http.HttpServletRequest JavaDoc;
39 import javax.servlet.http.HttpServletResponse JavaDoc;
40
41 import org.apache.struts.action.ActionForm;
42 import org.apache.struts.action.ActionForward;
43 import org.apache.struts.action.ActionMapping;
44 import org.objectweb.jonas.jmx.JonasManagementRepr;
45 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
46
47
48 /**
49  * List of all Operations for a MBean.
50  *
51  * @author Michel-Ange ANTON
52  */

53
54 public final class ListMBeanOperationsAction extends ListMBeanDetailsAction {
55
56 // --------------------------------------------------------- Public Methods
57

58     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
59         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
60         throws IOException JavaDoc, ServletException JavaDoc {
61
62         try {
63             // Save current action
64
setAction(ACTION_OPERATIONS);
65             // Parameter
66
String JavaDoc sSelect = p_Request.getParameter("select");
67
68             // Create a request attribute with our collection of MBeans
69
ArrayList JavaDoc list = new ArrayList JavaDoc();
70
71             // Get all infos of a MBean
72
ObjectName JavaDoc on = new ObjectName JavaDoc(sSelect);
73             MbeanItem oItem = MbeanItem.build(on);
74             MBeanInfo JavaDoc oMBeanInfo = JonasManagementRepr.getMBeanInfo(on);
75             // Get attributes infos
76
MBeanOperationInfo JavaDoc[] aoMBeanOperationInfo = oMBeanInfo.getOperations();
77             if (aoMBeanOperationInfo.length > 0) {
78                 // Loop to append each attribute node
79
for (int i = 0; i < aoMBeanOperationInfo.length; i++) {
80                     list.add(new ViewMBeanOperations(aoMBeanOperationInfo[i]));
81                 }
82                 // Sort
83
Collections.sort(list, new MBeanOperationsByName());
84             }
85             // Set the beans
86
p_Request.setAttribute("MBean", oItem);
87             p_Request.setAttribute("MBeanOperations", list);
88             // Active and save filtering display if not exists
89
MbeanFilteringForm oForm = (MbeanFilteringForm) m_Session.getAttribute(
90                 "mbeanFilteringForm");
91             if (oForm == null) {
92                 oForm = new MbeanFilteringForm();
93                 oForm.reset(p_Mapping, p_Request);
94                 m_Session.setAttribute("mbeanFilteringForm", oForm);
95             }
96             oForm.setSelectedName(sSelect);
97
98             // Force the node selected in tree when the direct is used (MBeans list)
99
StringBuffer JavaDoc sbBranch = new StringBuffer JavaDoc("domain*mbeans");
100             sbBranch.append(WhereAreYou.NODE_SEPARATOR);
101             sbBranch.append(sSelect);
102             m_WhereAreYou.selectNameNode(sbBranch.toString(), true);
103         }
104         catch (Throwable JavaDoc t) {
105             addGlobalError(t);
106             saveErrors(p_Request, m_Errors);
107             return (p_Mapping.findForward("Global Error"));
108         }
109         // Forward to the corresponding display page
110
return p_Mapping.findForward("List MBean Operations");
111     }
112
113 // --------------------------------------------------------- Inner Classes
114

115     public class ViewMBeanOperations {
116         private String JavaDoc name;
117         private String JavaDoc returnType;
118         private String JavaDoc impact;
119         private String JavaDoc parameters;
120         private String JavaDoc description;
121
122         public ViewMBeanOperations() {
123         }
124
125         public ViewMBeanOperations(MBeanOperationInfo JavaDoc po_Ope) {
126             setName(po_Ope.getName());
127             setReturnType(po_Ope.getReturnType());
128             setDescription(po_Ope.getDescription());
129             // Impact
130
switch (po_Ope.getImpact()) {
131                 case MBeanOperationInfo.ACTION:
132                     setImpact("Action");
133                     break;
134                 case MBeanOperationInfo.ACTION_INFO:
135                     setImpact("Action info");
136                     break;
137                 case MBeanOperationInfo.INFO:
138                     setImpact("Info");
139                     break;
140                 default:
141                     setImpact("Unknown");
142             }
143             // Parameters
144
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
145             MBeanParameterInfo JavaDoc[] oParams = po_Ope.getSignature();
146             for (int i = 0; i < oParams.length; i++) {
147                 sb.append(oParams[i].getType());
148                 sb.append(" ");
149                 sb.append(oParams[i].getName());
150                 if (i < (oParams.length - 1)) {
151                     sb.append(", ");
152                 }
153             }
154             setParameters(sb.toString());
155         }
156
157         public String JavaDoc getName() {
158             return name;
159         }
160
161         public void setName(String JavaDoc name) {
162             this.name = name;
163         }
164
165         public String JavaDoc getReturnType() {
166             return returnType;
167         }
168
169         public void setReturnType(String JavaDoc returnType) {
170             this.returnType = returnType;
171         }
172
173         public String JavaDoc getImpact() {
174             return impact;
175         }
176
177         public void setImpact(String JavaDoc impact) {
178             this.impact = impact;
179         }
180
181         public String JavaDoc getParameters() {
182             return parameters;
183         }
184
185         public void setParameters(String JavaDoc parameters) {
186             this.parameters = parameters;
187         }
188
189         public String JavaDoc getDescription() {
190             return description;
191         }
192
193         public void setDescription(String JavaDoc description) {
194             this.description = description;
195         }
196     }
197
198     public class MBeanOperationsByName implements Comparator JavaDoc {
199
200         public int compare(Object JavaDoc p_O1, Object JavaDoc p_O2) {
201             ViewMBeanOperations o1 = (ViewMBeanOperations) p_O1;
202             ViewMBeanOperations o2 = (ViewMBeanOperations) p_O2;
203             return o1.getName().compareToIgnoreCase(o2.getName());
204         }
205
206         public boolean equals(Object JavaDoc p_Obj) {
207             if (p_Obj instanceof ViewMBeanOperations) {
208                 return true;
209             }
210             return false;
211         }
212     }
213
214 }
215
Popular Tags