1 19 20 package org.netbeans.modules.j2ee.jboss4.nodes; 21 22 import java.io.File ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 import java.util.Vector ; 26 import javax.management.ObjectInstance ; 27 import javax.management.ObjectName ; 28 import javax.management.QueryExp ; 29 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager; 30 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties; 31 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; 32 import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; 33 import org.openide.ErrorManager; 34 import org.openide.nodes.Children; 35 import org.openide.nodes.Node; 36 import org.openide.util.Lookup; 37 import org.openide.util.RequestProcessor; 38 39 45 public class JBWebApplicationsChildren extends Children.Keys implements Refreshable { 46 47 private Lookup lookup; 48 private Boolean remoteManagementSupported = null; 49 private Boolean isJB4x = null; 50 51 public JBWebApplicationsChildren(Lookup lookup) { 52 this.lookup = lookup; 53 } 54 55 public void updateKeys(){ 56 setKeys(new Object [] {Util.WAIT_NODE}); 57 58 RequestProcessor.getDefault().post(new Runnable () { 59 Vector keys = new Vector (); 60 61 public void run() { 62 try { 63 ObjectName searchPattern; 65 if (isRemoteManagementSupported() && isJB4x()) { 66 searchPattern = new ObjectName ("jboss.management.local:j2eeType=WebModule,J2EEApplication=null,*"); } 68 else { 69 searchPattern = new ObjectName ("jboss.web:j2eeType=WebModule,J2EEApplication=none,*"); } 71 72 Object server = Util.getRMIServer(lookup); 73 Set managedObj = (Set ) server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 74 75 Iterator it = managedObj.iterator(); 76 77 JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class); 78 79 while(it.hasNext()) { 81 try { 82 ObjectName elem = ((ObjectInstance ) it.next()).getObjectName(); 83 String name = elem.getKeyProperty("name"); 84 String url = "http://" + dm.getHost() + ":" + dm.getPort(); 85 String context = ""; 86 if (isRemoteManagementSupported() && isJB4x()) { 87 if("jmx-console.war".equals(name)) { continue; 89 } 90 String descr = (String )Util.getMBeanParameter(dm, "jbossWebDeploymentDescriptor", elem.getCanonicalName()); context = Util.getWebContextRoot(descr); 92 } 93 else { 94 if (name.startsWith("//localhost/")) { name = name.substring("//localhost/".length()); } 97 if("".equals(name) || "jmx-console".equals(name) || "jbossws".equals(name) || 99 "web-console".equals(name) || "invoker".equals(name)) { 100 continue; 101 } 102 name += ".war"; 104 context = (String )Util.getMBeanParameter(dm, "path", elem.getCanonicalName()); } 106 keys.add(new JBWebModuleNode(name, lookup, (context == null ? null : url + context))); 107 } catch (Exception ex) { 108 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 109 } 110 } 111 } catch (Exception ex) { 112 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 113 } 114 115 setKeys(keys); 116 } 117 }, 0); 118 } 119 120 protected void addNotify() { 121 updateKeys(); 122 } 123 124 protected void removeNotify() { 125 setKeys(java.util.Collections.EMPTY_SET); 126 } 127 128 protected org.openide.nodes.Node[] createNodes(Object key) { 129 if (key instanceof JBWebModuleNode){ 130 return new Node[]{(JBWebModuleNode)key}; 131 } 132 133 if (key instanceof String && key.equals(Util.WAIT_NODE)){ 134 return new Node[]{Util.createWaitNode()}; 135 } 136 137 return null; 138 } 139 140 private boolean isRemoteManagementSupported() { 141 if (remoteManagementSupported == null) { 142 remoteManagementSupported = Util.isRemoteManagementSupported(lookup); 143 } 144 return remoteManagementSupported; 145 } 146 147 private boolean isJB4x() { 148 if (isJB4x == null) { 149 JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class); 150 isJB4x = JBPluginUtils.isGoodJBServerLocation4x(dm); 151 } 152 return isJB4x; 153 } 154 155 } 156 | Popular Tags |