1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.completion.management;
11
12 import com.jcorporate.expresso.core.controller.*;
13 import com.sri.emo.wizard.completion.model.CompletionBean;
14 import com.sri.emo.wizard.wizardgateway.ListWizards;
15 import com.sri.emo.wizard.wizardgateway.WizardGatewayController;
16
17
18 /***
19 * Class for managing the completion bean in the session.
20 *
21 * @author Michael Rimov
22 * @version 1.0
23 */
24 public class CompletionBeanManager implements ICompletionBeanManager {
25
26 /***
27 * Attribute name for what is stored in the session.
28 */
29 public static final String BEAN_NAME = "CompletionBean";
30
31
32 /***
33 * Default constructor.
34 */
35 public CompletionBeanManager() {
36 }
37
38 public boolean handleSessionTimeout(final ExpressoRequest request, final ExpressoResponse response) throws
39 ControllerException {
40 if ((CompletionBean) request.getSession().getPersistentAttribute(BEAN_NAME) == null) {
41 Transition t = new Transition("", "", WizardGatewayController.class, ListWizards.STATE_NAME);
42 response.addError("It appears that your session expired. Please begin again.");
43 t.executeTransition(request, response);
44 return true;
45 }
46
47 return false;
48
49 }
50
51 public CompletionBean createOrRetrieveActionForm(final ExpressoRequest request) throws ControllerException {
52 CompletionBean result = (CompletionBean) request.getSession().getPersistentAttribute(BEAN_NAME);
53 if (result == null) {
54 result = new CompletionBean();
55 request.getSession().setPersistentAttribute(BEAN_NAME, result);
56 }
57
58 return result;
59
60 }
61
62 public CompletionBean getActionForm(final ExpressoRequest request) throws ControllerException {
63
64 return (CompletionBean) request.getSession().getPersistentAttribute(BEAN_NAME);
65 }
66
67 public void destroyActionForm(final ExpressoRequest request) throws ControllerException {
68 request.getSession().removePersistentAttribute(BEAN_NAME);
69 }
70
71 public ErrorCollection validate(final ExpressoRequest request, final ErrorCollection errorsToAdd) throws
72 ControllerException {
73 return getActionForm(request).validate(errorsToAdd);
74 }
75
76
77 public void setCompletionBean(final ExpressoRequest request, final CompletionBean wizardBeanToSave) throws
78 ControllerException {
79 request.getSession().setPersistentAttribute(BEAN_NAME, wizardBeanToSave);
80 }
81
82 }