KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > jmx > renderer > html > NavigatorRenderer


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.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10
11 import javax.management.ObjectName JavaDoc;
12
13 import javax.faces.component.UIComponent;
14 import javax.faces.context.FacesContext;
15 import javax.faces.context.ResponseWriter;
16 import org.exoplatform.faces.core.component.model.Parameter;
17 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
18 import org.exoplatform.portlets.jmx.component.UIMBeanServer;
19 import org.exoplatform.portlets.jmx.component.UINavigator;
20 import org.exoplatform.portlets.jmx.component.model.MBeanDomain;
21
22 /**
23  * Jul 29, 2004
24  * @author: Tuan Nguyen
25  * @email: tuan08@users.sourceforge.net
26  * @version: $Id: NavigatorRenderer.java,v 1.2 2004/08/01 04:18:28 tuan08 Exp $
27  */

28 public class NavigatorRenderer extends HtmlBasicRenderer {
29   private static Parameter selectMServerParam = new Parameter(ACTION, UINavigator.SELECT_ACTION) ;
30   private static Parameter selectDomainParam = new Parameter(ACTION, UIMBeanServer.SELECT_DOMAIN_ACTION);
31   private static Parameter selectMBeanParam = new Parameter(ACTION, UIMBeanServer.SELECT_MBEAN_ACTION);
32
33   public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
34         UINavigator uiNavigator = (UINavigator) component ;
35     java.util.List JavaDoc children = uiNavigator.getChildren() ;
36     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
37     ResponseWriter w = context.getResponseWriter() ;
38     Parameter domainParam = new Parameter("domain", "") ;
39     Parameter[] selectDomainParams = {selectDomainParam, domainParam} ;
40     Parameter mbeanParam = new Parameter("mbean", "") ;
41     Parameter[] selectMBeanParams = {selectMBeanParam, mbeanParam} ;
42     Parameter mserverParam = new Parameter("mserver", "") ;
43     Parameter[] selectMServerParams = {selectMServerParam, mserverParam} ;
44     for(int i = 0 ; i < children.size(); i++) {
45       UIMBeanServer uiServer = (UIMBeanServer) children.get(i) ;
46       mserverParam.setValue(uiServer.getId()) ;
47       w.write("<div>\n") ;
48       if(uiServer.isRendered()) w.write(res.getString("UINavigator.icon.collapse")) ;
49       else w.write(res.getString("UINavigator.icon.expand")) ;
50       linkRenderer_.render(w,uiNavigator , uiServer.getName(), selectMServerParams) ;
51       if(uiServer.isRendered()) {
52         MBeanDomain rootDomain = uiServer.getRootDomain() ;
53         List JavaDoc childrenDomains = rootDomain.getDomains() ;
54         for(int j = 0 ; j < childrenDomains.size(); j++) {
55           MBeanDomain child = (MBeanDomain) childrenDomains.get(j) ;
56           renderDomain(w, uiServer, child, selectDomainParams, selectMBeanParams, res) ;
57         }
58       }
59       w.write("</div>\n") ;
60     }
61     }
62   
63   public void renderDomain(ResponseWriter w, UIMBeanServer uiServer, MBeanDomain domain,
64                            Parameter[] selectDomainParams,
65                            Parameter[] selectMBeanParams,
66                            ResourceBundle JavaDoc res) throws IOException JavaDoc {
67      w.write("<ul>") ;
68      selectDomainParams[1].setValue(domain.getDomainName()) ;
69      if(domain.isSelect()) w.write(res.getString("UINavigator.icon.collapse")) ;
70      else w.write(res.getString("UINavigator.icon.expand")) ;
71      linkRenderer_.render(w,uiServer, domain.getLabel(), selectDomainParams) ;
72      if(domain.isSelect()) {
73       List JavaDoc childrenDomains = domain.getDomains() ;
74       for(int i = 0 ; i < childrenDomains.size(); i++) {
75         MBeanDomain child = (MBeanDomain) childrenDomains.get(i) ;
76         renderDomain(w, uiServer, child, selectDomainParams, selectMBeanParams, res) ;
77       }
78       List JavaDoc mbeans = domain.getMBeanNames() ;
79       for(int i = 0 ; i < mbeans.size(); i++) {
80         MBeanDomain.MBeanDescription mbean = (MBeanDomain.MBeanDescription ) mbeans.get(i) ;
81         selectMBeanParams[1].setValue(mbean.getId()) ;
82         w.write("<li class='leaf'>") ;
83         linkRenderer_.render(w, uiServer,mbean.getLabel(), selectMBeanParams) ;
84         w.write("</li>") ;
85       }
86      }
87      w.write("</ul>\n") ;
88   }
89 }
Popular Tags