001// Copyright 2004, 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.coerce;
016
017/**
018 * Converts a value (possibly null) to an alternate data type; typically from String to boolean or a
019 * number type.
020 * <p>
021 * Typically, a ValueConverter will select a particular
022 * {@link org.apache.tapestry.coerce.TypeConverter}to perform the conversion. The
023 * {@link org.apache.tapestry.coerce.ValueConverterImpl}implementation also makes use of built-in
024 * {@link java.beans.PropertyEditor}s.
025 * 
026 * @author Howard M. Lewis Ship
027 * @since 4.0
028 */
029public interface ValueConverter
030{
031    /**
032     * Performs a conversion of a value to a particular type.
033     * 
034     * @param value
035     *            The value to be converted (may be null)
036     * @param desiredType
037     *            the type that will be converted to
038     * @returns the value converted to the indicated type. May return the input value if it is
039     *          already assignable to the desiredType.
040     * @throws org.apache.hivemind.ApplicationRuntimeException
041     *             if the value can not be converted
042     */
043    public Object coerceValue(Object value, Class desiredType);
044}