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/27 02:13:57 UTC
[3/5] incubator-tamaya git commit: TAMAYA-19: Separated config from
property source.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
index 0417f35..8b7180c 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationSpi.java
@@ -23,15 +23,12 @@ import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Consumer;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
-import org.apache.tamaya.core.internal.inject.WeakConfigListenerManager;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.core.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.ConfigurationSpi;
@@ -59,8 +56,10 @@ public class DefaultConfigurationSpi implements ConfigurationSpi {
}
public DefaultConfigurationSpi() {
- for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
- configProviders.put(spi.getConfigName(), spi);
+ if(configProviders.isEmpty()) {
+ for (ConfigurationProviderSpi spi : ServiceContext.getInstance().getServices(ConfigurationProviderSpi.class, Collections.emptyList())) {
+ configProviders.put(spi.getConfigName(), spi);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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 1494e7a..6fd4672 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
@@ -34,7 +34,7 @@ public class EnvPropertiesConfigProvider implements ConfigurationProviderSpi{
private Configuration envConfig;
public EnvPropertiesConfigProvider(){
- envConfig = PropertySourceBuilder.of("environment.properties").addEnvironmentProperties().build().toConfiguration();
+ envConfig = Configuration.from(PropertySourceBuilder.of("environment.properties").addEnvironmentProperties().build());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
index 7f997e5..7bcfb77 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FallbackSimpleConfigProvider.java
@@ -43,7 +43,7 @@ public class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
@Override
public void reload() {
- this.configuration =
+ this.configuration = Configuration.from(
PropertySourceBuilder.of(DEFAULT_CONFIG_NAME)
.addProviders(PropertySourceBuilder.of("CL default")
.withAggregationPolicy(AggregationPolicy.LOG_ERROR)
@@ -55,6 +55,6 @@ public class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
.build())
.addSystemProperties()
.addEnvironmentProperties()
- .build().toConfiguration();
+ .build());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
index 94e6694..afd1199 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
@@ -20,11 +20,11 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
/**
- * Class that has the responsibility to watch the folder and then update the {@link ConfigurationProviderSpi}
- * to update the Configuration from the properties or xml files, another ones will be ignored.
+ * Class that has the responsibility to watch the folder and then commit the {@link ConfigurationProviderSpi}
+ * to commit the Configuration from the properties or xml files, another ones will be ignored.
* @see FilesPropertiesConfigProvider
* This listener will wait to events and wait to one second to watch again.
- * <p>If new file was created or modified will update from this file.</p>
+ * <p>If new file was created or modified will commit from this file.</p>
* <p>If a file was removed then the listener will load using all files left.</p>
* @author otaviojava
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
index e4fc95d..a7d4ba9 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeObserver.java
@@ -3,7 +3,7 @@ package org.apache.tamaya.core.internal.config;
import java.util.Map;
/**
- * Observer to be used in {@link FileChangeListener} to update all configurations and provider.
+ * Observer to be used in {@link FileChangeListener} to commit all configurations and provider.
* @author otaviojava
*/
interface FileChangeObserver {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
index 8286768..4f76180 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FileConfiguration.java
@@ -8,7 +8,7 @@ import org.apache.tamaya.Configuration;
/**
* Implementation of Configuration which the information is from xml or properties files.
- * Once the File modified, it will update automatically by provider.
+ * Once the File modified, it will commit automatically by provider.
* @see FilesPropertiesConfigProvider
* @see FileChangeObserver
* @author otaviojava
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
index 5cd1a93..c2cf7fa 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/FilesPropertiesConfigProvider.java
@@ -19,7 +19,7 @@ import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
/**
* This implementation run in a folder and once found xml and properties files
- * will create the Configuration, when one file is created, deleted or modified the configuration will update
+ * will create the Configuration, when one file is created, deleted or modified the configuration will commit
* automatically.
* The default folder is META-INF/configuration, but you can change using the absolute path in
* "-Dtamaya.configbase" parameter.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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 4f42b95..cdd90b2 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
@@ -34,7 +34,7 @@ public class SystemPropertiesConfigProvider implements ConfigurationProviderSpi{
private Configuration systemConfig;
public SystemPropertiesConfigProvider(){
- systemConfig = PropertySourceBuilder.of("system.properties").addSystemProperties().build().toConfiguration();
+ systemConfig = Configuration.from(PropertySourceBuilder.of("system.properties").addSystemProperties().build());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
index eb776bc..eac0a3b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/DefaultConfigurationFormatSpi.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
index ac17d91..85ce778 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/IniFormat.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.ConfigException;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
index d360dae..10355ef 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesFormat.java
@@ -26,7 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
public class PropertiesFormat implements ConfigurationFormat{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
index 7b9b459..660c092 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/format/PropertiesXmlFormat.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.format;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import java.io.InputStream;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
index 554981b..f929f8e 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigChangeCallbackMethod.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.inject;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.Configuration;
import java.lang.reflect.Method;
@@ -41,10 +41,10 @@ public final class ConfigChangeCallbackMethod {
this.callbackMethod = Optional.of(callbackMethod).filter(
(m) -> void.class.equals(m.getReturnType()) &&
m.getParameterCount() == 1 &&
- m.getParameterTypes()[0].equals(ConfigChangeSet.class)).get();
+ m.getParameterTypes()[0].equals(PropertyChangeSet.class)).get();
}
- public Consumer<ConfigChangeSet> createConsumer(Object instance, Configuration... configurations){
+ public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
// TODO consider also environment !
return event -> {
for(Configuration cfg:configurations){
@@ -56,7 +56,7 @@ public final class ConfigChangeCallbackMethod {
};
}
- public void call(Object instance, ConfigChangeSet configChangeEvent) {
+ public void call(Object instance, PropertyChangeSet configChangeEvent) {
try {
callbackMethod.setAccessible(true);
callbackMethod.invoke(instance, configChangeEvent);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
index 57b83a9..90497ae 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredSetterMethod.java
@@ -24,7 +24,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.annotation.*;
@@ -53,7 +53,7 @@ public class ConfiguredSetterMethod {
m.getParameterCount() == 1).get();
}
- public Consumer<ConfigChangeSet> createConsumer(Object instance, Configuration... configurations){
+ public Consumer<PropertyChangeSet> createConsumer(Object instance, Configuration... configurations){
// TODO consider environment as well
return event -> {
for(Configuration cfg:configurations){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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 20b97c8..879d54a 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
@@ -22,7 +22,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.PropertySource;
@@ -134,7 +134,7 @@ public class ConfiguredType {
if (m.getParameterTypes().length != 1) {
return;
}
- if (!m.getParameterTypes()[0].equals(ConfigChangeSet.class)) {
+ if (!m.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
return;
}
if (!void.class.equals(m.getReturnType())) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
index 7bf85bd..e9b9ec3 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/WeakConfigListenerManager.java
@@ -18,7 +18,8 @@
*/
package org.apache.tamaya.core.internal.inject;
-import org.apache.tamaya.core.config.ConfigChangeSet;
+import org.apache.tamaya.core.properties.PropertyChangeSet;
+
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.locks.Lock;
@@ -36,7 +37,7 @@ public final class WeakConfigListenerManager{
private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
private StampedLock lock = new StampedLock();
- private Map<Object,Consumer<ConfigChangeSet>> listenerReferences = new WeakHashMap<>();
+ private Map<Object,Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
/** Private singleton constructor. */
private WeakConfigListenerManager(){}
@@ -51,11 +52,11 @@ public final class WeakConfigListenerManager{
* @param instance the instance, not null.
* @param listener the consumer.
*/
- public void registerConsumer(Object instance, Consumer<ConfigChangeSet> listener){
+ public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener){
Lock writeLock = lock.asWriteLock();
try {
writeLock.lock();
- Consumer<ConfigChangeSet> l = listenerReferences.get(instance);
+ Consumer<PropertyChangeSet> l = listenerReferences.get(instance);
if (l == null) {
listenerReferences.put(instance, listener);
} else {
@@ -86,7 +87,7 @@ public final class WeakConfigListenerManager{
* Publishes a change event to all consumers registered.
* @param change the change event, not null.
*/
- public void publishChangeEvent(ConfigChangeSet change){
+ public void publishChangeEvent(PropertyChangeSet change){
Lock readLock = lock.asReadLock();
try{
readLock.lock();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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
index 420246b..14ea651 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java b/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.java
new file mode 100644
index 0000000..cf94d99
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ConfigurationFormat.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.core.resource.Resource;
+import org.apache.tamaya.core.spi.ConfigurationFormatSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Implementations current this class encapsulate the mechanism how to read a
+ * resource URI including interpreting the format correctly (e.g. xml vs.
+ * properties).
+ */
+public interface ConfigurationFormat{
+
+ /**
+ * Returns a unique identifier that identifies each format.
+ *
+ * @return the unique format id, mever null.
+ */
+ public String getFormatName();
+
+ /**
+ * Check if the given {@link java.net.URI} and path xpression qualify that this format should be
+ * able to read them, e.g. checking for compatible file endings.
+ *
+ * @param resource the configuration location, not null
+ * @return {@code true} if the given resource is in a format supported by
+ * this instance.
+ */
+ boolean isAccepted(Resource resource);
+
+ /**
+ * Reads a {@link org.apache.tamaya.PropertySource} fromMap the given URI, using this format.
+ *
+ * @param resource the configuration location, not null
+ * @return the corresponding {@link java.util.Map}, never {@code null}.
+ */
+ Map<String,String> readConfiguration(Resource resource);
+
+ /**
+ * Access a {@link ConfigurationFormat}.
+ *
+ * @param formatName the format name
+ * @return the corresponding {@link ConfigurationFormat}, or {@code null}, if
+ * not available for the given environment.
+ */
+ public static ConfigurationFormat of(String formatName){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(formatName);
+ }
+
+ /**
+ * Get a collection current the keys current the registered {@link ConfigurationFormat} instances.
+ *
+ * @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
+ */
+ public static Collection<String> getFormatNames(){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormatNames();
+ }
+
+ /**
+ * Evaluate the matching format for a given resource.
+ *
+ * @param resource The resource
+ * @return a matching configuration format, or {@code null} if no matching format could be determined.
+ */
+ public static ConfigurationFormat from(Resource resource){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getFormat(resource);
+
+ }
+
+ /**
+ * Get an instance for reading configuration fromMap a {@code .properties} file,
+ * as defined by {@link java.util.Properties#load(java.io.InputStream)}.
+ *
+ * @return a format instance for reading configuration fromMap a {@code .properties} file, never null.
+ */
+ public static ConfigurationFormat getPropertiesFormat(){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getPropertiesFormat();
+ }
+
+ /**
+ * Get an instance for reading configuration fromMap a {@code .xml} properties file,
+ * as defined by {@link java.util.Properties#loadFromXML(java.io.InputStream)}.
+ *
+ * @return a format instance for reading configuration fromMap a {@code .xml} properties file, never null.
+ */
+ public static ConfigurationFormat getXmlPropertiesFormat(){
+ return ServiceContext.getInstance().getSingleton(ConfigurationFormatSpi.class).getXmlPropertiesFormat();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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
index e64cf07..6290706 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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
index e06f08d..c4bfc92 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/DelegatingPropertySource.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.PropertySource;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/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
index a780bcd..a0c1a53 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.PropertySource;
import java.util.HashMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
new file mode 100644
index 0000000..743655e
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FrozenPropertySource.java
@@ -0,0 +1,80 @@
+/*
+ * 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.io.Serializable;
+import java.util.Map;
+
+/**
+ * Configuration implementation that stores all current values current a given (possibly dynamic, contextual and non remote
+ * capable instance) and is fully serializable.
+ */
+final class FrozenPropertySource extends AbstractPropertySource implements Serializable{
+ private static final long serialVersionUID = -6373137316556444171L;
+
+ private PropertySource properties;
+
+ /**
+ * Constructor.
+ * @param config The base configuration.
+ */
+ private FrozenPropertySource(PropertySource config){
+ super(config.getName());
+ this.properties = PropertySourceBuilder.of(config).buildFrozen();
+ }
+
+ public static final PropertySource of(PropertySource config){
+ if(config instanceof FrozenPropertySource){
+ return config;
+ }
+ return new FrozenPropertySource(config);
+ }
+
+ @Override
+ public Map<String,String> getProperties(){
+ return properties.getProperties();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ FrozenPropertySource that = (FrozenPropertySource) o;
+
+ if (!properties.equals(that.properties)) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = properties.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "FreezedConfiguration{" +
+ "properties=" + properties +
+ ", name=" + name +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
new file mode 100644
index 0000000..160d6c4
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/MappedPropertySource.java
@@ -0,0 +1,53 @@
+package org.apache.tamaya.core.properties;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.UnaryOperator;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
+import org.apache.tamaya.core.properties.AbstractPropertySource;
+
+/**
+ * PropertySource implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate areas.
+ */
+class MappedPropertySource extends AbstractPropertySource {
+
+ private static final long serialVersionUID = 8690637705511432083L;
+
+ /** The mapping operator. */
+ private UnaryOperator<String> keyMapper;
+ /** The base configuration. */
+ private PropertySource config;
+
+ /**
+ * Creates a new instance.
+ * @param config the base configuration, not null
+ * @param keyMapper The mapping operator, not null
+ */
+ public MappedPropertySource(PropertySource config, UnaryOperator<String> keyMapper) {
+ super(config.getName());
+ this.config = Objects.requireNonNull(config);
+ this.keyMapper = Objects.requireNonNull(keyMapper);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> result = new HashMap<>();
+ Map<String, String> map = this.config.getProperties();
+ map.forEach((k,v) -> {
+ String targetKey = keyMapper.apply(k);
+ if(targetKey!=null){
+ result.put(targetKey, v);
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.config.isEmpty();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
index 56426ca..80184d1 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PathBasedPropertySource.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
import org.apache.tamaya.core.resource.Resource;
import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.core.config.ConfigurationFormat;
import org.apache.tamaya.core.resource.ResourceLoader;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
new file mode 100644
index 0000000..3cf6b31
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSet.java
@@ -0,0 +1,169 @@
+/*
+ * 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.PropertySource;
+
+import java.beans.PropertyChangeEvent;
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * Event that contains a set current changes that were applied or could be applied.
+ * This class is immutable and thread-safe. To create instances use
+ * {@link PropertyChangeSetBuilder}.
+ *
+ * Created by Anatole on 22.10.2014.
+ */
+public final class PropertyChangeSet implements Serializable{
+
+ private static final long serialVersionUID = 1l;
+ /** The base property provider/configuration. */
+ private PropertySource propertySource;
+ /** The base version, usable for optimistic locking. */
+ private String baseVersion;
+ /** The recorded changes. */
+ private Map<String,PropertyChangeEvent> changes = new HashMap<>();
+
+ /**
+ * Get an empty change set for the given provider.
+ * @param propertyProvider The base property provider/configuration, not null.
+ * @return an empty ConfigChangeSet instance.
+ */
+ public static PropertyChangeSet emptyChangeSet(PropertySource propertyProvider){
+ return new PropertyChangeSet(propertyProvider, Collections.emptySet());
+ }
+
+ /**
+ * Constructor used by {@link PropertyChangeSetBuilder}.
+ * @param propertySource The base property provider/configuration, not null.
+ * @param changes The recorded changes, not null.
+ */
+ PropertyChangeSet(PropertySource propertySource, Collection<PropertyChangeEvent> changes) {
+ this.propertySource = Objects.requireNonNull(propertySource);
+ changes.forEach((c) -> this.changes.put(c.getPropertyName(), c));
+ }
+
+ /**
+ * Get the underlying property provider/configuration.
+ * @return the underlying property provider/configuration, never null.
+ */
+ public PropertySource getPropertySource(){
+ return this.propertySource;
+ }
+
+ /**
+ * Get the base version, usable for optimistic locking.
+ * @return the base version.
+ */
+ public String getBaseVersion(){
+ return baseVersion;
+ }
+
+ /**
+ * Get the changes recorded.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertyChangeEvent> getEvents(){
+ return Collections.unmodifiableCollection(this.changes.values());
+ }
+
+ /**
+ * Access the number current removed entries.
+ * @return the number current removed entries.
+ */
+ public int getRemovedSize() {
+ return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
+ }
+
+ /**
+ * Access the number current added entries.
+ * @return the number current added entries.
+ */
+ public int getAddedSize() {
+ return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
+ }
+
+ /**
+ * Access the number current updated entries.
+ * @return the number current updated entries.
+ */
+ public int getUpdatedSize() {
+ return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
+ }
+
+
+ /**
+ * Checks if the given key was removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was removed.
+ */
+ public boolean isRemoved(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() == null;
+ }
+
+ /**
+ * Checks if the given key was added.
+ * @param key the target key, not null.
+ * @return true, if the given key was added.
+ */
+ public boolean isAdded(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() == null;
+ }
+
+ /**
+ * Checks if the given key was updated.
+ * @param key the target key, not null.
+ * @return true, if the given key was updated.
+ */
+ public boolean isUpdated(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() != null && change.getNewValue() != null;
+ }
+
+ /**
+ * Checks if the given key is added, or updated AND NOT removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was added, or updated BUT NOT removed.
+ */
+ public boolean containsKey(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() != null;
+ }
+
+ /**
+ * CHecks if the current change set does not contain any changes.
+ * @return tru, if the change set is empty.
+ */
+ public boolean isEmpty(){
+ return this.changes.isEmpty();
+ }
+
+
+ @Override
+ public String toString() {
+ return "ConfigChangeSet{" +
+ "properties=" + propertySource +
+ ", baseVersion=" + baseVersion +
+ ", changes=" + changes +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
new file mode 100644
index 0000000..b6e22f8
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertyChangeSetBuilder.java
@@ -0,0 +1,347 @@
+/*
+ * 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.PropertySource;
+
+import java.beans.PropertyChangeEvent;
+import java.util.*;
+import java.util.function.Function;
+
+/**
+ * Models a set current changes to be applied to a configuration/property provider. Such a set can be applied
+ * to any {@link org.apache.tamaya.PropertySource} instance. If the provider is mutable it may check the
+ * version given and applyChanges the changes to the provider/configuration, including triggering current regarding
+ * change events.
+ * <p>
+ * For appropriate conversion a {@code Function<String, Codec>} can be applied, which performs correct conversion,
+ * when changed values are set. This function enables connecting e.g. setters on a configuration template with
+ * the corresponding conversion logic, so the template calls are correctly converted back.
+ */
+public final class PropertyChangeSetBuilder {
+ /**
+ * The recorded changes.
+ */
+ final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
+ /**
+ * The underlying configuration/provider.
+ */
+ PropertySource source;
+
+ /**
+ * Constructor.
+ *
+ * @param source the underlying configuration/provider, not null.
+ */
+ private PropertyChangeSetBuilder(PropertySource source) {
+ this.source = Objects.requireNonNull(source);
+ }
+
+ /**
+ * Creates a new instance current this builder.
+ *
+ * @param source the underlying property provider/configuration, not null.
+ * @return the builder for chaining.
+ */
+ public static PropertyChangeSetBuilder of(PropertySource source) {
+ return new PropertyChangeSetBuilder(source);
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param newState the new target state, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder addChanges(PropertySource newState) {
+ compare(newState, this.source).forEach((c) -> this.delta.put(c.getPropertyName(), c));
+ return this;
+ }
+
+ /**
+ * Get the current values, also considering any changes recorded within this change set.
+ *
+ * @param key the key current the entry, not null.
+ * @return the keys, or null.
+ */
+ public String get(String key) {
+ PropertyChangeEvent change = this.delta.get(key);
+ if (change != null && !(change.getNewValue() == null)) {
+ return (String) change.getNewValue();
+ }
+ return null;
+ }
+
+ /**
+ * Marks the given key(s) fromMap the configuration/properties to be removed.
+ *
+ * @param key the key current the entry, not null.
+ * @param otherKeys additional keys to be removed (convenience), not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder remove(String key, String... otherKeys) {
+ String oldValue = this.source.get(key).orElse(null);
+ if (oldValue == null) {
+ this.delta.remove(key);
+ }
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
+ for (String addKey : otherKeys) {
+ oldValue = this.source.get(addKey).orElse(null);
+ if (oldValue == null) {
+ this.delta.remove(addKey);
+ }
+ this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
+ }
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, boolean value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ s* Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, byte value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, char value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, short value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, int value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, long value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, float value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, double value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder put(String key, String value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), String.valueOf(value)));
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @return the builder for chaining.
+ * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
+ */
+ public <T> PropertyChangeSetBuilder put(String key, Class<T> type, T value) {
+ put(key, type, value, null);
+ return this;
+ }
+
+ /**
+ * Applies the given keys.
+ *
+ * @param key the key current the entry, not null.
+ * @param value the keys to be applied, not null.
+ * @param adapter the codec to be used, if set overrides any other codecs that may apply. If null an appropriate
+ * codec is tried to be evaluated as needed.
+ * @return the builder for chaining.
+ * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
+ */
+ public <T> PropertyChangeSetBuilder put(String key, Class<T> type, T value, Function<T,String> adapter) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), adapter.apply(Objects.requireNonNull(value))));
+ return this;
+ }
+
+
+ /**
+ * Apply all the given values to the base configuration/properties.
+ * Note that all values passed must be convertible to String, either
+ * <ul>
+ * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
+ * <li>default codecs are present for the given type, or</li>
+ * <li>the value is an instanceof String</li>
+ * </ul>
+ *
+ * @param changes the changes to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder putAll(Map<String, String> changes) {
+ changes.putAll(changes);
+ return this;
+ }
+
+ /**
+ * This method will create a change set that clears all entries fromMap the given base configuration/properties.
+ *
+ * @return the builder for chaining.
+ */
+ public PropertyChangeSetBuilder deleteAll() {
+ this.delta.clear();
+ this.source.getProperties().forEach((k, v) ->
+ this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
+ return this;
+ }
+
+ /**
+ * Checks if the change set is empty, i.e. does not contain any changes.
+ *
+ * @return true, if the set is empty.
+ */
+ public boolean isEmpty() {
+ return this.delta.isEmpty();
+ }
+
+ /**
+ * Resets this change set instance. This will clear all changes done to this builder, so the
+ * set will be empty.
+ */
+ public void reset() {
+ this.delta.clear();
+ }
+
+ /**
+ * Builds the corresponding change set.
+ *
+ * @return the new change set, never null.
+ */
+ public PropertyChangeSet build() {
+ return new PropertyChangeSet(this.source, Collections.unmodifiableCollection(this.delta.values()));
+ }
+
+ /**
+ * Compares the two property config/configurations and creates a collection current all changes
+ * that must be appied to render {@code map1} into {@code map2}.
+ *
+ * @param map1 the source map, not null.
+ * @param map2 the target map, not null.
+ * @return a collection current change events, never null.
+ */
+ public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
+ List<PropertyChangeEvent> changes = new ArrayList<>();
+ for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
+ Optional<String> val = map2.get(en.getKey());
+ if (!val.isPresent()) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.get().equals(en.getValue())) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
+ }
+ }
+ for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
+ Optional<String> val = map1.get(en.getKey());
+ if (!val.isPresent()) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.equals(Optional.ofNullable(en.getValue()))) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
+ }
+ }
+ return changes;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "PropertyChangeEventBuilder [source=" + source + ", " +
+ ", delta=" + delta + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
new file mode 100644
index 0000000..5fcf895
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceFunctions.java
@@ -0,0 +1,65 @@
+/*
+ * 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.PropertySource;
+
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+import java.util.stream.Collectors;
+
+/**
+ * Accessor that provides useful functions along with configuration.
+ */
+public final class PropertySourceFunctions {
+ /**
+ * Private singleton constructor.
+ */
+ private PropertySourceFunctions() {
+ }
+
+ /**
+ * Creates a ConfigOperator that creates a Configuration containing only keys
+ * that are contained in the given area (non recursive). Hereby
+ * the area key is stripped away fromMap the resulting key.
+ *
+ * @param areaKey the area key, not null
+ * @param mappedAreaKey the target key, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<PropertySource> mapArea(String areaKey, String mappedAreaKey) {
+ return mapKeys(key -> key.startsWith(areaKey + '.') ?
+ mappedAreaKey + key.substring(areaKey.length()) : key);
+ }
+
+ /**
+ * Creates a {@link java.util.function.UnaryOperator} that creates a {@link org.apache.tamaya.Configuration} that maps any keys as
+ * defined by the {@code keyMapper} given. If the {@code keyMapper} returns
+ * {@code null} for a keys, it is removed from the resulting map.
+ *
+ * @param keyMapper the key mapper, not null
+ * @return the area configuration, with the areaKey stripped away.
+ */
+ public static UnaryOperator<PropertySource> mapKeys(UnaryOperator<String> keyMapper) {
+ return (c) -> new MappedPropertySource(c, keyMapper);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
index 69bbb79..85100e3 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.core.properties;
-import org.apache.tamaya.core.config.ConfigChangeSet;
import org.apache.tamaya.PropertySource;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
index 1d79537..f690ef9 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/URLBasedPropertySource.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.core.properties;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.core.internal.resources.io.UrlResource;
import org.apache.tamaya.core.resource.Resource;
-import org.apache.tamaya.core.config.ConfigurationFormat;
import java.net.URL;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
index 52e6f47..1c55e55 100644
--- a/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/resource/ResourceLoader.java
@@ -46,7 +46,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(String... expressions);
@@ -56,7 +56,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(Collection<String> expressions);
@@ -66,7 +66,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(ClassLoader classLoader, String... expressions);
@@ -76,7 +76,7 @@ public interface ResourceLoader{
*
* @param expressions the expressions to be resolved, not empty.
* @return the corresponding collection current {@link java.net.URI}s defining the
- * concrete resources to be read by a {@link org.apache.tamaya.core.config.ConfigurationFormat}
+ * concrete resources to be read by a {@link org.apache.tamaya.core.properties.ConfigurationFormat}
* .
*/
List<Resource> getResources(ClassLoader classLoader, Collection<String> expressions);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
index 7df988b..1c41820 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/ConfigurationFormatSpi.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.spi;
-import org.apache.tamaya.core.config.ConfigurationFormat;
+import org.apache.tamaya.core.properties.ConfigurationFormat;
import org.apache.tamaya.core.resource.Resource;
import java.util.Collection;
@@ -28,16 +28,16 @@ import java.util.Collection;
*/
public interface ConfigurationFormatSpi {
/**
- * Access a {@link org.apache.tamaya.core.config.ConfigurationFormat}.
+ * Access a {@link org.apache.tamaya.core.properties.ConfigurationFormat}.
*
* @param formatName the format name
- * @return the corresponding {@link org.apache.tamaya.core.config.ConfigurationFormat}, or {@code null}, if
+ * @return the corresponding {@link org.apache.tamaya.core.properties.ConfigurationFormat}, or {@code null}, if
* not available for the given environment.
*/
ConfigurationFormat getFormat(String formatName);
/**
- * Get a collection current the keys current the registered {@link org.apache.tamaya.core.config.ConfigurationFormat} instances.
+ * Get a collection current the keys current the registered {@link org.apache.tamaya.core.properties.ConfigurationFormat} instances.
*
* @return a collection current the keys current the registered {@link ConfigurationFormat} instances.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
deleted file mode 100644
index 7aa2407..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.config.ConfigurationFormat
+++ /dev/null
@@ -1,21 +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 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.
-#
-org.apache.tamaya.core.internal.format.PropertiesFormat
-org.apache.tamaya.core.internal.format.PropertiesXmlFormat
-org.apache.tamaya.core.internal.format.IniFormat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
new file mode 100644
index 0000000..7aa2407
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.properties.ConfigurationFormat
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+org.apache.tamaya.core.internal.format.PropertiesFormat
+org.apache.tamaya.core.internal.format.PropertiesXmlFormat
+org.apache.tamaya.core.internal.format.IniFormat
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/JavaOneDemo.java b/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
index e4c93ef..77cbf94 100644
--- a/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
+++ b/core/src/test/java/org/apache/tamaya/JavaOneDemo.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
-import org.apache.tamaya.core.config.ConfigFunctions;
+import org.apache.tamaya.core.ConfigurationFunctions;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -53,22 +53,22 @@ public class JavaOneDemo {
Map<String, String> cfgMap = new HashMap<>();
cfgMap.put("param1", "value1");
cfgMap.put("a", "Adrian"); // overrides Anatole
- Configuration config = PropertySourceBuilder.of("myTestConfig").addPaths(
+ Configuration config = Configuration.from(PropertySourceBuilder.of("myTestConfig").addPaths(
"classpath:test.properties").addPaths("classpath:cfg/test.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"})
- .addMap(cfgMap).build().toConfiguration();
- System.out.println(config.query(ConfigFunctions.getAreas()));
+ .addMap(cfgMap).build());
+ System.out.println(config.query(ConfigurationFunctions.getAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getAreas(s -> s.startsWith("another"))));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas()));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
System.out.println("---");
System.out.println(config);
System.out.print("--- b=");
System.out.println(config.get("b"));
- System.out.println("--- only a,b,c)");
- System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
+// System.out.println("--- only a,b,c)");
+// System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
index 4a5bfe7..bf8d709 100644
--- a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
@@ -1,93 +1,90 @@
-/*
- * 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.internal;
-
-import java.beans.PropertyChangeEvent;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.tamaya.core.config.ConfigChangeSet;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.AbstractConfiguration;
-import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
-
-/**
- * Simple test provider that creates a mutable instance of a configuration, just using a simple map instance.
- */
-public class MutableTestConfigProvider implements ConfigurationProviderSpi{
- /** The config name. */
- private static final String CONFIG_NAME = "mutableTestConfig";
- /** The config provided. */
- private MutableConfiguration testConfig;
-
- /**
- * COnsatructor.
- */
- public MutableTestConfigProvider(){
- Map<String, String> dataMap = new HashMap<>();
- dataMap.put("dad", "Anatole");
- dataMap.put("mom", "Sabine");
- dataMap.put("sons.1", "Robin");
- dataMap.put("sons.2", "Luke");
- dataMap.put("sons.3", "Benjamin");
-// PropertySource provider = PropertySourceBuilder.of(CONFIG_NAME).addMap(dataMap).build();
- testConfig = new MutableConfiguration(dataMap, CONFIG_NAME);
- }
-
- @Override
- public String getConfigName(){
- return CONFIG_NAME;
- }
-
- @Override
- public Configuration getConfiguration(){
- return testConfig;
- }
-
- @Override
- public void reload() {
-
- }
-
- /**
- * Implements a simple mutable config based on a Mao instance.
- */
- private final class MutableConfiguration extends AbstractConfiguration{
-
- private static final long serialVersionUID = 8811989470609598218L;
- private final Map<String,String> data = new ConcurrentHashMap<>();
-
- MutableConfiguration(Map<String,String> data, String name){
- super(name);
- this.data.putAll(data);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(data);
- }
-
- @Override
- public Configuration toConfiguration(){
- return this;
- }
- }
-}
+///*
+// * 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.internal;
+//
+//import java.util.Collections;
+//import java.util.HashMap;
+//import java.util.Map;
+//import java.util.concurrent.ConcurrentHashMap;
+//
+//import org.apache.tamaya.Configuration;
+//import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+//
+///**
+// * Simple test provider that creates a mutable instance of a configuration, just using a simple map instance.
+// */
+//public class MutableTestConfigProvider implements ConfigurationProviderSpi{
+// /** The config name. */
+// private static final String CONFIG_NAME = "mutableTestConfig";
+// /** The config provided. */
+// private MutableConfiguration testConfig;
+//
+// /**
+// * COnsatructor.
+// */
+// public MutableTestConfigProvider(){
+// Map<String, String> dataMap = new HashMap<>();
+// dataMap.put("dad", "Anatole");
+// dataMap.put("mom", "Sabine");
+// dataMap.put("sons.1", "Robin");
+// dataMap.put("sons.2", "Luke");
+// dataMap.put("sons.3", "Benjamin");
+//// PropertySource provider = PropertySourceBuilder.of(CONFIG_NAME).addMap(dataMap).build();
+// testConfig = new MutableConfiguration(dataMap, CONFIG_NAME);
+// }
+//
+// @Override
+// public String getConfigName(){
+// return CONFIG_NAME;
+// }
+//
+// @Override
+// public Configuration getConfiguration(){
+// return testConfig;
+// }
+//
+// @Override
+// public void reload() {
+//
+// }
+//
+// /**
+// * Implements a simple mutable config based on a Mao instance.
+// */
+// private final class MutableConfiguration extends AbstractConfiguration{
+//
+// private static final long serialVersionUID = 8811989470609598218L;
+// private final Map<String,String> data = new ConcurrentHashMap<>();
+//
+// MutableConfiguration(Map<String,String> data, String name){
+// super(name);
+// this.data.putAll(data);
+// }
+//
+// @Override
+// public Map<String, String> getProperties() {
+// return Collections.unmodifiableMap(data);
+// }
+//
+// @Override
+// public Configuration toConfiguration(){
+// return this;
+// }
+// }
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
index d185de1..ddbe4af 100644
--- a/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.internal;
+import org.apache.tamaya.PropertySource;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
@@ -47,8 +48,8 @@ public class TestConfigProvider implements ConfigurationProviderSpi{
config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
config.put("testProperty", "keys current testProperty");
config.put("runtimeVersion", "${java.version}");
- testConfig = PropertySourceBuilder.of("test").addMap(
- config).build().toConfiguration();
+ testConfig = Configuration.from(PropertySourceBuilder.of("test").addMap(
+ config).build());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
index 2e29cff..8b1c7dd 100644
--- a/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/AutoConfiguredTest.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.samples.annotations;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.ConfigurationBuilder;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -36,7 +36,7 @@ public class AutoConfiguredTest {
@Test
public void testTemplateWithEnvironmentVariableOnUnixoidSystem(){
AutoConfiguredClass config = new AutoConfiguredClass();
- Configuration.configure(config, ConfigurationBuilder.of("default").addPaths("classpath:cfg/autoloaded.xml").build());
+ Configuration.configure(config, Configuration.from(PropertySourceBuilder.of("default").addPaths("classpath:cfg/autoloaded.xml").build()));
System.out.println(config);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java b/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
index 499017a..e0351b2 100644
--- a/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
+++ b/core/src/test/java/org/apache/tamaya/simple/SimplePropertiesAndCLISample.java
@@ -22,7 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.ConfigFunctions;
+import org.apache.tamaya.core.ConfigurationFunctions;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -47,23 +47,23 @@ public class SimplePropertiesAndCLISample {
Map<String, String> cfgMap = new HashMap<>();
cfgMap.put("param1", "value1");
cfgMap.put("a", "Adrian"); // overrides Anatole
- Configuration config = PropertySourceBuilder.of("myTestConfig").addPaths(
+ Configuration config = Configuration.from(PropertySourceBuilder.of("myTestConfig").addPaths(
"classpath:test.properties").addPaths("classpath:cfg/test.xml")
.addArgs(new String[]{"-arg1", "--fullarg", "fullValue", "-myflag"}).addMap(cfgMap)
- .build().toConfiguration();
- System.out.println(config.query(ConfigFunctions.getAreas()));
+ .build());
+ System.out.println(config.query(ConfigurationFunctions.getAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getAreas(s -> s.startsWith("another"))));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas()));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas()));
System.out.println("---");
- System.out.println(config.query(ConfigFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
+ System.out.println(config.query(ConfigurationFunctions.getTransitiveAreas(s -> s.startsWith("another"))));
System.out.println("---");
System.out.println(config);
System.out.print("--- b=");
System.out.println(config.get("b"));
- System.out.println("--- only a,b,c)");
- System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
+// System.out.println("--- only a,b,c)");
+// System.out.println(PropertySourceBuilder.of(config).filter((f) -> f.equals("a") || f.equals("b") || f.equals("c")).build());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index 50e1753..e7f2049 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.config.ConfigFunctions;
+import org.apache.tamaya.core.ConfigurationFunctions;
import org.apache.tamaya.core.properties.AggregationPolicy;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
@@ -61,29 +61,29 @@ public class UC1ReadProperties {
@Test
public void example() {
- Configuration config = PropertySourceBuilder.of("test")
- .addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build().toConfiguration();
+ Configuration config = Configuration.from(PropertySourceBuilder.of("test")
+ .addPaths("classpath:ucs/UC1ReadProperties/UC1ReadPropertiesTest.properties").build());
// String name = config.get("name").orElse("Anatole");
// BigDecimal bigNum = config.get("num.BD", BigDecimal.class).orElseThrow(() -> new IllegalStateException("Sorry"));
// double anotherNum = config.getDouble("num.Double").getAsDouble();
// long longNum = config.getLong("num.Long").orElse(288900L);
// or more simpler use area function
- Configuration areaConfig2 = config.with(ConfigFunctions.selectArea("num"));
+ Configuration areaConfig2 = config.with(ConfigurationFunctions.selectArea("num"));
System.out.println(areaConfig2);
// iterator over an area, using streams only
Map<String, String> areaMap = config.getProperties().entrySet().stream()
.filter((e) -> e.getKey().startsWith("num."))
.collect(Collectors.toMap((e) -> e.getKey().substring("num.".length()), Map.Entry::getValue));
- Configuration areaConfig = PropertySourceBuilder.of("Test").addMap(areaMap).build().toConfiguration();
+ Configuration areaConfig = Configuration.from(PropertySourceBuilder.of("Test").addMap(areaMap).build());
System.out.println(areaConfig);
}
@Test
public void getConfigurationTest() {
PropertySource provider = PropertySourceBuilder.of("Test").addPaths("classpath:barFoo.properties").build();
- Configuration config = provider.toConfiguration();
+ Configuration config = Configuration.from(provider);
assertNotNull(config);
assertTrue(config.isEmpty());
assertTrue(config.getProperties().isEmpty());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java b/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
index 910610f..3269b3c 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/deltaspike/ConfigFiltering.java
@@ -19,8 +19,7 @@
package org.apache.tamaya.ucs.deltaspike;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.config.ConfigFunctions;
-import org.apache.tamaya.core.config.ConfigurationBuilder;
+import org.apache.tamaya.core.properties.PropertySourceBuilder;
import java.net.URL;
@@ -52,7 +51,7 @@ public class ConfigFiltering {
String pwd = Configuration.current().get("endPointURL.password").get();
// In the SPI
- ConfigurationBuilder.of().addPaths("...").filterValues((k,v) -> k.equals("endPointURL.password")?MyPKI.decrypt(v):v).build();
+ PropertySourceBuilder.of().addPaths("...").filterValues((k,v) -> k.equals("endPointURL.password")?MyPKI.decrypt(v):v).build();
}
private static class MyPKI{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b7a49a41/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
index 981a477..c4ba801 100644
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
+++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.spi.ConfigurationProviderSpi
@@ -16,5 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.internal.TestConfigProvider
-org.apache.tamaya.internal.MutableTestConfigProvider
\ No newline at end of file
+org.apache.tamaya.internal.TestConfigProvider
\ No newline at end of file