public Object convert(Type type) throws ConversionException { if (type instanceof Class<?> && ((Class<?>) type).isAssignableFrom(value.getClass())) { return value; } else { throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", value, type)); } }
public Object convert(Type type) throws ConversionException { if (type instanceof Class && ((Class) type).isAssignableFrom(value.getClass())) return value; else throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", value, type)); }
public Object convert(Type type) throws ConversionException { if (type instanceof Class<?> && ((Class<?>) type).isAssignableFrom(value.getClass())) { return value; } else { throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", value, type)); } }
public Object convert(Type type) throws ConversionException { if (type.equals(Boolean.class) || type.equals(Object.class)) value = Boolean.valueOf(element.getStringValue()); else if (type.equals(Boolean.TYPE)) value = Boolean.parseBoolean(element.getStringValue()); else throw new ConversionException(String.format( "Parameter [%s] cannot be converted to type [%s].", element .getStringValue(), type)); return value; }
public Object convert(Type type) throws ConversionException { if (type.equals(Boolean.class) || type.equals(Object.class)) value = Boolean.valueOf(element.getStringValue()); else if (type.equals(Boolean.TYPE)) value = Boolean.parseBoolean(element.getStringValue()); else throw new ConversionException(String.format( "Parameter [%s] cannot be converted to type [%s].", element .getStringValue(), type)); return value; }
public Object convert(Type type) throws ConversionException { if (type.equals(Boolean.class) || type.equals(Object.class)) value = Boolean.valueOf(element.getStringValue()); else if (type.equals(Boolean.TYPE)) value = Boolean.parseBoolean(element.getStringValue()); else throw new ConversionException(String.format( "Parameter [%s] cannot be converted to type [%s].", element.getStringValue(), type)); return value; }
throw new ConversionException("Error converting value - encoding not supported."); else throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", elementValue, type)); throw (ConversionException) ex; else throw new ConversionException(String.format("Could not convert value [%s] to type [%s].", elementValue, type.toString()), ex);
public Object convert(Type type) throws ConversionException { String elementValue = null; try { elementValue = URLDecoder.decode(element.getStringValue(), DEFAULT_ENCODING); } catch (UnsupportedEncodingException ex) { throw new ConversionException( "Error converting value - encoding not supported."); } try { if (converters.containsKey(type)) value = converters.get(type).convert(elementValue); else if (type instanceof Class && ((Class) type).isEnum()) value = Enum.valueOf((Class) type, elementValue); else // Should never reach this line - calcConverstionScore should // guarantee this. throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", elementValue, type)); return value; } catch (Exception ex) { if (ex instanceof ConversionException) throw (ConversionException) ex; else throw new ConversionException(String.format( "Could not convert value [%s] to type [%s].", elementValue, type.toString()), ex); } }
} catch (UnsupportedEncodingException ex) throw new ConversionException( "Error converting value - encoding not supported."); throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", elementValue, type)); throw (ConversionException) ex; else throw new ConversionException(String.format( "Could not convert value [%s] to type [%s].", elementValue, type.toString()), ex);
value = val; } else { throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", element .getStringValue(), type));
} else throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", element .getStringValue(), type));
public Object convert(Type type) throws ConversionException { if ((type instanceof Class && Date.class.isAssignableFrom((Class) type)) || type.equals(Object.class)) { try { value = getDateFormat().parse(element.getStringValue()); } catch (ParseException ex) { throw new ConversionException(String.format( "Date value [%s] is not in a valid format.", element .getStringValue())); } } else if ((type instanceof Class && Calendar.class .isAssignableFrom((Class) type))) { try { Calendar cal = Calendar.getInstance(); cal.setTime(getDateFormat().parse(element.getStringValue())); value = cal; } catch (ParseException ex) { throw new ConversionException(String.format( "Date value [%s] is not in a valid format.", element .getStringValue())); } } else { throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", element .getStringValue(), type)); } return value; }
throw new ConversionException(String.format("Value [%s] cannot be converted to type [%s].", element.getStringValue(), type));
throw new ConversionException(String.format("Date value [%s] is not in a valid format.", element.getStringValue())); throw new ConversionException(String.format("Date value [%s] is not in a valid format.", element.getStringValue())); throw new ConversionException(String.format("Value [%s] cannot be converted to type [%s].", element.getStringValue(), type));
value = getConcreteClass((Class<?>) type).newInstance(); } catch (Exception ex) { throw new ConversionException(String.format( "Could not create instance of target type [%s].", type)); value = getConcreteClass(rawType).newInstance(); } catch (Exception ex) { throw new ConversionException(String.format( "Could not create instance of target type [%s].", rawType));
} catch (ParseException ex) throw new ConversionException(String.format( "Date value [%s] is not in a valid format.", element .getStringValue())); } catch (ParseException ex) throw new ConversionException(String.format( "Date value [%s] is not in a valid format.", element .getStringValue())); throw new ConversionException(String.format( "Value [%s] cannot be converted to type [%s].", element .getStringValue(), type));
throw new ConversionException(String.format( "Could not create instance of target type [%s].", type)); throw new ConversionException(String.format( "Could not create instance of target type [%s].", rawType));
throw new ConversionException(String.format( "Cannot convert value to type [%s]", type)); throw new ConversionException(String.format( "Could not create value of type [%s]", type));
throw new ConversionException(String.format("Cannot convert value to type [%s]", type)); throw new ConversionException(String.format("Could not create value of type [%s]", type));
throw new ConversionException(String.format( "Could not create instance of target type [%s].", type)); throw new ConversionException(String.format( "Could not create instance of target type [%s].", rawType));