1 // Copyright 2009 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.tools
.admin
;
5 import com
.google
.cron
.GrocTimeSpecification
;
7 import java
.text
.DateFormat
;
8 import java
.text
.SimpleDateFormat
;
10 import java
.util
.Iterator
;
11 import java
.util
.TimeZone
;
14 * Implementation of the CronEntry interface used to describe a single cron
18 public class CronEntryImpl
implements CronEntry
{
20 private final DateFormat formatter
;
22 private final String url
;
23 private final String description
;
24 private final String schedule
;
25 private final String tz
;
27 public CronEntryImpl(String url
, String description
, String schedule
, String tz
) {
29 this.description
= description
;
30 this.schedule
= schedule
;
31 this.tz
= (tz
== null) ?
"UTC" : tz
;
32 formatter
= new SimpleDateFormat("EEE MMM dd, yyyy HH:mm z (Z)");
33 formatter
.setTimeZone(TimeZone
.getTimeZone(this.tz
));
37 public String
getDescription() {
42 public Iterator
<String
> getNextTimesIterator() {
43 return new TimeIterator(new Date(),
44 GrocTimeSpecification
.create(schedule
, TimeZone
.getTimeZone(tz
)));
48 * Test variant of {@link #getNextTimesIterator()}, with a specified start.
50 Iterator
<String
> getNextTimesIterator(Date start
) {
51 return new TimeIterator(start
,
52 GrocTimeSpecification
.create(schedule
, TimeZone
.getTimeZone(tz
)));
56 public String
getSchedule() {
60 public String
getTimezone() {
65 public String
getUrl() {
70 public String
toXml() {
73 " <url>" + url
+ "</url>\n" +
74 " <schedule>" + schedule
+ "</schedule>\n" +
75 " <timezone>" + tz
+ "</timezone>\n";
76 if (description
!= null) {
77 result
= result
+ " <description>" + description
+ "</description>\n";
79 return result
+ "</cron>";
83 * An iterator tracking the last execution time, and the groc time
84 * specification object to compute future execution times.
86 public class TimeIterator
implements Iterator
<String
> {
89 private GrocTimeSpecification groc
;
91 public TimeIterator(Date seedTime
, GrocTimeSpecification groc
) {
97 public boolean hasNext() {
102 public String
next() {
103 lastRun
= groc
.getMatch(lastRun
);
104 String result
= formatter
.format(lastRun
);
109 public void remove() {
110 throw new UnsupportedOperationException("cron execution times cannot be removed");