01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.rule.impl;
10:
11: import com.completex.objective.components.persistency.PersistentEntry;
12: import com.completex.objective.components.persistency.rule.FieldRule;
13: import com.completex.objective.components.persistency.rule.FieldValidator;
14: import com.completex.objective.components.persistency.rule.RuleException;
15:
16: /**
17: * @author Gennady Krizhevsky
18: */
19: public abstract class AbstractFieldValidator implements FieldValidator,
20: FieldRule {
21:
22: abstract protected void performValidation(PersistentEntry entry,
23: boolean verbose) throws RuleException;
24:
25: public String validate(PersistentEntry entry) throws Exception {
26: return validate(entry, false);
27: }
28:
29: public String validate(PersistentEntry entry, boolean verbose)
30: throws Exception {
31: try {
32: performValidation(entry, verbose);
33: } catch (Exception e) {
34: if (verbose) {
35: throw e;
36:
37: } else {
38: if (!(e instanceof RuleException)) {
39: throw e;
40: } else {
41: return e.getMessage();
42: }
43: }
44: }
45: return "";
46: }
47:
48: public void executeFieldRule(PersistentEntry entry)
49: throws Exception {
50: validate(entry);
51: }
52: }
|