1 5 package org.exoplatform.portlets.jmx.component; 6 7 import java.util.Iterator ; 8 import java.util.Set ; 9 10 import javax.management.MBeanServer ; 11 import javax.management.ObjectName ; 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 22 public class UIMBeanServer extends UIExoCommand { 23 static final public String SELECT_DOMAIN_ACTION = "selectDomain" ; 24 static final public String SELECT_MBEAN_ACTION = "selectMBean" ; 25 26 private MBeanServer mserver_ ; 27 private MBeanDomain rootDomain_ ; 28 private String name_ ; 29 30 public UIMBeanServer(MBeanServer server) { 31 mserver_ = server ; 32 rootDomain_ = new MBeanDomain("") ; 33 Set names = mserver_.queryNames(null, null) ; 34 Iterator i = names.iterator() ; 35 while(i.hasNext()) { 36 ObjectName oname = (ObjectName )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 getMBeanServer() { return mserver_ ; } 45 46 public MBeanDomain getRootDomain() { return rootDomain_ ; } 47 48 public String getName() { return name_ ; } 49 50 public String 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 { 56 UIMBeanServer uiServer = (UIMBeanServer)event.getComponent() ; 57 String 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 { 69 UIMBeanServer uiServer = (UIMBeanServer)event.getComponent() ; 70 String mbean = event.getParameter("mbean") ; 71 ObjectName 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 |