use of io.fabric8.api.gravia.MapPropertiesProvider in project fabric8 by jboss-fuse.
the class ComponentConfigurer method configure.
@Override
public <T> Map<String, ?> configure(final Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
assertValid();
Map<String, Object> result = new HashMap<>();
final PropertiesProvider runtimeProperties = new PropertiesProvider() {
@Override
public Object getProperty(String key) {
return bundleContext.getProperty(key);
}
@Override
public Object getRequiredProperty(String key) {
String value = bundleContext.getProperty(key);
IllegalStateAssertion.assertNotNull(value, "Cannot obtain property: " + key);
return value;
}
@Override
public Object getProperty(String key, Object defaultValue) {
String value = bundleContext.getProperty(key);
return value != null ? value : defaultValue;
}
};
final PropertiesProvider configurationProvider = new MapPropertiesProvider((Map<String, Object>) configuration);
final PropertiesProvider[] propertiesProviders = new PropertiesProvider[] { configurationProvider, runtimeProperties };
PropertiesProvider provider = new SubstitutionPropertiesProvider(propertiesProviders);
for (Map.Entry<String, ?> entry : configuration.entrySet()) {
String key = entry.getKey();
Object value = provider.getProperty(key);
result.put(key, value);
}
ConfigInjection.applyConfiguration(result, target, ignorePrefix);
return result;
}
Aggregations