KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_web > deployment > api > WebContainerDeploymentDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Florent BENOIT & Ludovic BERT
22  * --------------------------------------------------------------------------
23  * $Id: WebContainerDeploymentDesc.java,v 1.24 2004/07/29 12:19:55 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_web.deployment.api;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.util.Vector JavaDoc;
37
38 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
39 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
40 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
41 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
42 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroupDesc;
43 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
44 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
45 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
46 import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
47
48 import org.objectweb.jonas_web.deployment.xml.JonasWebApp;
49 import org.objectweb.jonas_web.deployment.xml.Servlet;
50 import org.objectweb.jonas_web.deployment.xml.ServletMapping;
51 import org.objectweb.jonas_web.deployment.xml.WebApp;
52
53 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
54
55 /**
56  * This class do the parsing of the web.xml file and jonas-web.xml files and
57  * contruct a data structure associated to these two files.
58  * 03/03 : Can read web.xml and jonas-web.xml if the url of the war is a directory.
59  * @author Ludovic Bert
60  * @author Florent Benoit
61  * @author Philippe Coq
62  */

63 public class WebContainerDeploymentDesc extends JndiEnvRefsGroupDesc {
64
65     /**
66      * The host on which the web application must be depoyed (can be null in
67      * ear case).
68      */

69     private String JavaDoc host = null;
70
71     /**
72      * The context root of the web application (can be null in ear case).
73      */

74     private String JavaDoc contextRoot = null;
75
76     /**
77      * The port number of the prefered connector to access the web application
78      * (can be null if defaults values can be found). Used only for WebServices.
79      */

80     private String JavaDoc port = null;
81
82     /**
83      * The delegation model used by the class loader context follows the java 2 delegation model ?
84      */

85     private boolean java2DelegationModel = true;
86
87     /**
88      * List of mapping between servlets names and servlets classes
89      */

90     private Map JavaDoc servlets = new HashMap JavaDoc();
91
92     /**
93      * List of mapping between servlets names and servlets url-mapping
94      */

95     private Hashtable JavaDoc servletsUrlMapping = new Hashtable JavaDoc();
96
97     /**
98      * Xml content of the web.xml file
99      */

100     private String JavaDoc xmlContent = "";
101
102     /**
103      * Xml content of the jonas-web.xml file
104      */

105     private String JavaDoc jonasXmlContent = "";
106
107     /**
108      * list of URLs
109      */

110     private List JavaDoc securityRoleList;
111
112     /**
113      * URLPattern Constraints
114      */

115     private SecurityConstraintListDesc securityConstraintListDesc;
116
117
118     /**
119      * Construct an instance of a WebContainerDeploymentDesc.<BR>
120      * Constructor is private, call one of the static getInstance
121      * method instead.
122      * @param fileName the name of the warFile
123      * @param classLoader the classloader for the classes.
124      * @param webApp the data structure of the web-app (web.xml)
125      * @param jonasWebApp the data structure of the jonas-web-app
126      * (jonas-web.xml)
127      * @throws DeploymentDescException if the deployment
128      * descriptors are corrupted.
129      */

130     public WebContainerDeploymentDesc(String JavaDoc fileName,
131                                       ClassLoader JavaDoc classLoader,
132                                       WebApp webApp,
133                                       JonasWebApp jonasWebApp)
134         throws DeploymentDescException {
135
136         super(classLoader, webApp, jonasWebApp, fileName);
137
138
139         // host
140
if (jonasWebApp.getHost() != null) {
141             host = jonasWebApp.getHost();
142         } else {
143             host = null;
144         }
145
146         // context-root
147
if (jonasWebApp.getContextRoot() != null) {
148         contextRoot = jonasWebApp.getContextRoot();
149         } else {
150             contextRoot = null;
151         }
152
153         // port
154
if (jonasWebApp.getPort() != null) {
155             port = jonasWebApp.getPort();
156         } else {
157             port = null;
158         }
159
160         // Class loader delegation model
161
String JavaDoc delegationModel = null;
162         if (jonasWebApp.getJava2DelegationModel() != null) {
163             delegationModel = jonasWebApp.getJava2DelegationModel();
164         } else {
165             delegationModel = "true";
166         }
167
168         if (delegationModel.equalsIgnoreCase("false")) {
169             java2DelegationModel = false;
170         } else if (delegationModel.equalsIgnoreCase("true")) {
171             java2DelegationModel = true;
172         } else {
173             throw new WebContainerDeploymentDescException("The java2 delegation model could be 'true' or 'false', not '" + delegationModel + "'.");
174         }
175
176         // Security Role List
177
SecurityRole securityRole = null;
178         securityRoleList = new ArrayList JavaDoc();
179         for (Iterator JavaDoc itSecurityRole = webApp.getSecurityRoleList().iterator(); itSecurityRole.hasNext();) {
180             securityRole = (SecurityRole) itSecurityRole.next();
181             securityRoleList.add(new SecurityRoleDesc(securityRole));
182         }
183
184
185         // servlet classes + names
186
List JavaDoc servletList = webApp.getServletList();
187         for (Iterator JavaDoc i = servletList.iterator(); i.hasNext();) {
188             Servlet servlet = (Servlet) i.next();
189             if (servlet.getServletName() != null) {
190                 ServletDesc servletDesc = new ServletDesc(servlet);
191                 servlets.put(servlet.getServletName(), servletDesc);
192             }
193         }
194
195
196         // Construct servletsUrlMapping
197
List JavaDoc urlMappings = webApp.getServletMappingList();
198         for (Iterator JavaDoc i = servletList.iterator(); i.hasNext();) {
199             Servlet servlet = (Servlet) i.next();
200             String JavaDoc name = servlet.getServletName().trim();
201             Vector JavaDoc mappings = new Vector JavaDoc();
202             for (Iterator JavaDoc m = urlMappings.iterator(); m.hasNext();) {
203                 ServletMapping sm = (ServletMapping) m.next();
204                 if (sm.getServletName().trim().equals(name)) {
205                     String JavaDoc pattern = sm.getUrlPattern().trim();
206                     if (pattern.indexOf('\n') != -1) {
207                         throw new WebContainerDeploymentDescException("There is a '\\n' character inside the url pattern for servlet named '" + sm.getServletName() + "' in the file '" + fileName + "'.");
208                     }
209                     mappings.add(pattern);
210                 }
211             }
212             servletsUrlMapping.put(name, mappings);
213         }
214
215         // Build SecurityConstraintListDesc
216
securityConstraintListDesc = new SecurityConstraintListDesc(webApp);
217
218         /*
219          * See SRV 13.2 of servlet spec 2.4 <br>
220          * The sub elements under web-app can be in an arbitrary order in this
221          * version of the specification. Because of the restriction of XML
222          * Schema, The multiplicity of the elements distributable,
223          * session-config, welcome-file-list, jspconfig, login-config, and
224          * locale-encoding-mapping-list was changed from optional to 0 or more .
225          * The containers must inform the developer with a descriptive error
226          * message when the deployment descriptor contains more than one element
227          * of session-config, jsp-config, and login-config.
228          */

229         if (webApp.getJspConfigNumber() > 1) {
230             throw new WebContainerDeploymentDescException("The web-app element must contain only one element jsp-config in file '" + fileName + "'");
231         }
232
233         if (webApp.getLoginConfigNumber() > 1) {
234             throw new WebContainerDeploymentDescException("The web-app element must contain only one element login-config in file '" + fileName + "'");
235         }
236
237         if (webApp.getSessionConfigNumber() > 1) {
238             throw new WebContainerDeploymentDescException("The web-app element must contain only one element session-config in file '" + fileName + "'");
239         }
240
241
242
243     }
244
245     /**
246      * Return the content of the web.xml file
247      * @return the content of the web.xml file
248      */

249     public String JavaDoc getXmlContent() {
250         return xmlContent;
251     }
252
253     /**
254      * Return the content of the jonas-web.xml file
255      * @return the content of the jonas-web.xml file
256      */

257     public String JavaDoc getJOnASXmlContent() {
258         return jonasXmlContent;
259     }
260
261     /**
262      * Set the content of the web.xml file
263      * @param xml the content of the file
264      */

265     public void setXmlContent(String JavaDoc xml) {
266         xmlContent = xml;
267     }
268
269     /**
270      * Set the content of the jonas-web.xml file
271      * @param jXml the content of the file
272      */

273     public void setJOnASXmlContent(String JavaDoc jXml) {
274         jonasXmlContent = jXml;
275     }
276
277
278     /**
279      * Get the context root of this web application.
280      * @return the context root of this web application.
281      */

282     public String JavaDoc getContextRoot() {
283         return contextRoot;
284     }
285
286     /**
287      * Context classloader must follow the java2 delegation model ?
288      * @return true if the context's classloader must follow the java 2 delegation model.
289      */

290     public boolean getJava2DelegationModel() {
291         return java2DelegationModel;
292     }
293
294     /**
295      * Get the host on which the web application must be deployed.
296      * @return the host on which the web application must be deployed.
297      */

298     public String JavaDoc getHost() {
299         return host;
300     }
301
302     /**
303      * Get the prefered port of the connector used to access the web application.
304      * @return the prefered port of the connector used to access the web application.
305      */

306     public String JavaDoc getPort() {
307         return port;
308     }
309
310     /**
311      * Return a String representation of the WebContainerDeploymentDesc.
312      * @return a String representation of the WebContainerDeploymentDesc.
313      */

314     public String JavaDoc toString() {
315         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
316
317         // Return the displayName
318
ret.append("\ngetDisplayName()=" + getDisplayName());
319
320         // Return the resource-env-ref
321
ResourceEnvRefDesc[] rer = getResourceEnvRefDesc();
322         for (int i = 0; i < rer.length; i++) {
323             ret.append("\ngetResourceEnvRefDesc(" + i + ")=" + rer[i].getClass().getName());
324             ret.append(rer[i].toString());
325         }
326
327         // Return the resource-ref
328
ResourceRefDesc[] resourceRefDesc = getResourceRefDesc();
329         for (int i = 0; i < resourceRefDesc.length; i++) {
330             ret.append("\ngetResourceRefDesc(" + i + ")=" + resourceRefDesc[i].getClass().getName());
331             ret.append(resourceRefDesc[i].toString());
332         }
333
334         // Return the env-entry
335
EnvEntryDesc[] envEntries = getEnvEntryDesc();
336         for (int i = 0; i < envEntries.length; i++) {
337             ret.append("\ngetEnvEntryDesc(" + i + ")=" + envEntries[i].getClass().getName());
338             ret.append(envEntries[i].toString());
339         }
340
341         // Return the ejb-ref
342
EjbRefDesc[] ejbRefDesc = getEjbRefDesc();
343         for (int i = 0; i < ejbRefDesc.length; i++) {
344             ret.append("\ngetEjbRefDesc(" + i + ")=" + ejbRefDesc[i].getClass().getName());
345             ret.append(ejbRefDesc[i].toString());
346         }
347
348         // Return the ejb-local-ref
349
EjbLocalRefDesc[] ejbLocalRefDesc = getEjbLocalRefDesc();
350         for (int i = 0; i < ejbLocalRefDesc.length; i++) {
351             ret.append("\ngetEjbLocalRefDesc(" + i + ")=" + ejbLocalRefDesc[i].getClass().getName());
352             ret.append(ejbLocalRefDesc[i].toString());
353         }
354
355         // Return the service-ref-name
356
ServiceRefDesc[] svcRef = getServiceRefDesc();
357         for (int i = 0; i < svcRef.length; i++) {
358             ret.append("\ngetServiceRefDesc(" + i + ")=" + svcRef[i].getClass().getName());
359             ret.append(svcRef[i].toString());
360         }
361
362         // Return the message-destination-ref
363
MessageDestinationRefDesc[] mdRefDesc = getMessageDestinationRefDesc();
364         for (int i = 0; i < mdRefDesc.length; i++) {
365             ret.append("\ngetMessageDestinationRefDesc(" + i + ")=" + mdRefDesc[i].getClass().getName());
366             ret.append(mdRefDesc[i].toString());
367         }
368
369         // Return the host
370
ret.append("\ngetHost()=" + getHost());
371
372         // Return the context-root
373
ret.append("\ngetContextRoot()=" + getContextRoot());
374
375         return ret.toString();
376     }
377
378     /**
379      * Gets the list of Servlets
380      * @return list of Servlets
381      */

382     public Collection JavaDoc getServletDescList() {
383         return servlets.values();
384     }
385
386     /**
387      * Return a list of all servlets name available
388      * @return a list of all servlets name available
389      */

390     public String JavaDoc[] getServletsName() {
391         String JavaDoc[] st = new String JavaDoc[servlets.size()];
392         return (String JavaDoc[]) servlets.keySet().toArray(st);
393     }
394
395     /**
396      * Return the classname of the given servlet
397      * @param servName name of the given servlet
398      * @return the classname of the given servlet
399      */

400     public String JavaDoc getServletClassname(String JavaDoc servName) {
401         return ((ServletDesc) servlets.get(servName)).getServletClass();
402     }
403
404     /**
405      * Gets the constraint list
406      * @return the constraint list
407      */

408     public SecurityConstraintListDesc getSecurityConstraintListDesc() {
409         return securityConstraintListDesc;
410     }
411
412     /**
413      * Gets the list of security roles
414      * @return the list of security roles
415      */

416     public List JavaDoc getSecurityRoleList() {
417         return securityRoleList;
418     }
419
420     /**
421      * Return the list of urlMapping of the given servlet
422      * @param servName name of the given servlet
423      * @return the list of urlMapping of the given servlet
424      */

425     public List JavaDoc getServletMappings(String JavaDoc servName) {
426         return (List JavaDoc) servletsUrlMapping.get(servName);
427     }
428
429 }
430
Popular Tags