001 /* 002 * Copyright 2001,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.scaffold.util; 018 019 020 import java.util.ArrayList; 021 import java.util.List; 022 023 import org.apache.commons.scaffold.lang.Tokens; 024 025 026 /** 027 * Concrete implementation of <code>ProcessResult</code> that can be 028 * used "as-is" to manage a response from the business tier. 029 * 030 * @author Ted Husted 031 * @author Synthis Corporation 032 * @version $Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $ 033 */ 034 public class ProcessResultBase implements ProcessResult { 035 036 037 // ----------------------------------------------------------- Properties 038 039 /** 040 * The attribute name for the result [null]. 041 */ 042 private String name = null; 043 044 045 // Inherits JavaDoc 046 public String getName() { 047 return this.name; 048 } 049 050 051 /** 052 * Set the attribute name for this result object. 053 * 054 * @param name The new name 055 */ 056 public void setName(String name) { 057 this.name = name; 058 } 059 060 061 /** 062 * Field to store the scope property [request]. 063 */ 064 private String scope = Tokens.REQUEST; 065 066 067 /** 068 * Return the scope under which to store this result object. 069 * 070 * @return the scope 071 */ 072 public String getScope() { 073 return this.scope; 074 } 075 076 077 /** 078 * Set the scope under which to store this result object. 079 * 080 * @param scope The new scope 081 */ 082 public void setScope(String scope) { 083 this.scope = scope; 084 } 085 086 087 088 /** 089 * Field to store single-form state [false]. 090 */ 091 private boolean singleForm = false; 092 093 094 /** 095 * Return the single-form state: 096 * list of 0 or more records=FALSE, exactly one record=TRUE. 097 * 098 * @return True if this is a single record 099 */ 100 public boolean isSingleForm() { 101 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 this.singleForm = singleForm; 113 } 114 115 116 /** 117 * Field to store exposed property [true]. 118 */ 119 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 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 this.exposed = exposed; 140 } 141 142 143 /** 144 * Field to store the data property [null]. 145 */ 146 private Object data = null; 147 148 149 /** 150 * Return the data object. 151 * 152 * @return The data object 153 */ 154 public Object getData() { 155 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 this.data = data; 166 } 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 return (getData()!=null); 176 } 177 178 179 /** 180 * Field to store the aggregate state [false]. 181 */ 182 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 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 this.aggregate = aggregate; 206 } 207 208 209 /** 210 * Field to store the message property [ArrayList]. 211 */ 212 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 List messages = getMessages(); 223 224 if (null==messages) return false; 225 226 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 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 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 this.messages = messages; 259 } 260 261 262 /** 263 * Field to store dispatch property [null]. 264 */ 265 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 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 this.dispatch = dispatch; 288 } 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 return (getDispatch()!=null); 298 } 299 300 301 /** 302 * Field to store dispatchPath property [false]. 303 */ 304 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 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 this.dispatchPath = dispatchPath; 325 } 326 327 328 /** 329 * Our scroller object for paging through lists. 330 */ 331 protected Scroller scroller = null; 332 333 334 public void setScroller(Scroller scroller){ 335 this.scroller = scroller; 336 } 337 338 339 public Scroller getScroller() { 340 return this.scroller; 341 } 342 343 344 // ----------------------------------------------------------- Constructors 345 346 347 /** 348 * Default constructor. 349 */ 350 public ProcessResultBase() { 351 super(); 352 } 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 super(); 363 setData(data); 364 365 } // 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 super(); 377 setData(data); 378 setSingleForm(singleForm); 379 380 } // 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 super(); 391 setDispatch(dispatch); 392 393 } // end ProcessResultBase 394 395 } // end ProcessResultBase