1 /* 2 * Copyright 2002-2006 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.springframework.binding.convert; 17 18 /** 19 * A type converter converts objects from one type to another. They may support 20 * conversion of multiple source types to multiple target types. 21 * <p> 22 * Implementations of this interface are thread-safe. 23 * @author Keith Donald 24 */ 25 public interface Converter { 26 27 /** 28 * The source classes this converter can convert from. 29 * @return The supported source classes. 30 */ 31 public Class[] getSourceClasses(); 32 33 /** 34 * The target classes this converter can convert to. 35 * @return The supported target classes. 36 */ 37 public Class[] getTargetClasses(); 38 39 /** 40 * Convert the provided source object argument to an instance of the 41 * specified target class. 42 * 43 * @param source the source object to convert, its class must be one of the 44 * supported <code>sourceClasses</code> 45 * @param targetClass the target class to convert the source to, must be one 46 * of the supported <code>targetClasses</code> 47 * @param context an optional conversion context that may be used to 48 * influence the conversion process. 49 * @return The converted object, an instance of the default target type 50 * @throws ConversionException An exception occured during the conversion 51 */ 52 public Object convert(Object source, Class targetClass, ConversionContext context) throws ConversionException; 53 54 }