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 java.text.ParseException;
019    
020    import org.quartz.CronTrigger;
021    import org.quartz.Trigger;
022    
023    public class CronTriggerDescriptor extends TriggerDescriptor {
024        private String cronExpression;
025    
026        /**
027         * @see org.kuali.kfs.sys.batch.TriggerDescriptor#completeTriggerDescription(org.quartz.Trigger)
028         */
029        protected void completeTriggerDescription(Trigger trigger) {
030            // prevent setting of the trigger information in test mode
031            try {
032                ((CronTrigger) trigger).setTimeZone(getDateTimeService().getCurrentCalendar().getTimeZone());
033                if (!isTestMode()) {
034                    ((CronTrigger) trigger).setCronExpression(cronExpression);
035                }
036                else {
037                    ((CronTrigger) trigger).setCronExpression("0 59 23 31 12 ? 2099");
038                }
039            }
040            catch (ParseException e) {
041                throw new RuntimeException("Caught exception while trying to set the cronExpression attribute of a CronTrigger: " + getJobName(), e);
042            }
043        }
044    
045        /**
046         * Sets the cronExpression attribute value.
047         * 
048         * @param cronExpression The cronExpression to set.
049         */
050        public void setCronExpression(String cronExpression) {
051            this.cronExpression = cronExpression;
052        }
053    }