1 // Copyright 2004, 2005 The Apache Software Foundation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package org.apache.tapestry.coerce; 16 17 /** 18 * Converts a value (possibly null) to an alternate data type; typically from String to boolean or a 19 * number type. 20 * <p> 21 * Typically, a ValueConverter will select a particular 22 * {@link org.apache.tapestry.coerce.TypeConverter}to perform the conversion. The 23 * {@link org.apache.tapestry.coerce.ValueConverterImpl}implementation also makes use of built-in 24 * {@link java.beans.PropertyEditor}s. 25 * 26 * @author Howard M. Lewis Ship 27 * @since 4.0 28 */ 29 public interface ValueConverter 30 { 31 /** 32 * Performs a conversion of a value to a particular type. 33 * 34 * @param value 35 * The value to be converted (may be null) 36 * @param desiredType 37 * the type that will be converted to 38 * @returns the value converted to the indicated type. May return the input value if it is 39 * already assignable to the desiredType. 40 * @throws org.apache.hivemind.ApplicationRuntimeException 41 * if the value can not be converted 42 */ 43 public Object coerceValue(Object value, Class desiredType); 44 }