1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package net.sf.morph.transform;
17  
18  import java.util.Locale;
19  
20  /**
21   * <p>
22   * An object that can convert one type of object into another type of object.
23   * Usually, the sourceClasses and destinationClasses attributes determine the
24   * set of sources and destinations which the converter can convert.  However,
25   * if any of the sourceClasses is not convertible to a destinationClass, then
26   * a converter may implement the {@link net.sf.morph.transform.ExplicitTransformer}
27   * to explicitly define which sources are convertible to which destinations.
28   * </p>
29   *  
30   * <p>
31   * Note that the Converter interface can be easily implemented by a Copier (see
32   * {@link net.sf.morph.transform.converters.CopierConverter}), so it is
33   * recommended that Converters only be implemented for basic data types
34   * (numbers, primitives) or immutable data types (e.g. Strings, but note Dates).
35   * </p>
36   * 
37   * @author Matt Sgarlata
38   * @since October 24, 2004
39   * @see net.sf.morph.transform.ExplicitTransformer
40   */
41  public interface Converter extends Transformer {
42  	
43  	/**
44  	 * Converts the given <code>source</code> into an object of class
45  	 * <code>destinationClass</code>. The returned object may be a reference
46  	 * to <code>source</code> itself. This isn't an issue for immutable
47  	 * classes (String, Long, etc) but is an issue for Collection and Array
48  	 * types.
49  	 * 
50  	 * @param destinationClass
51  	 *            the destination class to test
52  	 * @param source
53  	 *            the source object to test
54  	 * @param locale
55  	 *            the locale in which the conversion should take place, or
56  	 *            <code>null</code> if the locale is not applicable
57  	 * @return the result of the conversion
58  	 * @throws TransformationException
59  	 *             if <code>destinationClass</code> is <code>null</code>,
60  	 *             an error occurred while performing the conversion
61  	 */
62  	public Object convert(Class destinationClass, Object source, Locale locale)
63  		throws TransformationException;
64  }