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