Example usage for org.apache.commons.beanutils ConvertUtilsBean convert

List of usage examples for org.apache.commons.beanutils ConvertUtilsBean convert

Introduction

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

Prototype

public String convert(Object value) 

Source Link

Document

Convert the specified value into a String.

Usage

From source file:com.gs.obevo.db.impl.platforms.sybaseiq.iqload.IqLoadFileCreator.java

private static Function<FieldToColumnMapping, String> convertWithDefault(final ConvertUtilsBean cub) {
    return new Function<FieldToColumnMapping, String>() {
        @Override//from   w ww. ja  va2s.  c  om
        public String valueOf(FieldToColumnMapping field) {
            return field.getColumnName() + " DEFAULT '" + cub.convert(field.getDefaultValue()) + "'";
        }
    };
}

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

/**
 * This method takes the current value of the field in question in the bean
 * passed in and converts it to a string.
 * It works for all of the primitives, wrapped primitives,
 * {@link java.lang.String}, {@link java.math.BigDecimal}, and
 * {@link java.math.BigInteger}.//from   w ww  . j  ava 2s.  c om
 * 
 * @throws CsvDataTypeMismatchException If there is an error converting
 *   value to a string
 */
// The rest of the JavaDoc is automatically inherited from the base class.
@Override
protected String convertToWrite(Object value)
        throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException {
    // Validation
    if (value == null) {
        if (required) {
            throw new CsvRequiredFieldEmptyException();
        } else {
            return null;
        }
    }

    // Conversion
    String result;
    try {
        if (StringUtils.isEmpty(locale)) {
            ConvertUtilsBean converter = new ConvertUtilsBean();
            result = converter.convert(value);
        } else {
            LocaleConvertUtilsBean converter = new LocaleConvertUtilsBean();
            converter.setDefaultLocale(new Locale(locale));
            result = converter.convert(value);
        }
    } catch (ConversionException e) {
        CsvDataTypeMismatchException csve = new CsvDataTypeMismatchException(
                "The field must be primitive, boxed primitive, BigDecimal, BigInteger or String types only.");
        csve.initCause(e);
        throw csve;
    }
    return result;
}