001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ListMBeanOperationsAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.mbean;
025:
026: import java.io.IOException;
027: import java.util.ArrayList;
028: import java.util.Collections;
029: import java.util.Comparator;
030:
031: import javax.management.MBeanInfo;
032: import javax.management.MBeanOperationInfo;
033: import javax.management.MBeanParameterInfo;
034: import javax.management.ObjectName;
035: import javax.servlet.ServletException;
036: import javax.servlet.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038:
039: import org.apache.struts.action.ActionForm;
040: import org.apache.struts.action.ActionForward;
041: import org.apache.struts.action.ActionMapping;
042: import org.objectweb.jonas.jmx.JonasManagementRepr;
043: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
044:
045: /**
046: * List of all Operations for a MBean.
047: *
048: * @author Michel-Ange ANTON
049: */
050:
051: public final class ListMBeanOperationsAction extends
052: ListMBeanDetailsAction {
053:
054: // --------------------------------------------------------- Public Methods
055:
056: public ActionForward executeAction(ActionMapping p_Mapping,
057: ActionForm p_Form, HttpServletRequest p_Request,
058: HttpServletResponse p_Response) throws IOException,
059: ServletException {
060:
061: try {
062: // Save current action
063: setAction(ACTION_OPERATIONS);
064: // Parameter
065: String sSelect = p_Request.getParameter("select");
066: // get server name
067: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
068: .getAttribute(WhereAreYou.SESSION_NAME);
069: String serverName = oWhere.getCurrentJonasServerName();
070:
071: // Create a request attribute with our collection of MBeans
072: ArrayList list = new ArrayList();
073:
074: // Get all infos of a MBean
075: ObjectName on = new ObjectName(sSelect);
076: MbeanItem oItem = MbeanItem.build(on);
077: MBeanInfo oMBeanInfo = JonasManagementRepr.getMBeanInfo(on,
078: serverName);
079: // Get attributes infos
080: MBeanOperationInfo[] aoMBeanOperationInfo = oMBeanInfo
081: .getOperations();
082: if (aoMBeanOperationInfo.length > 0) {
083: // Loop to append each attribute node
084: for (int i = 0; i < aoMBeanOperationInfo.length; i++) {
085: list.add(new ViewMBeanOperations(
086: aoMBeanOperationInfo[i]));
087: }
088: // Sort
089: Collections.sort(list, new MBeanOperationsByName());
090: }
091: // Set the beans
092: p_Request.setAttribute("MBean", oItem);
093: p_Request.setAttribute("MBeanOperations", list);
094: // Active and save filtering display if not exists
095: MbeanFilteringForm oForm = (MbeanFilteringForm) m_Session
096: .getAttribute("mbeanFilteringForm");
097: if (oForm == null) {
098: oForm = new MbeanFilteringForm();
099: oForm.reset(p_Mapping, p_Request);
100: m_Session.setAttribute("mbeanFilteringForm", oForm);
101: }
102: oForm.setSelectedName(sSelect);
103:
104: // Force the node selected in tree when the direct is used (MBeans list)
105: StringBuffer sbBranch = new StringBuffer("domain*mbeans");
106: sbBranch.append(WhereAreYou.NODE_SEPARATOR);
107: sbBranch.append(sSelect);
108: m_WhereAreYou.selectNameNode(sbBranch.toString(), true);
109: } catch (Throwable t) {
110: addGlobalError(t);
111: saveErrors(p_Request, m_Errors);
112: return (p_Mapping.findForward("Global Error"));
113: }
114: // Forward to the corresponding display page
115: return p_Mapping.findForward("List MBean Operations");
116: }
117:
118: // --------------------------------------------------------- Inner Classes
119:
120: public class ViewMBeanOperations {
121: private String name;
122: private String returnType;
123: private String impact;
124: private String parameters;
125: private String description;
126:
127: public ViewMBeanOperations() {
128: }
129:
130: public ViewMBeanOperations(MBeanOperationInfo po_Ope) {
131: setName(po_Ope.getName());
132: setReturnType(po_Ope.getReturnType());
133: setDescription(po_Ope.getDescription());
134: // Impact
135: switch (po_Ope.getImpact()) {
136: case MBeanOperationInfo.ACTION:
137: setImpact("Action");
138: break;
139: case MBeanOperationInfo.ACTION_INFO:
140: setImpact("Action info");
141: break;
142: case MBeanOperationInfo.INFO:
143: setImpact("Info");
144: break;
145: default:
146: setImpact("Unknown");
147: }
148: // Parameters
149: StringBuffer sb = new StringBuffer();
150: MBeanParameterInfo[] oParams = po_Ope.getSignature();
151: for (int i = 0; i < oParams.length; i++) {
152: sb.append(oParams[i].getType());
153: sb.append(" ");
154: sb.append(oParams[i].getName());
155: if (i < (oParams.length - 1)) {
156: sb.append(", ");
157: }
158: }
159: setParameters(sb.toString());
160: }
161:
162: public String getName() {
163: return name;
164: }
165:
166: public void setName(String name) {
167: this .name = name;
168: }
169:
170: public String getReturnType() {
171: return returnType;
172: }
173:
174: public void setReturnType(String returnType) {
175: this .returnType = returnType;
176: }
177:
178: public String getImpact() {
179: return impact;
180: }
181:
182: public void setImpact(String impact) {
183: this .impact = impact;
184: }
185:
186: public String getParameters() {
187: return parameters;
188: }
189:
190: public void setParameters(String parameters) {
191: this .parameters = parameters;
192: }
193:
194: public String getDescription() {
195: return description;
196: }
197:
198: public void setDescription(String description) {
199: this .description = description;
200: }
201: }
202:
203: public class MBeanOperationsByName implements Comparator {
204:
205: public int compare(Object p_O1, Object p_O2) {
206: ViewMBeanOperations o1 = (ViewMBeanOperations) p_O1;
207: ViewMBeanOperations o2 = (ViewMBeanOperations) p_O2;
208: return o1.getName().compareToIgnoreCase(o2.getName());
209: }
210:
211: public boolean equals(Object p_Obj) {
212: if (p_Obj instanceof ViewMBeanOperations) {
213: return true;
214: }
215: return false;
216: }
217: }
218:
219: }
|