1 5 package org.exoplatform.portlets.jmx.component; 6 7 import javax.management.MBeanInfo ;import javax.management.MBeanOperationInfo ; 8 import javax.management.MBeanParameterInfo ; 9 import javax.management.MBeanServer ; 10 import javax.management.ObjectName ; 11 import org.exoplatform.faces.core.component.UIExoCommand; 12 import org.exoplatform.faces.core.event.ExoActionEvent; 13 import org.exoplatform.faces.core.event.ExoActionListener; 14 15 16 20 public class UIMBean extends UIExoCommand { 21 final static public String EXECUTE_ACTION = "execute" ; 22 23 private MBeanInfo minfo_ ; 24 private ObjectName name_ ; 25 private MBeanServer mserver_ ; 26 27 public UIMBean() { 28 setId("UIMBean") ; 29 setClazz("UIMBean") ; 30 setRendererType("ViewMBeanRenderer") ; 31 addActionListener(ExecuteActionListener.class, EXECUTE_ACTION) ; 32 } 33 34 public String getFamily() { 35 return "org.exoplatform.portlets.jmx.component.UIMBean" ; 36 } 37 38 public ObjectName getObjectName() { return name_ ; } 39 40 public MBeanServer getMBeanServer() { return mserver_ ; } 41 42 public MBeanInfo getMBeanInfo() { return minfo_ ; } 43 44 public void setUIMBeanData(MBeanServer server, ObjectName name) throws Exception { 45 mserver_ = server ; 46 name_ = name ; 47 minfo_ = mserver_.getMBeanInfo(name); 48 } 49 50 public boolean canExecute( MBeanOperationInfo method) { 51 MBeanParameterInfo [] param = method.getSignature() ; 52 for(int i = 0 ; i < param.length; i++) { 53 if(param[i].getType().equals("java.lang.String") || 54 param[i].getType().equals("java.lang.Boolean") || 55 param[i].getType().equals("java.lang.Double") || 56 param[i].getType().equals("java.lang.Float") || 57 param[i].getType().equals("java.lang.Long") || 58 param[i].getType().equals("java.lang.Integer") || 59 param[i].getType().equals(Boolean.TYPE.getName()) || 60 param[i].getType().equals(Double.TYPE.getName()) || 61 param[i].getType().equals(Float.TYPE.getName()) || 62 param[i].getType().equals(Long.TYPE.getName()) || 63 param[i].getType().equals(Integer.TYPE.getName())) { 64 continue ; 65 } 66 return false ; 67 } 68 return true ; 69 } 70 71 static public class ExecuteActionListener extends ExoActionListener { 72 public void execute(ExoActionEvent event) throws Exception { 73 UIMBean uiMBean = (UIMBean)event.getComponent() ; 74 int methodId = Integer.parseInt(event.getParameter("methodId")) ; 75 MBeanOperationInfo [] method = uiMBean.minfo_.getOperations(); 76 for (int i = 0; i < method.length; i++) { 77 if(methodId == method[i].hashCode()) { 78 UIOperation uiOperation = (UIOperation) uiMBean.getSibling(UIOperation.class) ; 79 uiOperation.setOperation(uiMBean.mserver_, uiMBean.name_, method[i]) ; 80 uiMBean.setRenderedSibling(UIOperation.class) ; 81 return ; 82 } 83 } 84 } 85 } 86 } | Popular Tags |