KickJava   Java API By Example, From Geeks To Geeks.

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


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 "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 JavaDoc request) {
24     Debug.println(Debug.STACKMVC, "Processing clear.");
25     StackModel stackModel = StackModel.getInstance();
26     stackModel.clearStack();
27     Object JavaDoc[] 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 }
35
Popular Tags