All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tngtech.configbuilder.util.PropertyLoaderConfigurator Maven / Gradle / Ivy

Go to download

The Config Builder creates fully configured instances of config classes, using values from various sources like properties files, command line arguments etc.

There is a newer version: 1.8.1
Show newest version
package com.tngtech.configbuilder.util;


import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationProcessor;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLoaderConfigurationAnnotation;
import com.tngtech.propertyloader.PropertyLoader;

import java.lang.annotation.Annotation;

public class PropertyLoaderConfigurator {
    private AnnotationHelper annotationHelper;
    private ConfigBuilderFactory configBuilderFactory;

    public PropertyLoaderConfigurator(ConfigBuilderFactory configBuilderFactory) {
        this.annotationHelper = configBuilderFactory.getInstance(AnnotationHelper.class);
        this.configBuilderFactory = configBuilderFactory;
    }

    public PropertyLoader configurePropertyLoader(Class configClass) {

        PropertyLoader propertyLoader = configBuilderFactory.createInstance(PropertyLoader.class).withDefaultConfig();
        for (Annotation annotation : annotationHelper.getAnnotationsAnnotatedWith(configClass.getDeclaredAnnotations(), PropertyLoaderConfigurationAnnotation.class)) {
            Class processorClass = annotation.annotationType().getAnnotation(PropertyLoaderConfigurationAnnotation.class).value();
            configBuilderFactory.getInstance(processorClass).configurePropertyLoader(annotation, propertyLoader);
        }
        return propertyLoader;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy