KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.Vector JavaDoc;
26 import javax.management.ObjectInstance JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import javax.management.QueryExp JavaDoc;
29 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
30 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties;
31 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils;
32 import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable;
33 import org.openide.ErrorManager;
34 import org.openide.nodes.Children;
35 import org.openide.nodes.Node;
36 import org.openide.util.Lookup;
37 import org.openide.util.RequestProcessor;
38
39 /**
40  * It describes children nodes of the Web Applications node. Implements
41  * Refreshable interface and due to it can be refreshed via ResreshModulesAction.
42  *
43  * @author Michal Mocnak
44  */

45 public class JBWebApplicationsChildren extends Children.Keys implements Refreshable {
46     
47     private Lookup lookup;
48     private Boolean JavaDoc remoteManagementSupported = null;
49     private Boolean JavaDoc isJB4x = null;
50     
51     public JBWebApplicationsChildren(Lookup lookup) {
52         this.lookup = lookup;
53     }
54     
55     public void updateKeys(){
56         setKeys(new Object JavaDoc[] {Util.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 jboss server
64
ObjectName JavaDoc searchPattern;
65                     if (isRemoteManagementSupported() && isJB4x()) {
66                         searchPattern = new ObjectName JavaDoc("jboss.management.local:j2eeType=WebModule,J2EEApplication=null,*"); // NOI18N
67
}
68                     else {
69                         searchPattern = new ObjectName JavaDoc("jboss.web:j2eeType=WebModule,J2EEApplication=none,*"); // NOI18N
70
}
71
72                     Object JavaDoc server = Util.getRMIServer(lookup);
73                     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});
74                     
75                     Iterator JavaDoc it = managedObj.iterator();
76                     
77                     JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class);
78                     
79                     // Query results processing
80
while(it.hasNext()) {
81                         try {
82                             ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) it.next()).getObjectName();
83                             String JavaDoc name = elem.getKeyProperty("name");
84                             String JavaDoc url = "http://" + dm.getHost() + ":" + dm.getPort();
85                             String JavaDoc context = "";
86                             if (isRemoteManagementSupported() && isJB4x()) {
87                                 if("jmx-console.war".equals(name)) { // Excluding it. It's system package
88
continue;
89                                 }
90                                 String JavaDoc descr = (String JavaDoc)Util.getMBeanParameter(dm, "jbossWebDeploymentDescriptor", elem.getCanonicalName()); // NOI18N
91
context = Util.getWebContextRoot(descr);
92                             }
93                             else {
94                                 if (name.startsWith("//localhost/")) { // NOI18N
95
name = name.substring("//localhost/".length()); // NOI18N
96
}
97                                 // excluding system packages
98
if("".equals(name) || "jmx-console".equals(name) || "jbossws".equals(name) ||
99                                    "web-console".equals(name) || "invoker".equals(name)) {
100                                     continue;
101                                 }
102                                 name += ".war"; // NOI18N
103

104                                 context = (String JavaDoc)Util.getMBeanParameter(dm, "path", elem.getCanonicalName()); // NOI18N
105
}
106                             keys.add(new JBWebModuleNode(name, lookup, (context == null ? null : url + context)));
107                         } catch (Exception JavaDoc ex) {
108                             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
109                         }
110                     }
111                 } catch (Exception JavaDoc ex) {
112                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
113                 }
114                 
115                 setKeys(keys);
116             }
117         }, 0);
118     }
119     
120     protected void addNotify() {
121         updateKeys();
122     }
123     
124     protected void removeNotify() {
125         setKeys(java.util.Collections.EMPTY_SET);
126     }
127     
128     protected org.openide.nodes.Node[] createNodes(Object JavaDoc key) {
129         if (key instanceof JBWebModuleNode){
130             return new Node[]{(JBWebModuleNode)key};
131         }
132         
133         if (key instanceof String JavaDoc && key.equals(Util.WAIT_NODE)){
134             return new Node[]{Util.createWaitNode()};
135         }
136         
137         return null;
138     }
139     
140     private boolean isRemoteManagementSupported() {
141         if (remoteManagementSupported == null) {
142             remoteManagementSupported = Util.isRemoteManagementSupported(lookup);
143         }
144         return remoteManagementSupported;
145     }
146
147     private boolean isJB4x() {
148         if (isJB4x == null) {
149             JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class);
150             isJB4x = JBPluginUtils.isGoodJBServerLocation4x(dm);
151         }
152         return isJB4x;
153     }
154
155 }
156
Popular Tags