1 16 17 package org.springframework.scheduling.quartz; 18 19 import java.text.ParseException ; 20 import java.util.Date ; 21 import java.util.Map ; 22 import java.util.TimeZone ; 23 24 import org.quartz.CronTrigger; 25 import org.quartz.JobDetail; 26 import org.quartz.Scheduler; 27 28 import org.springframework.beans.factory.BeanNameAware; 29 import org.springframework.beans.factory.InitializingBean; 30 import org.springframework.core.Constants; 31 32 63 public class CronTriggerBean extends CronTrigger 64 implements JobDetailAwareTrigger, BeanNameAware, InitializingBean { 65 66 67 private static final Constants constants = new Constants(CronTrigger.class); 68 69 70 private JobDetail jobDetail; 71 72 private String beanName; 73 74 75 83 public void setJobDataAsMap(Map jobDataAsMap) { 84 getJobDataMap().putAll(jobDataAsMap); 85 } 86 87 95 public void setMisfireInstructionName(String constantName) { 96 setMisfireInstruction(constants.asNumber(constantName).intValue()); 97 } 98 99 107 public void setTriggerListenerNames(String [] names) { 108 for (int i = 0; i < names.length; i++) { 109 addTriggerListener(names[i]); 110 } 111 } 112 113 121 public void setJobDetail(JobDetail jobDetail) { 122 this.jobDetail = jobDetail; 123 } 124 125 public JobDetail getJobDetail() { 126 return this.jobDetail; 127 } 128 129 public void setBeanName(String beanName) { 130 this.beanName = beanName; 131 } 132 133 134 public void afterPropertiesSet() throws ParseException { 135 if (getName() == null) { 136 setName(this.beanName); 137 } 138 if (getGroup() == null) { 139 setGroup(Scheduler.DEFAULT_GROUP); 140 } 141 if (getStartTime() == null) { 142 setStartTime(new Date ()); 143 } 144 if (getTimeZone() == null) { 145 setTimeZone(TimeZone.getDefault()); 146 } 147 if (this.jobDetail != null) { 148 setJobName(this.jobDetail.getName()); 149 setJobGroup(this.jobDetail.getGroup()); 150 } 151 } 152 153 } 154 | Popular Tags |