org.oddjob.schedules
Class ScheduleType

java.lang.Object
  extended by org.oddjob.schedules.ScheduleType
All Implemented Interfaces:
ArooaValue, ArooaLifeAware

public class ScheduleType
extends Object
implements ArooaValue, ArooaLifeAware

Description

Applies a schedule to a given date to provide a calculated date. If the date is not provide the current date is used. This type will most often be used to calculate the current date or the current time, or a next business date.

The ScheduleResult is also available and this can be used to calculate recurring schedules as in the example below.

Example

Display the time now. Note the date variable is passed into Oddjob during the testing of this example so the time can be fixed, but run as is it will be null and so the current time will be displayed.
<oddjob id="this">
    <job>
        <sequential>
            <jobs>
                <variables id="time">
                    <now>
                        <schedule>
                            <date>
                                <value value="${date}"/>
                            </date>
                            <schedule>
                                <schedules:now xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
                            </schedule>
                        </schedule>
                    </now>
                    <formatted>
                        <format date="${time.now}" format="hh:mm a"/>
                    </formatted>
                </variables>
                <echo id="echo-time">The time now is ${time.formatted}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example

Use a schedule with a time zone. This example displays when tomorrow starts in Hong Kong in the local time.
<oddjob id="this">
    <job>
        <sequential>
            <jobs>
                <variables id="time">
                    <now>
                        <schedule timeZone="Asia/Hong_Kong">
                            <date>
                                <value value="${date}"/>
                            </date>
                            <schedule>
                                <schedules:day-after xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
                            </schedule>
                        </schedule>
                    </now>
                    <formatted>
                        <format date="${time.now}" format="hh:mm a"/>
                    </formatted>
                </variables>
                <echo id="echo-time">Tomorrow in Hong Kong starts at ${time.formatted} our time.</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>
Note that to display the current time in Hong Kong we would use a Time Zone on the format type, not on the now schedule because dates internally use UTC (Coordinated Universal Time) so now will always be the same regardless of time zone.

Example

Calculate the next business date. Two schedule types are used, the first calculates the next day, the next takes this and applies it to a schedule that defines the business days. The result will be the next business day.
<oddjob xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
    <job>
        <sequential>
            <jobs>
                <variables id="time">
                    <tomorrow>
                        <schedule>
                            <date>
                                <value value="${date}"/>
                            </date>
                            <schedule>
                                <schedules:day-after/>
                            </schedule>
                        </schedule>
                    </tomorrow>
                    <nextBusinessDay>                    
                        <schedule>
                            <date>
                                <value value="${time.tomorrow}"/>
                            </date>
                            <schedule>
                                <schedules:broken>
                                    <schedule>
                                        <schedules:weekly from="Monday" to="Friday">
                                            <refinement>
                                                <schedules:daily/>
                                            </refinement>
                                        </schedules:weekly>
                                    </schedule>
                                    <breaks>
                                        <schedules:list>
                                            <schedules>
                                                <schedules:date on="2011-12-26"/>
                                                <schedules:date on="2011-12-27"/>
                                            </schedules>
                                        </schedules:list>
                                    </breaks>
                                </schedules:broken>
                            </schedule>
                        </schedule>
                    </nextBusinessDay>
                </variables>
                <echo id="echo-time">The next business date is ${time.nextBusinessDay}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example

Display the due dates for a recurring schedule. This would be useful for experimenting with schedules.
<oddjob id="this">
    <job>
        <sequential>
            <jobs>
                <variables id="vars">
                    <date>
                        <value value="${date}"/>
                    </date>
                </variables>
                <foreach>
                    <values>
                        <tokenizer text="1,2,3,4,5"/>
                    </values>
                    <configuration>
                        <xml>
                            <foreach>
                                <job>
                                    <sequential>
                                        <jobs>
                                            <variables id="time">
                                                <schedule>
                                                    <schedule>
                                                        <date>
                                                            <value value="${vars.date}"/>
                                                        </date>
                                                        <schedule>
                                                            <schedules:weekly from="Monday" to="Friday" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
                                                                <refinement>
                                                                    <schedules:daily from="10:30"/>
                                                                </refinement>
                                                            </schedules:weekly>
                                                        </schedule>
                                                    </schedule>
                                                </schedule>
                                            </variables>
                                            <echo>Next due: ${time.schedule.result}</echo>
                                            <set>
                                                <values>
                                                    <value key="vars.date" value="${time.schedule.result.useNext}"/>
                                                </values>
                                            </set>
                                        </jobs>
                                    </sequential>
                                </job>
                            </foreach>
                        </xml>
                    </configuration>
                </foreach>
            </jobs>
        </sequential>
    </job>
</oddjob>
Author:
Rob

Nested Class Summary
static class ScheduleType.Conversions
           
 
Constructor Summary
ScheduleType()
           
 
Method Summary
 void configured()
          The configuration for the bean has been fully configured.
 void destroy()
          The configuration for the bean is about to be destroyed.
 Date getDate()
           
 ScheduleResult getResult()
           
 Schedule getSchedule()
           
 String getTimeZone()
          Get the time zone id to use in this schedule.
 void initialised()
          The configuration for the bean has been initialised.
 void setDate(Date clock)
           
 void setSchedule(Schedule schedule)
           
 void setTimeZone(String timeZoneId)
          Set the time zone.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ScheduleType

public ScheduleType()
Method Detail

getResult

public ScheduleResult getResult()

getSchedule

public Schedule getSchedule()

setSchedule

public void setSchedule(Schedule schedule)

getDate

public Date getDate()

setDate

public void setDate(Date clock)

getTimeZone

public String getTimeZone()
Get the time zone id to use in this schedule.

Returns:
The time zone id being used.

setTimeZone

public void setTimeZone(String timeZoneId)
Set the time zone.

Parameters:
timeZoneId - the timeZoneId.

initialised

public void initialised()
Description copied from interface: ArooaLifeAware
The configuration for the bean has been initialised. Constant properties and element properties will have been injected.

Specified by:
initialised in interface ArooaLifeAware

configured

public void configured()
Description copied from interface: ArooaLifeAware
The configuration for the bean has been fully configured. Runtime properties will have been injected.

Specified by:
configured in interface ArooaLifeAware

destroy

public void destroy()
Description copied from interface: ArooaLifeAware
The configuration for the bean is about to be destroyed. A bean can use this method to free resources.

Specified by:
destroy in interface ArooaLifeAware

toString

public String toString()
Overrides:
toString in class Object