TAMAYA-252: Unified PropertyValue API and usage, also separating key, value, source and other meta-data and defining a clear builder policy.
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/9f915b25 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/9f915b25 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/9f915b25 Branch: refs/heads/master Commit: 9f915b254b91731f2e9fa1eefe8f459f727f6a7c Parents: ed22695 Author: anatole <anat...@apache.org> Authored: Sun Mar 5 21:29:02 2017 +0100 Committer: anatole <anat...@apache.org> Committed: Sun Mar 5 21:29:02 2017 +0100 ---------------------------------------------------------------------- .../events/FilePropertySourceProvider.java | 7 +- .../tamaya/events/FrozenPropertySource.java | 17 +++- .../events/PropertySourceChangeBuilder.java | 18 ++--- .../events/ChangeableGlobalPropertySource.java | 3 +- .../ChangeableThreadLocalPropertySource.java | 3 +- .../tamaya/events/FrozenPropertySourceTest.java | 5 +- .../tamaya/events/RandomPropertySource.java | 15 ++-- .../ObservingPropertySourceProvider.java | 12 +-- .../tamaya/filter/ConfigurationFilter.java | 3 +- .../org/apache/tamaya/filter/FilterContext.java | 3 +- .../filter/internal/DefaultMetadataFilter.java | 3 +- .../tamaya/filter/ConfigurationFilterTest.java | 21 ++--- .../tamaya/filter/ProgrammableFilterTest.java | 81 +++++++++++--------- .../MappedConfigurationDataPropertySource.java | 8 +- ...ppedConfigurationDataPropertySourceTest.java | 16 ++-- .../apache/tamaya/json/JSONPropertySource.java | 17 ++-- .../org/apache/tamaya/json/JSONVisitor.java | 1 + .../tamaya/yaml/JSONPropertySourceTest.java | 2 +- .../apache/tamaya/yaml/YAMLPropertySource.java | 17 ++-- .../functions/ConfigWrappingPropertySource.java | 9 ++- .../functions/EnrichedPropertySource.java | 30 +++++--- .../functions/FilteredPropertySource.java | 17 ++-- .../tamaya/functions/MappedPropertySource.java | 23 +++--- .../functions/PropertySourceFunctions.java | 7 +- .../functions/ValueMappedPropertySource.java | 15 ++-- .../functions/ConfigurationFunctionsTest.java | 20 +---- .../cdi/cfg/ProvidedPropertySource.java | 12 +-- .../integration/cdi/cfg/TestPropertySource.java | 10 ++- .../tamaya/inject/TestPropertySource.java | 13 +++- .../internal/DefaultDynamicValueTest.java | 46 ++++++----- .../apache/tamaya/jndi/JNDIPropertySource.java | 20 ++++- .../org.apache.tamaya.spi.PropertySource | 19 +++++ .../tamaya/jndi/JNDIPropertySourceTest.java | 3 +- .../MutablePropertiesPropertySource.java | 19 +---- .../MutableXmlPropertiesPropertySource.java | 20 ++--- .../internal/ExpressionResolutionFilter.java | 9 ++- .../tamaya/resolver/MyTestPropertySource.java | 13 +++- .../AbstractPathPropertySourceProvider.java | 16 ++-- .../AbstractPathPropertySourceProviderTest.java | 3 +- .../PathBasedPropertySourceProvider.java | 26 ++++--- .../tamaya/spisupport/BasePropertySource.java | 13 +--- .../tamaya/spisupport/CLIPropertySource.java | 13 +++- .../tamaya/spisupport/DefaultConfiguration.java | 80 +++++++++++-------- .../spisupport/EnvironmentPropertySource.java | 11 ++- .../tamaya/spisupport/MapPropertySource.java | 14 +++- .../spisupport/PropertyFilterManager.java | 16 ++-- .../tamaya/spisupport/PropertyFiltering.java | 17 ++-- .../spisupport/PropertySourceComparator.java | 52 ++++++------- .../tamaya/spisupport/RegexPropertyFilter.java | 3 +- .../tamaya/spisupport/SimplePropertySource.java | 39 ++++------ .../tamaya/spisupport/SystemPropertySource.java | 22 +++--- .../spisupport/BasePropertySourceTest.java | 25 +++--- .../spisupport/CLIPropertySourceTest.java | 18 ++--- .../DefaultConfigurationContextTest.java | 10 +-- .../EnvironmentPropertySourceTest.java | 9 ++- .../PropertiesFilePropertySourceTest.java | 6 +- .../spisupport/RegexPropertyFilterTest.java | 26 ++++--- .../spisupport/SimplePropertySourceTest.java | 9 ++- .../spisupport/SystemPropertySourceTest.java | 24 +++--- .../spisupport/TestPropertyDefaultSource.java | 9 ++- 60 files changed, 569 insertions(+), 449 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java index 90c430c..088ffe2 100644 --- a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java +++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java @@ -23,6 +23,7 @@ import org.apache.tamaya.ConfigException; import org.apache.tamaya.core.propertysource.BasePropertySource; import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; import java.io.IOException; import java.io.InputStream; @@ -49,9 +50,9 @@ public class FilePropertySourceProvider extends AbstractPathPropertySourceProvid } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { - Map<String, String> properties = new HashMap<>(); + Map<String, PropertyValue> properties = new HashMap<>(); try (InputStream stream = propertiesFile.openStream()) { Properties props = new Properties(); if (stream != null) { @@ -59,7 +60,7 @@ public class FilePropertySourceProvider extends AbstractPathPropertySourceProvid } for (String key : props.stringPropertyNames()) { - properties.put(key, props.getProperty(key)); + properties.put(key, PropertyValue.of(key, props.getProperty(key), getName())); } } catch (IOException e) { throw new ConfigException("Error loading properties from " + propertiesFile, e); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java index 53f1dda..0bc71ce 100644 --- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java +++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java @@ -40,12 +40,14 @@ public final class FrozenPropertySource implements PropertySource, Serializable /** * The properties read. */ - private Map<String, String> properties = new HashMap<>(); + private Map<String, PropertyValue> properties = new HashMap<>(); /** * The PropertySource's name. */ private final String name; + private long frozenAt = System.currentTimeMillis(); + /** * Constructor. * @@ -53,7 +55,6 @@ public final class FrozenPropertySource implements PropertySource, Serializable */ private FrozenPropertySource(PropertySource propertySource) { this.properties.putAll(propertySource.getProperties()); - this.properties.put("[meta]frozenAt", String.valueOf(System.currentTimeMillis())); this.properties = Collections.unmodifiableMap(this.properties); this.ordinal = PropertySourceComparator.getOrdinal(propertySource); this.name = propertySource.getName(); @@ -81,13 +82,21 @@ public final class FrozenPropertySource implements PropertySource, Serializable return this.ordinal; } + /** + * Get the creation timestamp of this instance. + * @return the creation timestamp + */ + public long getFrozenAt(){ + return frozenAt; + } + @Override public PropertyValue get(String key) { - return PropertyValue.of(key, this.properties.get(key), getName()); + return this.properties.get(key); } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return properties; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java ---------------------------------------------------------------------- diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java index 4c873bd..1e58855 100644 --- a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java +++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java @@ -89,20 +89,20 @@ public final class PropertySourceChangeBuilder { */ public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) { List<PropertyChangeEvent> changes = new ArrayList<>(); - for (Map.Entry<String, String> en : map1.getProperties().entrySet()) { + for (Map.Entry<String, PropertyValue> en : map1.getProperties().entrySet()) { PropertyValue val = map2.get(en.getKey()); if (val == null) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue())); + changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue().getValue())); } else if (!val.equals(en.getValue())) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue())); + changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue().getValue())); } } - for (Map.Entry<String, String> en : map2.getProperties().entrySet()) { + for (Map.Entry<String, PropertyValue> en : map2.getProperties().entrySet()) { PropertyValue val = map1.get(en.getKey()); if (val == null) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), null)); + changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), null)); } else if (!val.equals(en.getValue())) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val.getValue())); + changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), val.getValue())); } } return changes; @@ -193,7 +193,7 @@ public final class PropertySourceChangeBuilder { * @return the builder for chaining. */ public PropertySourceChangeBuilder putAll(Map<String, String> changes) { - for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) { + for (Map.Entry<String, PropertyValue> en : this.source.getProperties().entrySet()) { this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), null, en.getValue())); } return this; @@ -206,8 +206,8 @@ public final class PropertySourceChangeBuilder { */ public PropertySourceChangeBuilder deleteAll() { this.delta.clear(); - for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) { - this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null)); + for (Map.Entry<String, PropertyValue> en : this.source.getProperties().entrySet()) { + this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue().getValue(), null)); } return this; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java index 476aaf6..180b36e 100644 --- a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java +++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java @@ -19,6 +19,7 @@ package org.apache.tamaya.events; import org.apache.tamaya.core.propertysource.BasePropertySource; +import org.apache.tamaya.spi.PropertyValue; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -36,7 +37,7 @@ public class ChangeableGlobalPropertySource extends BasePropertySource{ } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java index cc6c812..fe6f973 100644 --- a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java +++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java @@ -19,6 +19,7 @@ package org.apache.tamaya.events; import org.apache.tamaya.core.propertysource.BasePropertySource; +import org.apache.tamaya.spi.PropertyValue; import java.util.HashMap; import java.util.Map; @@ -42,7 +43,7 @@ public class ChangeableThreadLocalPropertySource extends BasePropertySource{ } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java index dc02127..88cee48 100644 --- a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java +++ b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java @@ -20,6 +20,7 @@ package org.apache.tamaya.events; import org.apache.tamaya.core.propertysource.SystemPropertySource; import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.PropertySourceComparator; import org.junit.Test; @@ -59,8 +60,8 @@ public class FrozenPropertySourceTest { public void testGet() throws Exception { PropertySource ps = FrozenPropertySource.of(myPS); assertNotNull(ps); - for (Map.Entry<String, String> e : myPS.getProperties().entrySet()) { - assertEquals(ps.get(e.getKey()).getValue(), e.getValue()); + for (Map.Entry<String, PropertyValue> e : myPS.getProperties().entrySet()) { + assertEquals(ps.get(e.getKey()).getValue(), e.getValue().getValue()); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java index c4414f1..041056b 100644 --- a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java +++ b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java @@ -20,6 +20,7 @@ package org.apache.tamaya.events; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.spi.PropertyValueBuilder; import java.util.HashMap; import java.util.Map; @@ -29,7 +30,12 @@ import java.util.Map; */ public class RandomPropertySource implements PropertySource{ - private Map<String, String> data = new HashMap<>(); + private Map<String, PropertyValue> data = new HashMap<>(); + + @Override + public int getOrdinal() { + return 0; + } @Override public String getName() { @@ -45,11 +51,10 @@ public class RandomPropertySource implements PropertySource{ } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { synchronized(data) { - data.put("random.new", String.valueOf(Math.random())); - data.put("_random.new.source", getName()); - data.put("_random.new.timestamp", String.valueOf(System.currentTimeMillis())); + data.put("random.new", new PropertyValueBuilder("random.new", String.valueOf(Math.random()), getName()) + .addMetaEntry("_random.new.timestamp", String.valueOf(System.currentTimeMillis())).build()); return new HashMap<>(data); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/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 1197746..6142b5a 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 @@ -42,6 +42,7 @@ import java.util.logging.Logger; import org.apache.tamaya.ConfigException; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertySourceProvider; +import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.BasePropertySource; /** @@ -114,10 +115,10 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider, */ protected Collection<PropertySource> getPropertySources(final Path file) { return Arrays.asList(new PropertySource[]{new BasePropertySource(file.toString()) { - private final Map<String,String> props = readProperties(file); + private final Map<String,PropertyValue> props = readProperties(file); @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return props; } }}); @@ -129,13 +130,14 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider, * @param file the file, not null. * @return properties as read from the given file. */ - protected static Map<String,String> readProperties(Path file) { + protected static Map<String,PropertyValue> readProperties(Path file) { try (InputStream is = file.toUri().toURL().openStream()){ final Properties props = new Properties(); props.load(is); - final Map<String,String> result = new HashMap<>(); + final Map<String,PropertyValue> result = new HashMap<>(); for(final Map.Entry<Object,Object> en:props.entrySet()){ - result.put(String.valueOf(en.getKey()), String.valueOf(en.getValue())); + String key = String.valueOf(en.getKey()); + result.put(key, PropertyValue.of(key, String.valueOf(en.getValue()), file.toString())); } return result; } catch (final Exception e) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java ---------------------------------------------------------------------- diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java index 4848bdc..394fda8 100644 --- a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java +++ b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java @@ -19,6 +19,7 @@ package org.apache.tamaya.filter; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; /** @@ -108,7 +109,7 @@ public final class ConfigurationFilter implements PropertyFilter{ } @Override - public String filterProperty(String valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) { + public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) { if(context.isSinglePropertyScoped()){ for(PropertyFilter pred: THREADED_VALUE_FILTERS.get().getFilters()){ valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java ---------------------------------------------------------------------- diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java b/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java index 596c67f..35eb987 100644 --- a/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java +++ b/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java @@ -19,6 +19,7 @@ package org.apache.tamaya.filter; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; import java.util.ArrayList; import java.util.Arrays; @@ -101,7 +102,7 @@ public final class FilterContext implements PropertyFilter{ } @Override - public String filterProperty(String valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) { + public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) { for(PropertyFilter filter:filters){ valueToBeFiltered = filter.filterProperty(valueToBeFiltered, context); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java ---------------------------------------------------------------------- diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java index 95e9d25..5694a9d 100644 --- a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java +++ b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java @@ -21,13 +21,14 @@ package org.apache.tamaya.filter.internal; import org.apache.tamaya.filter.ConfigurationFilter; import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; /** * Default property filter that hides metadta entries starting with an '_', similar ti {@code etcd}. */ public final class DefaultMetadataFilter implements PropertyFilter{ @Override - public String filterProperty(String valueToBeFiltered, FilterContext context) { + public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { if(context.isSinglePropertyScoped()){ // When accessing keys explicitly, do not hide anything. return valueToBeFiltered; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java ---------------------------------------------------------------------- diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java index 73602c8..6a9e309 100644 --- a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java +++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java @@ -22,6 +22,7 @@ import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; import org.junit.Test; import static org.junit.Assert.*; @@ -45,8 +46,8 @@ public class ConfigurationFilterTest { assertNotNull(ConfigurationFilter.getSingleValueFilterContext()); PropertyFilter testFilter = new PropertyFilter() { @Override - public String filterProperty(String value, FilterContext context) { - return context.getKey() + ":testGetSingleFilters"; + public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test"); } }; ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter); @@ -61,8 +62,8 @@ public class ConfigurationFilterTest { assertNotNull(ConfigurationFilter.getSingleValueFilterContext()); PropertyFilter testFilter = new PropertyFilter() { @Override - public String filterProperty(String value, FilterContext context) { - return context.getKey() + ":testGetSingleFilters"; + public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test"); } }; ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter); @@ -77,8 +78,8 @@ public class ConfigurationFilterTest { assertNotNull(ConfigurationFilter.getMapFilterContext()); PropertyFilter testFilter = new PropertyFilter() { @Override - public String filterProperty(String value, FilterContext context) { - return context.getKey() + ":testGetMapFilters"; + public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + return PropertyValue.of(context.getKey(), context.getKey() + ":testGetMapFilters", "test"); } }; ConfigurationFilter.getMapFilterContext().addFilter(testFilter); @@ -93,8 +94,8 @@ public class ConfigurationFilterTest { assertNotNull(ConfigurationFilter.getMapFilterContext()); PropertyFilter testFilter = new PropertyFilter() { @Override - public String filterProperty(String value, FilterContext context) { - return context.getKey() + ":testGetMapFilters"; + public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + return PropertyValue.of(context.getKey(), context.getKey() + ":testGetMapFilters", "test"); } }; ConfigurationFilter.getMapFilterContext().addFilter(testFilter); @@ -109,8 +110,8 @@ public class ConfigurationFilterTest { assertNotNull(ConfigurationFilter.getSingleValueFilterContext()); PropertyFilter testFilter = new PropertyFilter() { @Override - public String filterProperty(String value, FilterContext context) { - return context.getKey() + ":testGetSingleFilters"; + public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test"); } }; ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java ---------------------------------------------------------------------- diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java index c236d45..910e089 100644 --- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java +++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java @@ -19,6 +19,7 @@ package org.apache.tamaya.filter; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.RegexPropertyFilter; import org.junit.Test; @@ -33,27 +34,31 @@ import static org.junit.Assert.*; */ public class ProgrammableFilterTest { + PropertyValue test1Property = PropertyValue.of("test1","test1","test"); + PropertyValue test2Property = PropertyValue.of("test2","test2","test"); + PropertyValue test3Property = PropertyValue.of("test.test3","test.test3","test"); + @Test public void testAddRemoveFilter() throws Exception { FilterContext filter = new FilterContext(); - Map<String,String> map = new HashMap<>(); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2"); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3"); + Map<String,PropertyValue> map = new HashMap<>(); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property); RegexPropertyFilter regexFilter = new RegexPropertyFilter(); regexFilter.setIncludes("test\\..*"); filter.addFilter(regexFilter); - assertNull(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true))); - assertNull(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true))); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3"); + assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map))); + assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map))); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property); filter.removeFilter(0); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2"); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3"); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property); filter.addFilter(0, regexFilter); - assertNull(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true))); - assertNull(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true))); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3"); + assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map))); + assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map))); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property); } @Test @@ -65,17 +70,17 @@ public class ProgrammableFilterTest { map.put("test1", "test1"); map.put("test2", "test2"); map.put("test.test3", "test.test3"); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test1.", map, true)), "test2"); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test1.test3", map, true)), "test.test3"); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test1.", test2Property)), test2Property); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test1.test3", test3Property)), test3Property); filter.addFilter(regexFilter); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test1.", map, true)), "test2"); - assertNull(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true))); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test1.", test2Property)), test2Property); + assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property))); filter.clearFilters(); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2"); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3"); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)), test2Property); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)), test3Property); } @Test @@ -83,17 +88,17 @@ public class ProgrammableFilterTest { FilterContext filter = new FilterContext(); RegexPropertyFilter regexFilter = new RegexPropertyFilter(); regexFilter.setIncludes("test\\..*"); - Map<String,String> map = new HashMap<>(); - map.put("test1", "test1"); - map.put("test2", "test2"); - map.put("test.test3", "test.test3"); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2"); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3"); + Map<String,PropertyValue> map = new HashMap<>(); + map.put("test1", test1Property); + map.put("test2", test1Property); + map.put("test.test3", test3Property); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property); filter.setFilters(regexFilter); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test.1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test.2", map, true)), "test2"); - assertNull(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test3.test3", map, true))); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test.1", map)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test.2", map)), test2Property); + assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test3.test3", map))); } @Test @@ -102,13 +107,13 @@ public class ProgrammableFilterTest { RegexPropertyFilter regexFilter = new RegexPropertyFilter(); regexFilter.setIncludes("test1.*"); Map<String,String> map = new HashMap<>(); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2"); - assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test1.test3", map, true)), "test.test3"); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property); + assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)), test2Property); + assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test1.test3", test3Property)), test3Property); filter.setFilters(Arrays.asList(new PropertyFilter[]{regexFilter})); - assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1"); - assertNull(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true))); - assertNull(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true))); + assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property); + assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property))); + assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property))); } @Test http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/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 9266718..e8eef40 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 @@ -141,8 +141,12 @@ public class MappedConfigurationDataPropertySource extends BasePropertySource { } @Override - public Map<String, String> getProperties() { - return Collections.unmodifiableMap(properties); + public Map<String, PropertyValue> getProperties() { + Map<String, PropertyValue> result = new HashMap<>(); + for(Map.Entry<String,String> en:this.properties.entrySet()) { + result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + return result; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java b/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java index 1e18187..1d26d3a 100644 --- a/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java +++ b/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java @@ -67,13 +67,13 @@ public class MappedConfigurationDataPropertySourceTest { @Test public void testGet() throws Exception { MappedConfigurationDataPropertySource ps = new MappedConfigurationDataPropertySource(createConfigurationData("test2")); - assertEquals("aValue", ps.get("a").get("a")); - assertNotNull(ps.get("section1.sectionKey1").get("section1.sectionKey1")); - assertNotNull(ps.get("section2.sectionKey1").get("section2.sectionKey1")); + assertEquals("aValue", ps.get("a").getValue()); + assertNotNull(ps.get("section1.sectionKey1").getValue()); + assertNotNull(ps.get("section2.sectionKey1").getValue()); assertNull(ps.get("sectionKey1")); ps = new MappedConfigurationDataPropertySource(createConfigurationDataNoDefault("test2")); - assertEquals("sectionValue11", ps.get("section1.sectionKey1").get("section1.sectionKey1")); - assertEquals("sectionValue21", ps.get("section2.sectionKey1").get("section2.sectionKey1")); + assertEquals("sectionValue11", ps.get("section1.sectionKey1").getValue()); + assertEquals("sectionValue21", ps.get("section2.sectionKey1").getValue()); assertNull(ps.get("a")); assertNull(ps.get("section1")); } @@ -82,7 +82,7 @@ public class MappedConfigurationDataPropertySourceTest { public void testGetProperties() throws Exception { MappedConfigurationDataPropertySource ps = new MappedConfigurationDataPropertySource(createConfigurationData("test3")); assertNotNull(ps.getProperties()); - assertEquals("aValue", ps.getProperties().get("a")); + assertEquals("aValue", ps.getProperties().get("a").getValue()); assertNotNull(ps.getProperties().get("section1.sectionKey1")); assertNotNull(ps.getProperties().get("section2.sectionKey1")); assertNull(ps.getProperties().get("section1.sectionKey2")); @@ -91,8 +91,8 @@ public class MappedConfigurationDataPropertySourceTest { assertNull(ps.getProperties().get("sectionKey2")); ps = new MappedConfigurationDataPropertySource(createConfigurationDataNoDefault("test3")); assertNotNull(ps.getProperties()); - assertEquals("sectionValue11", ps.getProperties().get("section1.sectionKey1")); - assertEquals("sectionValue21", ps.getProperties().get("section2.sectionKey1")); + assertEquals("sectionValue11", ps.getProperties().get("section1.sectionKey1").getValue()); + assertEquals("sectionValue21", ps.getProperties().get("section2.sectionKey1").getValue()); assertNull(ps.get("section1")); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java index 1ac5ee7..5934210 100644 --- a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java +++ b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java @@ -50,7 +50,7 @@ public class JSONPropertySource implements PropertySource { /** The underlying resource. */ private final URL urlResource; /** The values read. */ - private final Map<String, String> values; + private final Map<String, PropertyValue> values; /** The evaluated ordinal. */ private int ordinal; /** The JSON reader factory used. */ @@ -81,7 +81,7 @@ public class JSONPropertySource implements PropertySource { this.ordinal = defaultOrdinal; // may be overriden by read... this.values = readConfig(urlResource); if (this.values.containsKey(TAMAYA_ORDINAL)) { - this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL)); + this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL).getValue()); } Map<String, Object> config = new HashMap<>(); config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true); @@ -109,11 +109,12 @@ public class JSONPropertySource implements PropertySource { @Override public PropertyValue get(String key) { - return PropertyValue.of(key, getProperties().get(key), getName()); + return getProperties().get(key); } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { + return Collections.unmodifiableMap(values); } @@ -123,7 +124,7 @@ public class JSONPropertySource implements PropertySource { * @return the configuration read from the given resource URL. * @throws ConfigException if resource URL cannot be read. */ - protected Map<String, String> readConfig(URL urlResource) throws IOException{ + protected Map<String, PropertyValue> readConfig(URL urlResource) throws IOException{ try (InputStream is = urlResource.openStream()) { JsonStructure root = this.readerFactory.createReader(is, Charset.forName("UTF-8")).read(); @@ -135,7 +136,11 @@ public class JSONPropertySource implements PropertySource { Map<String, String> values = new HashMap<>(); JSONVisitor visitor = new JSONVisitor((JsonObject)root, values); visitor.run(); - return values; + Map<String, PropertyValue> result = new HashMap<>(); + for(Map.Entry<String,String> en:values.entrySet()){ + result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + return result; }catch(IOException ioe){ throw ioe; }catch (Exception t) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java ---------------------------------------------------------------------- diff --git a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java index e1516e5..b7aa532 100644 --- a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java +++ b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java @@ -19,6 +19,7 @@ package org.apache.tamaya.json; import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.PropertyValue; import java.util.*; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java b/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java index 015ad0a..e2cd404 100644 --- a/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java +++ b/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java @@ -39,7 +39,7 @@ public class JSONPropertySourceTest extends CommonJSONTestCaseCollection { assertThat(configURL, CoreMatchers.notNullValue()); JSONPropertySource source = new JSONPropertySource(configURL, 4); - assertEquals(source.get(PropertySource.TAMAYA_ORDINAL).getValue(), "16784"); + assertEquals(source.getOrdinal(), 16784); } @Test(expected=IOException.class) http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java index ae54624..aef0572 100644 --- a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java +++ b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java @@ -23,6 +23,7 @@ import org.apache.tamaya.spi.PropertyValue; import java.net.URL; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.logging.Level; @@ -37,7 +38,7 @@ public class YAMLPropertySource implements PropertySource { /** The underlying resource. */ private final URL urlResource; /** The values read. */ - private final Map<String, String> values; + private final Map<String, PropertyValue> values; /** The evaluated ordinal. */ private int ordinal; /** The format implementation used for parsing. */ @@ -59,9 +60,13 @@ public class YAMLPropertySource implements PropertySource { public YAMLPropertySource(URL resource, int defaultOrdinal) { urlResource = Objects.requireNonNull(resource); this.ordinal = defaultOrdinal; // may be overriden by read... - this.values = format.readConfig(urlResource); - if (this.values.containsKey(TAMAYA_ORDINAL)) { - this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL)); + Map<String,String> cfg = format.readConfig(urlResource); + this.values = new HashMap<>(); + for(Map.Entry<String,String> en:cfg.entrySet()){ + this.values.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + if (cfg.containsKey(TAMAYA_ORDINAL)) { + this.ordinal = Integer.parseInt(cfg.get(TAMAYA_ORDINAL)); } } @@ -85,11 +90,11 @@ public class YAMLPropertySource implements PropertySource { @Override public PropertyValue get(String key) { - return PropertyValue.of(key, getProperties().get(key), getName()); + return getProperties().get(key); } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return Collections.unmodifiableMap(values); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java index a4bf810..dbad205 100644 --- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java +++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java @@ -22,6 +22,7 @@ import org.apache.tamaya.Configuration; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; +import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -63,8 +64,12 @@ final class ConfigWrappingPropertySource implements PropertySource { } @Override - public Map<String, String> getProperties() { - return config.getProperties(); + public Map<String, PropertyValue> getProperties() { + Map<String,PropertyValue> result = new HashMap<>(); + for(Map.Entry<String,String> en:config.getProperties().entrySet()){ + result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + return result; } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java index d00e446..c1367b8 100644 --- a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java +++ b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java @@ -22,9 +22,7 @@ import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.PropertySourceComparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; /** * PropertySource, that has values added or overridden. @@ -33,7 +31,7 @@ class EnrichedPropertySource implements PropertySource { private final PropertySource basePropertySource; - private final Map<String, String> addedProperties; + private final Map<String, PropertyValue> addedProperties = new HashMap<>(); private final boolean overriding; @@ -46,11 +44,14 @@ class EnrichedPropertySource implements PropertySource { */ EnrichedPropertySource(PropertySource propertySource, Map<String, String> properties, boolean overriding) { this.basePropertySource = Objects.requireNonNull(propertySource); - this.addedProperties = Objects.requireNonNull(properties); + for(Map.Entry<String,String> en:properties.entrySet()){ + this.addedProperties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), propertySource.getName())); + } this.overriding = overriding; } + @Override public int getOrdinal() { return PropertySourceComparator.getOrdinal(basePropertySource); } @@ -63,9 +64,9 @@ class EnrichedPropertySource implements PropertySource { @Override public PropertyValue get(String key) { if (overriding) { - String val = addedProperties.get(key); + PropertyValue val = addedProperties.get(key); if (val != null) { - return PropertyValue.of(key, val, getName()); + return val; } return basePropertySource.get(key); } @@ -73,19 +74,24 @@ class EnrichedPropertySource implements PropertySource { if (val != null) { return val; } - return PropertyValue.of(key, addedProperties.get(key), getName()); + return addedProperties.get(key); } @Override - public Map<String, String> getProperties() { - Map<String, String> allProps; + public Map<String, PropertyValue> getProperties() { + Map<String, PropertyValue> allProps; if (overriding) { - allProps = new HashMap<>(basePropertySource.getProperties()); + allProps = new HashMap<>(); + for(PropertyValue val:basePropertySource.getProperties().values()){ + allProps.put(val.getKey(), val); + } allProps.putAll(addedProperties); } else { allProps = new HashMap<>(addedProperties); - allProps.putAll(basePropertySource.getProperties()); + for(PropertyValue val:basePropertySource.getProperties().values()){ + allProps.put(val.getKey(), val); + } } return allProps; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java index 92c6946..10736aa 100644 --- a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java +++ b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java @@ -44,6 +44,7 @@ class FilteredPropertySource implements PropertySource { this.filter = Objects.requireNonNull(filter); } + @Override public int getOrdinal(){ return PropertySourceComparator.getOrdinal(baseSource); } @@ -55,15 +56,19 @@ class FilteredPropertySource implements PropertySource { @Override public PropertyValue get(String key) { - return PropertyValue.of(key, getProperties().get(key), getName()); + PropertyValue val = this.baseSource.get(key); + if(val!=null && filter.test(val.getKey())) { + return val; + } + return null; } @Override - public Map<String,String> getProperties(){ - final Map<String,String> result = new HashMap<>(); - for(Map.Entry<String,String> en: this.baseSource.getProperties().entrySet()) { - if (filter.test(en.getKey())) { - result.put(en.getKey(), en.getValue()); + public Map<String, PropertyValue> getProperties(){ + final Map<String,PropertyValue> result = new HashMap<>(); + for(PropertyValue val: this.baseSource.getProperties().values()) { + if (filter.test(val.getKey())) { + result.put(val.getKey(), val); } } return result; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java index 793c62e..dfef0f9 100644 --- a/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java +++ b/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java @@ -22,9 +22,7 @@ import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.PropertySourceComparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; /** * PropertySource implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate sections. @@ -53,6 +51,7 @@ class MappedPropertySource implements PropertySource { this.keyMapper = Objects.requireNonNull(keyMapper); } + @Override public int getOrdinal() { return PropertySourceComparator.getOrdinal(this.propertySource); } @@ -63,13 +62,12 @@ class MappedPropertySource implements PropertySource { } @Override - public Map<String, String> getProperties() { - Map<String, String> result = new HashMap<>(); - Map<String, String> map = this.propertySource.getProperties(); - for (Map.Entry<String, String> en : map.entrySet()) { + public Map<String, PropertyValue> getProperties() { + Map<String,PropertyValue> result = new HashMap<>(); + for (PropertyValue en : this.propertySource.getProperties().values()) { String targetKey = keyMapper.mapKey(en.getKey()); if (targetKey != null) { - result.put(targetKey, en.getValue()); + result.put(targetKey, PropertyValue.of(targetKey, en.getValue(), getName())); } } return result; @@ -82,7 +80,14 @@ class MappedPropertySource implements PropertySource { @Override public PropertyValue get(String key) { - return PropertyValue.of(key, getProperties().get(key), getName()); + PropertyValue result = this.propertySource.get(key); + if(result!=null){ + String targetKey = keyMapper.mapKey(key); + if (targetKey != null) { + return result.toBuilder().mapKey(targetKey).build(); + } + } + return null; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java index c3128c4..4646df5 100644 --- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java +++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java @@ -42,6 +42,11 @@ public final class PropertySourceFunctions { private static final PropertySource EMPTY_PROPERTYSOURCE = new PropertySource() { @Override + public int getOrdinal() { + return 0; + } + + @Override public String getName() { return "<empty>"; } @@ -52,7 +57,7 @@ public final class PropertySourceFunctions { } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return Collections.emptyMap(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java index eb212f5..6264a43 100644 --- a/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java +++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java @@ -22,9 +22,7 @@ import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.PropertySourceComparator; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; +import java.util.*; /** @@ -42,6 +40,7 @@ class ValueMappedPropertySource implements PropertySource{ this.source = Objects.requireNonNull(current); } + @Override public int getOrdinal() { return PropertySourceComparator.getOrdinal(source); } @@ -61,12 +60,12 @@ class ValueMappedPropertySource implements PropertySource{ } @Override - public Map<String, String> getProperties() { - Map<String, String> map = new HashMap<>(); - for(Map.Entry<String,String> entry:source.getProperties().entrySet()) { - map.put(entry.getKey(), valueFilter.mapProperty(entry.getKey(), entry.getValue())); + public Map<String, PropertyValue> getProperties() { + Map<String,PropertyValue> result = new HashMap<>(); + for(PropertyValue val:source.getProperties().values()) { + result.put(val.getKey(), val.toBuilder().setValue(valueFilter.mapProperty(val.getKey(), val.getValue())).build()); } - return map; + return result; } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java ---------------------------------------------------------------------- diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java index 5aa6995..5850eb4 100644 --- a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java +++ b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java @@ -48,7 +48,10 @@ public class ConfigurationFunctionsTest { @Test public void testSection() throws Exception { -// TODO implement test + // Tests with/without stripping of keys: + // See https://issues.apache.org/jira/browse/TAMAYA-235 + testSection(false); + testSection(true); } @Test @@ -149,21 +152,6 @@ public class ConfigurationFunctionsTest { assertTrue(ps.getProperties().isEmpty()); } - /** - * See https://issues.apache.org/jira/browse/TAMAYA-235 - */ - @Test - public void testSection_StripKeys() { - testSection(true); - } - - /** - * See https://issues.apache.org/jira/browse/TAMAYA-235 - */ - @Test - public void testSection_NoStripKeys() { - testSection(false); - } private void testSection(boolean stripKeys){ ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java index a5a1755..90692f3 100644 --- a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java +++ b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java @@ -32,14 +32,14 @@ import java.util.Map; @Vetoed class ProvidedPropertySource implements PropertySource{ - final Map<String,String> config = new HashMap<>(); + final Map<String,PropertyValue> config = new HashMap<>(); public ProvidedPropertySource(){ - config.put("a.b.c.key3", "keys current a.b.c.key3"); - config.put("a.b.c.key4", "keys current a.b.c.key4"); - config.put("{meta}source.type:"+getClass().getName(), "PropertySourceProvider"); + config.put("a.b.c.key3", PropertyValue.of("a.b.c.key3","keys current a.b.c.key3",getName())); + config.put("a.b.c.key4", PropertyValue.of("a.b.c.key4","keys current a.b.c.key4", getName())); } + @Override public int getOrdinal() { return 10; } @@ -51,11 +51,11 @@ class ProvidedPropertySource implements PropertySource{ @Override public PropertyValue get(String key) { - return PropertyValue.of(key, config.get(key), getName()); + return config.get(key); } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return config; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java index ca09065..6e86b8d 100644 --- a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java +++ b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java @@ -63,12 +63,16 @@ public class TestPropertySource implements PropertySource{ @Override public PropertyValue get(String key) { - return PropertyValue.of(key, config.get(key), getName()); + String val = this.config.get(key); + if(val!=null) { + return PropertyValue.of(key, val, getName()); + } + return null; } @Override - public Map<String, String> getProperties() { - return config; + public Map<String, PropertyValue> getProperties() { + return PropertyValue.map(config ,getName()); } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java index 4af2f33..20de8e8 100644 --- a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java +++ b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java @@ -43,6 +43,11 @@ public class TestPropertySource implements PropertySource { } @Override + public int getOrdinal() { + return 0; + } + + @Override public String getName() { return getClass().getName(); } @@ -53,8 +58,12 @@ public class TestPropertySource implements PropertySource { } @Override - public Map<String, String> getProperties() { - return properties; + public Map<String, PropertyValue> getProperties() { + Map<String,PropertyValue> result = new HashMap<>(); + for(Map.Entry<String,String> en:properties.entrySet()){ + result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName())); + } + return result; } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java ---------------------------------------------------------------------- diff --git a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java index 16cc265..3ee690d 100644 --- a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java +++ b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.inject.internal; -import org.apache.tamaya.ConfigException; import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.inject.api.DynamicValue; import org.apache.tamaya.inject.api.Config; @@ -63,22 +62,27 @@ public class DefaultDynamicValueTest { } }; - private Map<String,String> properties = new HashMap<>(); + private Map<String,PropertyValue> properties = new HashMap<>(); private Configuration config = ConfigurationProvider.createConfiguration( ConfigurationProvider.getConfigurationContextBuilder().addPropertySources( new PropertySource() { @Override + public int getOrdinal() { + return 0; + } + + @Override public String getName() { return "test"; } @Override public PropertyValue get(String key) { - return PropertyValue.of(key,properties.get(key),getName()); + return properties.get(key); } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return properties; } @@ -105,7 +109,7 @@ public class DefaultDynamicValueTest { @Test public void testCommitAndGet() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); assertNotNull(val); @@ -114,7 +118,7 @@ public class DefaultDynamicValueTest { @Test public void testCommitAndGets() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.EXPLICIT); @@ -122,14 +126,14 @@ public class DefaultDynamicValueTest { assertEquals("aValue",val.evaluateValue()); // change config val.get(); - this.properties.put("a", "aValue2"); + properties.put("a",PropertyValue.of("a","aValue2","test")); assertTrue(val.updateValue()); assertEquals("aValue2", val.commitAndGet()); } @Test public void testCommit() throws Exception { - properties.put("a", "aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.EXPLICIT); @@ -137,7 +141,7 @@ public class DefaultDynamicValueTest { assertEquals("aValue", val.evaluateValue()); // change config val.get(); - this.properties.put("a", "aValue2"); + properties.put("a",PropertyValue.of("a","aValue2","test")); assertEquals("aValue2", val.evaluateValue()); assertTrue(val.updateValue()); val.commit(); @@ -156,37 +160,37 @@ public class DefaultDynamicValueTest { @Test public void testAddRemoveListener() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.IMMEDIATE); val.addListener(consumer); // change config val.get(); - this.properties.put("a", "aValue2"); + properties.put("a",PropertyValue.of("a","aValue2","test")); val.get(); assertNotNull(event); event = null; val.removeListener(consumer); - this.properties.put("a", "aValue3"); + properties.put("a",PropertyValue.of("a","aValue3","test")); val.updateValue(); assertNull(event); } @Test public void testGet() throws Exception { - properties.put("a", "aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.IMMEDIATE); - properties.put("a", "aValue2"); + properties.put("a",PropertyValue.of("a","aValue2","test")); val.updateValue(); assertEquals("aValue2", val.get()); } @Test public void testUpdateValue() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.EXPLICIT); @@ -201,25 +205,25 @@ public class DefaultDynamicValueTest { @Test public void testEvaluateValue() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.EXPLICIT); assertNotNull(val.get()); assertEquals("aValue",val.evaluateValue()); - properties.put("a", "aValue2"); + properties.put("a",PropertyValue.of("a","aValue2","test")); assertEquals("aValue2", val.evaluateValue()); } @Test public void testGetNewValue() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.EXPLICIT); val.get(); assertNull(val.getNewValue()); - properties.put("a", "aValue2"); + properties.put("a",PropertyValue.of("a","aValue2","test")); val.get(); assertNotNull(val.getNewValue()); assertEquals("aValue2", val.getNewValue()); @@ -234,7 +238,7 @@ public class DefaultDynamicValueTest { @Test public void testIfPresent() throws Exception { - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"), config); val.setUpdatePolicy(UpdatePolicy.IMMEDIATE); @@ -250,7 +254,7 @@ public class DefaultDynamicValueTest { config); val.setUpdatePolicy(UpdatePolicy.IMMEDIATE); assertEquals("bla", val.orElse("bla")); - properties.put("a","aValue"); + properties.put("a",PropertyValue.of("a","aValue","test")); val.updateValue(); assertEquals("aValue", val.orElse("bla")); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java index 307f096..a944db7 100644 --- a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java +++ b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java @@ -22,9 +22,15 @@ import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.BasePropertySource; -import javax.naming.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameClassPair; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.logging.Level; @@ -36,6 +42,12 @@ import java.util.logging.Logger; public class JNDIPropertySource extends BasePropertySource { /** The logger used. */ private static final Logger LOG = Logger.getLogger(JNDIPropertySource.class.getName()); + + /** + * Default ordinal to be used, as defined by {@link PropertySource#getOrdinal()} documentation. + */ + private static final int DEFAULT_ORDINAL = 200; + /** The root context, not null. */ private Context context; /** The scannable property, default is {@code false}. */ @@ -67,6 +79,7 @@ public class JNDIPropertySource extends BasePropertySource { */ public JNDIPropertySource() throws NamingException { this("jndi"); + setDefaultOrdinal(DEFAULT_ORDINAL); } /** @@ -80,10 +93,10 @@ public class JNDIPropertySource extends BasePropertySource { * @return a map representation of the JNDI tree. */ @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { if(scannable){ try { - return toMap(this.context); + return PropertyValue.map(toMap(this.context), getName()); } catch (NamingException e) { LOG.log(Level.WARNING, "Error scanning JNDI tree.", e); } @@ -122,6 +135,7 @@ public class JNDIPropertySource extends BasePropertySource { public String toString() { return "JNDIPropertySource{" + "name=" + getName() + + ", ordinal=" + getOrdinal() + ", context=" + context + '}'; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource ---------------------------------------------------------------------- diff --git a/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource new file mode 100644 index 0000000..b587cf7 --- /dev/null +++ b/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.jndi.JNDIPropertySource \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java index 00b3514..8d94966 100644 --- a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java +++ b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.jndi; +import org.apache.tamaya.spi.PropertyValue; import org.junit.Test; import javax.naming.Context; @@ -55,7 +56,7 @@ public class JNDIPropertySourceTest{ public void testScanContext() throws NamingException, MalformedURLException { JNDIPropertySource ps = new JNDIPropertySource("jndi-test", getTestDirContext(createFSContext())); assertFalse(ps.isScannable()); - Map<String,String> props = ps.getProperties(); + Map<String,PropertyValue> props = ps.getProperties(); assertNotNull(props); assertTrue(props.isEmpty()); ps.setScannable(true); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/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 fd5bb49..50a1b5f 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 @@ -89,24 +89,13 @@ implements MutablePropertySource{ @Override public PropertyValue get(String key) { - Map<String,String> properties = getProperties(); - String val = properties.get(key); - if(val==null){ - return null; - } - PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName()); - String metaKeyStart = "_" + key + "."; - for(Map.Entry<String,String> en:properties.entrySet()) { - if(en.getKey().startsWith(metaKeyStart)){ - b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue()); - } - } - return b.build(); + Map<String,PropertyValue> properties = getProperties(); + return properties.get(key); } @Override - public Map<String, String> getProperties() { - return Collections.unmodifiableMap(this.properties); + public Map<String, PropertyValue> getProperties() { + return PropertyValue.map(this.properties, getName()); } /** http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/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 e5aaea4..3d72d29 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 @@ -91,24 +91,16 @@ implements MutablePropertySource{ @Override public PropertyValue get(String key) { - Map<String,String> properties = getProperties(); - String val = properties.get(key); - if(val==null){ - return null; + String val = this.properties.get(key); + if(val!=null) { + return PropertyValue.of(key, val, getName()); } - PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName()); - String metaKeyStart = "_" + key + "."; - for(Map.Entry<String,String> en:properties.entrySet()) { - if(en.getKey().startsWith(metaKeyStart)){ - b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue()); - } - } - return b.build(); + return null; } @Override - public Map<String, String> getProperties() { - return Collections.unmodifiableMap(this.properties); + public Map<String, PropertyValue> getProperties() { + return PropertyValue.map(this.properties,getName()); } /**