com.tngtech.configbuilder.annotation.valueextractor.PropertyValueProcessor 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.annotation.valueextractor;
import com.tngtech.configbuilder.configuration.BuilderConfiguration;
import com.tngtech.configbuilder.util.ConfigBuilderFactory;
import java.lang.annotation.Annotation;
import java.util.Properties;
/**
* Processes PropertyValue annotations, implements ValueExtractorProcessor
*/
public class PropertyValueProcessor implements ValueExtractorProcessor {
public String getValue(Annotation annotation, ConfigBuilderFactory configBuilderFactory) {
BuilderConfiguration builderConfiguration = configBuilderFactory.getInstance(BuilderConfiguration.class);
final Properties properties = builderConfiguration.getProperties();
final String propertyName = ((PropertyValue) annotation).value();
for (final String propertyNamePrefix : builderConfiguration.getPropertyNamePrefixes()) {
final String fullPropertyName = propertyNamePrefix + propertyName;
if (properties.containsKey(fullPropertyName)) {
return properties.getProperty(fullPropertyName);
}
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy