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 factory for Conversion objects that will create a conversion on demand
20   * or return a singleton.
21   *
22   * @author Stephen Colebourne
23   * @version $Id: ConversionFactory.java 155441 2005-02-26 13:19:22Z dirkv $
24   * @since 1.0
25   */
26  public interface ConversionFactory {
27  
28      /**
29       * Checks if this factory supports the required conversion returning a
30       * percentage match.
31       * <p>
32       * The returned <code>int</code> represents the percentage by which this
33       * factory matches the required conversion. The percentage (ie 0-100) is used
34       * to determine which conversion factory to use when a conflict arises.
35       * 
36       * @param value  the value to be converted, read only, may be null
37       * @param fromType  the type to convert from, may be null
38       * @param toType  the type to convert to, may be null
39       * @return a value between 0 and 100 inclusive, 0 means no match, 100 perfact match
40       */
41      int getMatchPercent(Object value, Class fromType, Class toType);
42  
43      /**
44       * Create a conversion object for the conversion.
45       * <p>
46       * The returned conversion must not store the value. The conversion object
47       * will be used repeatedly for all future conversions between these two types
48       * without further reference to the factory.
49       *
50       * @param value  the value to be converted, read only, may be null
51       * @param fromType  the type to convert from, may be null
52       * @param toType  the type to convert to, may be null
53       * @return a Conversion object for repeatedly performing conversions
54       */
55      Conversion getInstance(Object value, Class fromType, Class toType);
56  
57  }