KickJava   Java API By Example, From Geeks To Geeks.

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


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

44 public class JBEjbModulesChildren extends Children.Keys implements Refreshable {
45     
46     private Lookup lookup;
47     private Boolean JavaDoc remoteManagementSupported = null;
48     private Boolean JavaDoc isJB4x = null;
49     
50     public JBEjbModulesChildren(Lookup lookup) {
51         this.lookup = lookup;
52     }
53     
54     public void updateKeys(){
55         setKeys(new Object JavaDoc[] {Util.WAIT_NODE});
56         
57         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
58             public void run() {
59                 List JavaDoc keys = new LinkedList JavaDoc();
60                 Object JavaDoc server = Util.getRMIServer(lookup);
61                 addEjbModules(server, keys);
62                 addEJB3Modules(server, keys);
63                 
64                 setKeys(keys);
65             }
66         }, 0);
67         
68     }
69     
70     private void addEjbModules(Object JavaDoc server, List JavaDoc keys) {
71
72         try {
73             String JavaDoc propertyName;
74             Object JavaDoc searchPattern;
75             if (isRemoteManagementSupported() && isJB4x()) {
76                 propertyName = "name"; // NOI18N
77
searchPattern = new ObjectName JavaDoc("jboss.management.local:j2eeType=EJBModule,J2EEApplication=null,*"); // NOI18N
78
}
79             else {
80                 propertyName = "module"; // NOI18N
81
searchPattern = new ObjectName JavaDoc("jboss.j2ee:service=EjbModule,*"); // NOI18N
82
}
83             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}); // NOI18N
84

85             Iterator JavaDoc it = managedObj.iterator();
86
87             // Query results processing
88
while(it.hasNext()) {
89                 ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) it.next()).getObjectName();
90                 String JavaDoc name = elem.getKeyProperty(propertyName);
91                 keys.add(new JBEjbModuleNode(name, lookup));
92             }
93
94         } catch (Exception JavaDoc ex) {
95             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
96         }
97     }
98     
99     private void addEJB3Modules(Object JavaDoc server, List JavaDoc keys) {
100         
101         try {
102             ObjectName JavaDoc searchPattern = new ObjectName JavaDoc("jboss.j2ee:service=EJB3,*"); // NOI18N
103
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}); // NOI18N
104

105             Iterator JavaDoc it = managedObj.iterator();
106
107             // Query results processing
108
while(it.hasNext()) {
109                 try {
110                     ObjectName JavaDoc elem = ((ObjectInstance JavaDoc) it.next()).getObjectName();
111                     String JavaDoc name = elem.getKeyProperty("module"); // NOI18N
112
keys.add(new JBEjbModuleNode(name, lookup, true));
113                 } catch (Exception JavaDoc ex) {
114                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
115                 }
116             }
117         } catch (Exception JavaDoc ex) {
118             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
119         }
120     }
121     
122     protected void addNotify() {
123         updateKeys();
124     }
125     
126     protected void removeNotify() {
127         setKeys(java.util.Collections.EMPTY_SET);
128     }
129     
130     protected org.openide.nodes.Node[] createNodes(Object JavaDoc key) {
131         if (key instanceof JBEjbModuleNode){
132             return new Node[]{(JBEjbModuleNode)key};
133         }
134         
135         if (key instanceof String JavaDoc && key.equals(Util.WAIT_NODE)){
136             return new Node[]{Util.createWaitNode()};
137         }
138         
139         return null;
140     }
141     
142     private boolean isRemoteManagementSupported() {
143         if (remoteManagementSupported == null) {
144             remoteManagementSupported = Util.isRemoteManagementSupported(lookup);
145         }
146         return remoteManagementSupported;
147     }
148
149     private boolean isJB4x() {
150         if (isJB4x == null) {
151             JBDeploymentManager dm = (JBDeploymentManager)lookup.lookup(JBDeploymentManager.class);
152             isJB4x = JBPluginUtils.isGoodJBServerLocation4x(dm);
153         }
154         return isJB4x;
155     }
156     
157 }
Popular Tags