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