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.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils; 30 import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; 31 import org.openide.ErrorManager; 32 import org.openide.nodes.Children; 33 import org.openide.nodes.Node; 34 import org.openide.util.Lookup; 35 import org.openide.util.RequestProcessor; 36 37 43 public class JBEarApplicationsChildren extends Children.Keys implements Refreshable { 44 45 private Lookup lookup; 46 private Boolean remoteManagementSupported = null; 47 private Boolean isJB4x = null; 48 49 JBEarApplicationsChildren(Lookup lookup) { 50 this.lookup = lookup; 51 } 52 53 public void updateKeys(){ 54 setKeys(new Object [] {Util.WAIT_NODE}); 55 56 RequestProcessor.getDefault().post(new Runnable () { 57 Vector keys = new Vector (); 58 59 public void run() { 60 try { 61 ObjectName searchPattern; 63 String propertyName; 64 if (isRemoteManagementSupported() && isJB4x()) { 65 searchPattern = new ObjectName ("jboss.management.local:j2eeType=J2EEApplication,*"); propertyName = "name"; } 68 else { 69 searchPattern = new ObjectName ("jboss.j2ee:service=EARDeployment,*"); propertyName = "url"; } 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 while(it.hasNext()) { 79 try { 80 ObjectName elem = ((ObjectInstance ) it.next()).getObjectName(); 81 String name = elem.getKeyProperty(propertyName); 82 83 if (isRemoteManagementSupported() && isJB4x) { 84 if (name.endsWith(".sar")) { continue; 86 } 87 } 88 else { 89 name = name.substring(1, name.length() - 1); } 91 92 keys.add(new JBEarApplicationNode(name, lookup)); 93 } catch (Exception ex) { 94 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 95 } 96 } 97 } catch (Exception ex) { 98 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 99 } 100 101 setKeys(keys); 102 } 103 }, 0); 104 105 } 106 107 protected void addNotify() { 108 updateKeys(); 109 } 110 111 protected void removeNotify() { 112 setKeys(java.util.Collections.EMPTY_SET); 113 } 114 115 protected org.openide.nodes.Node[] createNodes(Object key) { 116 if (key instanceof JBEarApplicationNode){ 117 return new Node[]{(JBEarApplicationNode)key}; 118 } 119 120 if (key instanceof String && key.equals(Util.WAIT_NODE)){ 121 return new Node[]{Util.createWaitNode()}; 122 } 123 124 return null; 125 } 126 127 private boolean isRemoteManagementSupported() { 128 if (remoteManagementSupported == null) { 129 remoteManagementSupported = Util.isRemoteManagementSupported(lookup); 130 } 131 return remoteManagementSupported; 132 } 133 134 private boolean isJB4x() { 135 if (isJB4x == null) { 136 JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class); 137 isJB4x = JBPluginUtils.isGoodJBServerLocation4x(dm); 138 } 139 return isJB4x; 140 } 141 142 } | Popular Tags |