KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > util > TriggerBean


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.util;
18
19 import java.text.ParseException JavaDoc;
20 import java.util.Calendar JavaDoc;
21 import java.util.GregorianCalendar JavaDoc;
22
23 import org.springframework.scheduling.quartz.SimpleTriggerBean;
24
25 /**
26  * Extended trigger bean to allow the setting of first firing
27  * using hours past midnight and minutes past the hour.
28  * <p>
29  * The default start time for the trigger will be next midnight
30  * after the bean is initialised. The <code>delay</code> property
31  * can still be used as an offset from this time.
32  *
33  * @author Derek Hulley
34  */

35 public class TriggerBean extends SimpleTriggerBean
36 {
37     private static final long serialVersionUID = 6526305743899044951L;
38
39     private int hour = 0;
40     private int minute = 0;
41
42     /**
43      * @param hour the hour in the day: 0 - 23.
44      */

45     public void setHour(int hour)
46     {
47         this.hour = hour;
48     }
49     
50     /**
51      * @param minute the minute in the hour: 0 - 59.
52      */

53     public void setMinute(int minute)
54     {
55         this.minute = minute;
56     }
57     
58     @Override JavaDoc
59     public void afterPropertiesSet() throws ParseException JavaDoc
60     {
61         // set the start time
62
Calendar JavaDoc calendar = new GregorianCalendar JavaDoc();
63         calendar.setLenient(true);
64         int year = calendar.get(Calendar.YEAR);
65         int month = calendar.get(Calendar.MONTH);
66         int day = calendar.get(Calendar.DAY_OF_MONTH);
67         int nowHour = calendar.get(Calendar.HOUR_OF_DAY);
68         int nowMinute = calendar.get(Calendar.MINUTE);
69         
70         // advance the day if the hour and minute are behind the current
71
if (hour < nowHour || (hour == nowHour && minute <= nowMinute))
72         {
73             calendar.set(Calendar.DAY_OF_MONTH, day + 1);
74         }
75         // set the hour and minute
76
calendar.set(Calendar.HOUR_OF_DAY, hour);
77         calendar.set(Calendar.MINUTE, minute);
78         // set the bean start time
79
setStartTime(calendar.getTime());
80         
81         // now do the default start
82
super.afterPropertiesSet();
83     }
84 }
85
Popular Tags