KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > controllers > J2EEServerMgmtController


1 package org.netbeans.modules.j2ee.sun.ide.controllers;
2 /*
3  * The contents of this file are subject to the terms of the Common Development
4  * and Distribution License (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
8  * or http://www.netbeans.org/cddl.txt.
9  *
10  * When distributing Covered Code, include this CDDL Header Notice in each file
11  * and include the License file at http://www.netbeans.org/cddl.txt.
12  * If applicable, add the following below the CDDL Header, with the fields
13  * enclosed by brackets [] replaced by your own identifying information:
14  * "Portions Copyrighted [year] [name of copyright owner]"
15  *
16  * The Original Software is NetBeans. The Initial Developer of the Original
17  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
18  * Microsystems, Inc. All Rights Reserved.
19  */

20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.List JavaDoc;
23 import com.sun.appserv.management.base.Util;
24 import com.sun.appserv.management.util.jmx.JMXUtil;
25 import com.sun.appserv.management.j2ee.AppClientModule;
26 import com.sun.appserv.management.j2ee.EJBModule;
27 import com.sun.appserv.management.j2ee.J2EEApplication;
28 import com.sun.appserv.management.j2ee.J2EEServer;
29 import com.sun.appserv.management.j2ee.ResourceAdapterModule;
30 import com.sun.appserv.management.j2ee.WebModule;
31 import com.sun.appserv.management.client.AppserverConnectionSource;
32 import com.sun.appserv.management.config.AppClientModuleConfig;
33 import com.sun.appserv.management.config.EJBModuleConfig;
34 import com.sun.appserv.management.config.J2EEApplicationConfig;
35 import com.sun.appserv.management.config.RARModuleConfig;
36 import com.sun.appserv.management.config.WebModuleConfig;
37 import com.sun.appserv.management.j2ee.J2EEDeployedObject;
38 import java.util.Arrays JavaDoc;
39
40 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
41 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtControllerBase;
42 import org.netbeans.modules.j2ee.sun.bridge.apis.Controller;
43
44 /**
45  * Used as a conduit between the Netbeans API's and the AMX MBean API
46  * data model. This API contains convienent methods for retrieving
47  * components allowing the netbeans module heirarchy remain agnostic to the
48  * underlying data model. This controller is used to navigate through deployed
49  * applications and web, ejb, connector, and app client modules.
50  */

51 public class J2EEServerMgmtController
52         extends AppserverMgmtControllerBase implements Controller {
53     
54     private J2EEServer j2eeServer;
55
56     /**
57      * Create an instance of J2EEServerMgmtController used in the interaction
58      * with AMX API for Sun Java System Application Server.
59      *
60      * @param server The AMX J2EEServer object representing a particular server.
61      */

62     public J2EEServerMgmtController(final J2EEServer server,
63             final DeploymentManager JavaDoc dplmtMgr,
64             final AppserverConnectionSource connection) {
65         super(server, dplmtMgr, connection);
66         this.j2eeServer = server;
67     }
68
69     
70     /**
71      * Returns all the properties of this server instance.
72      *
73      * @return All the properties of this server instance as a java.util.Map.
74      */

75     public Map JavaDoc getProperties(List JavaDoc propsToIgnore) {
76         return new java.util.HashMap JavaDoc() {};
77     }
78     
79     
80     /**
81      * Sets the properties.
82      *
83      * @param attrname The name of the attribute.
84      * @param value The value of the attribute to set.
85      *
86      * @return updated Attribute
87      */

88     public javax.management.Attribute JavaDoc setProperty(final String JavaDoc attrName, final Object JavaDoc value) {
89         
90         testIfServerInDebug();
91         
92         return ControllerUtil.setAttributeValue(j2eeServer, attrName, value,
93             getMBeanServerConnection());
94     }
95     
96     
97     /**
98      *
99      *
100      */

101     public J2EEApplicationMgmtController[] getApplications() {
102         
103         testIfServerInDebug();
104         
105         Map JavaDoc apps = j2eeServer.getContaineeMap(J2EEApplication.J2EE_TYPE);
106         Map JavaDoc appsMap = getJ2EEAppsAsMap(J2EEApplication.J2EE_TYPE);
107         Map JavaDoc configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(J2EEApplicationConfig.J2EE_TYPE);
108         configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps);
109         
110         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
111         for(Iterator JavaDoc configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) {
112             J2EEApplicationConfig appConfig = (J2EEApplicationConfig)configPeerItr.next();
113             J2EEApplication appMod = null;
114             if(appsMap.containsKey(appConfig.getName())){
115                 appMod = (J2EEApplication)appsMap.get(appConfig.getName());
116             }
117             controllers.add(new J2EEApplicationMgmtController(
118                 appMod, appConfig, getDeploymentManager(),
119                     appMgmtConnection));
120         }
121         
122         J2EEApplicationMgmtController[] result =
123             new J2EEApplicationMgmtController[controllers.size()];
124         return (J2EEApplicationMgmtController[]) controllers.toArray(result);
125     }
126     
127     
128     /**
129      *
130      *
131      */

