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 Push command by pushing the value supplied by the user
10: * onto the stack.
11: *
12: * @author Jitender Miglani
13: * @author Philip Johnson
14: */
15: public class PushCommand implements Command {
16:
17: /**
18: * Processes the "Push" command sent by the user.
19: * Sets the stackArray attribute with the resulting stack contents.
20: *
21: * @param request The request object.
22: * @return The page to be displayed (Page.INDEX).
23: */
24: public Page process(HttpServletRequest request) {
25: Debug.println(Debug.STACKMVC, "Processing push.");
26: StackModel stackModel = StackModel.getInstance();
27: String number = request.getParameter("number");
28: stackModel.push(number);
29: Object[] stackArray = stackModel.toArray();
30: request.setAttribute("stackArray", stackArray);
31: request.setAttribute("top", number);
32: return Page.INDEX;
33: }
34: }
|