KickJava   Java API By Example, From Geeks To Geeks.

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


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.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginUtils;
30 import org.netbeans.modules.j2ee.jboss4.nodes.actions.Refreshable;
31 import org.openide.ErrorManager;
32 import org.openide.nodes.Children;
33 import org.openide.nodes.Node;
34 import org.openide.util.Lookup;
35 import org.openide.util.RequestProcessor;
36
37 /**
38  * It describes children nodes of the EJB Modules node. Implements
39  * Refreshable interface and due to it can be refreshed via ResreshModulesAction.
40  *
41  * @author Michal Mocnak
42  */

43 public class JBEarApplicationsChildren extends Children.Keys implements Refreshable {
44     
45     private Lookup lookup;
46     private Boolean JavaDoc remoteManagementSupported = null;
47     private Boolean JavaDoc isJB4x = null;
48     
49     JBEarApplicationsChildren(Lookup lookup) {
50         this.lookup = lookup;
51     }
52     
53     public void updateKeys(){
54         setKeys(new Object JavaDoc[] {Util.WAIT_NODE});
55         
56         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
57             Vector JavaDoc keys = new Vector JavaDoc();
58             
59             public void run() {
60                 try {
61                     // Query to the jboss4 server
62
ObjectName JavaDoc searchPattern;
63                     String JavaDoc propertyName;
64                     if (isRemoteManagementSupported() && isJB4x()) {
65                         searchPattern = new ObjectName JavaDoc("jboss.management.local:j2eeType=J2EEApplication,*"); // NOI18N
66
propertyName = "name"; // NOI18N
67
}
68                     else {
69                         searchPattern = new ObjectName JavaDoc("jboss.j2ee:service=EARDeployment,*"); // NOI18N
70
propertyName = "url"; // NOI18N
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                     // Query results processing
78
while(it.hasNext()) {
79                         try {
80                             ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) it.next()).getObjectName();
81                             String JavaDoc name = elem.getKeyProperty(propertyName);
82
83                             if (isRemoteManagementSupported() && isJB4x) {
84                                 if (name.endsWith(".sar")) { // NOI18N
85
continue;
86                                 }
87                             }
88                             else {
89                                 name = name.substring(1, name.length() - 1); // NOI18N
90
}
91
92                             keys.add(new JBEarApplicationNode(name, lookup));
93                         } catch (Exception JavaDoc ex) {
94                             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
95                         }
96                     }
97                 } catch (Exception JavaDoc ex) {
98                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
99                 }
100                 
101                 setKeys(keys);
102             }
103         }, 0);
104         
105     }
106     
107     protected void addNotify() {
108         updateKeys();
109     }
110     
111     protected void removeNotify() {
112         setKeys(java.util.Collections.EMPTY_SET);
113     }
114     
115     protected org.openide.nodes.Node[] createNodes(Object JavaDoc key) {
116         if (key instanceof JBEarApplicationNode){
117             return new Node[]{(JBEarApplicationNode)key};
118         }
119         
120         if (key instanceof String JavaDoc && key.equals(Util.WAIT_NODE)){
121             return new Node[]{Util.createWaitNode()};
122         }
123         
124         return null;
125     }
126     
127     private boolean isRemoteManagementSupported() {
128         if (remoteManagementSupported == null) {
129             remoteManagementSupported = Util.isRemoteManagementSupported(lookup);
130         }
131         return remoteManagementSupported;
132     }
133  
134     private boolean isJB4x() {
135         if (isJB4x == null) {
136             JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class);
137             isJB4x = JBPluginUtils.isGoodJBServerLocation4x(dm);
138         }
139         return isJB4x;
140     }
141     
142 }
Popular Tags