Search in sources :

Example 1 with MapPropertiesProvider

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;
}
Also used : MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) PropertiesProvider(io.fabric8.api.gravia.PropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MapPropertiesProvider (io.fabric8.api.gravia.MapPropertiesProvider)1 PropertiesProvider (io.fabric8.api.gravia.PropertiesProvider)1 SubstitutionPropertiesProvider (io.fabric8.api.gravia.SubstitutionPropertiesProvider)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1