1 19 20 package org.netbeans.modules.j2ee.jboss4.nodes; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 import java.util.Vector ; 26 import javax.management.MalformedObjectNameException ; 27 import javax.management.ObjectInstance ; 28 import javax.management.ObjectName ; 29 import javax.management.QueryExp ; 30 import org.openide.ErrorManager; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.nodes.Children; 33 import org.openide.nodes.Node; 34 import org.openide.util.Lookup; 35 import org.openide.util.NbBundle; 36 import org.openide.util.RequestProcessor; 37 38 43 public class JBServletsChildren extends Children.Keys { 44 45 private static final String WAIT_NODE = "wait_node"; 47 private String name; 48 private Lookup lookup; 49 50 JBServletsChildren(String name, Lookup lookup) { 51 this.lookup = lookup; 52 this.name = name; 53 } 54 55 public void updateKeys(){ 56 setKeys(new Object [] {WAIT_NODE}); 57 58 RequestProcessor.getDefault().post(new Runnable () { 59 Vector keys = new Vector (); 60 61 public void run() { 62 try { 63 Object server = Util.getRMIServer(lookup); 65 ObjectName searchPattern = new ObjectName ("jboss.management.local:WebModule="+name+",j2eeType=Servlet,*"); 66 Set managedObj = (Set )server.getClass().getMethod("queryMBeans", new Class [] {ObjectName .class, QueryExp .class}).invoke(server, new Object [] {searchPattern, null}); 67 68 Iterator it = managedObj.iterator(); 69 70 while(it.hasNext()) { 72 ObjectName elem = ((ObjectInstance ) it.next()).getObjectName(); 73 String s = elem.getKeyProperty("name"); 74 keys.add(new JBServletNode(s)); 75 } 76 } catch (MalformedObjectNameException ex) { 77 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 78 } catch (NullPointerException ex) { 79 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 80 } catch (IllegalArgumentException ex) { 81 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 82 } catch (SecurityException ex) { 83 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 84 } catch (InvocationTargetException ex) { 85 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 86 } catch (IllegalAccessException ex) { 87 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 88 } catch (NoSuchMethodException ex) { 89 ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage()); 90 } 91 92 setKeys(keys); 93 } 94 }, 0); 95 } 96 97 protected void addNotify() { 98 updateKeys(); 99 } 100 101 protected void removeNotify() { 102 setKeys(java.util.Collections.EMPTY_SET); 103 } 104 105 protected org.openide.nodes.Node[] createNodes(Object key) { 106 if (key instanceof JBServletNode){ 107 return new Node[]{(JBServletNode)key}; 108 } 109 110 if (key instanceof String && key.equals(WAIT_NODE)){ 111 return new Node[]{createWaitNode()}; 112 } 113 114 return null; 115 } 116 117 122 private Node createWaitNode() { 123 AbstractNode n = new AbstractNode(Children.LEAF); 124 n.setName(NbBundle.getMessage(JBApplicationsChildren.class, "LBL_WaitNode_DisplayName")); n.setIconBaseWithExtension("org/openide/src/resources/wait.gif"); return n; 127 } 128 } | Popular Tags |