KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > ext > controller > ComponentManager


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.ext.controller;
66
67 import com.jcorporate.expresso.core.ExpressoSchema;
68 import com.jcorporate.expresso.core.controller.Block;
69 import com.jcorporate.expresso.core.controller.Controller;
70 import com.jcorporate.expresso.core.controller.ControllerException;
71 import com.jcorporate.expresso.core.controller.ControllerInstallLog;
72 import com.jcorporate.expresso.core.controller.ControllerRequest;
73 import com.jcorporate.expresso.core.controller.ControllerResponse;
74 import com.jcorporate.expresso.core.controller.DBController;
75 import com.jcorporate.expresso.core.controller.ErrorCollection;
76 import com.jcorporate.expresso.core.controller.Input;
77 import com.jcorporate.expresso.core.controller.NonHandleableException;
78 import com.jcorporate.expresso.core.controller.Output;
79 import com.jcorporate.expresso.core.controller.State;
80 import com.jcorporate.expresso.core.controller.Transition;
81 import com.jcorporate.expresso.core.dataobjects.Securable;
82 import com.jcorporate.expresso.core.db.DBException;
83 import com.jcorporate.expresso.core.db.exception.DBRecordNotFoundException;
84 import com.jcorporate.expresso.core.dbobj.DBObject;
85 import com.jcorporate.expresso.core.dbobj.Schema;
86 import com.jcorporate.expresso.core.dbobj.SchemaFactory;
87 import com.jcorporate.expresso.core.job.Job;
88 import com.jcorporate.expresso.core.misc.ConfigManager;
89 import com.jcorporate.expresso.core.misc.StringUtil;
90 import com.jcorporate.expresso.core.utility.DBTool;
91 import com.jcorporate.expresso.services.dbobj.SchemaList;
92 import com.jcorporate.expresso.services.test.SchemaCreator;
93 import com.jcorporate.expresso.services.test.SchemaDeleter;
94 import org.apache.log4j.Logger;
95
96 import java.util.ArrayList JavaDoc;
97 import java.util.Enumeration JavaDoc;
98 import java.util.Hashtable JavaDoc;
99 import java.util.Iterator JavaDoc;
100 import java.util.Vector JavaDoc;
101
102
103 /**
104  * <p>Component Manager Controller</p>
105  * <p>Description: The Expresso Framework</p>
106  * <p>Copyright: Copyright (c) 2001-2002</p>
107  * <p>Company: JCorporate Ltd.</p>
108  * <p>Component Manager is a short application to assist in the addition and
109  * removal of various Expresso-based components in an easy-to-use interface</p>
110  * <p>The version that ships with Expresso 5.0 is marked <b>Experimental</b> and
111  * should not be used in a production environment unless your data has first been
112  * backed up.</p>
113  * <p>Also note that the removal of a component also deletes the underlying
114  * tables and their associated data. Be sure to export any tables' data before
115  * removing a component</p>
116  *
117  * @author Michael Rimov
118  * @since Expresso 5.0
119  */

