use of org.apache.cxf.management.annotation.ManagedAttribute in project cxf by apache.
the class ModelMBeanAssembler method getModelMbeanInfo.
public ModelMBeanInfo getModelMbeanInfo(Class<?> clazz) {
supporter.clear();
ManagedResource mr = getManagedResource(clazz);
if (mr == null) {
// the class is not need to expose to jmx
return null;
}
// Clazz get all the method which should be managemed
Descriptor mbeanDescriptor = supporter.buildMBeanDescriptor(mr);
// add the notification
ManagedNotification[] mns = getManagedNotifications(clazz);
for (int k = 0; k < mns.length; k++) {
supporter.addModelMBeanNotification(mns[k].notificationTypes(), mns[k].name(), mns[k].description(), null);
}
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
ManagedAttribute ma = getManagedAttribute(methods[i]);
// add Attribute to the ModelMBean
if (ma != null) {
String attributeName = getAttributeName(methods[i].getName());
if (!supporter.checkAttribute(attributeName)) {
String attributeType = getAttributeType(methods, attributeName);
ManagedAttributeInfo mai = getAttributInfo(methods, attributeName, attributeType, ma);
Descriptor attributeDescriptor = supporter.buildAttributeDescriptor(ma, attributeName, mai.is, mai.read, mai.write);
// should setup the description
supporter.addModelMBeanAttribute(mai.fname, mai.ftype, mai.read, mai.write, mai.is, mai.description, attributeDescriptor);
Method method;
// add the attribute methode to operation
if (mai.read) {
if (mai.is) {
method = findMethodByName(methods, "is" + attributeName);
} else {
method = findMethodByName(methods, "get" + attributeName);
}
addAttributeOperation(method);
}
if (mai.write) {
method = findMethodByName(methods, "set" + attributeName);
addAttributeOperation(method);
}
}
} else {
// add Operation to the ModelMBean
ManagedOperation mo = getManagedOperation(methods[i]);
if (mo != null) {
Class<?>[] types = methods[i].getParameterTypes();
ManagedOperationParameter[] mop = getManagedOperationParameters(methods[i]);
String[] paramTypes = new String[types.length];
String[] paramNames = new String[types.length];
String[] paramDescs = new String[types.length];
for (int j = 0; j < types.length; j++) {
paramTypes[j] = types[j].getName();
if (j < mop.length) {
paramDescs[j] = mop[j].description();
paramNames[j] = mop[j].name();
} else {
paramDescs[j] = "";
paramNames[j] = types[j].getName();
}
}
Descriptor operationDescriptor = supporter.buildOperationDescriptor(mo, methods[i].getName());
supporter.addModelMBeanMethod(methods[i].getName(), paramTypes, paramNames, paramDescs, mo.description(), methods[i].getReturnType().getName(), operationDescriptor);
}
}
}
return supporter.buildModelMBeanInfo(mbeanDescriptor);
}
Aggregations