1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.osoco.dyninc;
16
17 import org.apache.commons.beanutils.ConvertUtils;
18 import org.apache.commons.beanutils.Converter;
19
20 public class ConversionUtil {
21
22 static Converter booleanConverter;
23 static Converter integerConverter;
24 static Converter longConverter;
25 static Converter doubleConverter;
26
27 public static Boolean convertToBoolean(Object value) {
28 if ( booleanConverter == null ) {
29 booleanConverter = ConvertUtils.lookup(Boolean.class);
30 }
31 return (Boolean)booleanConverter.convert(Boolean.class, value);
32 }
33
34 public static Integer convertToInteger(Object value) {
35 if ( integerConverter == null ) {
36 integerConverter = ConvertUtils.lookup(Integer.class);
37 }
38 if ( Boolean.TRUE.equals(convertToBoolean(value))) {
39 return new Integer(1);
40 }
41 return (Integer)integerConverter.convert(Integer.class, value);
42 }
43
44 public static Long convertToLong(Object value) {
45 if ( longConverter == null ) {
46 longConverter = ConvertUtils.lookup(Long.class);
47 }
48 if ( Boolean.TRUE.equals(convertToBoolean(value))) {
49 return new Long(1);
50 }
51 return (Long)longConverter.convert(Long.class, value);
52 }
53
54 public static Double convertToDouble(Object value) {
55 if ( doubleConverter == null ) {
56 doubleConverter = ConvertUtils.lookup(Double.class);
57 }
58 if ( Boolean.TRUE.equals(convertToBoolean(value))) {
59 return new Double(1);
60 }
61 return (Double)doubleConverter.convert(Double.class, value);
62 }
63
64 }