001 /*
002 * Copyright 2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.apache.commons.convert;
017
018 /**
019 * Defines a class that can convert one object to an object of another type.
020 * <p>
021 * All configuration data for the conversion must be set on the converter
022 * separately.
023 *
024 * @author Stephen Colebourne
025 * @version $Id: Conversion.java 155441 2005-02-26 13:19:22Z dirkv $
026 * @since 1.0
027 */
028 public interface Conversion {
029
030 /**
031 * Convert the specified input object into an output object
032 * of the another type.
033 *
034 * @param value the value to be converted, read only, may be null
035 * @param converter the converter being used, not null
036 * @return the converted value
037 * @throws Exception if conversion fails, use ConversionException if creating
038 * a new exception, otherwise just allow exceptions to be thrown
039 */
040 Object convert(Object value, Converter converter) throws Exception;
041
042 /**
043 * The type to convert from.
044 *
045 * @return the Class object representing the class to convert to
046 */
047 Class getFromType();
048
049 /**
050 * The type to convert to.
051 *
052 * @return the Class object representing the class to convert from
053 */
054 Class getToType();
055
056 }