1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
package net.smartlab.web.bean; |
25 |
|
|
26 |
|
import java.math.BigDecimal; |
27 |
|
import java.util.HashMap; |
28 |
|
import java.util.Locale; |
29 |
|
import java.util.Map; |
30 |
|
import net.smartlab.web.Enumeration; |
31 |
|
import net.smartlab.web.StringEnumeration; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@author |
37 |
|
|
|
|
| 90,5% |
Uncovered Elements: 6 (63) |
Complexity: 9 |
Complexity Density: 0,18 |
|
38 |
|
public class ConverterManager { |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private Map converters = new HashMap(); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@param |
51 |
|
@param |
52 |
|
@param |
53 |
|
@return |
54 |
|
@throws |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0,62 |
|
56 |
52
|
public Object convert(Class type, Object value, Locale locale) throws ConversionException {... |
57 |
52
|
if (value != null) { |
58 |
28
|
try { |
59 |
28
|
if (type.isArray()) { |
60 |
14
|
return this.getConverter(type).convert(type, value, locale); |
61 |
|
} else { |
62 |
14
|
if (type.equals(String.class)) { |
63 |
7
|
return this.getConverter(value.getClass()).convert(type, value, locale); |
64 |
|
} else { |
65 |
7
|
return this.getConverter(type).convert(type, value, locale); |
66 |
|
} |
67 |
|
} |
68 |
|
} catch (NullPointerException npe) { |
69 |
|
throw new ConversionException("unavailable converter for " + type); |
70 |
|
} |
71 |
|
} else { |
72 |
24
|
return null; |
73 |
|
} |
74 |
|
} |
75 |
|
|
|
|
| 40% |
Uncovered Elements: 6 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
76 |
28
|
private Converter getConverter(Class type) throws ConversionException {... |
77 |
28
|
Converter converter = (Converter)converters.get(type); |
78 |
28
|
if (converter == null) { |
79 |
0
|
if (type.equals(Object.class)) { |
80 |
0
|
throw new ConversionException(); |
81 |
|
} else { |
82 |
0
|
return getConverter(type.getSuperclass()); |
83 |
|
} |
84 |
|
} else { |
85 |
28
|
return converter; |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@return |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 1 |
Complexity Density: 0,03 |
|
94 |
1
|
static public ConverterManager getDefault() {... |
95 |
1
|
ConverterManager manager = new ConverterManager(); |
96 |
|
|
97 |
|
|
98 |
1
|
manager.converters.put(java.lang.Boolean.TYPE, new BooleanConverter(false)); |
99 |
1
|
manager.converters.put(java.lang.Boolean.class, new BooleanConverter(false)); |
100 |
1
|
manager.converters.put(boolean[].class, new BooleanArrayConverter()); |
101 |
|
|
102 |
|
|
103 |
1
|
manager.converters.put(java.lang.Character.TYPE, new CharConverter()); |
104 |
1
|
manager.converters.put(java.lang.Character.class, new CharConverter()); |
105 |
1
|
manager.converters.put(char[].class, new CharArrayConverter()); |
106 |
|
|
107 |
|
|
108 |
1
|
manager.converters.put(java.lang.Byte.TYPE, new ByteConverter((byte)0)); |
109 |
1
|
manager.converters.put(java.lang.Byte.class, new ByteConverter((byte)0)); |
110 |
1
|
manager.converters.put(byte[].class, new ByteArrayConverter()); |
111 |
|
|
112 |
|
|
113 |
1
|
manager.converters.put(java.lang.Short.TYPE, new ShortConverter((short)0)); |
114 |
1
|
manager.converters.put(java.lang.Short.class, new ShortConverter((short)0)); |
115 |
1
|
manager.converters.put(short[].class, new ShortArrayConverter()); |
116 |
|
|
117 |
|
|
118 |
1
|
manager.converters.put(java.lang.Integer.TYPE, new IntConverter(0)); |
119 |
1
|
manager.converters.put(java.lang.Integer.class, new IntConverter(0)); |
120 |
1
|
manager.converters.put(int[].class, new IntArrayConverter()); |
121 |
|
|
122 |
|
|
123 |
1
|
manager.converters.put(java.lang.Long.TYPE, new LongConverter(0)); |
124 |
1
|
manager.converters.put(java.lang.Long.class, new LongConverter(0)); |
125 |
1
|
manager.converters.put(long[].class, new LongArrayConverter()); |
126 |
|
|
127 |
|
|
128 |
1
|
manager.converters.put(java.lang.Float.TYPE, new FloatConverter(0)); |
129 |
1
|
manager.converters.put(java.lang.Float.class, new FloatConverter(0)); |
130 |
1
|
manager.converters.put(float[].class, new FloatArrayConverter()); |
131 |
|
|
132 |
|
|
133 |
1
|
manager.converters.put(java.lang.Double.TYPE, new DoubleConverter(0)); |
134 |
1
|
manager.converters.put(java.lang.Double.class, new DoubleConverter(0)); |
135 |
1
|
manager.converters.put(double[].class, new DoubleArrayConverter()); |
136 |
|
|
137 |
|
|
138 |
1
|
manager.converters.put(java.lang.String.class, new StringConverter()); |
139 |
1
|
manager.converters.put(String[].class, new StringArrayConverter()); |
140 |
|
|
141 |
|
|
142 |
1
|
manager.converters.put(java.util.Date.class, new DateConverter()); |
143 |
1
|
manager.converters.put(java.sql.Date.class, new DateConverter()); |
144 |
1
|
manager.converters.put(java.sql.Time.class, new TimeConverter()); |
145 |
1
|
manager.converters.put(java.sql.Timestamp.class, new DateTimeConverter()); |
146 |
|
|
147 |
|
|
148 |
1
|
manager.converters.put(Enumeration.class, new EnumerationConverter()); |
149 |
1
|
manager.converters.put(StringEnumeration.class, new StringEnumerationConverter()); |
150 |
|
|
151 |
|
|
152 |
1
|
manager.converters.put(BigDecimal.class, new BigDecimalConverter()); |
153 |
1
|
manager.converters.put(BigDecimal[].class, new BigDecimalArrayConverter()); |
154 |
1
|
return manager; |
155 |
|
} |
156 |
|
} |