KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > kernel > RootContainer


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2003 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64 package com.jcorporate.expresso.kernel;
65
66 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
67 import com.jcorporate.expresso.kernel.digester.ExpressoServicesConfig;
68 import com.jcorporate.expresso.kernel.exception.ConfigurationException;
69 import com.jcorporate.expresso.kernel.management.ExpressoRuntimeMap;
70
71 import java.lang.ref.WeakReference JavaDoc;
72 import java.util.Collections JavaDoc;
73 import java.util.HashMap JavaDoc;
74 import java.util.Map JavaDoc;
75
76
77 /**
78  * This is the default root container interface. It is essentially the root of
79  * the Expresso Runtime tree.
80  *
81  * @author Michael Rimov
82  */

83 public class RootContainer extends ContainerComponentBase
84         implements RootContainerInterface {
85     private Boolean JavaDoc showStackTrace;
86     private LogManager logManager = null;
87     private Map setupValues = new HashMap();
88     private String JavaDoc httpPort;
89     private String JavaDoc servletAPI;
90     private String JavaDoc sslPort;
91
92     /**
93      * The location of the services file so we can reload the config if
94      * necessary
95      */

96     private java.net.URL JavaDoc servicesFile;
97
98     /**
99      * Weak Reference that contains the expresso configuration file. To save
100      * memory, we allow the tree to be gc'ed if nobody else maintains a
101      * reference to it. We reload the system upon request at that point.
102      */

103     private WeakReference JavaDoc systemConfiguration = null;
104
105     /**
106      * Default constructor
107      */

108     public RootContainer() {
109     }
110
111     /**
112      * Set the ExpressoServicesConfig bean. This is usually done by the System
113      * factory, or possibly the management tools.
114      *
115      * @param theConfig the new Expresso services config file.
116      */

117     public synchronized void setExpressoServicesConfig(ExpressoServicesConfig theConfig) {
118         this.systemConfiguration = new WeakReference JavaDoc(theConfig);
119     }
120
121     /**
122      * Retrieve the current ExpressoServicesConfiguration file bean.
123      * <p/>
124      * <p/>
125      * <b>Note</b> An important aspect of memory saving that RootContainer does
126      * is that it maintains the local copy of the ExpressoServicesConfig as a
127      * weak reference. It then reloads from scratch if absolutely necessary.
128      * Because of this, you cannot modify ExpressoServicesConfig, lose your
129      * reference, and call getExpressoServicesConfig() again to retrieve your
130      * changes. Maintain a reference yourself if you want to save changes
131      * later!
132      * </p>
133      *
134      * @return the Root ExpressoServicesconfig
135      */

136     public synchronized ExpressoServicesConfig getExpressoServicesConfig() {
137         ExpressoServicesConfig sc;
138
139         if (systemConfiguration.get() == null) {
140             sc = new ExpressoServicesConfig();
141             sc.setExpressoServicesFile(servicesFile);
142             sc.loadExpressoServices();
143             systemConfiguration = new WeakReference JavaDoc(sc);
144         }
145
146         return (ExpressoServicesConfig) systemConfiguration.get();
147     }
148
149     /**
150      * Set the HTTP port of the server
151      *
152      * @param httpPort the new value for this configuration setting
153      */

154     public synchronized void setHttpPort(String JavaDoc httpPort) {
155         this.httpPort = httpPort;
156     }
157
158     /**
159      * Retrieve the HTTP port of this server
160      *
161      * @return java.lang.String
162      */

163     public synchronized String JavaDoc getHttpPort() {
164         return httpPort;
165     }
166
167     /**
168      * Set the log manager for the entire expresso system
169      *
170      * @param newManager the new LogManager for the system
171      */

172     public synchronized void setLogManager(LogManager newManager) {
173         logManager = newManager;
174     }
175
176     /**
177      * Retrieve the LogManager object for the system
178      *
179      * @return the LogManager for the system
180      */

181     public synchronized LogManager getLogManager() {
182         return this.logManager;
183     }
184
185     /**
186      * Sets the ULR location of the services file. This is usually called by
187      * the SystemFactory
188      *
189      * @param url the location of the services file.
190      */

191     public synchronized void setServicesFileLocation(java.net.URL JavaDoc url) {
192         servicesFile = url;
193     }
194
195     /**
196      * Retrieves the URL location of the services file location. May be inside
197      * a jar/war file
198      *
199      * @return java.net.URL
200      */

201     public synchronized java.net.URL JavaDoc getServicesFileLocation() {
202         return servicesFile;
203     }
204
205     /**
206      * Set the servlet API of the system
207      *
208      * @param servletAPI the new value for the system
209      */

210     public synchronized void setServletAPI(String JavaDoc servletAPI) {
211         this.servletAPI = servletAPI;
212     }
213
214     /**
215      * Retrieve the servlet API of the system
216      *
217      * @return the current servlet API string
218      */

219     public synchronized String JavaDoc getServletAPI() {
220         return servletAPI;
221     }
222
223     /**
224      * Retrieve a specific setup value for the container.
225      *
226      * @param key the key for the global setup value
227      * @return java.lang.String
228      */

229     public synchronized String JavaDoc getSetupValue(String JavaDoc key) {
230         return (String JavaDoc) setupValues.get(key);
231     }
232
233     /**
234      * Retrieve all the setup values for the root container.
235      *
236      * @return Map of all setup values.
237      */

238     public synchronized Map getSetupValues() {
239         return Collections.synchronizedMap(setupValues);
240     }
241
242     /**
243      * Sets whether stack traces should be shown or not.
244      *
245      * @param showStackTrace the new value.
246      * @throws IllegalArgumentException if showStackTrace is null
247      */

248     public synchronized void setShowStackTrace(Boolean JavaDoc showStackTrace) {
249         if (showStackTrace == null) {
250             this.showStackTrace = Boolean.FALSE;
251         }
252
253         this.showStackTrace = showStackTrace;
254     }
255
256     /**
257      * Get the show stack trace. This is backwards compatible with the old
258      * method of doing things in misc.ConfigManager.
259      *
260      * @return java.lang.Boolean
261      */

262     public synchronized Boolean JavaDoc getShowStackTrace() {
263         return showStackTrace;
264     }
265
266     /**
267      * Retrieve whether stack traces should be shown or not.
268      *
269      * @return boolean true if stacktrace should be shown
270      */

271     public synchronized boolean isShowStackTrace() {
272         return showStackTrace.booleanValue();
273     }
274
275     /**
276      * Set the SSL port property of this root container
277      *
278      * @param sslPort the new location for the SSL port
279      */

280     public synchronized void setSslPort(String JavaDoc sslPort) {
281         this.sslPort = sslPort;
282     }
283
284     /**
285      * Retrieve the location of the Expresso SSL port. This method is to
286      * eventually be removed to another separate component
287      *
288      * @return java.lang.String
289      */

290     public synchronized String JavaDoc getSslPort() {
291         return sslPort;
292     }
293
294     /**
295      * Configure the global container including type conversion for default
296      * values.
297      *
298      * @param newConfig The Configuration 'dynabean'
299      * @throws ConfigurationException upon error
300      */

301     public synchronized void configure(Configuration newConfig)
302             throws ConfigurationException {
303         Map setupMap = newConfig.getMappedProperties("SetupValue");
304
305         if (setupMap != null) {
306             setupValues = new ConcurrentReaderHashMap(setupMap);
307         }
308
309         setShowStackTrace((Boolean JavaDoc) newConfig.get("ShowStackTrace"));
310
311         setHttpPort((String JavaDoc) newConfig.get("HttpPort"));
312         setServletAPI((String JavaDoc) newConfig.get("ServletAPI"));
313         setSslPort((String JavaDoc) newConfig.get("SslPort"));
314     }
315
316     /**
317      * Destroys the container and unregisters itself from the
318      * ExpressoRuntimeMap
319      */

320     public synchronized void destroy() {
321         ExpressoRuntimeMap.unregisterRuntime(this.getExpressoServicesConfig()
322                 .getName());
323         this.getContainerImplementation().destroyContainer();
324     }
325
326     /**
327      * Default Initializer
328      */

329     public synchronized void initialize() {
330         return;
331     }
332
333     /**
334      * Reconfigure the global container
335      *
336      * @param newConfig the new configuration.
337      * @throws ConfigurationException upon reconfiguration error
338      */

339     public synchronized void reconfigure(Configuration newConfig)
340             throws ConfigurationException {
341         setShowStackTrace(null);
342         setHttpPort(null);
343         setServletAPI(null);
344         setSslPort(null);
345         setupValues = new HashMap();
346         configure(newConfig);
347     }
348 }
349
Popular Tags