KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > jmx > component > UIMBean


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.jmx.component;
6
7 import javax.management.MBeanInfo JavaDoc;import javax.management.MBeanOperationInfo JavaDoc;
8 import javax.management.MBeanParameterInfo JavaDoc;
9 import javax.management.MBeanServer JavaDoc;
10 import javax.management.ObjectName JavaDoc;
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 /**
17  * @email: tuan08@users.sourceforge.net
18  * @version: $Id: UIMBean.java,v 1.3 2004/08/01 18:56:11 tuan08 Exp $
19  */

20 public class UIMBean extends UIExoCommand {
21   final static public String JavaDoc EXECUTE_ACTION = "execute" ;
22   
23     private MBeanInfo JavaDoc minfo_ ;
24   private ObjectName JavaDoc name_ ;
25   private MBeanServer JavaDoc 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 JavaDoc getFamily() {
35     return "org.exoplatform.portlets.jmx.component.UIMBean" ;
36   }
37   
38   public ObjectName JavaDoc getObjectName() { return name_ ; }
39   
40   public MBeanServer JavaDoc getMBeanServer() { return mserver_ ; }
41   
42   public MBeanInfo JavaDoc getMBeanInfo() { return minfo_ ; }
43   
44   public void setUIMBeanData(MBeanServer JavaDoc server, ObjectName JavaDoc name) throws Exception JavaDoc {
45     mserver_ = server ;
46     name_ = name ;
47     minfo_ = mserver_.getMBeanInfo(name);
48   }
49   
50   public boolean canExecute( MBeanOperationInfo JavaDoc method) {
51      MBeanParameterInfo JavaDoc[] 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 JavaDoc {
73       UIMBean uiMBean = (UIMBean)event.getComponent() ;
74       int methodId = Integer.parseInt(event.getParameter("methodId")) ;
75       MBeanOperationInfo JavaDoc[] 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