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