001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005// http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.beanvalidator;
014
015import org.apache.tapestry5.MarkupWriter;
016
017import java.util.Map;
018import java.util.Set;
019
020/**
021 * Applies client-side validation constraints based on a particular JSR 303 annotation.
022 *
023 * Note: converted from a final class to an interface as part of 5.4.
024 */
025public interface ClientConstraintDescriptor
026{
027    /**
028     * The annotation class that drives this descriptor.
029     */
030    Class getAnnotationClass();
031
032    /**
033     * Names of attributes from the {@link javax.validation.metadata.ConstraintDescriptor} that are relevant.
034     */
035    Set<String> getAttributes();
036
037    /**
038     * Applies the validation
039     *
040     * @param writer
041     *         used to write new attributes into the HTML tag for the user interface element
042     * @param message
043     *         error message to present to user when the constraint is violated
044     * @param attributes
045     *         {@linkplain #getAttributes()} selected attributes} from the {@link javax.validation.metadata.ConstraintDescriptor}
046     */
047    void applyClientValidation(MarkupWriter writer, String message, Map<String, Object> attributes);
048}