KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > ActionFlowState


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.actionflow;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14
15 import com.inversoft.verge.mvc.controller.actionflow.config.Namespace;
16 import com.inversoft.verge.mvc.controller.actionflow.config.Node;
17
18
19 /**
20  * This class holds the current state of the entire
21  * ActionFlow system including the Node of the Node that
22  * that was last executed for all Namespaces for any session
23  *
24  * @author Brian Pontarelli
25  * @since 2.0
26  * @version 2.0
27  */

28 public class ActionFlowState {
29
30     /**
31      * The key in the session that the state is stored under
32      */

33     public static final String JavaDoc SESSION_KEY = "actionFlowState";
34
35     private HttpServletRequest JavaDoc request;
36
37
38     /**
39      * Constructs a new <code>ActionFlowState</code>.
40      */

41     public ActionFlowState(HttpServletRequest JavaDoc request) {
42         this.request = request;
43     }
44
45
46     /**
47      * Gets the {@link com.inversoft.verge.mvc.controller.actionflow.config.Node Node}
48      * of the Node currently being executed
49      *
50      * @return The <code>Node</code> of the Node currently being executed
51      */

52     public Node getCurrentNodeForNamespace(Namespace namespace) {
53         Map JavaDoc state = (Map JavaDoc) request.getSession().getAttribute(SESSION_KEY);
54         if (state == null) {
55             state = new HashMap JavaDoc();
56             request.getSession().setAttribute(SESSION_KEY, state);
57         }
58
59         return (Node) state.get(namespace.getName());
60     }
61     
62     /**
63      * Gets the {@link com.inversoft.verge.mvc.controller.actionflow.config.Node Node}
64      * of the Node currently being executed
65      *
66      * @return The <code>Node</code> of the Node currently being executed
67      */

68     public Node getCurrentNodeForNamespace(String JavaDoc namespace) {
69         Map JavaDoc state = (Map JavaDoc) request.getSession().getAttribute(SESSION_KEY);
70         if (state == null) {
71             state = new HashMap JavaDoc();
72             request.getSession().setAttribute(SESSION_KEY, state);
73         }
74
75         return (Node) state.get(namespace);
76     }
77     
78     /**
79      * Sets the {@link com.inversoft.verge.mvc.controller.actionflow.config.Node Node}
80      * of the Node currently being executed
81      *
82      * @param node The <code>Node</code> of the node currently being
83      * executed
84      */

85     void setCurrentNodeForNamespace(Namespace namespace, Node node) {
86         Map JavaDoc state = (Map JavaDoc) request.getSession().getAttribute(SESSION_KEY);
87         if (state == null) {
88             state = new HashMap JavaDoc();
89             request.getSession().setAttribute(SESSION_KEY, state);
90         }
91
92         state.put(namespace.getName(), node);
93     }
94 }
Popular Tags