1 7 package com.inversoft.verge.mvc; 8 9 10 import java.util.ArrayList ; 11 import java.util.HashMap ; 12 import java.util.List ; 13 import java.util.Map ; 14 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 18 import com.inversoft.verge.mvc.controller.Action; 19 import com.inversoft.verge.mvc.controller.ControllerMVCInfo; 20 import com.inversoft.verge.mvc.controller.ControllerParser; 21 import com.inversoft.verge.mvc.model.ModelParser; 22 import com.inversoft.verge.mvc.validator.Validator; 23 import com.inversoft.verge.mvc.validator.ValidatorParser; 24 import com.inversoft.verge.util.RequestContext; 25 26 27 39 public class MVCRequest { 40 41 private ControllerParser controllerParser; 42 private ModelParser modelParser; 43 private ValidatorParser validatorParser; 44 45 private RequestContext requestContext; 46 private HttpServletRequest request; 47 private HttpServletResponse response; 48 private Object configuration; 49 50 private ControllerMVCInfo controllerInfo; 51 private Action action; 52 53 private boolean modelEnabled; 54 private Map modelObjects; 55 56 private boolean validationEnabled; 57 private List validators; 58 private List validatorHandlersToCall; 59 60 61 68 public MVCRequest(HttpServletRequest request, HttpServletResponse response) { 69 assert (request != null) : "request == null"; 70 assert (response != null) : "response == null"; 71 this.request = request; 72 this.response = response; 73 74 requestContext = new RequestContext(request); 75 modelEnabled = true; 76 validationEnabled = true; 77 78 validators = new ArrayList (); 79 modelObjects = new HashMap (); 80 validatorHandlersToCall = new ArrayList (); 81 } 82 83 84 89 public ControllerParser getControllerParser() { 90 return controllerParser; 91 } 92 93 98 public void setControllerParser(ControllerParser controllerParser) { 99 this.controllerParser = controllerParser; 100 } 101 102 107 public ModelParser getModelParser() { 108 return modelParser; 109 } 110 111 116 public void setModelParser(ModelParser modelParser) { 117 this.modelParser = modelParser; 118 } 119 120 125 public ValidatorParser getValidatorParser() { 126 return validatorParser; 127 } 128 129 134 public void setValidatorParser(ValidatorParser validatorParser) { 135 this.validatorParser = validatorParser; 136 } 137 138 143 public HttpServletRequest getRequest() { 144 return request; 145 } 146 147 152 public HttpServletResponse getResponse() { 153 return response; 154 } 155 156 162 public RequestContext getRequestContext() { 163 return requestContext; 164 } 165 166 172 public void setRequestContext(RequestContext requestContext) { 173 assert (requestContext != null) : "requestContext == null"; 174 this.requestContext = requestContext; 175 } 176 177 184 public Object getConfiguration() { 185 return configuration; 186 } 187 188 196 public void setConfiguration(Object configuration) { 197 this.configuration = configuration; 198 } 199 200 207 public ControllerMVCInfo getControllerInfo() { 208 return controllerInfo; 209 } 210 211 218 public void setControllerInfo(ControllerMVCInfo controllerInfo) { 219 this.controllerInfo = controllerInfo; 220 } 221 222 228 public Action getAction() { 229 return action; 230 } 231 232 238 public void setAction(Action action) { 239 this.action = action; 240 } 241 242 248 public void putModelObject(String key, Object model) { 249 modelObjects.put(key, model); 250 } 251 252 257 public Map getModelObjects() { 258 return modelObjects; 259 } 260 265 public boolean isModelEnabled() { 266 return modelEnabled; 267 } 268 269 274 public void setModelEnabled(boolean modelEnabled) { 275 this.modelEnabled = modelEnabled; 276 } 277 278 283 public boolean isValidationEnabled() { 284 return validationEnabled; 285 } 286 287 292 public void setValidationEnabled(boolean validationEnabled) { 293 this.validationEnabled = validationEnabled; 294 } 295 296 302 public List getValidators() { 303 return validators; 304 } 305 306 313 public void addValidators(Validator[] validators) { 314 if (validators != null && validators.length > 0) { 315 for (int i = 0; i < validators.length; i++) { 316 if (validators[i] != null) { 317 this.validators.add(validators[i]); 318 } 319 } 320 } 321 } 322 323 329 public void addValidator(Validator validator) { 330 if (validator != null) { 331 this.validators.add(validator); 332 } 333 } 334 335 338 public void clearValidators() { 339 validators.clear(); 340 } 341 342 347 public boolean hasValidators() { 348 return (validators.size() > 0); 349 } 350 351 360 public void addValidatorHandlerToCall(String handler) { 361 if (MVCRegistry.lookupValidatorHandler(handler) == null) { 362 throw new IllegalArgumentException ("ValidatorHandler named: " + 363 handler + " not registred"); 364 } 365 366 validatorHandlersToCall.add(handler); 367 } 368 369 374 public List getValidatorHandlersToCall() { 375 return validatorHandlersToCall; 376 } 377 } | Popular Tags |