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 2015/01/11 01:43:52 UTC
[5/6] incubator-tamaya git commit: Adapted format implementations to
new interface.
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 <an...@apache.org>
Authored: Thu Jan 8 04:40:13 2015 +0100
Committer: anatole <an...@apache.org>
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<ConfigurationFormat> 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<String,String> entries,
- ConfigurationFormat formatUsed);
+ protected abstract PropertySource getPropertySource(String entryTypeName, Map<String, String> 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<String, Map<String, String>> entries = format.readConfiguration(res);
- for(Map.Entry<String, Map<String, String>> en:entries.entrySet()) {
+ for (Map.Entry<String, Map<String, String>> 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<String> getEntryTypes() {
+ Set<String> set = new HashSet<>();
+ set.add(ConfigurationFormat.DEFAULT_ENTRY_TYPE);
+ return set;
}
@SuppressWarnings("unchecked")
@Override
- public Collection<PropertySource> readConfiguration(URL url) {
+ public Map<String, Map<String, String>> 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<PropertySource> propertySources = new ArrayList<>();
+ Map<String, Map<String, String>> 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<String, String> 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<String> getEntryTypes() {
+ Set<String> 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<PropertySource> readConfiguration(URL url) {
+ public Map<String, Map<String, String>> 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<PropertySource> propertySources = new ArrayList<>();
+ Map<String, Map<String, String>> 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<String, String> 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;
}
}