KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > job > Job


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.job;
66
67 import com.jcorporate.expresso.core.ExpressoSchema;
68 import com.jcorporate.expresso.core.db.DBException;
69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
70 import com.jcorporate.expresso.core.i18n.Messages;
71 import com.jcorporate.expresso.core.misc.EMailSender;
72 import com.jcorporate.expresso.core.misc.EventHandler;
73 import com.jcorporate.expresso.core.misc.StringUtil;
74 import com.jcorporate.expresso.core.registry.ExpressoThread;
75 import com.jcorporate.expresso.core.security.User;
76 import com.jcorporate.expresso.kernel.util.ClassLocator;
77 import com.jcorporate.expresso.kernel.util.FastStringBuffer;
78 import com.jcorporate.expresso.services.crontab.CrontabEntry;
79 import com.jcorporate.expresso.services.dbobj.Event;
80 import com.jcorporate.expresso.services.dbobj.JobQueue;
81 import com.jcorporate.expresso.services.dbobj.JobQueueParam;
82 import com.jcorporate.expresso.services.dbobj.Setup;
83 import org.apache.log4j.Logger;
84
85 import java.util.Enumeration JavaDoc;
86 import java.util.HashMap JavaDoc;
87 import java.util.Hashtable JavaDoc;
88 import java.util.Iterator JavaDoc;
89 import java.util.List JavaDoc;
90 import java.util.Map JavaDoc;
91 import java.util.StringTokenizer JavaDoc;
92 import java.util.Vector JavaDoc;
93
94 /**
95  * A Job is an asynchronous task who's results will generally be emailed to
96  * the user initiating the job. Jobs themselves are executed by JobHandler, and
97  * are also capable of getting queued in such a way as to repeatedly execute.
98  *
99  * Important: from Expresso 5.6, threadlocal datamembers are expected to hold User ID and
100  * data context. Therefore, any subclass of Job should set this information
101  * at the beginning of run() by calling, in the subclass, super.run(); as the first line
102  * of the subclass run() method.
103  *
104  * @author Michael Nash
105  * @see com.jcorporate.expresso.core.utility.JobHandler
106  * @since Expresso 1.0
107  */

