// Para cada metodo verifica se ele está anotado com ManagedOperation e cria um MBeanOperationInfo para ele.
Method[] methodList = type.getMethods();
if (methodList != null) {
for (Method method : methodList) {
ManagedOperation opAnnotation = method.getAnnotation(ManagedOperation.class);
if (opAnnotation != null) {
// Lemos as informações sobre o método e criamos uma instância
// de MethodDetail para representar este método como uma
// operação.
Class<?>[] parameterTypes = method.getParameterTypes();
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
ParameterDetail[] parameterDetails = new ParameterDetail[parameterTypes.length];
OperationType operationType = opAnnotation.type();
for (int i = 0; i < parameterTypes.length; i++) {
OperationParameter paramAnnotation = null;
for (Annotation annotation : parameterAnnotations[i]) {
if (annotation.annotationType() == OperationParameter.class) {
paramAnnotation = (OperationParameter) annotation;
break;
}
}
String name = paramAnnotation != null ? paramAnnotation.name() : ("arg" + i);
String description = paramAnnotation != null ? paramAnnotation.description() : null;
parameterDetails[i] = new ParameterDetail(parameterTypes[i], name, description);
}
// Com todas as informações, criamos nossa instância de MethodDetail e
// acrescentamos na lista de todas as operações.
MethodDetail detail = new MethodDetail(method, opAnnotation.description(), operationType, parameterDetails);
operationMethods.put(method.getName(), detail);
}
}
}
}