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 23 import org.quartz.JobDetail; 24 import org.quartz.Scheduler; 25 import org.quartz.SimpleTrigger; 26 27 import org.springframework.beans.factory.BeanNameAware; 28 import org.springframework.beans.factory.InitializingBean; 29 import org.springframework.core.Constants; 30 31 62 public class SimpleTriggerBean extends SimpleTrigger 63 implements JobDetailAwareTrigger, BeanNameAware, InitializingBean { 64 65 66 private static final Constants constants = new Constants(SimpleTrigger.class); 67 68 69 private long startDelay = 0; 70 71 private JobDetail jobDetail; 72 73 private String beanName; 74 75 76 public SimpleTriggerBean() { 77 setRepeatCount(REPEAT_INDEFINITELY); 78 } 79 80 88 public void setJobDataAsMap(Map jobDataAsMap) { 89 getJobDataMap().putAll(jobDataAsMap); 90 } 91 92 103 public void setMisfireInstructionName(String constantName) { 104 setMisfireInstruction(constants.asNumber(constantName).intValue()); 105 } 106 107 115 public void setTriggerListenerNames(String [] names) { 116 for (int i = 0; i < names.length; i++) { 117 addTriggerListener(names[i]); 118 } 119 } 120 121 131 public void setStartDelay(long startDelay) { 132 this.startDelay = startDelay; 133 } 134 135 143 public void setJobDetail(JobDetail jobDetail) { 144 this.jobDetail = jobDetail; 145 } 146 147 public JobDetail getJobDetail() { 148 return this.jobDetail; 149 } 150 151 public void setBeanName(String beanName) { 152 this.beanName = beanName; 153 } 154 155 156 public void afterPropertiesSet() throws ParseException { 157 if (getName() == null) { 158 setName(this.beanName); 159 } 160 if (getGroup() == null) { 161 setGroup(Scheduler.DEFAULT_GROUP); 162 } 163 if (getStartTime() == null) { 164 setStartTime(new Date (System.currentTimeMillis() + this.startDelay)); 165 } 166 if (this.jobDetail != null) { 167 setJobName(this.jobDetail.getName()); 168 setJobGroup(this.jobDetail.getGroup()); 169 } 170 } 171 172 } 173 | Popular Tags |