01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ValidationRuleLimitedDate.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.site;
09:
10: import com.uwyn.rife.tools.BeanUtils;
11: import com.uwyn.rife.tools.exceptions.BeanUtilsException;
12: import java.lang.reflect.Array;
13: import java.util.Date;
14:
15: import static com.uwyn.rife.site.ValidityChecks.checkLimitedDate;
16:
17: public class ValidationRuleLimitedDate extends PropertyValidationRule {
18: private Date mMin = null;
19: private Date mMax = null;
20:
21: public ValidationRuleLimitedDate(String propertyName, Date min,
22: Date max) {
23: super (propertyName);
24:
25: mMin = min;
26: mMax = max;
27: }
28:
29: public boolean validate() {
30: Object value;
31: try {
32: value = BeanUtils.getPropertyValue(getBean(),
33: getPropertyName());
34: } catch (BeanUtilsException e) {
35: // an error occurred when obtaining the value of the property
36: // just consider it valid to skip over it
37: return true;
38: }
39:
40: if (null == value) {
41: return true;
42: }
43:
44: if (value.getClass().isArray()) {
45: int length = Array.getLength(value);
46: for (int i = 0; i < length; i++) {
47: if (!checkLimitedDate(Array.get(value, i), mMin, mMax)) {
48: return false;
49: }
50: }
51:
52: return true;
53: } else {
54: return checkLimitedDate(value, mMin, mMax);
55: }
56: }
57:
58: public ValidationError getError() {
59: return new ValidationError.INVALID(getSubject());
60: }
61: }
|