|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ValidationConstraint.java | - | 50% | 50% | 50% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.valid; | |
16 | ||
17 | import java.io.Serializable; | |
18 | ||
19 | /** | |
20 | * Defines an enumeration of different types of validation constraints that may be violated. | |
21 | * | |
22 | * @author Howard Lewis Ship | |
23 | */ | |
24 | ||
25 | public class ValidationConstraint implements Serializable | |
26 | { | |
27 | private static final long serialVersionUID = 371593028205311930L; | |
28 | ||
29 | /** | |
30 | * Indicates that no value (or a value consisting only of white space) was provided for a field | |
31 | * that requires a non-null value. | |
32 | */ | |
33 | ||
34 | public static final ValidationConstraint REQUIRED = new ValidationConstraint("REQUIRED"); | |
35 | ||
36 | /** | |
37 | * Indicates that a non-null value was provided, but that (after removing leading and trailing | |
38 | * whitespace), the value was not long enough. | |
39 | */ | |
40 | ||
41 | public static final ValidationConstraint MINIMUM_WIDTH = new ValidationConstraint( | |
42 | "MINIMUM_WIDTH"); | |
43 | ||
44 | /** | |
45 | * Indicates that a non-null value was provided, but that (after removing leading and trailing | |
46 | * whitespace), the value was too long. | |
47 | */ | |
48 | ||
49 | public static final ValidationConstraint MAXIMUM_WIDTH = new ValidationConstraint( | |
50 | "MAXIMUM_WIDTH"); | |
51 | ||
52 | /** | |
53 | * Indicates a general error in converting a String into a Date. | |
54 | */ | |
55 | ||
56 | public static final ValidationConstraint DATE_FORMAT = new ValidationConstraint("DATE_FORMAT"); | |
57 | ||
58 | /** | |
59 | * Indicates a general error in the format of a string that is to be interpreted as a email. | |
60 | */ | |
61 | ||
62 | public static final ValidationConstraint EMAIL_FORMAT = new ValidationConstraint("EMAIL_FORMAT"); | |
63 | ||
64 | /** | |
65 | * Indicates a general error in the format of a string that is to be interpreted as a number. | |
66 | */ | |
67 | ||
68 | public static final ValidationConstraint NUMBER_FORMAT = new ValidationConstraint( | |
69 | "NUMBER_FORMAT"); | |
70 | ||
71 | /** | |
72 | * Indicates that the value was too small (for a Date, too early). | |
73 | */ | |
74 | ||
75 | public static final ValidationConstraint TOO_SMALL = new ValidationConstraint("TOO_SMALL"); | |
76 | ||
77 | /** | |
78 | * Indicates that the value was too large (for a Date, too late). | |
79 | */ | |
80 | ||
81 | public static final ValidationConstraint TOO_LARGE = new ValidationConstraint("TOO_LARGE"); | |
82 | ||
83 | /** | |
84 | * Indicates an error in a string that does not fulfill a pattern. | |
85 | * | |
86 | * @since 3.0 | |
87 | */ | |
88 | ||
89 | public static final ValidationConstraint PATTERN_MISMATCH = new ValidationConstraint( | |
90 | "PATTERN_MISMATCH"); | |
91 | ||
92 | /** | |
93 | * Indicates a consistency error, usually between too different fields. | |
94 | * | |
95 | * @since 3.0 | |
96 | */ | |
97 | ||
98 | public static final ValidationConstraint CONSISTENCY = new ValidationConstraint("CONSISTENCY"); | |
99 | ||
100 | /** | |
101 | * Indicates that a URL is not of the correct format | |
102 | * | |
103 | * @since 3.0 | |
104 | */ | |
105 | ||
106 | public static final ValidationConstraint URL_FORMAT = new ValidationConstraint("URL_FORMAT"); | |
107 | ||
108 | /** | |
109 | * Indicates that the URL does not use one of the specified protocols | |
110 | * | |
111 | * @since 3.0 | |
112 | */ | |
113 | ||
114 | public static final ValidationConstraint DISALLOWED_PROTOCOL = new ValidationConstraint( | |
115 | "DISALLOWED_PROTOCOL"); | |
116 | ||
117 | private final String _name; | |
118 | ||
119 | /** | |
120 | * Protected constructor, which allows new constraints to be created as subclasses. | |
121 | */ | |
122 | ||
123 | 24 | protected ValidationConstraint(String name) |
124 | { | |
125 | 24 | _name = name; |
126 | } | |
127 | ||
128 | 0 | public String toString() |
129 | { | |
130 | 0 | return "ValidationConstraint[" + _name + "]"; |
131 | } | |
132 | } |
|