1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.coerce; |
16 |
| |
17 |
| import java.util.Iterator; |
18 |
| import java.util.List; |
19 |
| |
20 |
| import org.apache.hivemind.lib.util.StrategyRegistry; |
21 |
| import org.apache.hivemind.lib.util.StrategyRegistryImpl; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public final class TypeConverterWrapper implements TypeConverter |
34 |
| { |
35 |
| private StrategyRegistry _registry = new StrategyRegistryImpl(); |
36 |
| |
37 |
| private List _contributions; |
38 |
| |
39 |
| private TypeConverter _nullConverter; |
40 |
| |
41 |
40
| public void initializeService()
|
42 |
| { |
43 |
40
| Iterator i = _contributions.iterator();
|
44 |
| |
45 |
40
| while (i.hasNext())
|
46 |
| { |
47 |
231
| TypeConverterContribution c = (TypeConverterContribution) i.next();
|
48 |
| |
49 |
231
| _registry.register(c.getSubjectClass(), c.getConverter());
|
50 |
| } |
51 |
| } |
52 |
| |
53 |
233
| public Object convertValue(Object value)
|
54 |
| { |
55 |
233
| if (value == null)
|
56 |
| { |
57 |
126
| if (_nullConverter == null)
|
58 |
1
| return null;
|
59 |
| |
60 |
125
| return _nullConverter.convertValue(null);
|
61 |
| } |
62 |
| |
63 |
107
| TypeConverter delegate = (TypeConverter) _registry.getStrategy(value.getClass());
|
64 |
| |
65 |
107
| return delegate.convertValue(value);
|
66 |
| } |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
40
| public void setContributions(List contributions)
|
73 |
| { |
74 |
40
| _contributions = contributions;
|
75 |
| } |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
40
| public void setNullConverter(TypeConverter nullConverter)
|
82 |
| { |
83 |
40
| _nullConverter = nullConverter;
|
84 |
| } |
85 |
| } |