return (T) Long.valueOf(argument);
}
}
catch (IllegalArgumentException ex)
{
throw new BadParameterException(String.format("Could not convert \"%s\" to a %s",argument,type.getSimpleName()));
}
// date
if (type.equals(Date.class))
{
try
{
return (T) dateParser.parseDateTime(argument).toDate();
}
catch (IllegalArgumentException ex1)
{
throw new BadParameterException(String.format("Could not convert \"%s\" to a %s",argument,type.getSimpleName()));
}
}
// try to parse via valueOf(String s) method
try
{
logger.debug("Trying to get and invoke valueOf(String s) method on {}", type);
Method method = type.getMethod("valueOf", String.class);
return (T) method.invoke(type, argument);
}
catch (NoSuchMethodException ex)
{
logger.warn("{} does not have method valueOf(String s)", type);
}
catch (Exception ex)
{
throw new BadParameterException(String.format("Could not convert \"%s\" to a %s",argument,type.getSimpleName()),ex);
}
throw new BadParameterException(String.format("Could not convert \"%s\" to a %s",argument,type.getSimpleName()));
}