View Javadoc

1   /*
2    * Copyright 2004-2005 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package net.sf.morph.transform;
17  
18  import java.util.Locale;
19  
20  /**
21   * <p>
22   * An extension of the Converter interface that defines a few more convenient
23   * methods. All methods specified in this interface can be easily implemented
24   * using just the methods in the Converter interface. Thus, if you are defining
25   * your own converter you should implement only the Converter interface. If you
26   * extend from {@link net.sf.morph.transform.converters.BaseConverter}, your
27   * converter will implement this inteface automatically. If you don't want to
28   * extend from <code>BaseConverter</code>, you can still easily expose this
29   * interface by using the
30   * {@link net.sf.morph.transform.converters.ConverterDecorator}.
31   * </p>
32   * 
33   * <p>
34   * <em>You should not directly implement this interface, because additional
35   * methods may be introduced in later versions of Morph.  Instead, implement the
36   * Converter interface and use the ConverterDecorator to expose this
37   * interface.</em>
38   * </p>
39   * 
40   * @author Matt Sgarlata
41   * @since Dec 2, 2004
42   */
43  public interface DecoratedConverter extends Converter, DecoratedTransformer {
44  
45  	/**
46  	 * Converts the given <code>source</code> into an object of class
47  	 * <code>destinationClass</code>. The returned object may be a reference
48  	 * to <code>source</code> itself. This isn't an issue for immutable
49  	 * classes (String, Long, etc) but is an issue for Collection and Array
50  	 * types. Equivalent to calling
51  	 * <code>convert(destinationClass, source, Locale.getDefault())</code>.
52  	 * 
53  	 * @param destinationClass
54  	 *            the destination class to test
55  	 * @param source
56  	 *            the source object to test
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)
63  		throws TransformationException;
64  
65  	/**
66  	 * Tests if object1 and object2 are equivalent with respect to this
67  	 * converter. Specifically, this method returns <code>true</code> if
68  	 * either object1 can be converted to object2 or object2 can be converted to
69  	 * object1.
70  	 * 
71  	 * @param object1
72  	 *            the first object to test for equality
73  	 * @param object2
74  	 *            the second object to test for equality
75  	 * @param locale
76  	 *            the locale in which conversions take place
77  	 * @throws TransformationException
78  	 *             if an error occurred while performing the conversions
79  	 */
80  	public boolean equals(Object object1, Object object2, Locale locale)
81  		throws TransformationException;
82  
83  	/**
84  	 * Tests if object1 and object2 are equivalent with respect to this
85  	 * converter. Specifically, this method returns <code>true</code> if
86  	 * either object1 can be converted to object2 or object2 can be converted to
87  	 * object1. Equivalent to calling
88  	 * <code>equals(object, object2, Locale.getDefault)</code>.
89  	 * 
90  	 * @param object1
91  	 *            the first object to test for equality
92  	 * @param object2
93  	 *            the second object to test for equality
94  	 * @throws TransformationException
95  	 *             if an error occurred while performing the conversions
96  	 */
97  	public boolean equals(Object object1, Object object2)
98  		throws TransformationException;
99  
100 }