132     public EJBModuleController[] getEJBModules() {
133         
134         testIfServerInDebug();
135         
136         Map JavaDoc apps = j2eeServer.getContaineeMap(EJBModule.J2EE_TYPE);
137         Map JavaDoc appsMap = getJ2EEAppsAsMap(EJBModule.J2EE_TYPE);
138         Map JavaDoc configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(EJBModuleConfig.J2EE_TYPE);
139         configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps);
140         
141         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
142         for(Iterator JavaDoc configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) {
143             EJBModuleConfig ejbConfig = (EJBModuleConfig)configPeerItr.next();
144             EJBModule ejbMod = null;
145             if(appsMap.containsKey(ejbConfig.getName())){
146                 ejbMod = (EJBModule)appsMap.get(ejbConfig.getName());
147             }
148             controllers.add(new EJBModuleController(
149                 ejbMod, ejbConfig, getDeploymentManager(),
150                     appMgmtConnection));
151         }
152         
153         EJBModuleController[] result =
154             new EJBModuleController[controllers.size()];
155         return (EJBModuleController[]) controllers.toArray(result);
156     }
157     
158     
159     /**
160      *
161      *
162      */

163     public ConnectorModuleController[] getConnectorModules() {
164         
165         testIfServerInDebug();
166         Map JavaDoc j2eeApps = j2eeServer.getContaineeMap(ResourceAdapterModule.J2EE_TYPE);
167         Map JavaDoc appsMap = getJ2EEAppsAsMap(ResourceAdapterModule.J2EE_TYPE);
168         Map JavaDoc configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(RARModuleConfig.J2EE_TYPE);
169         configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps);
170         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
171         for(Iterator JavaDoc configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) {
172             RARModuleConfig rarConfig = (RARModuleConfig)configPeerItr.next();
173             ResourceAdapterModule rarMod = null;
174             if(appsMap.containsKey(rarConfig.getName())){
175                 rarMod = (ResourceAdapterModule)appsMap.get(rarConfig.getName());
176             }
177         
178             if(! Arrays.asList(ControllerUtil.RES_ADAPTOR_KEYS).contains(rarConfig.getName())){
179                 controllers.add(new ConnectorModuleController(
180                         rarMod, rarConfig, getDeploymentManager(), appMgmtConnection));
181             }
182         }
183         ConnectorModuleController[] result =
184             new ConnectorModuleController[controllers.size()];
185         return (ConnectorModuleController[]) controllers.toArray(result);
186     }
187
188     
189     /**
190      *
191      *
192      */

193     public WebModuleController[] getWebModules() {
194         
195         testIfServerInDebug();
196         
197         Map JavaDoc apps = j2eeServer.getContaineeMap(WebModule.J2EE_TYPE);
198         Map JavaDoc appsMap = getJ2EEAppsAsMap(WebModule.J2EE_TYPE);
199         Map JavaDoc configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(WebModuleConfig.J2EE_TYPE);
200         configPeerApps = ControllerUtil.stripOutSystemApps(configPeerApps);
201         
202         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
203         for(Iterator JavaDoc configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) {
204             WebModuleConfig webConfig = (WebModuleConfig)configPeerItr.next();
205             WebModule webMod = null;
206             if(appsMap.containsKey(webConfig.getName())){
207                 webMod = (WebModule)appsMap.get(webConfig.getName());
208             }
209             controllers.add(new WebModuleController(
210                 webMod, webConfig, getDeploymentManager(),
211                     appMgmtConnection));
212         }
213        
214         WebModuleController[] result =
215             new WebModuleController[controllers.size()];
216         return (WebModuleController[]) controllers.toArray(result);
217     }
218
219     /**
220      * Return the web module name of a standlaone or embeded webmodule
221      * from the context root
222      * @param String reprsenting the Context Root of the web module
223      * @return String giving the web module name. Can be null
224      */

