Example usage for javax.management.modelmbean ModelMBeanInfoSupport ModelMBeanInfoSupport

List of usage examples for javax.management.modelmbean ModelMBeanInfoSupport ModelMBeanInfoSupport

Introduction

In this page you can find the example usage for javax.management.modelmbean ModelMBeanInfoSupport ModelMBeanInfoSupport.

Prototype


public ModelMBeanInfoSupport(String className, String description, ModelMBeanAttributeInfo[] attributes,
        ModelMBeanConstructorInfo[] constructors, ModelMBeanOperationInfo[] operations,
        ModelMBeanNotificationInfo[] notifications, Descriptor mbeandescriptor) 

Source Link

Document

Creates a ModelMBeanInfoSupport with the provided information and the descriptor given in parameter.

Usage

From source file:org.eclipse.smila.management.jmx.DynamicMBeanBuilder.java

/**
 * Builds the model m bean info./*from   w w  w.ja  v  a 2s . c  om*/
 * 
 * @return the model m bean info
 * 
 * @throws IllegalAccessException
 *           the illegal access exception
 * @throws InvocationTargetException
 *           the invocation target exception
 */
private ModelMBeanInfo buildModelMBeanInfo() throws IllegalAccessException, InvocationTargetException {
    // lists
    final List<ModelMBeanOperationInfo> operationsList = new ArrayList<ModelMBeanOperationInfo>();
    final List<ModelMBeanAttributeInfo> attributesList = new ArrayList<ModelMBeanAttributeInfo>();
    // arrays
    final ModelMBeanConstructorInfo[] dConstructors = new ModelMBeanConstructorInfo[0];
    final ModelMBeanNotificationInfo[] dNotifications = new ModelMBeanNotificationInfo[0];
    for (final Method method : _methods) {
        if (!_skippedMethodsSet.contains(method.getName())) {
            // process getter
            if (method.getParameterTypes().length == 0 && method.getName().startsWith("get")
                    && !method.getName().equals("get") && method.getReturnType() != void.class) {
                String attributeName = method.getName().substring(3);
                final Descriptor attributeDescriptor;
                final boolean isPoc = PerformanceCounter.class.isAssignableFrom(method.getReturnType());

                String measureUnitStr = null;
                if (method.isAnnotationPresent(MeasureUnit.class)) {
                    measureUnitStr = method.getAnnotation(MeasureUnit.class).value();
                }

                Method setter = null;
                Class setterSignatureClass = null;
                for (final Method method1 : _methods) {
                    if (method1.getParameterTypes().length == 1 && (method1.getName().startsWith("set"))
                            && (method1.getName().substring(NUMBER_3).equals(attributeName))) {
                        setter = method1;
                        setterSignatureClass = method1.getParameterTypes()[0];
                        break;
                    }
                }

                if (measureUnitStr != null) {
                    attributeName += (" (" + measureUnitStr + ") ");
                }

                if (setter != null) {
                    attributeDescriptor = new DescriptorSupport(
                            new String[] { "name=" + attributeName, "descriptorType=attribute",
                                    "getMethod=" + method.getName(), "setMethod=" + setter.getName(),
                                    "setterSignatureClass=" + setterSignatureClass.getName() });
                } else {
                    if (isPoc) {
                        attributeDescriptor = new DescriptorSupport(new String[] { "name=" + attributeName,
                                "descriptorType=attribute", "getMethod=" + method.getName() });
                    } else {
                        attributeDescriptor = new DescriptorSupport(new String[] { "name=" + attributeName,
                                "descriptorType=attribute", "getMethod=" + method.getName() });
                    }
                }
                try {
                    final ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(attributeName,
                            attributeName, method, setter, attributeDescriptor);
                    attributesList.add(info);
                } catch (final IntrospectionException exception) {
                    _log.error("Error creating MBeanAttributeInfo [" + attributeName + "]", exception);
                }
            }
            // }
            final ModelMBeanOperationInfo info = new ModelMBeanOperationInfo("", method);
            operationsList.add(info);
        }
    }
    final ModelMBeanOperationInfo[] dOperations = operationsList
            .toArray(new ModelMBeanOperationInfo[operationsList.size()]);

    final ModelMBeanAttributeInfo[] dAttributes = attributesList
            .toArray(new ModelMBeanAttributeInfo[attributesList.size()]);

    final Descriptor beanDesc = new DescriptorSupport(
            new String[] { ("name=" + _objectName), "descriptorType=mbean", ("displayName=" + _beanName) });

    final ModelMBeanInfoSupport dMBeanInfo = new ModelMBeanInfoSupport(_beanName, "", dAttributes,
            dConstructors, dOperations, dNotifications, beanDesc);
    return dMBeanInfo;

}