120
121 public class ComponentManager extends DBController {
122     private static Logger log = Logger.getLogger("expresso.ext.controller.ComponentManager");
123
124     public ComponentManager() {
125         State s = new State("list", "List Components");
126         this.addState(s);
127
128         s = new State("promptAdd", "Add Component");
129         this.addState(s);
130
131         s = new State("processAdd", "Process Add");
132         s.addRequiredParameter("componentClass");
133         this.addState(s);
134
135         s = new State("componentDetails", "Show Component Details");
136         s.addRequiredParameter("componentClass");
137         this.addState(s);
138
139         s = new State("promptDelete", "Prompt Delete");
140         this.addState(s);
141
142         s = new State("processDelete", "Process Schema Deletion");
143         this.addState(s);
144
145         s = new State("verifyInstall", "Verify Installation Of All Components");
146         this.addState(s);
147
148         this.setInitialState("list");
149         this.setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
150     }
151
152     /**
153      * Returns the title of this controller
154      *
155      * @return java.lang.String
156      */

157     public String JavaDoc getTitle() {
158         return "Expresso Component Manager";
159     }
160
161     /**
162      * Lists the currently installed Schemas
163      *
164      * @param request The <code>ControllerRequest</code> object handed down
165      * by the base controller class.
166      * @param response The <code>ControllerResponse</code> object that is filled
167      * out by this function.
168      * @return <code>ControllerResponse</code> object.
169      * @throws ControllerException upon error
170      * @throws NonHandleableException upon fatal error
171      */

172     protected ControllerResponse runListState(ControllerRequest request,
173                                               ControllerResponse response)
174             throws ControllerException, NonHandleableException {
175
176         try {
177             SchemaList sl = new SchemaList(request);
178             ArrayList JavaDoc installedComponents = sl.searchAndRetrieveList(SchemaList.FLD_SCHEMA_CLASS);
179
180             response.setTitle("Currently Installed Components");
181             Block installedBlock = new Block("installedComponents");
182             response.add(installedBlock);
183             installedBlock.setAttribute("header-row", "Mark|Component|Version");
184             for (Iterator JavaDoc i = installedComponents.iterator(); i.hasNext();) {
185                 Block oneRow = new Block("oneRow");
186                 installedBlock.add(oneRow);
187                 SchemaList oneItem = (SchemaList) i.next();
188                 String JavaDoc className = oneItem.getField(SchemaList.FLD_SCHEMA_CLASS);
189                 Input mark = new Input("mark_" + className, "Mark");
190                 mark.setAttribute("checkBox", "Y");
191                 oneRow.add(mark);
192
193                 oneRow.add(new Output("className", className));
194                 oneRow.add(new Output("name", oneItem.getField(SchemaList.FLD_DESCRIP)));
195                 oneRow.add(new Output("version", oneItem.getField(SchemaList.FLD_VERSION_NUMBER)));
196
197                 Transition details = new Transition("details",
198                         oneItem.getField(SchemaList.FLD_DESCRIP),
199                         ComponentManager.class,
200                         "componentDetails");
201                 details.addParam("componentClass", className);
202                 oneRow.add(details);
203             }
204
205             Transition add = new Transition();
206             add.setControllerObject(ComponentManager.class);
207             add.setName("add");
208             add.setState("promptAdd");
209             add.setLabel("Add New Component");
210             response.add(add);
211
212
213             Transition delete = new Transition();
214             delete.setControllerObject(ComponentManager.class);
215             delete.setName("delete");
216             delete.setState("promptDelete");
217             delete.setLabel("Delete Components");
218             response.add(delete);
219
220
221             return response;
222         } catch (DBException ex) {
223             throw new ControllerException("Database Exception listing installed components", ex);
224         }
225     }
226
227
228     /**
229      * @param request The <code>ControllerRequest</code> object handed down
230      * by the base controller class.
231      * @param response The <code>ControllerResponse</code> object that is filled
232      * out by this function.
233      * @return <code>ControllerResponse</code> object.
234      * @throws ControllerException upon error
235      * @throws NonHandleableException upon fatal error
236      */

237     protected ControllerResponse runPromptAddState(ControllerRequest request,
238                                                    ControllerResponse response)
239             throws ControllerException, NonHandleableException {
240
241         response.setTitle("Add Expresso Component");
242         response.add(new Output("instructions",
243                 "Enter the classname of the component you wish to install and press 'Install Component'"));
244
245         Input className = new Input("componentClass", "Component Class Name");
246         String JavaDoc defaultVal = request.getParameter("componentClass");
247         if (defaultVal != null && defaultVal.length() > 0) {
248             className.setDefaultValue(defaultVal);
249         }
250
251         className.setMaxLength(256);
252         className.setDisplayLength(50);
253         response.add(className);
254
255         Transition add = new Transition();
256         add.setControllerObject(ComponentManager.class);
257         add.setName("processAdd");
258         add.setState("processAdd");
259         add.setLabel("Install Component");
260         response.add(add);
261
262
263         addBackLink(response);
264         return response;
265     }
266
267     /**
268      * @param request The <code>ControllerRequest</code> object handed down
269      * by the base controller class.
270      * @param response The <code>ControllerResponse</code> object that is filled
271      * out by this function.
272      * @return <code>ControllerResponse</code> object.
273      * @throws ControllerException upon error
274      * @throws NonHandleableException upon fatal error
275      */

276     protected ControllerResponse runProcessAddState(ControllerRequest request,
277                                                     ControllerResponse response)
278             throws ControllerException, NonHandleableException {
279
280         response.setTitle("Component Installation Results");
281         String JavaDoc className = request.getParameter("componentClass");
282         ErrorCollection ec = checkClassName(request, className);
283
284         if (isSchemaInstalled(request, response, className)) {
285             ec.addError("Class: " + className + " is already installed");
286         }
287
288         if (ec.getErrorCount() > 0) {
289             transition("promptAdd", request, response);
290             response.saveErrors(ec);
291
292             return response;
293         }
294
295         SchemaCreator sc = new SchemaCreator();
296         sc.setDataContext(request.getDataContext());
297         SchemaFactory sf = SchemaFactory.getInstance();
298         sf.setDataContext(request.getDataContext());
299         sf.setRequestingUser(request.getUid());
300         Block installBlock = new Block("installBlock");
301         response.add(installBlock);
302
303         ControllerInstallLog installLog = new ControllerInstallLog(response);
304         installLog.setParentBlock(installBlock);
305
306         try {
307             SchemaCreator.ensureSchemaExists(sf.getSchema(className), installLog);
308         } catch (Throwable JavaDoc ex) {
309             ec.addError("Error processing schema addition");
310 // ec.addError(ex.getMessage());
311
log.error("Error creating schema: ", ex);
312             installLog.error("Error creating schema: ", ex);
313         }
314
315         if (ec.getErrorCount() > 0) {
316             response.saveErrors(ec);
317         }
318
319         if (ec.getErrorCount() == 0) {
320             response.add(new Output("results", "Installation of schema: " +
321                     className + " successfull"));
322         } else {
323             response.add(new Output("results", "Installation of schema: " +
324                     className + " failed"));
325         }
326         addBackLink(response);
327         return response;
328     }
329
330     /**
331      * Lists the details of a particular schema component.
332      *
333      * @param request The <code>ControllerRequest</code> object handed down
334      * by the base controller class.
335      * @param response The <code>ControllerResponse</code> object that is filled
336      * out by this function.
337      * @return <code>ControllerResponse</code> object.
338      * @throws ControllerException upon error
339      * @throws NonHandleableException upon fatal error
340      */

341     protected ControllerResponse runComponentDetailsState(ControllerRequest request,
342                                                           ControllerResponse response)
343             throws ControllerException, NonHandleableException {
344
345         response.setTitle("Component Details");
346         String JavaDoc className = request.getParameter("componentClass");
347         ErrorCollection ec = checkClassName(request, className);
348
349         if (ec.getErrorCount() > 0) {
350             transition("list", request, response);
351         }
352
353         try {
354             SchemaList sl = new SchemaList(request);
355             sl.setField(SchemaList.FLD_SCHEMA_CLASS, className);
356             sl.retrieve();
357
358             Block basicInformation = new Block("basicInfo");
359             SchemaFactory sf = SchemaFactory.getInstance();
360             Schema oneSchema = sf.getSchema(className);
361
362             basicInformation.add(new Output("schemaClass", oneSchema.getClass().getName()));
363             basicInformation.add(new Output("description", sl.getField(SchemaList.FLD_DESCRIP)));
364             basicInformation.add(new Output("schemaVersion", oneSchema.getVersion()));
365             basicInformation.add(new Output("componentCode", sl.getField(SchemaList.FLD_COMPONENT_CODE)));
366             response.add(basicInformation);
367
368             Block dbobjects = new Block("dbobjects");
369             for (Enumeration JavaDoc e = oneSchema.getMembers(); e.hasMoreElements();) {
370                 DBObject oneObj = (DBObject) e.nextElement();
371                 dbobjects.add(new Output("onedbobj", oneObj.getClass().getName()));
372             }
373             response.add(dbobjects);
374
375             Block controllers = new Block("controllers");
376             for (Iterator JavaDoc e = oneSchema.getControllerList().iterator(); e.hasNext();) {
377                 Controller oneObj = (Controller) e.next();
378                 controllers.add(new Output("oneController", oneObj.getClass().getName()));
379             }
380             response.add(controllers);
381
382
383             Block jobs = new Block("jobs");
384             for (Enumeration JavaDoc e = oneSchema.getJobs(); e.hasMoreElements();) {
385                 Job oneObj = (Job) e.nextElement();
386                 jobs.add(new Output("onejob", oneObj.getClass().getName()));
387             }
388             response.add(jobs);
389
390         } catch (DBException ex) {
391             log.error("Error getting schema info: ", ex);
392             ec.addError("Error getting schema information: " + ex.getMessage());
393         }
394
395
396         addBackLink(response);
397         return response;
398     }
399
400     /**
401      * @param request The <code>ControllerRequest</code> object handed down
402      * by the base controller class.
403      * @param response The <code>ControllerResponse</code> object that is filled
404      * out by this function.
405      * @return <code>ControllerResponse</code> object.
406      * @throws ControllerException upon error
407      * @throws NonHandleableException upon fatal error
408      */

409     protected ControllerResponse runPromptDeleteState(ControllerRequest request,
410                                                       ControllerResponse response)
411             throws ControllerException, NonHandleableException {
412         response.setTitle("Confirm Delete");
413         Block schemas = new Block("deleteSchemas");
414         ArrayList JavaDoc al = parseMarkedClassNames(request, response);
415         for (Iterator JavaDoc i = al.iterator(); i.hasNext();) {
416             String JavaDoc oneClassName = (String JavaDoc) i.next();
417             Input input = new Input();
418             input.setLabel(oneClassName);
419             input.setName("mark_" + oneClassName);
420             schemas.add(input);
421         }
422         response.add(schemas);
423
424         Transition delete = new Transition("delete",
425                 "Delete Listed Components",
426                 ComponentManager.class,
427                 "processDelete");
428         response.add(delete);
429
430         addBackLink(response);
431         return response;
432     }
433
434
435     /**
436      * @param request The <code>ControllerRequest</code> object handed down
437      * by the base controller class.
438      * @param response The <code>ControllerResponse</code> object that is filled
439      * out by this function.
440      * @throws ControllerException upon error
441      * @throws NonHandleableException upon fatal error
442      */

443     protected void runVerifyInstallState(ControllerRequest request,
444                                          ControllerResponse response)
445             throws ControllerException, NonHandleableException {
446         String JavaDoc dbContext = StringUtil.notNull(request.getParameter("dbContext"));
447
448         try {
449             ExpressoSchema jc = (ExpressoSchema) SchemaFactory.getInstance()
450                     .getSchema(com.jcorporate.expresso
451
                    .core.ExpressoSchema.class.getName());
452
453             if (jc == null) {
454                 throw new ControllerException("Unable to construct Expresso Schema. Check logs for details");
455             }
456
457             response.setTitle("Verification Result");
458             Vector JavaDoc allSchemas = new Vector JavaDoc(5);
459             allSchemas.addElement(jc);
460
461             SchemaList sl = null;
462             SchemaList oneSchema = null;
463             boolean noOtherSchemas = true;
464
465             try {
466                 sl = new SchemaList(Securable.SYSTEM_ACCOUNT);
467                 sl.setDataContext(dbContext);
468                 sl.search();
469
470                 if (sl.getFoundCount() > 0) {
471                     noOtherSchemas = false;
472                 }
473             } catch (DBException de) {
474                 noOtherSchemas = true;
475             }
476             if (!noOtherSchemas) {
477                 for (Iterator JavaDoc e = sl.searchAndRetrieveList().iterator();
478                      e.hasNext();) {
479                     oneSchema = (SchemaList) e.next();
480
481                     boolean schemaWarning = false;
482
483                     Schema mySchema2 = SchemaFactory.getInstance()
484                             .getSchema(oneSchema.getField("SchemaClass"));
485
486                     if (mySchema2 == null) {
487                         schemaWarning = true;
488                     } else {
489                         allSchemas.addElement(mySchema2);
490                     }
491
492                     if (schemaWarning) {
493                         response.add(new Output("Warning: Unable to process schema " + oneSchema.getField(
494                                 "SchemaClass") +
495                                 " - see log for details"));
496                     }
497                 } /* for each registered schema in this db */
498
499             } /* if we read other schemas */
500
501             response.add(new Output(response.getString("Processing_initializations")));
502             ControllerInstallLog installLog = new ControllerInstallLog(response);
503
504             DBTool.createTables(installLog, allSchemas, dbContext);
505             DBTool.compareTables(installLog, allSchemas, dbContext);
506
507             //
508
//Setting up security goes before setting up default values.
509
//
510
DBTool.setupSecurity(installLog, allSchemas, dbContext);
511             DBTool.populateTables(installLog, allSchemas, dbContext);
512
513             DBTool.otherSetups(installLog, allSchemas, dbContext);
514
515             response.add(new Output(response.getString("All_functions_complete")));
516
517             //Now that things are created, let's try initializing again.
518
ConfigManager.initializeAllDBObjects();
519             ConfigManager.mapOtherDBs();
520             addBackLink(response);
521         } catch (Exception JavaDoc de) {
522             log.error("Error performing database verification", de);
523             throw new ControllerException("There was an error verifying database configuration", de);
524         }
525
526
527     }
528
529     protected ArrayList JavaDoc parseMarkedClassNames(ControllerRequest request,
530                                               ControllerResponse response) throws ControllerException {
531         ArrayList JavaDoc returnList = new ArrayList JavaDoc();
532
533         Hashtable JavaDoc allParams = request.getParameters();
534
535         for (Iterator JavaDoc i = allParams.keySet().iterator(); i.hasNext();) {
536             String JavaDoc oneParam = (String JavaDoc) i.next();
537             if (oneParam.startsWith("mark_")) {
538                 String JavaDoc oneClassName = oneParam.substring(5);
539                 returnList.add(oneClassName);
540             }
541         }
542
543         return returnList;
544     }
545
546     /**
547      * @param request The <code>ControllerRequest</code> object handed down
548      * by the base controller class.
549      * @param response The <code>ControllerResponse</code> object that is filled
550      * out by this function.
551      * @return <code>ControllerResponse</code> object.
552      * @throws ControllerException upon error
553      * @throws NonHandleableException upon fatal error
554      */

555     protected ControllerResponse runProcessDeleteState(ControllerRequest request,
556                                                        ControllerResponse response)
557             throws ControllerException, NonHandleableException {
558
559         response.setTitle("Component Deletion Results");
560
561         ArrayList JavaDoc classNames = this.parseMarkedClassNames(request, response);
562
563         ErrorCollection allErrors = new ErrorCollection();
564         for (Iterator JavaDoc i = classNames.iterator(); i.hasNext();) {
565             String JavaDoc className = (String JavaDoc) i.next();
566             ErrorCollection ec = checkClassName(request, className);
567
568             if (allErrors.getErrorCount() > 0) {
569                 for (int j = 0; j < ec.getErrorStrings().length; j++) {
570                     String JavaDoc s = ec.getErrorStrings()[j];
571                     allErrors.addError(s);
572                 }
573             }
574         }
575
576         if (allErrors.getErrorCount() > 0) {
577             response.saveErrors(allErrors);
578             transition("promptDelete", request, response);
579             return response;
580         }
581
582
583         SchemaFactory sf = SchemaFactory.getInstance();
584
585         for (Iterator JavaDoc i = classNames.iterator(); i.hasNext();) {
586             String JavaDoc className = (String JavaDoc) i.next();
587             Schema s = sf.getSchema(className);
588
589             SchemaDeleter.deleteSchema(request.getDataContext(), s);
590         }
591
592         Block deletedSchemas = new Block("deletedSchemas");
593         for (Iterator JavaDoc i = classNames.iterator(); i.hasNext();) {
594             String JavaDoc className = (String JavaDoc) i.next();
595             deletedSchemas.add(new Output("Deletion of schema: " + className +
596                     " successfull"));
597         }
598         response.add(deletedSchemas);
599         addBackLink(response);
600         return response;
601     }
602
603     /**
604      * Adds a transition that links back to the start page of the controller
605      *
606      * @param response The <code>ControllerResponse</code> object that is filled
607      * out by this function.
608      * @throws ControllerException upon error
609      */

610     private void addBackLink(ControllerResponse response)
611             throws ControllerException {
612         Transition backLink = new Transition();
613         backLink.setState("list");
614         backLink.setName("backLink");
615         backLink.setLabel("List Components");
616         backLink.setControllerObject(ComponentManager.class);
617         response.add(backLink);
618     }
619
620     /**
621      * Helper function that attempts to load a class and adds an error to the
622      * ErrorCollection if we're unable to load the class.
623      *
624      * @param request The <code>ControllerRequest</code> object handed down
625      * by the base controller class.
626      * @param className The name of the class to try to load.
627      * @return an instantiated ErrorCollection. If there was an error loading
628      * the class, then the ErrorCollection will have the specified error in it.
629      * @throws ControllerException upon other unforeseen errors.
630      */

631     private ErrorCollection checkClassName(ControllerRequest request,
632                                            String JavaDoc className)
633             throws ControllerException {
634
635
636         ErrorCollection ec = request.getErrorCollection();
637         if (ec == null) {
638             ec = new ErrorCollection();
639         }
640
641         try {
642             if (className == null || className.length() == 0) {
643                 log.error("Error: component classname was blank.");
644                 ec.addError("Error: component classname was blank.");
645             } else if (className.equalsIgnoreCase(com.jcorporate
646
                    .expresso.core.ExpressoSchema.class.getName())) {
647                 ec.addError("You cannot add or delete ExpressoSchema");
648             } else {
649                 ClassLoader JavaDoc cl = this.getClass().getClassLoader();
650                 if (cl == null) {
651                     Class.forName(className).newInstance();
652                 } else {
653                     cl.loadClass(className).newInstance();
654                 }
655
656
657             }
658         } catch (java.lang.NoClassDefFoundError JavaDoc ex) {
659             log.error("Error attempting to load class. " + className, ex);
660             ec.addError("Can't find class: " + className + " doesn't appear to " +
661                     "be in the system's classpath, or there could be a typo in what you've entered");
662
663         } catch (ClassCastException JavaDoc ex) {
664             log.error("Error attempting to load class. " + className, ex);
665             ec.addError("Class " + className + " is a valid class, but does not" +
666                     " appear to derive from com.jcorporate.expresso.core.dbobj.Schema");
667         } catch (Exception JavaDoc e) {
668             log.error("Error attempting to load class: " + className, e);
669             ec.addError("There was an error loading the class specified: " + className);
670         }
671
672         return ec;
673
674     }
675
676     /**
677      * Helper function that returns true if the schema does exist in the SchemaList
678      *
679      * @param request The <code>ControllerRequest</code> object handed down
680      * by the base controller class.
681      * @param response The <code>ControllerResponse</code> object that is filled
682      * out by this function.
683      * @param className The name of the class to try to load.
684      * @return <b>true</b> if the schema classname is found in the SchemaList
685      */

686     boolean isSchemaInstalled(ControllerRequest request,
687                               ControllerResponse response,
688                               String JavaDoc className) {
689         try {
690             SchemaList sl = new SchemaList(request);
691             sl.setField(SchemaList.FLD_SCHEMA_CLASS, className);
692             try {
693                 sl.retrieve();
694                 return true;
695             } catch (DBRecordNotFoundException ex) {
696                 log.error("Error attempting to load class. " + className, ex);
697                 return false;
698             }
699         } catch (DBException ex) {
700             log.error("Error attempting to load class. " + className, ex);
701             return false;
702         }
703
704     }
705
706 }
Popular Tags