225     public String JavaDoc getWebModuleName(String JavaDoc contextRoot) {
226         
227         testIfServerInDebug();
228         String JavaDoc modName = null;
229         Map JavaDoc webApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(WebModuleConfig.J2EE_TYPE);
230         webApps = ControllerUtil.stripOutSystemApps(webApps);
231         
232         for(Iterator JavaDoc webAppsItr = webApps.values().iterator(); webAppsItr.hasNext(); ) {
233             WebModuleConfig webConfig = (WebModuleConfig)webAppsItr.next();
234             String JavaDoc cRoot = webConfig.getContextRoot();
235             if(cRoot.equals(contextRoot)){
236                 modName = webConfig.getName();
237                 break;
238             }
239         }
240         
241         if(modName == null){
242             Map JavaDoc j2eeApps = ControllerUtil.stripOutSystemApps(
243                 j2eeServer.getContaineeMap(J2EEApplication.J2EE_TYPE));
244             for(Iterator JavaDoc itr = j2eeApps.values().iterator(); itr.hasNext(); ) {
245                 J2EEApplication j2eeApp = (J2EEApplication)itr.next();
246                 
247                 Map JavaDoc compWebs = ControllerUtil.stripOutSystemApps(
248                         j2eeApp.getContaineeMap(WebModule.J2EE_TYPE));
249                 for(Iterator JavaDoc webItr = compWebs.values().iterator(); webItr.hasNext(); ) {
250                     WebModule webApp = (WebModule)webItr.next();
251                     String JavaDoc cRoot = webApp.getPath();
252                     if(cRoot.equals(contextRoot)){
253                         String JavaDoc appName = j2eeApp.getName();
254                         String JavaDoc webName = webApp.getName();
255                         if(webName.indexOf("//server") != -1) //NOI18N
256
webName = webName.substring(8, webName.length());
257                         webName = webName + "_war"; //NOI18N
258
modName = appName + webName;
259                         break;
260                     }
261                 } //for
262

263             }
264         } //modName null
265
return modName;
266     }
267     
268     /**
269      *
270      */

271     public AppClientModuleController[] getAppClientModules() {
272         
273         testIfServerInDebug();
274         
275         String JavaDoc configPeerType = ControllerUtil.getConfigPeerAMXType(AppClientModule.J2EE_TYPE);
276         Map JavaDoc configPeerApps = j2eeServer.getConfigPeer().getContainer().getContaineeMap(configPeerType);
277         
278         Map JavaDoc apps = j2eeServer.getContaineeMap(AppClientModule.J2EE_TYPE);
279         Map JavaDoc appsMap = getJ2EEAppsAsMap(AppClientModule.J2EE_TYPE);
280         
281         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
282         for(Iterator JavaDoc configPeerItr = configPeerApps.values().iterator(); configPeerItr.hasNext(); ) {
283             AppClientModuleConfig appClientConfig = (AppClientModuleConfig)configPeerItr.next();
284             AppClientModule appClientMod = null;
285             if(appsMap.containsKey(appClientConfig.getName())){
286                 appClientMod = (AppClientModule)appsMap.get(appClientConfig.getName());
287             }
288             controllers.add(new AppClientModuleController(
289                 appClientMod, appClientConfig, getDeploymentManager(),
290                     appMgmtConnection));
291         }
292         
293         AppClientModuleController[] result =
294             new AppClientModuleController[controllers.size()];
295         return (AppClientModuleController[]) controllers.toArray(result);
296     }
297     
298     private Map JavaDoc getJ2EEAppsAsMap(String JavaDoc type){
299         Map JavaDoc apps = ControllerUtil.stripOutSystemApps(j2eeServer.getContaineeMap(type));
300         Map JavaDoc j2eePeerMap = new java.util.HashMap JavaDoc();
301         for(Iterator JavaDoc itr = apps.values().iterator(); itr.hasNext(); ) {
302             J2EEDeployedObject j2eeMod = (J2EEDeployedObject)itr.next();
303             if(j2eeMod.getConfigPeer() != null)
304                 j2eePeerMap.put(j2eeMod.getConfigPeer().getName(), j2eeMod);
305         }
306         return j2eePeerMap;
307     }
308     
309     public String JavaDoc getServerName(){
310         return j2eeServer.getserverVersion();
311     }
312 }
313
Popular Tags