001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.batch;
017
018 import org.kuali.rice.kns.service.DateTimeService;
019 import org.quartz.CronTrigger;
020 import org.quartz.SimpleTrigger;
021 import org.quartz.Trigger;
022 import org.springframework.beans.factory.BeanNameAware;
023
024 public abstract class TriggerDescriptor implements BeanNameAware {
025 private String name;
026 private String group;
027 private String jobName;
028 private DateTimeService dateTimeService;
029 private boolean testMode = false;
030
031 protected abstract void completeTriggerDescription(Trigger trigger);
032
033 public Trigger getTrigger() {
034 Trigger trigger = null;
035 if (getClass().equals(SimpleTriggerDescriptor.class)) {
036 trigger = new SimpleTrigger(name, group);
037 }
038 else {
039 trigger = new CronTrigger(name, group);
040 }
041 trigger.setJobName(jobName);
042 trigger.setJobGroup(group);
043 trigger.setStartTime(dateTimeService.getCurrentDate());
044 completeTriggerDescription(trigger);
045 return trigger;
046 }
047
048 /**
049 * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
050 */
051 public void setBeanName(String name) {
052 this.name = name;
053 }
054
055 /**
056 * Sets the group attribute value.
057 *
058 * @param group The group to set.
059 */
060 public void setGroup(String group) {
061 this.group = group;
062 }
063
064 /**
065 * Sets the jobName attribute value.
066 *
067 * @param jobName The jobName to set.
068 */
069 public void setJobName(String jobName) {
070 this.jobName = jobName;
071 }
072
073 protected String getJobName() {
074 return jobName;
075 }
076
077 /**
078 * Sets the dateTimeService attribute value.
079 *
080 * @param dateTimeService The dateTimeService to set.
081 */
082 public void setDateTimeService(DateTimeService dateTimeService) {
083 this.dateTimeService = dateTimeService;
084 }
085
086 protected DateTimeService getDateTimeService() {
087 return dateTimeService;
088 }
089
090 public boolean isTestMode() {
091 return testMode;
092 }
093
094 public void setTestMode(boolean testMode) {
095 this.testMode = testMode;
096 }
097 }