1 25 26 package org.objectweb.jonas.webapp.jonasadmin; 27 28 import java.net.URLEncoder ; 29 import java.util.ArrayList ; 30 import java.util.Collections ; 31 import java.util.Iterator ; 32 33 import javax.management.MBeanAttributeInfo ; 34 import javax.management.MBeanInfo ; 35 import javax.management.MBeanOperationInfo ; 36 import javax.management.ObjectName ; 37 import javax.servlet.http.HttpServletRequest ; 38 39 import org.apache.struts.Globals; 40 import org.apache.struts.action.ActionServlet; 41 import org.apache.struts.util.MessageResources; 42 43 import org.objectweb.jonas.jmx.JonasManagementRepr; 44 import org.objectweb.jonas.webapp.jonasadmin.common.BeanComparator; 45 import org.objectweb.jonas.webapp.jonasadmin.mbean.J2eeMbeanItem; 46 import org.objectweb.jonas.webapp.jonasadmin.mbean.MbeanItem; 47 import org.objectweb.jonas.webapp.jonasadmin.mbean.OwnerMbeanItem; 48 import org.objectweb.jonas.webapp.taglib.TreeBuilder; 49 import org.objectweb.jonas.webapp.taglib.TreeControl; 50 import org.objectweb.jonas.webapp.taglib.TreeControlNode; 51 52 59 60 public class MBeanTreeBuilder implements TreeBuilder { 61 63 65 74 public void buildTree(TreeControl treeControl, ActionServlet servlet 75 , HttpServletRequest request) { 76 try { 77 TreeControlNode rootNode = treeControl.getRoot(); 78 MessageResources resources = (MessageResources) servlet.getServletContext(). 79 getAttribute(Globals.MESSAGES_KEY); 80 getMBeans(rootNode, resources); 81 } 82 catch (Throwable t) { 83 t.printStackTrace(System.out); 84 } 85 } 86 87 89 97 public void getMBeans(TreeControlNode rootNode, MessageResources resources) 98 throws Exception { 99 100 TreeControlNode nodeMBeans = new TreeControlNode("mbeans", "icon/mbeans.gif" 101 , resources.getMessage("treenode.allmbeans"), "ListMBeans.do", "content", false); 102 rootNode.addChild(nodeMBeans); 103 104 ArrayList [] als = JonasAdminJmx.getFamiliesMbeansLists(); 105 if (als[MbeanItem.FAMILY_J2EE].size() > 0) { 106 getJ2eeMBeans(nodeMBeans, resources, als[MbeanItem.FAMILY_J2EE]); 107 } 108 if (als[MbeanItem.FAMILY_OWNER].size() > 0) { 109 getOwnerMBeans(nodeMBeans, resources, als[MbeanItem.FAMILY_OWNER]); 110 } 111 if (als[MbeanItem.FAMILY_UNKNOWN].size() > 0) { 112 getUnknownMBeans(nodeMBeans, resources, als[MbeanItem.FAMILY_UNKNOWN]); 113 } 114 } 115 116 125 public void getOwnerMBeans(TreeControlNode p_ParentNode, MessageResources p_Resources 126 , ArrayList p_List) 127 throws Exception { 128 129 TreeControlNode nodeMBeans = new TreeControlNode("mbeans" + WhereAreYou.NODE_SEPARATOR 130 + "owner", "icon/mbeans.gif", p_Resources.getMessage("treenode.mbeans.owner") 131 , "ListOwnerMBeans.do", "content", false); 132 p_ParentNode.addChild(nodeMBeans); 133 Collections.sort(p_List, new BeanComparator(new String [] { 135 "domain", "type", "objectName"})); 136 137 String sLastDomain = ""; 139 String sLastType = ""; 140 TreeControlNode nodeMBean = null; 141 TreeControlNode nodeDomain = null; 142 TreeControlNode nodeType = null; 143 TreeControlNode nodeParent = null; 144 OwnerMbeanItem oItem; 145 146 Iterator it = p_List.iterator(); 147 while (it.hasNext()) { 148 oItem = (OwnerMbeanItem) it.next(); 149 150 nodeParent = nodeMBeans; 151 if (oItem.getDomain() != null) { 152 if (oItem.getDomain().equals(sLastDomain) == false) { 154 sLastDomain = oItem.getDomain(); 155 nodeDomain = new TreeControlNode(nodeParent.getName() 156 + WhereAreYou.NODE_SEPARATOR + oItem.getDomain(), "icon/mbeandomain.gif" 157 , oItem.getDomain(), null, "content", false); 158 nodeMBeans.addChild(nodeDomain); 159 } 160 nodeParent = nodeDomain; 161 162 if (oItem.getType() != null) { 163 if (oItem.getType().equals(sLastType) == false) { 165 sLastType = oItem.getType(); 166 nodeType = new TreeControlNode(nodeParent.getName() 167 + WhereAreYou.NODE_SEPARATOR + oItem.getType(), "icon/mbeantype.gif" 168 , oItem.getType(), null, "content", false); 169 nodeDomain.addChild(nodeType); 170 } 171 nodeParent = nodeType; 172 } 173 } 174 175 nodeMBean = new TreeControlNode("mbeans" + WhereAreYou.NODE_SEPARATOR 177 + oItem.getObjectName(), "icon/mbean.gif", oItem.getObjectName() 178 , "ListMBeanDetails.do?select=" + URLEncoder.encode(oItem.getObjectName() 179 , "UTF-8"), "content", false); 180 nodeParent.addChild(nodeMBean); 181 182 } 183 } 184 185 194 public void getJ2eeMBeans(TreeControlNode p_ParentNode, MessageResources p_Resources 195 , ArrayList p_List) 196 throws Exception { 197 198 TreeControlNode nodeMBeans = new TreeControlNode("mbeans" + WhereAreYou.NODE_SEPARATOR 199 + "j2ee", "icon/mbeans.gif", p_Resources.getMessage("treenode.mbeans.j2ee") 200 , "ListJ2eeMBeans.do", "content", false); 201 p_ParentNode.addChild(nodeMBeans); 202 Collections.sort(p_List, new BeanComparator(new String [] { 204 "domain", "j2eeType", "name", "objectName"})); 205 206 J2eeMbeanItem oItem; 208 String sLastDomain = ""; 209 String sLastType = ""; 210 TreeControlNode nodeMBean = null; 211 TreeControlNode nodeDomain = null; 212 TreeControlNode nodeType = null; 213 TreeControlNode nodeParent = null; 214 215 Iterator it = p_List.iterator(); 216 while (it.hasNext()) { 217 oItem = (J2eeMbeanItem) it.next(); 218 219 nodeParent = nodeMBeans; 220 if (oItem.getDomain() != null) { 221 if (oItem.getDomain().equals(sLastDomain) == false) { 223 sLastDomain = oItem.getDomain(); 224 nodeDomain = new TreeControlNode(nodeParent.getName() 225 + WhereAreYou.NODE_SEPARATOR + oItem.getDomain(), "icon/mbeandomain.gif" 226 , oItem.getDomain(), null, "content", false); 227 nodeMBeans.addChild(nodeDomain); 228 } 229 nodeParent = nodeDomain; 230 } 231 if (oItem.getJ2eeType() != null) { 232 if (oItem.getJ2eeType().equals(sLastType) == false) { 234 sLastType = oItem.getJ2eeType(); 235 nodeType = new TreeControlNode(nodeParent.getName() 236 + WhereAreYou.NODE_SEPARATOR + oItem.getJ2eeType(), "icon/mbeantype.gif" 237 , oItem.getJ2eeType(), null, "content", false); 238 nodeDomain.addChild(nodeType); 239 } 240 nodeParent = nodeType; 241 } 242 243 nodeMBean = new TreeControlNode("mbeans" + WhereAreYou.NODE_SEPARATOR 245 + oItem.getObjectName(), "icon/mbean.gif", oItem.getObjectName() 246 , "ListMBeanDetails.do?select=" + URLEncoder.encode(oItem.getObjectName() 247 , "UTF-8"), "content", false); 248 nodeParent.addChild(nodeMBean); 249 250 } 251 } 252 253 262 public void getUnknownMBeans(TreeControlNode p_ParentNode, MessageResources p_Resources 263 , ArrayList p_List) 264 throws Exception { 265 266 TreeControlNode nodeMBeans = new TreeControlNode("mbeans" + WhereAreYou.NODE_SEPARATOR 267 + "unknown", "icon/mbeans.gif", p_Resources.getMessage("treenode.mbeans.unknown") 268 , "ListUnknownMBeans.do", "content", false); 269 p_ParentNode.addChild(nodeMBeans); 270 Collections.sort(p_List, new BeanComparator(new String [] { 272 "domain", "objectName"})); 273 274 MbeanItem oItem; 276 String sLastDomain = ""; 277 TreeControlNode nodeMBean = null; 278 TreeControlNode nodeDomain = null; 279 TreeControlNode nodeType = null; 280 TreeControlNode nodeParent = null; 281 282 Iterator it = p_List.iterator(); 283 while (it.hasNext()) { 284 oItem = (MbeanItem) it.next(); 285 286 nodeParent = nodeMBeans; 287 if (oItem.getDomain() != null) { 288 if (oItem.getDomain().equals(sLastDomain) == false) { 290 sLastDomain = oItem.getDomain(); 291 nodeDomain = new TreeControlNode(nodeParent.getName() 292 + WhereAreYou.NODE_SEPARATOR + oItem.getDomain(), "icon/mbeandomain.gif" 293 , oItem.getDomain(), null, "content", false); 294 nodeMBeans.addChild(nodeDomain); 295 } 296 nodeParent = nodeDomain; 297 298 } 299 300 nodeMBean = new TreeControlNode("mbeans" + WhereAreYou.NODE_SEPARATOR 302 + oItem.getObjectName(), "icon/mbean.gif", oItem.getObjectName() 303 , "ListMBeanDetails.do?select=" + URLEncoder.encode(oItem.getObjectName() 304 , "UTF-8"), "content", false); 305 nodeParent.addChild(nodeMBean); 306 307 } 308 } 309 310 318 protected void getMBeanInfo(TreeControlNode nodeMBean, ObjectName onMBean 319 , MessageResources resources) 320 throws Exception { 321 MBeanInfo oMBeanInfo = JonasManagementRepr.getMBeanInfo(onMBean); 323 MBeanAttributeInfo [] aoMBeanAttributeInfo = oMBeanInfo.getAttributes(); 325 if (aoMBeanAttributeInfo.length > 0) { 326 TreeControlNode nodeAttributes = new TreeControlNode("Attributes" 328 + WhereAreYou.NODE_SEPARATOR + onMBean.toString(), "icon/JonasQuestion.gif" 329 , resources.getMessage("treenode.allmbeans.attributes"), null, "content", false); 330 nodeMBean.addChild(nodeAttributes); 331 for (int i = 0; i < aoMBeanAttributeInfo.length; i++) { 333 TreeControlNode nodeAttr = new TreeControlNode(String.valueOf(i) 334 + WhereAreYou.NODE_SEPARATOR + onMBean.toString() + WhereAreYou.NODE_SEPARATOR 335 + aoMBeanAttributeInfo[i].getName(), "icon/property.gif" 336 , aoMBeanAttributeInfo[i].getName(), null, "content", false); 337 nodeAttributes.addChild(nodeAttr); 338 } 339 } 340 MBeanOperationInfo [] aoMBeanOperationInfo = oMBeanInfo.getOperations(); 342 if (aoMBeanOperationInfo.length > 0) { 343 TreeControlNode nodeOperations = new TreeControlNode("Operations" 345 + WhereAreYou.NODE_SEPARATOR + onMBean.toString(), "icon/JonasQuestion.gif" 346 , resources.getMessage("treenode.allmbeans.operations"), null, "content", false); 347 nodeMBean.addChild(nodeOperations); 348 for (int i = 0; i < aoMBeanOperationInfo.length; i++) { 350 TreeControlNode nodeOpe = new TreeControlNode(String.valueOf(i) 351 + WhereAreYou.NODE_SEPARATOR + onMBean.toString() + WhereAreYou.NODE_SEPARATOR 352 + aoMBeanOperationInfo[i].getName(), "icon/action.gif" 353 , aoMBeanOperationInfo[i].getName(), null, "content", false); 354 nodeOperations.addChild(nodeOpe); 355 } 356 } 357 } 358 } 359 | Popular Tags |