tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [4/8] incubator-tamaya git commit: Fixed bugs: getName() of flattened provider returned always the same name and did not reflect the underlying resource. Ordinal was not read from the config entries.
Date Fri, 27 Feb 2015 02:40:49 GMT
Fixed bugs: getName() of flattened provider returned always the same name and did not reflect
the underlying resource.
Ordinal was not read from the config entries.


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

Branch: refs/heads/master
Commit: fc79de438ba48a3b734ba055117d644afa24ca2c
Parents: 3267be0
Author: anatole <anatole@apache.org>
Authored: Fri Feb 27 02:20:08 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Fri Feb 27 03:40:35 2015 +0100

----------------------------------------------------------------------
 .../format/FlattenedDefaultPropertySource.java  | 44 ++++++++++++++++----
 1 file changed, 35 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/fc79de43/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
index ba4fd91..b782be1 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
@@ -19,42 +19,68 @@
 package org.apache.tamaya.format;
 
 import org.apache.tamaya.spi.PropertySource;
+import sun.reflect.generics.reflectiveObjects.LazyReflectiveObjectGenerator;
 
 import java.util.Collections;
 import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * Flattened default PropertySource that uses the flattened config data read from an URL
by a
  * ${@link org.apache.tamaya.format.ConfigurationFormat}.
  */
 public class FlattenedDefaultPropertySource implements PropertySource {
-
-    private Map<String, String> data;
+    private static final Logger LOG = Logger.getLogger(FlattenedDefaultPropertySource.class.getName());
+    private Map<String, String> defaultSection;
+    private ConfigurationData data;
 
     /*
      * Constructor, uses hereby the flattened config data read from an URL by a
      * ${@link org.apache.tamaya.format.ConfigurationFormat}, and if not present falls back
to the default section.
      */
     public FlattenedDefaultPropertySource(ConfigurationData data) {
-        this.data = data.getSection(ConfigurationData.FLATTENED_SECTION_NAME);
-        if (this.data == null) {
-            this.data = data.getDefaultSection();
+        this.defaultSection = data.getSection(ConfigurationData.FLATTENED_SECTION_NAME);
+        if (this.defaultSection == null) {
+            this.defaultSection = data.getDefaultSection();
         }
-        this.data = Collections.unmodifiableMap(this.data);
+        this.defaultSection = Collections.unmodifiableMap(this.defaultSection);
+        this.data = data;
+    }
+
+    @Override
+    public String getName(){
+        String name = this.defaultSection.get("[meta].name");
+        if(name==null){
+            name = this.data.getResource();
+        }
+        if(name==null){
+            name = getClass().getSimpleName();
+        }
+        return name;
     }
 
     @Override
     public int getOrdinal() {
-        return 0; // TODO read from config!
+        String ordinalValue = this.defaultSection.get(PropertySource.TAMAYA_ORDINAL);
+        if(ordinalValue!=null){
+            try{
+                return Integer.parseInt(ordinalValue.trim());
+            }
+            catch(Exception e){
+                LOG.log(Level.WARNING, e, () -> "Failed to parse Tamaya ordinal from "
+ data.getResource());
+            }
+        }
+        return 0;
     }
 
     @Override
     public String get(String key) {
-        return data.get(key);
+        return defaultSection.get(key);
     }
 
     @Override
     public Map<String, String> getProperties() {
-        return data;
+        return defaultSection;
     }
 }


Mime
View raw message