KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > War


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2005 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  * --------------------------------------------------------------------------
22  * $Id: War.java,v 1.5 2005/05/05 16:09:14 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.web;
27
28 import java.net.URL JavaDoc;
29
30 import org.objectweb.jonas.web.lib.PermissionManager;
31
32
33 /**
34  * This class is representing a War (a web application) structure which is
35  * composed of :
36  * - the URL of the war file.
37  * - the URL of the ear containing this war.
38  * - the name of the host on which this war is deployed.
39  * - the context root of this war.
40  * - compliance to the java 2 delegation model.
41  * - Content of the web.xml file
42  * - Content of the jonas-web.xml file
43  * - List of the servlets name
44  * - A permission manager
45  * @author Florent Benoit
46  */

47 public class War implements WarMBean {
48
49     /**
50      * The URL of the war file.
51      */

52     private URL JavaDoc warURL = null;
53
54     /**
55      * The URL of the ear containing this war.
56      */

57     private URL JavaDoc earURL = null;
58
59     /**
60      * The name of the host on which this war is deployed.
61      */

62     private String JavaDoc hostName = null;
63
64     /**
65      * The context root where this war is deployed.
66      */

67     private String JavaDoc contextRoot = null;
68
69     /**
70      * Compliance to the java 2 delegation model.
71      */

72     private boolean java2DelegationModel = true;
73
74     /**
75      * Content of the web.xml file
76      */

77     private String JavaDoc xmlContent = null;
78
79     /**
80      * Content of the jonas-web.xml file
81      */

82     private String JavaDoc jonasXmlContent = null;
83
84     /**
85      * Names of the servlet
86      */

87     private String JavaDoc[] servletsName = null;
88
89     /**
90      * Permission Manager used
91      */

92     private PermissionManager permissionManager = null;
93
94     /**
95      * Construct a War with the specified name, of the specified
96      * ear. (Used in the case of an ear application).
97      * @param warURL the URL of the war.
98      * @param earURL the URL of the ear containing this war.
99      * @param hostName the name of the host on which this war is deployed.
100      * @param contextRoot the context root of this war.
101      * @param java2DelegationModel the java2 delegation model compliance
102      * @param xmlContent content of the web.xml file
103      * @param jonasXmlContent content of the jonas-web.xml file
104      * @param servletsName name of the servlets
105      */

106     public War(final URL JavaDoc warURL, final URL JavaDoc earURL,
107             final String JavaDoc hostName, final String JavaDoc contextRoot,
108             final boolean java2DelegationModel,
109             final String JavaDoc xmlContent,
110             final String JavaDoc jonasXmlContent,
111             final String JavaDoc[] servletsName) {
112         this.warURL = warURL;
113         this.earURL = earURL;
114         this.hostName = hostName;
115         this.contextRoot = contextRoot;
116         this.java2DelegationModel = java2DelegationModel;
117         this.xmlContent = xmlContent;
118         this.jonasXmlContent = jonasXmlContent;
119         this.servletsName = servletsName;
120     }
121
122     /**
123      * Return true if only if this war is in an ear file.
124      * @return true if only if this war is in an ear file.
125      */

126     public boolean isInEarCase() {
127         return earURL != null;
128     }
129
130     /**
131      * Get the URL of the war file.
132      * @return the URL of the war file.
133      */

134     public URL JavaDoc getWarURL() {
135         return warURL;
136     }
137
138     /**
139      * Get the URL of the ear containing this war.
140      * @return the URL of the war file.
141      */

142     public URL JavaDoc getEarURL() {
143         return earURL;
144     }
145
146     /**
147      * Get the name of the host on which this war is deployed.
148      * @return the name of the host on which this war is deployed.
149      */

150     public String JavaDoc getHostName() {
151         return hostName;
152     }
153
154     /**
155      * Get the context root of this war.
156      * @return the context root of this war.
157      */

158     public String JavaDoc getContextRoot() {
159         return contextRoot;
160     }
161
162     /**
163      * Context classloader must follow the java2 delegation model ?
164      * @return true if the context's classloader must follow the java 2 delegation model.
165      */

166     public boolean getJava2DelegationModel() {
167         return java2DelegationModel;
168     }
169
170     /**
171      * Return the standard xml file
172      * @return the standard xml file
173      */

174     public String JavaDoc getXmlContent() {
175         return xmlContent;
176     }
177
178     /**
179      * Return the jonas-specific xml file
180      * @return the jonas-specific xml file
181      */

182     public String JavaDoc getJOnASXmlContent() {
183         return jonasXmlContent;
184     }
185
186     /**
187      * Return a list of all servlets available
188      * @return a list of all servlets available
189      */

190     public String JavaDoc[] getServletsName() {
191         return servletsName;
192     }
193
194     /**
195      * Set the permission manager
196      * @param permissionManager permission manager to set
197      */

198     public void setPermissionManager(PermissionManager permissionManager) {
199         this.permissionManager = permissionManager;
200     }
201
202     /**
203      * Gets the permission manager
204      * @return permission manager
205      */

206     public PermissionManager getPermissionManager() {
207         return permissionManager;
208     }
209
210
211     /**
212      * Gets a contextId for this module
213      * @return contextId
214      */

215     public String JavaDoc getContextId() {
216         return getWarURL().getFile() + contextRoot;
217     }
218
219     /**
220      * Return true if only if the specified war is equal to this war.
221      * @param war the war to compare for the equality.
222      * @return true if only if the specified war is equal to this war.
223      */

224     public boolean equals(War war) {
225         return war.getWarURL().equals(warURL)
226             && war.getEarURL().equals(earURL)
227             && war.getHostName().equals(hostName)
228             && war.getContextRoot().equals(contextRoot)
229             && (war.getJava2DelegationModel() == java2DelegationModel);
230     }
231
232     /**
233      * @return an hashcode for this object
234      * @see java.lang.Object#hashCode()
235      */

236     public int hashCode() {
237         return warURL.hashCode();
238     }
239
240     /**
241      * Return a string representation of the war. Used for debug.
242      * @return a string representation of the war.
243      */

244     public String JavaDoc toString() {
245         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
246         ret.append("WAR=\n");
247         ret.append("\twarURL=" + getWarURL() + "\n");
248         ret.append("\tearURL=" + getEarURL() + "\n");
249         ret.append("\thostName=" + getHostName() + "\n");
250         ret.append("\tcontextRoot=" + getContextRoot());
251         ret.append("\tjava2DelegationModel=" + getJava2DelegationModel());
252         return ret.toString();
253     }
254 }
255
256
Popular Tags