1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.converters;
18
19 import org.apache.commons.beanutils.Converter;
20
21 /***
22 * Provides a facade for {@link Converter} implementations
23 * preventing access to any public API in the implementation,
24 * other than that specified by {@link Converter}.
25 * <p />
26 * This implementation can be used to prevent registered {@link Converter}
27 * implementations that provide configuration options from being
28 * retrieved and modified.
29 *
30 * @version $Revision: 552084 $ $Date: 2007-06-30 04:04:13 +0100 (Sat, 30 Jun 2007) $
31 * @since 1.8.0
32 */
33 public final class ConverterFacade implements Converter {
34
35 private final Converter converter;
36
37 /***
38 * Construct a converter which delegates to the specified
39 * {@link Converter} implementation.
40 *
41 * @param converter The converter to delegate to
42 */
43 public ConverterFacade(Converter converter) {
44 if (converter == null) {
45 throw new IllegalArgumentException("Converter is missing");
46 }
47 this.converter = converter;
48 }
49
50 /***
51 * Convert the input object into an output object of the
52 * specified type by delegating to the underlying {@link Converter}
53 * implementation.
54 *
55 * @param type Data type to which this value should be converted
56 * @param value The input value to be converted
57 * @return The converted value.
58 */
59 public Object convert(Class type, Object value) {
60 return converter.convert(type, value);
61 }
62
63 /***
64 * Provide a String representation of this facade implementation
65 * sand the underlying {@link Converter} it delegates to.
66 *
67 * @return A String representation of this facade implementation
68 * sand the underlying {@link Converter} it delegates to
69 */
70 public String toString() {
71 return "ConverterFacade[" + converter.toString() + "]";
72 }
73
74 }