Search in sources :

Example 1 with DefaultBeanReference

use of org.glassfish.admin.rest.composite.metadata.DefaultBeanReference in project Payara by payara.

the class CompositeUtil method analyzeInterface.

private void analyzeInterface(Class<?> iface, Map<String, Map<String, Object>> properties) throws SecurityException {
    // find class level bean reference
    String defaultBean = null;
    if (iface.isAnnotationPresent(DefaultBeanReference.class)) {
        DefaultBeanReference beanRef = iface.getAnnotation(DefaultBeanReference.class);
        defaultBean = beanRef.bean();
    }
    for (Method method : iface.getMethods()) {
        String name = method.getName();
        final boolean isGetter = name.startsWith("get");
        if (isGetter || name.startsWith("set")) {
            name = name.substring(3);
            Map<String, Object> property = properties.get(name);
            if (property == null) {
                property = new HashMap<String, Object>();
                properties.put(name, property);
            }
            String bean = null;
            String attribute = null;
            AttributeReference ar = method.getAnnotation(AttributeReference.class);
            if (ar != null) {
                bean = ar.bean();
                attribute = ar.attribute();
            }
            if (!StringUtil.notEmpty(bean)) {
                bean = defaultBean;
            }
            if (!StringUtil.notEmpty(attribute)) {
                attribute = name;
            }
            if (StringUtil.notEmpty(bean) && StringUtil.notEmpty(attribute)) {
                property.put("annotations", gatherReferencedAttributes(bean, attribute));
            }
            Attribute attr = method.getAnnotation(Attribute.class);
            if (attr != null) {
                property.put("defaultValue", attr.defaultValue());
            }
            Class<?> type = isGetter ? method.getReturnType() : method.getParameterTypes()[0];
            property.put("type", type);
        }
    }
}
Also used : DefaultBeanReference(org.glassfish.admin.rest.composite.metadata.DefaultBeanReference) Attribute(org.jvnet.hk2.config.Attribute) AttributeReference(org.glassfish.admin.rest.composite.metadata.AttributeReference) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)1 JsonObject (javax.json.JsonObject)1 JsonString (javax.json.JsonString)1 AttributeReference (org.glassfish.admin.rest.composite.metadata.AttributeReference)1 DefaultBeanReference (org.glassfish.admin.rest.composite.metadata.DefaultBeanReference)1 Attribute (org.jvnet.hk2.config.Attribute)1