View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.batch;
17  
18  import java.text.ParseException;
19  
20  import org.quartz.CronTrigger;
21  import org.quartz.Trigger;
22  
23  public class CronTriggerDescriptor extends TriggerDescriptor {
24      private String cronExpression;
25  
26      /**
27       * @see org.kuali.ole.sys.batch.TriggerDescriptor#completeTriggerDescription(org.quartz.Trigger)
28       */
29      protected void completeTriggerDescription(Trigger trigger) {
30          // prevent setting of the trigger information in test mode
31          try {
32              ((CronTrigger) trigger).setTimeZone(getDateTimeService().getCurrentCalendar().getTimeZone());
33              if (!isTestMode()) {
34                  ((CronTrigger) trigger).setCronExpression(cronExpression);
35              }
36              else {
37                  ((CronTrigger) trigger).setCronExpression("0 59 23 31 12 ? 2099");
38              }
39          }
40          catch (ParseException e) {
41              throw new RuntimeException("Caught exception while trying to set the cronExpression attribute of a CronTrigger: " + getJobName(), e);
42          }
43      }
44  
45      /**
46       * Sets the cronExpression attribute value.
47       * 
48       * @param cronExpression The cronExpression to set.
49       */
50      public void setCronExpression(String cronExpression) {
51          this.cronExpression = cronExpression;
52      }
53  }