001: /* ====================================================================
002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003: *
004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by Jcorporate Ltd.
021: * (http://www.jcorporate.com/)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. "Jcorporate" and product names such as "Expresso" must
026: * not be used to endorse or promote products derived from this
027: * software without prior written permission. For written permission,
028: * please contact info@jcorporate.com.
029: *
030: * 5. Products derived from this software may not be called "Expresso",
031: * or other Jcorporate product names; nor may "Expresso" or other
032: * Jcorporate product names appear in their name, without prior
033: * written permission of Jcorporate Ltd.
034: *
035: * 6. No product derived from this software may compete in the same
036: * market space, i.e. framework, without prior written permission
037: * of Jcorporate Ltd. For written permission, please contact
038: * partners@jcorporate.com.
039: *
040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051: * SUCH DAMAGE.
052: * ====================================================================
053: *
054: * This software consists of voluntary contributions made by many
055: * individuals on behalf of the Jcorporate Ltd. Contributions back
056: * to the project(s) are encouraged when you make modifications.
057: * Please send them to support@jcorporate.com. For more information
058: * on Jcorporate Ltd. and its products, please see
059: * <http://www.jcorporate.com/>.
060: *
061: * Portions of this software are based upon other open source
062: * products and are subject to their respective licenses.
063: */
064:
065: package com.jcorporate.expresso.ext.controller;
066:
067: import com.jcorporate.expresso.core.ExpressoSchema;
068: import com.jcorporate.expresso.core.controller.Block;
069: import com.jcorporate.expresso.core.controller.Controller;
070: import com.jcorporate.expresso.core.controller.ControllerException;
071: import com.jcorporate.expresso.core.controller.ControllerInstallLog;
072: import com.jcorporate.expresso.core.controller.ControllerRequest;
073: import com.jcorporate.expresso.core.controller.ControllerResponse;
074: import com.jcorporate.expresso.core.controller.DBController;
075: import com.jcorporate.expresso.core.controller.ErrorCollection;
076: import com.jcorporate.expresso.core.controller.Input;
077: import com.jcorporate.expresso.core.controller.NonHandleableException;
078: import com.jcorporate.expresso.core.controller.Output;
079: import com.jcorporate.expresso.core.controller.State;
080: import com.jcorporate.expresso.core.controller.Transition;
081: import com.jcorporate.expresso.core.dataobjects.Securable;
082: import com.jcorporate.expresso.core.db.DBException;
083: import com.jcorporate.expresso.core.db.exception.DBRecordNotFoundException;
084: import com.jcorporate.expresso.core.dbobj.DBObject;
085: import com.jcorporate.expresso.core.dbobj.Schema;
086: import com.jcorporate.expresso.core.dbobj.SchemaFactory;
087: import com.jcorporate.expresso.core.job.Job;
088: import com.jcorporate.expresso.core.misc.ConfigManager;
089: import com.jcorporate.expresso.core.misc.StringUtil;
090: import com.jcorporate.expresso.core.utility.DBTool;
091: import com.jcorporate.expresso.services.dbobj.SchemaList;
092: import com.jcorporate.expresso.services.test.SchemaCreator;
093: import com.jcorporate.expresso.services.test.SchemaDeleter;
094: import org.apache.log4j.Logger;
095:
096: import java.util.ArrayList;
097: import java.util.Enumeration;
098: import java.util.Hashtable;
099: import java.util.Iterator;
100: import java.util.Vector;
101:
102: /**
103: * <p>Component Manager Controller</p>
104: * <p>Description: The Expresso Framework</p>
105: * <p>Copyright: Copyright (c) 2001-2002</p>
106: * <p>Company: JCorporate Ltd.</p>
107: * <p>Component Manager is a short application to assist in the addition and
108: * removal of various Expresso-based components in an easy-to-use interface</p>
109: * <p>The version that ships with Expresso 5.0 is marked <b>Experimental</b> and
110: * should not be used in a production environment unless your data has first been
111: * backed up.</p>
112: * <p>Also note that the removal of a component also deletes the underlying
113: * tables and their associated data. Be sure to export any tables' data before
114: * removing a component</p>
115: *
116: * @author Michael Rimov
117: * @since Expresso 5.0
118: */
119:
120: public class ComponentManager extends DBController {
121: private static Logger log = Logger
122: .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",
146: "Verify Installation Of All Components");
147: this .addState(s);
148:
149: this .setInitialState("list");
150: this
151: .setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
152: }
153:
154: /**
155: * Returns the title of this controller
156: *
157: * @return java.lang.String
158: */
159: public String getTitle() {
160: return "Expresso Component Manager";
161: }
162:
163: /**
164: * Lists the currently installed Schemas
165: *
166: * @param request The <code>ControllerRequest</code> object handed down
167: * by the base controller class.
168: * @param response The <code>ControllerResponse</code> object that is filled
169: * out by this function.
170: * @return <code>ControllerResponse</code> object.
171: * @throws ControllerException upon error
172: * @throws NonHandleableException upon fatal error
173: */
174: protected ControllerResponse runListState(
175: ControllerRequest request, ControllerResponse response)
176: throws ControllerException, NonHandleableException {
177:
178: try {
179: SchemaList sl = new SchemaList(request);
180: ArrayList installedComponents = sl
181: .searchAndRetrieveList(SchemaList.FLD_SCHEMA_CLASS);
182:
183: response.setTitle("Currently Installed Components");
184: Block installedBlock = new Block("installedComponents");
185: response.add(installedBlock);
186: installedBlock.setAttribute("header-row",
187: "Mark|Component|Version");
188: for (Iterator i = installedComponents.iterator(); i
189: .hasNext();) {
190: Block oneRow = new Block("oneRow");
191: installedBlock.add(oneRow);
192: SchemaList oneItem = (SchemaList) i.next();
193: String className = oneItem
194: .getField(SchemaList.FLD_SCHEMA_CLASS);
195: Input mark = new Input("mark_" + className, "Mark");
196: mark.setAttribute("checkBox", "Y");
197: oneRow.add(mark);
198:
199: oneRow.add(new Output("className", className));
200: oneRow.add(new Output("name", oneItem
201: .getField(SchemaList.FLD_DESCRIP)));
202: oneRow.add(new Output("version", oneItem
203: .getField(SchemaList.FLD_VERSION_NUMBER)));
204:
205: Transition details = new Transition("details", oneItem
206: .getField(SchemaList.FLD_DESCRIP),
207: ComponentManager.class, "componentDetails");
208: details.addParam("componentClass", className);
209: oneRow.add(details);
210: }
211:
212: Transition add = new Transition();
213: add.setControllerObject(ComponentManager.class);
214: add.setName("add");
215: add.setState("promptAdd");
216: add.setLabel("Add New Component");
217: response.add(add);
218:
219: Transition delete = new Transition();
220: delete.setControllerObject(ComponentManager.class);
221: delete.setName("delete");
222: delete.setState("promptDelete");
223: delete.setLabel("Delete Components");
224: response.add(delete);
225:
226: return response;
227: } catch (DBException ex) {
228: throw new ControllerException(
229: "Database Exception listing installed components",
230: ex);
231: }
232: }
233:
234: /**
235: * @param request The <code>ControllerRequest</code> object handed down
236: * by the base controller class.
237: * @param response The <code>ControllerResponse</code> object that is filled
238: * out by this function.
239: * @return <code>ControllerResponse</code> object.
240: * @throws ControllerException upon error
241: * @throws NonHandleableException upon fatal error
242: */
243: protected ControllerResponse runPromptAddState(
244: ControllerRequest request, ControllerResponse response)
245: throws ControllerException, NonHandleableException {
246:
247: response.setTitle("Add Expresso Component");
248: response
249: .add(new Output(
250: "instructions",
251: "Enter the classname of the component you wish to install and press 'Install Component'"));
252:
253: Input className = new Input("componentClass",
254: "Component Class Name");
255: String defaultVal = request.getParameter("componentClass");
256: if (defaultVal != null && defaultVal.length() > 0) {
257: className.setDefaultValue(defaultVal);
258: }
259:
260: className.setMaxLength(256);
261: className.setDisplayLength(50);
262: response.add(className);
263:
264: Transition add = new Transition();
265: add.setControllerObject(ComponentManager.class);
266: add.setName("processAdd");
267: add.setState("processAdd");
268: add.setLabel("Install Component");
269: response.add(add);
270:
271: addBackLink(response);
272: return response;
273: }
274:
275: /**
276: * @param request The <code>ControllerRequest</code> object handed down
277: * by the base controller class.
278: * @param response The <code>ControllerResponse</code> object that is filled
279: * out by this function.
280: * @return <code>ControllerResponse</code> object.
281: * @throws ControllerException upon error
282: * @throws NonHandleableException upon fatal error
283: */
284: protected ControllerResponse runProcessAddState(
285: ControllerRequest request, ControllerResponse response)
286: throws ControllerException, NonHandleableException {
287:
288: response.setTitle("Component Installation Results");
289: String className = request.getParameter("componentClass");
290: ErrorCollection ec = checkClassName(request, className);
291:
292: if (isSchemaInstalled(request, response, className)) {
293: ec
294: .addError("Class: " + className
295: + " is already installed");
296: }
297:
298: if (ec.getErrorCount() > 0) {
299: transition("promptAdd", request, response);
300: response.saveErrors(ec);
301:
302: return response;
303: }
304:
305: SchemaCreator sc = new SchemaCreator();
306: sc.setDataContext(request.getDataContext());
307: SchemaFactory sf = SchemaFactory.getInstance();
308: sf.setDataContext(request.getDataContext());
309: sf.setRequestingUser(request.getUid());
310: Block installBlock = new Block("installBlock");
311: response.add(installBlock);
312:
313: ControllerInstallLog installLog = new ControllerInstallLog(
314: response);
315: installLog.setParentBlock(installBlock);
316:
317: try {
318: SchemaCreator.ensureSchemaExists(sf.getSchema(className),
319: installLog);
320: } catch (Throwable ex) {
321: ec.addError("Error processing schema addition");
322: // ec.addError(ex.getMessage());
323: log.error("Error creating schema: ", ex);
324: installLog.error("Error creating schema: ", ex);
325: }
326:
327: if (ec.getErrorCount() > 0) {
328: response.saveErrors(ec);
329: }
330:
331: if (ec.getErrorCount() == 0) {
332: response.add(new Output("results",
333: "Installation of schema: " + className
334: + " successfull"));
335: } else {
336: response
337: .add(new Output("results",
338: "Installation of schema: " + className
339: + " failed"));
340: }
341: addBackLink(response);
342: return response;
343: }
344:
345: /**
346: * Lists the details of a particular schema component.
347: *
348: * @param request The <code>ControllerRequest</code> object handed down
349: * by the base controller class.
350: * @param response The <code>ControllerResponse</code> object that is filled
351: * out by this function.
352: * @return <code>ControllerResponse</code> object.
353: * @throws ControllerException upon error
354: * @throws NonHandleableException upon fatal error
355: */
356: protected ControllerResponse runComponentDetailsState(
357: ControllerRequest request, ControllerResponse response)
358: throws ControllerException, NonHandleableException {
359:
360: response.setTitle("Component Details");
361: String className = request.getParameter("componentClass");
362: ErrorCollection ec = checkClassName(request, className);
363:
364: if (ec.getErrorCount() > 0) {
365: transition("list", request, response);
366: }
367:
368: try {
369: SchemaList sl = new SchemaList(request);
370: sl.setField(SchemaList.FLD_SCHEMA_CLASS, className);
371: sl.retrieve();
372:
373: Block basicInformation = new Block("basicInfo");
374: SchemaFactory sf = SchemaFactory.getInstance();
375: Schema oneSchema = sf.getSchema(className);
376:
377: basicInformation.add(new Output("schemaClass", oneSchema
378: .getClass().getName()));
379: basicInformation.add(new Output("description", sl
380: .getField(SchemaList.FLD_DESCRIP)));
381: basicInformation.add(new Output("schemaVersion", oneSchema
382: .getVersion()));
383: basicInformation.add(new Output("componentCode", sl
384: .getField(SchemaList.FLD_COMPONENT_CODE)));
385: response.add(basicInformation);
386:
387: Block dbobjects = new Block("dbobjects");
388: for (Enumeration e = oneSchema.getMembers(); e
389: .hasMoreElements();) {
390: DBObject oneObj = (DBObject) e.nextElement();
391: dbobjects.add(new Output("onedbobj", oneObj.getClass()
392: .getName()));
393: }
394: response.add(dbobjects);
395:
396: Block controllers = new Block("controllers");
397: for (Iterator e = oneSchema.getControllerList().iterator(); e
398: .hasNext();) {
399: Controller oneObj = (Controller) e.next();
400: controllers.add(new Output("oneController", oneObj
401: .getClass().getName()));
402: }
403: response.add(controllers);
404:
405: Block jobs = new Block("jobs");
406: for (Enumeration e = oneSchema.getJobs(); e
407: .hasMoreElements();) {
408: Job oneObj = (Job) e.nextElement();
409: jobs.add(new Output("onejob", oneObj.getClass()
410: .getName()));
411: }
412: response.add(jobs);
413:
414: } catch (DBException ex) {
415: log.error("Error getting schema info: ", ex);
416: ec.addError("Error getting schema information: "
417: + ex.getMessage());
418: }
419:
420: addBackLink(response);
421: return response;
422: }
423:
424: /**
425: * @param request The <code>ControllerRequest</code> object handed down
426: * by the base controller class.
427: * @param response The <code>ControllerResponse</code> object that is filled
428: * out by this function.
429: * @return <code>ControllerResponse</code> object.
430: * @throws ControllerException upon error
431: * @throws NonHandleableException upon fatal error
432: */
433: protected ControllerResponse runPromptDeleteState(
434: ControllerRequest request, ControllerResponse response)
435: throws ControllerException, NonHandleableException {
436: response.setTitle("Confirm Delete");
437: Block schemas = new Block("deleteSchemas");
438: ArrayList al = parseMarkedClassNames(request, response);
439: for (Iterator i = al.iterator(); i.hasNext();) {
440: String oneClassName = (String) i.next();
441: Input input = new Input();
442: input.setLabel(oneClassName);
443: input.setName("mark_" + oneClassName);
444: schemas.add(input);
445: }
446: response.add(schemas);
447:
448: Transition delete = new Transition("delete",
449: "Delete Listed Components", ComponentManager.class,
450: "processDelete");
451: response.add(delete);
452:
453: addBackLink(response);
454: return response;
455: }
456:
457: /**
458: * @param request The <code>ControllerRequest</code> object handed down
459: * by the base controller class.
460: * @param response The <code>ControllerResponse</code> object that is filled
461: * out by this function.
462: * @throws ControllerException upon error
463: * @throws NonHandleableException upon fatal error
464: */
465: protected void runVerifyInstallState(ControllerRequest request,
466: ControllerResponse response) throws ControllerException,
467: NonHandleableException {
468: String dbContext = StringUtil.notNull(request
469: .getParameter("dbContext"));
470:
471: try {
472: ExpressoSchema jc = (ExpressoSchema) SchemaFactory
473: .getInstance()
474: .getSchema(
475: com.jcorporate.expresso.core.ExpressoSchema.class
476: .getName());
477:
478: if (jc == null) {
479: throw new ControllerException(
480: "Unable to construct Expresso Schema. Check logs for details");
481: }
482:
483: response.setTitle("Verification Result");
484: Vector allSchemas = new Vector(5);
485: allSchemas.addElement(jc);
486:
487: SchemaList sl = null;
488: SchemaList oneSchema = null;
489: boolean noOtherSchemas = true;
490:
491: try {
492: sl = new SchemaList(Securable.SYSTEM_ACCOUNT);
493: sl.setDataContext(dbContext);
494: sl.search();
495:
496: if (sl.getFoundCount() > 0) {
497: noOtherSchemas = false;
498: }
499: } catch (DBException de) {
500: noOtherSchemas = true;
501: }
502: if (!noOtherSchemas) {
503: for (Iterator e = sl.searchAndRetrieveList().iterator(); e
504: .hasNext();) {
505: oneSchema = (SchemaList) e.next();
506:
507: boolean schemaWarning = false;
508:
509: Schema mySchema2 = SchemaFactory.getInstance()
510: .getSchema(
511: oneSchema.getField("SchemaClass"));
512:
513: if (mySchema2 == null) {
514: schemaWarning = true;
515: } else {
516: allSchemas.addElement(mySchema2);
517: }
518:
519: if (schemaWarning) {
520: response
521: .add(new Output(
522: "Warning: Unable to process schema "
523: + oneSchema
524: .getField("SchemaClass")
525: + " - see log for details"));
526: }
527: } /* for each registered schema in this db */
528:
529: } /* if we read other schemas */
530:
531: response.add(new Output(response
532: .getString("Processing_initializations")));
533: ControllerInstallLog installLog = new ControllerInstallLog(
534: response);
535:
536: DBTool.createTables(installLog, allSchemas, dbContext);
537: DBTool.compareTables(installLog, allSchemas, dbContext);
538:
539: //
540: //Setting up security goes before setting up default values.
541: //
542: DBTool.setupSecurity(installLog, allSchemas, dbContext);
543: DBTool.populateTables(installLog, allSchemas, dbContext);
544:
545: DBTool.otherSetups(installLog, allSchemas, dbContext);
546:
547: response.add(new Output(response
548: .getString("All_functions_complete")));
549:
550: //Now that things are created, let's try initializing again.
551: ConfigManager.initializeAllDBObjects();
552: ConfigManager.mapOtherDBs();
553: addBackLink(response);
554: } catch (Exception de) {
555: log.error("Error performing database verification", de);
556: throw new ControllerException(
557: "There was an error verifying database configuration",
558: de);
559: }
560:
561: }
562:
563: protected ArrayList parseMarkedClassNames(
564: ControllerRequest request, ControllerResponse response)
565: throws ControllerException {
566: ArrayList returnList = new ArrayList();
567:
568: Hashtable allParams = request.getParameters();
569:
570: for (Iterator i = allParams.keySet().iterator(); i.hasNext();) {
571: String oneParam = (String) i.next();
572: if (oneParam.startsWith("mark_")) {
573: String oneClassName = oneParam.substring(5);
574: returnList.add(oneClassName);
575: }
576: }
577:
578: return returnList;
579: }
580:
581: /**
582: * @param request The <code>ControllerRequest</code> object handed down
583: * by the base controller class.
584: * @param response The <code>ControllerResponse</code> object that is filled
585: * out by this function.
586: * @return <code>ControllerResponse</code> object.
587: * @throws ControllerException upon error
588: * @throws NonHandleableException upon fatal error
589: */
590: protected ControllerResponse runProcessDeleteState(
591: ControllerRequest request, ControllerResponse response)
592: throws ControllerException, NonHandleableException {
593:
594: response.setTitle("Component Deletion Results");
595:
596: ArrayList classNames = this .parseMarkedClassNames(request,
597: response);
598:
599: ErrorCollection allErrors = new ErrorCollection();
600: for (Iterator i = classNames.iterator(); i.hasNext();) {
601: String className = (String) i.next();
602: ErrorCollection ec = checkClassName(request, className);
603:
604: if (allErrors.getErrorCount() > 0) {
605: for (int j = 0; j < ec.getErrorStrings().length; j++) {
606: String s = ec.getErrorStrings()[j];
607: allErrors.addError(s);
608: }
609: }
610: }
611:
612: if (allErrors.getErrorCount() > 0) {
613: response.saveErrors(allErrors);
614: transition("promptDelete", request, response);
615: return response;
616: }
617:
618: SchemaFactory sf = SchemaFactory.getInstance();
619:
620: for (Iterator i = classNames.iterator(); i.hasNext();) {
621: String className = (String) i.next();
622: Schema s = sf.getSchema(className);
623:
624: SchemaDeleter.deleteSchema(request.getDataContext(), s);
625: }
626:
627: Block deletedSchemas = new Block("deletedSchemas");
628: for (Iterator i = classNames.iterator(); i.hasNext();) {
629: String className = (String) i.next();
630: deletedSchemas.add(new Output("Deletion of schema: "
631: + className + " successfull"));
632: }
633: response.add(deletedSchemas);
634: addBackLink(response);
635: return response;
636: }
637:
638: /**
639: * Adds a transition that links back to the start page of the controller
640: *
641: * @param response The <code>ControllerResponse</code> object that is filled
642: * out by this function.
643: * @throws ControllerException upon error
644: */
645: private void addBackLink(ControllerResponse response)
646: throws ControllerException {
647: Transition backLink = new Transition();
648: backLink.setState("list");
649: backLink.setName("backLink");
650: backLink.setLabel("List Components");
651: backLink.setControllerObject(ComponentManager.class);
652: response.add(backLink);
653: }
654:
655: /**
656: * Helper function that attempts to load a class and adds an error to the
657: * ErrorCollection if we're unable to load the class.
658: *
659: * @param request The <code>ControllerRequest</code> object handed down
660: * by the base controller class.
661: * @param className The name of the class to try to load.
662: * @return an instantiated ErrorCollection. If there was an error loading
663: * the class, then the ErrorCollection will have the specified error in it.
664: * @throws ControllerException upon other unforeseen errors.
665: */
666: private ErrorCollection checkClassName(ControllerRequest request,
667: String className) throws ControllerException {
668:
669: ErrorCollection ec = request.getErrorCollection();
670: if (ec == null) {
671: ec = new ErrorCollection();
672: }
673:
674: try {
675: if (className == null || className.length() == 0) {
676: log.error("Error: component classname was blank.");
677: ec.addError("Error: component classname was blank.");
678: } else if (className
679: .equalsIgnoreCase(com.jcorporate.expresso.core.ExpressoSchema.class
680: .getName())) {
681: ec.addError("You cannot add or delete ExpressoSchema");
682: } else {
683: ClassLoader cl = this .getClass().getClassLoader();
684: if (cl == null) {
685: Class.forName(className).newInstance();
686: } else {
687: cl.loadClass(className).newInstance();
688: }
689:
690: }
691: } catch (java.lang.NoClassDefFoundError ex) {
692: log.error("Error attempting to load class. " + className,
693: ex);
694: ec
695: .addError("Can't find class: "
696: + className
697: + " doesn't appear to "
698: + "be in the system's classpath, or there could be a typo in what you've entered");
699:
700: } catch (ClassCastException ex) {
701: log.error("Error attempting to load class. " + className,
702: ex);
703: ec
704: .addError("Class "
705: + className
706: + " is a valid class, but does not"
707: + " appear to derive from com.jcorporate.expresso.core.dbobj.Schema");
708: } catch (Exception e) {
709: log
710: .error("Error attempting to load class: "
711: + className, e);
712: ec
713: .addError("There was an error loading the class specified: "
714: + className);
715: }
716:
717: return ec;
718:
719: }
720:
721: /**
722: * Helper function that returns true if the schema does exist in the SchemaList
723: *
724: * @param request The <code>ControllerRequest</code> object handed down
725: * by the base controller class.
726: * @param response The <code>ControllerResponse</code> object that is filled
727: * out by this function.
728: * @param className The name of the class to try to load.
729: * @return <b>true</b> if the schema classname is found in the SchemaList
730: */
731: boolean isSchemaInstalled(ControllerRequest request,
732: ControllerResponse response, String className) {
733: try {
734: SchemaList sl = new SchemaList(request);
735: sl.setField(SchemaList.FLD_SCHEMA_CLASS, className);
736: try {
737: sl.retrieve();
738: return true;
739: } catch (DBRecordNotFoundException ex) {
740: log.error("Error attempting to load class. "
741: + className, ex);
742: return false;
743: }
744: } catch (DBException ex) {
745: log.error("Error attempting to load class. " + className,
746: ex);
747: return false;
748: }
749:
750: }
751:
752: }
|