* @see de.odysseus.calyxo.base.conf.MethodConfig#invoke(java.lang.Class, java.lang.Object)
*/
public Object invoke(Class clazz, Object object, ClassLoader loader) throws ConfigException {
if (clazz == null) {
if (object == null) {
throw new ConfigException("Cannot invoke method on null in " + toInlineString());
}
clazz = object.getClass();
} else if (object != null && !clazz.isInstance(object)) {
throw new ConfigException("Specified object is not an instance of " + clazz.getName() + " in " + toInlineString());
}
Object[] rawArgs = evalArgs(loader);
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().equals(name)) {
if (object == null && !Modifier.isStatic(methods[i].getModifiers())) {
continue;
}
Class[] types = methods[i].getParameterTypes();
Object[] coercedArgs = coerce(rawArgs, types);
if (coercedArgs != null) {
try {
return methods[i].invoke(object, coercedArgs);
} catch (Exception e) {
throw new ConfigException(
"Could not invoke method " + name + " in " + toInlineString(), e);
}
}
}
}
throw new ConfigException(
"Could not find method " + name + " in " + toInlineString());
}