コード例 #1
0
  /**
   * This method populates the form from a schedule time value object.
   *
   * @param sv The ScheduleValue object to populate the form from.
   */
  public void populateFromSchedule(ScheduleValue sv, Locale userLocale)
      throws IllegalArgumentException {

    this.populateStartDate(sv.getStart(), userLocale);
    Date end = sv.getEnd();
    int ival = sv.getInterval();
    if (null != end && ival > 0) {
      this.setWantEndDate(true); // performs validation on end date
      this.populateEndDate(sv.getEnd(), userLocale);
      endTime = END_ON_DATE;
    } else {
      endTime = END_NEVER;
    }

    // won't ever be editing an "immediate"
    this.startTime = START_ON_DATE;

    if (sv instanceof ScheduleSingleValue) {
      ScheduleSingleValue ssv = (ScheduleSingleValue) sv;
      recurInterval = RECUR_NEVER;
      return;
    } else if (sv instanceof ScheduleDailyValue) {
      ScheduleDailyValue sdv = (ScheduleDailyValue) sv;
      this.recurInterval = RECUR_DAILY;
      this.numDays = new Integer(sdv.getInterval()).toString();
      if (sdv.getEveryWeekDay()) {
        recurrenceFrequencyDaily = EVERY_WEEKDAY;
      } else {
        recurrenceFrequencyDaily = EVERY_DAY;
      }
      return;
    } else if (sv instanceof ScheduleWeeklyValue) {
      ScheduleWeeklyValue swv = (ScheduleWeeklyValue) sv;
      this.recurInterval = RECUR_WEEKLY;
      this.numWeeks = new Integer(swv.getInterval()).toString();
      ArrayList tmpDays = new ArrayList();
      for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
        if (swv.isDaySet(i)) {
          tmpDays.add(new Integer(i));
        }
      }
      recurrenceDay = new Integer[tmpDays.size()];
      recurrenceDay = (Integer[]) tmpDays.toArray(recurrenceDay);
      return;
    } else if (sv instanceof ScheduleMonthlyValue) {
      ScheduleMonthlyValue smv = (ScheduleMonthlyValue) sv;
      this.recurInterval = RECUR_MONTHLY;
      this.numMonths = new Integer(smv.getInterval()).toString();

      if (smv.isOffset()) {
        // "3rd Sunday"
        this.recurrenceWeek = new Integer(smv.getWeekOfMonth());
        this.monthlyRecurrenceDay = new Integer(smv.getDayOfWeek());
        this.recurrenceFrequencyMonthly = ON_DAY;
      } else {
        // "31st of October"
        this.recurrenceFrequencyMonthly = ON_EACH;
        this.eachDay = new Integer(smv.getDay());
      }
      return;
    }
  }
コード例 #2
0
  /**
   * This method constructs a schedule time value object from the form. It assumes that validate()
   * has already been called.
   */
  public ScheduleValue createSchedule() throws IllegalArgumentException {
    // this assumes that validate has already been called
    Date start;
    Date end = null;
    int occur = 0;

    // when to start
    if (startTime.equals(START_NOW)) {
      start = new Date();
    } else {
      start = getStartDate();
    }

    // when to end
    if (endTime.equals(END_ON_DATE)) {
      this.setWantEndDate(true);
      end = getEndDate();
    } else {
      end = null;
    }

    // never end
    if (recurInterval.equals(RECUR_NEVER)) {
      return new ScheduleSingleValue(start);
    } else if (recurInterval.equals(RECUR_DAILY)) {
      if (recurrenceFrequencyDaily.equals(EVERY_DAY)) {
        return new ScheduleDailyValue(start, end, Integer.parseInt(numDays));
      } else if (recurrenceFrequencyDaily.equals(EVERY_WEEKDAY)) {
        ScheduleDailyValue sdv = new ScheduleDailyValue(start, end, 0);
        sdv.setEveryWeekDay(true /* only on weekdays */);
        return sdv;
      } else {
        // shouldnt get here.
        return new ScheduleDailyValue(start, end, 0);
      }
    } else if (recurInterval.equals(RECUR_WEEKLY)) {
      int intNumWeeks = Integer.parseInt(numWeeks);
      ScheduleWeeklyValue swv = new ScheduleWeeklyValue(start, end, intNumWeeks);
      for (int i = 0; i < recurrenceDay.length; i++) {
        swv.setDay(recurrenceDay[i].intValue());
      }
      return swv;
    } else if (recurInterval.equals(RECUR_MONTHLY)) {
      int intNumMonths = Integer.parseInt(numMonths);
      ScheduleMonthlyValue smv = new ScheduleMonthlyValue(start, end, intNumMonths);

      // which day of the month to run this on
      if (ON_EACH.equals(recurrenceFrequencyMonthly)) {
        // "1st of November"
        smv.setDay(eachDay.intValue());
      } else if (ON_DAY.equals(recurrenceFrequencyMonthly)) {
        // "3rd Sunday"
        smv.setWeekOfMonth(recurrenceWeek.intValue());
        smv.setDayOfWeek(monthlyRecurrenceDay.intValue());
      } else {
        // shouldnt get here
        smv.setDay(1);
      }
      return smv;
    } else {
      throw new IllegalArgumentException("recurInterval had invalid value");
    }
  }