KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > nodes > OC4JManagedDataSourcesChildren


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.oc4j.nodes;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.Vector JavaDoc;
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectInstance JavaDoc;
26 import javax.management.ObjectName JavaDoc;
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.NbBundle;
33 import org.openide.util.RequestProcessor;
34
35 /**
36  * It describes children nodes of the JDBC Resources node
37  *
38  * @author Michal Mocnak
39  */

40 public class OC4JManagedDataSourcesChildren extends Children.Keys implements Refreshable {
41     
42     private Lookup lookup;
43     private final static Node WAIT_NODE = OC4JItemNode.createWaitNode();
44     
45     OC4JManagedDataSourcesChildren(Lookup lookup) {
46         this.lookup = lookup;
47     }
48     
49     public void updateKeys(){
50         setKeys(new Object JavaDoc[] {WAIT_NODE});
51         
52         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
53             Vector JavaDoc keys = new Vector JavaDoc();
54             OC4JDeploymentManager dm = lookup.lookup(OC4JDeploymentManager.class);
55             
56             public void run() {
57                 
58                 try {
59                     MBeanServerConnection JavaDoc server = dm.getJMXConnector();
60                     Iterator JavaDoc i = server.queryMBeans(new ObjectName JavaDoc("oc4j:j2eeType=JDBCDataSource,*"), null).iterator();
61                     
62                     while(i.hasNext()) {
63                         ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) i.next()).getObjectName();
64                         String JavaDoc pool = elem.getKeyProperty("JDBCResource").substring(1, elem.getKeyProperty("JDBCResource").length()-1);
65                         
66                         if(pool.length() == 0)
67                             continue;
68                         
69                         String JavaDoc name = (String JavaDoc) server.getAttribute(elem, "dataSourceName");
70                         String JavaDoc jndiName = (String JavaDoc) server.getAttribute(elem, "jndiName");
71                         Node node = new OC4JItemNode(lookup, Children.LEAF, name, OC4JItemNode.ItemType.JDBC_MANAGED_DATASOURCES);
72                         node.setShortDescription(jndiName + " -> " + NbBundle.getMessage(OC4JManagedDataSourcesChildren.class, "TXT_ConnectionPool")+pool);
73                         
74                         keys.add(node);
75                     }
76                     
77                 } catch(Exception JavaDoc ex) {
78                     // Nothing to do
79
}
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 JavaDoc key) {
95         if (key instanceof OC4JItemNode){
96             return new Node[]{(OC4JItemNode)key};
97         }
98         
99         if (key instanceof String JavaDoc && key.equals(WAIT_NODE)){
100             return new Node[]{WAIT_NODE};
101         }
102         
103         return null;
104     }
105 }
Popular Tags