01: package csdl.stackmvc.control.command;
02:
03: import csdl.stackmvc.control.Page;
04: import csdl.stackmvc.model.StackModel;
05: import javax.servlet.http.HttpServletRequest;
06: import csdl.stackmvc.util.Debug;
07:
08: /**
09: * Implements the "Clear" command by clearing the stack instance.
10: *
11: * @author Jitender Miglani
12: * @author Philip Johnson
13: */
14: public class ClearCommand implements Command {
15:
16: /**
17: * Processes the "Clear" command sent by the user.
18: * Sets the stackArray attribute with the resulting stack contents.
19: *
20: * @param request The request object.
21: * @return The page to be displayed (Page.INDEX).
22: */
23: public Page process(HttpServletRequest request) {
24: Debug.println(Debug.STACKMVC, "Processing clear.");
25: StackModel stackModel = StackModel.getInstance();
26: stackModel.clearStack();
27: Object[] stackArray = stackModel.toArray();
28: request.setAttribute("stackArray", stackArray);
29:
30: // String top = "Stack is empty.";
31: request.setAttribute("top", "Stack is empty");
32: return Page.INDEX;
33: }
34: }
|