01: /*
02: * Copyright 2003 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package velosurf.validation;
18:
19: import java.sql.SQLException;
20: import java.util.Locale;
21:
22: /**
23: * <p>This class encapsulates a constraint on a column of an entity, used to validate data
24: * before an update or an insert.</p>
25: *
26: * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
27: */
28: public abstract class FieldConstraint {
29:
30: /**
31: * validate data against this constraint.
32: * @param data to validate
33: * @param locale
34: * @return true if the data respects the constraint
35: */
36: public boolean validate(Object data, Locale locale)
37: throws SQLException {
38: return validate(data);
39: }
40:
41: /**
42: * validate data against this constraint.
43: * @param data data to validate
44: * @return true if data respects the constaint
45: * @throws SQLException
46: */
47: public boolean validate(Object data) throws SQLException {
48: return false;
49: }
50:
51: /** the error message */
52: private String message = null;
53:
54: /** error message setter
55: *
56: * @param msg error message
57: */
58: public void setMessage(String msg) {
59: message = msg;
60: }
61:
62: /**
63: * get the error message
64: * @return the error message
65: */
66: public String getMessage() {
67: return message;
68: }
69:
70: }
|