return ((DynamicMBean)resource).invoke(name, params, signature);
}
// Validate the input parameters
if (name == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Method name is null"),
"Method name is null");
if( log.isDebugEnabled()) log.debug("Invoke " + name);
MethodKey mkey = new MethodKey(name, signature);
Method method=(Method)invokeAttMap.get(mkey);
if( method==null ) {
if (params == null)
params = new Object[0];
if (signature == null)
signature = new String[0];
if (params.length != signature.length)
throw new RuntimeOperationsException
(new IllegalArgumentException("Inconsistent arguments and signature"),
"Inconsistent arguments and signature");
// Acquire the ModelMBeanOperationInfo information for
// the requested operation
ModelMBeanOperationInfo opInfo = info.getOperation(name);
if (opInfo == null)
throw new MBeanException
(new ServiceNotFoundException("Cannot find operation " + name),
"Cannot find operation " + name);
// Prepare the signature required by Java reflection APIs
// FIXME - should we use the signature from opInfo?
Class types[] = new Class[signature.length];
for (int i = 0; i < signature.length; i++) {
types[i]=getAttributeClass( signature[i] );
}
// Locate the method to be invoked, either in this MBean itself
// or in the corresponding managed resource
// FIXME - Accessible methods in superinterfaces?
Object object = null;
Exception exception = null;
try {
object = this;
method = object.getClass().getMethod(name, types);
} catch (NoSuchMethodException e) {
exception = e;;
}
try {
if ((method == null) && (resource != null)) {
object = resource;
method = object.getClass().getMethod(name, types);
}
} catch (NoSuchMethodException e) {
exception = e;
}
if (method == null) {
throw new ReflectionException(exception,
"Cannot find method " + name +
" with this signature");
}
invokeAttMap.put( mkey, method );
}
// Invoke the selected method on the appropriate object
Object result = null;
try {
if( method.getDeclaringClass().isAssignableFrom( this.getClass()) ) {
result = method.invoke(this, params );
} else {
result = method.invoke(resource, params);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
log.error("Exception invoking method " + name , t );
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException
((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException
((Error) t, "Error invoking method " + name);
else