ListMBeanOperationsAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: ListMBeanOperationsAction.java,v 1.7 2004/03/19 14:31:47 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.mbean;
00027 
00028 import java.io.IOException;
00029 import java.util.ArrayList;
00030 import java.util.Collections;
00031 import java.util.Comparator;
00032 
00033 import javax.management.MBeanInfo;
00034 import javax.management.MBeanOperationInfo;
00035 import javax.management.MBeanParameterInfo;
00036 import javax.management.ObjectName;
00037 import javax.servlet.ServletException;
00038 import javax.servlet.http.HttpServletRequest;
00039 import javax.servlet.http.HttpServletResponse;
00040 
00041 import org.apache.struts.action.ActionForm;
00042 import org.apache.struts.action.ActionForward;
00043 import org.apache.struts.action.ActionMapping;
00044 import org.objectweb.jonas.jmx.JonasManagementRepr;
00045 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
00046 
00047 
00054 public final class ListMBeanOperationsAction extends ListMBeanDetailsAction {
00055 
00056 // --------------------------------------------------------- Public Methods
00057 
00058     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
00059         , HttpServletRequest p_Request, HttpServletResponse p_Response)
00060         throws IOException, ServletException {
00061 
00062         try {
00063             // Save current action
00064             setAction(ACTION_OPERATIONS);
00065             // Parameter
00066             String sSelect = p_Request.getParameter("select");
00067 
00068             // Create a request attribute with our collection of MBeans
00069             ArrayList list = new ArrayList();
00070 
00071             // Get all infos of a MBean
00072             ObjectName on = new ObjectName(sSelect);
00073             MbeanItem oItem = MbeanItem.build(on);
00074             MBeanInfo oMBeanInfo = JonasManagementRepr.getMBeanInfo(on);
00075             // Get attributes infos
00076             MBeanOperationInfo[] aoMBeanOperationInfo = oMBeanInfo.getOperations();
00077             if (aoMBeanOperationInfo.length > 0) {
00078                 // Loop to append each attribute node
00079                 for (int i = 0; i < aoMBeanOperationInfo.length; i++) {
00080                     list.add(new ViewMBeanOperations(aoMBeanOperationInfo[i]));
00081                 }
00082                 // Sort
00083                 Collections.sort(list, new MBeanOperationsByName());
00084             }
00085             // Set the beans
00086             p_Request.setAttribute("MBean", oItem);
00087             p_Request.setAttribute("MBeanOperations", list);
00088             // Active and save filtering display if not exists
00089             MbeanFilteringForm oForm = (MbeanFilteringForm) m_Session.getAttribute(
00090                 "mbeanFilteringForm");
00091             if (oForm == null) {
00092                 oForm = new MbeanFilteringForm();
00093                 oForm.reset(p_Mapping, p_Request);
00094                 m_Session.setAttribute("mbeanFilteringForm", oForm);
00095             }
00096             oForm.setSelectedName(sSelect);
00097 
00098             // Force the node selected in tree when the direct is used (MBeans list)
00099             StringBuffer sbBranch = new StringBuffer("mbeans");
00100             sbBranch.append(WhereAreYou.NODE_SEPARATOR);
00101             sbBranch.append(sSelect);
00102             m_WhereAreYou.selectNameNode(sbBranch.toString(), true);
00103         }
00104         catch (Throwable t) {
00105             addGlobalError(t);
00106             saveErrors(p_Request, m_Errors);
00107             return (p_Mapping.findForward("Global Error"));
00108         }
00109         // Forward to the corresponding display page
00110         return p_Mapping.findForward("List MBean Operations");
00111     }
00112 
00113 // --------------------------------------------------------- Inner Classes
00114 
00115     public class ViewMBeanOperations {
00116         private String name;
00117         private String returnType;
00118         private String impact;
00119         private String parameters;
00120         private String description;
00121 
00122         public ViewMBeanOperations() {
00123         }
00124 
00125         public ViewMBeanOperations(MBeanOperationInfo po_Ope) {
00126             setName(po_Ope.getName());
00127             setReturnType(po_Ope.getReturnType());
00128             setDescription(po_Ope.getDescription());
00129             // Impact
00130             switch (po_Ope.getImpact()) {
00131                 case MBeanOperationInfo.ACTION:
00132                     setImpact("Action");
00133                     break;
00134                 case MBeanOperationInfo.ACTION_INFO:
00135                     setImpact("Action info");
00136                     break;
00137                 case MBeanOperationInfo.INFO:
00138                     setImpact("Info");
00139                     break;
00140                 default:
00141                     setImpact("Unknown");
00142             }
00143             // Parameters
00144             StringBuffer sb = new StringBuffer();
00145             MBeanParameterInfo[] oParams = po_Ope.getSignature();
00146             for (int i = 0; i < oParams.length; i++) {
00147                 sb.append(oParams[i].getType());
00148                 sb.append(" ");
00149                 sb.append(oParams[i].getName());
00150                 if (i < (oParams.length - 1)) {
00151                     sb.append(", ");
00152                 }
00153             }
00154             setParameters(sb.toString());
00155         }
00156 
00157         public String getName() {
00158             return name;
00159         }
00160 
00161         public void setName(String name) {
00162             this.name = name;
00163         }
00164 
00165         public String getReturnType() {
00166             return returnType;
00167         }
00168 
00169         public void setReturnType(String returnType) {
00170             this.returnType = returnType;
00171         }
00172 
00173         public String getImpact() {
00174             return impact;
00175         }
00176 
00177         public void setImpact(String impact) {
00178             this.impact = impact;
00179         }
00180 
00181         public String getParameters() {
00182             return parameters;
00183         }
00184 
00185         public void setParameters(String parameters) {
00186             this.parameters = parameters;
00187         }
00188 
00189         public String getDescription() {
00190             return description;
00191         }
00192 
00193         public void setDescription(String description) {
00194             this.description = description;
00195         }
00196     }
00197 
00198     public class MBeanOperationsByName implements Comparator {
00199 
00200         public int compare(Object p_O1, Object p_O2) {
00201             ViewMBeanOperations o1 = (ViewMBeanOperations) p_O1;
00202             ViewMBeanOperations o2 = (ViewMBeanOperations) p_O2;
00203             return o1.getName().compareToIgnoreCase(o2.getName());
00204         }
00205 
00206         public boolean equals(Object p_Obj) {
00207             if (p_Obj instanceof ViewMBeanOperations) {
00208                 return true;
00209             }
00210             return false;
00211         }
00212     }
00213 
00214 }

Generated on Tue Feb 15 15:05:28 2005 for JOnAS by  doxygen 1.3.9.1