KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > simpl > SimpleJobFactory


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17 package org.quartz.simpl;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.quartz.Job;
22 import org.quartz.JobDetail;
23 import org.quartz.SchedulerException;
24 import org.quartz.spi.JobFactory;
25 import org.quartz.spi.TriggerFiredBundle;
26
27 /**
28  * The default JobFactory used by Quartz - simply calls
29  * <code>newInstance()</code> on the job class.
30  *
31  * @see JobFactory
32  * @see PropertySettingJobFactory
33  *
34  * @author jhouse
35  */

36 public class SimpleJobFactory implements JobFactory {
37
38     private final Log log = LogFactory.getLog(getClass());
39     
40     protected Log getLog() {
41         return log;
42     }
43     
44     public Job newJob(TriggerFiredBundle bundle) throws SchedulerException {
45
46         JobDetail jobDetail = bundle.getJobDetail();
47         Class JavaDoc jobClass = jobDetail.getJobClass();
48         try {
49             if(log.isDebugEnabled()) {
50                 log.debug(
51                     "Producing instance of Job '" + jobDetail.getFullName() +
52                     "', class=" + jobClass.getName());
53             }
54             
55             return (Job) jobClass.newInstance();
56         } catch (Exception JavaDoc e) {
57             SchedulerException se = new SchedulerException(
58                     "Problem instantiating class '"
59                             + jobDetail.getJobClass().getName() + "'", e);
60             throw se;
61         }
62     }
63 }
Popular Tags