Search in sources :

Example 6 with Parameter

use of org.apache.dubbo.config.support.Parameter in project dubbo by alibaba.

the class AbstractConfig method appendAttributes.

@Deprecated
protected static void appendAttributes(Map<String, Object> parameters, Object config, String prefix) {
    if (config == null) {
        return;
    }
    Method[] methods = config.getClass().getMethods();
    for (Method method : methods) {
        try {
            Parameter parameter = method.getAnnotation(Parameter.class);
            if (parameter == null || !parameter.attribute()) {
                continue;
            }
            String name = method.getName();
            if (MethodUtils.isGetter(method)) {
                String key;
                if (parameter.key().length() > 0) {
                    key = parameter.key();
                } else {
                    key = calculateAttributeFromGetter(name);
                }
                Object value = method.invoke(config);
                if (value != null) {
                    if (prefix != null && prefix.length() > 0) {
                        key = prefix + "." + key;
                    }
                    parameters.put(key, value);
                }
            }
        } catch (Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }
}
Also used : Parameter(org.apache.dubbo.config.support.Parameter) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)6 Parameter (org.apache.dubbo.config.support.Parameter)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2