KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > stackmvc > control > command > PushCommand


1 package csdl.stackmvc.control.command;
2
3 import csdl.stackmvc.control.Page;
4 import csdl.stackmvc.model.StackModel;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import csdl.stackmvc.util.Debug;
7
8 /**
9  * 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 JavaDoc request) {
25     Debug.println(Debug.STACKMVC, "Processing push.");
26     StackModel stackModel = StackModel.getInstance();
27     String JavaDoc number = request.getParameter("number");
28     stackModel.push(number);
29     Object JavaDoc[] stackArray = stackModel.toArray();
30     request.setAttribute("stackArray", stackArray);
31     request.setAttribute("top", number);
32     return Page.INDEX;
33   }
34 }
35
Popular Tags