tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: TAMAYA-69: Fixed API/compilation issues.
Date Fri, 27 Feb 2015 07:13:13 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 1f7eb1cea -> 54828fa94


TAMAYA-69: Fixed API/compilation issues.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/54828fa9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/54828fa9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/54828fa9

Branch: refs/heads/master
Commit: 54828fa9425978b882badae42665c7f28d038d55
Parents: 1f7eb1c
Author: anatole <anatole@apache.org>
Authored: Fri Feb 27 08:13:02 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Fri Feb 27 08:13:02 2015 +0100

----------------------------------------------------------------------
 .../tamaya/spi/ConfigurationContextBuilder.java | 17 -------
 .../tamaya/TestConfigurationProvider.java       | 17 ++++++-
 .../internal/DefaultConfigurationContext.java   |  2 +-
 .../DefaultConfigurationContextBuilder.java     | 51 ++++++++++++--------
 .../internal/DefaultConfigurationProvider.java  |  7 +++
 5 files changed, 54 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/54828fa9/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
index 4555bc8..0e75810 100644
--- a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
@@ -21,9 +21,7 @@ package org.apache.tamaya.spi;
 import org.apache.tamaya.PropertyConverter;
 import org.apache.tamaya.TypeLiteral;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.function.Predicate;
 
 /**
  * A builder for creating new or adapting instances of {@link ConfigurationContext}.
@@ -112,13 +110,6 @@ public interface ConfigurationContextBuilder {
      * @return this builder, for chaining, never null.
      */
     ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters);
-    /**
-     * Removes the given PropertyFilter instances.
-     *
-     * @param selector the selector query, not null.
-     * @return this builder, for chaining, never null.
-     */
-    ConfigurationContextBuilder removePropertyFilters(Predicate<PropertyFilter> selector);
 
     /**
      * Removes the given PropertyFilter instances.
@@ -129,14 +120,6 @@ public interface ConfigurationContextBuilder {
     ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters);
 
     /**
-     * Remove the property sources selected by the given selector predicate.
-     *
-     * @param selector the selector query, not null.
-     * @return this builder, for chaining, never null.
-     */
-    ConfigurationContextBuilder removePropertySources(Predicate<PropertySource> selector);
-
-    /**
      * This method can be used for programmatically adding {@link org.apache.tamaya.PropertyConverter}s.
      * It is not needed for normal 'usage' by end users, but only for Extension Developers!
      *

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/54828fa9/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
index 7c356c8..1a02903 100644
--- a/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
+++ b/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
@@ -19,6 +19,7 @@
 package org.apache.tamaya;
 
 import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
 import org.apache.tamaya.spi.ConfigurationProviderSpi;
 
 /**
@@ -28,7 +29,6 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi
{
 
     private static final Configuration config = new TestConfiguration();
 
-
     @Override
     public Configuration getConfiguration() {
         return config;
@@ -38,4 +38,19 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi
{
     public ConfigurationContext getConfigurationContext() {
         return null;
     }
+
+    @Override
+    public void setConfigurationContext(ConfigurationContext context) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isConfigurationContextSettable() {
+        return false;
+    }
+
+    @Override
+    public ConfigurationContextBuilder getConfigurationContextBuilder() {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/54828fa9/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
index 74f269a..bdcf7cc 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -121,7 +121,7 @@ public class DefaultConfigurationContext implements ConfigurationContext
{
     DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
         List<PropertySource> propertySources = new ArrayList<>();
         // first we load all PropertySources which got registered via java.util.ServiceLoader
-        propertySources.addAll(builder.propertySources);
+        propertySources.addAll(builder.propertySources.values());
         // now sort them according to their ordinal values
         Collections.sort(propertySources, propertySourceComparator);
         immutablePropertySources = Collections.unmodifiableList(propertySources);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/54828fa9/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
index 7b27c77..f89e8d1 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tamaya.core.internal;
 
+import org.apache.tamaya.ConfigException;
 import org.apache.tamaya.PropertyConverter;
 import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.spi.ConfigurationContext;
@@ -39,7 +40,7 @@ import java.util.Objects;
  */
 class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
 
