}
private static final Object[] EMPTY_PARAMS = new Object[0];
public static Object invokeMethod(Object base, Method m, Object[] paramValues) throws ELException {
if (m == null) throw new MethodNotFoundException();
Class[] paramTypes = m.getParameterTypes();
Object[] params = null;
if (paramTypes.length == 0) {
// leave params null
} else if (paramValues == null) {
throw new MethodNotFoundException(m.getDeclaringClass() + "." + m.getName() + " has " + paramTypes.length + " params");
} else if (m.isVarArgs()) {
// add values
params = new Object[paramTypes.length];
int i = 0;
for (; i < paramTypes.length - 1; i++) {
params[i] = ELSupport.coerceToType(paramValues[i], paramTypes[i]);
}
Class argType = paramTypes[i].getComponentType();
if (paramTypes.length == paramValues.length) {
if (paramValues[i] == null) {
params[i] = Array.newInstance(argType, 0);
} else if (paramValues[i].getClass().isArray()) {
params[i] = paramValues[i];
} else {
params[i] = Array.newInstance(argType, 1);
Array.set(params[i], 0, ELSupport.coerceToType(paramValues[i], argType));
}
} else {
int len = paramValues.length - paramTypes.length + 1;
Object ar = Array.newInstance(argType, len);
for (int j = 0; j < len; j++) {
Array.set(ar, j, ELSupport.coerceToType(paramValues[paramTypes.length - 1 + j], argType));
}
params[i] = ar;
}
} else if (paramValues.length == paramTypes.length) {
// add values
params = new Object[paramTypes.length];
// assign first set
for (int i = 0; i < paramTypes.length; i++) {
params[i] = ELSupport.coerceToType(paramValues[i], paramTypes[i]);
}
} else {
throw new MethodNotFoundException(m.getDeclaringClass().getName() + "." + m.getName() + " has " + paramTypes.length + ", only passed " + paramValues.length + " parameters");
}
try {
return m.invoke(base, params);
} catch (IllegalAccessException iae) {