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.util.Locale;
20:
21: /**
22: * <p>A "not null" constraint. Syntax is:</p>
23: * <pre>
24: * <<i>column</i> not-null="true"/>
25: * </pre>
26: *<p>Or:</p><pre>
27: * <<i>column</i>>
28: * <not-null [message="<i>error-message</i>"]/>
29: * </<i>column</i>></pre>
30: * <p>To validate data coming from an HTML form, you should rather use the not-empty constraint since there cannot
31: * be any null value.</p>
32: * <p>Note: this constraint is not meant to replace an internal SQL "not-null" clause in the database,
33: * since it cannot be made sure that complex updates will respect this constraint.</p>
34: *
35: * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a>
36: */
37: public class NotNull extends FieldConstraint {
38:
39: /**
40: * Default constructor.
41: */
42: public NotNull() {
43: setMessage("field {0} cannot be null");
44: }
45:
46: /**
47: * Validate datea against this constraint.
48: * @param data the data to be validated
49: * @return true if data is not null
50: */
51: public boolean validate(Object data) {
52: return data != null;
53: }
54:
55: /**
56: * return a string representation for this constraint.
57: * @return string
58: */
59: public String toString() {
60: return "not-null";
61: }
62: }
|