KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > tags > StateManager


1 package com.tonbeller.jpivot.tags;
2
3 /**
4  * Manages state of JSPs.
5  * <p />
6  * Example: the user displays customerdetail.jsp for customer A, then productdetail.jsp for product B,
7  * and then again customerdetail.jsp for customer C. What should happen to A and B at this point?
8  * There are two possible strategies: stack and page.
9  * <p />
10  * PageStateStrategy preserves the latest state for every page. In the example A will be destroyed and
11  * B and C will be preserved. So the user can display the productdetails.jsp with B and the
12  * customerdetail.jsp with C using browser history buttons.
13  * <p />
14  * StackStateStrategy puts the pages into a stack. In the example, first customerdetail.jsp/A is pushed,
15  * then productdetail.jsp/B is pushed. In the last step, productdetail.jsp is popped because there is
16  * already a customerdetail.jsp on the stack. After productdetail.jsp is popped, the associated
17  * value of customerdetail.jsp is changed from A to C. The stack will only contain the value C for
18  * customerdetail.jsp, the values A and B will be destroyed.
19  *
20  * @author av
21  * @since 15.02.2005
22  */

23 public interface StateManager {
24
25   /**
26    * lifecycle: initialize() -> show() -> hide() -> ... -> show() -> hide() -> destroy()
27    * @author av
28    * @since 15.02.2005
29    */

30   public interface State {
31     /**
32      * the name of the state, for example the name of the JSP file. States that belong
33      * to the same name will replace each other, i.e. there will be only one state
34      * for each name.
35      */

36     String JavaDoc getName();
37     /**
38      * called once before the state is used
39      */

40     void initialize() throws Exception JavaDoc;
41     /**
42      * called once after the state is no longer used
43      */

44     void destroy() throws Exception JavaDoc;
45     /**
46      * called when this state is made the visible one. There is only one visible state
47      */

48     void show() throws Exception JavaDoc;
49     /**
50      * called when the
51      */

52     void hide() throws Exception JavaDoc;
53     
54   }
55   
56   /**
57    * makes s the current state. If there is already another state with the name of <code>s</code>,
58    * it will be destroyed and replaced by <code>s</code>.
59    */

60   public void initializeAndShow(State s) throws Exception JavaDoc;
61   
62   /**
63    * makes a state with <code>name</code> the current state.
64    */

65   public void showByName(String JavaDoc name) throws Exception JavaDoc;
66   
67   /**
68    * removes all states
69    */

70   public void destroyAll() throws Exception JavaDoc;
71
72   /**
73    * removes + destroys a named state
74    */

75   public void destroyByName(String JavaDoc name) throws Exception JavaDoc;
76   
77   /**
78    * logger for debug/test
79    */

80   void setLogger(StateLogger logger);
81   StateLogger getLogger();
82 }
83
Popular Tags