Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ProcessResultBase |
|
| 1.0714285714285714;1.071 |
1 | /* | |
2 | * Copyright 2001,2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | package org.apache.commons.scaffold.util; | |
18 | ||
19 | ||
20 | import java.util.ArrayList; | |
21 | import java.util.List; | |
22 | ||
23 | import org.apache.commons.scaffold.lang.Tokens; | |
24 | ||
25 | ||
26 | /** | |
27 | * Concrete implementation of <code>ProcessResult</code> that can be | |
28 | * used "as-is" to manage a response from the business tier. | |
29 | * | |
30 | * @author Ted Husted | |
31 | * @author Synthis Corporation | |
32 | * @version $Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $ | |
33 | */ | |
34 | public class ProcessResultBase implements ProcessResult { | |
35 | ||
36 | ||
37 | // ----------------------------------------------------------- Properties | |
38 | ||
39 | /** | |
40 | * The attribute name for the result [null]. | |
41 | */ | |
42 | 0 | private String name = null; |
43 | ||
44 | ||
45 | // Inherits JavaDoc | |
46 | public String getName() { | |
47 | 0 | return this.name; |
48 | } | |
49 | ||
50 | ||
51 | /** | |
52 | * Set the attribute name for this result object. | |
53 | * | |
54 | * @param name The new name | |
55 | */ | |
56 | public void setName(String name) { | |
57 | 0 | this.name = name; |
58 | 0 | } |
59 | ||
60 | ||
61 | /** | |
62 | * Field to store the scope property [request]. | |
63 | */ | |
64 | 0 | private String scope = Tokens.REQUEST; |
65 | ||
66 | ||
67 | /** | |
68 | * Return the scope under which to store this result object. | |
69 | * | |
70 | * @return the scope | |
71 | */ | |
72 | public String getScope() { | |
73 | 0 | return this.scope; |
74 | } | |
75 | ||
76 | ||
77 | /** | |
78 | * Set the scope under which to store this result object. | |
79 | * | |
80 | * @param scope The new scope | |
81 | */ | |
82 | public void setScope(String scope) { | |
83 | 0 | this.scope = scope; |
84 | 0 | } |
85 | ||
86 | ||
87 | ||
88 | /** | |
89 | * Field to store single-form state [false]. | |
90 | */ | |
91 | 0 | private boolean singleForm = false; |
92 | ||
93 | ||
94 | /** | |
95 | * Return the single-form state: | |
96 | * list of 0 or more records=FALSE, exactly one record=TRUE. | |
97 | * | |
98 | * @return True if this is a single record | |
99 | */ | |
100 | public boolean isSingleForm() { | |
101 | 0 | return this.singleForm; |
102 | } | |
103 | ||
104 | ||
105 | /** | |
106 | * Set the single-form state: | |
107 | * list of 0 or more records=FALSE, exactly one record=TRUE. | |
108 | * | |
109 | * @param Set to true for single form. | |
110 | */ | |
111 | public void setSingleForm(boolean singleForm) { | |
112 | 0 | this.singleForm = singleForm; |
113 | 0 | } |
114 | ||
115 | ||
116 | /** | |
117 | * Field to store exposed property [true]. | |
118 | */ | |
119 | 0 | private boolean exposed = true; |
120 | ||
121 | ||
122 | /** | |
123 | * Return the exposed state. | |
124 | * | |
125 | * @return True if the result should be exposed | |
126 | */ | |
127 | public boolean isExposed() { | |
128 | 0 | return this.exposed; |
129 | } | |
130 | ||
131 | ||
132 | /** | |
133 | * Indicates whether the result should be exposed | |
134 | * to the rest of the application through a context. | |
135 | * | |
136 | * @param multiple The new exposed | |
137 | */ | |
138 | public void setExposed(boolean exposed) { | |
139 | 0 | this.exposed = exposed; |
140 | 0 | } |
141 | ||
142 | ||
143 | /** | |
144 | * Field to store the data property [null]. | |
145 | */ | |
146 | 0 | private Object data = null; |
147 | ||
148 | ||
149 | /** | |
150 | * Return the data object. | |
151 | * | |
152 | * @return The data object | |
153 | */ | |
154 | public Object getData() { | |
155 | 0 | return this.data; |
156 | } | |
157 | ||
158 | ||
159 | /** | |
160 | * Assign a new data object. | |
161 | * | |
162 | * @param data The new data object | |
163 | */ | |
164 | public void setData(Object data) { | |
165 | 0 | this.data = data; |
166 | 0 | } |
167 | ||
168 | ||
169 | /** | |
170 | * Return whether data object has been set. | |
171 | * | |
172 | * @return True if this result contains a data object | |
173 | */ | |
174 | public boolean isData() { | |
175 | 0 | return (getData()!=null); |
176 | } | |
177 | ||
178 | ||
179 | /** | |
180 | * Field to store the aggregate state [false]. | |
181 | */ | |
182 | 0 | protected boolean aggregate = false; |
183 | ||
184 | ||
185 | /** | |
186 | * Return whether the result of this ProcessResult is a collection of | |
187 | * contains other ProcessResult objects to be handled individually. | |
188 | * This allows processes to be combined on the business tier and | |
189 | * returned to controller as a single operation. | |
190 | * | |
191 | * @return True if this ProcessResult contains other ProcessResults | |
192 | * objects | |
193 | */ | |
194 | public boolean isAggregate() { | |
195 | 0 | return aggregate; |
196 | } | |
197 | ||
198 | ||
199 | /** | |
200 | * Assign a new container state. | |
201 | * | |
202 | * @param aggregate Set to true for aggregate result | |
203 | */ | |
204 | public void setAggregate(boolean aggregate) { | |
205 | 0 | this.aggregate = aggregate; |
206 | 0 | } |
207 | ||
208 | ||
209 | /** | |
210 | * Field to store the message property [ArrayList]. | |
211 | */ | |
212 | 0 | private List messages = (List) new ArrayList(); |
213 | ||
214 | ||
215 | /** | |
216 | * Return whether there are any messages queued. | |
217 | * | |
218 | * @return True if there are messages queued. | |
219 | */ | |
220 | public boolean isMessages() { | |
221 | ||
222 | 0 | List messages = getMessages(); |
223 | ||
224 | 0 | if (null==messages) return false; |
225 | ||
226 | 0 | return !(messages.isEmpty()); |
227 | ||
228 | } // end isMessages() | |
229 | ||
230 | ||
231 | /** | |
232 | * Add a message to the list. | |
233 | * Instantiate messages if it does not already exist. | |
234 | * | |
235 | * @return True if message added. | |
236 | */ | |
237 | public boolean addMessage(Object message) { | |
238 | 0 | return getMessages().add(message); |
239 | } | |
240 | ||
241 | ||
242 | /** | |
243 | * Return the messages list (an ArrayList). | |
244 | * | |
245 | * @return The message list | |
246 | */ | |
247 | public List getMessages() { | |
248 | 0 | return (List) this.messages; |
249 | } | |
250 | ||
251 | ||
252 | /** | |
253 | * Set a new list of messages. | |
254 | * | |
255 | * @param The new list of messages | |
256 | */ | |
257 | public void setMessages(List messages) { | |
258 | 0 | this.messages = messages; |
259 | 0 | } |
260 | ||
261 | ||
262 | /** | |
263 | * Field to store dispatch property [null]. | |
264 | */ | |
265 | 0 | private String dispatch = null; |
266 | ||
267 | ||
268 | /** | |
269 | * The dispatch property can be used to re-route control to an non-default location, | |
270 | * either as a system path or via a logical name (e.g ActionForward). | |
271 | * | |
272 | * @see <code>setDispatchPath()</code> | |
273 | * | |
274 | * @return The dispatch advice | |
275 | */ | |
276 | public String getDispatch() { | |
277 | 0 | return (this.dispatch); |
278 | } | |
279 | ||
280 | ||
281 | /** | |
282 | * Set the dispatch advice. | |
283 | * | |
284 | * @param dispatch The new dispatch advice. | |
285 | */ | |
286 | public void setDispatch(String dispatch) { | |
287 | 0 | this.dispatch = dispatch; |
288 | 0 | } |
289 | ||
290 | ||
291 | /** | |
292 | * Return whether dispatch advice has been set. | |
293 | * | |
294 | * @return True if dispatch advice has been set. | |
295 | */ | |
296 | public boolean isDispatch() { | |
297 | 0 | return (getDispatch()!=null); |
298 | } | |
299 | ||
300 | ||
301 | /** | |
302 | * Field to store dispatchPath property [false]. | |
303 | */ | |
304 | 0 | private boolean dispatchPath = false; |
305 | ||
306 | ||
307 | /** | |
308 | * Return whether dispatch advice is suppose to be a | |
309 | * path or a token (e.g. ActionForward name) | |
310 | * | |
311 | * @return True if dispatch advice is a URI | |
312 | */ | |
313 | public boolean isDispatchPath() { | |
314 | 0 | return this.dispatchPath; |
315 | } | |
316 | ||
317 | ||
318 | /** | |
319 | * Set the dispatchPath state. | |
320 | * | |
321 | * @param Boolean Set to true if dispatch is a URI | |
322 | */ | |
323 | public void setDispatchPath(boolean dispatchPath) { | |
324 | 0 | this.dispatchPath = dispatchPath; |
325 | 0 | } |
326 | ||
327 | ||
328 | /** | |
329 | * Our scroller object for paging through lists. | |
330 | */ | |
331 | 0 | protected Scroller scroller = null; |
332 | ||
333 | ||
334 | public void setScroller(Scroller scroller){ | |
335 | 0 | this.scroller = scroller; |
336 | 0 | } |
337 | ||
338 | ||
339 | public Scroller getScroller() { | |
340 | 0 | return this.scroller; |
341 | } | |
342 | ||
343 | ||
344 | // ----------------------------------------------------------- Constructors | |
345 | ||
346 | ||
347 | /** | |
348 | * Default constructor. | |
349 | */ | |
350 | public ProcessResultBase() { | |
351 | 0 | super(); |
352 | 0 | } |
353 | ||
354 | ||
355 | /** | |
356 | * Convenience constructor to set result object. | |
357 | * | |
358 | * @param data The default data object | |
359 | */ | |
360 | public ProcessResultBase(Object data) { | |
361 | ||
362 | 0 | super(); |
363 | 0 | setData(data); |
364 | ||
365 | 0 | } // end ProcessResultBase |
366 | ||
367 | ||
368 | /** | |
369 | * Convenience constructor to set result object | |
370 | * and singleForm status. | |
371 | * | |
372 | * @param data The default data object | |
373 | */ | |
374 | public ProcessResultBase(Object data, boolean singleForm) { | |
375 | ||
376 | 0 | super(); |
377 | 0 | setData(data); |
378 | 0 | setSingleForm(singleForm); |
379 | ||
380 | 0 | } // end ProcessResultBase |
381 | ||
382 | ||
383 | /** | |
384 | * Convenience constructor to set forwarding advice. | |
385 | * | |
386 | * @param dispatch The default dispatch advice | |
387 | */ | |
388 | public ProcessResultBase(String dispatch) { | |
389 | ||
390 | 0 | super(); |
391 | 0 | setDispatch(dispatch); |
392 | ||
393 | 0 | } // end ProcessResultBase |
394 | ||
395 | } // end ProcessResultBase |