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 2016/11/13 22:28:36 UTC

[2/2] incubator-tamaya-extensions git commit: TAMAYA-196: Added mutable name support to BaseProperty, simplifying downstream.

TAMAYA-196: Added mutable name support to BaseProperty, simplifying downstream.


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

Branch: refs/heads/master
Commit: dc2cd7d380bd8a0971f8b3a49bd9394caea781a3
Parents: df3978a
Author: anatole <an...@apache.org>
Authored: Sun Nov 13 23:10:50 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Nov 13 23:10:50 2016 +0100

----------------------------------------------------------------------
 .../ObservingPropertySourceProvider.java        |  2 +-
 .../MappedConfigurationDataPropertySource.java  | 23 +++++++-----------
 .../MutablePropertiesPropertySource.java        | 25 +++++++++-----------
 .../MutableXmlPropertiesPropertySource.java     | 24 +++++++++----------
 4 files changed, 32 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/dc2cd7d3/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index f7c0097..1197746 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -113,7 +113,7 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
      * @return property sources from the given file.
      */
     protected Collection<PropertySource> getPropertySources(final Path file) {
-        return Arrays.asList(new PropertySource[]{new BasePropertySource() {
+        return Arrays.asList(new PropertySource[]{new BasePropertySource(file.toString()) {
             private final Map<String,String> props = readProperties(file);
 
             @Override

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/dc2cd7d3/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java b/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
index e47652c..589ff82 100644
--- a/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
+++ b/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
@@ -44,8 +44,7 @@ public class MappedConfigurationDataPropertySource extends BasePropertySource {
      * @see ConfigurationData#getCombinedProperties()
      */
     public MappedConfigurationDataPropertySource(ConfigurationData data) {
-        this.properties = Collections.unmodifiableMap(populateData(data));
-        this.data = data;
+        this(0, data);
     }
 
     /*
@@ -59,6 +58,14 @@ public class MappedConfigurationDataPropertySource extends BasePropertySource {
         super(defaultOrdinal);
         this.properties = Collections.unmodifiableMap(populateData(data));
         this.data = data;
+        String name = this.properties.get("_name");
+        if (name == null) {
+            name = this.data.getResource();
+        }
+        if (name == null) {
+            name = getClass().getSimpleName();
+        }
+        setName(name);
     }
 
     /**
@@ -82,18 +89,6 @@ public class MappedConfigurationDataPropertySource extends BasePropertySource {
     }
 
     @Override
-    public String getName() {
-        String name = this.properties.get("_name");
-        if (name == null) {
-            name = this.data.getResource();
-        }
-        if (name == null) {
-            name = getClass().getSimpleName();
-        }
-        return name;
-    }
-
-    @Override
     public PropertyValue get(String key) {
         String val = properties.get(key);
         return PropertyValue.of(key, val, getName());

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/dc2cd7d3/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
index b38cf7a..fd5bb49 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
@@ -51,11 +51,6 @@ implements MutablePropertySource{
     private static final Logger LOG = Logger.getLogger(MutablePropertiesPropertySource.class.getName());
 
     /**
-     * The property source name.
-     */
-    private String name;
-
-    /**
      * The configuration resource's URL.
      */
     private File file;
@@ -69,12 +64,20 @@ implements MutablePropertySource{
      * Creates a new Properties based PropertySource based on the given URL.
      *
      * @param propertiesLocation the URL encoded location, not null.
+     */
+    public MutablePropertiesPropertySource(File propertiesLocation) {
+        this(propertiesLocation, 0);
+    }
+
+    /**
+     * Creates a new Properties based PropertySource based on the given URL.
+     *
+     * @param propertiesLocation the URL encoded location, not null.
      * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
      *                       source's properties.
      */
     public MutablePropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
-        super(defaultOrdinal);
-        this.name = propertiesLocation.toString();
+        super(propertiesLocation.toString(), defaultOrdinal);
         try {
             this.file = propertiesLocation;
             refresh();
@@ -83,6 +86,7 @@ implements MutablePropertySource{
         }
     }
 
+
     @Override
     public PropertyValue get(String key) {
         Map<String,String> properties = getProperties();
@@ -101,17 +105,10 @@ implements MutablePropertySource{
     }
 
     @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
     public Map<String, String> getProperties() {
         return Collections.unmodifiableMap(this.properties);
     }
 
-
-
     /**
      * loads the Properties from the given URL
      *

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/dc2cd7d3/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
index 62ae0c8..e5aaea4 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
@@ -51,11 +51,6 @@ implements MutablePropertySource{
     private static final Logger LOG = Logger.getLogger(MutableXmlPropertiesPropertySource.class.getName());
 
     /**
-     * The property source name.
-     */
-    private String name;
-
-    /**
      * The configuration resource's URL.
      */
     private File file;
@@ -65,6 +60,16 @@ implements MutablePropertySource{
      */
     private Map<String, String> properties = new HashMap<>();
 
+
+    /**
+     * Creates a new Properties based PropertySource based on the given URL.
+     *
+     * @param propertiesLocation the URL encoded location, not null.
+     */
+    public MutableXmlPropertiesPropertySource(File propertiesLocation) {
+        this(propertiesLocation, 0);
+    }
+
     /**
      * Creates a new Properties based PropertySource based on the given URL.
      *
@@ -73,8 +78,7 @@ implements MutablePropertySource{
      *                       source's properties.
      */
     public MutableXmlPropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
-        super(defaultOrdinal);
-        this.name = propertiesLocation.toString();
+        super(propertiesLocation.toString(), defaultOrdinal);
         try {
             this.file = propertiesLocation;
             load();
@@ -103,16 +107,10 @@ implements MutablePropertySource{
     }
 
     @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
     public Map<String, String> getProperties() {
         return Collections.unmodifiableMap(this.properties);
     }
 
-
     /**
      * loads the Properties from the given URL
      *