Example usage for org.apache.commons.beanutils ConversionException ConversionException

List of usage examples for org.apache.commons.beanutils ConversionException ConversionException

Introduction

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

Prototype

public ConversionException(Throwable cause) 

Source Link

Document

Construct a new exception with the specified root cause.

Usage

From source file:net.kornr.swit.site.ColorConverter.java

public Object convert(Class clzz, Object obj) {
    if (Color.class.equals(clzz) == false)
        throw new ConversionException("Not a color conversion!");

    if (Color.class.equals(obj.getClass()))
        return obj;

    String value = obj.toString();
    if (value.startsWith("#"))
        value = value.substring(1);/*from  www .  ja  va  2s .co m*/

    Integer i = Integer.parseInt(value, 16);
    return new Color(i);
}

From source file:me.yyam.beanutils.DateConverter.java

@Override
public Object convert(Class type, Object value) {
    if (value == null) {
        return null;
    } else if (type == Timestamp.class) {
        return convertToDate(type, value, "yyyy-MM-dd HH:mm:ss");
    } else if (type == Date.class) {
        return convertToDate(type, value, "yyyy-MM-dd HH:mm:ss");
    } else if (type == String.class) {
        return convertToString(type, value);
    }//from w  w  w.  j  a va  2 s.com

    throw new ConversionException("?? " + value.getClass().getName() + "  " + type.getName());
}

From source file:com.ocpsoft.pretty.faces.config.convert.CaseConverter.java

@SuppressWarnings("rawtypes")
public Object convert(final Class type, final Object value) {
    if (value instanceof String) {
        return Enum.valueOf(Case.class, ((String) value).toUpperCase());
    }//ww w  . j a  va 2  s .co m
    throw new ConversionException("Could not convert value: [" + value + "] to Case type.");
}

From source file:com.ocpsoft.pretty.faces.config.convert.TrailingSlashConverter.java

@SuppressWarnings("rawtypes")
public Object convert(final Class type, final Object value) {
    if (value instanceof String) {
        return Enum.valueOf(TrailingSlash.class, ((String) value).toUpperCase());
    }//  w  w  w .j  ava 2  s.c o  m
    throw new ConversionException("Could not convert value: [" + value + "] to TrailingSlash type.");
}

From source file:com.terradue.jcatalogue.client.internal.converters.CharsetConverter.java

public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) {
    if (value == null) {
        throw new ConversionException("Null values not supported in this version.");
    }/*from   w  ww .  j  a  v a  2 s  .  com*/

    if (String.class == type) {
        if (value instanceof Charset) {
            return ((Charset) value).displayName();
        }
    } else if (Charset.class == type) {
        if (value instanceof String) {
            return forName((String) value);
        }
    }
    throw new ConversionException(format("type %s and value %s not supported", type, value));
}

From source file:com.terradue.jcatalogue.client.internal.converters.LocaleConverter.java

public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) {
    if (value == null) {
        throw new ConversionException("Null values not supported in this version.");
    }// ww w  .  ja  va  2s.com

    if (String.class == type) {
        if (value instanceof Locale) {
            Locale locale = (Locale) value;
            return locale.getLanguage() + SEPARATOR + locale.getCountry();
        }
    } else if (Locale.class == type) {
        if (value instanceof String) {
            StringTokenizer tokenizer = new StringTokenizer((String) value, SEPARATOR);
            return new Locale(tokenizer.nextToken(), tokenizer.nextToken());
        }
    }
    throw new ConversionException(format("type %s and value %s not supported", type, value));
}

From source file:ca.sqlpower.dao.session.DimensionConverter.java

public Dimension convertToComplexType(String convertFrom) throws ConversionException {

    String[] pieces = convertFrom.split(DELIMITER);
    if (pieces.length != 2) {
        throw new ConversionException(
                "The value " + convertFrom + " is not a valid serialized Dimension. The serialized"
                        + " form must consist of two integers separated by a comma.");
    }//from  w  w  w .  jav  a2s . com

    int width = Integer.valueOf(pieces[0]);
    int height = Integer.valueOf(pieces[1]);

    return new Dimension(width, height);
}

From source file:com.ge.apm.service.converter.DateConverter.java

@Override
public Object convert(Class type, Object value) {
    if (value == null) {
        return null;
    } else if (type == Timestamp.class) {
        return convertToDate(type, value, "yyyy-MM-dd HH:mm:ss");
    } else if (type == Date.class) {
        if (value.toString().contains(":") && !value.toString().contains("-")) {
            return convertToDate(type, value, "HH:mm:ss");
        } else {/*from w w w  . j a v a2s  .c o  m*/
            return convertToDate(type, value, "yyyy-MM-dd");
        }
    } else if (type == String.class) {
        return convertToString(type, value);
    }

    throw new ConversionException("?? " + value.getClass().getName() + "  " + type.getName());
}

From source file:ca.sqlpower.dao.session.URIConverter.java

@Override
public URI convertToComplexType(String convertFrom) throws ConversionException {
    try {//from w  w  w . java 2 s  . c  om
        return new URI(convertFrom);
    } catch (URISyntaxException e) {
        throw new ConversionException(e);
    }
}

From source file:com.ocpsoft.pretty.faces.config.convert.RedirectConverter.java

@SuppressWarnings("rawtypes")
public Object convert(final Class type, final Object value) {
    if (value instanceof String) {
        String item = (String) value;
        if ("301".equals(item)) {
            item = "PERMANENT";
        } else if ("302".equals(item)) {
            item = "TEMPORARY";
        }// w ww  . ja  v a 2  s  . c o m
        return Enum.valueOf(Redirect.class, item.toUpperCase());
    }
    throw new ConversionException("Could not convert value: [" + value + "] to Redirect type.");
}