001// Copyright 2005 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.tapestry.form.validator;
016
017import java.util.List;
018
019import org.apache.tapestry.IComponent;
020
021/**
022 * Constructs {@link org.apache.tapestry.form.validator.Validator} instances from a specification. A
023 * specification is a comma-seperated list of entries. Each entry is in one of the following forms:
024 * <ul>
025 * <li><em>name</em>
026 * <li><em>name</em>=<em>value</em>
027 * <li><em>name[<em>message</em>]</em>
028 * <li><em>name</em>=<em>value</em>[<em>message</em>]
029 * <li>$<em>name</em>
030 * </ul>
031 * <p>
032 * Most validator classes are <em>configurable</em>: they have a property that matches their
033 * name. For example, {@link org.apache.tapestry.form.validator.MinDate} (which is named "minDate"
034 * has a <code>minDate</code> property. A few validators are not configurable ("required" =>
035 * {@link org.apache.tapestry.form.validator.Required}, for example).
036 * <p>
037 * Validators are expected to have a public no-args constructor. They are also expected to have a
038 * <code>message</code> property which is set from the value in brackets.
039 * The message is either a literal string, or may be prefixed with a '%' character, to indicate
040 * a localized key, resolved using the component's message catalog.
041 * <p>
042 * When the name is prefixed with a dollary sign, it indicates a reference to a <em>bean</em>
043 * with the given name.
044 * <p>
045 * A full validator specification might be:
046 * <code>required,email[%email-format],minLength=20[Email addresses must be at least 20 characters long.]
047 * 
048 * @author Howard Lewis Ship
049 * @since 4.0
050 */
051public interface ValidatorFactory
052{
053    /**
054     * Constructs a new (immutable) List of {@link Validator}, or returns a previously constructed
055     * List.
056     * 
057     * @param component
058     *            the component for which the list is being created
059     * @param specification
060     *            a string identifying which validators and their configuration
061     * @return List of {@link Validator} (possibly empty)
062     */
063    public List constructValidatorList(IComponent component, String specification);
064}