KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > wizard > AbstractWizardSequence


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.wizard;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.struts.action.ActionForward;
28
29 import com.sslexplorer.security.SessionInfo;
30 import com.sslexplorer.wizard.forms.AbstractWizardForm;
31
32 /**
33  * Every wizard should provide a concreate implementation of this class. It
34  * is used to store state between wizard pages and should be created
35  * when the wizard is started.
36  *
37  * <p>For convenience, a simple object map is provided for storing values
38  *
39  * @author Brett Smith <brett@3sp.com>
40  */

41 public abstract class AbstractWizardSequence {
42     
43     // Private instance variables
44

45     private HashMap JavaDoc attributes;
46     private ActionForward finishActionForward;
47     private AbstractWizardForm currentPageForm;
48     private String JavaDoc resourcePrefix;
49     private String JavaDoc resourceBundle;
50     private List JavaDoc steps;
51     private String JavaDoc referer;
52     private List JavaDoc forms;
53     private String JavaDoc wizardName;
54     private SessionInfo session;
55     
56     /**
57      * Construct a new sequence.
58      *
59      * @param finishActionForward forward to jump to for completion of the wizard
60      * @param resourceBundle resource bundle to get resources for each steps menu item
61      * @param resourcePrefix prefix for keys in the resource bundle.
62      * @param referer page to return to on completion or exit
63      * @param wizardName the name of this wizard
64      * @param session session
65      */

66     public AbstractWizardSequence(ActionForward finishActionForward, String JavaDoc resourceBundle, String JavaDoc resourcePrefix, String JavaDoc referer, String JavaDoc wizardName, SessionInfo session) {
67         super();
68         this.finishActionForward = finishActionForward;
69         this.resourceBundle = resourceBundle;
70         this.resourcePrefix = resourcePrefix;
71         this.referer = referer;
72         this.wizardName = wizardName;
73         this.session = session;
74         steps = new ArrayList JavaDoc();
75         attributes = new HashMap JavaDoc();
76         forms = new ArrayList JavaDoc();
77     }
78     
79     /**
80      * Get all of the forms that have been used for this sequence.
81      *
82      * @return forms
83      */

84     public List JavaDoc getForms() {
85         return forms;
86     }
87     
88     /**
89      * Get all of the steps in this wizard.
90      *
91      * @return steps
92      */

93     public List JavaDoc getSteps() {
94         return steps;
95     }
96     
97     /**
98      * Add a new step to this sequence. This will be added as a menu item
99      */

100     public void addStep(WizardStep step) {
101         steps.add(step);
102     }
103     
104     /**
105      * Get the current form for the active page
106      *
107      * @return current page form
108      */

109     public AbstractWizardForm getCurrentPageForm() {
110         return currentPageForm;
111     }
112     
113     /**
114      * Set the current form for the active page. This also stores the form
115      * in a list so the instances can be cleared up when the wizard is
116      * cancelled.
117      *
118      * @param currentPageForm current page form
119      */

120     public void setCurrentPageForm(AbstractWizardForm currentPageForm) {
121         this.currentPageForm = currentPageForm;
122         for(int i = 0; i < currentPageForm.getStepIndex(); i++) {
123             ((WizardStep)steps.get(i)).setAvailable(true);
124         }
125         if(!forms.contains(currentPageForm)) {
126             forms.add(currentPageForm);
127         }
128     }
129     
130     /**
131      * Return all of the attributes stored in this sequence as a {@link java.util.Map}
132      *
133      * @return attributes
134      */

135     public Map JavaDoc getAttributes() {
136         return attributes;
137     }
138     
139     /**
140      * Store an attribute in the sequnce
141      *
142      * @param key key
143      * @param val values
144      * @return old values
145      */

146     public Object JavaDoc putAttribute(Object JavaDoc key, Object JavaDoc val) {
147         return attributes.put(key, val);
148     }
149     
150     /**
151      * Get the value of an attribute, or a default if it doesn't exist.
152  
153      * @param key
154      * @param defVal
155      * @return
156      */

157     public Object JavaDoc getAttribute(Object JavaDoc key, Object JavaDoc defVal) {
158         Object JavaDoc o = attributes.get(key);
159         return o == null ? defVal : o;
160     }
161
162     /**
163      * Get the action to jump to upon wizard completion
164      *
165      * @return finish action forward
166      */

167     public ActionForward getFinishActionForward() {
168         return finishActionForward;
169     }
170
171     /**
172      * Remove an attribute given its key.
173      *
174      * @param key key of attribute to remove
175      */

176     public void removeAttribute(String JavaDoc key) {
177         attributes.remove(key);
178     }
179
180     /**
181      * @return Returns the resourceBundle.
182      */

183     public String JavaDoc getResourceBundle() {
184         return resourceBundle;
185     }
186
187     /**
188      * @return Returns the resourcePrefix.
189      */

190     public String JavaDoc getResourcePrefix() {
191         return resourcePrefix;
192     }
193
194     /**
195      * @return Returns the referer.
196      */

197     public String JavaDoc getReferer() {
198         return referer;
199     }
200
201     /**
202      * Get if the sequence has an attribute with the specified key
203      *
204      * @parma key attribute key
205      * @return has attribute
206      */

207     public boolean hasAttribute(String JavaDoc key) {
208         return attributes.containsKey(key);
209     }
210
211     /**
212      * @return Returns the wizardName.
213      */

214     public String JavaDoc getWizardName() {
215         return wizardName;
216     }
217     
218     /**
219      * Get the session that started this wizard
220      *
221      * @return session
222      */

223     public SessionInfo getSession() {
224         return session;
225     }
226 }
227
Popular Tags