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());
}
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());
}
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);
}
}
Aggregations