1 package org.oddjob.schedules; 2 3 import java.text.ParseException ; 4 import java.util.Date ; 5 6 import org.apache.log4j.Logger; 7 8 14 15 abstract public class ConstrainedSchedule extends AbstractSchedule { 16 17 private static final long serialVersionUID = 20050226; 18 19 private static Logger logger = Logger.getLogger(ConstrainedSchedule.class); 20 21 28 abstract public void setFrom(String from); 29 30 35 abstract public String getFrom(); 36 37 45 abstract public void setTo(String to); 46 47 52 abstract public String getTo(); 53 54 61 abstract public Date getStartDate(ScheduleContext context); 62 63 70 abstract public Date getEndDate(ScheduleContext context); 71 72 81 public void setOn(String on) { 82 setFrom(on); 83 setTo(on); 84 } 85 86 90 public Interval nextDue(ScheduleContext context) { 91 Date now = context.getDate(); 92 if (now == null) { 93 return null; 94 } 95 96 Interval withoutLimits = new Interval( 97 getStartDate(context), getEndDate(context)); 98 Interval nextInterval = withoutLimits.limit(getLimits()); 99 logger.debug(this + ": in date is " + now + 100 ", next interval is " + nextInterval); 101 if (nextInterval == null) { 102 return null; 103 } 104 Schedule child = getChildSchedule(); 105 if (child == null) { 106 return nextInterval; 107 } 108 child.setLimits(nextInterval); 109 Interval childInterval = null; 110 if (now.compareTo(nextInterval.getFromDate()) < 0) { 113 childInterval = child.nextDue( 114 context.spawn(nextInterval.getFromDate())); 115 } 116 else { 117 childInterval = child.nextDue(context); 118 } 119 if (childInterval == null) { 123 return nextDue(context.spawn(DateUtils.oneMillisAfter( 124 nextInterval.getToDate()))); 125 } 126 return childInterval; 127 } 128 129 134 public String toString() { 135 return this.getClass().getName() + " from " + getFrom() + " to " + getTo(); 136 } 137 } 138 | Popular Tags |