{
obj = type.newInstance();
}
catch (InstantiationException e)
{
throw new ReaderException(e.getCause());
}
catch (IllegalAccessException e)
{
throw new ReaderException(e);
}
Class<?> theType = type;
while (theType != null && !theType.equals(Object.class))
{
setFields(theType, input, obj);
theType = theType.getSuperclass();
}
for (Method method : type.getMethods())
{
if (method.isAnnotationPresent(FormParam.class)
&& method.getName().startsWith("set")
&& method.getParameterTypes().length == 1)
{
FormParam param = method.getAnnotation(FormParam.class);
List<InputPart> list = input.getFormDataMap()
.get(param.value());
if (list == null || list.isEmpty())
continue;
InputPart part = list.get(0);
// if (part == null) throw new
// LoggableFailure("Unable to find @FormParam in multipart: " +
// param.value());
if (part == null)
continue;
Object data = part.getBody(method.getParameterTypes()[0],
method.getGenericParameterTypes()[0]);
try
{
method.invoke(obj, data);
}
catch (IllegalAccessException e)
{
throw new ReaderException(e);
}
catch (InvocationTargetException e)
{
throw new ReaderException(e.getCause());
}
}
}
return obj;