{
Object invoke = method.invoke(o);
if (returnType != null && invoke != null && !invoke.getClass().isAssignableFrom(returnType))
{
throw new ApplicationRuntimeException("Unable to cast result " + invoke + " of method "
+ method.getName() + "() of class " + o.getClass().getName() + " to return type " + returnType);
}
return (T) invoke;
}
catch (IllegalArgumentException e)
{
throw new ApplicationRuntimeException("Unable to invoke method " + method.getName() + " of class "
+ o.getClass(), e);
}
catch (SecurityException e)
{
throw new ApplicationRuntimeException("Security violation " + method.getName() + " of class "
+ o.getClass(), e);
}
catch (IllegalAccessException e)
{
throw new ApplicationRuntimeException("Security violation " + method.getName() + " of class "
+ o.getClass(), e);
}
catch (InvocationTargetException e)
{
Throwable targetException = e.getTargetException();
Throwable nested = null;
if (targetException instanceof Exception)
nested = targetException;
else
nested = e;
throw new ApplicationRuntimeException("Invocation target exception for " + method.getName() + " of class "
+ o.getClass(), nested);
}
}