KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
8 import java.util.Set JavaDoc;
9
10 import javax.management.MBeanServer JavaDoc;
11 import javax.management.ObjectName JavaDoc;
12 import org.exoplatform.faces.core.component.UIExoCommand;
13 import org.exoplatform.faces.core.event.ExoActionEvent;
14 import org.exoplatform.faces.core.event.ExoActionListener;
15 import org.exoplatform.portlets.jmx.component.model.MBeanDomain;
16
17 ;
18 /**
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: UIMBeanServer.java,v 1.2 2004/08/01 04:18:27 tuan08 Exp $
21  */

22 public class UIMBeanServer extends UIExoCommand {
23   static final public String JavaDoc SELECT_DOMAIN_ACTION = "selectDomain" ;
24   static final public String JavaDoc SELECT_MBEAN_ACTION = "selectMBean" ;
25   
26     private MBeanServer JavaDoc mserver_ ;
27   private MBeanDomain rootDomain_ ;
28   private String JavaDoc name_ ;
29   
30   public UIMBeanServer(MBeanServer JavaDoc server) {
31     mserver_ = server ;
32     rootDomain_ = new MBeanDomain("") ;
33     Set JavaDoc names = mserver_.queryNames(null, null) ;
34     Iterator JavaDoc i = names.iterator() ;
35     while(i.hasNext()) {
36         ObjectName JavaDoc oname = (ObjectName JavaDoc)i.next() ;
37       rootDomain_.addObjectName(oname) ;
38     }
39     name_ = server.getDefaultDomain() ;
40     addActionListener(SelectDomainActionListener.class, SELECT_DOMAIN_ACTION) ;
41     addActionListener(SelectMBeanActionListener.class, SELECT_MBEAN_ACTION) ;
42   }
43   
44   public MBeanServer JavaDoc getMBeanServer() { return mserver_ ; }
45   
46   public MBeanDomain getRootDomain() { return rootDomain_ ; }
47   
48   public String JavaDoc getName() { return name_ ; }
49   
50   public String JavaDoc getFamily() {
51     return "org.exoplatform.portlets.jmx.component.UIMBeanServer" ;
52   }
53   
54   static public class SelectDomainActionListener extends ExoActionListener {
55     public void execute(ExoActionEvent event) throws Exception JavaDoc {
56       UIMBeanServer uiServer = (UIMBeanServer)event.getComponent() ;
57       String JavaDoc domain = event.getParameter("domain") ;
58       MBeanDomain mdomain = uiServer.rootDomain_.findMBeanDomain(domain) ;
59       UIJMXPortlet uiPortlet = (UIJMXPortlet) uiServer.getAncestorOfType(UIJMXPortlet.class) ;
60       UIListMBean uiListMBean = (UIListMBean) uiPortlet.getChildComponentOfType(UIListMBean.class) ;
61       uiListMBean.setMBeanServerDomain(uiServer.getMBeanServer(), mdomain) ;
62       uiPortlet.setRenderedComponent(UIListMBean.class) ;
63       mdomain.setSelect(!mdomain.isSelect()) ;
64     }
65   }
66   
67   static public class SelectMBeanActionListener extends ExoActionListener {
68     public void execute(ExoActionEvent event) throws Exception JavaDoc {
69       UIMBeanServer uiServer = (UIMBeanServer)event.getComponent() ;
70       String JavaDoc mbean = event.getParameter("mbean") ;
71       ObjectName JavaDoc name = uiServer.rootDomain_.findMBeanObjectname(mbean) ;
72       UIJMXPortlet uiPortlet = (UIJMXPortlet) uiServer.getAncestorOfType(UIJMXPortlet.class) ;
73       UIMBean uiMBean = (UIMBean) uiPortlet.getChildComponentOfType(UIMBean.class) ;
74       uiMBean.setUIMBeanData(uiServer.mserver_, name) ;
75       uiPortlet.setRenderedComponent(uiMBean.getId()) ;
76     }
77   }
78 }
Popular Tags