com.tngtech.configbuilder.util.PropertyLoaderConfigurator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of config-builder Show documentation
Show all versions of config-builder Show documentation
The Config Builder creates fully configured instances of config classes, using values from various sources like properties files, command line arguments etc.
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 extends PropertyLoaderConfigurationProcessor> processorClass = annotation.annotationType().getAnnotation(PropertyLoaderConfigurationAnnotation.class).value();
configBuilderFactory.getInstance(processorClass).configurePropertyLoader(annotation, propertyLoader);
}
return propertyLoader;
}
}