View Javadoc

1   /*
2    *  Copyright 2004 The Apache Software Foundation
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.apache.commons.convert;
17  
18  /**
19   * Defines a class that can convert one object to an object of another type.
20   * <p>
21   * All configuration data for the conversion must be set on the converter
22   * separately.
23   *
24   * @author Stephen Colebourne
25   * @version $Id: Conversion.java 155441 2005-02-26 13:19:22Z dirkv $
26   * @since 1.0
27   */
28  public interface Conversion {
29  
30      /**
31       * Convert the specified input object into an output object
32       * of the another type.
33       *
34       * @param value  the value to be converted, read only, may be null
35       * @param converter  the converter being used, not null
36       * @return the converted value
37       * @throws Exception if conversion fails, use ConversionException if creating
38       *  a new exception, otherwise just allow exceptions to be thrown
39       */
40      Object convert(Object value, Converter converter) throws Exception;
41  
42      /**
43       * The type to convert from.
44       *
45       * @return the Class object representing the class to convert to
46       */
47      Class getFromType();
48  
49      /**
50       * The type to convert to.
51       *
52       * @return the Class object representing the class to convert from
53       */
54      Class getToType();
55  
56  }