http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java new file mode 100644 index 0000000..d880e8d --- /dev/null +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport; + +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.*; + +import java.util.*; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.logging.Logger; + +/** + * Default implementation of a simple ConfigurationContext. + */ +public class DefaultConfigurationContext implements ConfigurationContext { + + /** The logger used. */ + private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName()); + + /** + * Subcomponent handling {@link PropertyConverter} instances. + */ + private final PropertyConverterManager propertyConverterManager = new PropertyConverterManager(); + + /** + * The current unmodifiable list of loaded {@link PropertySource} instances. + */ + private List<PropertySource> immutablePropertySources; + + /** + * The current unmodifiable list of loaded {@link PropertyFilter} instances. + */ + private List<PropertyFilter> immutablePropertyFilters; + + /** + * The overriding policy used when combining PropertySources registered to evalute the final configuration + * values. + */ + private PropertyValueCombinationPolicy propertyValueCombinationPolicy; + + /** + * Lock for internal synchronization. + */ + private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock(); + + @SuppressWarnings("unchecked") + protected DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) { + List<PropertySource> propertySources = new ArrayList<>(); + // first we load all PropertySources which got registered via java.util.ServiceLoader + propertySources.addAll(builder.propertySources); + // now sort them according to their ordinal values + immutablePropertySources = Collections.unmodifiableList(propertySources); + + // as next step we pick up the PropertyFilters pretty much the same way + List<PropertyFilter> propertyFilters = new ArrayList<>(builder.getPropertyFilters()); + immutablePropertyFilters = Collections.unmodifiableList(propertyFilters); + + // Finally add the converters + for(Map.Entry<TypeLiteral<?>, Collection<PropertyConverter<?>>> en:builder.getPropertyConverter().entrySet()) { + for (@SuppressWarnings("rawtypes") PropertyConverter converter : en.getValue()) { + this.propertyConverterManager.register(en.getKey(), converter); + } + } + LOG.info("Registered " + propertyConverterManager.getPropertyConverters().size() + " property converters: " + + propertyConverterManager.getPropertyConverters()); + + propertyValueCombinationPolicy = builder.combinationPolicy; + if(propertyValueCombinationPolicy==null){ + propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class); + } + if(propertyValueCombinationPolicy==null){ + propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR; + } + LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy); + } + + + @Deprecated + @Override + public void addPropertySources(PropertySource... propertySourcesToAdd) { + Lock writeLock = propertySourceLock.writeLock(); + try { + writeLock.lock(); + List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources); + newPropertySources.addAll(Arrays.asList(propertySourcesToAdd)); + Collections.sort(newPropertySources, PropertySourceComparator.getInstance()); + + this.immutablePropertySources = Collections.unmodifiableList(newPropertySources); + } finally { + writeLock.unlock(); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof DefaultConfigurationContext)){ + return false; + } + + DefaultConfigurationContext that = (DefaultConfigurationContext) o; + + if (!propertyConverterManager.equals(that.propertyConverterManager)) { + return false; + } + if (!immutablePropertySources.equals(that.immutablePropertySources)) { + return false; + } + if (!immutablePropertyFilters.equals(that.immutablePropertyFilters)) { + return false; + } + return getPropertyValueCombinationPolicy().equals(that.getPropertyValueCombinationPolicy()); + + } + + @Override + public int hashCode() { + int result = propertyConverterManager.hashCode(); + result = 31 * result + immutablePropertySources.hashCode(); + result = 31 * result + immutablePropertyFilters.hashCode(); + result = 31 * result + getPropertyValueCombinationPolicy().hashCode(); + return result; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder("ConfigurationContext{\n"); + b.append(" Property Sources\n"); + b.append(" ----------------\n"); + if(immutablePropertySources.isEmpty()){ + b.append(" No property sources loaded.\n\n"); + }else { + b.append(" CLASS NAME ORDINAL SCANNABLE SIZE STATE ERROR\n\n"); + for (PropertySource ps : immutablePropertySources) { + b.append(" "); + appendFormatted(b, ps.getClass().getSimpleName(), 30); + appendFormatted(b, ps.getName(), 70); + appendFormatted(b, String.valueOf(PropertySourceComparator.getOrdinal(ps)), 8); + appendFormatted(b, String.valueOf(ps.isScannable()), 10); + if (ps.isScannable()) { + appendFormatted(b, String.valueOf(ps.getProperties().size()), 8); + } else { + appendFormatted(b, "-", 8); + } + PropertyValue state = ps.get("_state"); + if(state==null){ + appendFormatted(b, "OK", 10); + }else { + appendFormatted(b, state.getValue(), 10); + if("ERROR".equals(state.getValue())){ + PropertyValue val = ps.get("_exception"); + if(val!=null) { + appendFormatted(b, val.getValue(), 30); + } + } + } + b.append('\n'); + } + b.append("\n"); + } + b.append(" Property Filters\n"); + b.append(" ----------------\n"); + if(immutablePropertyFilters.isEmpty()){ + b.append(" No property filters loaded.\n\n"); + }else { + b.append(" CLASS INFO\n\n"); + for (PropertyFilter filter : getPropertyFilters()) { + b.append(" "); + appendFormatted(b, filter.getClass().getSimpleName(), 30); + b.append(removeNewLines(filter.toString())); + b.append('\n'); + } + b.append("\n\n"); + } + b.append(" Property Converters\n"); + b.append(" -------------------\n"); + b.append(" CLASS TYPE INFO\n\n"); + for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> converterEntry:getPropertyConverters().entrySet()){ + for(PropertyConverter converter: converterEntry.getValue()){ + b.append(" "); + appendFormatted(b, converter.getClass().getSimpleName(), 30); + appendFormatted(b, converterEntry.getKey().getRawType().getSimpleName(), 30); + b.append(removeNewLines(converter.toString())); + b.append('\n'); + } + } + b.append("\n\n"); + b.append(" PropertyValueCombinationPolicy: " + getPropertyValueCombinationPolicy().getClass().getName()).append('\n'); + b.append('}'); + return b.toString(); + } + + private void appendFormatted(StringBuilder b, String text, int length) { + int padding; + if(text.length() <= (length)){ + b.append(text); + padding = length - text.length(); + }else{ + b.append(text.substring(0, length-1)); + padding = 1; + } + for(int i=0;i<padding;i++){ + b.append(' '); + } + } + + private String removeNewLines(String s) { + return s.replace('\n', ' ').replace('\r', ' '); + } + + + @Override + public List<PropertySource> getPropertySources() { + return immutablePropertySources; + } + + @Override + public PropertySource getPropertySource(String name) { + for(PropertySource ps:getPropertySources()){ + if(name.equals(ps.getName())){ + return ps; + } + } + return null; + } + + @Override + public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) { + propertyConverterManager.register(typeToConvert, propertyConverter); + LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName()); + } + + @Override + public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() { + return propertyConverterManager.getPropertyConverters(); + } + + @Override + public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) { + return propertyConverterManager.getPropertyConverters(targetType); + } + + @Override + public List<PropertyFilter> getPropertyFilters() { + return immutablePropertyFilters; + } + + @Override + public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){ + return propertyValueCombinationPolicy; + } + + @Override + public ConfigurationContextBuilder toBuilder() { + return new DefaultConfigurationContextBuilder(this); + } + +}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java new file mode 100644 index 0000000..079527f --- /dev/null +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java @@ -0,0 +1,437 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spisupport; + +import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.*; +import org.apache.tamaya.spisupport.propertysource.CLIPropertySource; +import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource; +import org.apache.tamaya.spisupport.propertysource.JavaConfigurationPropertySource; +import org.apache.tamaya.spisupport.propertysource.SystemPropertySource; + +import java.io.File; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URI; +import java.net.URL; +import java.nio.file.Path; +import java.util.*; +import java.util.logging.Logger; + +/** + * Default implementation of {@link ConfigurationContextBuilder}. + */ +public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder { + + private static final Logger LOG = Logger.getLogger(DefaultConfigurationContextBuilder.class.getName()); + + protected List<PropertyFilter> propertyFilters = new ArrayList<>(); + protected List<PropertySource> propertySources = new ArrayList<>(); + protected PropertyValueCombinationPolicy combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY; + protected Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> propertyConverters = new HashMap<>(); + + /** + * Flag if the config has already been built. + * Configuration can be built only once + */ + private boolean built; + + + + /** + * Creates a new builder instance. + */ + public DefaultConfigurationContextBuilder() { + } + + /** + * Creates a new builder instance initializing it with the given context. + * @param context the context to be used, not null. + */ + 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 reset configuration context during unit tests. + */ + public final ConfigurationContextBuilder resetWithConfigurationContext(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; + } + + + @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 final ConfigurationContextBuilder addPropertySources(PropertySource... sources){ + return addPropertySources(Arrays.asList(sources)); + } + + @Override + public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> sources){ + checkBuilderState(); + for(PropertySource source:sources) { + if (!this.propertySources.contains(source)) { + this.propertySources.add(source); + } + } + return this; + } + + @Override + public ConfigurationContextBuilder addDefaultPropertySources() { + checkBuilderState(); + List<PropertySource> propertySources = new ArrayList<>(); + addCorePropertyResources(propertySources); + for(PropertySource ps: ServiceContextManager.getServiceContext().getServices(PropertySource.class)) { + if(!propertySources.contains(ps)){ + propertySources.add(ps); + } + } + for(PropertySourceProvider provider: + ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class)){ + propertySources.addAll(provider.getPropertySources()); + } + Collections.sort(propertySources, PropertySourceComparator.getInstance()); + return addPropertySources(propertySources); + } + + protected void addCorePropertyResources(List<PropertySource> propertySources) { + for(PropertySource ps: new PropertySource[]{ + new EnvironmentPropertySource(), + new JavaConfigurationPropertySource(), + new CLIPropertySource(), + new SystemPropertySource() + }){ + if(!propertySources.contains(ps)){ + propertySources.add(ps); + } + } + } + + @Override + public ConfigurationContextBuilder addDefaultPropertyFilters() { + checkBuilderState(); + for(PropertyFilter pf:ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)){ + addPropertyFilters(pf); + } + return this; + } + + @Override + public DefaultConfigurationContextBuilder addDefaultPropertyConverters() { + checkBuilderState(); + addCorePropertyConverters(); + for(Map.Entry<TypeLiteral, Collection<PropertyConverter>> en:getDefaultPropertyConverters().entrySet()){ + for(PropertyConverter pc: en.getValue()) { + addPropertyConverters(en.getKey(), pc); + } + } + return this; + } + + @SuppressWarnings("unchecked") + protected void addCorePropertyConverters() { + // should be overridden by subclasses. + } + + @Override + public final ConfigurationContextBuilder removePropertySources(PropertySource... propertySources) { + return removePropertySources(Arrays.asList(propertySources)); + } + + @Override + public ConfigurationContextBuilder removePropertySources(Collection<PropertySource> propertySources) { + checkBuilderState(); + this.propertySources.removeAll(propertySources); + return this; + } + + protected PropertySource getPropertySource(String name) { + for(PropertySource ps:propertySources){ + if(ps.getName().equals(name)){ + return ps; + } + } + throw new IllegalArgumentException("No such PropertySource: "+name); + } + + @Override + public List<PropertySource> getPropertySources() { + return Collections.unmodifiableList(this.propertySources); + } + + @Override + public ConfigurationContextBuilder increasePriority(PropertySource propertySource) { + checkBuilderState(); + int index = propertySources.indexOf(propertySource); + if(index<0){ + throw new IllegalArgumentException("No such PropertySource: " + propertySource); + } + if(index<(propertySources.size()-1)){ + propertySources.remove(propertySource); + propertySources.add(index+1, propertySource); + } + return this; + } + + @Override + public ConfigurationContextBuilder decreasePriority(PropertySource propertySource) { + checkBuilderState(); + int index = propertySources.indexOf(propertySource); + if(index<0){ + throw new IllegalArgumentException("No such PropertySource: " + propertySource); + } + if(index>0){ + propertySources.remove(propertySource); + propertySources.add(index-1, propertySource); + } + return this; + } + + @Override + public ConfigurationContextBuilder highestPriority(PropertySource propertySource) { + checkBuilderState(); + int index = propertySources.indexOf(propertySource); + if(index<0){ + throw new IllegalArgumentException("No such PropertySource: " + propertySource); + } + if(index<(propertySources.size()-1)){ + propertySources.remove(propertySource); + propertySources.add(propertySource); + } + return this; + } + + @Override + public ConfigurationContextBuilder lowestPriority(PropertySource propertySource) { + checkBuilderState(); + int index = propertySources.indexOf(propertySource); + if(index<0){ + throw new IllegalArgumentException("No such PropertySource: " + propertySource); + } + if(index>0){ + propertySources.remove(propertySource); + propertySources.add(0, propertySource); + } + return this; + } + + @Override + public final ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters){ + return addPropertyFilters(Arrays.asList(filters)); + } + + @Override + public final ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters){ + checkBuilderState(); + for(PropertyFilter f:filters) { + if (!this.propertyFilters.contains(f)) { + this.propertyFilters.add(f); + } + } + return this; + } + + @Override + public final ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) { + return removePropertyFilters(Arrays.asList(filters)); + } + + @Override + public final ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) { + checkBuilderState(); + this.propertyFilters.removeAll(filters); + return this; + } + + + @Override + public final <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert, + @SuppressWarnings("unchecked") PropertyConverter<T>... converters) { + return removePropertyConverters(typeToConvert, Arrays.asList(converters)); + } + + @Override + public final <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert, + Collection<PropertyConverter<T>> converters) { + Collection<PropertyConverter<?>> subConverters = this.propertyConverters.get(typeToConvert); + if(subConverters!=null) { + subConverters.removeAll(converters); + } + return this; + } + + @Override + public final ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert) { + this.propertyConverters.remove(typeToConvert); + return this; + } + + + @Override + public final ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy combinationPolicy){ + checkBuilderState(); + this.combinationPolicy = Objects.requireNonNull(combinationPolicy); + return this; + } + + + @Override + public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> type, PropertyConverter<T>... propertyConverters){ + checkBuilderState(); + Objects.requireNonNull(type); + Objects.requireNonNull(propertyConverters); + Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type); + if(converters==null){ + converters = new ArrayList<>(); + this.propertyConverters.put(type, converters); + } + for(PropertyConverter<T> propertyConverter:propertyConverters) { + if (!converters.contains(propertyConverter)) { + converters.add(propertyConverter); + } else { + LOG.warning("Converter ignored, already registered: " + propertyConverter); + } + } + return this; + } + + @Override + public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> type, Collection<PropertyConverter<T>> propertyConverters){ + checkBuilderState(); + Objects.requireNonNull(type); + Objects.requireNonNull(propertyConverters); + Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type); + if(converters==null){ + converters = new ArrayList<>(); + this.propertyConverters.put(type, converters); + } + for(PropertyConverter<T> propertyConverter:propertyConverters) { + if (!converters.contains(propertyConverter)) { + converters.add(propertyConverter); + } else { + LOG.warning("Converter ignored, already registered: " + propertyConverter); + } + } + return this; + } + + protected ConfigurationContextBuilder loadDefaults() { + checkBuilderState(); + this.combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR; + addDefaultPropertySources(); + addDefaultPropertyFilters(); + addDefaultPropertyConverters(); + return this; + } + + + protected Map<TypeLiteral, Collection<PropertyConverter>> getDefaultPropertyConverters() { + Map<TypeLiteral, Collection<PropertyConverter>> result = new HashMap<>(); + for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices( + PropertyConverter.class)) { + for(Type type:conv.getClass().getGenericInterfaces()){ + if(type instanceof ParameterizedType){ + ParameterizedType pt = (ParameterizedType)type; + if(PropertyConverter.class.equals(((ParameterizedType) type).getRawType())){ + TypeLiteral target = TypeLiteral.of(pt.getActualTypeArguments()[0]); + Collection<PropertyConverter> convList = result.get(target); + if (convList == null) { + convList = new ArrayList<>(); + result.put(target, convList); + } + convList.add(conv); + } + } + } + } + return result; + } + + + /** + * Builds a new configuration based on the configuration of this builder instance. + * + * @return a new {@link org.apache.tamaya.Configuration configuration instance}, + * never {@code null}. + */ + @Override + public ConfigurationContext build() { + checkBuilderState(); + built = true; + return new DefaultConfigurationContext(this); + } + + @Override + public ConfigurationContextBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) { + Collections.sort(propertyFilters, comparator); + return this; + } + + @Override + public ConfigurationContextBuilder sortPropertySources(Comparator<PropertySource> comparator) { + Collections.sort(propertySources, comparator); + return this; + } + + private void checkBuilderState() { + if (built) { + throw new IllegalStateException("Configuration has already been build."); + } + } + + @Override + public List<PropertyFilter> getPropertyFilters() { + return propertyFilters; + } + + @Override + public Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter() { + return Collections.unmodifiableMap(this.propertyConverters); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java ---------------------------------------------------------------------- diff --git a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java index c993eeb..632f886 100644 --- a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java +++ b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java @@ -19,13 +19,16 @@ package org.apache.tamaya.examples.minimal; import org.apache.tamaya.Configuration; -import org.apache.tamaya.spisupport.DefaultConfigurationProvider; +import org.apache.tamaya.core.internal.CoreConfigurationContextBuilder; +import org.apache.tamaya.spi.ConfigurationContext; +import org.apache.tamaya.spi.ConfigurationContextBuilder; +import org.apache.tamaya.spi.ConfigurationProviderSpi; /** * Configuration provider that allows to set and reset a configuration * different per thread. */ -public class TestConfigProvider extends DefaultConfigurationProvider{ +public class TestConfigProvider implements ConfigurationProviderSpi{ private ThreadLocal<Configuration> threadedConfig = new ThreadLocal<>(); @@ -35,7 +38,23 @@ public class TestConfigProvider extends DefaultConfigurationProvider{ if(config!=null){ return config; } - return super.getConfiguration(); + config = createConfiguration(new CoreConfigurationContextBuilder() + .addDefaultPropertyFilters() + .addDefaultPropertySources() + .addDefaultPropertyConverters() + .build()); + threadedConfig.set(config); + return config; + } + + @Override + public Configuration createConfiguration(ConfigurationContext context) { + return null; + } + + @Override + public ConfigurationContextBuilder getConfigurationContextBuilder() { + return null; } @Override @@ -46,4 +65,9 @@ public class TestConfigProvider extends DefaultConfigurationProvider{ threadedConfig.set(config); } } + + @Override + public boolean isConfigurationSettable() { + return false; + } }