private void handleAsString(String str) { if (isBlank(str)) { super.setValueInternal(null); return; } try { super.setValueInternal(new URL(str)); } catch (MalformedURLException e) { throw illegalValue(str, URL.class, e); } }
protected void setValueInternal(Object value) { if (null == value) { super.setValueInternal(null); } else if (value instanceof CharSequence) { handleAsString(String.valueOf(value)); } else if (value instanceof File) { handleAsFile((File) value); } else if (value instanceof URL) { super.setValueInternal(value); } else { throw illegalValue(value, URL.class); } }
protected void setValueInternal(Object value) { if (null == value) { super.setValueInternal(null); } else if (value instanceof CharSequence) { handleAsString(String.valueOf(value)); } else if (value instanceof Date) { super.setValueInternal(value); } else if (value instanceof Calendar) { super.setValueInternal(((Calendar) value).getTime()); } else if (value instanceof Number) { super.setValueInternal(new Date(((Number) value).longValue())); } else { throw illegalValue(value, Date.class); } }
private void handleAsFile(File file) { try { super.setValueInternal(file.toURI().toURL()); } catch (MalformedURLException e) { throw illegalValue(file, URL.class); } }
protected void handleAsString(String str) { try { super.setValueInternal(isBlank(str) ? null : Long.parseLong(str)); } catch (NumberFormatException e) { throw illegalValue(str, Long.class, e); } }
protected void handleAsString(String str) { if (isBlank(str)) { super.setValueInternal(null); return; } try { super.setValueInternal(new Date(Long.parseLong(str))); return; } catch (NumberFormatException nfe) { // ignore, let's try parsing the date in a locale specific format } try { super.setValueInternal(new SimpleDateFormat().parse(str)); } catch (ParseException e) { throw illegalValue(str, Date.class, e); } }
protected void setValueInternal(Object value) { if (null == value) { super.setValueInternal(null); } else if (value instanceof CharSequence) { handleAsString(String.valueOf(value)); } else if (value instanceof Number) { handleAsNumber((Number) value); } else { throw illegalValue(value, Long.class); } }
protected void handleAsNumber(Number number) { super.setValueInternal(number.longValue()); }