001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.valid;
016
017 import java.io.Serializable;
018
019 /**
020 * Defines an enumeration of different types of validation constraints that may be violated.
021 *
022 * @author Howard Lewis Ship
023 */
024
025 public class ValidationConstraint implements Serializable
026 {
027 /**
028 * Indicates that no value (or a value consisting only of white space) was provided for a field
029 * that requires a non-null value.
030 */
031
032 public static final ValidationConstraint REQUIRED = new ValidationConstraint("REQUIRED");
033
034 /**
035 * Indicates that a non-null value was provided, but that (after removing leading and trailing
036 * whitespace), the value was not long enough.
037 */
038
039 public static final ValidationConstraint MINIMUM_WIDTH = new ValidationConstraint(
040 "MINIMUM_WIDTH");
041
042 /**
043 * Indicates that a non-null value was provided, but that (after removing leading and trailing
044 * whitespace), the value was too long.
045 */
046
047 public static final ValidationConstraint MAXIMUM_WIDTH = new ValidationConstraint(
048 "MAXIMUM_WIDTH");
049
050 /**
051 * Indicates a general error in converting a String into a Date.
052 */
053
054 public static final ValidationConstraint DATE_FORMAT = new ValidationConstraint("DATE_FORMAT");
055
056 /**
057 * Indicates a general error in the format of a string that is to be interpreted as a email.
058 */
059
060 public static final ValidationConstraint EMAIL_FORMAT = new ValidationConstraint("EMAIL_FORMAT");
061
062 /**
063 * Indicates a general error in the format of a string that is to be interpreted as a number.
064 */
065
066 public static final ValidationConstraint NUMBER_FORMAT = new ValidationConstraint(
067 "NUMBER_FORMAT");
068
069 /**
070 * Indicates that the value was too small (for a Date, too early).
071 */
072
073 public static final ValidationConstraint TOO_SMALL = new ValidationConstraint("TOO_SMALL");
074
075 /**
076 * Indicates that the value was too large (for a Date, too late).
077 */
078
079 public static final ValidationConstraint TOO_LARGE = new ValidationConstraint("TOO_LARGE");
080
081 /**
082 * Indicates an error in a string that does not fulfill a pattern.
083 *
084 * @since 3.0
085 */
086
087 public static final ValidationConstraint PATTERN_MISMATCH = new ValidationConstraint(
088 "PATTERN_MISMATCH");
089
090 /**
091 * Indicates a consistency error, usually between too different fields.
092 *
093 * @since 3.0
094 */
095
096 public static final ValidationConstraint CONSISTENCY = new ValidationConstraint("CONSISTENCY");
097
098 /**
099 * Indicates that a URL is not of the correct format.
100 *
101 * @since 3.0
102 */
103
104 public static final ValidationConstraint URL_FORMAT = new ValidationConstraint("URL_FORMAT");
105
106 /**
107 * Indicates that the URL does not use one of the specified protocols.
108 *
109 * @since 3.0
110 */
111
112 public static final ValidationConstraint DISALLOWED_PROTOCOL = new ValidationConstraint(
113 "DISALLOWED_PROTOCOL");
114
115 private static final long serialVersionUID = 371593028205311930L;
116
117 private final String _name;
118
119 /**
120 * Protected constructor, which allows new constraints to be created as subclasses.
121 */
122
123 protected ValidationConstraint(String name)
124 {
125 _name = name;
126 }
127
128 public String toString()
129 {
130 return "ValidationConstraint[" + _name + "]";
131 }
132 }