001 // Copyright 2007, 2008, 2011 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.services;
016
017 import org.apache.tapestry5.ComponentResources;
018 import org.apache.tapestry5.Field;
019 import org.apache.tapestry5.FieldValidator;
020 import org.apache.tapestry5.ioc.AnnotationProvider;
021 import org.apache.tapestry5.ioc.Messages;
022
023 import java.util.Locale;
024
025 /**
026 * For a particular field, generates the default validation for the field, in accordance with a number of factors and
027 * contributions.
028 */
029 public interface FieldValidatorDefaultSource
030 {
031 /**
032 * Analyzes the property type and property annotations to determine the default set of validations for the property,
033 * which are wrapped to form a {@link org.apache.tapestry5.FieldValidator} for a field.
034 *
035 * @param field
036 * Field component for which a validator is being created
037 * @param overrideId
038 * the id of the component, used to locate related messages for labels and errors
039 * @param overrideMessages
040 * where to search for label and error messages
041 * @param locale
042 * locale used for locating messages
043 * @param propertyType
044 * type of property bound to the editting parameter of the field (typically, the
045 * parameter named "value").
046 * @param propertyAnnotations
047 * source of annotations for the property being editted
048 * @return a validator reflecting all default validations for the field
049 */
050 FieldValidator createDefaultValidator(Field field, String overrideId, Messages overrideMessages, Locale locale,
051 Class propertyType, AnnotationProvider propertyAnnotations);
052
053 /**
054 * A convenience for the full version; assumes that the resources are associated with a
055 * {@link org.apache.tapestry5.Field}.
056 *
057 * @param resources
058 * @param parameterName
059 * @return a validator reflecting all default validations for the field
060 */
061 FieldValidator createDefaultValidator(ComponentResources resources, String parameterName);
062 }