Search in sources :

Example 6 with OpenMBeanParameterInfo

use of javax.management.openmbean.OpenMBeanParameterInfo in project jdk8u_jdk by JetBrains.

the class MXBeanIntrospector method getMBeanOperationInfo.

@Override
MBeanOperationInfo getMBeanOperationInfo(String operationName, ConvertingMethod operation) {
    final Method method = operation.getMethod();
    final String description = operationName;
    /* Ideally this would be an empty string, but
           OMBOperationInfo constructor forbids that.  Also, we
           could consult an annotation to get a useful
           description.  */
    final int impact = MBeanOperationInfo.UNKNOWN;
    final OpenType<?> returnType = operation.getOpenReturnType();
    final Type originalReturnType = operation.getGenericReturnType();
    final OpenType<?>[] paramTypes = operation.getOpenParameterTypes();
    final Type[] originalParamTypes = operation.getGenericParameterTypes();
    final MBeanParameterInfo[] params = new MBeanParameterInfo[paramTypes.length];
    boolean openReturnType = canUseOpenInfo(originalReturnType);
    boolean openParameterTypes = true;
    Annotation[][] annots = method.getParameterAnnotations();
    for (int i = 0; i < paramTypes.length; i++) {
        final String paramName = "p" + i;
        final String paramDescription = paramName;
        final OpenType<?> openType = paramTypes[i];
        final Type originalType = originalParamTypes[i];
        Descriptor descriptor = typeDescriptor(openType, originalType);
        descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForAnnotations(annots[i]));
        final MBeanParameterInfo pi;
        if (canUseOpenInfo(originalType)) {
            pi = new OpenMBeanParameterInfoSupport(paramName, paramDescription, openType, descriptor);
        } else {
            openParameterTypes = false;
            pi = new MBeanParameterInfo(paramName, originalTypeString(originalType), paramDescription, descriptor);
        }
        params[i] = pi;
    }
    Descriptor descriptor = typeDescriptor(returnType, originalReturnType);
    descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForElement(method));
    final MBeanOperationInfo oi;
    if (openReturnType && openParameterTypes) {
        /* If the return value and all the parameters can be faithfully
             * represented as OpenType then we return an OpenMBeanOperationInfo.
             * If any of them is a primitive type, we can't.  Compatibility
             * with JSR 174 means that we must return an MBean*Info where
             * the getType() is the primitive type, not its wrapped type as
             * we would get with an OpenMBean*Info.  The OpenType is available
             * in the Descriptor in either case.
             */
        final OpenMBeanParameterInfo[] oparams = new OpenMBeanParameterInfo[params.length];
        System.arraycopy(params, 0, oparams, 0, params.length);
        oi = new OpenMBeanOperationInfoSupport(operationName, description, oparams, returnType, impact, descriptor);
    } else {
        oi = new MBeanOperationInfo(operationName, description, params, openReturnType ? returnType.getClassName() : originalTypeString(originalReturnType), impact, descriptor);
    }
    return oi;
}
Also used : OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo) OpenType(javax.management.openmbean.OpenType) MBeanOperationInfo(javax.management.MBeanOperationInfo) OpenMBeanParameterInfoSupport(javax.management.openmbean.OpenMBeanParameterInfoSupport) Method(java.lang.reflect.Method) GenericArrayType(java.lang.reflect.GenericArrayType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Descriptor(javax.management.Descriptor) ImmutableDescriptor(javax.management.ImmutableDescriptor) OpenMBeanOperationInfoSupport(javax.management.openmbean.OpenMBeanOperationInfoSupport) MBeanParameterInfo(javax.management.MBeanParameterInfo) OpenMBeanParameterInfo(javax.management.openmbean.OpenMBeanParameterInfo)

Aggregations

OpenMBeanOperationInfoSupport (javax.management.openmbean.OpenMBeanOperationInfoSupport)6 OpenMBeanParameterInfo (javax.management.openmbean.OpenMBeanParameterInfo)6 OpenMBeanParameterInfoSupport (javax.management.openmbean.OpenMBeanParameterInfoSupport)5 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)4 OpenMBeanAttributeInfoSupport (javax.management.openmbean.OpenMBeanAttributeInfoSupport)4 OpenMBeanConstructorInfoSupport (javax.management.openmbean.OpenMBeanConstructorInfoSupport)4 OpenMBeanInfoSupport (javax.management.openmbean.OpenMBeanInfoSupport)4 OpenMBeanOperationInfo (javax.management.openmbean.OpenMBeanOperationInfo)4 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)3 OpenMBeanAttributeInfo (javax.management.openmbean.OpenMBeanAttributeInfo)3 OpenMBeanConstructorInfo (javax.management.openmbean.OpenMBeanConstructorInfo)3 Descriptor (javax.management.Descriptor)2 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 MBeanParameterInfo (javax.management.MBeanParameterInfo)2 OpenMBeanInfo (javax.management.openmbean.OpenMBeanInfo)2 GenericArrayType (java.lang.reflect.GenericArrayType)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1