} else if (Date.class.isAssignableFrom(parameterClass)) {
try {
Date date = DEFAULT_DATE_FORMAT.parse(paramValueStr);
return date;
} catch (java.text.ParseException e) {
throw new ReportingException(
String.format("Couldn't read date from value [%s]. Date format should be [%s].",
paramValueStr,
DEFAULT_DATE_FORMAT_STR));
}
} else {
try {
Constructor constructor = ConstructorUtils.getAccessibleConstructor(parameterClass, String.class);
if (constructor != null) {
Object value = constructor.newInstance(paramValueStr);
return value;
} else {
Method valueOf = MethodUtils.getAccessibleMethod(parameterClass, "valueOf", String.class);
if (valueOf != null) {
Object value = valueOf.invoke(null, paramValueStr);
return value;
}
}
} catch (InstantiationException e) {
throw new ReportingException(
String.format("Could not instantiate object with class [%s] from [%s] string.",
parameterClass.getCanonicalName(),
paramValueStr));
} catch (IllegalAccessException e) {
throw new ReportingException(
String.format("Could not instantiate object with class [%s] from [%s] string.",
parameterClass.getCanonicalName(),
paramValueStr));
} catch (InvocationTargetException e) {
throw new ReportingException(
String.format("Could not instantiate object with class [%s] from [%s] string.",
parameterClass.getCanonicalName(),
paramValueStr));
}
}