001    // Copyright 2008 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.tapestry5.validator;
016    
017    import org.apache.tapestry5.Validator;
018    
019    /**
020     * Base class for constructing a {@link org.apache.tapestry5.Validator}.
021     */
022    public abstract class AbstractValidator<C, T> implements Validator<C, T>
023    {
024        private final Class<C> constraintType;
025    
026        private final Class<T> valueType;
027    
028        private final String messageKey;
029    
030        protected AbstractValidator(Class<C> constraintType, Class<T> valueType, String messageKey)
031        {
032            this.constraintType = constraintType;
033            this.valueType = valueType;
034            this.messageKey = messageKey;
035        }
036    
037        public final Class<C> getConstraintType()
038        {
039            return constraintType;
040        }
041    
042        public final Class<T> getValueType()
043        {
044            return valueType;
045        }
046    
047        public final String getMessageKey()
048        {
049            return messageKey;
050        }
051    
052        /**
053         * Return false, which is correct for the vast majority of validators. {@link org.apache.tapestry5.validator.Required}
054         * overrides this to true.F
055         */
056        public boolean isRequired()
057        {
058            return false;
059        }
060    }