Search in sources :

Example 1 with Forecast

use of org.openhab.binding.weather.internal.annotation.Forecast in project openhab1-addons by openhab.

the class MetadataHandler method generate.

/**
     * Scans the class and generates metadata.
     */
public void generate(Class<?> clazz) throws IllegalAccessException {
    if (clazz == null) {
        return;
    }
    for (Field field : clazz.getDeclaredFields()) {
        if (field.getType().getName().startsWith(PACKAGE_TO_SCAN) && !field.isEnumConstant()) {
            generate(field.getType());
        } else {
            for (Annotation annotation : field.getAnnotations()) {
                if (annotation.annotationType().equals(ProviderMappings.class)) {
                    ProviderMappings providerAnnotations = (ProviderMappings) annotation;
                    for (Provider provider : providerAnnotations.value()) {
                        Map<String, ProviderMappingInfo> mappings = providerMappings.get(provider.name());
                        if (mappings == null) {
                            mappings = new HashMap<String, ProviderMappingInfo>();
                            providerMappings.put(provider.name(), mappings);
                        }
                        Converter<?> converter = getConverter(field, provider.converter());
                        String target = clazz.getSimpleName().toLowerCase() + "." + field.getName();
                        ProviderMappingInfo pm = new ProviderMappingInfo(provider.property(), target, converter);
                        mappings.put(pm.getSource(), pm);
                        logger.trace("Added provider mapping {}: {}", provider.name(), pm);
                    }
                } else if (annotation.annotationType().equals(ForecastMappings.class)) {
                    ForecastMappings forecastsAnnotations = (ForecastMappings) annotation;
                    for (Forecast forecast : forecastsAnnotations.value()) {
                        List<String> forecastProperties = forecastMappings.get(forecast.provider());
                        if (forecastProperties == null) {
                            forecastProperties = new ArrayList<String>();
                            forecastMappings.put(forecast.provider(), forecastProperties);
                        }
                        forecastProperties.add(forecast.property());
                        logger.trace("Added forecast mapping {}: {}", forecast.provider(), forecast.property());
                    }
                }
            }
        }
    }
}
Also used : ProviderMappings(org.openhab.binding.weather.internal.annotation.ProviderMappings) ForecastMappings(org.openhab.binding.weather.internal.annotation.ForecastMappings) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) Provider(org.openhab.binding.weather.internal.annotation.Provider) Field(java.lang.reflect.Field) Forecast(org.openhab.binding.weather.internal.annotation.Forecast) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Forecast (org.openhab.binding.weather.internal.annotation.Forecast)1 ForecastMappings (org.openhab.binding.weather.internal.annotation.ForecastMappings)1 Provider (org.openhab.binding.weather.internal.annotation.Provider)1 ProviderMappings (org.openhab.binding.weather.internal.annotation.ProviderMappings)1