001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: War.java 6702 2005-05-05 16:09:14Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.web;
025:
026: import java.net.URL;
027:
028: import org.objectweb.jonas.web.lib.PermissionManager;
029:
030: /**
031: * This class is representing a War (a web application) structure which is
032: * composed of :
033: * - the URL of the war file.
034: * - the URL of the ear containing this war.
035: * - the name of the host on which this war is deployed.
036: * - the context root of this war.
037: * - compliance to the java 2 delegation model.
038: * - Content of the web.xml file
039: * - Content of the jonas-web.xml file
040: * - List of the servlets name
041: * - A permission manager
042: * @author Florent Benoit
043: */
044: public class War implements WarMBean {
045:
046: /**
047: * The URL of the war file.
048: */
049: private URL warURL = null;
050:
051: /**
052: * The URL of the ear containing this war.
053: */
054: private URL earURL = null;
055:
056: /**
057: * The name of the host on which this war is deployed.
058: */
059: private String hostName = null;
060:
061: /**
062: * The context root where this war is deployed.
063: */
064: private String contextRoot = null;
065:
066: /**
067: * Compliance to the java 2 delegation model.
068: */
069: private boolean java2DelegationModel = true;
070:
071: /**
072: * Content of the web.xml file
073: */
074: private String xmlContent = null;
075:
076: /**
077: * Content of the jonas-web.xml file
078: */
079: private String jonasXmlContent = null;
080:
081: /**
082: * Names of the servlet
083: */
084: private String[] servletsName = null;
085:
086: /**
087: * Permission Manager used
088: */
089: private PermissionManager permissionManager = null;
090:
091: /**
092: * Construct a War with the specified name, of the specified
093: * ear. (Used in the case of an ear application).
094: * @param warURL the URL of the war.
095: * @param earURL the URL of the ear containing this war.
096: * @param hostName the name of the host on which this war is deployed.
097: * @param contextRoot the context root of this war.
098: * @param java2DelegationModel the java2 delegation model compliance
099: * @param xmlContent content of the web.xml file
100: * @param jonasXmlContent content of the jonas-web.xml file
101: * @param servletsName name of the servlets
102: */
103: public War(final URL warURL, final URL earURL,
104: final String hostName, final String contextRoot,
105: final boolean java2DelegationModel,
106: final String xmlContent, final String jonasXmlContent,
107: final String[] servletsName) {
108: this .warURL = warURL;
109: this .earURL = earURL;
110: this .hostName = hostName;
111: this .contextRoot = contextRoot;
112: this .java2DelegationModel = java2DelegationModel;
113: this .xmlContent = xmlContent;
114: this .jonasXmlContent = jonasXmlContent;
115: this .servletsName = servletsName;
116: }
117:
118: /**
119: * Return true if only if this war is in an ear file.
120: * @return true if only if this war is in an ear file.
121: */
122: public boolean isInEarCase() {
123: return earURL != null;
124: }
125:
126: /**
127: * Get the URL of the war file.
128: * @return the URL of the war file.
129: */
130: public URL getWarURL() {
131: return warURL;
132: }
133:
134: /**
135: * Get the URL of the ear containing this war.
136: * @return the URL of the war file.
137: */
138: public URL getEarURL() {
139: return earURL;
140: }
141:
142: /**
143: * Get the name of the host on which this war is deployed.
144: * @return the name of the host on which this war is deployed.
145: */
146: public String getHostName() {
147: return hostName;
148: }
149:
150: /**
151: * Get the context root of this war.
152: * @return the context root of this war.
153: */
154: public String getContextRoot() {
155: return contextRoot;
156: }
157:
158: /**
159: * Context classloader must follow the java2 delegation model ?
160: * @return true if the context's classloader must follow the java 2 delegation model.
161: */
162: public boolean getJava2DelegationModel() {
163: return java2DelegationModel;
164: }
165:
166: /**
167: * Return the standard xml file
168: * @return the standard xml file
169: */
170: public String getXmlContent() {
171: return xmlContent;
172: }
173:
174: /**
175: * Return the jonas-specific xml file
176: * @return the jonas-specific xml file
177: */
178: public String getJOnASXmlContent() {
179: return jonasXmlContent;
180: }
181:
182: /**
183: * Return a list of all servlets available
184: * @return a list of all servlets available
185: */
186: public String[] getServletsName() {
187: return servletsName;
188: }
189:
190: /**
191: * Set the permission manager
192: * @param permissionManager permission manager to set
193: */
194: public void setPermissionManager(PermissionManager permissionManager) {
195: this .permissionManager = permissionManager;
196: }
197:
198: /**
199: * Gets the permission manager
200: * @return permission manager
201: */
202: public PermissionManager getPermissionManager() {
203: return permissionManager;
204: }
205:
206: /**
207: * Gets a contextId for this module
208: * @return contextId
209: */
210: public String getContextId() {
211: return getWarURL().getFile() + contextRoot;
212: }
213:
214: /**
215: * Return true if only if the specified war is equal to this war.
216: * @param war the war to compare for the equality.
217: * @return true if only if the specified war is equal to this war.
218: */
219: public boolean equals(War war) {
220: return war.getWarURL().equals(warURL)
221: && war.getEarURL().equals(earURL)
222: && war.getHostName().equals(hostName)
223: && war.getContextRoot().equals(contextRoot)
224: && (war.getJava2DelegationModel() == java2DelegationModel);
225: }
226:
227: /**
228: * @return an hashcode for this object
229: * @see java.lang.Object#hashCode()
230: */
231: public int hashCode() {
232: return warURL.hashCode();
233: }
234:
235: /**
236: * Return a string representation of the war. Used for debug.
237: * @return a string representation of the war.
238: */
239: public String toString() {
240: StringBuffer ret = new StringBuffer();
241: ret.append("WAR=\n");
242: ret.append("\twarURL=" + getWarURL() + "\n");
243: ret.append("\tearURL=" + getEarURL() + "\n");
244: ret.append("\thostName=" + getHostName() + "\n");
245: ret.append("\tcontextRoot=" + getContextRoot());
246: ret.append("\tjava2DelegationModel="
247: + getJava2DelegationModel());
248: return ret.toString();
249: }
250: }
|