KickJava   Java API By Example, From Geeks To Geeks.

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


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

25 public class UIListMBean extends UIGrid {
26   private static Parameter[] VIEW_ACTION = {new Parameter(ACTION , "view") } ;
27     private MBeanServer JavaDoc mserver_ ;
28   private MBeanDomain mdomain_;
29   private ObjectNameDataHandler dataHandler_ ;
30   
31     public UIListMBean() {
32         setId("UIListMbean") ;
33     setClazz("UIListMBean") ;
34     dataHandler_ = new ObjectNameDataHandler() ;
35     add(new Rows(dataHandler_, "even", "odd").
36         add(new Column("#{UIListMBean.header.object-name}", "name")).
37         add(new ActionColumn("#{UIListMBean.header.action}", "id").
38             add(true ,new Button("#{UIListMBean.button.view}", VIEW_ACTION)))) ;
39     addActionListener(SelectMBeanActionListener.class, "view") ;
40     }
41   
42   public void setMBeanServerDomain(MBeanServer JavaDoc mserver, MBeanDomain mdomain) {
43     mserver_ = mserver ;
44     mdomain_ = mdomain ;
45     dataHandler_.setDatas(mdomain.getMBeanNames()) ;
46   }
47   
48   
49   static public class ObjectNameDataHandler extends CollectionDataHandler {
50     private MBeanDomain.MBeanDescription desc_ ;
51     
52     public String JavaDoc getData(String JavaDoc fieldName) {
53       if("name".equals(fieldName)) return desc_.getObjectName().getCanonicalName();
54       if("id".equals(fieldName)) return desc_.getId();
55       return null ;
56     }
57     
58     public void setCurrentObject(Object JavaDoc o) { desc_ = (MBeanDomain.MBeanDescription) o; }
59   }
60   
61   static public class SelectMBeanActionListener extends ExoActionListener {
62     public void execute(ExoActionEvent event) throws Exception JavaDoc {
63       UIListMBean uiList = (UIListMBean)event.getComponent() ;
64       String JavaDoc mbean = event.getParameter("objectId") ;
65       ObjectName JavaDoc name = uiList.mdomain_.findMBeanObjectname(mbean) ;
66       UIJMXPortlet uiPortlet = (UIJMXPortlet) uiList.getAncestorOfType(UIJMXPortlet.class) ;
67       UIMBean uiMBean = (UIMBean) uiPortlet.getChildComponentOfType(UIMBean.class) ;
68       uiMBean.setUIMBeanData(uiList.mserver_, name) ;
69       uiPortlet.setRenderedComponent(uiMBean.getId()) ;
70     }
71   }
72 }
Popular Tags