1 16 17 package org.springframework.scheduling.quartz; 18 19 import org.quartz.Job; 20 import org.quartz.SchedulerException; 21 import org.quartz.spi.JobFactory; 22 import org.quartz.spi.TriggerFiredBundle; 23 24 33 public class AdaptableJobFactory implements JobFactory { 34 35 public Job newJob(TriggerFiredBundle bundle) throws SchedulerException { 36 try { 37 Object jobObject = createJobInstance(bundle); 38 return adaptJob(jobObject); 39 } 40 catch (Exception ex) { 41 throw new SchedulerException("Job instantiation failed", ex); 42 } 43 } 44 45 53 protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { 54 return bundle.getJobDetail().getJobClass().newInstance(); 55 } 56 57 66 protected Job adaptJob(Object jobObject) throws Exception { 67 if (jobObject instanceof Job) { 68 return (Job) jobObject; 69 } 70 else if (jobObject instanceof Runnable ) { 71 return new DelegatingJob((Runnable ) jobObject); 72 } 73 else { 74 throw new IllegalArgumentException ("Unable to execute job class [" + jobObject.getClass().getName() + 75 "]: only [org.quartz.Job] and [java.lang.Runnable] supported."); 76 } 77 } 78 79 } 80 | Popular Tags |