KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > nodes > JBServletsChildren


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.jboss4.nodes;
21
22 import java.lang.reflect.InvocationTargetException JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.Vector JavaDoc;
26 import javax.management.MalformedObjectNameException JavaDoc;
27 import javax.management.ObjectInstance JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.QueryExp JavaDoc;
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 /**
39  * It describes children nodes of the Web Module node.
40  *
41  * @author Michal Mocnak
42  */

43 public class JBServletsChildren extends Children.Keys {
44     
45     private static final String JavaDoc WAIT_NODE = "wait_node"; //NOI18N
46

47     private String JavaDoc name;
48     private Lookup lookup;
49     
50     JBServletsChildren(String JavaDoc name, Lookup lookup) {
51         this.lookup = lookup;
52         this.name = name;
53     }
54     
55     public void updateKeys(){
56         setKeys(new Object JavaDoc[] {WAIT_NODE});
57         
58         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
59             Vector JavaDoc keys = new Vector JavaDoc();
60             
61             public void run() {
62                 try {
63                     // Query to the jboss4 server
64
Object JavaDoc server = Util.getRMIServer(lookup);
65                     ObjectName JavaDoc searchPattern = new ObjectName JavaDoc("jboss.management.local:WebModule="+name+",j2eeType=Servlet,*");
66                     Set JavaDoc managedObj = (Set JavaDoc)server.getClass().getMethod("queryMBeans", new Class JavaDoc[] {ObjectName JavaDoc.class, QueryExp JavaDoc.class}).invoke(server, new Object JavaDoc[] {searchPattern, null});
67                     
68                     Iterator JavaDoc it = managedObj.iterator();
69                     
70                     // Query results processing
71
while(it.hasNext()) {
72                         ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) it.next()).getObjectName();
73                         String JavaDoc s = elem.getKeyProperty("name");
74                         keys.add(new JBServletNode(s));
75                     }
76                 } catch (MalformedObjectNameException JavaDoc ex) {
77                     ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
78                 } catch (NullPointerException JavaDoc ex) {
79                     ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
80                 } catch (IllegalArgumentException JavaDoc ex) {
81                     ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
82                 } catch (SecurityException JavaDoc ex) {
83                     ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
84                 } catch (InvocationTargetException JavaDoc ex) {
85                     ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
86                 } catch (IllegalAccessException JavaDoc ex) {
87                     ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
88                 } catch (NoSuchMethodException JavaDoc 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 JavaDoc key) {
106         if (key instanceof JBServletNode){
107             return new Node[]{(JBServletNode)key};
108         }
109         
110         if (key instanceof String JavaDoc && key.equals(WAIT_NODE)){
111             return new Node[]{createWaitNode()};
112         }
113         
114         return null;
115     }
116     
117     /* Creates and returns the instance of the node
118      * representing the status 'WAIT' of the node.
119      * It is used when it spent more time to create elements hierarchy.
120      * @return the wait node.
121      */

122     private Node createWaitNode() {
123         AbstractNode n = new AbstractNode(Children.LEAF);
124         n.setName(NbBundle.getMessage(JBApplicationsChildren.class, "LBL_WaitNode_DisplayName")); //NOI18N
125
n.setIconBaseWithExtension("org/openide/src/resources/wait.gif"); // NOI18N
126
return n;
127     }
128 }
Popular Tags