1 22 package org.jboss.console.plugins; 23 24 import java.util.ArrayList ; 25 import java.util.Collections ; 26 import java.util.Comparator ; 27 28 import javax.management.AttributeNotFoundException ; 29 import javax.management.ObjectInstance ; 30 import javax.management.ObjectName ; 31 32 import org.jboss.console.manager.interfaces.ManageableResource; 33 import org.jboss.console.manager.interfaces.ResourceTreeNode; 34 import org.jboss.console.manager.interfaces.TreeNode; 35 import org.jboss.console.plugins.helpers.AbstractPluginWrapper; 36 import org.jboss.management.j2ee.J2EEServerMBean; 37 import org.jboss.mx.util.MBeanProxyExt; 38 39 47 public class JSR77Lister extends AbstractPluginWrapper 48 { 49 private static final long serialVersionUID = -5466799611043095874L; 50 51 54 public JSR77Lister() 55 { 56 super(); 57 } 58 59 150 TreeNode createSubResources (String [] resources) throws Exception 151 { 152 ResourceTreeNode[] deployed = new ResourceTreeNode[resources.length]; 153 for (int i = 0; i < resources.length; i++) 154 { 155 ObjectName objectName = new ObjectName (resources[i]); 156 deployed[i] = createResourceNode ( 157 objectName.getKeyProperty ("name"), "J2EE Resource", null, null, null, 162 null, null, resources[i].toString (), 165 this.mbeanServer.getMBeanInfo (objectName).getClassName () 166 ).setVisibility (ResourceTreeNode.INVISIBLE_IF_SUBNODE_EXISTS); 167 } 168 169 return createTreeNode ( 170 "J2EE Resources", "J2EE Resources", "images/spirale.gif", null, null, 175 null, deployed ); 178 } 179 180 ResourceTreeNode[] createDeployedObjects (String [] resources) throws Exception 181 { 182 ArrayList deployed = new ArrayList (); 183 for (int i = 0; i < resources.length; i++) 184 { 185 ObjectName objectName = new ObjectName (resources[i]); 186 { 188 deployed.add(createResourceNode ( 189 objectName.getKeyProperty("name"), "", "images/EspressoMaker.gif", null, null, 194 null, null, resources[i].toString (), 197 this.mbeanServer.getMBeanInfo (objectName).getClassName () 198 ).setVisibility (ResourceTreeNode.INVISIBLE_IF_SUBNODE_EXISTS)); 199 } 200 201 } 202 Collections.sort(deployed, new ListerSorter()); 203 204 return (ResourceTreeNode[])deployed.toArray(new ResourceTreeNode[deployed.size()]); 205 } 206 207 ResourceTreeNode createServer (String serverName) throws Exception 208 { 209 210 ObjectName objectName = new ObjectName (serverName); 211 J2EEServerMBean serv = (J2EEServerMBean) 212 MBeanProxyExt.create(J2EEServerMBean.class, objectName, getMBeanServer ()); 213 214 String [] deployedON = serv.getdeployedObjects(); 215 ResourceTreeNode[] subResArray = createDeployedObjects (deployedON); 216 217 return createResourceNode ( 218 serv.getserverVendor () + " - " + serv.getserverVersion (), objectName.getKeyProperty ("name"), "images/database.gif", null, null, 223 new TreeNode[] {createSubResources (serv.getresources())}, subResArray, serverName.toString (), 226 org.jboss.management.j2ee.J2EEServer.class.getName () 227 ); 228 229 } 230 231 ResourceTreeNode[] createServers(ObjectName domain) throws Exception 232 { 233 String [] serversObjectNames = (String [])getMBeanServer().getAttribute(domain, "servers"); 235 236 ArrayList servers = new ArrayList (); 237 for (int i = 0; i < serversObjectNames.length; i++) 238 { 239 servers.add(createServer(serversObjectNames[i])); 240 } 241 242 return (ResourceTreeNode[])servers.toArray(new ResourceTreeNode[servers.size()]); 243 } 244 245 251 252 TreeNode createDomain(ObjectName domain) throws Exception 253 { 254 return createTreeNode( 255 domain.getKeyProperty("name"), "", "images/spirale.gif", null, null, 260 null, createServers(domain) ); 263 } 264 265 268 TreeNode[] createDomains() 269 { 270 ObjectInstance [] insts = getMBeansForQuery("*:j2eeType=J2EEDomain,*", null); 274 275 ArrayList domainsCreated = new ArrayList (); 277 278 for (int i=0; i < insts.length; i++) 279 { 280 ObjectName objectName = insts[i].getObjectName(); 281 try 282 { 283 if (objectName.getDomain().equals(objectName.getKeyProperty("name"))) 284 { 285 domainsCreated.add(createDomain(objectName)); 287 } 288 } 289 catch (AttributeNotFoundException e) 290 { 291 System.err.println(e.getClass().getName() + ": " + e.getMessage() 293 + "; mbean '" + objectName + "' not a proper j2eeType=J2EEDomain"); 294 } 295 catch (Exception e) 296 { 297 e.printStackTrace(); 299 } 300 } 301 TreeNode[] domains = (TreeNode[])domainsCreated.toArray(new TreeNode[domainsCreated.size()]); 303 304 return domains; 306 } 307 308 protected TreeNode getTreeForResource(String profile, ManageableResource resource) 309 { 310 try 311 { 312 return createTreeNode ( 313 "J2EE Domains", "Display JSR-77 Managed Objects", "images/elements32.gif", null, null, 318 createDomains (), null ); 321 } 322 catch (Exception e) 323 { 324 e.printStackTrace (); 325 return null; 326 } 327 } 328 329 public final static String [] DEFAULT_SUFFIX_ORDER = { 330 "ear", "jar", "war", "sar", "rar", "ds.xml", "service.xml", "wsr", "zip" 331 }; 332 333 public class ListerSorter implements Comparator 334 { 335 336 protected String [] suffixOrder; 337 338 public ListerSorter (String [] suffixOrder) 339 { 340 this.suffixOrder = suffixOrder; 341 } 342 343 public ListerSorter () 344 { 345 this (DEFAULT_SUFFIX_ORDER); 346 } 347 348 public int compare (Object o1, Object o2) 349 { 350 return getExtensionIndex ((ResourceTreeNode) o1) - getExtensionIndex ((ResourceTreeNode) o2); 351 } 352 353 public int getExtensionIndex (ResourceTreeNode node) 354 { 355 String name = node.getName(); 356 if (name == null) name = ""; 357 358 int i = 0; 359 for (; i < suffixOrder.length; i++) 360 { 361 if (name.endsWith (suffixOrder[i])) 362 break; 363 } 364 return i; 365 } 366 } 367 368 } 369 | Popular Tags |