org.oddjob.schedules.schedules
Class MonthlySchedule

java.lang.Object
  extended by org.oddjob.schedules.AbstractSchedule
      extended by org.oddjob.schedules.ConstrainedSchedule
          extended by org.oddjob.schedules.schedules.MonthlySchedule
All Implemented Interfaces:
Serializable, RefineableSchedule, Schedule

public final class MonthlySchedule
extends ConstrainedSchedule
implements Serializable

Description

A schedule for monthly intervals. The intervals can be specified as days of the month, a day of the week in a week of the month, or less usefully as weeks of the month.

The day of the month is given as an number, normally 1 to 31. 0 and negative numbers can be used to specify days from the end of the month. The words LAST and PENULTIMATE (case insensitive) can also be used as a convenience. Note that unlike the java GregorianCalander, 0 and negative numbers are taken to be this month, not the previous month. i.e. on="0" is the last day of the month and is equivalent to on="LAST".

Days and week of the month are given as the day number, 1 to 7, or as one of MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY (case insensitive). The week of the month is specified as a number, typically 1 to 5, or using one of FIRST, SECOND, THIRD, FOURTH, FIFTH, PENULTIMATE, or LAST (case insensitive).

If the week of the month is specified on it's own then the first week is taken to be the first complete week of the month.

Example

A range of days of the month.
<schedules:monthly fromDay="17" toDay="22" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
     <refinement>
        <schedules:daily at="10:00"/>
     </refinement>
</schedules:monthly>
This would schedule a job to run every day from the 17th of each month to the 25th of each month at 10am.

Example

On a single day of the month.
<schedules:monthly onDay="15" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
This will run a job on the 15th of every month.

Example

On the last Friday of the month.
<schedules:monthly onDayOfWeek="FRIDAY" inWeek="LAST" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
     <refinement>
        <schedules:time at="07:00"/>
     </refinement>
</schedules:monthly>
See Also:
Serialized Form
Author:
Rob Gordon

Constructor Summary
MonthlySchedule()
           
 
Method Summary
protected  Calendar fromCalendar(Date referenceDate, TimeZone timeZone)
          Get a calendar for the from day.
 DayOfMonth getFromDay()
           
 DayOfWeek getFromDayOfWeek()
           
 WeekOfMonth getFromWeek()
           
 DayOfMonth getToDay()
           
 DayOfWeek getToDayOfWeek()
           
 WeekOfMonth getToWeek()
           
protected  CalendarUnit intervalBetween()
          Sub classes must provide a unit which is what must be added to move the schedule on.
 void setFromDay(DayOfMonth day)
           
 void setFromDayOfWeek(DayOfWeek fromDayOfWeek)
           
 void setFromWeek(WeekOfMonth fromWeek)
           
 void setInWeek(WeekOfMonth inWeek)
           
 void setOnDay(DayOfMonth on)
           
 void setOnDayOfWeek(DayOfWeek onDayOfWeek)
           
 void setToDay(DayOfMonth to)
           
 void setToDayOfWeek(DayOfWeek toDayOfWeek)
           
 void setToWeek(WeekOfMonth toWeek)
           
protected  Calendar shiftFromCalendar(Calendar calendar, int intervals)
          Shift the from Calendar by an interval.
protected  Calendar shiftToCalendar(Calendar calendar, int intervals)
          Shift the to Calendar by an interval.
protected  Calendar toCalendar(Date referenceDate, TimeZone timeZone)
          Get a calendar for the to day.
 String toString()
          Override toString.
 
Methods inherited from class org.oddjob.schedules.ConstrainedSchedule
lastInterval, nextDue, nextInterval
 
Methods inherited from class org.oddjob.schedules.AbstractSchedule
getRefinement, setRefinement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MonthlySchedule

public MonthlySchedule()
Method Detail

setFromDay

public void setFromDay(DayOfMonth day)

Property: fromDay

Description: The from day of the month.

Required: No. Defaults to 1.

