001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.web;
018:
019: import java.math.BigDecimal;
020: import java.math.BigInteger;
021:
022: import org.apache.commons.beanutils.ConvertUtils;
023: import org.apache.commons.beanutils.Converter;
024: import org.apache.commons.beanutils.converters.BigDecimalConverter;
025: import org.apache.commons.beanutils.converters.BigIntegerConverter;
026: import org.apache.commons.beanutils.converters.BooleanConverter;
027: import org.apache.commons.beanutils.converters.ByteConverter;
028: import org.apache.commons.beanutils.converters.CharacterConverter;
029: import org.apache.commons.beanutils.converters.DoubleConverter;
030: import org.apache.commons.beanutils.converters.FloatConverter;
031: import org.apache.commons.beanutils.converters.IntegerConverter;
032: import org.apache.commons.beanutils.converters.LongConverter;
033: import org.apache.commons.beanutils.converters.ShortConverter;
034:
035: /**
036: * Utility class for registering the various context sensitive converters.
037: *
038: * @see ContextSensitiveConverter
039: *
040: * @author ewestfal
041: */
042: public class ConverterUtils {
043:
044: public static synchronized void registerContextSensitiveConverters() {
045: registerBigDecimalConverter();
046: registerBigIntegerConverter();
047: registerBooleanConverter();
048: registerByteConverter();
049: registerCharacterConverter();
050: registerDoubleConverter();
051: registerFloatConverter();
052: registerIntegerConverter();
053: registerLongConverter();
054: registerShortConverter();
055: }
056:
057: public static void registerBigDecimalConverter() {
058: Converter currentConverter = ConvertUtils
059: .lookup(BigDecimal.class);
060: ConvertUtils.register(new ContextSensitiveConverter(
061: currentConverter, new BigDecimalConverter(null)),
062: BigDecimal.class);
063: }
064:
065: public static void registerBigIntegerConverter() {
066: Converter currentConverter = ConvertUtils
067: .lookup(BigInteger.class);
068: ConvertUtils.register(new ContextSensitiveConverter(
069: currentConverter, new BigIntegerConverter(null)),
070: BigInteger.class);
071: }
072:
073: public static void registerBooleanConverter() {
074: Converter currentConverter = ConvertUtils.lookup(Boolean.class);
075: ConvertUtils.register(new ContextSensitiveConverter(
076: currentConverter, new BooleanConverter(null)),
077: Boolean.class);
078: }
079:
080: public static void registerByteConverter() {
081: Converter currentConverter = ConvertUtils.lookup(Byte.class);
082: ConvertUtils.register(new ContextSensitiveConverter(
083: currentConverter, new ByteConverter(null)), Byte.class);
084: }
085:
086: public static void registerCharacterConverter() {
087: Converter currentConverter = ConvertUtils
088: .lookup(Character.class);
089: ConvertUtils.register(new ContextSensitiveConverter(
090: currentConverter, new CharacterConverter(null)),
091: Character.class);
092: }
093:
094: public static void registerDoubleConverter() {
095: Converter currentConverter = ConvertUtils.lookup(Double.class);
096: ConvertUtils.register(new ContextSensitiveConverter(
097: currentConverter, new DoubleConverter(null)),
098: Double.class);
099: }
100:
101: public static void registerFloatConverter() {
102: Converter currentConverter = ConvertUtils.lookup(Float.class);
103: ConvertUtils.register(new ContextSensitiveConverter(
104: currentConverter, new FloatConverter(null)),
105: Float.class);
106: }
107:
108: public static void registerIntegerConverter() {
109: Converter currentConverter = ConvertUtils.lookup(Integer.class);
110: ConvertUtils.register(new ContextSensitiveConverter(
111: currentConverter, new IntegerConverter(null)),
112: Integer.class);
113: }
114:
115: public static void registerLongConverter() {
116: Converter currentConverter = ConvertUtils.lookup(Long.class);
117: ConvertUtils.register(new ContextSensitiveConverter(
118: currentConverter, new LongConverter(null)), Long.class);
119: }
120:
121: public static void registerShortConverter() {
122: Converter currentConverter = ConvertUtils.lookup(Short.class);
123: ConvertUtils.register(new ContextSensitiveConverter(
124: currentConverter, new ShortConverter(null)),
125: Short.class);
126: }
127:
128: }
|