KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > WebModuleConfig


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (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
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.web;
25
26 import java.io.File JavaDoc;
27
28 import org.apache.catalina.util.StringManager;
29
30 import com.sun.enterprise.deployment.Application;
31 import com.sun.enterprise.deployment.WebBundleDescriptor;
32 import com.sun.enterprise.config.serverbeans.WebModule;
33 import com.sun.enterprise.config.ConfigException;
34 import com.sun.enterprise.util.io.FileUtils;
35
36 /**
37  * Represents the configuration parameters required in order to create
38  * and install a web module (web application) in the iAS 7.0 server runtime.
39  */

40 public class WebModuleConfig {
41
42     // ----------------------------------------------------- Instance Variables
43

44     /**
45      * The config bean containing the properties specified in the web-module
46      * element in server.xml.
47      */

48     private WebModule _wmBean = null;
49
50     /**
51      * The parent directory under which the work directory for files generated
52      * by the web application (i.e compiled JSP class files etc) resides.
53      */

54     private String JavaDoc _baseDir = null;
55
56     /**
57      * The parent classloader for the web application.
58      */

59     private ClassLoader JavaDoc _parentLoader = null;
60
61    /**
62     * Deployment descriptor information about the web application.
63     */

64    private WebBundleDescriptor _wbd = null;
65
66    /**
67     * keep a list of virtual servers that this webmodule is associated with
68     */

69    private String JavaDoc _vsIDs;
70
71     // START S1AS 6178005
72
private String JavaDoc stubBaseDir;
73     // END S1AS 6178005
74

75    
76    /**
77      * The string manager for this package.
78      */

79     private static StringManager _sm =
80         StringManager.getManager(Constants.Package);
81
82     // ------------------------------------------------------------- Properties
83

84     /**
85      * Set the elements of information specified in the web-module element
86      * in server.xml.
87      */

88     public void setBean(WebModule wmBean) {
89         _wmBean = wmBean;
90     }
91
92
93     /**
94      * Return the configuration information specified in server.xml.
95      */

96     public WebModule getBean() {
97         return _wmBean;
98     }
99
100     /**
101      * Return the name of the web application (as specified in server.xml)
102      *
103      * @return [$appID:]$moduleID
104      */

105     public String JavaDoc getName() {
106         String JavaDoc name = null;
107         if (_wmBean != null) {
108             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
109             String JavaDoc appName = getAppName();
110             if (appName != null) {
111                 // Include the application id (if this is not a
112
// standalone web module)
113
buffer.append(appName);
114                 buffer.append(Constants.NAME_SEPARATOR);
115             }
116             buffer.append(getModuleName());
117             name = buffer.toString();
118         }
119         return name;
120     }
121
122     /**
123      * Return the context path at which the web application is deployed.
124      */

125     public String JavaDoc getContextPath() {
126         String JavaDoc ctxPath = null;
127         if (_wmBean != null) {
128                 ctxPath = _wmBean.getContextRoot().trim();
129                 // Don't prefix a / if this web module is the default one
130
// i.e. has an empty context-root
131
if ((ctxPath.length() > 0) && !ctxPath.startsWith("/")) {
132                     ctxPath = "/" + ctxPath;
133                 } else if (ctxPath.equals("/")) {
134                     ctxPath = "";
135                 }
136         }
137         return ctxPath;
138     }
139
140     /**
141      * Return the directory in which the web application is deployed.
142      */

143     public String JavaDoc getLocation() {
144         String JavaDoc dir = null;
145         if (_wmBean != null) {
146             dir = _wmBean.getLocation();
147         }
148         return dir;
149     }
150
151     /**
152      * Return the list of virtual servers to which the web application is
153      * deployed.
154      */

155     public String JavaDoc getVirtualServers() {
156         /*String vsIDs = null;
157         if (_wmBean != null) {
158             vsIDs = _wmBean.getVirtualServers();
159         }
160          */

161         return _vsIDs;
162     }
163
164     /**
165      * Return the list of virtual servers to which the web application is
166      * deployed.
167      */

168     public void setVirtualServers(String JavaDoc virtualServers) {
169         _vsIDs = virtualServers;
170     }
171     
172     /**
173      * Set the parent classloader for the web application.
174      */

175     public void setParentLoader(ClassLoader JavaDoc parentLoader) {
176         _parentLoader = parentLoader;
177     }
178
179     /**
180      * Return the parent classloader for the web application.
181      */

182     public ClassLoader JavaDoc getParentLoader() {
183         return _parentLoader;
184     }
185
186     /**
187      * Return the work directory for this web application.
188      *
189      * The work directory is either
190      * generated/j2ee-apps/$appID/$moduleID
191      * or
192      * generated/j2ee-modules/$moduleID
193      */

194     public String JavaDoc getWorkDir() {
195         return getWebDir(_baseDir);
196     }
197
198
199     // START S1AS 6178005
200
/**
201      * Gets the stub path of this web application.
202      *
203      * @return Stub path of this web application
204      */

205     public String JavaDoc getStubPath() {
206         return getWebDir(stubBaseDir);
207     }
208     // END S1AS 6178005
209

210
211     /**
212      * Set the base work directory for this web application.
213      *
214      * The actual work directory is a subdirectory (using the name of the
215      * web application) of this base directory.
216      *
217      * @param baseDir The new base directory under which the actual work
218      * directory will be created
219      */

220     public void setWorkDirBase(String JavaDoc baseDir) {
221         _baseDir = baseDir;
222     }
223
224
225     // START S1AS 6178005
226
/**
227      * Sets the base directory of this web application's stub path.
228      *
229      * @param stubPath Stub path
230      */

231     public void setStubBaseDir(String JavaDoc stubBaseDir) {
232         this.stubBaseDir = stubBaseDir;
233     }
234     // END S1AS 6178005
235

236
237     /**
238      * Return the object representation of the deployment descriptor specified
239      * for the web application.
240      */

241     public WebBundleDescriptor getDescriptor() {
242         return _wbd;
243     }
244
245
246     /**
247      * Set the deployment descriptor object describing the contents of the
248      * web application.
249      *
250      * @param wbd The deployment descriptor object
251      */

252     public void setDescriptor(WebBundleDescriptor wbd) {
253         _wbd = wbd;
254     }
255
256     // --------------------------------------------------------Private metthods
257

258     /**
259      * Return the name of the application that this web module belongs
260      * to or null if this is a standalone web module.
261      */

262     private String JavaDoc getAppName() {
263         String JavaDoc name = null;
264         if (_wbd != null) {
265             Application app = _wbd.getApplication();
266             if ((app != null) && !app.isVirtual()) {
267                 String JavaDoc appName = app.getRegistrationName();
268                 if ((appName != null) && (appName.length() > 0)) {
269                     name = appName.trim();
270                 }
271             }
272         }
273         return name;
274     }
275
276     /**
277      * Return just the name of the web module.
278      */

279     private String JavaDoc getModuleName() {
280         String JavaDoc name = null;
281         if (_wmBean != null) {
282             name = _wmBean.getName();
283         }
284         return name;
285     }
286
287
288     /*
289      * Appends this web module's id to the given base directory path, and
290      * returns it.
291      *
292      * @param baseDir Base directory path
293      */

294     private String JavaDoc getWebDir(String JavaDoc baseDir) {
295
296         String JavaDoc workDir = null;
297
298         if (baseDir != null) {
299             StringBuffer JavaDoc dir = new StringBuffer JavaDoc();
300             dir.append(baseDir);
301
302             // Append the application id (if this is not a standalone web
303
// module)
304
String JavaDoc appName = getAppName();
305             if (appName != null) {
306                 dir.append(File.separator);
307                 dir.append(FileUtils.makeFriendlyFilename(appName));
308             }
309
310             // Append the web module id
311
String JavaDoc name = getModuleName();
312             if (name != null) {
313                 dir.append(File.separator);
314                 dir.append(FileUtils.makeFriendlyFilename(name));
315             }
316             workDir = dir.toString();
317         }
318
319         return workDir;
320     }
321 }
322
Popular Tags