You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2014/12/13 01:41:05 UTC
[3/4] incubator-tamaya git commit: TAMAYA-3: - Renamed
PropertyProvider to PropertySource. - Factored out PropertyProviderBuilder
(now to PropertySourceBuilder) into core implemntation (was API). - Removed
SPI in favor of harcoded PropertySourceFactory.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
index 6aa41ad..1576cf0 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
@@ -18,28 +18,32 @@
*/
package org.apache.tamaya.core.internal.config;
-import org.apache.tamaya.PropertyProviderBuilder;
+import org.apache.tamaya.*;
import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.core.spi.ExpressionEvaluator;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.Bootstrap;
import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
import java.lang.annotation.Annotation;
import java.lang.reflect.Proxy;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
public class DefaultConfigurationManagerSingletonSpi implements ConfigurationManagerSingletonSpi {
+ private static final String DEFAULT_CONFIG_NAME = "default";
+
private Map<String, ConfigurationProviderSpi> configProviders = new ConcurrentHashMap<>();
+ private Map<Consumer<ConfigChangeSet>, List<Predicate<PropertySource>>> listenerMap = new ConcurrentHashMap<>();
+
private ExpressionEvaluator expressionEvaluator = loadEvaluator();
private ExpressionEvaluator loadEvaluator() {
@@ -60,11 +64,10 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
public <T> T getConfiguration(String name, Class<T> type) {
ConfigurationProviderSpi provider = configProviders.get(name);
if (provider == null) {
- if(DefaultConigProvider.DEFAULT_CONFIG_NAME.equals(name)){
- provider = new DefaultConigProvider();
- configProviders.put(DefaultConigProvider.DEFAULT_CONFIG_NAME, provider);
- }
- else{
+ if (DEFAULT_CONFIG_NAME.equals(name)) {
+ provider = new FallbackSimpleConfigProvider();
+ configProviders.put(DEFAULT_CONFIG_NAME, provider);
+ } else {
throw new ConfigException("No such config: " + name);
}
}
@@ -89,7 +92,7 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
private <T> T createAdapterProxy(Configuration config, Class<T> type) {
ClassLoader cl = Optional.ofNullable(Thread.currentThread()
.getContextClassLoader()).orElse(getClass().getClassLoader());
- return (T)Proxy.newProxyInstance(cl,new Class[]{type}, new ConfigTemplateInvocationHandler(type, config));
+ return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, config));
}
@Override
@@ -118,24 +121,53 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
}
@Override
+ public void addChangeListener(Predicate<PropertySource> predicate, Consumer<ConfigChangeSet> l) {
+ List<Predicate<PropertySource>> predicates = listenerMap.computeIfAbsent(l,
+ cs -> Collections.synchronizedList(new ArrayList<>()));
+ if (predicate == null) {
+ predicates.add(p -> true); // select all events!
+ } else {
+ predicates.add(predicate);
+ }
+ }
+
+ @Override
+ public void removeChangeListener(Predicate<PropertySource> predicate, Consumer<ConfigChangeSet> l) {
+ List<Predicate<PropertySource>> predicates = listenerMap.get(l);
+ if (predicate == null) {
+ listenerMap.remove(l); // select all events!
+ } else {
+ predicates.add(predicate);
+ }
+ }
+
+ @Override
+ public void publishChange(ConfigChangeSet configChangeSet) {
+ listenerMap.entrySet().forEach(
+ (en) -> {
+ if (en.getValue().stream()
+ .filter(v -> v.test(configChangeSet.getPropertySource())).findAny().isPresent()) {
+ en.getKey().accept(configChangeSet);
+ }
+ }
+ );
+ }
+
+ @Override
public boolean isConfigurationDefined(String name) {
ConfigurationProviderSpi spi = this.configProviders.get(name);
return spi != null;
}
/**
- * This config provider is loaded if no
+ * Implementation of a default config provider used as fallback, if no {@link org.apache.tamaya.core.spi.ConfigurationProviderSpi}
+ * instance is registered for providing the {@code default} {@link org.apache.tamaya.Configuration}.
*/
- private static final class DefaultConigProvider implements ConfigurationProviderSpi{
- private static final String DEFAULT_CONFIG_NAME = "default";
-
- private Configuration defaultConfig = PropertyProviderBuilder.create(DEFAULT_CONFIG_NAME)
- .addEnvironmentProperties()
- .addPaths("META-INF/cfg/default/**/*.properties","META-INF/cfg/default/**/*.xml","META-INF/cfg/default/**/*.ini")
- .addPaths("META-INF/cfg/config/**/*.properties","META-INF/cfg/config/**/*.xml","META-INF/cfg/config/**/*.ini")
- .addSystemProperties()
- .addPaths("META-INF/cfg/fixed/**/*.properties","META-INF/cfg/fixed/**/*.xml","META-INF/cfg/fixed/**/*.ini")
- .build().toConfiguration();
+ private static final class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
+ /**
+ * The loaded configuration instance.
+ */
+ private volatile Configuration configuration;
@Override
public String getConfigName() {
@@ -144,7 +176,30 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
@Override
public Configuration getConfiguration() {
- return defaultConfig;
+ Configuration cfg = configuration;
+ if (cfg == null) {
+ reload();
+ cfg = configuration;
+ }
+ return cfg;
+ }
+
+
+ @Override
+ public void reload() {
+ this.configuration =
+ PropertySourceBuilder.create(DEFAULT_CONFIG_NAME)
+ .addProviders(PropertySourceBuilder.create("CL default")
+ .withAggregationPolicy(AggregationPolicy.LOG_ERROR)
+ .addPaths("META-INF/cfg/default/**/*.xml", "META-INF/cfg/default/**/*.properties", "META-INF/cfg/default/**/*.ini")
+ .build())
+ .addProviders(PropertySourceBuilder.create("CL default")
+ .withAggregationPolicy(AggregationPolicy.LOG_ERROR)
+ .addPaths("META-INF/cfg/config/**/*.xml", "META-INF/cfg/config/**/*.properties", "META-INF/cfg/config/**/*.ini")
+ .build())
+ .addSystemProperties()
+ .addEnvironmentProperties()
+ .build().toConfiguration();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
index 08abed7..5f2263e 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/EnvPropertiesConfigProvider.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.config;
-import org.apache.tamaya.PropertyProviderBuilder;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.Configuration;
@@ -34,7 +34,7 @@ public class EnvPropertiesConfigProvider implements ConfigurationProviderSpi{
private Configuration envConfig;
public EnvPropertiesConfigProvider(){
- envConfig = PropertyProviderBuilder.create("environment.properties").addEnvironmentProperties().build().toConfiguration();
+ envConfig = PropertySourceBuilder.create("environment.properties").addEnvironmentProperties().build().toConfiguration();
}
@Override
@@ -46,4 +46,9 @@ public class EnvPropertiesConfigProvider implements ConfigurationProviderSpi{
public Configuration getConfiguration(){
return envConfig;
}
+
+ @Override
+ public void reload() {
+ // nothing todo here
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/config/Store.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/Store.java b/core/src/main/java/org/apache/tamaya/core/internal/config/Store.java
new file mode 100644
index 0000000..815e0f3
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/Store.java
@@ -0,0 +1,98 @@
+/*
+ * 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.core.internal.config;
+
+import java.lang.ref.WeakReference;
+import java.util.*;
+
+/**
+ * This store encapsulates an list current WeakReferences to items.
+ * It cleans up the list fromMap null references, when an item is removed, or an Iterator is created.
+ * Created by Anatole on 10.04.2014.
+ */
+public class Store<T>implements Iterable<T> {
+
+ private List<WeakReference<T>> weakItems = new ArrayList<>();
+
+ private List<T> items = new ArrayList<>();
+
+ private final Object LOCK = new Object();
+
+ public void add(T item){
+ Objects.requireNonNull(item);
+ this.items.add(item);
+ }
+
+ public void addWeak(T item){
+ Objects.requireNonNull(item);
+ this.weakItems.add(new WeakReference<>(item));
+ }
+
+ public void remove(T item){
+ Objects.requireNonNull(item);
+ synchronized(LOCK){
+ for(Iterator<WeakReference<T>> iter = weakItems.iterator(); iter.hasNext();iter.next()){
+ WeakReference<T> wr = iter.next();
+ T t = wr.get();
+ if(t==null || t.equals(item)){
+ iter.remove();
+ }
+ }
+ for(Iterator<T> iter = items.iterator(); iter.hasNext();iter.next()){
+ T t = iter.next();
+ if(t==null || t.equals(item)){
+ iter.remove();
+ }
+ }
+ }
+ }
+
+ public List<T> toList(){
+ List<T> newList = new ArrayList<>();
+ synchronized(LOCK){
+ Iterator<T> iter = items.iterator();
+ while(iter.hasNext()){
+ T t = iter.next();
+ newList.add(t);
+ }
+ for (WeakReference<T> wr : weakItems) {
+ T t = wr.get();
+ if (t == null) {
+ iter.remove();
+ } else {
+ newList.add(t);
+ }
+ }
+ }
+ return newList;
+ }
+
+ @Override
+ public Iterator<T> iterator(){
+ return toList().iterator();
+ }
+
+ @Override
+ public String toString(){
+ return "Store{" +
+ "items=" + items +
+ ", weakItems=" + weakItems +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
index d2004d8..54453c5 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/SystemPropertiesConfigProvider.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.config;
-import org.apache.tamaya.PropertyProviderBuilder;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.Configuration;
@@ -34,7 +34,7 @@ public class SystemPropertiesConfigProvider implements ConfigurationProviderSpi{
private Configuration systemConfig;
public SystemPropertiesConfigProvider(){
- systemConfig = PropertyProviderBuilder.create("system.properties").addSystemProperties().build().toConfiguration();
+ systemConfig = PropertySourceBuilder.create("system.properties").addSystemProperties().build().toConfiguration();
}
@Override
@@ -46,4 +46,9 @@ public class SystemPropertiesConfigProvider implements ConfigurationProviderSpi{
public Configuration getConfiguration(){
return systemConfig;
}
+
+ @Override
+ public void reload() {
+ // nothing todo here
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/config/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/WeakConfigListenerManager.java b/core/src/main/java/org/apache/tamaya/core/internal/config/WeakConfigListenerManager.java
index a65c042..4c950fc 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/WeakConfigListenerManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/WeakConfigListenerManager.java
@@ -18,8 +18,6 @@
*/
package org.apache.tamaya.core.internal.config;
-import org.apache.tamaya.core.properties.Store;
-
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
index 83b5c2a..2153777 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.inject;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyProvider;
+import org.apache.tamaya.PropertySource;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -62,7 +62,7 @@ public final class ConfiguredInstancesManager implements PropertyChangeListener{
@Override
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
for(Map.Entry<ConfiguredType,List<WeakReference<Object>>> en: configuredInstances.entrySet()){
- PropertyProvider propertyProvider = (PropertyProvider)propertyChangeEvent.getSource();
+ PropertySource propertyProvider = (PropertySource)propertyChangeEvent.getSource();
if((propertyProvider instanceof Configuration) && en.getKey().isConfiguredBy((Configuration)propertyProvider)){
List<WeakReference<Object>> instances = en.getValue();
synchronized (instances){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
index 2770e8a..b199c23 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
@@ -65,7 +65,7 @@ public class ConfiguredType {
}
}
for (Method m : type.getDeclaredMethods()) {
- ConfigChangeListener mAnnot = m.getAnnotation(ConfigChangeListener.class);
+ ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
if(mAnnot!=null) {
if (m.getParameterTypes().length != 1) {
continue;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/properties/ClasspathPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/properties/ClasspathPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/properties/ClasspathPropertyProvider.java
deleted file mode 100644
index f6aa4f6..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/properties/ClasspathPropertyProvider.java
+++ /dev/null
@@ -1,150 +0,0 @@
-///*
-// * 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.core.internal.properties;
-//
-//import org.apache.tamaya.ConfigChangeSet;
-//import org.apache.tamaya.MetaInfo;
-//import org.apache.tamaya.core.properties.AbstractPropertyProvider;
-//import org.apache.tamaya.core.properties.ClasspathModulePropertyProvider;
-//
-//import java.util.*;
-//
-//public class ClasspathPropertyProvider extends AbstractPropertyProvider {
-//
-// private static final long serialVersionUID = -2193109047946712701L;
-// private Map<ClassLoader,ClasspathModulePropertyProvider> configs = new HashMap<>();
-// private String[] resources;
-//
-// public ClasspathPropertyProvider(MetaInfo metaInfo, String... resources) {
-// super(metaInfo);
-// Objects.requireNonNull(resources);
-// this.resources = resources;
-// }
-//
-//
-// @Override
-// public Map<String,String> toMap(){
-// return new Map<String,String>(){
-//
-// @Override
-// public int size(){
-// return getLoaderDependentDelegate().size();
-// }
-//
-// @Override
-// public boolean isEmpty(){
-// return getLoaderDependentDelegate().isEmpty();
-// }
-//
-// @Override
-// public boolean containsKey(Object key){
-// return getLoaderDependentDelegate().containsKey(key);
-// }
-//
-// @Override
-// public boolean containsValue(Object value){
-// return getLoaderDependentDelegate().containsValue(value);
-// }
-//
-// @Override
-// public String get(Object key){
-// return getLoaderDependentDelegate().get(key);
-// }
-//
-// @Override
-// public String put(String key, String value){
-// return getLoaderDependentDelegate().put(key,value);
-// }
-//
-// @Override
-// public String remove(Object key){
-// return getLoaderDependentDelegate().remove(key);
-// }
-//
-// @Override
-// public void putAll(Map<? extends String,? extends String> m){
-// getLoaderDependentDelegate().putAll(m);
-// }
-//
-// @Override
-// public void clear(){
-// getLoaderDependentDelegate().clear();
-// }
-//
-// @Override
-// public Set<String> keySet(){
-// return getLoaderDependentDelegate().keySet();
-// }
-//
-// @Override
-// public Collection<String> values(){
-// return getLoaderDependentDelegate().values();
-// }
-//
-// @Override
-// public Set<Entry<String,String>> entrySet(){
-// return getLoaderDependentDelegate().entrySet();
-// }
-//
-// };
-// }
-//
-// private Map<String, String> getLoaderDependentDelegate() {
-// Map<String, String> props = new HashMap<>();
-// ClassLoader cl = Thread.currentThread().getContextClassLoader();
-// if (cl == null) {
-// cl = getClass().getClassLoader();
-// }
-// while (cl != null) {
-// ClasspathModulePropertyProvider cfg = this.configs.get(cl);
-// if (cfg == null) {
-// cfg = new ClasspathModulePropertyProvider(cl, this.resources);
-// this.configs.put(cl, cfg);
-// }
-// props.putAll(cfg.toMap());
-// cl = cl.getParent();
-// }
-// return props;
-// }
-//
-// @Override
-// public ConfigChangeSet load() {
-// Map<String, String> props = new HashMap<>();
-// ClassLoader cl = Thread.currentThread().getContextClassLoader();
-// if (cl == null) {
-// cl = getClass().getClassLoader();
-// }
-// while (cl != null) {
-// ClasspathModulePropertyProvider cfg = this.configs.get(cl);
-// if (cfg != null) {
-// cfg.load();
-// }
-// cl = cl.getParent();
-// }
-// return super.load();
-// }
-//
-// @Override
-// public String toString(){
-// return "ClasspathPropertyProvider{" +
-// "configs=" + configs +
-// ", resources=" + Arrays.toString(resources) +
-// '}';
-// }
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
deleted file mode 100644
index 6af3b42..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathClasspathsResolver.java
+++ /dev/null
@@ -1,56 +0,0 @@
-///*
-// * 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.core.internal.resources;
-//
-//import org.apache.tamaya.core.internal.resources.io.PathMatchingResourcePatternResolver;
-//import org.apache.tamaya.core.spi.PathResolver;
-//import org.apache.tamaya.core.resource.Resource;
-//
-//import java.io.IOException;
-//import java.util.*;
-//import java.util.logging.Level;
-//import java.util.logging.Logger;
-//
-//public class AntPathClasspathsResolver implements PathResolver {
-//
-// private static final Logger LOG = Logger.getLogger(AntPathClasspathResolver.class.getName());
-//
-// @Override
-// public String getResolverId(){
-// return "classpath*";
-// }
-//
-// @Override
-// public Collection<Resource> resolve(ClassLoader classLoader, Collection<String> expressions){
-// PathMatchingResourcePatternResolver resolver = PathMatchingResourcePatternResolver.of(classLoader);
-// List<Resource> result = new ArrayList<>();
-// expressions.forEach((expression) -> {
-// try {
-// Resource[] resources = resolver.getResources(expression);
-// for (Resource res : resources) {
-// result.add(res);
-// }
-// }
-// catch(IOException e){
-// LOG.log(Level.FINE, "Failed to load resource expression: " + expression, e);
-// }
-// });
-// return result;
-// }
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
deleted file mode 100644
index c0b16c1..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/AntPathFilesResolver.java
+++ /dev/null
@@ -1,62 +0,0 @@
-///*
-// * 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.core.internal.resources;
-//
-//import org.apache.tamaya.core.internal.resources.io.PathMatchingResourcePatternResolver;
-//import org.apache.tamaya.core.spi.PathResolver;
-//import org.apache.tamaya.core.resource.Resource;
-//
-//import java.io.IOException;
-//import java.util.*;
-//import java.util.logging.Level;
-//import java.util.logging.Logger;
-//
-//public class AntPathFilesResolver implements PathResolver {
-//
-// private static final Logger LOG = Logger.getLogger(AntPathFileResolver.class.getName());
-//
-// @Override
-// public String getResolverId(){
-// return "file*";
-// }
-//
-// @Override
-// public Collection<Resource> resolve(ClassLoader classLoader, Collection<String> expressions){
-// PathMatchingResourcePatternResolver resolver = PathMatchingResourcePatternResolver.of(classLoader);
-// List<Resource> result = new ArrayList<>();
-// expressions.forEach((expression) -> {
-// try {
-// Resource[] resources = resolver.getResources(expression);
-// for (Resource res : resources) {
-// try {
-// if(res.exists()) {
-// result.add(res);
-// }
-// } catch (Exception e) {
-// LOG.log(Level.FINE, "URI could not be extracted from Resource: " + res.toString(), e);
-// }
-// }
-// }
-// catch(IOException e){
-// LOG.log(Level.FINE, "Failed to load resource expression: " + expression.toString(), e);
-// }
-// });
-// return result;
-// }
-//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
new file mode 100644
index 0000000..e35dfd4
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AbstractClasspathAwarePropertySource.java
@@ -0,0 +1,86 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.core.resource.Resource;
+import org.apache.tamaya.spi.Bootstrap;
+import org.apache.tamaya.core.resource.ResourceLoader;
+
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+
+import java.util.*;
+
+public abstract class AbstractClasspathAwarePropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = 5484306410557548246L;
+ private ClassLoader classLoader;
+ private AbstractClasspathAwarePropertySource parentConfig;
+ private Set<String> sources;
+
+
+ public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
+ Set<String> sourceExpressions, long configReadDT, Map<String, String> entries,
+ MetaInfo metaInfo, Set<String> sources, List<Throwable> errors){
+ super(metaInfo);
+ Objects.requireNonNull(sources, "sources required.");
+ Objects.requireNonNull(classLoader, "classLoader required.");
+ this.sources = sources;
+ this.classLoader = classLoader;
+ this.parentConfig = parentConfig;
+ }
+
+ public AbstractClasspathAwarePropertySource(ClassLoader classLoader, AbstractClasspathAwarePropertySource parentConfig,
+ String sourceExpression){
+ super(MetaInfoBuilder.of().setSourceExpressions(sourceExpression).set("parentConfig", parentConfig.toString())
+ .build());
+ Objects.requireNonNull(sources, "sources required.");
+ Objects.requireNonNull(sourceExpression, "sourceExpression required.");
+ List<Resource> resources = Bootstrap.getService(ResourceLoader.class).getResources(classLoader, sourceExpression);
+ for(Resource res : resources){
+ addSource(res.toString());
+ }
+ this.classLoader = classLoader;
+ this.parentConfig = parentConfig;
+ }
+
+ protected abstract void readSource(Map<String,String> targetMap, String source);
+
+ @Override
+ public Map<String,String> toMap(){
+ Map<String,String> result = new HashMap<>();
+ for(String source : sources){
+ // if(!isSourceRead(source)){
+ readSource(result, source);
+ // }
+ }
+ return result;
+ }
+
+
+ public ClassLoader getClassLoader(){
+ return classLoader;
+ }
+
+ public AbstractClasspathAwarePropertySource getParentConfig(){
+ return this.parentConfig;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertyProvider.java
deleted file mode 100644
index cce9841..0000000
--- a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertyProvider.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.core.properties;
-
-import org.apache.tamaya.MetaInfo;
-import org.apache.tamaya.MetaInfoBuilder;
-import org.apache.tamaya.PropertyProvider;
-
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * Abstract base class for implementing a {@link org.apache.tamaya.PropertyProvider}.
- */
-@SuppressWarnings("NullableProblems")
-public abstract class AbstractPropertyProvider implements PropertyProvider, Serializable{
- /**
- * serialVersionUID.
- */
- private static final long serialVersionUID = -6553955893879292837L;
-
- protected MetaInfo metaInfo;
-
- /**
- * The underlying sources.
- */
- private volatile Set<String> sources = new HashSet<>();
-
- /**
- * Constructor.
- */
- protected AbstractPropertyProvider(MetaInfo metaInfo){
- Objects.requireNonNull(metaInfo);
- this.metaInfo = metaInfo;
- }
-
- @Override
- public MetaInfo getMetaInfo(){
- return metaInfo;
- }
-
-
- /**
- * Method that allows an additional source to be added, to be used by
- * subclasses.
- *
- * @param source the source, not {@code null}.
- */
- protected void addSource(String source){
- Objects.requireNonNull(source);
- this.sources.add(source);
- }
-
-
- protected void addSources(Collection<String> sources){
- Objects.requireNonNull(sources);
- this.sources.addAll(sources);
- }
-
- @Override
- public boolean containsKey(String key){
- return toMap().containsKey(key);
- }
-
- @Override
- public Optional<String> get(String key){
- return Optional.ofNullable(toMap().get(key));
- }
-
- @SuppressWarnings("NullableProblems")
- @Override
- public Set<String> keySet(){
- return toMap().keySet();
- }
-
- @Override
- public String toString(){
- StringBuilder b = new StringBuilder(getClass().getSimpleName()).append("{\n");
- b.append(" ").append("(").append(MetaInfoBuilder.NAME).append(" = ").append(getMetaInfo().get(MetaInfoBuilder.NAME)).append(")\n");
- printContents(b);
- return b.append('}').toString();
- }
-
- protected String printContents(StringBuilder b){
- Map<String,String> sortMap = toMap();
- if(!(sortMap instanceof SortedMap)){
- sortMap = new TreeMap<>(sortMap);
- }
- for(Map.Entry<String,String> en : sortMap.entrySet()){
- b.append(" ").append(en.getKey()).append(" = \"").append(en.getValue().replaceAll("\\\"", "\\\\\"").replaceAll("=", "\\=")).append("\"\n");
- }
- return b.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
new file mode 100644
index 0000000..1e9acd3
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
@@ -0,0 +1,111 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertySource;
+
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * Abstract base class for implementing a {@link org.apache.tamaya.PropertySource}.
+ */
+@SuppressWarnings("NullableProblems")
+public abstract class AbstractPropertySource implements PropertySource, Serializable{
+ /**
+ * serialVersionUID.
+ */
+ private static final long serialVersionUID = -6553955893879292837L;
+
+ protected MetaInfo metaInfo;
+
+ /**
+ * The underlying sources.
+ */
+ private volatile Set<String> sources = new HashSet<>();
+
+ /**
+ * Constructor.
+ */
+ protected AbstractPropertySource(MetaInfo metaInfo){
+ Objects.requireNonNull(metaInfo);
+ this.metaInfo = metaInfo;
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return metaInfo;
+ }
+
+
+ /**
+ * Method that allows an additional source to be added, to be used by
+ * subclasses.
+ *
+ * @param source the source, not {@code null}.
+ */
+ protected void addSource(String source){
+ Objects.requireNonNull(source);
+ this.sources.add(source);
+ }
+
+
+ protected void addSources(Collection<String> sources){
+ Objects.requireNonNull(sources);
+ this.sources.addAll(sources);
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return toMap().containsKey(key);
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return Optional.ofNullable(toMap().get(key));
+ }
+
+ @SuppressWarnings("NullableProblems")
+ @Override
+ public Set<String> keySet(){
+ return toMap().keySet();
+ }
+
+ @Override
+ public String toString(){
+ StringBuilder b = new StringBuilder(getClass().getSimpleName()).append("{\n");
+ b.append(" ").append("(").append(MetaInfoBuilder.NAME).append(" = ").append(getMetaInfo().get(MetaInfoBuilder.NAME)).append(")\n");
+ printContents(b);
+ return b.append('}').toString();
+ }
+
+ protected String printContents(StringBuilder b){
+ Map<String,String> sortMap = toMap();
+ if(!(sortMap instanceof SortedMap)){
+ sortMap = new TreeMap<>(sortMap);
+ }
+ for(Map.Entry<String,String> en : sortMap.entrySet()){
+ b.append(" ").append(en.getKey()).append(" = \"").append(en.getValue().replaceAll("\\\"", "\\\\\"").replaceAll("=", "\\=")).append("\"\n");
+ }
+ return b.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/AbstractResourceConfigMap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractResourceConfigMap.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractResourceConfigMap.java
deleted file mode 100644
index 0d34c6a..0000000
--- a/core/src/main/java/org/apache/tamaya/core/properties/AbstractResourceConfigMap.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.core.properties;
-
-import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.spi.Bootstrap;
-import org.apache.tamaya.core.resource.ResourceLoader;
-
-import org.apache.tamaya.MetaInfo;
-import org.apache.tamaya.MetaInfoBuilder;
-
-import java.util.*;
-
-public abstract class AbstractResourceConfigMap extends AbstractPropertyProvider{
-
- private static final long serialVersionUID = 5484306410557548246L;
- private ClassLoader classLoader;
- private AbstractResourceConfigMap parentConfig;
- private Set<String> sources;
-
-
- public AbstractResourceConfigMap(ClassLoader classLoader, AbstractResourceConfigMap parentConfig,
- Set<String> sourceExpressions, long configReadDT, Map<String,String> entries,
- MetaInfo metaInfo, Set<String> sources, List<Throwable> errors){
- super(metaInfo);
- Objects.requireNonNull(sources, "sources required.");
- Objects.requireNonNull(classLoader, "classLoader required.");
- this.sources = sources;
- this.classLoader = classLoader;
- this.parentConfig = parentConfig;
- }
-
- public AbstractResourceConfigMap(ClassLoader classLoader, AbstractResourceConfigMap parentConfig,
- String sourceExpression){
- super(MetaInfoBuilder.of().setSourceExpressions(sourceExpression).set("parentConfig", parentConfig.toString())
- .build());
- Objects.requireNonNull(sources, "sources required.");
- Objects.requireNonNull(sourceExpression, "sourceExpression required.");
- List<Resource> resources = Bootstrap.getService(ResourceLoader.class).getResources(classLoader, sourceExpression);
- for(Resource res : resources){
- addSource(res.toString());
- }
- this.classLoader = classLoader;
- this.parentConfig = parentConfig;
- }
-
- protected abstract void readSource(Map<String,String> targetMap, String source);
-
- @Override
- public Map<String,String> toMap(){
- Map<String,String> result = new HashMap<>();
- for(String source : sources){
- // if(!isSourceRead(source)){
- readSource(result, source);
- // }
- }
- return result;
- }
-
-
- public ClassLoader getClassLoader(){
- return classLoader;
- }
-
- public AbstractResourceConfigMap getParentConfig(){
- return this.parentConfig;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
new file mode 100644
index 0000000..85844b6
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
@@ -0,0 +1,122 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.properties.AbstractPropertySource;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
+ * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
+ * following aggregations are supported:
+ * <ul>
+ * <li><b>IGNORE_DUPLICATES: </b>Ignore all overrides.</li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * </ul>
+ */
+class AggregatedPropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = -1419376385695224799L;
+ private AggregationPolicy policy = AggregationPolicy.COMBINE;
+ private List<PropertySource> units = new ArrayList<>();
+ private PropertySource mutableProvider;
+
+ /**
+ * Creates a new instance.
+ * @param mutableProvider the provider instance that would be used for delegating
+ * change requests.
+ * @param policy
+ * The aggregation policy to be used.
+ * @param propertyMaps
+ * The property sets to be included.
+ */
+ public AggregatedPropertySource(MetaInfo metaInfo, PropertySource mutableProvider, AggregationPolicy policy, List<PropertySource> propertyMaps) {
+ super(MetaInfoBuilder.of(metaInfo).setType("aggregated").build());
+ Objects.requireNonNull(policy);
+ this.policy = policy;
+ units.addAll(propertyMaps);
+ this.mutableProvider = mutableProvider;
+ }
+
+ /**
+ * Get the {@link AggregationPolicy} for this instance.
+ *
+ * @return the {@link AggregationPolicy}, never {@code null}.
+ */
+ public AggregationPolicy getAggregationPolicy() {
+ return policy;
+ }
+
+ /**
+ * Return the names current the {@link org.apache.tamaya.PropertySource} instances to be
+ * aggregated in this instance, in the order current precedence (the first are
+ * the weakest).
+ *
+ * @return the ordered list current aggregated scope identifiers, never
+ * {@code null}.
+ */
+ public List<PropertySource> getConfigurationUnits() {
+ return Collections.unmodifiableList(units);
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ if(mutableProvider!=null)
+ mutableProvider.apply(change);
+ else
+ super.apply(change);
+ }
+
+ @Override
+ public Map<String,String> toMap() {
+ Map<String, String> value = new HashMap<>();
+ for (PropertySource unit : units) {
+ for (Map.Entry<String, String> entry : unit.toMap()
+ .entrySet()) {
+ String valueToAdd = this.policy.aggregate(entry.getKey(), value.get(entry.getKey()), entry.getValue());
+ if(valueToAdd==null){
+ value.remove(entry.getKey());
+ }
+ else{
+ value.put(entry.getKey(), valueToAdd);
+ }
+ }
+ }
+ return value;
+ }
+
+ @Override
+ public ConfigChangeSet load() {
+ for (PropertySource unit : units) {
+ unit.load();
+ }
+ return super.load();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
new file mode 100644
index 0000000..dd7011e
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/BuildablePropertySource.java
@@ -0,0 +1,66 @@
+/* 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 current 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.core.properties;
+
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.PropertySource;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * Created by Anatole on 07.12.2014.
+ */
+class BuildablePropertySource implements PropertySource
+{
+
+ private MetaInfo metaInfo;
+ private PropertySource baseProvider;
+
+ public BuildablePropertySource(MetaInfo metaInfo, PropertySource baseProvider) {
+ this.metaInfo = Objects.requireNonNull(metaInfo);
+ this.baseProvider = Objects.requireNonNull(baseProvider);
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return this.baseProvider.get(key);
+ }
+
+ @Override
+ public boolean containsKey(String key) {
+ return this.baseProvider.containsKey(key);
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return this.baseProvider.toMap();
+ }
+
+ @Override
+ public MetaInfo getMetaInfo() {
+ return this.metaInfo;
+ }
+
+ @Override
+ public String toString(){
+ return "BuildablePropertyProvider -> " + getMetaInfo().toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
new file mode 100644
index 0000000..504e1f7
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
@@ -0,0 +1,177 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.*;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
+
+/**
+ * Created by Anatole on 12.04.2014.
+ */
+class ContextualPropertySource implements PropertySource {
+
+ private volatile Map<String,PropertySource> cachedMaps = new ConcurrentHashMap<>();
+
+ private Supplier<PropertySource> mapSupplier;
+ private Supplier<String> isolationKeySupplier;
+ private MetaInfo metaInfo;
+
+ /**
+ * Creates a new contextual PropertyMap. Contextual maps delegate to different instances current PropertyMap depending
+ * on the keys returned fromMap the isolationP
+ *
+ * @param mapSupplier
+ * @param isolationKeySupplier
+ */
+ public ContextualPropertySource(MetaInfo metaInfo, Supplier<PropertySource> mapSupplier, Supplier<String> isolationKeySupplier){
+ if(metaInfo==null){
+ this.metaInfo = MetaInfoBuilder.of().setType("contextual").set("mapSupplier", mapSupplier.toString())
+ .set("isolationKeySupplier", isolationKeySupplier.toString()).build();
+ }
+ else{
+ this.metaInfo = MetaInfoBuilder.of(metaInfo).setType("contextual").set("mapSupplier", mapSupplier.toString())
+ .set("isolationKeySupplier", isolationKeySupplier.toString()).build();
+ }
+ Objects.requireNonNull(mapSupplier);
+ Objects.requireNonNull(isolationKeySupplier);
+ this.mapSupplier = mapSupplier;
+ this.isolationKeySupplier = isolationKeySupplier;
+ }
+
+ /**
+ * This method provides the contextual Map for the current environment. Hereby, ba default, for each different
+ * key returned by the #isolationKeySupplier a separate PropertyMap instance is acquired fromMap the #mapSupplier.
+ * If the map supplier returns an instance it is cached in the local #cachedMaps.
+ *
+ * @return the current contextual PropertyMap.
+ */
+ protected PropertySource getContextualMap(){
+ String environmentKey = this.isolationKeySupplier.get();
+ if(environmentKey == null){
+ return PropertySource.EMPTY_PROPERTYSOURCE;
+ }
+ PropertySource map = this.cachedMaps.get(environmentKey);
+ if(map == null){
+ synchronized(cachedMaps){
+ map = this.cachedMaps.get(environmentKey);
+ if(map == null){
+ map = this.mapSupplier.get();
+ if(map == null){
+ return PropertySource.EMPTY_PROPERTYSOURCE;
+ }
+ this.cachedMaps.put(environmentKey, map);
+ }
+ }
+ }
+ return map;
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return getContextualMap().load();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return getContextualMap().containsKey(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return getContextualMap().toMap();
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return getContextualMap().get(key);
+ }
+
+ @Override
+ public Set<String> keySet(){
+ return getContextualMap().keySet();
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ getContextualMap().apply(change);
+ }
+
+ /**
+ * Access a cached PropertyMap.
+ *
+ * @param key the target environment key as returned by the environment key supplier, not null.
+ * @return the corresponding PropertyMap, or null.
+ */
+ public PropertySource getCachedMap(String key){
+ return this.cachedMaps.get(key);
+ }
+
+ /**
+ * Access the set current currently loaded/cached maps.
+ *
+ * @return the set current cached map keys, never null.
+ */
+ public Set<String> getCachedMapKeys(){
+ return this.cachedMaps.keySet();
+ }
+
+ /**
+ * Access the supplier for environment key, determining map isolation.
+ *
+ * @return the environment key supplier instance, not null.
+ */
+ public Supplier<String> getIsolationKeySupplier(){
+ return this.isolationKeySupplier;
+ }
+
+ /**
+ * Access the supplier for new PropertyMap instances.
+ *
+ * @return the PropertyMap supplier instance, not null.
+ */
+ public Supplier<PropertySource> getMapSupplier(){
+ return this.mapSupplier;
+ }
+
+ @Override
+ public String toString(){
+ return "ContextualMap{" +
+ "cachedMaps(key)=" + cachedMaps.keySet() +
+ ", mapSupplier=" + mapSupplier +
+ ", isolationKeySupplier=" + isolationKeySupplier +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/DefaultPropertyProviderManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/DefaultPropertyProviderManager.java b/core/src/main/java/org/apache/tamaya/core/properties/DefaultPropertyProviderManager.java
deleted file mode 100644
index d9ce5c8..0000000
--- a/core/src/main/java/org/apache/tamaya/core/properties/DefaultPropertyProviderManager.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.core.properties;
-
-import org.apache.tamaya.PropertyProvider;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class DefaultPropertyProviderManager implements PropertyProviderManager{
-
- private Map<String,PropertyProvider> propertyProviders = new ConcurrentHashMap<>();
-
-// @Inject
-// private MetaModelItemFactoryManagerSpi metaModelFactory;
-
- @Override
- public PropertyProvider getConfigMap(String setId){
- PropertyProvider propertyMap = propertyProviders.get(setId);
-// if(propertyMap == null){
-// MetaModel.Specification<PropertyMap> desc =
-// metaModel.getSpecification(PropertyMap.class, setId);
-// if(desc == null){
-// throw new IllegalArgumentException("No such property set: " + setId);
-// }
-// try{
-// propertyMap = createSet(desc);
-// this.propertyProviders.put(setId, propertyMap);
-// }
-// catch(Exception e){
-// throw new IllegalStateException("Error creating property set: " + setId, e);
-// }
-// }
- return propertyMap;
- }
-
-// private ConfigyMap createSet(MetaModel.Specification<PropertyMap> config)
-// throws ClassNotFoundException, IllegalAccessException, InstantiationException{
-// return metaModelFactory.create(config);
-// }
-
- @Override
- public void reloadConfigMap(String setId){
- PropertyProvider unit = propertyProviders.get(setId);
- if(unit != null){
- unit.load();
- }
- }
-
-
- @Override
- public Collection<String> getConfigMapKeys(){
- return this.propertyProviders.keySet();
- }
-
-
- @Override
- public boolean isConfigMapDefined(String key){
- // TODO check meta model, load if necessary
- return this.propertyProviders.containsKey(key);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
new file mode 100644
index 0000000..0e1914b
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
@@ -0,0 +1,108 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertySource;
+
+import java.util.*;
+
+/**
+ * Implementation for a {@link org.apache.tamaya.PropertySource} that is an aggregate current
+ * multiple child instances. Controlled by an {@link org.apache.tamaya.AggregationPolicy} the
+ * following aggregations are supported:
+ * <ul>
+ * <li><b>IGNORE_DUPLICATES: </b>Ignore all overrides.</li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * <li><b>: </b></li>
+ * </ul>
+ */
+class DelegatingPropertySource implements PropertySource {
+
+ private static final long serialVersionUID = -1419376385695224799L;
+ private PropertySource mainMap;
+ private Map<String,String> parentMap;
+ private MetaInfo metaInfo;
+
+ /**
+ * Creates a mew instance, with aggregation polilcy
+ * {@code AggregationPolicy.OVERRIDE}.
+ *
+ * @param mainMap The main ConfigMap.
+ * @param parentMap The delegated parent ConfigMap.
+ */
+ public DelegatingPropertySource(MetaInfo metaInfo, PropertySource mainMap, Map<String, String> parentMap){
+ if(metaInfo==null) {
+ this.metaInfo =
+ MetaInfoBuilder.of().setType("delegate").set("provider", mainMap.toString()).set("delegate", parentMap.toString())
+ .build();
+ }
+ else{
+ this.metaInfo =
+ MetaInfoBuilder.of(metaInfo).setType("delegate").set("provider", mainMap.toString()).set("delegate", parentMap.toString())
+ .build();
+ }
+ this.parentMap = Objects.requireNonNull(parentMap);
+ this.parentMap = Objects.requireNonNull(parentMap);
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return mainMap.load();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return keySet().contains(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return null;
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ Optional<String> val = mainMap.get(key);
+ if(!val.isPresent()){
+ return Optional.ofNullable(parentMap.get(key));
+ }
+ return val;
+ }
+
+ @Override
+ public Set<String> keySet(){
+ Set<String> keys = new HashSet<>(mainMap.keySet());
+ keys.addAll(parentMap.keySet());
+ return keys;
+ }
+
+ @Override
+ public String toString(){
+ return super.toString() + "(mainMap=" + mainMap + ", delegate=" + parentMap + ")";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
new file mode 100644
index 0000000..365b107
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/EnvironmentPropertySource.java
@@ -0,0 +1,43 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.core.properties.AbstractPropertySource;
+
+import java.util.Map;
+
+class EnvironmentPropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = 4753258482658331010L;
+
+ public Map<String,String> toMap(){
+ return System.getenv();
+ }
+
+ public EnvironmentPropertySource(){
+ super(MetaInfoBuilder.of().setType("env-properties").build());
+ }
+
+ @Override
+ public String toString(){
+ return "EnvironmentPropertyProvider[" + System.getenv().size() + " environment properties]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertyProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertyProvider.java b/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertyProvider.java
deleted file mode 100644
index 3f5adf9..0000000
--- a/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertyProvider.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.core.properties;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class FileSystemPropertyProvider extends AbstractResourceConfigMap{
-
- private static final Logger LOG = Logger.getLogger(FileSystemPropertyProvider.class.getName());
- private static final long serialVersionUID = -2016119697552480056L;
- private Map<String, Map<String, String>> propMetaInfo = new HashMap<>();
-
- public FileSystemPropertyProvider(String resourcePath, ClassLoader classLoader,
- AbstractResourceConfigMap parentConfig) {
- super(classLoader, parentConfig, resourcePath);
- }
-
- public FileSystemPropertyProvider(String resourcePath, AbstractResourceConfigMap parentConfig) {
- super(getCurrentClassLoader(), parentConfig, resourcePath);
- }
-
- public FileSystemPropertyProvider(String resourcePath) {
- super(getCurrentClassLoader(), null, resourcePath);
- }
-
-
- @Override
- protected void readSource(Map<String, String> targetMap, String src) {
- try (InputStream is = getClassLoader().getResource(
- src).openStream()) {
- Properties props = new Properties();
- URL resource = getClassLoader().getResource(
- src);
-// if (isSourceRead(resource.toString())) {
-// // continue;
-// return;
-// }
- addSource(resource.toString());
- Map<String, String> mi = new HashMap<>();
- mi.put("source", resource.toString());
- if (Thread.currentThread().getContextClassLoader() != null) {
- mi.put("classloader", Thread.currentThread()
- .getContextClassLoader().toString());
- }
- props.load(is);
- for (Map.Entry<Object, Object> en : props.entrySet()) {
- targetMap.put(en.getKey().toString(),
- en.getValue().toString());
- propMetaInfo.put(en.getKey().toString(),
- mi);
- }
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "Error loading config unit.", e);
- }
- }
-
- protected Map<String, String> getMetaInfo(String key, String value) {
- Map<String, String> mi = propMetaInfo.get(key);
- if (mi != null) {
- return mi;
- }
- return Collections.emptyMap();
- }
-
- private static ClassLoader getCurrentClassLoader() {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- return FileSystemPropertyProvider.class.getClassLoader();
- }
- return cl;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java
new file mode 100644
index 0000000..b3aca71
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FileSystemPropertySource.java
@@ -0,0 +1,97 @@
+/*
+ * 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.core.properties;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class FileSystemPropertySource extends AbstractClasspathAwarePropertySource {
+
+ private static final Logger LOG = Logger.getLogger(FileSystemPropertySource.class.getName());
+ private static final long serialVersionUID = -2016119697552480056L;
+ private Map<String, Map<String, String>> propMetaInfo = new HashMap<>();
+
+ public FileSystemPropertySource(String resourcePath, ClassLoader classLoader,
+ AbstractClasspathAwarePropertySource parentConfig) {
+ super(classLoader, parentConfig, resourcePath);
+ }
+
+ public FileSystemPropertySource(String resourcePath, AbstractClasspathAwarePropertySource parentConfig) {
+ super(getCurrentClassLoader(), parentConfig, resourcePath);
+ }
+
+ public FileSystemPropertySource(String resourcePath) {
+ super(getCurrentClassLoader(), null, resourcePath);
+ }
+
+
+ @Override
+ protected void readSource(Map<String, String> targetMap, String src) {
+ try (InputStream is = getClassLoader().getResource(
+ src).openStream()) {
+ Properties props = new Properties();
+ URL resource = getClassLoader().getResource(
+ src);
+// if (isSourceRead(resource.toString())) {
+// // continue;
+// return;
+// }
+ addSource(resource.toString());
+ Map<String, String> mi = new HashMap<>();
+ mi.put("source", resource.toString());
+ if (Thread.currentThread().getContextClassLoader() != null) {
+ mi.put("classloader", Thread.currentThread()
+ .getContextClassLoader().toString());
+ }
+ props.load(is);
+ for (Map.Entry<Object, Object> en : props.entrySet()) {
+ targetMap.put(en.getKey().toString(),
+ en.getValue().toString());
+ propMetaInfo.put(en.getKey().toString(),
+ mi);
+ }
+ } catch (IOException e) {
+ LOG.log(Level.SEVERE, "Error loading config unit.", e);
+ }
+ }
+
+ protected Map<String, String> getMetaInfo(String key, String value) {
+ Map<String, String> mi = propMetaInfo.get(key);
+ if (mi != null) {
+ return mi;
+ }
+ return Collections.emptyMap();
+ }
+
+ private static ClassLoader getCurrentClassLoader() {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ return FileSystemPropertySource.class.getClassLoader();
+ }
+ return cl;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
new file mode 100644
index 0000000..f8dc36c
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
@@ -0,0 +1,74 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.core.properties.AbstractPropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+class FilteredPropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = 4301042530074932562L;
+ private PropertySource unit;
+ private Predicate<String> filter;
+
+ public FilteredPropertySource(MetaInfo metaInfo, PropertySource configuration, Predicate<String> filter){
+ super(metaInfo==null?MetaInfoBuilder.of(configuration.getMetaInfo()).setType("filtered").set("filter", filter.toString()).build():
+ MetaInfoBuilder.of(metaInfo).setType("filtered").set("filter", filter.toString()).build());
+ Objects.requireNonNull(configuration);
+ this.unit = configuration;
+ this.filter = filter;
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ final Map<String,String> result = new HashMap<>();
+ this.unit.toMap().entrySet().forEach(e -> {
+ if(filter.test(e.getKey())){
+ result.put(e.getKey(), e.getValue());
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ unit.load();
+ return super.load();
+ }
+
+ /**
+ * Apply a config change to this item. Hereby the change must be related to the same instance.
+ * @param change the config change
+ * @throws org.apache.tamaya.ConfigException if an unrelated change was passed.
+ * @throws UnsupportedOperationException when the configuration is not writable.
+ */
+ @Override
+ public void apply(ConfigChangeSet change){
+ this.unit.apply(change);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
new file mode 100644
index 0000000..81ea88c
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FreezedPropertySource.java
@@ -0,0 +1,98 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.MetaInfo;
+import org.apache.tamaya.MetaInfoBuilder;
+import org.apache.tamaya.PropertySource;
+
+import java.io.Serializable;
+import java.time.Instant;
+import java.util.*;
+
+/**
+ * This class models a freezed instance current an {@link org.apache.tamaya.PropertySource}.
+ * Created by Anatole on 28.03.14.
+ */
+final class FreezedPropertySource implements PropertySource, Serializable{
+
+ private static final long serialVersionUID = 3365413090311267088L;
+ private Map<String,Map<String,String>> fieldMMetaInfo = new HashMap<>();
+ private MetaInfo metaInfo;
+ private Map<String,String> properties = new HashMap<>();
+
+ private FreezedPropertySource(MetaInfo metaInfo, PropertySource propertyMap) {
+ Map<String, String> map = propertyMap.toMap();
+ this.properties.putAll(map);
+ this.properties = Collections.unmodifiableMap(this.properties);
+ if (metaInfo == null) {
+ this.metaInfo =
+ MetaInfoBuilder.of(propertyMap.getMetaInfo()).set("freezedAt", Instant.now().toString()).build();
+ } else {
+ this.metaInfo = metaInfo;
+ }
+ }
+
+ public static PropertySource of(MetaInfo metaInfo, PropertySource propertyProvider){
+ if(propertyProvider instanceof FreezedPropertySource){
+ return propertyProvider;
+ }
+ return new FreezedPropertySource(metaInfo, propertyProvider);
+ }
+
+ @Override
+ public ConfigChangeSet load(){
+ return ConfigChangeSet.emptyChangeSet(this);
+ }
+
+ public int size(){
+ return properties.size();
+ }
+
+ public boolean isEmpty(){
+ return properties.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(String key){
+ return properties.containsKey(key);
+ }
+
+ @Override
+ public Map<String,String> toMap(){
+ return Collections.unmodifiableMap(this.properties);
+ }
+
+ @Override
+ public MetaInfo getMetaInfo(){
+ return this.metaInfo;
+ }
+
+ @Override
+ public Optional<String> get(String key){
+ return Optional.ofNullable(properties.get(key));
+ }
+
+ @Override
+ public Set<String> keySet(){
+ return properties.keySet();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/80bce9ec/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
new file mode 100644
index 0000000..39daabf
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/IntersectingPropertySource.java
@@ -0,0 +1,71 @@
+/*
+ * 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.core.properties;
+
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.properties.AbstractPropertySource;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * Provider implementation that combines multiple other config by intersecting
+ * the key/values common to all config, conflicting keys are resolved using an
+ * {@link org.apache.tamaya.AggregationPolicy}.
+ */
+class IntersectingPropertySource extends AbstractPropertySource {
+
+ private List<PropertySource> providers;
+ private PropertySource aggregatedDelegate;
+
+ public IntersectingPropertySource(MetaInfo metaInfo, AggregationPolicy policy, List<PropertySource> providers) {
+ super(MetaInfoBuilder.of(metaInfo).setType("intersection").build());
+ this.providers = new ArrayList<>(providers);
+ aggregatedDelegate = PropertySourceBuilder.create(getMetaInfo()).withAggregationPolicy(policy)
+ .addProviders(this.providers).build();
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ if (containsKey(key))
+ return aggregatedDelegate.get(key);
+ return Optional.empty();
+ }
+
+ private boolean filter(Map.Entry<String, String> entry) {
+ return containsKey(entry.getKey());
+ }
+
+ @Override
+ public boolean containsKey(String key) {
+ for (PropertySource prov : this.providers) {
+ if (!prov.containsKey(key)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return aggregatedDelegate.toMap().entrySet().stream().filter(en -> containsKey(en.getKey())).collect(
+ Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue));
+ }
+
+}