1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 package com.ivata.mask.web.struts;
64 import java.util.List;
65 import javax.servlet.http.HttpServletRequest;
66 import javax.servlet.http.HttpServletResponse;
67 import javax.servlet.http.HttpSession;
68 import org.apache.struts.action.ActionErrors;
69 import org.apache.struts.action.ActionForm;
70 import org.apache.struts.action.ActionMapping;
71 import com.ivata.mask.Mask;
72 import com.ivata.mask.MaskFactory;
73 import com.ivata.mask.persistence.PersistenceManager;
74 import com.ivata.mask.persistence.PersistenceSession;
75 import com.ivata.mask.util.StringHandling;
76 import com.ivata.mask.util.SystemException;
77 /***
78 * <p>
79 * Load the list for a given base class. The base class is specified in a
80 * request parameter, or may be specified in the request as a
81 * <code>ListForm</code>.
82 * </p>
83 *
84 * @since ivata masks 0.1 (2004-04-30)
85 * @author Colin MacLeod
86 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
87 * @version $Revision: 1.7 $
88 */
89 public class ListAction extends MaskAction {
90 /***
91 * <p>
92 * This factory is needed to access the masks and groups of masks.
93 * </p>
94 */
95 private MaskFactory maskFactory;
96 /***
97 * <p>
98 * Used to locate the value objects by their shared base class.
99 * </p>
100 */
101 private PersistenceManager persistenceManager;
102 /***
103 * <p>
104 * Create a new list action with the given value object locator.
105 * </p>
106 *
107 * @param persistenceManagerParam
108 * used to locate the value objects by their shared base class.
109 * @param maskFactoryParam
110 * Refer to {@link MaskAction#MaskAction}.
111 * @param authenticatorParam
112 * Refer to {@link MaskAction#MaskAction}.
113 */
114 public ListAction(final PersistenceManager persistenceManagerParam,
115 final MaskFactory maskFactoryParam,
116 final MaskAuthenticator authenticatorParam) {
117 super(maskFactoryParam, authenticatorParam);
118 this.maskFactory = maskFactoryParam;
119 this.persistenceManager = persistenceManagerParam;
120 }
121 /***
122 * This method does all the hard work, preparing objects for display in the
123 * list.
124 *
125 * @param mapping
126 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
127 * @param errors
128 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
129 * @param form
130 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
131 * @param request
132 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
133 * @param response
134 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
135 * @param session
136 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
137 * @return Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
138 * @throws SystemException
139 * Refer to {@link com.ivata.mask.web.struts.MaskAction#execute}.
140 */
141 public String execute(final ActionMapping mapping,
142 final ActionErrors errors, final ActionForm form,
143 final HttpServletRequest request,
144 final HttpServletResponse response, final HttpSession session)
145 throws SystemException {
146
147
148 String clear = getFromRequestOrForm("clear", request, form);
149 if (!StringHandling.isNullOrEmpty(clear)) {
150 return "new";
151 }
152
153 String baseClassName = request.getParameter("baseClass");
154 Class newBaseClass = null;
155 if (baseClassName != null) {
156 try {
157 newBaseClass = Class.forName(baseClassName);
158 } catch (ClassNotFoundException e) {
159 throw new SystemException(e);
160 }
161 } else if (form == null) {
162 throw new NullPointerException(
163 "ERROR in ListAction: either the "
164 + "class request parameter 'baseClass', "
165 + "or a valid list or mask form must be specified.");
166 } else if (form instanceof InputMaskForm) {
167 InputMaskForm inputMaskForm = (InputMaskForm) form;
168 newBaseClass = inputMaskForm.getBaseClass();
169 }
170
171 if (newBaseClass != null) {
172 PersistenceSession persistenceSession = persistenceManager
173 .openSession();
174 List valueObjects;
175 try {
176 valueObjects = persistenceManager.findAll(persistenceSession,
177 newBaseClass);
178 } finally {
179 persistenceSession.close();
180 }
181 Mask mask = maskFactory.getMask(newBaseClass, getListMask(request,
182 form));
183 ListForm listForm = new ListForm(valueObjects, mask, newBaseClass);
184 request.setAttribute(ListForm.REQUEST_ATTRIBUTE, listForm);
185 }
186 return "success";
187 }
188 }
189