1 16 17 package org.springframework.scheduling.quartz; 18 19 import java.util.Map ; 20 21 import org.quartz.Job; 22 import org.quartz.JobDetail; 23 import org.quartz.Scheduler; 24 25 import org.springframework.beans.factory.BeanNameAware; 26 import org.springframework.beans.factory.InitializingBean; 27 import org.springframework.context.ApplicationContext; 28 import org.springframework.context.ApplicationContextAware; 29 30 45 public class JobDetailBean extends JobDetail 46 implements BeanNameAware, ApplicationContextAware, InitializingBean { 47 48 private Class actualJobClass; 49 50 private String beanName; 51 52 private ApplicationContext applicationContext; 53 54 private String applicationContextJobDataKey; 55 56 57 62 public void setJobClass(Class jobClass) { 63 if (jobClass != null && !Job.class.isAssignableFrom(jobClass)) { 64 super.setJobClass(DelegatingJob.class); 65 this.actualJobClass = jobClass; 66 } 67 else { 68 super.setJobClass(jobClass); 69 } 70 } 71 72 76 public Class getJobClass() { 77 return (this.actualJobClass != null ? this.actualJobClass : super.getJobClass()); 78 } 79 80 91 public void setJobDataAsMap(Map jobDataAsMap) { 92 getJobDataMap().putAll(jobDataAsMap); 93 } 94 95 103 public void setJobListenerNames(String [] names) { 104 for (int i = 0; i < names.length; i++) { 105 addJobListener(names[i]); 106 } 107 } 108 109 public void setBeanName(String beanName) { 110 this.beanName = beanName; 111 } 112 113 public void setApplicationContext(ApplicationContext applicationContext) { 114 this.applicationContext = applicationContext; 115 } 116 117 133 public void setApplicationContextJobDataKey(String applicationContextJobDataKey) { 134 this.applicationContextJobDataKey = applicationContextJobDataKey; 135 } 136 137 138 public void afterPropertiesSet() { 139 if (getName() == null) { 140 setName(this.beanName); 141 } 142 if (getGroup() == null) { 143 setGroup(Scheduler.DEFAULT_GROUP); 144 } 145 if (this.applicationContextJobDataKey != null) { 146 if (this.applicationContext == null) { 147 throw new IllegalStateException ( 148 "JobDetailBean needs to be set up in an ApplicationContext " + 149 "to be able to handle an 'applicationContextJobDataKey'"); 150 } 151 getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext); 152 } 153 } 154 155 } 156 | Popular Tags |