Example usage for org.apache.commons.beanutils.locale LocaleConvertUtilsBean convert

List of usage examples for org.apache.commons.beanutils.locale LocaleConvertUtilsBean convert

Introduction

In this page you can find the example usage for org.apache.commons.beanutils.locale LocaleConvertUtilsBean convert.

Prototype

public Object convert(String[] values, Class clazz) 

Source Link

Document

Convert an array of specified values to an array of objects of the specified class (if possible) .

Usage

From source file:com.opencsv.bean.BeanFieldPrimitiveTypes.java

@Override
protected Object convert(String value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException {
    if (required && StringUtils.isBlank(value)) {
        throw new CsvRequiredFieldEmptyException(
                String.format("Field '%s' is mandatory but no value was provided.", field.getName()));
    }// w  w  w  .  jav a  2 s .  c o m

    Object o = null;

    if (StringUtils.isNotBlank(value)) {
        try {
            if (StringUtils.isEmpty(locale)) {
                ConvertUtilsBean converter = new ConvertUtilsBean();
                converter.register(true, false, 0);
                o = converter.convert(value, field.getType());
            } else {
                LocaleConvertUtilsBean lcub = new LocaleConvertUtilsBean();
                lcub.setDefaultLocale(new Locale(locale));
                o = lcub.convert(value, field.getType());
            }
        } catch (ConversionException e) {
            CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(value, field.getType(),
                    "Conversion of " + value + " to " + field.getType().getCanonicalName() + " failed.");
            csve.initCause(e);
            throw csve;
        }
    }
    return o;
}