KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > schedules > schedules > DayAfterSchedule


1 package org.oddjob.schedules.schedules;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Calendar JavaDoc;
5 import java.util.Date JavaDoc;
6 import java.util.GregorianCalendar JavaDoc;
7
8 import org.oddjob.schedules.AbstractSchedule;
9 import org.oddjob.schedules.DateUtils;
10 import org.oddjob.schedules.Interval;
11 import org.oddjob.schedules.ScheduleContext;
12
13 /**
14  * @oddjob.description A schedule that returns the day after when a
15  * nested schedule is due.
16  * <p>
17  * This is designed to be used for processing which happens the
18  * day after, i.e. processing previous business days data.
19  * <p>
20  * This is paticularly useful for scheduling around holidays when a process
21  * is still required to run on the holiday, but not the day after the holiday.
22  *
23  * @oddjob.example
24  *
25  * This will run at 2am tuesday to saturday.
26  *
27  * <pre>
28  * &lt;dayafter&gt;
29  * &lt;dayofmonth from="25" to="0" &gt;
30  * &lt;last&gt;
31  * &lt;dayofweek from="mon" to="fri" &gt;
32  * &lt;time on="02:00" /gt;
33  * &lt;/dayofweek&gt;
34  * &lt;/last&gth;
35  * &lt;/dayofmonth&gt;
36  * &lt;/dayafter&gt;
37  * </pre>
38  *
39  * @author Rob Gordon
40  */

41
42 final public class DayAfterSchedule extends AbstractSchedule implements Serializable JavaDoc {
43
44     private static final long serialVersionUID = 20050226;
45     
46     /*
47      * (non-Javadoc)
48      * @see org.treesched.Schedule#nextDue(java.util.Date)
49      */

50     public Interval nextDue(ScheduleContext context) {
51         Date JavaDoc now = context.getDate();
52         if (now == null) {
53             return null;
54         }
55         if (getChildSchedule() == null) {
56             throw new IllegalStateException JavaDoc("DayAfter must have a child schedule.");
57         }
58
59         Interval childInterval = getChildSchedule().nextDue(context);
60
61         Calendar JavaDoc startCal = new GregorianCalendar JavaDoc();
62         startCal.setTime(childInterval.getFromDate());
63         startCal.add(Calendar.DATE, 1);
64         Date JavaDoc dayAfterStart = startCal.getTime();
65         
66         Calendar JavaDoc endCal = new GregorianCalendar JavaDoc();
67         endCal.setTime(childInterval.getFromDate());
68         endCal.add(Calendar.DATE, 2);
69         Date JavaDoc dayAfterEnd = DateUtils.oneMillisBefore(endCal.getTime());
70         
71         Interval dayAfter = new Interval(dayAfterStart, dayAfterEnd);
72
73         return dayAfter.limit(getLimits());
74     }
75     
76     /**
77      * Override toString.
78      */

79     
80     public String JavaDoc toString() {
81         
82         return "Day After Schedule";
83     }
84 }
85
Popular Tags