View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.web;
18  
19  import java.math.BigDecimal;
20  import java.math.BigInteger;
21  
22  import org.apache.commons.beanutils.ConvertUtils;
23  import org.apache.commons.beanutils.Converter;
24  import org.apache.commons.beanutils.converters.BigDecimalConverter;
25  import org.apache.commons.beanutils.converters.BigIntegerConverter;
26  import org.apache.commons.beanutils.converters.BooleanConverter;
27  import org.apache.commons.beanutils.converters.ByteConverter;
28  import org.apache.commons.beanutils.converters.CharacterConverter;
29  import org.apache.commons.beanutils.converters.DoubleConverter;
30  import org.apache.commons.beanutils.converters.FloatConverter;
31  import org.apache.commons.beanutils.converters.IntegerConverter;
32  import org.apache.commons.beanutils.converters.LongConverter;
33  import org.apache.commons.beanutils.converters.ShortConverter;
34  
35  /**
36   * Utility class for registering the various context sensitive converters.
37   *
38   * @see ContextSensitiveConverter
39   *
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   */
42  public class ConverterUtils {
43  
44  	public static synchronized void registerContextSensitiveConverters() {
45      	registerBigDecimalConverter();
46      	registerBigIntegerConverter();
47      	registerBooleanConverter();
48      	registerByteConverter();
49      	registerCharacterConverter();
50      	registerDoubleConverter();
51      	registerFloatConverter();
52      	registerIntegerConverter();
53      	registerLongConverter();
54      	registerShortConverter();
55      }
56  
57  	public static void registerBigDecimalConverter() {
58  		Converter currentConverter = ConvertUtils.lookup(BigDecimal.class);
59  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new BigDecimalConverter(null)), BigDecimal.class);
60  	}
61  
62  	public static void registerBigIntegerConverter() {
63  		Converter currentConverter = ConvertUtils.lookup(BigInteger.class);
64  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new BigIntegerConverter(null)), BigInteger.class);
65  	}
66  
67  	public static void registerBooleanConverter() {
68  		Converter currentConverter = ConvertUtils.lookup(Boolean.class);
69  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new BooleanConverter(null)), Boolean.class);
70  	}
71  
72  	public static void registerByteConverter() {
73  		Converter currentConverter = ConvertUtils.lookup(Byte.class);
74  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new ByteConverter(null)), Byte.class);
75  	}
76  
77  	public static void registerCharacterConverter() {
78  		Converter currentConverter = ConvertUtils.lookup(Character.class);
79  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new CharacterConverter(null)), Character.class);
80  	}
81  
82  	public static void registerDoubleConverter() {
83  		Converter currentConverter = ConvertUtils.lookup(Double.class);
84  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new DoubleConverter(null)), Double.class);
85  	}
86  
87  	public static void registerFloatConverter() {
88  		Converter currentConverter = ConvertUtils.lookup(Float.class);
89  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new FloatConverter(null)), Float.class);
90  	}
91  
92  	public static void registerIntegerConverter() {
93  		Converter currentConverter = ConvertUtils.lookup(Integer.class);
94  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new IntegerConverter(null)), Integer.class);
95  	}
96  
97  	public static void registerLongConverter() {
98  		Converter currentConverter = ConvertUtils.lookup(Long.class);
99  		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new LongConverter(null)), Long.class);
100 	}
101 
102 	public static void registerShortConverter() {
103 		Converter currentConverter = ConvertUtils.lookup(Short.class);
104 		ConvertUtils.register(new ContextSensitiveConverter(currentConverter, new ShortConverter(null)), Short.class);
105 	}
106 
107 }