@Override public ConfigurationContextBuilder setContext(ConfigurationContext context) { this.propertySources.clear(); for(PropertySource ps:context.getPropertySources()) { this.propertySources.put(ps.getName(), ps); } this.propertyFilters.clear(); this.propertyFilters.addAll(context.getPropertyFilters()); this.propertyConverters.clear(); this.propertyConverters.putAll(context.getPropertyConverters()); this.combinationPolicy = context.getPropertyValueCombinationPolicy(); return this; }
@Override public Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); for (PropertySource propertySource : context.getPropertySources()) { for (Map.Entry<String,PropertyValue> propEntry: propertySource.getProperties().entrySet()) { PropertyValue unfilteredValue = result.get(propEntry.getKey()); unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, propEntry.getKey(), propertySource); if(unfilteredValue!=null){ result.put(unfilteredValue.getKey(), unfilteredValue); } } } return result; }
@Override public ConfigurationContextBuilder setContext(ConfigurationContext context) { checkBuilderState(); this.propertyConverters.putAll(context.getPropertyConverters()); for(PropertySource ps:context.getPropertySources()){ this.propertySources.add(ps); } this.propertyFilters.addAll(context.getPropertyFilters()); this.combinationPolicy = context.getPropertyValueCombinationPolicy(); return this; }
@Override public Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); for (PropertySource propertySource : context.getPropertySources()) { for (Map.Entry<String,PropertyValue> propEntry: propertySource.getProperties().entrySet()) { PropertyValue unfilteredValue = result.get(propEntry.getKey()); unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, propEntry.getKey(), propertySource); if(unfilteredValue!=null){ result.put(unfilteredValue.getKey(), unfilteredValue); } } } return result; }
/** * Evaluates the raw value using the context's PropertyValueCombinationPolicy. * @param key the key, not null. * @return the value, before filtering is applied. */ protected PropertyValue evaluteRawValue(String key) { List<PropertySource> propertySources = configurationContext.getPropertySources(); PropertyValue filteredValue = null; PropertyValueCombinationPolicy combinationPolicy = this.configurationContext .getPropertyValueCombinationPolicy(); for (PropertySource propertySource : propertySources) { filteredValue = combinationPolicy.collect(filteredValue, key, propertySource); } return filteredValue; }
@Override public ConfigurationContextBuilder setContext(ConfigurationContext context) { checkBuilderState(); this.propertyConverters.putAll(context.getPropertyConverters()); for(PropertySource ps:context.getPropertySources()){ this.propertySources.add(ps); } this.propertyFilters.addAll(context.getPropertyFilters()); this.combinationPolicy = context.getPropertyValueCombinationPolicy(); return this; }
/** * Allows to set configuration context during unit tests. */ ConfigurationContextBuilder setConfigurationContext(ConfigurationContext configurationContext) { checkBuilderState(); //noinspection deprecation this.propertyFilters.clear(); this.propertyFilters.addAll(configurationContext.getPropertyFilters()); this.propertySources.clear(); for(PropertySource ps:configurationContext.getPropertySources()) { addPropertySources(ps); } this.propertyConverters.clear(); this.propertyConverters.putAll(configurationContext.getPropertyConverters()); this.combinationPolicy = configurationContext.getPropertyValueCombinationPolicy(); return this; }
/** * Creates a new builder instance. */ public DefaultConfigurationContextBuilder(ConfigurationContext context) { this.propertyConverters.putAll(context.getPropertyConverters()); this.propertyFilters.addAll(context.getPropertyFilters()); for(PropertySource ps:context.getPropertySources()) { addPropertySources(ps); } this.combinationPolicy = context.getPropertyValueCombinationPolicy(); }
/** * Allows to set configuration context during unit tests. */ ConfigurationContextBuilder setConfigurationContext(ConfigurationContext configurationContext) { checkBuilderState(); //noinspection deprecation this.propertyFilters.clear(); this.propertyFilters.addAll(configurationContext.getPropertyFilters()); this.propertySources.clear(); for(PropertySource ps:configurationContext.getPropertySources()) { addPropertySources(ps); } this.propertyConverters.clear(); this.propertyConverters.putAll(configurationContext.getPropertyConverters()); this.combinationPolicy = configurationContext.getPropertyValueCombinationPolicy(); return this; }
/** * Creates a new builder instance. */ public DefaultConfigurationContextBuilder(ConfigurationContext context) { this.propertyConverters.putAll(context.getPropertyConverters()); this.propertyFilters.addAll(context.getPropertyFilters()); for(PropertySource ps:context.getPropertySources()) { addPropertySources(ps); } this.combinationPolicy = context.getPropertyValueCombinationPolicy(); }
/** * Should be never used. */ @Deprecated public Builder setConfigurationContext(ConfigurationContext configurationContext) { this.addPropertySources(configurationContext.getPropertySources()); this.addPropertyFilters(configurationContext.getPropertyFilters()); this.propertyValueCombinationPolicy = Objects.requireNonNull( configurationContext.getPropertyValueCombinationPolicy()); return this; }
@Override public PropertyValue evaluteRawValue(String key, ConfigurationContext context) { PropertyValue unfilteredValue = null; for (PropertySource propertySource : context.getPropertySources()) { unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, key, propertySource); } if(unfilteredValue==null || unfilteredValue.getValue()==null){ return unfilteredValue; } return unfilteredValue; }
@Override public PropertyValue evaluteRawValue(String key, ConfigurationContext context) { PropertyValue unfilteredValue = null; for (PropertySource propertySource : context.getPropertySources()) { unfilteredValue = context.getPropertyValueCombinationPolicy(). collect(unfilteredValue, key, propertySource); } if(unfilteredValue==null || unfilteredValue.getValue()==null){ return unfilteredValue; } return unfilteredValue; }
/** * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances * provided by the current {@link org.apache.tamaya.spi.ConfigurationContext}. The first non-null-value returned * is taken as an intermediate value. Finally the value is filtered through the * {@link org.apache.tamaya.spi.PropertyFilter} instances installed, before it is returned as the final result of * this method. * * @param key the property's key, not null. * @return the optional configuration value, never null. */ @Override public String get(String key) { List<PropertySource> propertySources = configurationContext.getPropertySources(); String unfilteredValue = null; PropertyValueCombinationPolicy combinationPolicy = this.configurationContext .getPropertyValueCombinationPolicy(); for (PropertySource propertySource : propertySources) { unfilteredValue = combinationPolicy.collect(unfilteredValue, key, propertySource); } return applyFilter(key, unfilteredValue); }