1 19 20 package org.netbeans.modules.j2ee.jboss4.nodes; 21 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.Set ; 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.JBPluginUtils; 31 import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable; 32 import org.openide.ErrorManager; 33 import org.openide.nodes.Children; 34 import org.openide.nodes.Node; 35 import org.openide.util.Lookup; 36 import org.openide.util.RequestProcessor; 37 38 44 public class JBEjbModulesChildren extends Children.Keys implements Refreshable { 45 46 private Lookup lookup; 47 private Boolean remoteManagementSupported = null; 48 private Boolean isJB4x = null; 49 50 public JBEjbModulesChildren(Lookup lookup) { 51 this.lookup = lookup; 52 } 53 54 public void updateKeys(){ 55 setKeys(new Object [] {Util.WAIT_NODE}); 56 57 RequestProcessor.getDefault().post(new Runnable () { 58 public void run() { 59 List keys = new LinkedList (); 60 Object server = Util.getRMIServer(lookup); 61 addEjbModules(server, keys); 62 addEJB3Modules(server, keys); 63 64 setKeys(keys); 65 } 66 }, 0); 67 68 } 69 70 private void addEjbModules(Object server, List keys) { 71 72 try { 73 String propertyName; 74 Object searchPattern; 75 if (isRemoteManagementSupported() && isJB4x()) { 76 propertyName = "name"; searchPattern = new ObjectName ("jboss.management.local:j2eeType=EJBModule,J2EEApplication=null,*"); } 79 else { 80 propertyName = "module"; searchPattern = new ObjectName ("jboss.j2ee:service=EjbModule,*"); } 83 Set managedObj = (Set )server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 85 Iterator it = managedObj.iterator(); 86 87 while(it.hasNext()) { 89 ObjectName elem = ((ObjectInstance ) it.next()).getObjectName(); 90 String name = elem.getKeyProperty(propertyName); 91 keys.add(new JBEjbModuleNode(name, lookup)); 92 } 93 94 } catch (Exception ex) { 95 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 96 } 97 } 98 99 private void addEJB3Modules(Object server, List keys) { 100 101 try { 102 ObjectName searchPattern = new ObjectName ("jboss.j2ee:service=EJB3,*"); Set managedObj = (Set )server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 105 Iterator it = managedObj.iterator(); 106 107 while(it.hasNext()) { 109 try { 110 ObjectName elem = ((ObjectInstance ) it.next()).getObjectName(); 111 String name = elem.getKeyProperty("module"); keys.add(new JBEjbModuleNode(name, lookup, true)); 113 } catch (Exception ex) { 114 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 115 } 116 } 117 } catch (Exception ex) { 118 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 119 } 120 } 121 122 protected void addNotify() { 123 updateKeys(); 124 } 125 126 protected void removeNotify() { 127 setKeys(java.util.Collections.EMPTY_SET); 128 } 129 130 protected org.openide.nodes.Node[] createNodes(Object key) { 131 if (key instanceof JBEjbModuleNode){ 132 return new Node[]{(JBEjbModuleNode)key}; 133 } 134 135 if (key instanceof String && key.equals(Util.WAIT_NODE)){ 136 return new Node[]{Util.createWaitNode()}; 137 } 138 139 return null; 140 } 141 142 private boolean isRemoteManagementSupported() { 143 if (remoteManagementSupported == null) { 144 remoteManagementSupported = Util.isRemoteManagementSupported(lookup); 145 } 146 return remoteManagementSupported; 147 } 148 149 private boolean isJB4x() { 150 if (isJB4x == null) { 151 JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class); 152 isJB4x = JBPluginUtils.isGoodJBServerLocation4x(dm); 153 } 154 return isJB4x; 155 } 156 157 } | Popular Tags |