if (mBeanInfo == null) {
throw new IllegalArgumentException("MBean with name " + callBean + " is not found");
}
// Find operation
MBeanOperationInfo mBeanOperationInfo = findMBeanOperation(mBeanInfo, definition.getMethod());
if (mBeanOperationInfo == null) {
throw new IllegalArgumentException("Operation [" + callMethod + "] is not found for bean " + callBean);
}
// Get arguments type
MBeanParameterInfo[] mBeanParameterInfos = mBeanOperationInfo.getSignature();
int realCount = (mBeanParameterInfos != null) ? mBeanParameterInfos.length : 0;
int haveCount = (callParameters != null) ? callParameters.size() : 0;
if (realCount != haveCount) {
throw new IllegalArgumentException("Method " + callMethod + " of bean " + callBean +
" has " + realCount + " arguments but there are " + haveCount + " values specified");
}
// Compose parameters
Object[] parameterArray = null;
String[] signatureArray = null;
if ((callParameters != null) && (mBeanParameterInfos != null) && (realCount > 0)) {
parameterArray = new Object[realCount];
signatureArray = new String[realCount];
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
for (int i = 0; i < realCount; i++) {
String value = callParameters.get(i);
String requiredType = mBeanParameterInfos[i].getType();
Class<?> requiredClass = ClassUtils.forName(requiredType, this.getClass().getClassLoader());
parameterArray[i] = typeConverter.convertIfNecessary(value, requiredClass);
signatureArray[i] = requiredType;
}
}
// Make call
Object resultObject = mBeanServerConnection.invoke(objectName, mBeanOperationInfo.getName(),
parameterArray, signatureArray);
// Convert object to text
String resultText = String.valueOf(resultObject);