1 5 package org.exoplatform.portlets.jmx.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.List ; 9 import java.util.ResourceBundle ; 10 11 import javax.management.ObjectName ; 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 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 { 34 UINavigator uiNavigator = (UINavigator) component ; 35 java.util.List children = uiNavigator.getChildren() ; 36 ResourceBundle 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 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 res) throws IOException { 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 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 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 |