Return-Path: X-Original-To: apmail-tamaya-commits-archive@minotaur.apache.org Delivered-To: apmail-tamaya-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1CDFD179AE for ; Fri, 27 Feb 2015 02:41:09 +0000 (UTC) Received: (qmail 42341 invoked by uid 500); 27 Feb 2015 02:41:09 -0000 Delivered-To: apmail-tamaya-commits-archive@tamaya.apache.org Received: (qmail 42286 invoked by uid 500); 27 Feb 2015 02:41:09 -0000 Mailing-List: contact commits-help@tamaya.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tamaya.incubator.apache.org Delivered-To: mailing list commits@tamaya.incubator.apache.org Received: (qmail 42261 invoked by uid 99); 27 Feb 2015 02:41:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Feb 2015 02:41:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 27 Feb 2015 02:41:07 +0000 Received: (qmail 41693 invoked by uid 99); 27 Feb 2015 02:40:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Feb 2015 02:40:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BFA61E0E3E; Fri, 27 Feb 2015 02:40:46 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anatole@apache.org To: commits@tamaya.incubator.apache.org Date: Fri, 27 Feb 2015 02:40:49 -0000 Message-Id: In-Reply-To: <4215e2d842614b86bf737deee4755050@git.apache.org> References: <4215e2d842614b86bf737deee4755050@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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. X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Fri Feb 27 02:20:08 2015 +0100 Committer: anatole 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 data; + private static final Logger LOG = Logger.getLogger(FlattenedDefaultPropertySource.class.getName()); + private Map 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 getProperties() { - return data; + return defaultSection; } }