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: ValidationRuleInList.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.site;
09:
10: import static com.uwyn.rife.site.ValidityChecks.checkInList;
11:
12: import com.uwyn.rife.tools.BeanUtils;
13: import com.uwyn.rife.tools.exceptions.BeanUtilsException;
14:
15: public class ValidationRuleInList extends PropertyValidationRule {
16: private String[] mList = null;
17:
18: public ValidationRuleInList(String propertyName, String[] list) {
19: super (propertyName);
20:
21: mList = list;
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 checkInList(value, mList);
36: }
37:
38: public ValidationError getError() {
39: return new ValidationError.INVALID(getSubject());
40: }
41: }
|