Parameters:
from - The from date.

getFromDay

public DayOfMonth getFromDay()

setToDay

public void setToDay(DayOfMonth to)

Property: toDay

Description: The to day of the month.

Required: No. Defaults to the last day of the month.

Parameters:
to - The to date.

getToDay

public DayOfMonth getToDay()

setOnDay

public void setOnDay(DayOfMonth on)

Property: onDay

Description: The day on which this schedule is for. This has the same effect as setting fromDay and toDay to the same thing.

Required: No.

Parameters:
on - The day on which this schedule is for.

getFromDayOfWeek

public DayOfWeek getFromDayOfWeek()

setFromDayOfWeek

public void setFromDayOfWeek(DayOfWeek fromDayOfWeek)

Property: fromDayOfWeek

Description: The from day of the week. Used in conjunction with fromWeekOfMonth.

Required: No.

Parameters:
from - The from date.

getToDayOfWeek

public DayOfWeek getToDayOfWeek()

setToDayOfWeek

public void setToDayOfWeek(DayOfWeek toDayOfWeek)

Property: toDayOfWeek

Description: The to day of the week. Used in conjunction with toDayOfWeek.

Required: No.

Parameters:
from - The from date.

setOnDayOfWeek

public void setOnDayOfWeek(DayOfWeek onDayOfWeek)

Property: onDayOfWeek

Description: The on day of the week. This is equivalent to setting fromDayOfWeek and toDayOfWeek to the same thing.

Required: No.

Parameters:
from - The from date.

getFromWeek

public WeekOfMonth getFromWeek()

setFromWeek

public void setFromWeek(WeekOfMonth fromWeek)

Property: fromWeek

Description: The from week of the month.

Required: No.

Parameters:
from - The from date.

getToWeek

public WeekOfMonth getToWeek()

setToWeek

public void setToWeek(WeekOfMonth toWeek)

Property: toWeek

Description: The to week of the month.

Required: No.

Parameters:
from - The from date.

setInWeek

public void setInWeek(WeekOfMonth inWeek)

Property: inWeek

Description: The in week of the month. This is equivalent to setting fromWeek and toWeek to the same thing.

Required: No.

Parameters:
from - The from date.

intervalBetween

protected CalendarUnit intervalBetween()
Description copied from class: ConstrainedSchedule
Sub classes must provide a unit which is what must be added to move the schedule on. I.e. the equivalent of a day, week, month etc.

Specified by:
intervalBetween in class ConstrainedSchedule
Returns:

fromCalendar

protected Calendar fromCalendar(Date referenceDate,
                                TimeZone timeZone)
Get a calendar for the from day.

Specified by:
fromCalendar in class ConstrainedSchedule
Parameters:
referenceDate - The date to get month, year info from.
timeZone - The time zone.
Returns:
A calendar.

toCalendar

protected Calendar toCalendar(Date referenceDate,
                              TimeZone timeZone)
Get a calendar for the to day.

Specified by:
toCalendar in class ConstrainedSchedule
Parameters:
referenceDate - The date to get month, yar info from.
timeZone - The time zone.
Returns:
A calendar.

shiftFromCalendar

protected Calendar shiftFromCalendar(Calendar calendar,
                                     int intervals)
Description copied from class: ConstrainedSchedule
Shift the from Calendar by an interval. The subclass fromCalendar is used to re-adjust the shifted calendar. This is needed in at least these situations:

shiftToCalendar

protected Calendar shiftToCalendar(Calendar calendar,
                                   int intervals)
Description copied from class: ConstrainedSchedule
Shift the to Calendar by an interval. The subclass toCalendar is used to re-adjust the shifted calendar for the reasons given in ConstrainedSchedule.shiftFromCalendar(Calendar, int)

Overrides:
shiftToCalendar in class ConstrainedSchedule
Returns:

toString

public String toString()
Override toString.

Specified by:
toString in class ConstrainedSchedule
Returns:
A description of the schedule.