1 25 26 package org.objectweb.jonas.webapp.jonasadmin.mbean; 27 28 import java.io.IOException ; 29 import java.util.ArrayList ; 30 import java.util.Collections ; 31 import java.util.Comparator ; 32 33 import javax.management.MBeanInfo ; 34 import javax.management.MBeanOperationInfo ; 35 import javax.management.MBeanParameterInfo ; 36 import javax.management.ObjectName ; 37 import javax.servlet.ServletException ; 38 import javax.servlet.http.HttpServletRequest ; 39 import javax.servlet.http.HttpServletResponse ; 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 53 54 public final class ListMBeanOperationsAction extends ListMBeanDetailsAction { 55 56 58 public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form 59 , HttpServletRequest p_Request, HttpServletResponse p_Response) 60 throws IOException , ServletException { 61 62 try { 63 setAction(ACTION_OPERATIONS); 65 String sSelect = p_Request.getParameter("select"); 67 68 ArrayList list = new ArrayList (); 70 71 ObjectName on = new ObjectName (sSelect); 73 MbeanItem oItem = MbeanItem.build(on); 74 MBeanInfo oMBeanInfo = JonasManagementRepr.getMBeanInfo(on); 75 MBeanOperationInfo [] aoMBeanOperationInfo = oMBeanInfo.getOperations(); 77 if (aoMBeanOperationInfo.length > 0) { 78 for (int i = 0; i < aoMBeanOperationInfo.length; i++) { 80 list.add(new ViewMBeanOperations(aoMBeanOperationInfo[i])); 81 } 82 Collections.sort(list, new MBeanOperationsByName()); 84 } 85 p_Request.setAttribute("MBean", oItem); 87 p_Request.setAttribute("MBeanOperations", list); 88 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 StringBuffer sbBranch = new StringBuffer ("domain*mbeans"); 100 sbBranch.append(WhereAreYou.NODE_SEPARATOR); 101 sbBranch.append(sSelect); 102 m_WhereAreYou.selectNameNode(sbBranch.toString(), true); 103 } 104 catch (Throwable t) { 105 addGlobalError(t); 106 saveErrors(p_Request, m_Errors); 107 return (p_Mapping.findForward("Global Error")); 108 } 109 return p_Mapping.findForward("List MBean Operations"); 111 } 112 113 115 public class ViewMBeanOperations { 116 private String name; 117 private String returnType; 118 private String impact; 119 private String parameters; 120 private String description; 121 122 public ViewMBeanOperations() { 123 } 124 125 public ViewMBeanOperations(MBeanOperationInfo po_Ope) { 126 setName(po_Ope.getName()); 127 setReturnType(po_Ope.getReturnType()); 128 setDescription(po_Ope.getDescription()); 129 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 StringBuffer sb = new StringBuffer (); 145 MBeanParameterInfo [] 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 getName() { 158 return name; 159 } 160 161 public void setName(String name) { 162 this.name = name; 163 } 164 165 public String getReturnType() { 166 return returnType; 167 } 168 169 public void setReturnType(String returnType) { 170 this.returnType = returnType; 171 } 172 173 public String getImpact() { 174 return impact; 175 } 176 177 public void setImpact(String impact) { 178 this.impact = impact; 179 } 180 181 public String getParameters() { 182 return parameters; 183 } 184 185 public void setParameters(String parameters) { 186 this.parameters = parameters; 187 } 188 189 public String getDescription() { 190 return description; 191 } 192 193 public void setDescription(String description) { 194 this.description = description; 195 } 196 } 197 198 public class MBeanOperationsByName implements Comparator { 199 200 public int compare(Object p_O1, Object 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 p_Obj) { 207 if (p_Obj instanceof ViewMBeanOperations) { 208 return true; 209 } 210 return false; 211 } 212 } 213 214 } 215 | Popular Tags |