KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > catalina55 > JOnASStandardContext


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  * Initial developer(s): Philippe Coq
22  * --------------------------------------------------------------------------
23  * $Id: JOnASStandardContext.java,v 1.3 2005/05/05 16:09:14 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.web.catalina55;
28
29 import java.net.URL JavaDoc;
30
31 import org.apache.catalina.LifecycleException;
32 import org.apache.catalina.Valve;
33 import org.apache.catalina.authenticator.AuthenticatorBase;
34 import org.apache.catalina.core.StandardContext;
35 import org.apache.catalina.deploy.ContextEnvironment;
36 import org.apache.catalina.deploy.ContextResource;
37
38 import org.objectweb.jonas.common.Log;
39 import org.objectweb.jonas.service.ServiceManager;
40 import org.objectweb.jonas.web.wrapper.CatalinaJWebContainerService;
41
42 import org.objectweb.util.monolog.api.BasicLevel;
43 import org.objectweb.util.monolog.api.Logger;
44
45 /**
46  * Define a JOnAS context. It is used to check if a context has been defined in
47  * server.xml and to use this context while deploying the war instead of
48  * creating a new one
49  * @author Florent Benoit
50  * @author Philippe Coq (Tomcat 4.0)
51  */

52
53 public final class JOnASStandardContext extends StandardContext {
54
55     /**
56      * Unique instance of Catalina
57      */

58     private static CatalinaJWebContainerService catalinaService = null;
59
60     /**
61      * Logger for this service.
62      */

63     private static Logger logger = null;
64
65     /**
66      * URL of the ear
67      */

68     private URL JavaDoc earURL = null;
69
70     /**
71      * We are in ear case or not ?
72      */

73     private boolean inEarCase = false;
74
75     /**
76      * This context was configured in server.xml ?
77      */

78     private boolean inServerXml = false;
79
80     /**
81      * Java 2 delegation model is use or not ?
82      */

83     private boolean java2DelegationModel = false;
84
85     /**
86      * JOnAS deployment descriptor
87      */

88     private String JavaDoc jonasDeploymentDescriptor = null;
89
90     /**
91      * Context was started ?
92      */

93     private boolean startedJStdx = false;
94
95     /**
96      * URL of the war
97      */

98     private URL JavaDoc warURL = null;
99
100     /**
101      * Constructor of the Context
102      */

103     public JOnASStandardContext() {
104         this(true, true, false);
105     }
106
107     /**
108      * Constructor of the Context
109      * @param inServerXml this context was defined in server.xml
110      * @param java2DelegationModel delegation model for classloader is true ?
111      * @param inEarCase if we are or not in EAR case
112      */

113     public JOnASStandardContext(final boolean inServerXml, final boolean java2DelegationModel, final boolean inEarCase) {
114         super();
115         this.inServerXml = inServerXml;
116         this.java2DelegationModel = java2DelegationModel;
117         this.inEarCase = inEarCase;
118         logger = Log.getLogger(Log.JONAS_WEB_PREFIX);
119         try {
120             catalinaService = (CatalinaJWebContainerService) ServiceManager.getInstance().getWebContainerService();
121         } catch (Exception JavaDoc e) {
122             if (logger.isLoggable(BasicLevel.ERROR)) {
123                 logger.log(BasicLevel.ERROR, "Cannot get Web container service");
124             }
125         }
126     }
127
128     /**
129      * @return Returns the earURL.
130      */

131     public URL JavaDoc getEarURL() {
132         return earURL;
133     }
134
135     /**
136      * Gets the deployment descriptor content of jonas-web.xml file
137      * @return the content of jonas-web.xml file
138      */

139     public String JavaDoc getJonasDeploymentDescriptor() {
140         return jonasDeploymentDescriptor;
141     }
142
143     /**
144      * @return Returns the warURL.
145      */

146     public URL JavaDoc getWarURL() {
147         return warURL;
148     }
149
150     /**
151      * @return true if this web module is a part of a EAR
152      */

153     public boolean isInEarCase() {
154         return inEarCase;
155     }
156
157     /**
158      * This context was defined in server.xml ?
159      * @return true if this context was defined in server.xml
160      */

161     public boolean isInServerXml() {
162         return inServerXml;
163     }
164
165     /**
166      * @return true if the Java2 delegation model is used
167      */

168     public boolean isJava2DelegationModel() {
169         return java2DelegationModel;
170     }
171
172     /**
173      * @param earURL The earURL to set.
174      */

175     protected void setEarURL(URL JavaDoc earURL) {
176         this.earURL = earURL;
177     }
178
179     /**
180      * @param inEarCase The inEarCase to set.
181      */

182     protected void setInEarCase(boolean inEarCase) {
183         this.inEarCase = inEarCase;
184     }
185
186     /**
187      * @param java2DelegationModel The java2DelegationModel to set.
188      */

189     protected void setJava2DelegationModel(boolean java2DelegationModel) {
190         this.java2DelegationModel = java2DelegationModel;
191     }
192
193     /**
194      * Set the deployment descriptor content of jonas-web.xml file
195      * @param jonasDeploymentDescriptor the content of jonas-web.xml
196      */

197     public void setJonasDeploymentDescriptor(String JavaDoc jonasDeploymentDescriptor) {
198         this.jonasDeploymentDescriptor = jonasDeploymentDescriptor;
199     }
200
201     /**
202      * @param warURL The warURL to set.
203      */

204     protected void setWarURL(URL JavaDoc warURL) {
205         this.warURL = warURL;
206     }
207
208     /**
209      * Start the JOnAS context if catalina is started
210      * @throws LifecycleException if the context can't be started
211      */

212     public synchronized void start() throws LifecycleException {
213         if (logger.isLoggable(BasicLevel.DEBUG)) {
214             logger.log(BasicLevel.DEBUG, "");
215         }
216         if (catalinaService != null && catalinaService.isTomcatStarted()) {
217             if (logger.isLoggable(BasicLevel.DEBUG)) {
218                 logger.log(BasicLevel.DEBUG, "Tomcat in Web container service is started, starting the context...");
219             }
220             startedJStdx = true;
221             super.start();
222         }
223
224     }
225
226     /**
227      * Stop this Context component.
228      * @exception LifecycleException if a shutdown error occurs
229      */

230     public synchronized void stop() throws LifecycleException {
231         if (logger.isLoggable(BasicLevel.DEBUG)) {
232             logger.log(BasicLevel.DEBUG, "");
233         }
234         if (startedJStdx) {
235             startedJStdx = false;
236             super.stop();
237         }
238
239     }
240
241     /**
242      * Disable cache of the authenticator
243      */

244     public void unsetAuthenticationCaching() {
245         Valve[] valves = getValves();
246         for (int i = 0; i < valves.length; i++) {
247             Valve valve = valves[i];
248             if (valve instanceof AuthenticatorBase) {
249                 AuthenticatorBase authBase = (AuthenticatorBase) valve;
250                 authBase.setCache(false);
251             }
252         }
253     }
254
255     /**
256      * Add a resource reference for this web application.
257      * Do nothing when running inside JOnAS. Resources are managed by JOnAS
258      * @param resource New resource reference
259      */

260     public void addResource(ContextResource resource) {
261     }
262
263     /**
264      * Add an environment entry for this web application.
265      * Do nothing when running inside JOnAS. ENC environment is managed by JOnAS
266      * @param environment New environment entry
267      */

268     public void addEnvironment(ContextEnvironment environment) {
269     }
270
271
272     /**
273      * Set the parent class loader for this web application.
274      * Do it only if it is not started.
275      * @param parent The new parent class loader
276      */

277     public void setParentClassLoader(ClassLoader JavaDoc parent) {
278         // Do it only if the context is not already started
279
if (!startedJStdx) {
280             super.setParentClassLoader(parent);
281         }
282     }
283 }
284
Popular Tags