001// Copyright 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.beanvalidator;
016
017import org.apache.tapestry5.MarkupWriter;
018
019import java.util.Map;
020import java.util.Set;
021
022/**
023 * Applies client-side validation constraints based on a particular JSR 303 annotation.
024 * <p/>
025 * Note: converted from a final class to an interface as part of 5.4.
026 */
027public interface ClientConstraintDescriptor
028{
029    /**
030     * The annotation class that drives this descriptor.
031     */
032    Class getAnnotationClass();
033
034    /**
035     * Names of attributes from the {@link javax.validation.metadata.ConstraintDescriptor} that are relevant.
036     */
037    Set<String> getAttributes();
038
039    /**
040     * Applies the validation
041     *
042     * @param writer
043     *         used to write new attributes into the HTML tag for the user interface element
044     * @param message
045     *         error message to present to user when the constraint is violated
046     * @param attributes
047     *         {@linkplain #getAttributes()} selected attributes} from the {@link javax.validation.metadata.ConstraintDescriptor}
048     */
049    void applyClientValidation(MarkupWriter writer, String message, Map<String, Object> attributes);
050}