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        private static final long serialVersionUID = 371593028205311930L;
028    
029        /**
030         * Indicates that no value (or a value consisting only of white space) was provided for a field
031         * that requires a non-null value.
032         */
033    
034        public static final ValidationConstraint REQUIRED = new ValidationConstraint("REQUIRED");
035    
036        /**
037         * Indicates that a non-null value was provided, but that (after removing leading and trailing
038         * whitespace), the value was not long enough.
039         */
040    
041        public static final ValidationConstraint MINIMUM_WIDTH = new ValidationConstraint(
042                "MINIMUM_WIDTH");
043    
044        /**
045         * Indicates that a non-null value was provided, but that (after removing leading and trailing
046         * whitespace), the value was too long.
047         */
048    
049        public static final ValidationConstraint MAXIMUM_WIDTH = new ValidationConstraint(
050                "MAXIMUM_WIDTH");
051    
052        /**
053         * Indicates a general error in converting a String into a Date.
054         */
055    
056        public static final ValidationConstraint DATE_FORMAT = new ValidationConstraint("DATE_FORMAT");
057    
058        /**
059         * Indicates a general error in the format of a string that is to be interpreted as a email.
060         */
061    
062        public static final ValidationConstraint EMAIL_FORMAT = new ValidationConstraint("EMAIL_FORMAT");
063    
064        /**
065         * Indicates a general error in the format of a string that is to be interpreted as a number.
066         */
067    
068        public static final ValidationConstraint NUMBER_FORMAT = new ValidationConstraint(
069                "NUMBER_FORMAT");
070    
071        /**
072         * Indicates that the value was too small (for a Date, too early).
073         */
074    
075        public static final ValidationConstraint TOO_SMALL = new ValidationConstraint("TOO_SMALL");
076    
077        /**
078         * Indicates that the value was too large (for a Date, too late).
079         */
080    
081        public static final ValidationConstraint TOO_LARGE = new ValidationConstraint("TOO_LARGE");
082    
083        /**
084         * Indicates an error in a string that does not fulfill a pattern.
085         * 
086         * @since 3.0
087         */
088    
089        public static final ValidationConstraint PATTERN_MISMATCH = new ValidationConstraint(
090                "PATTERN_MISMATCH");
091    
092        /**
093         * Indicates a consistency error, usually between too different fields.
094         * 
095         * @since 3.0
096         */
097    
098        public static final ValidationConstraint CONSISTENCY = new ValidationConstraint("CONSISTENCY");
099    
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        protected ValidationConstraint(String name)
124        {
125            _name = name;
126        }
127    
128        public String toString()
129        {
130            return "ValidationConstraint[" + _name + "]";
131        }
132    }