ReflectionException {
if (log.isDebugEnabled()) {
log.debugf("Invoke method called on %s", name);
}
MBeanOperationInfo opInfo = null;
for (IspnMBeanOperationInfo op : opInfos) {
if (op.getOperationName().equals(name)) {
opInfo = op;
break;
}
}
if (opInfo == null) {
final String msg = "Operation " + name + " not amongst operations in " + opInfos;
throw new MBeanException(new ServiceNotFoundException(msg), msg);
}
// Argument type transformation according to signatures
for (int i = 0; i < sig.length; i++) {
// arguments are taken from RHQ like java.lang.String but we need some fields to be numbers
if (args[i] != null) {
if (log.isDebugEnabled())
log.debugf("Argument value before transformation: %s and its class: %s. " +
"For method.invoke we need it to be class: %s", args[i], args[i].getClass(), sig[i]);
if (sig[i].equals(int.class.getCanonicalName()) || sig[i].equals(Integer.class.getCanonicalName())) {
if ((args[i].getClass() != Integer.class) && (args[i].getClass() != int.class))
args[i] = Integer.parseInt((String) args[i]);
}
if (sig[i].equals(Long.class.getCanonicalName()) || sig[i].equals(long.class.getCanonicalName())) {
if ((args[i].getClass() != Long.class) && (args[i].getClass() != long.class))
args[i] = Long.parseLong((String) args[i]);
}
}
}
try {
Class<?>[] classes = new Class[sig.length];
for (int i = 0; i < classes.length; i++) {
classes[i] = ReflectionUtil.getClassForName(sig[i], null);
}
Method method = getObject().getClass().getMethod(opInfo.getName(), classes);
return method.invoke(getObject(), args);
} catch (Exception e) {
throw new MBeanException(new Exception(getRootCause(e)));
}
}