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 A0038C7C4 for ; Sun, 11 Jan 2015 00:44:15 +0000 (UTC) Received: (qmail 67086 invoked by uid 500); 11 Jan 2015 00:44:17 -0000 Delivered-To: apmail-tamaya-commits-archive@tamaya.apache.org Received: (qmail 67062 invoked by uid 500); 11 Jan 2015 00:44:17 -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 67053 invoked by uid 99); 11 Jan 2015 00:44:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Jan 2015 00:44:17 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT,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; Sun, 11 Jan 2015 00:43:52 +0000 Received: (qmail 66919 invoked by uid 99); 11 Jan 2015 00:43:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Jan 2015 00:43:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C83619A890F; Sun, 11 Jan 2015 00:43:48 +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: Sun, 11 Jan 2015 00:43:52 -0000 Message-Id: <792c0ca146ae4c9d9423ec6ec221fd7d@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/6] incubator-tamaya git commit: Adapted format implementations to new interface. X-Virus-Checked: Checked by ClamAV on apache.org Adapted format implementations to new interface. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/1bd7ce1a Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/1bd7ce1a Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/1bd7ce1a Branch: refs/heads/master Commit: 1bd7ce1a655bed2031af72821d3c21734c581a77 Parents: 202e9ac Author: anatole Authored: Thu Jan 8 04:40:13 2015 +0100 Committer: anatole Committed: Sun Jan 11 01:42:07 2015 +0100 ---------------------------------------------------------------------- ...hBasedMultiFormatPropertySourceProvider.java | 28 ++++---- .../tamaya/format/ConfigurationFormat.java | 7 +- .../apache/tamaya/format/PropertiesFormat.java | 71 ++++---------------- .../tamaya/format/PropertiesXmlFormat.java | 71 ++++---------------- 4 files changed, 44 insertions(+), 133 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1bd7ce1a/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java b/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java index 992878d..ed59f39 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/BasePathBasedMultiFormatPropertySourceProvider.java @@ -62,8 +62,8 @@ public abstract class BasePathBasedMultiFormatPropertySourceProvider implements /** * Creates a new instance. * - * @param formats the formats to be used, not null, not empty. - * @param paths the paths to be resolved, not null, not empty. + * @param formats the formats to be used, not null, not empty. + * @param paths the paths to be resolved, not null, not empty. */ public BasePathBasedMultiFormatPropertySourceProvider( List formats, @@ -75,8 +75,8 @@ public abstract class BasePathBasedMultiFormatPropertySourceProvider implements /** * Creates a new instance. * - * @param formats the formats to be used, not null, not empty. - * @param paths the paths to be resolved, not null, not empty. + * @param formats the formats to be used, not null, not empty. + * @param paths the paths to be resolved, not null, not empty. */ public BasePathBasedMultiFormatPropertySourceProvider( ClassLoader classLoader, @@ -88,14 +88,15 @@ public abstract class BasePathBasedMultiFormatPropertySourceProvider implements /** * Method to create a {@link org.apache.tamaya.spi.PropertySource} based on the given entries read. + * * @param entryTypeName the entry type of the entries read, not null. - * @param entries the entries read by the {@link org.apache.tamaya.format.ConfigurationFormat} - * @param formatUsed the format instance used to read the entries. + * @param entries the entries read by the {@link org.apache.tamaya.format.ConfigurationFormat} + * @param formatUsed the format instance used to read the entries. * @return the {@link org.apache.tamaya.spi.PropertySource} instance ready to be registered. * @see org.apache.tamaya.format.ConfigurationFormat#getEntryTypes() */ - protected abstract PropertySource getPropertySource(String entryTypeName, Map entries, - ConfigurationFormat formatUsed); + protected abstract PropertySource getPropertySource(String entryTypeName, Map entries, + ConfigurationFormat formatUsed); /** * This method does dynamically resolve the paths using the current ClassLoader set. If no ClassLoader was @@ -114,14 +115,13 @@ public abstract class BasePathBasedMultiFormatPropertySourceProvider implements try { for (ConfigurationFormat format : configFormats) { Map> entries = format.readConfiguration(res); - for(Map.Entry> en:entries.entrySet()) { + for (Map.Entry> en : entries.entrySet()) { PropertySource ps = getPropertySource(en.getKey(), en.getValue(), format); - if(ps!=null) { + if (ps != null) { propertySources.add(ps); - } - else{ - LOG.info(() -> "Config Entries read ignored by PropertySourceFactory: format="+format+ - ", entryType="+en.getKey()); + } else { + LOG.info(() -> "Config Entries read ignored by PropertySourceFactory: format=" + format + + ", entryType=" + en.getKey()); } } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1bd7ce1a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java index 970d0c5..2e43c17 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormat.java @@ -18,11 +18,8 @@ */ package org.apache.tamaya.format; -import org.apache.tamaya.spi.PropertySource; - import java.io.IOException; import java.net.URL; -import java.util.Collection; import java.util.Map; import java.util.Set; @@ -30,9 +27,9 @@ import java.util.Set; * Implementations current this class encapsulate the mechanism how to read a * resource including interpreting the format correctly (e.g. xml vs. * properties). In most cases file only contains entries of the same priority, which would then - * result in only one {@link PropertySource}. Complex file formats, hoiwever, may contain entries + * result in only one {@link org.apache.tamaya.spi.PropertySource}. Complex file formats, hoiwever, may contain entries * of different priorities. In this cases, each ordinal type found must be returned as a separate - * {@link PropertySource} instance. + * {@link org.apache.tamaya.spi.PropertySource} instance. */ public interface ConfigurationFormat { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1bd7ce1a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java index a49e492..ab7b029 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java @@ -18,17 +18,14 @@ */ package org.apache.tamaya.format; -import org.apache.tamaya.spi.PropertySource; - import java.io.InputStream; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -44,77 +41,37 @@ public class PropertiesFormat implements ConfigurationFormat { private final static Logger LOG = Logger.getLogger(PropertiesFormat.class.getName()); /** - * The target ordinal. - */ - private int ordinal; - - /** - * Creates a new format instance, hereby producing entries with the given ordinal, if not overridden by the - * configuration itself. - * TODO document and implement override feature - * - * @param ordinal the target ordinal. + * Creates a new format instance. */ - public PropertiesFormat(int ordinal) { - this.ordinal = ordinal; + public PropertiesFormat() { } - /** - * Get the target ordinal, produced by this format. - * - * @return the target ordinal - */ - public int getOrdinal() { - return ordinal; + @Override + public Set getEntryTypes() { + Set set = new HashSet<>(); + set.add(ConfigurationFormat.DEFAULT_ENTRY_TYPE); + return set; } @SuppressWarnings("unchecked") @Override - public Collection readConfiguration(URL url) { + public Map> readConfiguration(URL url) { final String name; if (Objects.requireNonNull(url).getQuery() == null) { name = "Properties(" + Objects.requireNonNull(url).toString() + ')'; } else { name = Objects.requireNonNull(url).getQuery(); } - List propertySources = new ArrayList<>(); + Map> result = new HashMap<>(); try (InputStream is = url.openStream()) { if (is != null) { final Properties p = new Properties(); p.load(is); - propertySources.add(new PropertySource() { - @Override - public int getOrdinal() { - return ordinal; - } - - @Override - public String getName() { - return name; - } - - @Override - public String get(String key) { - return p.getProperty(key); - } - - @Override - public Map getProperties() { - return Map.class.cast(p); - } - }); - return propertySources; + result.put(ConfigurationFormat.DEFAULT_ENTRY_TYPE, Map.class.cast(p)); } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + url); } - return Collections.emptyList(); - } - - @Override - public String toString() { - return "PropertiesFormat{" + - "ordinal=" + ordinal + - '}'; + return result; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1bd7ce1a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java index ddfe723..7aa549b 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java @@ -18,17 +18,14 @@ */ package org.apache.tamaya.format; -import org.apache.tamaya.spi.PropertySource; - import java.io.InputStream; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -45,77 +42,37 @@ public class PropertiesXmlFormat implements ConfigurationFormat { private final static Logger LOG = Logger.getLogger(PropertiesXmlFormat.class.getName()); /** - * The target ordinal. + * Creates a new format instance. */ - private int ordinal; + public PropertiesXmlFormat() { } - /** - * Creates a new format instance, producing entries for the given ordinal, if not overridden by a - * config entry itself. - * TODO document and implement override feature - * - * @param ordinal the target ordinal. - */ - public PropertiesXmlFormat(int ordinal) { - this.ordinal = ordinal; + @Override + public Set getEntryTypes() { + Set set = new HashSet<>(); + set.add(ConfigurationFormat.DEFAULT_ENTRY_TYPE); + return set; } - /** - * Get the target ordinal, produced by this format. - * - * @return the target ordinal - */ - public int getOrdinal() { - return ordinal; - } @SuppressWarnings("unchecked") @Override - public Collection readConfiguration(URL url) { + public Map> readConfiguration(URL url) { final String name; if (Objects.requireNonNull(url).getQuery() == null) { name = "XML-Properties(" + Objects.requireNonNull(url).toString() + ')'; } else { name = Objects.requireNonNull(url).getQuery(); } - List propertySources = new ArrayList<>(); + Map> result = new HashMap<>(); try (InputStream is = url.openStream()) { if (is != null) { final Properties p = new Properties(); p.loadFromXML(is); - propertySources.add(new PropertySource() { - @Override - public int getOrdinal() { - return ordinal; - } - - @Override - public String getName() { - return name; - } - - @Override - public String get(String key) { - return p.getProperty(key); - } - - @Override - public Map getProperties() { - return Map.class.cast(p); - } - }); - return propertySources; + result.put(ConfigurationFormat.DEFAULT_ENTRY_TYPE, Map.class.cast(p)); } } catch (Exception e) { LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + url); } - return Collections.emptyList(); - } - - @Override - public String toString() { - return "PropertiesXmlFormat{" + - "ordinal=" + ordinal + - '}'; + return result; } }