01: package org.conform.validator;
02:
03: import org.conform.Validator;
04: import org.conform.ValidationException;
05:
06: public class StringLengthValidator implements Validator {
07: private String message = "validation.stringlength";
08: private int length;
09:
10: public StringLengthValidator() {
11: }
12:
13: public StringLengthValidator(int length) {
14: this .length = length;
15: }
16:
17: public int getLength() {
18: return length;
19: }
20:
21: public void setLength(int length) {
22: this .length = length;
23: }
24:
25: public void setMessage(String message) {
26: this .message = message;
27: }
28:
29: public String getMessage() {
30: return message;
31: }
32:
33: public Object validate(Object value) {
34: if (value == null)
35: return null;
36:
37: String string = (String) value;
38: if (string.length() > length)
39: throw new ValidationException(
40: new ValidationException.Message(getMessage(),
41: new Object[] { value, new Integer(length) }));
42:
43: return value;
44: }
45: }
|