1 2 18 19 22 package org.quartz; 23 24 import org.quartz.Job; 25 import org.quartz.JobExecutionContext; 26 import org.quartz.JobExecutionException; 27 import org.quartz.Scheduler; 28 import org.quartz.SimpleTrigger; 29 import org.quartz.Trigger; 30 import org.quartz.CronTrigger; 31 32 import java.util.Calendar ; 33 import java.util.Date ; 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 import java.util.Map ; 37 import java.util.Set ; 38 import java.util.SortedSet ; 39 import java.util.TimeZone ; 40 import java.util.TreeSet ; 41 import java.text.ParseException ; 42 43 148 public class UICronTrigger extends Trigger { 149 150 157 158 165 public static final int MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1; 166 167 175 public static final int MISFIRE_INSTRUCTION_DO_NOTHING = 2; 176 177 184 private static final int ALL_SPEC_INT = 99; 186 private static final int NO_SPEC_INT = 98; 188 private static final Integer ALL_SPEC = new Integer (ALL_SPEC_INT); 189 190 private static final Integer NO_SPEC = new Integer (NO_SPEC_INT); 191 192 private static Map monthMap = new HashMap (20); 193 194 private static Map dayMap = new HashMap (60); 195 196 static { 197 monthMap.put("JAN", new Integer (0)); 198 monthMap.put("FEB", new Integer (1)); 199 monthMap.put("MAR", new Integer (2)); 200 monthMap.put("APR", new Integer (3)); 201 monthMap.put("MAY", new Integer (4)); 202 monthMap.put("JUN", new Integer (5)); 203 monthMap.put("JUL", new Integer (6)); 204 monthMap.put("AUG", new Integer (7)); 205 monthMap.put("SEP", new Integer (8)); 206 monthMap.put("OCT", new Integer (9)); 207 monthMap.put("NOV", new Integer (10)); 208 monthMap.put("DEC", new Integer (11)); 209 210 dayMap.put("SUN", new Integer (1)); 211 dayMap.put("MON", new Integer (2)); 212 dayMap.put("TUE", new Integer (3)); 213 dayMap.put("WED", new Integer (4)); 214 dayMap.put("THU", new Integer (5)); 215 dayMap.put("FRI", new Integer (6)); 216 dayMap.put("SAT", new Integer (7)); 217 } 218 219 private Date startTime = null; 220 221 private Date endTime = null; 222 223 private Date nextFireTime = null; 224 225 private TimeZone timeZone = null; 226 227 private Date previousFireTime = null; 228 229 private TreeSet seconds = null; 230 231 private TreeSet minutes = null; 232 233 private TreeSet hours = null; 234 235 private TreeSet daysOfMonth = null; 236 237 private TreeSet months = null; 238 239 private TreeSet daysOfWeek = null; 240 241 private TreeSet years = null; 242 243 private transient boolean lastdayOfWeek = false; 244 245 private transient int nthdayOfWeek = 0; 246 247 private transient boolean lastdayOfMonth = false; 248 249 private transient boolean calendardayOfWeek = false; 250 251 private transient boolean calendardayOfMonth = false; 252 253 260 261 public void reset() { 262 seconds = new TreeSet (); 263 minutes = new TreeSet (); 264 hours = new TreeSet (); 265 daysOfMonth = new TreeSet (); 266 months = new TreeSet (); 267 daysOfWeek = new TreeSet (); 268 years = new TreeSet (); 269 270 seconds.add(new Integer (0)); 272 273 minutes.add(ALL_SPEC); 274 for (int i = 0; i < 60; i++) 275 minutes.add(new Integer (i)); 276 277 hours.add(ALL_SPEC); 278 for (int i = 0; i < 24; i++) 279 hours.add(new Integer (i)); 280 281 daysOfMonth.add(ALL_SPEC); 282 for (int i = 1; i <= 31; i++) 283 daysOfMonth.add(new Integer (i)); 284 285 months.add(ALL_SPEC); 286 for (int i = 1; i <= 12; i++) 287 months.add(new Integer (i)); 288 289 daysOfWeek.add(NO_SPEC); 290 291 years.add(ALL_SPEC); 292 for (int i = 1970; i <= 2099; i++) 293 years.add(new Integer (i)); 294 295 startTime = new Date (); 296 setStartTime(startTime); 297 setTimeZone(TimeZone.getDefault()); 298 } 299 300 305 public UICronTrigger() { 306 super(); 307 reset(); 308 } 309 310 315 public UICronTrigger(String name, String group) { 316 super(name, group); 317 reset(); 318 } 319 320 326 public UICronTrigger(String name, String group, String jobName, 327 String jobGroup) { 328 super(name, group, jobName, jobGroup); 329 reset(); 330 } 331 332 339 340 345 public Date getStartTime() { 346 return this.startTime; 347 } 348 349 public void setStartTime(Date startTime) { 350 if (startTime == null) 351 throw new IllegalArgumentException ("Start time cannot be null"); 352 353 Date eTime = getEndTime(); 354 if (eTime != null && startTime != null && eTime.before(startTime)) 355 throw new IllegalArgumentException ( 356 "End time cannot be before start time"); 357 358 359 Calendar cl = Calendar.getInstance(); 364 cl.setTime(startTime); 365 cl.set(Calendar.MILLISECOND, 0); 366 367 this.startTime = cl.getTime(); 368 } 369 370 378 public Date getEndTime() { 379 return this.endTime; 380 } 381 382 public void setEndTime(Date endTime) { 383 Date sTime = getStartTime(); 384 if (sTime != null && endTime != null && sTime.after(endTime)) 385 throw new IllegalArgumentException ( 386 "End time cannot be before start time"); 387 388 this.endTime = endTime; 389 } 390 391 399 public Date getNextFireTime() { 400 return this.nextFireTime; 401 } 402 403 public void updateAfterMisfire(org.quartz.Calendar cal) { 404 int instr = getMisfireInstruction(); 405 406 if (instr == MISFIRE_INSTRUCTION_SMART_POLICY) 407 instr = MISFIRE_INSTRUCTION_DO_NOTHING; 408 409 if (instr == MISFIRE_INSTRUCTION_DO_NOTHING) { 410 Date newFireTime = getFireTimeAfter(new Date ()); 411 while (newFireTime != null && cal != null 412 && !cal.isTimeIncluded(newFireTime.getTime())) { 413 newFireTime = getFireTimeAfter(newFireTime); 414 } 415 416 setNextFireTime(newFireTime); 417 418 } else if (instr == MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) { 419 setNextFireTime(new Date ()); 420 } 421 } 422 423 public Date getPreviousFireTime() { 424 return this.previousFireTime; 425 } 426 427 436 public void setPreviousFireTime(Date previousFireTime) { 437 this.previousFireTime = previousFireTime; 438 } 439 440 446 public void setNextFireTime(Date nextFireTime) { 447 this.nextFireTime = nextFireTime; 448 } 449 450 456 public TimeZone getTimeZone() { 457 return this.timeZone; 458 } 459 460 466 public void setTimeZone(TimeZone timeZone) { 467 this.timeZone = timeZone; 468 } 469 470 482 public Date getFireTimeAfter(Date afterTime) { 483 if (afterTime == null) afterTime = new Date (); 484 485 if (startTime.after(afterTime)) 486 afterTime = new Date (startTime.getTime() - 1000l); 487 488 Date pot = getTimeAfter(afterTime); 489 if (endTime != null && pot != null && pot.after(endTime)) return null; 490 491 return pot; 492 } 493 494 505 public Date getFinalFireTime() { 506 if (this.endTime != null) return getTimeBefore(this.endTime); 507 else 508 return null; 509 } 510 511 517 public boolean mayFireAgain() { 518 return (getNextFireTime() != null); 519 } 520 521 protected boolean validateMisfireInstruction(int misfireInstruction) { 522 if (misfireInstruction < MISFIRE_INSTRUCTION_SMART_POLICY) 523 return false; 524 525 if (misfireInstruction > MISFIRE_INSTRUCTION_DO_NOTHING) return false; 526 527 return true; 528 } 529 530 545 public void updateAfterMisfire() { 546 int instr = getMisfireInstruction(); 547 548 if (instr == MISFIRE_INSTRUCTION_SMART_POLICY) 549 instr = MISFIRE_INSTRUCTION_DO_NOTHING; 550 551 if (instr == MISFIRE_INSTRUCTION_DO_NOTHING) { 552 setNextFireTime(getFireTimeAfter(new Date ())); 553 } else if (instr == MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) { 554 setNextFireTime(new Date ()); 555 } 556 } 557 558 569 public boolean willFireOn(Calendar test) { 570 Integer second = new Integer (test.get(Calendar.SECOND)); 571 Integer minute = new Integer (test.get(Calendar.MINUTE)); 572 Integer hour = new Integer (test.get(Calendar.HOUR_OF_DAY)); 573 Integer day = new Integer (test.get(Calendar.DAY_OF_MONTH)); 574 Integer month = new Integer (test.get(Calendar.MONTH)); 575 576 if ((seconds.contains(second) || seconds.contains(ALL_SPEC)) 577 && (minutes.contains(minute) || minutes.contains(ALL_SPEC)) 578 && (hours.contains(hour) || hours.contains(ALL_SPEC)) 579 && (daysOfMonth.contains(day) || daysOfMonth.contains(ALL_SPEC)) 580 && (months.contains(month) || months.contains(ALL_SPEC))) { 581 582 return true; } 583 584 return false; 585 } 586 587 608 public int executionComplete(JobExecutionContext context, 609 JobExecutionException result) { 610 if (result != null && result.refireImmediately()) 611 return Trigger.INSTRUCTION_RE_EXECUTE_JOB; 612 613 if (result != null && result.refireImmediately()) 614 return INSTRUCTION_RE_EXECUTE_JOB; 615 616 if (result != null && result.unscheduleFiringTrigger()) 617 return INSTRUCTION_SET_TRIGGER_COMPLETE; 618 619 if (result != null && result.unscheduleAllTriggers()) 620 return INSTRUCTION_SET_ALL_JOB_TRIGGERS_COMPLETE; 621 622 if (!mayFireAgain()) return INSTRUCTION_DELETE_TRIGGER; 623 624 return INSTRUCTION_NOOP; 625 } 626 627 637 public void triggered(org.quartz.Calendar calendar) { 638 previousFireTime = nextFireTime; 639 nextFireTime = getFireTimeAfter(nextFireTime); 640 641 while (nextFireTime != null && calendar != null 642 && !calendar.isTimeIncluded(nextFireTime.getTime())) { 643 nextFireTime = getFireTimeAfter(nextFireTime); 644 } 645 } 646 647 651 public void updateWithNewCalendar(org.quartz.Calendar calendar, long misfireThreshold) 652 { 653 nextFireTime = getFireTimeAfter(previousFireTime); 654 655 Date now = new Date (); 656 do { 657 while (nextFireTime != null && calendar != null 658 && !calendar.isTimeIncluded(nextFireTime.getTime())) { 659 nextFireTime = getFireTimeAfter(nextFireTime); 660 } 661 662 if(nextFireTime != null && nextFireTime.before(now)) { 663 long diff = now.getTime() - nextFireTime.getTime(); 664 if(diff >= misfireThreshold) { 665 nextFireTime = getFireTimeAfter(nextFireTime); 666 continue; 667 } 668 } 669 }while(false); 670 } 671 672 689 public Date computeFirstFireTime(org.quartz.Calendar calendar) { 690 nextFireTime = getFireTimeAfter(new Date (startTime.getTime() - 1000l)); 691 692 while (nextFireTime != null && calendar != null 693 && !calendar.isTimeIncluded(nextFireTime.getTime())) { 694 nextFireTime = getFireTimeAfter(nextFireTime); 695 } 696 697 return nextFireTime; 698 } 699 700 public String getExpressionSummary() { 701 StringBuffer buf = new StringBuffer (); 702 703 buf.append("seconds: "); 704 buf.append(getExpressionSetSummary(seconds)); 705 buf.append("\n"); 706 buf.append("minutes: "); 707 buf.append(getExpressionSetSummary(minutes)); 708 buf.append("\n"); 709 buf.append("hours: "); 710 buf.append(getExpressionSetSummary(hours)); 711 buf.append("\n"); 712 buf.append("daysOfMonth: "); 713 buf.append(getExpressionSetSummary(daysOfMonth)); 714 buf.append("\n"); 715 buf.append("months: "); 716 buf.append(getExpressionSetSummary(months)); 717 buf.append("\n"); 718 buf.append("daysOfWeek: "); 719 buf.append(getExpressionSetSummary(daysOfWeek)); 720 buf.append("\n"); 721 buf.append("lastdayOfWeek: "); 722 buf.append(lastdayOfWeek); 723 buf.append("\n"); 724 buf.append("lastdayOfMonth: "); 725 buf.append(lastdayOfMonth); 726 buf.append("\n"); 727 buf.append("calendardayOfWeek: "); 728 buf.append(calendardayOfWeek); 729 buf.append("\n"); 730 buf.append("calendardayOfMonth: "); 731 buf.append(calendardayOfMonth); 732 buf.append("\n"); 733 buf.append("years: "); 734 buf.append(getExpressionSetSummary(years)); 735 buf.append("\n"); 736 737 return buf.toString(); 738 } 739 740 private String getExpressionSetSummary(Set set) { 741 742 if (set.contains(NO_SPEC)) return "?"; 743 if (set.contains(ALL_SPEC)) return "*"; 744 745 StringBuffer buf = new StringBuffer (); 746 747 Iterator itr = set.iterator(); 748 boolean first = true; 749 while (itr.hasNext()) { 750 Integer iVal = (Integer ) itr.next(); 751 String val = iVal.toString(); 752 if (!first) buf.append(","); 753 buf.append(val); 754 first = false; 755 } 756 757 return buf.toString(); 758 } 759 760 766 private Date getTimeAfter(Date afterTime) { 767 Calendar cl = Calendar.getInstance(timeZone); 768 769 afterTime = new Date (afterTime.getTime() + 1000); 772 cl.setTime(afterTime); 774 cl.set(Calendar.MILLISECOND, 0); 775 776 boolean gotOne = false; 777 778 while (!gotOne) { 780 781 if (endTime != null && cl.getTime().after(endTime)) return null; 782 783 SortedSet st = null; 784 int t = 0; 785 786 int sec = cl.get(Calendar.SECOND); 787 int min = cl.get(Calendar.MINUTE); 788 789 st = seconds.tailSet(new Integer (sec)); 791 if (st != null && st.size() != 0) { 792 sec = ((Integer ) st.first()).intValue(); 793 } else { 794 sec = ((Integer ) seconds.first()).intValue(); 795 min++; 796 cl.set(Calendar.MINUTE, min); 797 } 798 cl.set(Calendar.SECOND, sec); 799 800 min = cl.get(Calendar.MINUTE); 801 int hr = cl.get(Calendar.HOUR_OF_DAY); 802 t = -1; 803 804 st = minutes.tailSet(new Integer (min)); 806 if (st != null && st.size() != 0) { 807 t = min; 808 min = ((Integer ) st.first()).intValue(); 809 } else { 810 min = ((Integer ) minutes.first()).intValue(); 811 hr++; 812 } 813 if (min != t) { 814 cl.set(Calendar.SECOND, 0); 815 cl.set(Calendar.MINUTE, min); 816 cl.set(Calendar.HOUR_OF_DAY, hr); 817 continue; 818 } 819 cl.set(Calendar.MINUTE, min); 820 821 hr = cl.get(Calendar.HOUR_OF_DAY); 822 int day = cl.get(Calendar.DAY_OF_MONTH); 823 t = -1; 824 825 st = hours.tailSet(new Integer (hr)); 827 if (st != null && st.size() != 0) { 828 t = hr; 829 hr = ((Integer ) st.first()).intValue(); 830 } else { 831 hr = ((Integer ) hours.first()).intValue(); 832 day++; 833 } 834 if (hr != t) { 835 cl.set(Calendar.SECOND, 0); 836 cl.set(Calendar.MINUTE, 0); 837 cl.set(Calendar.HOUR_OF_DAY, hr); 838 cl.set(Calendar.DAY_OF_MONTH, day); 839 continue; 840 } 841 cl.set(Calendar.HOUR_OF_DAY, hr); 842 843 day = cl.get(Calendar.DAY_OF_MONTH); 844 int mon = cl.get(Calendar.MONTH) + 1; t = -1; 848 849 boolean dayOfMSpec = !daysOfMonth.contains(NO_SPEC); 851 boolean dayOfWSpec = !daysOfWeek.contains(NO_SPEC); 852 if (dayOfMSpec && !dayOfWSpec) { st = daysOfMonth.tailSet(new Integer (day)); 855 if (lastdayOfMonth) { 856 t = day; 857 day = getLastDayOfMonth(mon); 858 } else if (st != null && st.size() != 0) { 859 t = day; 860 day = ((Integer ) st.first()).intValue(); 861 } else { 862 day = ((Integer ) daysOfMonth.first()).intValue(); 863 mon++; 864 } 865 if (day != t) { 866 cl.set(Calendar.SECOND, 0); 867 cl.set(Calendar.MINUTE, 0); 868 cl.set(Calendar.HOUR_OF_DAY, 0); 869 cl.set(Calendar.DAY_OF_MONTH, day); 870 cl.set(Calendar.MONTH, mon - 1); continue; 875 } 876 } else if (dayOfWSpec && !dayOfMSpec) { if (lastdayOfWeek) { int dow = ((Integer ) daysOfWeek.first()).intValue(); int cDow = cl.get(Calendar.DAY_OF_WEEK); int daysToAdd = 0; 884 if (cDow < dow) daysToAdd = dow - cDow; 885 if (cDow > dow) daysToAdd = dow + (7 - cDow); 886 887 int lDay = getLastDayOfMonth(mon); 888 889 if (day + daysToAdd > lDay) { cl.set(Calendar.SECOND, 0); 892 cl.set(Calendar.MINUTE, 0); 893 cl.set(Calendar.HOUR_OF_DAY, 0); 894 cl.set(Calendar.DAY_OF_MONTH, 1); 895 cl.set(Calendar.MONTH, mon); continue; 899 } 900 901 while ((day + daysToAdd + 7) <= lDay) 903 daysToAdd += 7; 904 905 day += daysToAdd; 906 } else if (nthdayOfWeek != 0) { int dow = ((Integer ) daysOfWeek.first()).intValue(); int cDow = cl.get(Calendar.DAY_OF_WEEK); int daysToAdd = 0; 912 if (cDow < dow) daysToAdd = dow - cDow; 913 else if (cDow > dow) daysToAdd = dow + (7 - cDow); 914 915 day += daysToAdd; 916 int weekOfMonth = day / 7; 917 if (day % 7 > 0) weekOfMonth++; 918 919 daysToAdd = (nthdayOfWeek - weekOfMonth) * 7; 920 day += daysToAdd; 921 if (daysToAdd < 0 || day > getLastDayOfMonth(mon)) { 922 cl.set(Calendar.SECOND, 0); 923 cl.set(Calendar.MINUTE, 0); 924 cl.set(Calendar.HOUR_OF_DAY, 0); 925 cl.set(Calendar.DAY_OF_MONTH, 1); 926 cl.set(Calendar.MONTH, mon); continue; 930 } 931 } else { 932 int cDow = cl.get(Calendar.DAY_OF_WEEK); int dow = ((Integer ) daysOfWeek.first()).intValue(); st = daysOfWeek.tailSet(new Integer (cDow)); 936 if (st != null && st.size() > 0) { 937 dow = ((Integer ) st.first()).intValue(); 938 } 939 940 int daysToAdd = 0; 941 if (cDow < dow) daysToAdd = dow - cDow; 942 if (cDow > dow) daysToAdd = dow + (7 - cDow); 943 944 int lDay = getLastDayOfMonth(mon); 945 946 if (day + daysToAdd > lDay) { cl.set(Calendar.SECOND, 0); 949 cl.set(Calendar.MINUTE, 0); 950 cl.set(Calendar.HOUR_OF_DAY, 0); 951 cl.set(Calendar.DAY_OF_MONTH, 1); 952 cl.set(Calendar.MONTH, mon); continue; 956 } else if (daysToAdd > 0) { cl.set(Calendar.SECOND, 0); 958 cl.set(Calendar.MINUTE, 0); 959 cl.set(Calendar.HOUR_OF_DAY, 0); 960 cl.set(Calendar.DAY_OF_MONTH, day + daysToAdd); 961 cl.set(Calendar.MONTH, mon - 1); continue; 966 } 967 } 968 } else { throw new UnsupportedOperationException ( 970 "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."); } 972 cl.set(Calendar.DAY_OF_MONTH, day); 973 974 mon = cl.get(Calendar.MONTH) + 1; int year = cl.get(Calendar.YEAR); 978 t = -1; 979 980 st = months.tailSet(new Integer (mon)); 982 if (st != null && st.size() != 0) { 983 t = mon; 984 mon = ((Integer ) st.first()).intValue(); 985 } else { 986 mon = ((Integer ) months.first()).intValue(); 987 year++; 988 } 989 if (mon != t) { 990 cl.set(Calendar.SECOND, 0); 991 cl.set(Calendar.MINUTE, 0); 992 cl.set(Calendar.HOUR_OF_DAY, 0); 993 cl.set(Calendar.DAY_OF_MONTH, 1); 994 cl.set(Calendar.MONTH, mon - 1); cl.set(Calendar.YEAR, year); 998 continue; 999 } 1000 cl.set(Calendar.MONTH, mon - 1); 1004 year = cl.get(Calendar.YEAR); 1005 t = -1; 1006 1007 st = years.tailSet(new Integer (year)); 1009 if (st != null && st.size() != 0) { 1010 t = year; 1011 year = ((Integer ) st.first()).intValue(); 1012 } else 1013 return null; 1015 if (year != t) { 1016 cl.set(Calendar.SECOND, 0); 1017 cl.set(Calendar.MINUTE, 0); 1018 cl.set(Calendar.HOUR_OF_DAY, 0); 1019 cl.set(Calendar.DAY_OF_MONTH, 1); 1020 cl.set(Calendar.MONTH, mon - 1); cl.set(Calendar.YEAR, year); 1024 continue; 1025 } 1026 cl.set(Calendar.YEAR, year); 1027 1028 gotOne = true; 1029 } 1031 return cl.getTime(); 1032 } 1033 1034 private Date getTimeBefore(Date endTime) { 1036 return null; 1037 } 1038 1039 public boolean isLeapYear() { 1040 Calendar cl = Calendar.getInstance(timeZone); 1041 int year = cl.get(Calendar.YEAR); 1042 1043 if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) return true; 1044 else 1045 return false; 1046 } 1047 1048 public int getLastDayOfMonth(int monthNum) { 1049 1050 switch (monthNum) { 1051 case 1: 1052 return 31; 1053 case 2: 1054 return (isLeapYear()) ? 29 : 28; 1055 case 3: 1056 return 31; 1057 case 4: 1058 return 30; 1059 case 5: 1060 return 31; 1061 case 6: 1062 return 30; 1063 case 7: 1064 return 31; 1065 case 8: 1066 return 31; 1067 case 9: 1068 return 30; 1069 case 10: 1070 return 31; 1071 case 11: 1072 return 30; 1073 case 12: 1074 return 31; 1075 default: 1076 throw new IllegalArgumentException ("Illegal month number: " 1077 + monthNum); 1078 } 1079 } 1080 1081 public Integer [] getSecondsValues() { 1082 Integer list[] = new Integer [60]; 1083 for (int i = 0; i < 60; i++) { 1084 list[i] = new Integer (i); 1085 } 1086 1087 return list; 1088 } 1089 1090 public Integer [] getSecondsLabels() { 1091 return getSecondsValues(); 1092 } 1093 1094 public Integer [] getSeconds() { 1095 Integer list[] = new Integer [seconds.size()]; 1096 if (seconds != null) { 1097 int i = 0; 1098 for (Iterator it = seconds.iterator(); it.hasNext(); i++) { 1099 list[i] = (Integer ) it.next(); 1100 } 1101 } 1102 return list; 1103 } 1104 1105 public void setSeconds(Integer [] val) { 1106 if (seconds != null) seconds.clear(); 1107 else 1108 seconds = new TreeSet (); 1109 1110 for (int i = 0; i < val.length; i++) { 1111 seconds.add(val[i]); 1112 } 1113 } 1114 1115 public Integer [] getMinutesValues() { 1116 Integer list[] = new Integer [60]; 1117 for (int i = 0; i < 60; i++) { 1118 list[i] = new Integer (i); 1119 } 1120 1121 return list; 1122 } 1123 1124 public Integer [] getMinutesLabels() { 1125 return getMinutesValues(); 1126 } 1127 1128 public Integer [] getMinutes() { 1129 Integer list[] = new Integer [minutes.size()]; 1130 if (minutes != null) { 1131 int i = 0; 1132 for (Iterator it = minutes.iterator(); it.hasNext(); i++) { 1133 list[i] = (Integer ) it.next(); 1134 } 1135 } 1136 return list; 1137 } 1138 1139 public void setMinutes(Integer [] val) { 1140 if (minutes != null) minutes.clear(); 1141 else 1142 minutes = new TreeSet (); 1143 1144 for (int i = 0; i < val.length; i++) { 1145 minutes.add(val[i]); 1146 } 1147 } 1148 1149 public Integer [] getHoursValues() { 1150 Integer list[] = new Integer [24]; 1151 for (int i = 0; i < 24; i++) { 1152 list[i] = new Integer (i); 1153 } 1154 1155 return list; 1156 } 1157 1158 public String [] getHoursLabels() { 1159 String vals[] = {"12AM (Midnight)", "1AM", "2AM", "3AM", "4AM", "5AM", 1160 "6AM", "7AM", "8AM", "9AM", "10AM", "11AM", "12PM (Noon)", 1161 "1PM", "2PM", "3PM", "4PM", "5PM", "6PM", "7PM", "8PM", "9PM", 1162 "10PM", "11PM"}; 1163 return vals; 1164 } 1165 1166 public Integer [] getHours() { 1167 Integer list[] = new Integer [hours.size()]; 1168 if (hours != null) { 1169 int i = 0; 1170 for (Iterator it = hours.iterator(); it.hasNext(); i++) { 1171 list[i] = (Integer ) it.next(); 1172 } 1173 } 1174 return list; 1175 } 1176 1177 public void setHours(Integer [] val) { 1178 if (hours != null) hours.clear(); 1179 else 1180 hours = new TreeSet (); 1181 1182 for (int i = 0; i < val.length; i++) { 1183 hours.add(val[i]); 1184 } 1185 } 1186 1187 public Integer [] getDaysOfMonthValues() { 1188 Integer list[] = new Integer [31]; 1189 for (int i = 0; i < 31; i++) { 1190 list[i] = new Integer (i + 1); 1191 } 1192 1193 return list; 1194 } 1195 1196 public Integer [] getDaysOfMonthLabels() { 1197 return getDaysOfMonthValues(); 1198 } 1199 1200 public Integer [] getDaysOfMonth() { 1201 Integer list[] = new Integer [daysOfMonth.size()]; 1202 if (daysOfMonth != null) { 1203 int i = 0; 1204 for (Iterator it = daysOfMonth.iterator(); it.hasNext(); i++) { 1205 list[i] = (Integer ) it.next(); 1206 } 1207 } 1208 return list; 1209 } 1210 1211 public void setDaysOfMonth(Integer [] val) { 1212 if (daysOfMonth != null) daysOfMonth.clear(); 1213 else 1214 daysOfMonth = new TreeSet (); 1215 1216 for (int i = 0; i < val.length; i++) { 1217 daysOfMonth.add(val[i]); 1218 } 1219 daysOfWeek.clear(); 1220 daysOfWeek.add(NO_SPEC); 1221 } 1222 1223 public Integer [] getMonthsValues() { 1224 Integer list[] = new Integer [12]; 1225 for (int i = 0; i < 12; i++) { 1226 list[i] = new Integer (i + 1); 1227 } 1228 1229 return list; 1230 } 1231 1232 public String [] getMonthsLabels() { 1233 String vals[] = {"January", "February", "March", "April", "May", 1234 "June", "July", "August", "September", "October", "November", 1235 "December"}; 1236 return vals; 1237 } 1238 1239 public Integer [] getMonths() { 1240 Integer list[] = new Integer [months.size()]; 1241 if (months != null) { 1242 int i = 0; 1243 for (Iterator it = months.iterator(); it.hasNext(); i++) { 1244 list[i] = (Integer ) it.next(); 1245 } 1246 } 1247 return list; 1248 } 1249 1250 public void setMonths(Integer [] val) { 1251 if (months != null) months.clear(); 1252 else 1253 months = new TreeSet (); 1254 1255 for (int i = 0; i < val.length; i++) { 1256 months.add(val[i]); 1257 } 1258 } 1259 1260 public String [] getDaysOfWeekLabels() { 1261 String list[] = {"Sunday", "Monday", "Tuesday", "Wednesday", 1262 "Thursday", "Friday", "Saturday"}; 1263 return list; 1264 } 1265 1266 public Integer [] getDaysOfWeekValues() { 1267 Integer list[] = new Integer [7]; 1268 for (int i = 0; i < 7; i++) 1269 list[i] = new Integer (i + 1); 1270 return list; 1271 } 1272 1273 public Integer [] getDaysOfWeek() { 1274 Integer list[] = new Integer [daysOfWeek.size()]; 1275 if (daysOfWeek != null) { 1276 int i = 0; 1277 for (Iterator it = daysOfWeek.iterator(); it.hasNext(); i++) { 1278 list[i] = (Integer ) it.next(); 1279 } 1280 } 1281 return list; 1282 } 1283 1284 public void setDaysOfWeek(Integer [] val) { 1285 if (daysOfWeek != null) daysOfWeek.clear(); 1286 else 1287 daysOfWeek = new TreeSet (); 1288 1289 for (int i = 0; i < val.length; i++) { 1290 daysOfWeek.add(val[i]); 1291 } 1292 1293 daysOfMonth.clear(); 1294 daysOfMonth.add(NO_SPEC); 1295 } 1296 1297 public Integer [] getYearsValues() { 1298 Integer list[] = new Integer [20]; 1299 Calendar now = Calendar.getInstance(); 1300 int year = now.get(Calendar.YEAR); 1301 for (int i = 0; i < 20; i++) { 1302 list[i] = new Integer (i + year); 1303 } 1304 1305 return list; 1306 } 1307 1308 public Integer [] getYearsLabels() { 1309 return getYearsValues(); 1310 } 1311 1312 public Integer [] getYears() { 1313 Integer list[] = new Integer [years.size()]; 1314 if (years != null) { 1315 int i = 0; 1316 for (Iterator it = years.iterator(); it.hasNext(); i++) { 1317 list[i] = (Integer ) it.next(); 1318 } 1319 } 1320 return list; 1321 } 1322 1323 public void setYears(Integer [] val) { 1324 if (years != null) years.clear(); 1325 else 1326 years = new TreeSet (); 1327 1328 for (int i = 0; i < val.length; i++) { 1329 years.add(val[i]); 1330 } 1331 } 1332 1333 public static void main(String [] argv) { 1334 CronTrigger ct = new CronTrigger("a", "a"); 1335 try { 1336 ct.setCronExpression("0 * * * * ? *"); 1337 } catch (ParseException e) { 1338 } 1340 ct.setStartTime(new Date ()); 1341 ct.setTimeZone(TimeZone.getDefault()); 1342 System.out.println(ct.getExpressionSummary()); 1343 ct.computeFirstFireTime(null); 1344 1345 UICronTrigger uict = new UICronTrigger("a", "a"); 1346 Integer set[] = new Integer [1]; 1347 set[0] = new Integer (1); 1348 uict.setSeconds(set); 1349 System.out.println(ct.getExpressionSummary()); 1350 uict.computeFirstFireTime(null); 1351 1352 } 1353} 1354 | Popular Tags |