package caltool.model.schedule; import caltool.model.PrecondViolation; import java.util.*; /**** * * Class ScheduleEventPrecondViolation defines and exception containing error * conditions for the Schedule.scheduleEvent method. It contains a list of * the specific error messages that may be output in response to a precondition * having been violated by a call to scheduleEvent. * */ public class ScheduleEventPrecondViolation extends Exception implements PrecondViolation { /** * Construct this by initializing the error message list to an empty list, * initializing the numErrors count to 0, and initializing local copies of * the error message text for each of the possible errors from * Schedule.scheduleEvent. The text of these error messages comes from the * requirements. */ public ScheduleEventPrecondViolation() { errors = new ArrayList(); emptyTitleMessage = new String( "Event title cannot be empty."); alreadyScheduledMessage = new String( "An event of the given start date and title is already scheduled."); invalidStartDateMessage = new String( "Invalid start date."); invalidEndDateMessage = new String( "Invalid end date."); invalidCategoryMessage = new String( "Invalid category."); noActiveCalendarMessage = new String( "There is no active calendar in the Calendar Tool workspace."); outOfMemoryMessage = new String( "Due to computer memory limitations, there is no more space in the current calendar."); numErrors = 0; } /*-* * Implemented interface methods. */ /** * Return the error list. */ public String[] getErrors() { return (String[]) errors.toArray(new String[1]); } /** * Clear all error messages. */ public void clear() { errors = new ArrayList(); numErrors = 0; } /** * Return true if any errors have been set. */ public boolean anyErrors() { return (numErrors > 0); } /** * Return the number of errors. */ public int numberOfErrors() { return numErrors; } /*-* * Error-setting methods */ /** * Set the empty title error message. */ public void setEmptyTitleError() { errors.add(emptyTitleMessage); numErrors++; } /** * Set the already scheduled error message. */ public void setAlreadyScheduledError() { errors.add(alreadyScheduledMessage); numErrors++; } /** * Set the invalid start date error message. */ public void setInvalidStartDateError() { errors.add(invalidStartDateMessage); numErrors++; } /** * Set the invalid end date error message. */ public void setInvalidEndDateError() { errors.add(invalidEndDateMessage); numErrors++; } /** * Set the no active calendar error message. */ public void setNoActiveCalendarError() { errors.add(noActiveCalendarMessage); numErrors++; } /*-* * Data fields */ /** List of current error messages */ protected ArrayList errors; /** Error message count */ protected int numErrors; /** Error message for empty title */ protected String emptyTitleMessage; /** Error message for event of same date,title already scheduled */ protected String alreadyScheduledMessage; /** Error message for invalid start date */ protected String invalidStartDateMessage; /** Error message for invalid end date */ protected String invalidEndDateMessage; /** Error message for invalid category */ protected String invalidCategoryMessage; /** Error message for no currently active calendar in the workspace */ protected String noActiveCalendarMessage; /** Error message for out of memory, so no space left in calendar */ protected String outOfMemoryMessage; }