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
015 package org.apache.tapestry.form.translator;
016
017 import java.util.Locale;
018
019 import org.apache.tapestry.form.FormComponentContributor;
020 import org.apache.tapestry.form.IFormComponent;
021 import org.apache.tapestry.form.ValidatableField;
022 import org.apache.tapestry.form.ValidationMessages;
023 import org.apache.tapestry.valid.ValidatorException;
024
025 /**
026 * Interface used by {@link ValidatableField}s to both format an object as text and translate
027 * submitted text into an appropriate object for a given field.
028 *
029 * @author Paul Ferraro
030 * @since 4.0
031 */
032 public interface Translator extends FormComponentContributor
033 {
034 /**
035 * Invoked during rendering to format an object (which may be null) into a text value (which
036 * should not be null) appropriate for the specified field.
037 * @param locale TODO
038 */
039 String format(IFormComponent field, Locale locale, Object object);
040
041 /**
042 * Invoked during rewind to parse a submitted input value into an object suitable for the
043 * specified component.
044 * @param messages TODO
045 *
046 * @return the parsed object
047 * @throws ValidatorException
048 * if the specified text could not be parsed into an object.
049 */
050 Object parse(IFormComponent field, ValidationMessages messages, String value) throws ValidatorException;
051 }