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: AbstractValidationRule.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.site;
09:
10: import java.util.logging.Logger;
11:
12: import com.uwyn.rife.tools.ExceptionUtils;
13:
14: public abstract class AbstractValidationRule implements ValidationRule {
15: private Object mBean = null;
16: private String mCachedSubject = null;
17:
18: protected AbstractValidationRule() {
19: }
20:
21: abstract public boolean validate();
22:
23: abstract public ValidationError getError();
24:
25: public String getSubject() {
26: if (null == mCachedSubject) {
27: mCachedSubject = getError().getSubject();
28: }
29:
30: return mCachedSubject;
31: }
32:
33: public <T extends ValidationRule> T setBean(Object bean) {
34: mBean = bean;
35:
36: return (T) this ;
37: }
38:
39: public Object getBean() {
40: return mBean;
41: }
42:
43: public Object clone() {
44: try {
45: return super .clone();
46: } catch (CloneNotSupportedException e) {
47: ///CLOVER:OFF
48: // this should never happen
49: Logger.getLogger("com.uwyn.rife.site").severe(
50: ExceptionUtils.getExceptionStackTrace(e));
51: return null;
52: ///CLOVER:ON
53: }
54: }
55: }
|