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: ValidationRuleRange.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:
13: import static com.uwyn.rife.site.ValidityChecks.checkRange;
14:
15: public class ValidationRuleRange extends PropertyValidationRule {
16: private Comparable mBegin = null;
17: private Comparable mEnd = null;
18:
19: public ValidationRuleRange(String propertyName, Comparable begin,
20: Comparable end) {
21: super (propertyName);
22:
23: mBegin = begin;
24: mEnd = end;
25: }
26:
27: public boolean validate() {
28: Object value;
29: try {
30: value = BeanUtils.getPropertyValue(getBean(),
31: getPropertyName());
32: } catch (BeanUtilsException e) {
33: // an error occurred when obtaining the value of the property
34: // just consider it valid to skip over it
35: return true;
36: }
37:
38: return checkRange(value, mBegin, mEnd);
39: }
40:
41: public ValidationError getError() {
42: return new ValidationError.INVALID(getSubject());
43: }
44: }
|