Search in sources :

Example 1 with ConvertUtilsBean

use of org.apache.commons.beanutils.ConvertUtilsBean in project checkstyle by checkstyle.

the class AutomaticBean method createBeanUtilsBean.

/**
     * Creates a BeanUtilsBean that is configured to use
     * type converters that throw a ConversionException
     * instead of using the default value when something
     * goes wrong.
     *
     * @return a configured BeanUtilsBean
     */
private static BeanUtilsBean createBeanUtilsBean() {
    final ConvertUtilsBean cub = new ConvertUtilsBean();
    registerIntegralTypes(cub);
    registerCustomTypes(cub);
    return new BeanUtilsBean(cub, new PropertyUtilsBean());
}
Also used : BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) ConvertUtilsBean(org.apache.commons.beanutils.ConvertUtilsBean)

Example 2 with ConvertUtilsBean

use of org.apache.commons.beanutils.ConvertUtilsBean in project databus by linkedin.

the class TestConfigManager method testPaddedInt.

@Test
public void testPaddedInt() throws Exception {
    ConvertUtilsBean convertUtils = new ConvertUtilsBean();
    Integer intValue = (Integer) convertUtils.convert("456", int.class);
    assertEquals("correct int value", 456, intValue.intValue());
    BeanUtilsBean beanUtils = new BeanUtilsBean();
    PropertyDescriptor propDesc = beanUtils.getPropertyUtils().getPropertyDescriptor(_configBuilder, "intSetting");
    assertEquals("correct setting type", int.class, propDesc.getPropertyType());
    _configManager.setSetting("com.linkedin.databus2.intSetting", " 123 ");
    DynamicConfig config = _configManager.getReadOnlyConfig();
    assertEquals("correct int value", 123, config.getIntSetting());
}
Also used : BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) PropertyDescriptor(java.beans.PropertyDescriptor) ConvertUtilsBean(org.apache.commons.beanutils.ConvertUtilsBean) Test(org.testng.annotations.Test)

Example 3 with ConvertUtilsBean

use of org.apache.commons.beanutils.ConvertUtilsBean in project head by mifos.

the class ConversionUtil method populateBusinessObject.

public static void populateBusinessObject(ActionForm actionForm, AbstractBusinessObject object, Locale locale) throws ValueObjectConversionException {
    try {
        if (null != object) {
            ConvertUtilsBean conBean = new ConvertUtilsBean();
            MifosSqlDateConverter converter = new MifosSqlDateConverter();
            MifosDoubleConverter mifosDoubleConverter = new MifosDoubleConverter();
            MifosStringToJavaUtilDateConverter stringToJavaDateConverter = new MifosStringToJavaUtilDateConverter();
            converter.setLocale(locale);
            conBean.register(stringToJavaDateConverter, java.util.Date.class);
            conBean.register(converter, java.sql.Date.class);
            conBean.register(mifosDoubleConverter, Double.class);
            BeanUtilsBean bean = new BeanUtilsBean(conBean, BeanUtilsBean.getInstance().getPropertyUtils());
            bean.copyProperties(object, actionForm);
        } else {
            throw new IllegalArgumentException("business object was null");
        }
    } catch (InvocationTargetException e) {
        throw new ValueObjectConversionException(e);
    } catch (IllegalAccessException e) {
        throw new ValueObjectConversionException(e);
    } catch (Exception e) {
        throw new ValueObjectConversionException(e);
    }
}
Also used : BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException) ConvertUtilsBean(org.apache.commons.beanutils.ConvertUtilsBean) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValueObjectConversionException(org.mifos.framework.exceptions.ValueObjectConversionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

BeanUtilsBean (org.apache.commons.beanutils.BeanUtilsBean)3 ConvertUtilsBean (org.apache.commons.beanutils.ConvertUtilsBean)3 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)1 ValueObjectConversionException (org.mifos.framework.exceptions.ValueObjectConversionException)1 Test (org.testng.annotations.Test)1