...
Code Block |
---|
/** * An implementation of {@link ConfigProvider} that simply uses a Properties file. */ public class FileConfigProvider implements ConfigProvider { private static final Logger log = LoggerFactory.getLogger(FileConfigProvider.class); public final static String FILE_NAME = "filename"; private Properties properties; /** * Configure this class with the initialization parameters */ public void configure(Map<String, ?> configs) { String fileName = (String) configs.get(FILE_NAME); try { (FileReader fileReader = new FileReader(fileName);) { properties = new Properties(); properties.load(fileReader); } catch (IOException e) { throw new ConfigException("File name " + fileName + " not found for FileConfigProvider"); } } /** * Transform the configs by resolving all indirect references */ public Map<String, String> transform(ConfigContext ctx, Map<String, String> configs) { Map<String, String> newConfigs = new HashMap<>(); for (Map.Entry<String, String> config : configs.entrySet()) { String value = properties.getProperty(config.getValue()); if (value != null) { log.info("Replacing {} for key {}", config.getValue(), config.getKey()); newConfigs.put(config.getKey(), value); } } return newConfigs; } public void close() { } } |
...