-    List<PropertySource> propertySources = new ArrayList<>();
+    Map<String, PropertySource> propertySources = new HashMap<>();
     List<PropertyFilter> propertyFilters = new ArrayList<>();
     Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters
= new HashMap<>();
     PropertyValueCombinationPolicy combinationPolicy;
@@ -50,7 +51,9 @@ class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder
     @Override
     public ConfigurationContextBuilder setContext(ConfigurationContext context) {
         this.propertySources.clear();
-        this.propertySources.addAll(context.getPropertySources());
+        for(PropertySource ps:context.getPropertySources()) {
+            this.propertySources.put(ps.getName(), ps);
+        }
         this.propertyFilters.clear();
         this.propertyFilters.addAll(context.getPropertyFilters());
         this.propertyConverters.clear();
@@ -60,24 +63,39 @@ class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder
     }
 
     @Override
+    public ConfigurationContextBuilder addPropertySources(Collection<PropertySource>
propertySourcesToAdd) {
+        for(PropertySource ps:propertySourcesToAdd){
+            if(this.propertySources.containsKey(ps.getName())){
+                throw new ConfigException("Duplicate PropertySource: " + ps.getName());
+            }
+        }
+        for(PropertySource ps:propertySourcesToAdd) {
+            this.propertySources.put(ps.getName(), ps);
+        }
+        return this;
+    }
+
+    @Override
     public ConfigurationContextBuilder addPropertySources(PropertySource... propertySourcesToAdd)
{
         return addPropertySources(Arrays.asList(propertySourcesToAdd));
     }
 
     @Override
-    public ConfigurationContextBuilder addPropertySources(Collection<PropertySource>
propertySourcesToAdd) {
-        this.propertySources.addAll(propertySourcesToAdd);
+    public ConfigurationContextBuilder removePropertySources(Collection<String> propertySourcesToRemove)
{
+        for(String key: propertySourcesToRemove){
+            this.propertySources.remove(key);
+        }
         return this;
     }
 
     @Override
-    public ConfigurationContextBuilder removePropertySources(PropertySource... propertySourcesToRemove)
{
+    public ConfigurationContextBuilder removePropertySources(String... propertySourcesToRemove)
{
         return removePropertySources(Arrays.asList(propertySourcesToRemove));
     }
 
     @Override
-    public ConfigurationContextBuilder removePropertySources(Collection<PropertySource>
propertySourcesToRemove) {
-        this.propertySources.removeAll(propertySourcesToRemove);
+    public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter>
filters) {
+        this.propertyFilters.addAll(filters);
         return this;
     }
 
@@ -87,8 +105,8 @@ class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder
     }
 
     @Override
-    public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter>
filters) {
-        this.propertyFilters.addAll(filters);
+    public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter>
filters) {
+        this.propertyFilters.removeAll(filters);
         return this;
     }
 
@@ -98,21 +116,12 @@ class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder
     }
 
     @Override
-    public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter>
filters) {
-        this.propertyFilters.removeAll(filters);
-        return this;
-    }
-
-    @Override
-    public <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T>
typeToConvert,
-                                                                PropertyConverter<T>
propertyConverter) {
+    public <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T>
typeToConvert, PropertyConverter<T> propertyConverter) {
         List<PropertyConverter<?>> converters = this.propertyConverters.get(typeToConvert);
         if(converters==null){
-            converters = new ArrayList<>();
-            this.propertyConverters.putIfAbsent(typeToConvert, converters);
-            converters = this.propertyConverters.get(typeToConvert);
+            converters =  new ArrayList<>();
+            this.propertyConverters.put(typeToConvert, converters);
         }
-        converters.add(propertyConverter);
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/54828fa9/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index a0671f2..31e46d8 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -54,6 +54,13 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi
{
         Configuration newConfig = new DefaultConfiguration(context);
         // TODO think on a SPI or move event part into API...
         this.config = newConfig;
+        this.context = context;
+    }
+
+
+    @Override
+    public boolean isConfigurationContextSettable() {
+        return true;
     }
 
 }


Mime
View raw message