    001// Copyright 2007, 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
    015package org.apache.tapestry5.services;
    016
    017import org.apache.tapestry5.FieldValidator;
    018import org.apache.tapestry5.ioc.AnnotationProvider;
    019import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
    020
    021import java.util.List;
    022
    023/**
    024 * Invoked to generate a list of validation constraint strings for a property. This typically involves scanning the
    025 * property for annotations or naming conventions that confer the desired validation. The constraint strings are
    026 * ultimately handed to {@link FieldValidatorSource#createValidator(org.apache.tapestry5.Field, String, String, String,
    027 * org.apache.tapestry5.ioc.Messages, java.util.Locale)}.
    028 */
    029@UsesOrderedConfiguration(ValidationConstraintGenerator.class)
    030public interface ValidationConstraintGenerator
    031{
    032    /**
    033     * For a given property, identify all the approprite validation constraints. Each returned value is the name of a
    034     * validator (i.e., "required") or a validator name and configuration (i.e., "minlength=5"). These contraints are
    035     * exactly the individual terms in a {@link FieldValidatorSource#createValidators(org.apache.tapestry5.Field,
    036     * String) validate specification}. These will ultimately be used to create {@link FieldValidator}s for the field
    037     * that edits the property.
    038     *
    039     * @param propertyType       the type of the property for which constraints are needed
    040     * @param annotationProvider provides access to any annotations concerning the property (for implementations that
    041     *                           are based on analysis of property annotations)
    042     * @return a list of constraints
    043     * @see FieldValidatorSource
    044     */
    045    List<String> buildConstraints(Class<?> propertyType, AnnotationProvider annotationProvider);
    046}