Search in sources :

Example 1 with ToDo

use of org.glassfish.quality.ToDo in project Payara by payara.

the class ConfigBeanJMXSupport method elementToMBeanAttributeInfo.

/**
 *    @Elements are represented as Attributes:  getters for sub-elements are presented
 *    as ObjectName, Collection<String> presented as String[], Collection<? extends ConfigBeanProxy>
 *    represented as ObjectName[].
 */
public MBeanAttributeInfo elementToMBeanAttributeInfo(final Method m) {
    // we assume that all getters are writeable for now, not true for sub-elements (ObjectName)
    boolean isWriteable = true;
    final ElementMethodInfo info = ElementMethodInfo.get(m);
    if (info == null || info.anonymous()) {
        return null;
    }
    // eg strip the "get"
    final String name = info.attrName();
    final String xmlName = info.xmlName();
    // debug( m.getName() + " => " + name + " => " + xmlName );
    final Class methodReturnType = info.returnType();
    Class<?> returnType = null;
    if (info.intf() != null) {
        // some sub-type, which we must represent as an ObjectName
        returnType = ObjectName.class;
        isWriteable = false;
    } else if (Collection.class.isAssignableFrom(methodReturnType)) {
        final Type genericReturnType = m.getGenericReturnType();
        if (genericReturnType instanceof ParameterizedType) {
            final ParameterizedType pt = (ParameterizedType) genericReturnType;
            final Type[] argTypes = pt.getActualTypeArguments();
            if (argTypes.length == 1) {
                final Type argType = argTypes[0];
                if ((argType instanceof Class) && (Class) argType == String.class) {
                    returnType = String[].class;
                } else {
                    returnType = ObjectName[].class;
                    isWriteable = false;
                }
            }
        }
    } else {
    // some unknown type we cannot handle
    }
    MBeanAttributeInfo attrInfo = null;
    if (returnType != null) {
        final DescriptorSupport descriptor = descriptor(info.element());
        descriptor.setField(DESC_ELEMENT_CLASS, returnType.getName());
        descriptor.setField(DESC_XML_NAME, xmlName);
        final ToDo toDo = info.method().getAnnotation(ToDo.class);
        if (toDo != null) {
            descriptor.setField(DESC_CONFIG_PREFIX + "toDo", toDo.priority() + ", " + toDo.details());
        }
        final PropertiesDesc props = info.method().getAnnotation(PropertiesDesc.class);
        if (props != null) {
            final String propType = props.systemProperties() ? "system-property" : "property";
            for (final PropertyDesc p : props.props()) {
                final String value = p.defaultValue() + " | " + p.dataType().getName() + " | " + p.description();
                descriptor.setField(DESC_CONFIG_PREFIX + propType + "." + p.name(), value);
            }
        }
        String description = "@Element " + name + " of interface " + mIntf.getName();
        final boolean isReadable = true;
        final boolean isIs = false;
        attrInfo = new MBeanAttributeInfo(name, returnType.getName(), description, isReadable, isWriteable, isIs, descriptor);
    }
    return attrInfo;
}
Also used : ToDo(org.glassfish.quality.ToDo) DescriptorSupport(javax.management.modelmbean.DescriptorSupport) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ParameterizedType(java.lang.reflect.ParameterizedType) PropertiesDesc(org.glassfish.api.admin.config.PropertiesDesc) Type(java.lang.reflect.Type) CompositeType(javax.management.openmbean.CompositeType) OpenType(javax.management.openmbean.OpenType) ParameterizedType(java.lang.reflect.ParameterizedType) Collection(java.util.Collection) PropertyDesc(org.glassfish.api.admin.config.PropertyDesc)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 DescriptorSupport (javax.management.modelmbean.DescriptorSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 OpenType (javax.management.openmbean.OpenType)1 PropertiesDesc (org.glassfish.api.admin.config.PropertiesDesc)1 PropertyDesc (org.glassfish.api.admin.config.PropertyDesc)1 ToDo (org.glassfish.quality.ToDo)1