1 19 20 package org.netbeans.modules.j2ee.jboss4.nodes; 21 22 import java.util.Iterator ; 23 import java.util.Set ; 24 import java.util.Vector ; 25 import javax.management.ObjectInstance ; 26 import javax.management.ObjectName ; 27 import javax.management.QueryExp ; 28 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; 29 import org.openide.ErrorManager; 30 import org.openide.nodes.Children; 31 import org.openide.nodes.Node; 32 import org.openide.util.Lookup; 33 import org.openide.util.RequestProcessor; 34 35 40 public class JBEarModulesChildren extends Children.Keys { 41 42 private Lookup lookup; 43 private String j2eeAppName; 44 45 public JBEarModulesChildren(Lookup lookup, String j2eeAppName) { 46 this.lookup = lookup; 47 this.j2eeAppName = j2eeAppName; 48 } 49 50 public void updateKeys(){ 51 setKeys(new Object [] {Util.WAIT_NODE}); 52 53 RequestProcessor.getDefault().post(new Runnable () { 54 Vector keys = new Vector (); 55 JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class); 56 57 public void run() { 58 try { 59 Object server = Util.getRMIServer(lookup); 61 ObjectName searchPattern = new ObjectName ("jboss.management.local:J2EEApplication="+j2eeAppName+",*"); 62 Set managedObj = (Set )server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 63 64 Iterator it = managedObj.iterator(); 65 66 while(it.hasNext()) { 68 try { 69 ObjectName elem = ((ObjectInstance ) it.next()).getObjectName(); 70 String name = elem.getKeyProperty("name"); 71 72 if(elem.getKeyProperty("j2eeType").equals("EJBModule")) 73 keys.add(new JBEjbModuleNode(name, lookup)); 74 else if(elem.getKeyProperty("j2eeType").equals("WebModule")) { 75 String url = "http://"+dm.getHost()+":"+dm.getPort(); 76 String context = Util.getWebContextRoot((String )Util.getMBeanParameter(dm, "jbossWebDeploymentDescriptor", 77 elem.getCanonicalName())); 78 keys.add(new JBWebModuleNode(name, lookup, (context == null) ? null : url+context)); 79 } 80 } catch (Exception ex) { 81 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 82 } 83 } 84 } catch (Exception ex) { 85 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 86 } 87 88 setKeys(keys); 89 } 90 }, 0); 91 92 } 93 94 protected void addNotify() { 95 updateKeys(); 96 } 97 98 protected void removeNotify() { 99 setKeys(java.util.Collections.EMPTY_SET); 100 } 101 102 protected org.openide.nodes.Node[] createNodes(Object key) { 103 if (key instanceof JBEjbModuleNode){ 104 return new Node[]{(JBEjbModuleNode)key}; 105 } 106 107 if (key instanceof JBWebModuleNode){ 108 return new Node[]{(JBWebModuleNode)key}; 109 } 110 111 if (key instanceof String && key.equals(Util.WAIT_NODE)){ 112 return new Node[]{Util.createWaitNode()}; 113 } 114 115 return null; 116 } 117 } | Popular Tags |