Java Code Examples for org.apache.commons.beanutils.ConvertUtilsBean#register()

The following examples show how to use org.apache.commons.beanutils.ConvertUtilsBean#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceStorageHelper.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public static void convertMapToServiceSettings(IServiceSettings serviceSettings, Map<String, String> params) {
    ConvertUtilsBean converter = new ConvertUtilsBean();
    PropertyUtilsBean beanUtils = new PropertyUtilsBean();
    PropertyDescriptor[] descriptors = beanUtils.getPropertyDescriptors(serviceSettings);

    converter.register(new SailfishURIConverter(), SailfishURI.class);
    converter.register(true, false, 0);

    for(PropertyDescriptor descriptor : descriptors) {
        if(descriptor.getWriteMethod() == null) {
            continue;
        }

        String name = descriptor.getName();
        String value = params.get(name);

        if(value == null) {
            continue;
        }

        try {
            BeanUtils.setProperty(serviceSettings, name, converter.convert(value, descriptor.getPropertyType()));
        } catch(Exception e) {
            throw new EPSCommonException(String.format("Failed to set setting '%s' to: %s", name, value), e);
        }
    }
}
 
Example 2
Source File: ConversionUtils.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
protected ConvertUtilsBean initialValue() {
  ConvertUtilsBean ret = BeanUtilsBean2.getInstance().getConvertUtils();
  ret.deregister();
  ret.register(false, true, 1);
  return ret;
}
 
Example 3
Source File: ServiceActions.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
@Override
      protected ConvertUtilsBean initialValue() {
    ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();
    convertUtilsBean.register(new SailfishURIConverter(), SailfishURI.class);
    return convertUtilsBean;
}
 
Example 4
Source File: CamsFixture.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
private CamsFixture() {
    BeanUtilsBean instance = BeanUtilsBean.getInstance();
    ConvertUtilsBean convertUtils = instance.getConvertUtils();
    // Register Kuali Decimal Converter
    convertUtils.register(new KualiDecimalConverter(), KualiDecimal.class);
}