KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.j2ee.sun.ide.controllers;
20
21 import java.util.Map JavaDoc;
22 import java.util.List JavaDoc;
23 import com.sun.appserv.management.client.AppserverConnectionSource;
24 import com.sun.appserv.management.config.DeployedItemRefConfig;
25 import com.sun.appserv.management.config.Enabled;
26 import com.sun.appserv.management.config.WebModuleConfig;
27 import com.sun.appserv.management.j2ee.J2EEDeployedObject;
28 import com.sun.appserv.management.j2ee.WebModule;
29 import com.sun.appserv.management.j2ee.Servlet;
30
31 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
32 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtControllerBase;
33
34 import org.netbeans.modules.j2ee.sun.util.NodeTypes;
35
36
37 /**
38  * Used as a conduit between the Netbeans API's and the AMX MBean API
39  * data model. This API contains convenient methods for retrieving
40  * components allowing the netbeans module heirarchy remain agnostic to the
41  * underlying data model.
42  *
43  * This controller is used to navigate through deployed web modules.
44  */

45 public class WebModuleController extends AppserverMgmtControllerBase
46         implements DeployedItemsController, EnablerController {
47     
48     private WebModule webModule;
49     private WebModuleConfig webConfig;
50     
51     
52     /**
53      * Create an instance of J2EEServerMgmtController used in the interaction
54      * with AMX API for Sun Java System Application Server.
55      *
56      * @param server The AMX J2EEServer object representing a particular server.
57      */

58     public WebModuleController(WebModule webModule,
59             AppserverConnectionSource connection) {
60         super(webModule, connection);
61         this.webModule = webModule;
62     }
63     
64     
65     /**
66      * Create an instance of J2EEServerMgmtController used in the interaction
67      * with AMX API for Sun Java System Application Server.
68      *
69      * @param server The AMX J2EEServer object representing a particular server.
70      */

71     public WebModuleController(final WebModule webModule,
72             final DeploymentManager JavaDoc dplmtMgr,
73             final AppserverConnectionSource connection) {
74         super(webModule, dplmtMgr, connection);
75         this.webModule = webModule;
76     }
77
78     public WebModuleController(final WebModule webModule,
79             final WebModuleConfig webConfig,
80             final DeploymentManager JavaDoc dplmtMgr,
81             final AppserverConnectionSource connection) {
82         super(webConfig, dplmtMgr, connection);
83         this.webModule = webModule;
84         this.webConfig = webConfig;
85     }
86     
87     /**
88      * Returns the name that the node will use to display.
89      *
90      * @return The name used to display in the node hierarchy.
91      */

92     public String JavaDoc getDisplayName() {
93         if(webConfig != null)
94             return webConfig.getName();
95         else
96             return webModule.getPath();
97     }
98     
99     /**
100      * Returns the properties of the application given the name.
101      *
102      * @param propsToIgnore The String properties to ignore.
103      * @return All the application properties.
104      */

105     public Map JavaDoc getProperties(List JavaDoc propsToIgnore) {
106         return getJ2EEAndConfigProperties(NodeTypes.WEB_MODULE, this.webModule,
107             this.webConfig, propsToIgnore);
108     }
109     
110     /**
111      * Sets the properties.
112      *
113      * @param attrname The name of the attribute.
114      * @param value The value of the attribute to set.
115      *
116      * @return updated Attribute
117      */

118     public javax.management.Attribute JavaDoc setProperty(final String JavaDoc attrName, final Object JavaDoc value) {
119         
120         testIfServerInDebug();
121         
122         return ControllerUtil.setAttributeValue(webModule, webConfig, attrName, value,
123             getMBeanServerConnection());
124     }
125
126     /**
127      *
128      *
129      */

130     private Servlet getServletByName(String JavaDoc servletName) {
131         
132         testIfServerInDebug();
133         
134         return (Servlet) (getServletsAsMap().get(servletName));
135     }
136     
137     
138     /**
139      *
140      *
141      */

142     private Map JavaDoc getServletsAsMap() {
143         
144         testIfServerInDebug();
145         
146         return webModule.getContaineeMap(
147             NodeTypes.getAMXJ2EETypeByNodeType(NodeTypes.SERVLET));
148     }
149     
150     
151     /**
152      *
153      *
154      */

155     public Map JavaDoc getServletProperties(final String JavaDoc servletName,
156             final List JavaDoc propsToIgnore) {
157         return getPropertiesFromBackend(NodeTypes.SERVLET,
158             getServletByName(servletName), propsToIgnore);
159     }
160     
161     
162     /**
163      *
164      */

165     public javax.management.Attribute JavaDoc setServletProperties(final String JavaDoc servletName,
166             final String JavaDoc attrName, final Object JavaDoc value) {
167         
168         testIfServerInDebug();
169         
170         return ControllerUtil.setAttributeValue(
171             getServletByName(servletName), attrName, value,
172                 getMBeanServerConnection());
173     }
174     
175     
176     /**
177      *
178      *
179      */

180     public String JavaDoc[] getServlets() {
181         testIfServerInDebug();
182         return ControllerUtil.getComponentNamesFromMap(getServletsAsMap());
183     }
184     
185     
186     
187     /**
188      *
189      *
190      *
191      */

192     public boolean isEnabled() {
193         testIfServerInDebug();
194         boolean configEnabled = ((Enabled)webConfig).getEnabled();
195         return ControllerUtil.calculateIsEnabled(webConfig, configEnabled);
196     }
197     
198     
199     /**
200      *
201      *
202      *
203      */

204     public void setEnabled(boolean enabled) {
205         testIfServerInDebug();
206         DeployedItemRefConfig config = ControllerUtil.getDeployedItemRefConfig(webConfig);
207         if(config != null)
208             config.setEnabled(enabled);
209     }
210  
211     public J2EEDeployedObject getJ2EEObject() {
212         return webModule;
213     }
214 }
215
Popular Tags