1 19 20 package org.netbeans.modules.j2ee.oc4j.nodes; 21 22 import java.util.Iterator ; 23 import java.util.Vector ; 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectInstance ; 26 import javax.management.ObjectName ; 27 import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager; 28 import org.netbeans.modules.j2ee.oc4j.nodes.actions.Refreshable; 29 import org.openide.nodes.Children; 30 import org.openide.nodes.Node; 31 import org.openide.util.Lookup; 32 import org.openide.util.RequestProcessor; 33 34 39 public class OC4JNativeDataSourcesChildren extends Children.Keys implements Refreshable { 40 41 private Lookup lookup; 42 private final static Node WAIT_NODE = OC4JItemNode.createWaitNode(); 43 44 OC4JNativeDataSourcesChildren(Lookup lookup) { 45 this.lookup = lookup; 46 } 47 48 public void updateKeys(){ 49 setKeys(new Object [] {WAIT_NODE}); 50 51 RequestProcessor.getDefault().post(new Runnable () { 52 Vector keys = new Vector (); 53 OC4JDeploymentManager dm = lookup.lookup(OC4JDeploymentManager.class); 54 55 public void run() { 56 57 try { 58 MBeanServerConnection server = dm.getJMXConnector(); 59 Iterator i = server.queryMBeans(new ObjectName ("oc4j:j2eeType=JDBCDataSource,*"), null).iterator(); 60 61 while(i.hasNext()) { 62 ObjectName elem = ((ObjectInstance ) i.next()).getObjectName(); 63 String pool = elem.getKeyProperty("JDBCResource").substring(1, elem.getKeyProperty("JDBCResource").length()-1); 64 65 if(pool.length() > 0) 66 continue; 67 68 String name = (String ) server.getAttribute(elem, "dataSourceName"); 69 String jndiName = (String ) server.getAttribute(elem, "jndiName"); 70 String url = (String ) server.getAttribute(elem, "url"); 71 Node node = new OC4JItemNode(lookup, Children.LEAF, name, OC4JItemNode.ItemType.JDBC_NATIVE_DATASOURCES); 72 node.setShortDescription(jndiName + " -> " + url); 73 74 keys.add(node); 75 } 76 77 } catch(Exception ex) { 78 } 80 81 setKeys(keys); 82 } 83 }, 0); 84 } 85 86 protected void addNotify() { 87 updateKeys(); 88 } 89 90 protected void removeNotify() { 91 setKeys(java.util.Collections.EMPTY_SET); 92 } 93 94 protected org.openide.nodes.Node[] createNodes(Object key) { 95 if (key instanceof OC4JItemNode){ 96 return new Node[]{(OC4JItemNode)key}; 97 } 98 99 if (key instanceof String && key.equals(WAIT_NODE)){ 100 return new Node[]{WAIT_NODE}; 101 } 102 103 return null; 104 } 105 } | Popular Tags |