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("NUMBER_FORMAT");
067    
068        /**
069         * Indicates that the value was too small (for a Date, too early).
070         */
071    
072        public static final ValidationConstraint TOO_SMALL = new ValidationConstraint("TOO_SMALL");
073    
074        /**
075         * Indicates that the value was too large (for a Date, too late).
076         */
077    
078        public static final ValidationConstraint TOO_LARGE = new ValidationConstraint("TOO_LARGE");
079    
080        /**
081         * Indicates an error in a string that does not fulfill a pattern.
082         * 
083         * @since 3.0
084         */
085    
086        public static final ValidationConstraint PATTERN_MISMATCH = new ValidationConstraint(
087                "PATTERN_MISMATCH");
088    
089        /**
090         * Indicates a consistency error, usually between too different fields.
091         * 
092         * @since 3.0
093         */
094    
095        public static final ValidationConstraint CONSISTENCY = new ValidationConstraint("CONSISTENCY");
096    
097        /**
098         * Indicates that a URL is not of the correct format.
099         * 
100         * @since 3.0
101         */
102    
103        public static final ValidationConstraint URL_FORMAT = new ValidationConstraint("URL_FORMAT");
104    
105        /**
106         * Indicates that the URL does not use one of the specified protocols.
107         * 
108         * @since 3.0
109         */
110    
111        public static final ValidationConstraint DISALLOWED_PROTOCOL = new ValidationConstraint(
112                "DISALLOWED_PROTOCOL");
113    
114        private static final long serialVersionUID = 371593028205311930L;
115        
116        private final String _name;
117    
118        /**
119         * Protected constructor, which allows new constraints to be created as subclasses.
120         */
121    
122        protected ValidationConstraint(String name)
123        {
124            _name = name;
125        }
126    
127        public String toString()
128        {
129            return "ValidationConstraint[" + _name + "]";
130        }
131    }