| 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.util.Locale; |
| 27 |
|
|
| 28 |
|
import net.smartlab.web.Enumeration; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0,75 |
|
| 35 |
|
public class EnumerationConverter extends Converter { |
| 36 |
|
|
| 37 |
|
private final static String NAME = "decode"; |
| 38 |
|
|
| 39 |
|
private final static Class[] ARGUMENTS = new Class[] {int.class}; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@see |
| 43 |
|
|
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0,75 |
|
| 45 |
0
|
public Object convert(Class type, Object value, Locale locale) throws ConversionException {... |
| 46 |
0
|
try { |
| 47 |
0
|
if (Enumeration.class.isAssignableFrom(type)) { |
| 48 |
0
|
return type.getMethod(NAME, ARGUMENTS).invoke(type.newInstance(), new Object[] {Integer.valueOf(value.toString())}); |
| 49 |
|
} else { |
| 50 |
0
|
return Integer.toString(((Enumeration)value).getId()); |
| 51 |
|
} |
| 52 |
|
} catch (Exception e) { |
| 53 |
|
throw new ConversionException("Invalid enumeration " + value.toString(), e); |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
} |