Search in sources :

Example 1 with ServiceProperty

use of org.springframework.cloud.service.ServiceInfo.ServiceProperty in project spring-cloud-connectors by spring-cloud.

the class ServiceConnectorCreatorRegistry method getServiceProperties.

private Properties getServiceProperties(String keyLead, ServiceInfo serviceInfo) {
    Properties cloudProperties = new Properties();
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(serviceInfo.getClass());
        PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor propDescriptor : propDescriptors) {
            ServiceProperty propAnnotation = propDescriptor.getReadMethod().getAnnotation(ServiceProperty.class);
            String key = keyLead;
            if (propAnnotation != null) {
                if (!propAnnotation.category().isEmpty()) {
                    key = key + "." + propAnnotation.category();
                }
                if (!propAnnotation.name().isEmpty()) {
                    key = key + "." + propAnnotation.name();
                } else {
                    key = key + "." + propDescriptor.getName().toLowerCase();
                }
                Object value = propDescriptor.getReadMethod().invoke(serviceInfo);
                if (value != null) {
                    cloudProperties.put(key, value);
                }
            }
        }
    } catch (Exception e) {
        throw new CloudException(e);
    }
    return cloudProperties;
}
Also used : ServiceProperty(org.springframework.cloud.service.ServiceInfo.ServiceProperty) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) Properties(java.util.Properties)

Aggregations

BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Properties (java.util.Properties)1 ServiceProperty (org.springframework.cloud.service.ServiceInfo.ServiceProperty)1