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