Source code: com/RuntimeCollective/webapps/bean/ScreenFlowState.java
1 /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/bean/ScreenFlowState.java,v 1.6 2003/09/30 15:13:09 joe Exp $
2 * $Revision: 1.6 $
3 * $Date: 2003/09/30 15:13:09 $
4 *
5 * ====================================================================
6 *
7 * Josephine : http://www.runtime-collective.com/josephine/index.html
8 *
9 * Copyright (C) 2003 Runtime Collective
10 *
11 * This product includes software developed by the
12 * Apache Software Foundation (http://www.apache.org/).
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30 package com.RuntimeCollective.webapps.bean;
31
32 import java.sql.SQLException;
33 import java.util.Date;
34 import java.util.Stack;
35 import java.util.Map;
36 import java.util.Iterator;
37
38 import com.RuntimeCollective.webapps.RuntimeParameters;
39 import com.RuntimeCollective.webapps.bean.EntityBean;
40 import com.RuntimeCollective.webapps.bean.DateBean;
41 import com.RuntimeCollective.webapps.bean.User;
42
43 import com.RuntimeCollective.webapps.RuntimeDataSource;
44 import com.RuntimeCollective.webapps.RuntimeParameters;
45
46 import javax.servlet.http.HttpServletRequest;
47
48 /**
49 * A stack of local forwards for screens with a very simplistic
50 * workflow.
51 * <br>
52 * Note: This class is currently under development. Highest level of
53 * workflow is the initial screen, lowest level is the furthest
54 * traversible screen in the flow.
55 */
56 public class ScreenFlowState {
57
58 public static final String SESSION_KEY = ScreenFlowState.class.getName();
59
60 private Stack iStack;
61
62 private String cancelForward;
63
64 private static int iFlowId = 0;
65 private static int iStateId = 0;
66
67 public ScreenFlowState() {
68 iFlowId++;
69 iStack = new Stack();
70 }
71
72 /**
73 * For future use
74 */
75 public int getFlowId() {
76 return iFlowId;
77 }
78
79 /**
80 * Use this to set the name of a global forward to return to in the
81 * event of a cancel. This has been developed for the situation in
82 * which the same page/action set is called from a number of
83 * different locations.
84 */
85 public void setCancelForward(String forward) {
86
87 RuntimeParameters.log(this, "Setting cancel forward : " + forward);
88
89 this.cancelForward = forward;
90 }
91
92 public String getCancelForward() {
93 return this.cancelForward;
94 }
95
96 /**
97 * Add a forward to the stack.
98 */
99 public void addForward(String forward) {
100 iStack.push(new ScreenObject(forward, iStateId));
101 iStateId++;
102 }
103
104 public String getForward() {
105 String forward = "success";
106 if(!iStack.empty()) {
107 forward = ((ScreenObject) iStack.pop()).getForward();
108 }
109 return forward;
110 }
111
112 public String toString() {
113 StringBuffer buffer = new StringBuffer();
114
115 buffer.append("[Cancel Forward = " + (this.cancelForward != null ? this.cancelForward : "not set") + "]");
116 buffer.append("Forward Stack : ");
117
118 Iterator i = iStack.iterator();
119 while(i.hasNext()) {
120 ScreenObject o = (ScreenObject) i.next();
121 buffer.append("[" + o.getForward() + "]");
122 }
123
124 return buffer.toString();
125 }
126
127 /**
128 * Reset the states when you are at
129 * the highest level of workflow
130 */
131 public void reset() {
132 iStack = new Stack();
133 }
134
135 /**
136 * An internal stack class, for no particular purpose at the
137 * moment. For future use
138 */
139 private class ScreenObject {
140 private String iForward;
141 private int iStateId;
142
143 public ScreenObject(String forward, int stateId) {
144 iForward = forward;
145 iStateId = stateId;
146 }
147
148 public String getForward() {
149 return iForward;
150 }
151
152 /**
153 * For future use
154 */
155 public int getStateId() {
156 return iStateId;
157 }
158
159 }
160 }