KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > misc > ConfigContext


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 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
65 package com.jcorporate.expresso.core.misc;
66
67 import java.util.Hashtable JavaDoc;
68 import java.util.Vector JavaDoc;
69
70
71 /**
72  * Bean class helping with expresso-config.xml and working with the Digester
73  * to read the configuration.
74  * <p/>
75  * A config context is in the past called a 'db'. It represents one connection
76  * to a database. (May be separate database), each context has it's own
77  * job handler, potentially it's own security setup. etc.
78  */

79 public class ConfigContext {
80
81     /**
82      * Name of this context
83      */

84     private String JavaDoc name = null;
85     private String JavaDoc hasSetupTables = "y";
86
87     /**
88      * Description of this context
89      */

90     private String JavaDoc description = null;
91
92     /**
93      * JDBC configuration information for this context.
94      */

95     private ConfigJdbc myJdbc = null;
96
97     /**
98      * LDAP configuration for this context (optional)
99      */

100     private ConfigLdap myLdap = null;
101
102     /**
103      * Location of images directory
104      */

105     private String JavaDoc images = null;
106
107     /**
108      * Should the job handler for this context be started?
109      */

110     private String JavaDoc startJobHandler = null;
111
112     /**
113      * Used for if you want stack trace information on error pages. This is
114      * a security hazard if turned on. Use only for development.
115      */

116     private String JavaDoc showStackTrace = null;
117
118     /**
119      * Set if you want mail debugging
120      */

121     private String JavaDoc mailDebug = null;
122
123     /**
124      * Contains custom properties for this context.
125      */

126     private Hashtable JavaDoc customProperties = new Hashtable JavaDoc();
127
128     /**
129      * Contains the database type mappings for this context.
130      */

131     private Vector JavaDoc typeMappings = new Vector JavaDoc();
132     private Vector JavaDoc pathMappings = new Vector JavaDoc();
133
134     /**
135      * Set to yes if the context is loaded, set to no if the context
136      * should be ignored upon startup.
137      */

138     private String JavaDoc active = "y";
139
140     /**
141      * When set to true, it will direct controllers to redirect to secured
142      * states when transferring to a state. Otherwise, this will be ignored.
143      */

144     private String JavaDoc useSSL = "n";
145
146     /**
147      * Used for getting the proper message bundles for this context
148      */

149     private String JavaDoc language = "en";
150
151     /**
152      * Used for getting the proper message bundles for this context
153      */

154     private String JavaDoc country = "US";
155
156     /**
157      * What subdirectory of the expresso distribution that Expresso sits in.
158      */

159     private String JavaDoc expressoDir = "expresso";
160
161     /**
162      *
163      */

164     private Vector JavaDoc setupDefaults = new Vector JavaDoc();
165
166     /**
167      * minimum password length for users.
168      */

169     private String JavaDoc minPasswordSize = "6";
170
171     /**
172      * Stylesheet to use with this context.
173      */

174     private String JavaDoc styleSheet = null;
175
176     /**
177      * Is email address used for the login name in this context?
178      */

179     private String JavaDoc useEmailAsLogin = "n";
180
181     public ConfigContext() {
182     }
183
184     public void setUseEmailAsLogin(String JavaDoc newUse) {
185         StringUtil.assertBoolean(newUse, "You must specify a boolean value");
186         useEmailAsLogin = newUse;
187     }
188
189     public boolean useEmailAsLogin() {
190         return StringUtil.toBoolean(useEmailAsLogin);
191     }
192
193     public void setStyleSheet(String JavaDoc newSheet) {
194         styleSheet = newSheet;
195     }
196
197     public String JavaDoc getStyleSheet() {
198         return styleSheet;
199     }
200
201     public void setMinPasswordSize(String JavaDoc newSize) {
202         minPasswordSize = newSize;
203     }
204
205     public String JavaDoc getMinPasswordSize() {
206         return minPasswordSize;
207     }
208
209     public Vector JavaDoc getSetupDefaults() {
210         return setupDefaults;
211     }
212
213     public void addSetupDefault(ConfigSetupDefault newDefault) {
214         setupDefaults.addElement(newDefault);
215     }
216
217     public Vector JavaDoc getCustomProperties() {
218         return new Vector JavaDoc(customProperties.entrySet());
219     }
220
221     /**
222      * @return property value, or null if not found
223      */

224     public String JavaDoc getCustomProperty(String JavaDoc customPropertyName) {
225         String JavaDoc result = null;
226         ConfigCustomProperty prop =
227                 (ConfigCustomProperty) customProperties.get(customPropertyName);
228         if (prop != null) {
229             result = prop.getValue();
230         }
231
232         return result;
233     }
234
235     public void addJdbc(ConfigJdbc newJdbc) {
236         myJdbc = newJdbc;
237     }
238
239     public void addPathMapping(ConfigPathMapping newPathMapping) {
240         pathMappings.addElement(newPathMapping);
241     }
242
243     public Vector JavaDoc getPathMappings() {
244         return pathMappings;
245     }
246
247     public void addLdap(ConfigLdap newLdap) {
248         myLdap = newLdap;
249     }
250
251     public void setExpressoDir(String JavaDoc newDir) {
252         StringUtil.assertNotBlank(newDir, "You must specify a directory");
253         expressoDir = newDir;
254     }
255
256     public String JavaDoc getExpressoDir() {
257         return ConfigManager.expandValue(expressoDir);
258     }
259
260     public void setLanguage(String JavaDoc newLang) {
261         language = newLang;
262     }
263
264     public String JavaDoc getLanguage() {
265         return language;
266     }
267
268     public void setCountry(String JavaDoc newCountry) {
269         country = newCountry;
270     }
271
272     public String JavaDoc getCountry() {
273         return country;
274     }
275
276     public void setActive(String JavaDoc newActive) {
277         StringUtil.assertBoolean(newActive, "You must specify a boolean value");
278         active = newActive;
279     }
280
281     public void setActive(boolean newValue) {
282         active = Boolean.toString(newValue);
283     }
284
285     public void setUseSSL(String JavaDoc newValue) {
286         StringUtil.assertBoolean(newValue, "You must specify a boolean value");
287         useSSL = newValue;
288     }
289
290     public void setUseSSL(boolean newValue) {
291         useSSL = Boolean.toString(newValue);
292     }
293
294     public boolean isActive() {
295         return StringUtil.toBoolean(active);
296     }
297
298     public boolean isUseSSL() {
299         return StringUtil.toBoolean(useSSL);
300     }
301
302     public void addTypeMapping(ConfigTypeMapping newMapping) {
303         typeMappings.addElement(newMapping);
304     }
305
306     public Vector JavaDoc getTypeMappings() {
307         return typeMappings;
308     }
309
310     public ConfigJdbc getJdbc() {
311         return myJdbc;
312     }
313
314     public ConfigLdap getLdap() {
315         return myLdap;
316     }
317
318     public void addCustomProperty(ConfigCustomProperty newCustom) {
319         customProperties.put(newCustom.getName(), newCustom);
320     }
321
322     public void setStartJobHandler(String JavaDoc newJobHandler) {
323         StringUtil.assertBoolean(newJobHandler,
324                 "You must specify a boolean value");
325         startJobHandler = newJobHandler;
326     }
327
328     public boolean startJobHandler() {
329         return StringUtil.toBoolean(startJobHandler);
330     }
331
332     public void setShowStackTrace(String JavaDoc newStackTrace) {
333         StringUtil.assertBoolean(newStackTrace,
334                 "You must specify a boolean value");
335         showStackTrace = newStackTrace;
336     }
337
338     public boolean showStackTrace() {
339         return StringUtil.toBoolean(showStackTrace);
340     }
341
342     public void setMailDebug(String JavaDoc newMailDebug) {
343         StringUtil.assertBoolean(newMailDebug,
344                 "You must specify a boolean value");
345         mailDebug = newMailDebug;
346     }
347
348     public boolean mailDebug() {
349         return StringUtil.toBoolean(mailDebug);
350     }
351
352     public void setName(String JavaDoc newName) {
353         StringUtil.assertNotBlank(newName, "You must specify a name");
354         name = newName;
355     }
356
357     public String JavaDoc getName() {
358         return name;
359     }
360
361     public void setDescription(String JavaDoc newDescrip) {
362         StringUtil.assertNotBlank(newDescrip, "You must specify a description");
363         description = newDescrip;
364     }
365
366     public String JavaDoc getDescription() {
367         return description;
368     }
369
370     public void setImages(String JavaDoc newImages) {
371         StringUtil.assertNotBlank(newImages,
372                 "You may not specify an empty location");
373         images = newImages;
374     }
375
376     public String JavaDoc getImages() {
377         return ConfigManager.expandValue(images);
378     }
379
380     public void setHasSetupTables(String JavaDoc newHasSetup) {
381         StringUtil.assertBoolean(newHasSetup,
382                 "You must specify a boolean value");
383         hasSetupTables = newHasSetup;
384     }
385
386     public boolean hasSetupTables() {
387         return StringUtil.toBoolean(hasSetupTables);
388     }
389 }
390
Popular Tags