01: /*
02: * Created on 12 Sep 2007
03: */
04: package uk.org.ponder.springutil.validator.support;
05:
06: import org.springframework.validation.Errors;
07: import org.springframework.validation.Validator;
08:
09: import uk.org.ponder.springutil.validator.ValidatorCodeReceiver;
10:
11: public abstract class ValidatorBase implements Validator,
12: ValidatorCodeReceiver {
13: protected String messageCode;
14: private String offsetPath;
15: private int priority;
16: private Object[] messageArgs;
17:
18: public int getPriority() {
19: return priority;
20: }
21:
22: public void setPriority(int priority) {
23: this .priority = priority;
24: }
25:
26: public String getOffsetPath() {
27: return offsetPath;
28: }
29:
30: public void setOffsetPath(String offsetPath) {
31: this .offsetPath = offsetPath;
32: }
33:
34: public void setMessageCode(String code) {
35: this .messageCode = code;
36: }
37:
38: public void setMessageArgs(Object[] args) {
39: this .messageArgs = args;
40: }
41:
42: public boolean supports(Class clazz) {
43: return true;
44: }
45:
46: public void reject(Errors errors, String defaultCode) {
47: String code = messageCode == null ? defaultCode : messageCode;
48: if (messageArgs == null) {
49: errors.rejectValue(null, code);
50: } else {
51: errors.rejectValue(null, code, messageArgs, null);
52: }
53: }
54:
55: }
|