KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > ExpressoSchema


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 package com.jcorporate.expresso.core;
65
66 import com.jcorporate.expresso.core.db.DBException;
67 import com.jcorporate.expresso.core.dbobj.Schema;
68 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
69 import com.jcorporate.expresso.core.misc.ConfigManager;
70 import com.jcorporate.expresso.core.security.User;
71 import com.jcorporate.expresso.kernel.InstallLog;
72 import com.jcorporate.expresso.kernel.util.ClassLocator;
73 import com.jcorporate.expresso.services.dbobj.JobQueue;
74
75
76 /**
77  * Standard Schema
78  * object for the Expresso framework. It provides 'tie ins' for all the
79  * classes within the framework. You use your own Schema derived from
80  * <code>com.jcorporate.expresso.core.dbobj.Schema</code> when creating your
81  * own application
82  *
83  * @author Michael Nash
84  * @since Expresso 1.0
85  */

86 public final class ExpressoSchema extends Schema {
87     private static String JavaDoc currentVersionString = "5.6.0";
88 // private static String log4jRequiredVersion = "1.2.8";
89
// private static String xercesRequiredVersion = "XmlCommons 1.0";
90

91     /**
92      * This variable prevents multiple complex instantiations since most of the
93      * schema data is kept in a static variable anyway.
94      */

95     private static boolean isInitialized = false;
96
97     /**
98      * Constructor
99      *
100      * @throws DBException if there's an error building the object
101      */

102     public ExpressoSchema() throws DBException {
103         if (isInitialized) {
104             return;
105         }
106
107         /* Check the Log4j version */
108         try {
109             ClassLocator.loadClass("org.apache.log4j.Logger");
110         } catch (Exception JavaDoc e) {
111             System.err.println("You have an older version of log4j. " +
112                     "Please install a version greater or equal to version 1.2.1");
113         }
114
115         if (ConfigManager.isInitialized()) {
116             isInitialized = true;
117
118             try {
119                 constructDBObjects();
120                 constructControllers();
121
122                 //Add all reports belonging to the Expresso Schema
123
addReportPage(com.jcorporate.expresso.ext.report.DownloadUsers.class);
124
125                 /* Now add the Jobs in this Schema */
126                 addJob(com.jcorporate.expresso.ext.job.SendNotice.class);
127                 addJob(com.jcorporate.expresso.services.job.TestJob.class);
128                 addJob(com.jcorporate.expresso.services.job.ControllerJob.class);
129                 addJob(com.jcorporate.expresso.services.job.ValidationJob.class);
130                 addJob(com.jcorporate.expresso.services.job.ClearOldValidation.class);
131
132                 /* Now add the normal servlets */
133                 addServlet(com.jcorporate.expresso.core.servlet.Test.class);
134
135                 constructSetupValues();
136             } catch (Exception JavaDoc e) {
137                 e.printStackTrace();
138                 isInitialized = false;
139                 throw new DBException(e);
140             }
141         }
142         /* if */
143     }
144     /* ExpressoSchema() */
145
146     /**
147      * Returns the default component code for this schema. Useful for automated
148      * component testing/installation
149      *
150      * @return the component code string. In this case there is no component
151      * code so it returns an empty string.
152      */

153     public String JavaDoc getDefaultComponentCode() {
154         return "";
155     }
156
157     /**
158      * Returns the default description for this schema. Useful for automated
159      * component testing/installation
160      *
161      * @return the name of the schema
162      */

163     public String JavaDoc getDefaultDescription() {
164         return "Expresso Framework Schema";
165     }
166
167     /**
168      * Returns the path to the messages bundle property file
169      *
170      * @return the path to the messages bundle
171      */

172     public String JavaDoc getMessageBundlePath() {
173         return "com/jcorporate/expresso/core";
174     }
175     /* getMessageBundlePath() */
176
177     /**
178      * Gets the current version of this Framework
179      *
180      * @return the current version in string format
181      */

182     public String JavaDoc getVersion() {
183         return currentVersionString;
184     }
185
186     /**
187      * Runs additional setup operations for the Expresso Schema
188      *
189      * @param installLog The 'logger' to send informational output to.
190      * @param dataContext the datacontext to work with.
191      * @throws com.jcorporate.expresso.core.db.DBException
192      * upon database access
193      * error
194      */

195     public synchronized void otherSetup(InstallLog installLog,
196                                         String JavaDoc dataContext) throws com.jcorporate.expresso.core.db.DBException {
197         //Add a recurring 'Clear old validation entries job'
198
JobQueue jq = new JobQueue(SecuredDBObject.SYSTEM_ACCOUNT);
199         jq.setDataContext(dataContext);
200         jq.setField(JobQueue.FLD_JOBCODE,
201                 com.jcorporate.expresso.services.job.ClearOldValidation.class.getName());
202         if (!jq.find()) {
203
204             //Execute every Saturday at midnight
205
jq.setField(JobQueue.FLD_JOBCRON_PARAMS, "0,0,-1,-1,7,-1");
206             jq.setField(JobQueue.FLD_SERVERID, 0);
207             jq.setField(JobQueue.FLD_STATUS_CODE, JobQueue.JOB_STATUS_AVAILABLE);
208             jq.setField(JobQueue.FLD_JOBCODE,
209                     com.jcorporate.expresso.services.job.ClearOldValidation.class.
210                     getName());
211             jq.setField(JobQueue.FLD_UID, User.getAdminId(dataContext));
212             jq.add();
213             installLog.info("Added " +
214                     com.jcorporate.expresso.services.job.
215
                    ClearOldValidation.class.getName() +
216                     " to execute once a week");
217         } else {
218             installLog.info("Clear Old Validation Job already exists in jobqueue, skipping add.");
219         }
220
221         super.otherSetup(installLog, dataContext);
222     }
223
224     /**
225      * Adds the appropriate controllers to the schema
226      */

227     protected void constructControllers() {
228         /* Controllers */
229         addController(com.jcorporate.expresso.services.controller.ControllerSecurityMatrix.class);
230         addController(com.jcorporate.expresso.services.controller.QueueJob.class);
231         addController(com.jcorporate.expresso.services.controller.SimpleLoginController.class);
232         addController(com.jcorporate.expresso.services.controller.SimpleRegistration.class);
233         addController(com.jcorporate.expresso.services.controller.JobSecurityMatrix.class);
234         addController(com.jcorporate.expresso.services.controller.CacheControl.class);
235
236         // addController(com.jcorporate.expresso.ext.controller.TestController.class);
237
addController(com.jcorporate.expresso.services.controller.DBMaint.class);
238         addController(com.jcorporate.expresso.services.controller.EditUserPreference.class);
239
240         // addController(com.jcorporate.expresso.ext.controller.RunTests.class);
241
addController(com.jcorporate.expresso.ext.controller.HealthCheck.class);
242         addController(com.jcorporate.expresso.ext.controller.DataTransfer.class);
243         addController(com.jcorporate.expresso.services.controller.ValidationController.class);
244         addController(com.jcorporate.expresso.ext.controller.Download.class);
245         addController(com.jcorporate.expresso.ext.xml.controller.XMLController.class);
246         addController(com.jcorporate.expresso.ext.controller.RunSQL.class);
247         addController(com.jcorporate.expresso.services.controller.Log.class);
248         addController(com.jcorporate.expresso.services.controller.Status.class);
249         addController(com.jcorporate.expresso.services.controller.DBSecurityMatrix.class);
250
251         addController(com.jcorporate.expresso.ext.controller.Upload.class);
252         addController(com.jcorporate.expresso.ext.controller.ServeTextFile.class);
253         addController(com.jcorporate.expresso.ext.controller.ComponentManager.class);
254         addController(com.jcorporate.expresso.ext.controller.ReportServer.class);
255         addController(com.jcorporate.expresso.services.controller.CronController.class);
256
257         //
258
//Controllers for managing configuration system
259
//
260
addController(com.jcorporate.expresso.services.controller.configuration.CreateSettingsWizard.class);
261
262         addController(com.jcorporate.expresso.services.controller.Configuration.class);
263
264         addController(com.jcorporate.expresso.services.controller.configuration.UpgradeSettingsWizard.class);
265     }
266
267     /**
268      * Adds all the Expresso DbObjects
269      */

270     protected void constructDBObjects() {
271         addDBObject(com.jcorporate.expresso.services.dbobj.Event.class);
272         addDBObject(com.jcorporate.expresso.services.dbobj.EventMail.class);
273         addDBObject(com.jcorporate.expresso.services.dbobj.MimeTypes.class);
274         addDBObject(com.jcorporate.expresso.services.dbobj.DBMessage.class);
275         addDBObject(com.jcorporate.expresso.services.dbobj.DBOtherMap.class);
276         addDBObject(com.jcorporate.expresso.services.dbobj.DBObjLimit.class);
277         addDBObject(com.jcorporate.expresso.ext.dbobj.DownloadFiles.class);
278         addDBObject(com.jcorporate.expresso.services.dbobj.Setup.class);
279         addDBObject(com.jcorporate.expresso.services.dbobj.UserPreferenceVal.class);
280         addDBObject(com.jcorporate.expresso.services.dbobj.UserPreferenceDef.class);
281         addDBObject(com.jcorporate.expresso.services.dbobj.ControllerDefault.class);
282         addDBObject(com.jcorporate.expresso.ext.dbobj.ISOCountryCodes.class);
283         addDBObject(com.jcorporate.expresso.ext.dbobj.ReverseLookupDomains.class);
284
285
286         addDBObject(com.jcorporate.expresso.services.dbobj.ControllerSecurity.class);
287         addDBObject(com.jcorporate.expresso.services.dbobj.DefaultUserInfo.class);
288         addDBObject(com.jcorporate.expresso.services.dbobj.UserGroup.class);
289         addDBObject(com.jcorporate.expresso.ext.dbobj.RegisteredUser.class);
290         addDBObject(com.jcorporate.expresso.ext.dbobj.regobj.Person.class);
291         addDBObject(com.jcorporate.expresso.ext.dbobj.regobj.Phone.class);
292         addDBObject(com.jcorporate.expresso.ext.dbobj.regobj.Address.class);
293         addDBObject(com.jcorporate.expresso.ext.dbobj.regobj.Contact.class);
294         addDBObject(com.jcorporate.expresso.ext.dbobj.RestrictedCountries.class);
295         addDBObject(com.jcorporate.expresso.ext.dbobj.RestrictedOverrides.class);
296         addDBObject(com.jcorporate.expresso.services.dbobj.DBObjSecurity.class);
297         addDBObject(com.jcorporate.expresso.services.dbobj.JobSecurity.class);
298         addDBObject(com.jcorporate.expresso.services.dbobj.GroupMembers.class);
299         addDBObject(com.jcorporate.expresso.services.dbobj.GroupNest.class);
300         addDBObject(com.jcorporate.expresso.services.dbobj.RegistrationDomain.class);
301         addDBObject(com.jcorporate.expresso.services.dbobj.RegistrationObjectMap.class);
302         addDBObject(com.jcorporate.expresso.services.dbobj.RowPermissions.class);
303         addDBObject(com.jcorporate.expresso.services.dbobj.RowGroupPerms.class);
304
305         addDBObject(com.jcorporate.expresso.ext.dbobj.DownloadLog.class);
306         addDBObject(com.jcorporate.expresso.ext.dbobj.PerfTests.class);
307         addDBObject(com.jcorporate.expresso.ext.dbobj.PerfTestStat.class);
308         addDBObject(com.jcorporate.expresso.ext.dbobj.PerfTestSet.class);
309         addDBObject(com.jcorporate.expresso.ext.dbobj.PerfTestSetDet.class);
310         addDBObject(com.jcorporate.expresso.services.dbobj.JobQueue.class);
311         addDBObject(com.jcorporate.expresso.services.dbobj.JobQueueParam.class);
312         addDBObject(com.jcorporate.expresso.services.dbobj.LogEntry.class);
313         addDBObject(com.jcorporate.expresso.services.dbobj.SchemaList.class);
314         addDBObject(com.jcorporate.expresso.services.dbobj.JobHandlerRegistry.class);
315         addDBObject(com.jcorporate.expresso.services.dbobj.JobHandlerControl.class);
316         addDBObject(com.jcorporate.expresso.ext.dbobj.AppIntegration.class);
317         addDBObject(com.jcorporate.expresso.services.dbobj.ValidationQueue.class);
318         addDBObject(com.jcorporate.expresso.services.dbobj.ValidationQueueParam.class);
319         addDBObject(com.jcorporate.expresso.services.dbobj.UserPreference.class);
320         addDBObject(com.jcorporate.expresso.ext.xml.dbobj.UserAgent.class);
321         addDBObject(com.jcorporate.expresso.ext.xml.dbobj.ControllerXSLMap.class);
322
323         /** @todo this is required for AuditedSecuredDBObject to work *RD* Mon Jul 27 2004 */
324         addDBObject(com.jcorporate.expresso.ext.dbobj.AuditLog.class);
325         addDBObject(com.jcorporate.expresso.ext.dbobj.AuditLogL.class);
326
327         /** @todo this is required for change log to work *RD* Mon Jul 27 2004 */
328         addDBObject(com.jcorporate.expresso.services.dbobj.ChangeLog.class);
329
330     }
331
332     /**
333      * Adds the setup values for this schema to the schema's definition
334      *
335      * @throws DBException upon database access error
336      */

337     protected void constructSetupValues() throws DBException {
338         addSetup("DefaultXSL", "Default XSL Stylesheet",
339                 "%web-app%/expresso/xsl/default.xsl");
340         addSetup("BaseDir",
341                 getString("Web_Document_Root_Director"),
342                 getSetupDefault("BaseDir", "%web-app%"));
343         addSetup("HTTPServ",
344                 getString("Web_Server_Host_Name"),
345                 getSetupDefault("HTTPServ", "javacorp"));
346         addSetup("MAILFrom",
347                 getString("Value_for_From_field_in_Ev"),
348                 getSetupDefault("MAILFrom", "none"));
349         addSetup("MAILPassword",
350                 getString("Password_for_sending_e-mai"),
351                 getSetupDefault("MAILPassword", ""));
352         addSetup("MAILServer",
353                 getString("SMTP_Server_Name_for_sendi"),
354                 getSetupDefault("MAILServer", "example.org"));
355         addSetup("MAILUserName",
356                 getString("User_Name_for_sending_e-ma"),
357                 getSetupDefault("MAILUserName", ""));
358         addSetup("MaxJobs",
359                 getString("Max_Number_of_Server_Jobs_"),
360                 getSetupDefault("MaxJobs", "1"));
361         addSetup("ServletPath",
362                 getString("Default_path_for_Servlets"),
363                 getSetupDefault("ServletPath", "/servlet"));
364         addSetup("ServletPort",
365                 getString("Port_Number_for_Servlet_Se"),
366                 getSetupDefault("ServletPort", "80"));
367         addSetup("TempDir", getString("Temporary_Directory"),
368                 getSetupDefault("TempDir", "%web-app%temp/"));
369         addSetup("TimerInterval",
370                 getString("Scan_Job_Queue_and_directo"),
371                 getSetupDefault("TimerInterval", "30"));
372         addSetup("ConnTimeOut",
373                 getString("Database_Connection_Timout"),
374                 getSetupDefault("ConnTimeOut", "60"));
375         addSetup("DefaultGroup",
376                 getString("Default_User_Group_for_Sel"),
377                 getSetupDefault("DefaultGroup", "Demo"));
378         addSetup("MaxConnections",
379                 getString("Maximum_connections_to_att"),
380                 getSetupDefault("MaxConnections", "4"));
381         addSetup("MinConnections",
382                 getString("Minimum_connections_to_att"),
383                 getSetupDefault("MinConnections", "2"));
384         addSetup("MailList",
385                 getString("Mailing_List_Address"),
386                 getSetupDefault("MailList", "opensource@servlets.net"));
387         addSetup("RestartServer", getString("RestartServer"),
388                 getSetupDefault("RestartServer", ""));
389
390         // Added to better customize standard messages, such as email validations
391
addSetup("RequireEmailValidate",
392                 getString("RequireEmailValidate"),
393                 getSetupDefault("RequireEmailValidate", "N"));
394         addSetup("EmailValidateURL",
395                 getString("EmailValidateURL"),
396                 getSetupDefault("EmailValidateURL",
397                         "http://www.yourdomain.com/servlet/EmailValidation"));
398         addSetup("AdminName", getString("AdminName"),
399                 getSetupDefault("AdminName", "webmaster"));
400         addSetup("AdminEmail", getString("AdminEmail"),
401                 getSetupDefault("AdminEmail", ""));
402         addSetup("CompanyName", getString("CompanyName"),
403                 getSetupDefault("CompanyName", ""));
404         addSetup("HomePageURL", getString("HomePageURL"),
405                 getSetupDefault("HomePageURL", ""));
406         addSetup("ServletEvent", getString("ServletEvent"),
407                 getSetupDefault("ServletEvent", "Y"));
408         addSetup("ContextPath", "Context Path for Expresso",
409                 getSetupDefault("ContextPath", "%context%"));
410         addSetup("Header", "Header URL for Framesets",
411                 getSetupDefault("Header", "%context%/%expresso-dir%/header.jsp"));
412         addSetup("HeaderHeight",
413                 "Size of Header for Framesets",
414                 getSetupDefault("HeaderHeight", "73"));
415
416         addSetup("SecurityDB",
417                 "Database to use for User/Group Security Info",
418                 getSetupDefault("SecurityDB", ""));
419
420         addSetup("SecurityDBObjs",
421                 "Database Objects that use the SecurityDB db/context",
422                 getSetupDefault("SecurityDB", ""));
423
424         //
425
//This 'default' is not the same as 'default context'
426
//
427
addSetup("defaultRegDomain",
428                 "Default Registration Domain",
429                 getSetupDefault("defaultRegDomain", "default"));
430
431         addSetup("defaultCSS", "Default CSS Extension",
432                 getSetupDefault("defaultCSS", ""));
433
434         addSetup("privacyPolicy",
435                 "URL To Website Privacy Policy",
436                 getSetupDefault("privacyPolicy", ""));
437
438         addSetup("isNotifyOnJobSuccess",
439                 "Boolean flag for whether to send an e-mail notification when a job completes successfully",
440                 "N");
441
442
443         // addSetup("nativeBlob","Native Blob Types (Y/N)", "N");
444

445         addSetup("insecureDBMaint",
446                 "Allow DBMaint to Edit Unsecured DBObjects", "N");
447
448         addSetup("enableGlobalExceptions",
449                 "Allow all Expresso Controllers to pass unhandled exception to GlobalExceptions as of Struts 1.1",
450                 "N");
451
452         //Asynchronous process setup values
453
addSetup("AsyncClaimTimeout", "Claim Timeout for Asynchronous processes", "30000");
454
455         addSetup("AsyncNumThreads", "Number of aysnc handling threads", "10");
456         addSetup("AsyncQueueSize", "Size of queue for waiting async processes.", "20");
457
458     }
459 }
460
461 /* ExpressoSchema */
462
Popular Tags