KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.Vector JavaDoc;
25 import javax.management.ObjectInstance JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import javax.management.QueryExp JavaDoc;
28 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
29 import org.openide.ErrorManager;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
32 import org.openide.util.Lookup;
33 import org.openide.util.RequestProcessor;
34
35 /**
36  * It describes children nodes of the enterprise application node.
37  *
38  * @author Michal Mocnak
39  */

40 public class JBEarModulesChildren extends Children.Keys {
41     
42     private Lookup lookup;
43     private String JavaDoc j2eeAppName;
44     
45     public JBEarModulesChildren(Lookup lookup, String JavaDoc j2eeAppName) {
46         this.lookup = lookup;
47         this.j2eeAppName = j2eeAppName;
48     }
49     
50     public void updateKeys(){
51         setKeys(new Object JavaDoc[] {Util.WAIT_NODE});
52         
53         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
54             Vector JavaDoc keys = new Vector JavaDoc();
55             JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class);
56             
57             public void run() {
58                 try {
59                     // Query to the jboss4 server
60
Object JavaDoc server = Util.getRMIServer(lookup);
61                     ObjectName JavaDoc searchPattern = new ObjectName JavaDoc("jboss.management.local:J2EEApplication="+j2eeAppName+",*");
62                     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});
63                     
64                     Iterator JavaDoc it = managedObj.iterator();
65                     
66                     // Query results processing
67
while(it.hasNext()) {
68                         try {
69                             ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) it.next()).getObjectName();
70                             String JavaDoc name = elem.getKeyProperty("name");
71
72                             if(elem.getKeyProperty("j2eeType").equals("EJBModule"))
73                                 keys.add(new JBEjbModuleNode(name, lookup));
74                             else if(elem.getKeyProperty("j2eeType").equals("WebModule")) {
75                                 String JavaDoc url = "http://"+dm.getHost()+":"+dm.getPort();
76                                 String JavaDoc context = Util.getWebContextRoot((String JavaDoc)Util.getMBeanParameter(dm, "jbossWebDeploymentDescriptor",
77                                         elem.getCanonicalName()));
78                                 keys.add(new JBWebModuleNode(name, lookup, (context == null) ? null : url+context));
79                             }
80                         } catch (Exception JavaDoc ex) {
81                             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
82                         }
83                     }
84                 } catch (Exception JavaDoc ex) {
85                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
86                 }
87                 
88                 setKeys(keys);
89             }
90         }, 0);
91         
92     }
93     
94     protected void addNotify() {
95         updateKeys();
96     }
97     
98     protected void removeNotify() {
99         setKeys(java.util.Collections.EMPTY_SET);
100     }
101     
102     protected org.openide.nodes.Node[] createNodes(Object JavaDoc key) {
103         if (key instanceof JBEjbModuleNode){
104             return new Node[]{(JBEjbModuleNode)key};
105         }
106         
107         if (key instanceof JBWebModuleNode){
108             return new Node[]{(JBWebModuleNode)key};
109         }
110         
111         if (key instanceof String JavaDoc && key.equals(Util.WAIT_NODE)){
112             return new Node[]{Util.createWaitNode()};
113         }
114         
115         return null;
116     }
117 }
Popular Tags