if (isArray)
{
parameterType = parameterType.getComponentType();
}
ValueEncoder valueEncoder = valueEncoderSource.getValueEncoder(parameterType);
String parameterValue = request.getParameter(parameterName);
if (!allowBlank && InternalUtils.isBlank(parameterValue))
throw new RuntimeException(String.format(
"The value for query parameter '%s' was blank, but a non-blank value is needed.",
parameterName));
Object value;
if (!isArray)
{
value = coerce(parameterName, parameterType, parameterValue, valueEncoder, allowBlank);
} else
{
String[] parameterValues = request.getParameters(parameterName);
Object[] array = (Object[]) Array.newInstance(parameterType, parameterValues.length);
for (int i = 0; i < parameterValues.length; i++)
{
array[i] = coerce(parameterName, parameterType, parameterValues[i], valueEncoder, allowBlank);
}
value = array;
}
return value;
} catch (Exception ex)
{
throw new RuntimeException(
String.format(
"Unable process query parameter '%s' as parameter #%d of event handler method %s: %s",
parameterName, parameterIndex + 1, methodIdentifier,
ExceptionUtils.toMessage(ex)), ex);
}
}
private Object coerce(final String parameterName, Class parameterType,
String parameterValue, ValueEncoder valueEncoder, boolean allowBlank)
{
if (!allowBlank && InternalUtils.isBlank(parameterValue))
{
throw new RuntimeException(String.format(
"The value for query parameter '%s' was blank, but a non-blank value is needed.",
parameterName));
}
Object value = valueEncoder.toValue(parameterValue);
if (parameterType.isPrimitive() && value == null)
throw new RuntimeException(
String.format(
"Query parameter '%s' evaluates to null, but the event method parameter is type %s, a primitive.",