KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.appserv.management.j2ee.J2EEDeployedObject;
21 import java.util.Iterator 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.config.Enabled;
26 import com.sun.appserv.management.client.AppserverConnectionSource;
27 import com.sun.appserv.management.config.DeployedItemRefConfig;
28 import com.sun.appserv.management.config.J2EEApplicationConfig;
29 import com.sun.appserv.management.j2ee.J2EEApplication;
30 import com.sun.appserv.management.j2ee.EJBModule;
31 import com.sun.appserv.management.j2ee.WebModule;
32 import com.sun.appserv.management.j2ee.AppClientModule;
33 import com.sun.appserv.management.j2ee.ResourceAdapterModule;
34 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
35 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtControllerBase;
36
37 import org.netbeans.modules.j2ee.sun.util.NodeTypes;
38
39 /**
40  * Used as a conduit between the Netbeans API's and the AMX MBean API
41  * data model. This API contains convenient methods for retrieving
42  * components allowing the netbeans module heirarchy remain agnostic to the
43  * underlying data model.
44  *
45  * This controller is used to navigate through deployed applications
46  * subcomponents such as web, ejb, connector, and app client modules.
47  */

48 public class J2EEApplicationMgmtController extends AppserverMgmtControllerBase
49         implements DeployedItemsController, EnablerController {
50     
51     private J2EEApplication application;
52     private J2EEApplicationConfig appConfig;
53        
54     /**
55      * Create an instance of J2EEServerMgmtController used in the interaction
56      * with AMX API for Sun Java System Application Server.
57      *
58      * @param server The AMX J2EEServer object representing a particular server.
59      */

60     public J2EEApplicationMgmtController(final J2EEApplication application,
61             final DeploymentManager JavaDoc dplmtMgr,
62             final AppserverConnectionSource connection) {
63         super(application, dplmtMgr, connection);
64         this.application = application;
65     }
66
67      public J2EEApplicationMgmtController(final J2EEApplication application,
68             final J2EEApplicationConfig appConfig,
69             final DeploymentManager JavaDoc dplmtMgr,
70             final AppserverConnectionSource connection) {
71         super(appConfig, dplmtMgr, connection);
72         this.application = application;
73         this.appConfig = appConfig;
74     }
75     /**
76      * Returns the properties of the application given the name.
77      *
78      * @param appName The name of the application.
79      * @return All the application properties.
80      */

81     public java.util.Map JavaDoc getProperties(List JavaDoc propsToIgnore) {
82         return getJ2EEAndConfigProperties(NodeTypes.ENTERPRISE_APPLICATION,
83             this.application, this.appConfig, propsToIgnore);
84     }
85     
86     
87     /**
88      * Sets the properties.
89      *
90      * @param attrname The name of the attribute.
91      * @param value The value of the attribute to set.
92      *
93      * @return updated Attribute
94      */

95     public javax.management.Attribute JavaDoc setProperty(final String JavaDoc attrName, final Object JavaDoc value) {
96         
97         testIfServerInDebug();
98         
99         return ControllerUtil.setAttributeValue(application, appConfig, attrName, value,
100             getMBeanServerConnection());
101     }
102     
103     /**
104      *
105      *
106      */

107     public EJBModuleController[] getEJBModules() {
108         
109         testIfServerInDebug();
110         
111         java.util.Map JavaDoc apps = application.getContaineeMap(EJBModule.J2EE_TYPE);
112         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
113         for(Iterator JavaDoc itr = apps.values().iterator(); itr.hasNext(); ) {
114             controllers.add(new EJBModuleController(
115                 (EJBModule)itr.next(), getDeploymentManager(),
116                     appMgmtConnection));
117         }
118         EJBModuleController[] result =
119             new EJBModuleController[controllers.size()];
120         return (EJBModuleController[]) controllers.toArray(result);
121     }
122
123     
124     /**
125      *
126      *
127      */

128     public AppClientModuleController[] getAppClientModules() {
129         
130         testIfServerInDebug();
131         
132         java.util.Map JavaDoc apps = application.getContaineeMap(AppClientModule.J2EE_TYPE);
133         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
134         for(Iterator JavaDoc itr = apps.values().iterator(); itr.hasNext(); ) {
135             controllers.add(new AppClientModuleController(
136                 (AppClientModule)itr.next(), getDeploymentManager(),
137                     appMgmtConnection));
138         }
139         AppClientModuleController[] result =
140             new AppClientModuleController[controllers.size()];
141         return (AppClientModuleController[]) controllers.toArray(result);
142     }
143
144     
145     /**
146      *
147      *
148      */

149     public ConnectorModuleController[] getConnectorModules() {
150         
151         testIfServerInDebug();
152         
153         String JavaDoc resJ2EETypeProp =
154             Util.makeJ2EETypeProp(ResourceAdapterModule.J2EE_TYPE);
155         String JavaDoc appProperty =
156             JMXUtil.makeProp(J2EEApplication.J2EE_TYPE, getName());
157         String JavaDoc props = Util.concatenateProps(resJ2EETypeProp, appProperty);
158         java.util.Set JavaDoc embeddedRars = getQueryMgr().queryPropsSet(props);
159         java.util.Vector JavaDoc resAdaptorModules = new java.util.Vector JavaDoc();
160         for(Iterator JavaDoc itr = embeddedRars.iterator(); itr.hasNext(); ) {
161             resAdaptorModules.add(new ConnectorModuleController(
162                     (ResourceAdapterModule)itr.next(), getDeploymentManager(),
163                         appMgmtConnection));
164         }
165         ConnectorModuleController[] result =
166             new ConnectorModuleController[resAdaptorModules.size()];
167         return (ConnectorModuleController[]) resAdaptorModules.toArray(result);
168     }
169     
170     
171     /**
172      *
173      *
174      */

175     public WebModuleController[] getWebModules() {
176         
177         testIfServerInDebug();
178         java.util.Map JavaDoc apps = ControllerUtil.stripOutSystemApps(
179             application.getContaineeMap(WebModule.J2EE_TYPE));
180         
181         java.util.Vector JavaDoc controllers = new java.util.Vector JavaDoc();
182         for(Iterator JavaDoc itr = apps.values().iterator(); itr.hasNext(); ) {
183             controllers.add(new WebModuleController(
184                 (WebModule)itr.next(), getDeploymentManager(),
185                     appMgmtConnection));
186         }
187         WebModuleController[] result =
188             new WebModuleController[controllers.size()];
189         return (WebModuleController[]) controllers.toArray(result);
190     }
191     
192     /**
193      * Returns all the names of the web modules embedded in the specified
194      * deployed application.
195      *
196      * @return An array of modules embedded in this application.
197      */

198     public String JavaDoc[] getEmbeddedModulesByType(String JavaDoc nodeType) {
199         
200         testIfServerInDebug();
201         
202         return ControllerUtil.getComponentNamesFromMap(
203             application.getContaineeMap(
204                 NodeTypes.getAMXJ2EETypeByNodeType(nodeType)));
205     }
206     
207     
208     /**
209      *
210      */

211     public String JavaDoc[] getEjbsByType(String JavaDoc nodeType, String JavaDoc ejbModuleName,
212             String JavaDoc ejbName) {
213         
214         testIfServerInDebug();
215         
216          return ControllerUtil.getComponentNamesFromMap(
217             application.getContaineeMap(
218                 NodeTypes.getAMXJ2EETypeByNodeType(nodeType)));
219     }
220     
221     
222     /**
223      * Returns the EJBModule object by ejb module name.
224      *
225      * @param ejbModuleName The name of the ejbmodule.
226      * @return The EJBModule object corresponding to the name given.
227      */

228     public EJBModule getEJBModuleByName(String JavaDoc ejbModuleName) {
229         
230         testIfServerInDebug();
231         
232         java.util.Map JavaDoc modules = application.getContaineeMap(EJBModule.J2EE_TYPE);
233         return (EJBModule) modules.get(ejbModuleName);
234     }
235     
236     
237     /**
238      *
239      *
240      *
241      */

242     public boolean isEnabled() {
243         testIfServerInDebug();
244         boolean configEnabled = ((Enabled)appConfig).getEnabled();
245         return ControllerUtil.calculateIsEnabled(appConfig, configEnabled);
246     }
247     
248     
249     /**
250      *
251      *
252      *
253      */

254     public void setEnabled(boolean enabled) {
255         testIfServerInDebug();
256         DeployedItemRefConfig config = ControllerUtil.getDeployedItemRefConfig(appConfig);
257         if(config != null)
258             config.setEnabled(enabled);
259     }
260
261     public J2EEDeployedObject getJ2EEObject() {
262         return application;
263     }
264     
265 }
266
267
268
269
Popular Tags