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

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

Introduction

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

Prototype

public void setDefaultLocale(Locale locale) 

Source Link

Document

setter for defaultLocale.

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()));
    }//from   w  ww.  j  a va 2  s .c om

    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;
}