Search in sources :

Example 1 with PropertiesDesc

use of org.glassfish.api.admin.config.PropertiesDesc 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)

Example 2 with PropertiesDesc

use of org.glassfish.api.admin.config.PropertiesDesc in project Payara by payara.

the class AttributeMethodVisitor method visitAnnotation.

/**
 * Visits an annotation of this method.
 *
 * @param desc the class descriptor of the annotation class.
 * @param visible <tt>true</tt> if the annotation is visible at runtime.
 *
 * @return a visitor to visit the annotation values, or <tt>null</tt> if this visitor is not interested in visiting
 *         this annotation.
 */
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
    duckTyped |= "Lorg/jvnet/hk2/config/DuckTyped;".equals(desc);
    AnnotationVisitor visitor = null;
    if ("Lorg/jvnet/hk2/config/Attribute;".equals(desc) || "Lorg/jvnet/hk2/config/Element;".equals(desc)) {
        try {
            final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
            final Attribute annotation = configurable.getMethod(name).getAnnotation(Attribute.class);
            def.addAttribute(name, annotation);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } else if ("Lorg/glassfish/api/admin/config/PropertiesDesc;".equals(desc)) {
        try {
            final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
            final PropertiesDesc annotation = configurable.getMethod(name).getAnnotation(PropertiesDesc.class);
            final PropertyDesc[] propertyDescs = annotation.props();
            for (PropertyDesc prop : propertyDescs) {
                def.addProperty(prop);
            }
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return visitor;
}
Also used : PropertiesDesc(org.glassfish.api.admin.config.PropertiesDesc) Attribute(org.jvnet.hk2.config.Attribute) AnnotationVisitor(org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor) PropertyDesc(org.glassfish.api.admin.config.PropertyDesc)

Aggregations

PropertiesDesc (org.glassfish.api.admin.config.PropertiesDesc)2 PropertyDesc (org.glassfish.api.admin.config.PropertyDesc)2 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 AnnotationVisitor (org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor)1 ToDo (org.glassfish.quality.ToDo)1 Attribute (org.jvnet.hk2.config.Attribute)1