108 public abstract class Job
109         extends ExpressoThread {
110
111     /**
112      * The associated job weueue
113      */

114     private JobQueue myJobQueue = null;
115
116     /**
117      * The user that launched the job
118      */

119     private String JavaDoc myUser = null;
120
121     /**
122      * The job number
123      */

124     private String JavaDoc myJobNumber = null;
125
126     /**
127      *
128      */

129     private Hashtable JavaDoc myFunctions = new Hashtable JavaDoc();
130
131     /**
132      * names of Job Parameters--not values, just name + description
133      */

134     private Hashtable JavaDoc myParameterNames = new Hashtable JavaDoc();
135
136     /**
137      * Job Parameter valid values
138      */

139     private Hashtable JavaDoc myParamValidValues = new Hashtable JavaDoc();
140
141     /**
142      * number of parameters received with this job
143      */

144     private int m_jobParamsNum = -1;
145
146     /**
147      * All job parameters in a list format
148      */

149     private List JavaDoc m_jobParamsEntries = null;
150
151     /**
152      * VALUES of parameters
153      * map of job parameters that can be accessed through
154      * get jobParameter(String) function.
155      * Built only on demand
156      */

157     private Map JavaDoc jobParameterValueMap = null;
158
159     /**
160      * The log4j Logger
161      */

162     protected static Logger log = Logger.getLogger(Job.class);
163
164     /**
165      * Schema associated with the job
166      */

167     private String JavaDoc mySchema = null;
168
169     /**
170      * Is the Crontab being used
171      */

172     private boolean m_useCron = false;
173
174     /**
175      * The cron alarm entry (usually Crontab entry)
176      */

177     private CrontabEntry m_cronAlarmEntry = null;
178
179
180     /**
181      * Key for if we should notify the user on a successful job.
182      */

183     public static final String JavaDoc IS_NOTIFY_ON_JOB_SUCCESS = "isNotifyOnJobSuccess";
184
185     /**
186      * Default Constructor
187      */

188     public Job() {
189         this.setDaemon(true);
190     } /* Job() */
191
192
193     /**
194      * If a job can do more than one distinct function, it registers
195      * those functions so that the administration controller can
196      * tell the user about them.
197      *
198      * @param name the name of the function
199      * @param descrip the function description
200      */

201     protected void addFunction(String JavaDoc name, String JavaDoc descrip) {
202         myFunctions.put(name, descrip);
203     } /* addFunction(String, String) */
204
205     /**
206      * If a job will be executed in cron process - say it
207      *
208      * @param useCron true if this job will be executed in cron process
209      */

210     public void setUseCron(boolean useCron) {
211         m_useCron = useCron;
212     }
213
214     /**
215      * Sets the cron alarm entry
216      *
217      * @param obj the cron alarm entry
218      */

219     public void setCronAlarmEntry(CrontabEntry obj) {
220         m_cronAlarmEntry = obj;
221     }
222
223     /**
224      * Retrieve the cron alarm entry
225      *
226      * @return Object
227      */

228     public CrontabEntry getCronAlarmEntry() {
229         return m_cronAlarmEntry;
230     }
231
232     /**
233      * Should we use Crontab?
234      *
235      * @return true if set
236      */

237     public boolean useCron() {
238         return m_useCron;
239     }
240
241     /**
242      * Add a parameter
243      *
244      * @param paramCode the actual parameter code, similar to the parameter
245      * code for a controller.
246      * @param paramDescrip The "user friendly" name of the description.
247      */

248     protected void addParameter(String JavaDoc paramCode, String JavaDoc paramDescrip) {
249         myParameterNames.put(paramCode, paramDescrip);
250     } /* addParameter(String, String) */
251
252     /**
253      * Adds a list of valid values for the particular parmeters. Will be
254      * automatically be picked up by the controller that generically launches
255      * any jobs.
256      *
257      * @param paramCode the parameter code
258      * @param paramValidValues Vector of valid value objects
259      */

260     public void addParamValidValues(String JavaDoc paramCode, Vector JavaDoc paramValidValues) {
261         myParamValidValues.put(paramCode, paramValidValues);
262     } /* addParamValidValues(String, Vector) */
263
264     /**
265      * Finish up the Job, clearing the job queue entry, sending a completion email,
266      * flush the queues, etc
267      *
268      * @param msg the message to send to the queuing user
269      */

270     protected void finish(String JavaDoc msg) {
271         finish(msg, null);
272     } /* finish(String) */
273
274     /**
275      * Finish up the Job, clearing the job queue entry, sending a completion email,
276      * flush the queues, etc
277      *
278      * @param msg the message to send to the queuing user
279      * @param t The Exception to log in the message
280      */

281     protected void finish(String JavaDoc msg, Throwable JavaDoc t) {
282         log.info("Finishing job");
283
284         FastStringBuffer mailmsg = new FastStringBuffer(64);
285         mailmsg.append(msg + "\n");
286
287         boolean success = true;
288
289         try {
290             String JavaDoc dbName = "default";
291             JobQueue jq = getJobQueueEntry();
292
293             if (jq == null) {
294                 mailmsg.append("Job '" + getClass().getName() +
295                         "' has no job queue entry available\n");
296                 success = false;
297             } else {
298
299                 //
300
//We don't set to completion jobs that are in the crontab and repetitive
301
//
302
if (StringUtil.notNull(jq.getField(JobQueue.FLD_JOBCRON_PARAMS)).length() == 0) {
303                     jq.setField("StatusCode", JobQueue.JOB_STATUS_COMPLETED);
304                     jq.update();
305                     dbName = jq.getDataContext();
306                 } else if (this.getCronAlarmEntry() != null
307                         && this.getCronAlarmEntry().isIsRepetitive() == false) {
308                     jq.setField("StatusCode", JobQueue.JOB_STATUS_COMPLETED);
309                     jq.update();
310                     dbName = jq.getDataContext();
311                 }
312             }
313
314             User u = new User();
315             u.setDataContext(dbName);
316
317             u.setUid(jq.getField("ExpUid"));
318
319             if (!u.find()) {
320                 mailmsg.append("Unable to locate user '" +
321                         jq.getField("ExpUid") + "' to notify them " +
322                         " of job completion in database '" +
323                         jq.getDataContext() + "'");
324                 success = false;
325             }
326
327             if (t != null) {
328                 log.error("Job " + jq.getField("JobNumber") +
329                         " failed in db '" + jq.getDataContext() + "'", t);
330                 mailmsg.append("Job '" + getClass().getName() + "' Failed. " +
331                         " Job Number :" + getJobNumber() +
332                         " from User '" + getUser() + "'");
333                 success = false;
334             }
335
336             if (success) {
337                 // we only notify on success if there is a special setup value set to true
338
String JavaDoc isNotify = Setup.getValueUnrequired(getDataContext(), IS_NOTIFY_ON_JOB_SUCCESS);
339                 if (StringUtil.toBoolean(isNotify)) {
340                     log.debug("Notifying user " + u.getUid() +
341                             " that job completed successfully");
342                     mailmsg.append("Job " + jq.getField("JobNumber") +
343                             " Completed");
344                     u.notify("Job " + jq.getField("JobNumber") + " Completed",
345                             mailmsg.toString());
346                 }
347             } else {
348                 new Event(dbName, "SYSERROR", mailmsg.toString(), success);
349             }
350             EventHandler.flush();
351         } catch (Exception JavaDoc de) {
352             de.printStackTrace(System.err);
353             log.error("Error finishing job:", de);
354         }
355     } /* finish(String, Exception) */
356
357     /**
358      * Retrieve the functions the Job Handler can execute
359      *
360      * @return Hashtable
361      */

362     public Hashtable JavaDoc getFunctions() {
363         return (Hashtable JavaDoc) myFunctions.clone();
364     } /* getFunctions() */
365
366     /**
367      * Return the jobnumber of this job
368      *
369      * @return String
370      */

371     public String JavaDoc getJobNumber() {
372         return myJobNumber;
373     } /* getJobNumber() */
374
375     /**
376      * Return the job queue entry that caused this job to begin
377      *
378      * @return JobQueue A JobQueue object
379      * @throws DBException If the object cannot be returned
380      */

381     public JobQueue getJobQueueEntry()
382             throws DBException {
383         if (myJobQueue == null) {
384             throw new DBException("Job queue entry not initialized");
385         }
386
387         return myJobQueue;
388     } /* getJobQueueEntry() */
389
390     /**
391      * Retreive all parameters
392      *
393      * @return hashtable of parameters
394      */

395     public Hashtable JavaDoc getParameterNamesAndDescriptions() {
396         return (Hashtable JavaDoc) myParameterNames.clone();
397     } /* getParameters() */
398
399     /**
400      * Get the value of a specified parameter
401      *
402      * @param paramName the parameter name
403      * @return java.lang.String the parameter value or null
404      */

405     public String JavaDoc getParameterDescription(String JavaDoc paramName) {
406         return (String JavaDoc) myParameterNames.get(paramName);
407     }
408
409     /**
410      * Retrieve all valid values for the given parameter
411      *
412      * @param paramCode the parameter name
413      * @return a vector of valid value objects
414      */

415     public Vector JavaDoc getParamValidValues(String JavaDoc paramCode) {
416         return (Vector JavaDoc) myParamValidValues.get(paramCode);
417     } /* getParamValidValues(String) */
418
419     /**
420      * Retrieve the title of the job. Override in your own job for a descriptive
421      * entry
422      *
423      * @return java.lang.String
424      */

425     public String JavaDoc getTitle() {
426         return ("No Title");
427     } /* getTitle() */
428
429     /**
430      * Return the username who requested this job
431      *
432      * @return String
433      */

434     public String JavaDoc getUser() {
435         return myUser;
436     } /* getUser() */
437
438     /**
439      * Implementors of this class must override this to return true if they are
440      * multi-threaded, e.g. can be run at the same time as other jobs.
441      *
442      * @return boolean True if this job can be run in parallel with other jobs
443      */

444     public boolean multiThreaded() {
445         return false;
446     } /* multiThreaded() */
447
448     /**
449      * Implement the actual logic for this server object
450      */

451     public void run() {
452         super.run();
453     }
454
455     /**
456      * Send an e-mail message to a list of recipients
457      *
458      * @param subject Subject of the message
459      * @param myRecipients Recipients of the message
460      * @param mailMessage Contents of the message, as strings in a vector
461      */

462     protected synchronized void sendMail(String JavaDoc subject, String JavaDoc myRecipients,
463                                          Vector JavaDoc mailMessage) {
464         log.info("Sending e-mail '" + subject + "' to user(s):" +
465                 myRecipients);
466
467         Enumeration JavaDoc e = mailMessage.elements();
468         String JavaDoc bigString = ("");
469
470         while (e.hasMoreElements()) {
471             bigString = bigString + (String JavaDoc) e.nextElement() + "\n";
472         }
473         try {
474             String JavaDoc oneRecipient = ("");
475             StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(myRecipients, ";");
476
477             while (stk.hasMoreTokens()) {
478                 oneRecipient = stk.nextToken();
479
480                 EMailSender ems = new EMailSender();
481                 ems.setDBName(getDataContext());
482                 ems.send(oneRecipient, subject, bigString);
483             }
484         } catch (Exception JavaDoc ie) {
485             log.error("Error sending mail", ie);
486         }
487     } /* sendMail(String, String, Vector) */
488
489     /**
490      * Set the JobQueue object that created this job. Called by the
491      * server when the job is launched, so we have this information available.
492      *
493      * @param newJobQueue JobQueue object that triggered this job
494      */

495     public synchronized void setQueue(JobQueue newJobQueue) {
496         myJobQueue = newJobQueue;
497
498         try {
499             myUser = myJobQueue.getField("ExpUid");
500             myJobNumber = myJobQueue.getField("JobNumber");
501         } catch (DBException de) {
502             myUser = ("Unknown:" + de.getMessage());
503             myJobNumber = ("Unknown:" + de.getMessage());
504         }
505     } /* setQueue(JobQueue) */
506
507     /**
508      * Retrieve the data context of the job
509      *
510      * @return java.lang.String
511      */

512     protected String JavaDoc getDataContext() throws DBException {
513         return getJobQueueEntry().getDataContext();
514     }
515
516     /**
517      * Tell this Job object what Schema it belongs to. This is used
518      * when the Job tries to use it's "getString(String, Object[])"
519      * method to prepare internationalized messages - it passes the call
520      * along to the appropriate schema which knows how to locate the
521      * proper message file.
522      *
523      * @param schemaClass the schema class name
524      */

525     protected void setSchema(String JavaDoc schemaClass) {
526         StringUtil.assertNotBlank(schemaClass, "Cannot set blank schema");
527         mySchema = schemaClass;
528     } /* setSchema(String) */
529
530     /**
531      * Getstring without any substitution capabilities
532      *
533      * @param stringCode the string code.
534      * @return java.lang.String
535      * @see com.jcorporate.expresso.core.i18n.Messages#getString
536      */

537     protected String JavaDoc getString(String JavaDoc stringCode) {
538         Object JavaDoc[] args = {};
539
540         return getString(stringCode, args);
541     } /* getString(String) */
542
543     /**
544      * Internationalization methods.
545      *
546      * @param stringCode the string code to look up in the messages bundle
547      * @param arg1 Formatting argument
548      * @return java.lang.String the expanded value
549      * @throws IllegalArgumentException if the stringCode cannot be found in
550      * the schema's message bundle.
551      * @see com.jcorporate.expresso.core.i18n.Messages#getString
552      */

553     protected String JavaDoc getString(String JavaDoc stringCode, String JavaDoc arg1) {
554         Object JavaDoc[] args = {arg1};
555
556         return getString(stringCode, args);
557     }
558
559     /**
560      * Internationalization methods.
561      *
562      * @param stringCode the string code to look up in the messages bundle
563      * @param arg1 Formatting argument
564      * @param arg2 Formatting argument
565      * @return java.lang.String the expanded value
566      * @throws IllegalArgumentException if the stringCode cannot be found in
567      * the schema's message bundle.
568      * @see com.jcorporate.expresso.core.i18n.Messages#getString
569      */

570     protected String JavaDoc getString(String JavaDoc stringCode, String JavaDoc arg1, String JavaDoc arg2) {
571         Object JavaDoc[] args = {arg1, arg2};
572
573         return getString(stringCode, args);
574     }
575
576     /**
577      * Internationalization methods.
578      *
579      * @param stringCode the string code to look up in the messages bundle
580      * @param arg1 Formatting argument
581      * @param arg2 Formatting argument
582      * @param arg3 Formatting argument
583      * @return java.lang.String the expanded value
584      * @throws IllegalArgumentException if the stringCode cannot be found in
585      * the schema's message bundle.
586      * @see com.jcorporate.expresso.core.i18n.Messages#getString
587      */

588     protected String JavaDoc getString(String JavaDoc stringCode, String JavaDoc arg1, String JavaDoc arg2,
589                                String JavaDoc arg3) {
590         Object JavaDoc[] args = {arg1, arg2, arg3};
591
592         return getString(stringCode, args);
593     }
594
595     /**
596      * Internationalization methods.
597      *
598      * @param stringCode the string code to look up in the messages bundle
599      * @param arg1 Formatting argument
600      * @param arg2 Formatting argument
601      * @param arg3 Formatting argument
602      * @param arg4 Formatting argument
603      * @return java.lang.String the expanded value
604      * @throws IllegalArgumentException if the stringCode cannot be found in
605      * the schema's message bundle.
606      * @see com.jcorporate.expresso.core.i18n.Messages#getString
607      */

608     protected String JavaDoc getString(String JavaDoc stringCode, String JavaDoc arg1, String JavaDoc arg2,
609                                String JavaDoc arg3, String JavaDoc arg4) {
610         Object JavaDoc[] args = {arg1, arg2, arg3, arg4};
611
612         return getString(stringCode, args);
613     }
614
615     /**
616      * Pass on a call to retrieve an appropriate localized string from the
617      * correct Schema object. This is a convenience method that can be used
618      * within Job objects to save having to build a long call to the
619      * static methods in the Messages object.
620      *
621      * @param stringCode the string code to look up in the messages bundle
622      * @param args the formatting object array
623      * @return java.lang.String the expanded value
624      * @throws IllegalArgumentException if the stringCode cannot be found in
625      * the schema's message bundle.
626      */

627     protected String JavaDoc getString(String JavaDoc stringCode, Object JavaDoc[] args) {
628         if (mySchema == null) {
629             setSchema(ExpressoSchema.class.getName());
630         }
631         try {
632             JobQueue jq = myJobQueue;
633
634             if (jq != null) {
635                 return Messages.getStringForUser(getJobQueueEntry().getFieldInt("ExpUid"),
636                         getJobQueueEntry().getDataContext(), mySchema,
637                         stringCode, args);
638             } else {
639                 return Messages.getString(mySchema, stringCode, args);
640             }
641         } catch (DBException de) {
642             log.error(de);
643
644             return "Unable to retrieve string:" + de.getMessage();
645         }
646     } /* getString(String, Object[]) */
647
648     /**
649      * Does this job have parameters?
650      *
651      * @return true if it does.
652      * @throws DBException upon error
653      */

654     protected boolean hasParameters()
655             throws DBException {
656         if (m_jobParamsNum == -1) {
657             JobQueueParam jqp = new JobQueueParam(SecuredDBObject.SYSTEM_ACCOUNT);
658             jqp.setDataContext(getDataContext());
659             jqp.setField(JobQueueParam.FLD_JOB_NUMBER, getJobNumber());
660             m_jobParamsEntries = jqp.searchAndRetrieveList();
661             m_jobParamsNum = m_jobParamsEntries.size();
662         }
663
664         return (m_jobParamsNum > 0);
665     }
666
667     /**
668      * Returns a List of the parameters given to the job
669      *
670      * @return A List of the parameters or null if there are no parameters
671      * for the job.
672      * @throws DBException upon error
673      */

674     protected List JavaDoc getJobParameterList()
675             throws DBException {
676         List JavaDoc ret = null;
677
678         if (hasParameters()) {
679             ret = m_jobParamsEntries;
680         }
681
682         return ret;
683     }
684
685     /**
686      * Convenience method to get the job parameters one by one as needed.
687      *
688      * @param paramCode to retrieve.
689      * @return The string of the param value, or null if no such named parameter
690      * exists.
691      * @throws DBException if there's an error reading the values.
692      */

693     protected String JavaDoc getJobParameter(String JavaDoc paramCode)
694             throws DBException {
695         if (paramCode == null) {
696             return null;
697         }
698
699         if (this.jobParameterValueMap == null) {
700             if (hasParameters()) {
701                 List JavaDoc v = this.getJobParameterList();
702                 jobParameterValueMap = new HashMap JavaDoc(v.size());
703
704                 //Build the parameter hashtable.
705
for (Iterator JavaDoc i = v.iterator(); i.hasNext();) {
706                     JobQueueParam param = (JobQueueParam) i.next();
707                     jobParameterValueMap.put(param.getField(JobQueueParam.FLD_PARAM_CODE),
708                             param.getField(JobQueueParam.FLD_PARAM_VALUE));
709                 }
710             } else {
711                 return null; // no params to find
712
}
713         }
714
715         return (String JavaDoc) jobParameterValueMap.get(paramCode);
716     }
717
718     /**
719      * Instantiate & return the schema class given in the current parameter
720      * BUG BUG: This function isn't right, what was the intention: -MR
721      *
722      * @param schemaClass the schema class to set
723      * @return A Schema object instantiated from the class named by the
724      * 'SchemaClass' parameter
725      */

726     protected String JavaDoc getSchema(String JavaDoc schemaClass)
727             throws ServerException {
728         return mySchema;
729     } /* getSchema(String) */
730
731
732     /**
733      * Convenience method to create a Job from it's name
734      *
735      * @param className the classname to instantiate
736      * @return an instantiated Job
737      * @throws ServerException upon instantiation error
738      */

739     public synchronized static Job instantiate(String JavaDoc className)
740             throws ServerException {
741         StringUtil.assertNotBlank(className,
742                 "Job class name " +
743                 " may not be blank or null here");
744
745         try {
746             Class JavaDoc c = ClassLocator.loadClass(className);
747
748             return (Job) c.newInstance();
749         } catch (ClassNotFoundException JavaDoc cn) {
750             throw new ServerException("Job object '" + className +
751                     "' not found", cn);
752         } catch (InstantiationException JavaDoc ie) {
753             throw new ServerException("Job object '" + className +
754                     "' cannot be instantiated", ie);
755         } catch (IllegalAccessException JavaDoc iae) {
756             throw new ServerException("Illegal access loading " +
757                     "Job object '" + className + "'", iae);
758         }
759     } /* instantiate(String) */
760
761
762 } /* Job */
763
Popular Tags