1 16 17 package org.springframework.scheduling.quartz; 18 19 import org.quartz.SchedulerContext; 20 import org.quartz.spi.TriggerFiredBundle; 21 22 import org.springframework.beans.BeanWrapper; 23 import org.springframework.beans.BeanWrapperImpl; 24 import org.springframework.beans.MutablePropertyValues; 25 26 41 public class SpringBeanJobFactory extends AdaptableJobFactory implements SchedulerContextAware { 42 43 private String [] ignoredUnknownProperties; 44 45 private SchedulerContext schedulerContext; 46 47 48 56 public void setIgnoredUnknownProperties(String [] ignoredUnknownProperties) { 57 this.ignoredUnknownProperties = ignoredUnknownProperties; 58 } 59 60 public void setSchedulerContext(SchedulerContext schedulerContext) { 61 this.schedulerContext = schedulerContext; 62 } 63 64 65 69 protected Object createJobInstance(TriggerFiredBundle bundle) { 70 BeanWrapper bw = new BeanWrapperImpl(bundle.getJobDetail().getJobClass()); 71 if (isEligibleForPropertyPopulation(bw.getWrappedInstance())) { 72 MutablePropertyValues pvs = new MutablePropertyValues(); 73 if (this.schedulerContext != null) { 74 pvs.addPropertyValues(this.schedulerContext); 75 } 76 pvs.addPropertyValues(bundle.getJobDetail().getJobDataMap()); 77 pvs.addPropertyValues(bundle.getTrigger().getJobDataMap()); 78 if (this.ignoredUnknownProperties != null) { 79 for (int i = 0; i < this.ignoredUnknownProperties.length; i++) { 80 String propName = this.ignoredUnknownProperties[i]; 81 if (pvs.contains(propName) && !bw.isWritableProperty(propName)) { 82 pvs.removePropertyValue(propName); 83 } 84 } 85 bw.setPropertyValues(pvs); 86 } 87 else { 88 bw.setPropertyValues(pvs, true); 89 } 90 } 91 return bw.getWrappedInstance(); 92 } 93 94 102 protected boolean isEligibleForPropertyPopulation(Object jobObject) { 103 return (!(jobObject instanceof QuartzJobBean)); 104 } 105 106 } 107 | Popular Tags |