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/07/21 23:50:42 UTC
[1/4] incubator-tamaya git commit: Minor additions on usage and
spelling.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 34ffd1906 -> 910c69fa5
Minor additions on usage and spelling.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/68c715fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/68c715fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/68c715fd
Branch: refs/heads/master
Commit: 68c715fd901764d1bfa6a058f940562d1ee7449c
Parents: 34ffd19
Author: anatole <at...@gmail.com>
Authored: Sun Jul 12 18:12:37 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Sun Jul 12 18:12:37 2015 +0200
----------------------------------------------------------------------
docs/src/main/asciidoc/index.adoc | 20 ++++++++++++++++++--
docs/src/main/asciidoc/mod_formats.adoc | 2 +-
2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/68c715fd/docs/src/main/asciidoc/index.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/index.adoc b/docs/src/main/asciidoc/index.adoc
index 5707fc5..be0ab69 100644
--- a/docs/src/main/asciidoc/index.adoc
+++ b/docs/src/main/asciidoc/index.adoc
@@ -97,6 +97,24 @@ Nevertheless there are a few things that are not part of Tamaya:
your enterprise context, such as supported file locations, formats, overriding and filter rules etc.
+[[WhatCanIDoEithTamaya]]
+=== And what can I do with Apache Tamaya?
+
+There are basically two main usage scenarios, which are synergetic:
+
+* In an enterprise context you can easily implement a configuration architecture for your whole company and deploy the
+ logic as an extension module. All application development teams in your company can then depend on this module (and the
+ basic Tamaya core implementation). As a result all applications/modules in your company follow the same configuration
+ policy, which makes it much more simpler to move people between your teams. Similarly additional tooling functionality
+ can help you to manage configuration on application as well as on enterprise level, e.g. providing command line or
+ REST support to access the supported configuration entries, types and values, configuration validation and more.
+* If you are writing an application, application component or library you can support configuration using Tamaya by
+ adding it as an optional dependency. If done so your users/customers can use Tamaya to connect their current enterprise
+ configuration infrastructure transparently to your code. As an example you can use Tamaya to read your default
+ configuration files, but since Tamaya is so easily extendable, customers can deploy an additional jar, which then
+ allows them to add their own configuration mechanisms such as databases, datagrids or REST services.
+
+
[[WorkingGroup]]
=== Working Group
This work is being conducted as part of a community lead joint effort under the Apache Software Foundation. This
@@ -191,5 +209,3 @@ Javadoc of the current Extension Modules
=== Examples
A comprehensive set of examples can be found link:../examples.html[here].
-
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/68c715fd/docs/src/main/asciidoc/mod_formats.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_formats.adoc b/docs/src/main/asciidoc/mod_formats.adoc
index 02c8868..984337b 100644
--- a/docs/src/main/asciidoc/mod_formats.adoc
+++ b/docs/src/main/asciidoc/mod_formats.adoc
@@ -208,7 +208,7 @@ Nevertheless from the +ConfigurationData+ instance a more complex algorithm can
==== Mapping xml-Files
-The same principal can also be applied to xml-files. Consider the following configuration file:
+The same concept can also be applied to xml-files. Consider the following configuration file:
[source,xml]
.Example.conf
[4/4] incubator-tamaya git commit: - Unified API for
ConfigurationContext. - Rendered all modules,
despite builder Java 7 compatible. -
Posted by an...@apache.org.
- Unified API for ConfigurationContext.
- Rendered all modules, despite builder Java 7 compatible.
-
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/910c69fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/910c69fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/910c69fa
Branch: refs/heads/master
Commit: 910c69fa5af33ae652b9753767af9a866f3dfb2b
Parents: d37a74d
Author: anatole <at...@gmail.com>
Authored: Tue Jul 21 23:50:03 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Tue Jul 21 23:50:03 2015 +0200
----------------------------------------------------------------------
.../apache/tamaya/spi/ConfigurationContext.java | 6 +
.../core/internal/DefaultConfiguration.java | 2 +-
.../internal/DefaultConfigurationContext.java | 7 ++
.../propertysource/SimplePropertySource.java | 46 +++++---
.../propertysource/SimplePropertySource.java | 11 ++
modules/events/pom.xml | 14 +--
.../org/apache/tamaya/events/ConfigEvent.java | 20 +++-
.../tamaya/events/FrozenConfiguration.java | 22 ++++
.../tamaya/events/FrozenPropertySource.java | 5 +
.../events/delta/ConfigurationChange.java | 34 +++++-
.../delta/ConfigurationChangeBuilder.java | 26 +++--
.../delta/ConfigurationContextChange.java | 56 ++++++++--
.../events/delta/PropertySourceChange.java | 32 +++++-
.../delta/PropertySourceChangeBuilder.java | 10 +-
.../ObservingPropertySourceProvider.java | 14 +--
.../events/internal/DefaultConfigEventSpi.java | 15 ++-
...faultConfigurationContextChangeListener.java | 21 ++--
.../tamaya/events/FrozenPropertySourceTest.java | 8 +-
.../apache/tamaya/events/TestConfigView.java | 36 +++++-
.../events/delta/ConfigurationChangeTest.java | 14 +--
.../events/delta/PropertySourceChangeTest.java | 41 ++++---
modules/formats/pom.xml | 9 +-
.../BaseFormatPropertySourceProvider.java | 8 +-
.../apache/tamaya/format/ConfigurationData.java | 15 ++-
.../tamaya/format/ConfigurationDataBuilder.java | 16 ++-
.../tamaya/format/ConfigurationFormats.java | 50 ++++++---
.../format/FlattenedDefaultPropertySource.java | 7 +-
.../tamaya/format/InputStreamFactory.java | 2 +-
.../format/formats/IniConfigurationFormat.java | 2 +-
.../tamaya/format/formats/PropertiesFormat.java | 2 +-
.../format/formats/PropertiesXmlFormat.java | 2 +-
modules/injection/pom.xml | 9 +-
.../apache/tamaya/inject/BaseDynamicValue.java | 41 +++++++
.../tamaya/inject/ConfigurationInjection.java | 42 +++++++
.../tamaya/inject/ConfigurationInjector.java | 13 ---
.../org/apache/tamaya/inject/DynamicValue.java | 61 ++--------
.../java/org/apache/tamaya/inject/Supplier.java | 41 +++++++
.../internal/ConfigChangeCallbackMethod.java | 27 +++--
.../tamaya/inject/internal/ConfiguredField.java | 18 ++-
.../inject/internal/ConfiguredSetterMethod.java | 17 +--
.../tamaya/inject/internal/ConfiguredType.java | 18 +--
.../internal/DefaultConfigurationInjector.java | 19 +++-
.../inject/internal/DefaultDynamicValue.java | 85 ++++++--------
.../tamaya/inject/internal/InjectionUtils.java | 4 +-
.../internal/PropertyChangeSetListener.java | 37 +++++++
.../internal/WeakConfigListenerManager.java | 21 ++--
.../java/annottext/AnnotatedConfigTemplate.java | 2 +-
.../tamaya/inject/TamayaInjectionTest.java | 8 +-
.../tamaya/inject/TestPropertySource.java | 5 +
.../internal/DefaultDynamicValueTest.java | 82 +++++++++-----
.../internal/WeakConfigListenerManagerTest.java | 24 +++-
modules/json/pom.xml | 9 +-
.../apache/tamaya/json/JSONPropertySource.java | 9 +-
.../org/apache/tamaya/json/JSONFormatIT.java | 14 ++-
modules/resolver/pom.xml | 8 +-
.../org/apache/tamaya/resolver/Resolver.java | 4 +-
.../internal/DefaultExpressionEvaluator.java | 22 +++-
.../internal/ExpressionResolutionFilter.java | 6 +-
.../tamaya/resolver/internal/FileResolver.java | 4 +-
.../resolver/internal/ResourceResolver.java | 7 +-
.../tamaya/resolver/MyTestPropertySource.java | 5 +
modules/resources/pom.xml | 6 +-
.../AbstractPathPropertySourceProvider.java | 32 +++++-
.../tamaya/resource/BaseResourceResolver.java | 111 +++++++++++++++++++
.../apache/tamaya/resource/ConfigResources.java | 10 +-
.../tamaya/resource/ResourceResolver.java | 17 +--
.../internal/DefaultResourceResolver.java | 12 +-
.../tamaya/resource/internal/FileCollector.java | 2 +-
.../tamaya/resource/internal/Locator.java | 8 +-
.../AbstractPathPropertySourceProviderTest.java | 85 ++++++++++++--
.../PathBasedPropertySourceProvider.java | 14 ++-
71 files changed, 1101 insertions(+), 411 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index 1ebfd8b..f0b7265 100644
--- a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -146,4 +146,10 @@ public interface ConfigurationContext {
* @return the {@link org.apache.tamaya.spi.PropertyValueCombinationPolicy} used, never null.
*/
PropertyValueCombinationPolicy getPropertyValueCombinationPolicy();
+
+ /**
+ * Creates a {@link ConfigurationContextBuilder} preinitialized with the data from this instance.
+ * @return a new builder instance, never null.
+ */
+ ConfigurationContextBuilder toBuilder();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 60d1307..61a3f34 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -165,7 +165,7 @@ public class DefaultConfiguration implements Configuration {
* @return the filtered map.
*/
private Map<String, String> applyFilters(Map<String, String> inputMap) {
- Map<String, String> resultMap = new HashMap<>();
+ Map<String, String> resultMap = new HashMap<>(inputMap);
// Apply filters to values, prevent values filtered to null!
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
AtomicInteger changes = new AtomicInteger();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
index 2cd2207..cdbff0c 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -18,8 +18,10 @@
*/
package org.apache.tamaya.core.internal;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
@@ -265,4 +267,9 @@ public class DefaultConfigurationContext implements ConfigurationContext {
return propertyValueCombinationPolicy;
}
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ return ConfigurationProvider.getConfigurationContextBuilder().setContext(this);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
index 8129189..3ae4f2d 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
@@ -32,29 +32,34 @@ import java.util.Properties;
/**
* Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for properties-files.
*/
-public class SimplePropertySource extends BasePropertySource{
- /** The property source name. */
+public class SimplePropertySource extends BasePropertySource {
+ /**
+ * The property source name.
+ */
private String name;
- /** The current properties. */
- private Map<String,String> properties;
+ /**
+ * The current properties.
+ */
+ private Map<String, String> properties;
/**
* Creates a new Properties based PropertySource based on the given URL.
+ *
* @param propertiesLocation the URL encoded location, not null.
*/
public SimplePropertySource(File propertiesLocation) {
super(0);
- try{
+ try {
this.properties = load(propertiesLocation.toURI().toURL());
this.name = propertiesLocation.toString();
- }
- catch(IOException e){
- throw new ConfigException("Failed to load properties from " + propertiesLocation,e);
+ } catch (IOException e) {
+ throw new ConfigException("Failed to load properties from " + propertiesLocation, e);
}
}
/**
* Creates a new Properties based PropertySource based on the given URL.
+ *
* @param propertiesLocation the URL encoded location, not null.
*/
public SimplePropertySource(URL propertiesLocation) {
@@ -64,8 +69,21 @@ public class SimplePropertySource extends BasePropertySource{
}
/**
+ * Creates a new Properties based PropertySource based on the given properties map.
+ *
+ * @param name the name, not null.
+ * @param properties the properties, not null.
+ */
+ public SimplePropertySource(String name, Map<String, String> properties) {
+ super(0);
+ this.properties = new HashMap<>(properties);
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
* Creates a new Properties based PropertySource based on the given URL.
- * @param name The property source name
+ *
+ * @param name The property source name
* @param propertiesLocation the URL encoded location, not null.
*/
public SimplePropertySource(String name, URL propertiesLocation) {
@@ -88,20 +106,18 @@ public class SimplePropertySource extends BasePropertySource{
* loads the Properties from the given URL
*
* @param propertiesFile {@link java.net.URL} to load Properties from
- *
* @return loaded {@link java.util.Properties}
- *
* @throws IllegalStateException in case of an error while reading properties-file
*/
- private Map<String,String> load(URL propertiesFile) {
- Map<String,String> properties = new HashMap<>();
+ private Map<String, String> load(URL propertiesFile) {
+ Map<String, String> properties = new HashMap<>();
try (InputStream stream = propertiesFile.openStream()) {
Properties props = new Properties();
if (stream != null) {
props.load(stream);
}
- for(String key:props.stringPropertyNames()){
- properties.put(key, props.getProperty(key));
+ for (String key : props.stringPropertyNames()) {
+ properties.put(key, props.getProperty(key));
}
} catch (IOException e) {
throw new ConfigException("Error loading properties " + propertiesFile, e);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
index 9853b30..72b2e92 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
@@ -71,6 +71,17 @@ public class SimplePropertySource implements PropertySource{
this.name = Objects.requireNonNull(name);
}
+ /**
+ * Creates a new Properties based PropertySource based on the given properties map.
+ *
+ * @param name the name, not null.
+ * @param properties the properties, not null.
+ */
+ public SimplePropertySource(String name, Map<String, String> properties) {
+ this.properties = new HashMap<>(properties);
+ this.name = Objects.requireNonNull(name);
+ }
+
@Override
public String getName() {
return name;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index 00c1876..e89069e 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -31,11 +31,16 @@ under the License.
<artifactId>tamaya-events</artifactId>
<name>Apache Tamaya Event and dynamic Update Extensions</name>
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-java7-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
@@ -43,13 +48,8 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-builder</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <artifactId>tamaya-java7-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
index 9b9b3f6..3ed2ba2 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.events;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.events.spi.ConfigEventSpi;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
/**
* Singleton accessor for accessing the event support component that distributes change events of
@@ -30,10 +30,8 @@ public final class ConfigEvent {
/**
* The backing SPI.
*/
- private static final ConfigEventSpi SPI = ServiceContext.getInstance()
- .getService(ConfigEventSpi.class)
- .orElseThrow(() -> new ConfigException("No SPI registered for " +
- ConfigEvent.class.getName()));
+ private static final ConfigEventSpi SPI = ServiceContextManager.getServiceContext()
+ .getService(ConfigEventSpi.class);
/**
* Private singleton constructor.
@@ -48,6 +46,10 @@ public final class ConfigEvent {
* @param l the listener not null.
*/
public static <T> void addListener(ConfigEventListener<T> l) {
+ if (SPI == null) {
+ throw new ConfigException("No SPI registered for " +
+ ConfigEvent.class.getName());
+ }
SPI.addListener(l);
}
@@ -58,6 +60,10 @@ public final class ConfigEvent {
* @param l the listener not null.
*/
public static <T> void removeListener(ConfigEventListener<T> l) {
+ if (SPI == null) {
+ throw new ConfigException("No SPI registered for " +
+ ConfigEvent.class.getName());
+ }
SPI.removeListener(l);
}
@@ -77,6 +83,10 @@ public final class ConfigEvent {
* @param eventType the event type, the vent may be a subclass.
*/
public static <T> void fireEvent(T event, Class<T> eventType) {
+ if (SPI == null) {
+ throw new ConfigException("No SPI registered for " +
+ ConfigEvent.class.getName());
+ }
SPI.fireEvent(event, eventType);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
index 58a1391..290e1a9 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
@@ -19,6 +19,8 @@
package org.apache.tamaya.events;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
@@ -68,6 +70,16 @@ public final class FrozenConfiguration implements Configuration, Serializable {
return new FrozenConfiguration(config);
}
+ @Override
+ public String get(String key) {
+ return this.properties.get(key);
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ return (T) get(key, TypeLiteral.of(type));
+ }
+
/**
* Accesses the current String value for the given key and tries to convert it
* using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
@@ -109,6 +121,16 @@ public final class FrozenConfiguration implements Configuration, Serializable {
}
@Override
+ public Configuration with(ConfigOperator operator) {
+ return operator.operate(this);
+ }
+
+ @Override
+ public <T> T query(ConfigQuery<T> query) {
+ return query.query(this);
+ }
+
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/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 2c6eddb..71f5294 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
@@ -91,6 +91,11 @@ public final class FrozenPropertySource implements PropertySource, Serializable
}
@Override
+ public boolean isScannable() {
+ return true;
+ }
+
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
index dffb835..5f26eaa 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
@@ -63,7 +63,9 @@ public final class ConfigurationChange implements Serializable{
*/
ConfigurationChange(ConfigurationChangeBuilder builder) {
this.configuration = FrozenConfiguration.of(builder.source);
- builder.delta.values().forEach((c) -> this.changes.put(c.getPropertyName(), c));
+ for(PropertyChangeEvent ev:builder.delta.values()){
+ this.changes.put(ev.getPropertyName(), ev);
+ }
if(builder.version!=null){
this.version = builder.version;
}
@@ -110,7 +112,14 @@ public final class ConfigurationChange implements Serializable{
* @return the number current removed entries.
*/
public int getRemovedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
+ int removedCount = 0;
+ for(PropertyChangeEvent ev:this.changes.values()){
+ if(ev.getNewValue() == null){
+ removedCount++;
+ }
+ }
+ return removedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
}
/**
@@ -118,8 +127,16 @@ public final class ConfigurationChange implements Serializable{
* @return the number current added entries.
*/
public int getAddedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null &&
- e.getNewValue() != null).count();
+ int addedCount = 0;
+ for(PropertyChangeEvent ev:this.changes.values()){
+ if(ev.getOldValue() == null &&
+ ev.getNewValue() != null){
+ addedCount++;
+ }
+ }
+ return addedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null &&
+// e.getNewValue() != null).count();
}
/**
@@ -127,7 +144,14 @@ public final class ConfigurationChange implements Serializable{
* @return the number current updated entries.
*/
public int getUpdatedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
+ int updatedCount = 0;
+ for(PropertyChangeEvent ev:this.changes.values()){
+ if( ev.getOldValue()!=null && ev.getNewValue()!=null){
+ updatedCount++;
+ }
+ }
+ return updatedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
index a6d0bf6..ff5e26b 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
@@ -33,12 +33,12 @@ import java.util.TreeMap;
* Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
* can observing changes to property sources and
* <ol>
- * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
- * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
- * change, its only the data of the property source).</li>
- * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
- * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
- * event on configuration level.
+ * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
+ * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
+ * change, its only the data of the property source).</li>
+ * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
+ * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
+ * event on configuration level.
* </ol>
*/
public final class ConfigurationChangeBuilder {
@@ -135,13 +135,16 @@ public final class ConfigurationChangeBuilder {
* @return the builder for chaining.
*/
public ConfigurationChangeBuilder addChanges(Configuration newState) {
- compare(newState, this.source).forEach((c) -> this.delta.put(c.getPropertyName(), c));
+ for (PropertyChangeEvent c : compare(newState, this.source)) {
+ this.delta.put(c.getPropertyName(), c);
+ }
return this;
}
/**
* Applies a single key/value change.
- * @param key the changed key
+ *
+ * @param key the changed key
* @param value the new value.
* @return this instance for chining.
*/
@@ -211,8 +214,11 @@ public final class ConfigurationChangeBuilder {
*/
public ConfigurationChangeBuilder removeAllKeys() {
this.delta.clear();
- this.source.getProperties().forEach((k, v) ->
- this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
+ for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
+ this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
+ }
+// this.source.getProperties().forEach((k, v) ->
+// this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
index 2ebc3ef..2378418 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
@@ -26,7 +26,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
-import java.util.stream.Collectors;
/**
* Event that contains a set current changes that were applied or could be applied.
@@ -97,8 +96,15 @@ public final class ConfigurationContextChange implements Serializable{
* @return the recorded changes, never null.
*/
public Collection<PropertySourceChange> getPropertySourceUpdates(){
- return Collections.unmodifiableCollection(this.changedPropertySources).stream()
- .filter(pc -> pc.getChangeType()==ChangeType.UPDATED).collect(Collectors.toList());
+ List<PropertySourceChange> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.UPDATED) {
+ result.add(pc);
+ }
+ }
+ return result;
+// return Collections.unmodifiableCollection(this.changedPropertySources).stream()
+// .filter(pc -> pc.getChangeType()==ChangeType.UPDATED).collect(Collectors.toList());
}
/**
@@ -106,8 +112,15 @@ public final class ConfigurationContextChange implements Serializable{
* @return the recorded changes, never null.
*/
public Collection<PropertySource> getRemovedPropertySources(){
- return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.DELETED).
- map(ps -> ps.getPropertySource()).collect(Collectors.toList());
+ List<PropertySource> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.DELETED) {
+ result.add(pc.getPropertySource());
+ }
+ }
+ return result;
+// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.DELETED).
+// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
}
/**
@@ -115,8 +128,15 @@ public final class ConfigurationContextChange implements Serializable{
* @return the recorded changes, never null.
*/
public Collection<PropertySource> getAddedPropertySources(){
- return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.NEW).
- map(ps -> ps.getPropertySource()).collect(Collectors.toList());
+ List<PropertySource> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.NEW) {
+ result.add(pc.getPropertySource());
+ }
+ }
+ return result;
+// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.NEW).
+// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
}
/**
@@ -124,8 +144,15 @@ public final class ConfigurationContextChange implements Serializable{
* @return the recorded changes, never null.
*/
public Collection<PropertySource> getUpdatedPropertySources(){
- return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.UPDATED).
- map(ps -> ps.getPropertySource()).collect(Collectors.toList());
+ List<PropertySource> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.UPDATED) {
+ result.add(pc.getPropertySource());
+ }
+ }
+ return result;
+// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.UPDATED).
+// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
}
/**
@@ -134,8 +161,15 @@ public final class ConfigurationContextChange implements Serializable{
* @return true, if the given propertySource ia affected.
*/
public boolean isAffected(PropertySource propertySource) {
- return this.changedPropertySources.stream().filter(ps -> ps.getPropertySource()==propertySource ||
- ps.getPropertySource().getName().equals(propertySource.getName())).findAny().isPresent();
+ for (PropertySourceChange ps : this.changedPropertySources) {
+ if (ps.getPropertySource() == propertySource ||
+ ps.getPropertySource().getName().equals(propertySource.getName())) {
+ return true;
+ }
+ }
+ return false;
+// return this.changedPropertySources.stream().filter(ps -> ps.getPropertySource()==propertySource ||
+// ps.getPropertySource().getName().equals(propertySource.getName())).findAny().isPresent();
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
index 89554ee..4e9acda 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
@@ -56,7 +56,9 @@ public final class PropertySourceChange implements Serializable{
*/
PropertySourceChange(PropertySourceChangeBuilder builder) {
this.propertySource = FrozenPropertySource.of(builder.source);
- builder.delta.values().forEach((c) -> this.changes.put(c.getPropertyName(), c));
+ for (PropertyChangeEvent c : builder.delta.values()) {
+ this.changes.put(c.getPropertyName(), c);
+ }
if(builder.version!=null){
this.version = builder.version;
}
@@ -112,7 +114,14 @@ public final class PropertySourceChange implements Serializable{
* @return the number current removed entries.
*/
public int getRemovedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
+ int removedCount = 0;
+ for (PropertyChangeEvent ev : this.changes.values()) {
+ if (ev.getNewValue() == null) {
+ removedCount++;
+ }
+ }
+ return removedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
}
/**
@@ -120,7 +129,15 @@ public final class PropertySourceChange implements Serializable{
* @return the number current added entries.
*/
public int getAddedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
+ int addedCount = 0;
+ for (PropertyChangeEvent ev : this.changes.values()) {
+ if (ev.getOldValue() == null &&
+ ev.getNewValue() != null) {
+ addedCount++;
+ }
+ }
+ return addedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
}
/**
@@ -128,7 +145,14 @@ public final class PropertySourceChange implements Serializable{
* @return the number current updated entries.
*/
public int getUpdatedSize() {
- return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
+ int updatedCount = 0;
+ for (PropertyChangeEvent ev : this.changes.values()) {
+ if (ev.getOldValue() != null && ev.getNewValue() != null) {
+ updatedCount++;
+ }
+ }
+ return updatedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
index b03e570..a0c0027 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
@@ -139,7 +139,10 @@ public final class PropertySourceChangeBuilder {
* @return the builder for chaining.
*/
public PropertySourceChangeBuilder addChanges(PropertySource newState) {
- compare(newState, this.source).forEach((c) -> this.delta.put(c.getPropertyName(), c));
+ Collection<PropertyChangeEvent> events = PropertySourceChangeBuilder.compare(newState, this.source);
+ for (PropertyChangeEvent c : events) {
+ this.delta.put(c.getPropertyName(), c);
+ }
return this;
}
@@ -204,8 +207,9 @@ public final class PropertySourceChangeBuilder {
*/
public PropertySourceChangeBuilder deleteAll() {
this.delta.clear();
- this.source.getProperties().forEach((k, v) ->
- this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
+ for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
+ this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
+ }
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 55176aa..86f68b9 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -63,7 +63,7 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
/**
* The current active property sources of this provider.
*/
- private final List<PropertySource> propertySources = Collections.synchronizedList(new LinkedList<>());
+ private final List<PropertySource> propertySources = Collections.synchronizedList(new LinkedList<PropertySource>());
/**
* The supported configuration formats of this provider.
*/
@@ -120,7 +120,7 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
return result;
}
} catch (IOException e) {
- LOG.log(Level.WARNING, e, () -> "Failed to read configuration from dir: " + directory);
+ LOG.log(Level.WARNING, "Failed to read configuration from dir: " + directory, e);
}
return result;
}
@@ -147,19 +147,19 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
}
}
} catch (IOException e) {
- LOG.log(Level.INFO, e, () -> "Error reading file: " + file.toString() +
- ", using format: " + format);
+ LOG.log(Level.INFO, "Error reading file: " + file.toString() +
+ ", using format: " + format, e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ioe) {
- LOG.log(Level.SEVERE, ioe, () -> "Failed to rea data...");
+ LOG.log(Level.SEVERE, "Failed to rea data...", ioe);
}
}
}
}
- LOG.warning(() -> "Error reading file: " + file.toString());
+ LOG.warning("Error reading file: " + file.toString());
return null;
}
@@ -211,7 +211,7 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
b.newPropertySource(ps);
}
ConfigurationContextChange changeEvent = b.build();
- LOG.fine(() -> "Trigger Config Context Change: " + changeEvent);
+ LOG.fine("Trigger Config Context Change: " + changeEvent);
ConfigEvent.fireEvent(changeEvent);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventSpi.java
index 8be785e..0032c4d 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventSpi.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.events.internal;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.events.ConfigEventListener;
import org.apache.tamaya.events.spi.ConfigEventSpi;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -48,23 +48,26 @@ public class DefaultConfigEventSpi implements ConfigEventSpi {
*/
public DefaultConfigEventSpi() {
try {
- for (ConfigEventListener<?> l : ServiceContext.getInstance().getServices(ConfigEventListener.class)) {
+ for (ConfigEventListener<?> l : ServiceContextManager.getServiceContext().getServices(ConfigEventListener.class)) {
try {
addListener(l);
} catch (Exception e) {
- LOG.log(Level.WARNING, e, () -> "Failed to load configured listener: " + l.getClass().getName());
+ LOG.log(Level.WARNING, "Failed to load configured listener: " + l.getClass().getName(), e);
}
}
} catch (Exception e) {
- LOG.log(Level.WARNING, e, () -> "Failed to load configured listeners.");
+ LOG.log(Level.WARNING, "Failed to load configured listeners.", e);
}
}
@Override
public <T> void addListener(ConfigEventListener<T> l) {
Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), ConfigEventListener.class)[0];
- List<ConfigEventListener> listeners = listenerMap.computeIfAbsent(type,
- (k) -> Collections.synchronizedList(new ArrayList<>()));
+ List<ConfigEventListener> listeners = listenerMap.get(type);
+ if (listeners == null) {
+ listeners = Collections.synchronizedList(new ArrayList<ConfigEventListener>());
+ listenerMap.put(type, listeners);
+ }
synchronized (listeners) {
if (!listeners.contains(l)) {
listeners.add(l);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
index 2b0f633..fed5e40 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
@@ -25,10 +25,9 @@ import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.PropertySource;
-import java.util.Collection;
+import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
* Default ConfigEventListener for ConfigurationContextChange events that updates the current context, if resources were
@@ -41,12 +40,20 @@ public class DefaultConfigurationContextChangeListener implements ConfigEventLis
@Override
public void onConfigEvent(ConfigurationContextChange event) {
ConfigurationContext context = ConfigurationProvider.getConfigurationContext();
- Collection<PropertySource> affectedPropertySources = context.getPropertySources(ps ->
- event.isAffected(ps));
- ConfigurationContextBuilder newContextBuilder = context.toBuilder();
+ List<PropertySource> affectedPropertySources = new ArrayList<>();
+ for (PropertySource ps : context.getPropertySources()) {
+ if (event.isAffected(ps)) {
+ affectedPropertySources.add(ps);
+ }
+ }
+ ConfigurationContextBuilder newContextBuilder = ConfigurationProvider.getConfigurationContextBuilder()
+ .setContext(context);
if (!affectedPropertySources.isEmpty()) {
- newContextBuilder.removePropertySources(event.getRemovedPropertySources().stream()
- .map(ps -> ps.getName()).collect(Collectors.toSet()));
+ Set<String> propertySourceNames = new HashSet<>();
+ for (PropertySource removed : event.getRemovedPropertySources()) {
+ propertySourceNames.add(removed.getName());
+ }
+ newContextBuilder.removePropertySources(propertySourceNames);
}
newContextBuilder.addPropertySources(event.getAddedPropertySources());
newContextBuilder.addPropertySources(event.getUpdatedPropertySources());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/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 40d3335..ed7a20e 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
@@ -22,6 +22,8 @@ import org.apache.tamaya.core.propertysource.SystemPropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
+import java.util.Map;
+
import static org.junit.Assert.*;
/**
@@ -55,9 +57,9 @@ public class FrozenPropertySourceTest {
public void testGet() throws Exception {
PropertySource ps = FrozenPropertySource.of(myPS);
assertNotNull(ps);
- myPS.getProperties().entrySet().forEach(
- e -> assertEquals(ps.get(e.getKey()), e.getValue())
- );
+ for (Map.Entry<String, String> e : myPS.getProperties().entrySet()) {
+ assertEquals(ps.get(e.getKey()), e.getValue());
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
index ab6135d..6ee5397 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
@@ -20,11 +20,13 @@ package org.apache.tamaya.events;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.PropertyConverter;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@@ -45,13 +47,41 @@ public class TestConfigView implements ConfigOperator{
}
@Override
- public Configuration operate(Configuration config) {
+ public Configuration operate(final Configuration config) {
return new Configuration() {
@Override
public Map<String, String> getProperties() {
- return config.getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("test")).collect(
- Collectors.toMap(en -> en.getKey(), en -> en.getValue()));
+ Map<String, String> result = new HashMap<>();
+ for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
+ if (en.getKey().startsWith("test")) {
+ result.put(en.getKey(), en.getValue());
+ }
+ }
+ return result;
+// return config.getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("test")).collect(
+// Collectors.toMap(en -> en.getKey(), en -> en.getValue()));
}
+
+ @Override
+ public Configuration with(ConfigOperator operator) {
+ return null;
+ }
+
+ @Override
+ public <T> T query(ConfigQuery<T> query) {
+ return null;
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ return (T) get(key, TypeLiteral.of(type));
+ }
+
/**
* Accesses the current String value for the given key and tries to convert it
* using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
index 0d668c5..7d44b92 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
@@ -22,6 +22,8 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.junit.Test;
+import java.util.Map;
+
import static org.junit.Assert.*;
/**
@@ -42,13 +44,11 @@ public class ConfigurationChangeTest {
ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
assertNotNull(change);
assertTrue(change.isEmpty());
- config.getProperties().entrySet().forEach(
- en -> {
- if (!"[meta]frozenAt".equals(en.getKey())) {
- assertEquals("Error for " + en.getKey(), en.getValue(), change.getConfiguration().get(en.getKey()));
- }
- }
- );
+ for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
+ if (!"[meta]frozenAt".equals(en.getKey())) {
+ assertEquals("Error for " + en.getKey(), en.getValue(), change.getConfiguration().get(en.getKey()));
+ }
+ }
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
index 770bd5d..2b44543 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
@@ -18,12 +18,15 @@
*/
package org.apache.tamaya.events.delta;
-import org.apache.tamaya.builder.PropertySourceBuilder;
import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.core.propertysource.SimplePropertySource;
import org.apache.tamaya.core.propertysource.SystemPropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
+
import static org.junit.Assert.*;
/**
@@ -99,10 +102,14 @@ public class PropertySourceChangeTest {
@Test
public void testIsRemoved() throws Exception {
- PropertySource ps1 = PropertySourceBuilder.of("test").put("key1", "value1")
- .put("key2", "value2").build();
- PropertySource ps2 = PropertySourceBuilder.of("test").put("key1", "value2")
- .put("key3", "value3").build();
+ Map<String, String> testData = new HashMap<>();
+ testData.put("key1", "value1");
+ testData.put("key2", "value2");
+ PropertySource ps1 = new SimplePropertySource("test", testData);
+ testData = new HashMap<>();
+ testData.put("key1", "value2");
+ testData.put("key3", "value3");
+ PropertySource ps2 = new SimplePropertySource("test", testData);
PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
.addChanges(
ps2
@@ -114,10 +121,14 @@ public class PropertySourceChangeTest {
@Test
public void testIsAdded() throws Exception {
- PropertySource ps1 = PropertySourceBuilder.of("test").put("key1", "value1")
- .put("key2", "value2").build();
- PropertySource ps2 = PropertySourceBuilder.of("test").put("key1", "value2")
- .put("key3", "value3").build();
+ Map<String, String> testData = new HashMap<>();
+ testData.put("key1", "value1");
+ testData.put("key2", "value2");
+ PropertySource ps1 = new SimplePropertySource("test", testData);
+ testData = new HashMap<>();
+ testData.put("key1", "value2");
+ testData.put("key3", "value3");
+ PropertySource ps2 = new SimplePropertySource("test", testData);
PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
.addChanges(
ps2
@@ -129,10 +140,14 @@ public class PropertySourceChangeTest {
@Test
public void testIsUpdated() throws Exception {
- PropertySource ps1 = PropertySourceBuilder.of("test").put("key1", "value1")
- .put("key2", "value2").build();
- PropertySource ps2 = PropertySourceBuilder.of("test").put("key1", "value2")
- .put("key3", "value3").build();
+ Map<String, String> testData = new HashMap<>();
+ testData.put("key1", "value1");
+ testData.put("key2", "value2");
+ PropertySource ps1 = new SimplePropertySource("test", testData);
+ testData = new HashMap<>();
+ testData.put("key1", "value2");
+ testData.put("key3", "value3");
+ PropertySource ps2 = new SimplePropertySource("test", testData);
PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED)
.addChanges(
ps2
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/pom.xml
----------------------------------------------------------------------
diff --git a/modules/formats/pom.xml b/modules/formats/pom.xml
index e7377fa..6d0c1fa 100644
--- a/modules/formats/pom.xml
+++ b/modules/formats/pom.xml
@@ -29,11 +29,16 @@ under the License.
<artifactId>tamaya-formats</artifactId>
<name>Apache Tamaya Format Services</name>
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-java7-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
@@ -43,7 +48,7 @@ under the License.
<!-- Test scope only, do not create a code dependency! -->
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <artifactId>tamaya-java7-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java b/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
index 55f8a8d..6b5fd27 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
@@ -90,7 +90,7 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource
try {
urls = cl.getResources(path);
} catch (IOException e) {
- LOG.log(Level.WARNING, e, () -> "Failed to read resource: " + path);
+ LOG.log(Level.WARNING, "Failed to read resource: " + path, e);
continue;
}
while(urls.hasMoreElements()) {
@@ -115,7 +115,7 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource
try {
urls = classLoader.getResources(path);
} catch (IOException e) {
- LOG.log(Level.WARNING, e, () -> "Failed to read resource: " + path);
+ LOG.log(Level.WARNING, "Failed to read resource: " + path, e);
continue;
}
while(urls.hasMoreElements()) {
@@ -143,7 +143,7 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource
@Override
public Collection<PropertySource> getPropertySources() {
List<PropertySource> propertySources = new ArrayList<>();
- this.paths.forEach(res -> {
+ for (URL res : this.paths) {
try(InputStream is = res.openStream()) {
for (ConfigurationFormat format : configFormats) {
ConfigurationData data = format.readConfiguration(res.toString(), is);
@@ -152,7 +152,7 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to put resource based config: " + res, e);
}
- });
+ }
return propertySources;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
index 628b6bd..6735709 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationData.java
@@ -125,7 +125,10 @@ public final class ConfigurationData {
* @return the default section's data, or null, if no such section exists.
*/
public Map<String, String> getDefaultProperties() {
- return Optional.ofNullable(defaultProperties).orElse(Collections.emptyMap());
+ if (defaultProperties == null) {
+ return Collections.emptyMap();
+ }
+ return defaultProperties;
}
/**
@@ -134,7 +137,10 @@ public final class ConfigurationData {
* @return the normalized properties.
*/
public Map<String, String> getCombinedProperties() {
- return Optional.ofNullable(combinedProperties).orElse(Collections.emptyMap());
+ if (combinedProperties == null) {
+ return Collections.emptyMap();
+ }
+ return combinedProperties;
}
/**
@@ -143,7 +149,10 @@ public final class ConfigurationData {
* @return the data contained, never null.
*/
public Map<String, Map<String, String>> getSections() {
- return Optional.ofNullable(namedSections).orElse(Collections.emptyMap());
+ if (namedSections == null) {
+ return Collections.emptyMap();
+ }
+ return namedSections;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
index 45645e0..ddb03c6 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationDataBuilder.java
@@ -87,7 +87,9 @@ public final class ConfigurationDataBuilder {
*/
public ConfigurationDataBuilder addSections(String... sections){
for (String section : sections) {
- getSections().computeIfAbsent(section, (k) -> new HashMap<>());
+ if (!getSections().containsKey(section)) {
+ getSections().put(section, new HashMap<String, String>());
+ }
}
return this;
}
@@ -100,7 +102,11 @@ public final class ConfigurationDataBuilder {
* @return the builder for chaining.
*/
public ConfigurationDataBuilder addSectionProperty(String section, String key, String value) {
- Map<String, String> map = getSections().computeIfAbsent(section, (k) -> new HashMap<>());
+ Map<String, String> map = getSections().get(section);
+ if (map == null) {
+ map = new HashMap<String, String>();
+ getSections().put(section, map);
+ }
map.put(key, value);
return this;
}
@@ -123,7 +129,11 @@ public final class ConfigurationDataBuilder {
* @return the builder for chaining.
*/
public ConfigurationDataBuilder addSectionProperties(String section, Map<String, String> properties) {
- Map<String, String> map = getSections().computeIfAbsent(section, (k) -> new HashMap<>());
+ Map<String, String> map = getSections().get(section);
+ if (map == null) {
+ map = new HashMap<String, String>();
+ getSections().put(section, map);
+ }
map.putAll(properties);
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
index 948e8f1..f4117e3 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.format;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import java.io.IOException;
import java.io.InputStream;
@@ -30,10 +30,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
-import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
* Small accessor and management class dealing with {@link org.apache.tamaya.format.ConfigurationFormat}
@@ -57,7 +55,7 @@ public final class ConfigurationFormats {
* @return the currently available formats, never null.
*/
public static List<ConfigurationFormat> getFormats() {
- return ServiceContext.getInstance().getServices(ConfigurationFormat.class);
+ return ServiceContextManager.getServiceContext().getServices(ConfigurationFormat.class);
}
/**
@@ -66,19 +64,31 @@ public final class ConfigurationFormats {
* @return the currently available formats, never null.
*/
public static List<ConfigurationFormat> getFormats(String... formatNames) {
+ List<ConfigurationFormat> result = new ArrayList<>();
Set<String> names = new HashSet<>(Arrays.asList(formatNames));
- return getFormats(names::contains);
+ for (ConfigurationFormat f : getFormats()) {
+ if (names.contains(f.getName())) {
+ result.add(f);
+ }
+ }
+ return result;
}
- /**
- * Get all currently available formats, ordered by priority.
- *
- * @return the currently available formats, never null.
- */
- public static List<ConfigurationFormat> getFormats(Predicate<String> namePredicate) {
- return getFormats().stream().filter(f -> namePredicate.test(f.getName()))
- .collect(Collectors.toList());
- }
+ // Activate for JDK 8...
+// /**
+// * Get all currently available formats, ordered by priority.
+// *
+// * @return the currently available formats, never null.
+// */
+// public static List<ConfigurationFormat> getFormats(Predicate<String> namePredicate) {
+// List<ConfigurationFormat> result = new ArrayList<>();
+// for(ConfigurationFormat f:getFormats()){
+// if(namePredicate.test(f.getName()){
+// result.add(f);
+// }
+// }
+// return result;
+// }
/**
* Get all currently available formats, ordered by priority.
@@ -87,7 +97,13 @@ public final class ConfigurationFormats {
*/
public static List<ConfigurationFormat> getFormats(URL url) {
List<ConfigurationFormat> formats = getFormats();
- return formats.stream().filter(f -> f.accepts(url)).collect(Collectors.toList());
+ List<ConfigurationFormat> result = new ArrayList<>();
+ for (ConfigurationFormat f : formats) {
+ if (f.accepts(url)) {
+ result.add(f);
+ }
+ }
+ return result;
}
/**
@@ -158,8 +174,8 @@ public final class ConfigurationFormats {
return data;
}
} catch (Exception e) {
- LOG.log(Level.INFO, e,
- () -> "Format " + format.getClass().getName() + " failed to read resource " + resource);
+ LOG.log(Level.INFO,
+ "Format " + format.getClass().getName() + " failed to read resource " + resource, e);
}
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
index 7735b81..1eaec9e 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
@@ -94,7 +94,7 @@ public class FlattenedDefaultPropertySource implements PropertySource {
try {
return Integer.parseInt(ordinalValue.trim());
} catch (Exception e) {
- LOG.log(Level.WARNING, e, () -> "Failed to parse Tamaya ordinal from " + data.getResource());
+ LOG.log(Level.WARNING, "Failed to parse Tamaya ordinal from " + data.getResource(), e);
}
}
return defaultOrdinal;
@@ -109,4 +109,9 @@ public class FlattenedDefaultPropertySource implements PropertySource {
public Map<String, String> getProperties() {
return properties;
}
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java b/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
index 255f0cc..89ec45b 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/InputStreamFactory.java
@@ -63,7 +63,7 @@ public class InputStreamFactory implements Closeable {
try {
original.close();
} catch (IOException e) {
- LOG.log(Level.FINEST, e, () -> "Error closing stream: " + original);
+ LOG.log(Level.FINEST, "Error closing stream: " + original, e);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
index 4b4c75b..fe27ba7 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/IniConfigurationFormat.java
@@ -88,7 +88,7 @@ public class IniConfigurationFormat implements ConfigurationFormat {
}
return builder.build();
} catch (Exception e) {
- LOG.log(Level.SEVERE, e, () -> "Could not read configuration: " + resource);
+ LOG.log(Level.SEVERE, "Could not read configuration: " + resource, e);
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
index d69f623..35cef77 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesFormat.java
@@ -64,7 +64,7 @@ public class PropertiesFormat implements ConfigurationFormat {
p.load(inputStream);
return ConfigurationDataBuilder.of(resource, this).addProperties(Map.class.cast(p)).build();
} catch (Exception e) {
- LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
+ LOG.log(Level.FINEST, "Failed to read config from resource: " + resource, e);
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
index 44731d8..c47b6f6 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/formats/PropertiesXmlFormat.java
@@ -62,7 +62,7 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
p.loadFromXML(inputStream);
return ConfigurationDataBuilder.of(resource, this).addProperties(Map.class.cast(p)).build();
} catch (Exception e) {
- LOG.log(Level.FINEST, e, () -> "Failed to read config from resource: " + resource);
+ LOG.log(Level.FINEST, "Failed to read config from resource: " + resource, e);
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml
index ede0432..68f9fb2 100644
--- a/modules/injection/pom.xml
+++ b/modules/injection/pom.xml
@@ -30,15 +30,20 @@ under the License.
<name>Apache Tamaya Injection Support</name>
<packaging>jar</packaging>
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-java7-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <artifactId>tamaya-java7-core</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java
new file mode 100644
index 0000000..c905ad2
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java
@@ -0,0 +1,41 @@
+/*
+ * 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 of 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.
+ */
+package org.apache.tamaya.inject;
+
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
+ * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the value.<br/>
+ * Types of this interface can be used as injection targets in injected beans or as template resiult on configuration
+ * templates.
+ * <h3>Implementation Specification</h3>
+ * Implementation of this interface must be
+ * <ul>
+ * <li>Serializable, when also the item stored is serializable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ *
+ * @param <T> The type of the value.
+ */
+public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
new file mode 100644
index 0000000..79d6218
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
@@ -0,0 +1,42 @@
+/*
+ * 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 of 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.
+ */
+package org.apache.tamaya.inject;
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Singleton accessor class for accessing {@link ConfigurationInjector} instances.
+ */
+public final class ConfigurationInjection {
+
+ /**
+ * Singleton constructor.
+ */
+ private ConfigurationInjection() {
+ }
+
+ /**
+ * Get the current injector instance.
+ *
+ * @return the current injector, not null.
+ */
+ public static ConfigurationInjector getConfigurationInjector() {
+ return ServiceContextManager.getServiceContext().getService(ConfigurationInjector.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
index 33c5227..0ac4509 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
@@ -18,10 +18,6 @@
*/
package org.apache.tamaya.inject;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.function.Supplier;
-
/**
* Accessor interface for injection of configuration and configuration templates.
@@ -53,13 +49,4 @@ public interface ConfigurationInjector {
*/
<T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier);
- /**
- * Get the current injector instance.
- *
- * @return the current injector, not null.
- */
- public static ConfigurationInjector getInstance() {
- return ServiceContext.getInstance().getService(ConfigurationInjector.class).get();
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
index 1979b55..b4e671c 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
@@ -18,10 +18,8 @@
*/
package org.apache.tamaya.inject;
-import java.beans.PropertyChangeEvent;
-import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
+import java.beans.PropertyChangeListener;
+
/**
* A accessor for a single configured value. This can be used to support values that may change during runtime,
@@ -68,10 +66,7 @@ public interface DynamicValue<T> {
*
* @see DynamicValue#isPresent()
*/
- default T commitAndGet(){
- commit();
- return get();
- }
+ T commitAndGet();
/**
* Commits a new value that has not been committed yet, make it the new value of the instance. On change any
@@ -94,13 +89,13 @@ public interface DynamicValue<T> {
* Add a listener to be called as weak reference, when this value has been changed.
* @param l the listener, not null
*/
- void addListener(Consumer<PropertyChangeEvent> l);
+ void addListener(PropertyChangeListener l);
/**
* Removes a listener to be called, when this value has been changed.
* @param l the listner to be removed, not null
*/
- void removeListener(Consumer<PropertyChangeEvent> l);
+ void removeListener(PropertyChangeListener l);
/**
* If a value is present in this {@code DynamicValue}, returns the value,
@@ -147,32 +142,13 @@ public interface DynamicValue<T> {
boolean isPresent();
/**
- * If a value is present, invoke the specified consumer with the value,
- * otherwise do nothing.
- *
- * @param consumer block to be executed if a value is present
- * @throws NullPointerException if value is present and {@code consumer} is
- * null
- */
- default void ifPresent(Consumer<? super T> consumer){
- if(isPresent()){
- consumer.accept(get());
- }
- }
-
- /**
* Return the value if present, otherwise return {@code other}.
*
* @param other the value to be returned if there is no value present, may
* be null
* @return the value, if present, otherwise {@code other}
*/
- default T orElse(T other){
- if(isPresent()){
- return get();
- }
- return other;
- }
+ T orElse(T other);
/**
* Return the value if present, otherwise invoke {@code other} and return
@@ -184,12 +160,7 @@ public interface DynamicValue<T> {
* @throws NullPointerException if value is not present and {@code other} is
* null
*/
- default T orElseGet(Supplier<? extends T> other){
- if(isPresent()){
- return get();
- }
- return other.get();
- }
+ T orElseGet(Supplier<? extends T> other);
/**
* Return the contained value, if present, otherwise throw an exception
@@ -207,22 +178,6 @@ public interface DynamicValue<T> {
* @throws NullPointerException if no value is present and
* {@code exceptionSupplier} is null
*/
- default <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X{
- if(isPresent()){
- return get();
- }
- throw exceptionSupplier.get();
- }
-
- /**
- * Converts the instance to an {@link java.util.Optional} instance.
- * @return the corresponding Optional value.
- */
- default Optional<T> toOptional(){
- if(isPresent()){
- return Optional.of(get());
- }
- return Optional.empty();
- }
+ <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/Supplier.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/Supplier.java b/modules/injection/src/main/java/org/apache/tamaya/inject/Supplier.java
new file mode 100644
index 0000000..b494d97
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/Supplier.java
@@ -0,0 +1,41 @@
+/*
+ * 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 of 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.
+ */
+package org.apache.tamaya.inject;
+
+/**
+ * Represents a supplier of results.
+ * <p>
+ * <p>There is no requirement that a new or distinct result be returned each
+ * time the supplier is invoked.
+ * <p>
+ * <p>This is a functional interface,
+ * whose functional method is {@link #get()}.
+ *
+ * @param <T> the type of results supplied by this supplier
+ */
+//@FunctionalInterface
+public interface Supplier<T> {
+
+ /**
+ * Gets a result.
+ *
+ * @return a result
+ */
+ T get();
+}
\ No newline at end of file
[2/4] incubator-tamaya git commit: Added infos on usage.
Posted by an...@apache.org.
Added infos on usage.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d37a74d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d37a74d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d37a74d5
Branch: refs/heads/master
Commit: d37a74d5e112e837edd89dd80b7173ee789ae29e
Parents: 68c715f
Author: anatole <at...@gmail.com>
Authored: Sun Jul 12 18:13:10 2015 +0200
Committer: anatole <at...@gmail.com>
Committed: Sun Jul 12 18:13:10 2015 +0200
----------------------------------------------------------------------
README.md | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d37a74d5/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 33a6aa2..897c656 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,21 @@
# Apache Tamaya (incubating)
-Tamaya is a very powerful yet flexible configuration solution. It's core is built based on a few simple concepts. More information on Tamaya can be found
-on the [homepage of Apache Tamaya](http://tamaya.incubator.apache.org/).
+Tamaya is a very powerful yet flexible configuration solution. It's core is built based on a few simple concepts.
+There are at least two main usage scenarios for Tamaya, which are synergetic:
+
+- In an enterprise context you can easily implement a configuration architecture for your whole company and deploy the
+ logic as an extension module. All application development teams in your company can then depend on this module (and the
+ basic Tamaya core implementation). As a result all applications/modules in your company follow the same configuration
+ policy, which makes it much more simpler to move people between your teams. Similarly additional tooling functionality
+ can help you to manage configuration on application as well as on enterprise level, e.g. providing command line or
+ REST support to access the supported configuration entries, types and values, configuration validation and more.
+- If you are writing an application, application component or library you can support configuration using Tamaya by
+ adding it as an optional dependency. If done so your users/customers can use Tamaya to connect their current enterprise
+ configuration infrastructure transparently to your code. As an example you can use Tamaya to read your default
+ configuration files, but since Tamaya is so easily extendable, customers can deploy an additional jar, which then
+ allows them to add their own configuration mechanisms such as databases, datagrids or REST services.
+
+More information on Tamaya can be found on the [homepage of Apache Tamaya](http://tamaya.incubator.apache.org/).
## Building Apache Tamaya
[3/4] incubator-tamaya git commit: - Unified API for
ConfigurationContext. - Rendered all modules,
despite builder Java 7 compatible. -
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
index 5f51741..a2b0f2a 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
@@ -21,8 +21,6 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.event.PropertyChangeSet;
import java.lang.reflect.Method;
-import java.util.Optional;
-import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -36,16 +34,20 @@ public final class ConfigChangeCallbackMethod {
private Method callbackMethod;
- public ConfigChangeCallbackMethod(Method callbackMethod) {
- this.callbackMethod = Optional.of(callbackMethod).filter(
- (m) -> void.class.equals(m.getReturnType()) &&
- m.getParameterCount() == 1 &&
- m.getParameterTypes()[0].equals(PropertyChangeSet.class)).get();
+ public ConfigChangeCallbackMethod(Method methodCandidate) {
+ if (void.class.equals(methodCandidate.getReturnType()) &&
+ methodCandidate.getParameterCount() == 1 &&
+ methodCandidate.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
+ this.callbackMethod = methodCandidate;
+ }
}
- public Consumer<PropertyChangeSet> createConsumer(Object instance){
- return event -> {
- call(instance, event);
+ public PropertyChangeSetListener createConsumer(final Object instance) {
+ return new PropertyChangeSetListener() {
+ @Override
+ public void propertyChange(PropertyChangeSet propertyChangeSet) {
+ call(instance, propertyChangeSet);
+ }
};
}
@@ -54,8 +56,9 @@ public final class ConfigChangeCallbackMethod {
callbackMethod.setAccessible(true);
callbackMethod.invoke(instance, configChangeEvent);
} catch (Exception e) {
- LOG.log(Level.SEVERE, e, () -> "Error calling ConfigChange callback method " +
- callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance);
+ LOG.log(Level.SEVERE, "Error calling ConfigChange callback method " +
+ callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance,
+ e);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
index d85f787..0b6e108 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -78,9 +78,12 @@ public class ConfiguredField {
private void applyDynamicValue(Object target) throws ConfigException {
Objects.requireNonNull(target);
try {
- AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
- annotatedField.setAccessible(true);
- return annotatedField;
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ annotatedField.setAccessible(true);
+ return annotatedField;
+ }
});
annotatedField.set(target,
DefaultDynamicValue.of(annotatedField, ConfigurationProvider.getConfiguration()));
@@ -108,9 +111,12 @@ public class ConfiguredField {
// Check for adapter/filter
Object value = InjectionUtils.adaptValue(this.annotatedField, TypeLiteral.of(this.annotatedField.getType()), evaluatedValue);
- AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
- annotatedField.setAccessible(true);
- return annotatedField;
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ annotatedField.setAccessible(true);
+ return annotatedField;
+ }
});
annotatedField.set(target, value);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 8dca102..a9cb58e 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -22,7 +22,6 @@ import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.Objects;
-import java.util.Optional;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.TypeLiteral;
@@ -45,9 +44,10 @@ public class ConfiguredSetterMethod {
* @param method the method instance.
*/
public ConfiguredSetterMethod(Method method) {
- this.setterMethod = Optional.of(method).filter(
- (m) -> void.class.equals(m.getReturnType()) &&
- m.getParameterCount() == 1).get();
+ if (void.class.equals(method.getReturnType()) &&
+ method.getParameterCount() == 1) {
+ this.setterMethod = method;
+ }
}
/**
@@ -67,9 +67,12 @@ public class ConfiguredSetterMethod {
// Check for adapter/filter
Object value = InjectionUtils.adaptValue(this.setterMethod, TypeLiteral.of(this.setterMethod.getParameterTypes()[0]), evaluatedString);
- AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
- setterMethod.setAccessible(true);
- return setterMethod;
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ @Override
+ public Object run() throws Exception {
+ setterMethod.setAccessible(true);
+ return setterMethod;
+ }
});
setterMethod.invoke(target, value);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
index 90700ff..8ec34e5 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
@@ -72,24 +72,24 @@ public class ConfiguredType {
private void initFields(Class type) {
for (Field f : type.getDeclaredFields()) {
if (f.isAnnotationPresent(NoConfig.class)) {
- LOG.finest(() -> "Ignored @NoConfig annotated field " +f.getClass().getName() + "#" +
+ LOG.finest("Ignored @NoConfig annotated field " + f.getClass().getName() + "#" +
f.toGenericString());
continue;
}
if (Modifier.isFinal(f.getModifiers())) {
- LOG.finest(() -> "Ignored final field " +f.getClass().getName() + "#" +
+ LOG.finest("Ignored final field " + f.getClass().getName() + "#" +
f.toGenericString());
continue;
}
if (f.isSynthetic()) {
- LOG.finest(() -> "Ignored synthetic field " +f.getClass().getName() + "#" +
+ LOG.finest("Ignored synthetic field " + f.getClass().getName() + "#" +
f.toGenericString());
continue;
}
try {
ConfiguredField configuredField = new ConfiguredField(f);
configuredFields.add(configuredField);
- LOG.finer(() -> "Registered field " +f.getClass().getName() + "#" +
+ LOG.finer("Registered field " + f.getClass().getName() + "#" +
f.toGenericString());
} catch (Exception e) {
throw new ConfigException("Failed to initialized configured field: " +
@@ -102,12 +102,12 @@ public class ConfiguredType {
// TODO revisit this logic here...
for (Method m : type.getDeclaredMethods()) {
if (m.isAnnotationPresent(NoConfig.class)) {
- LOG.finest(() -> "Ignored @NoConfig annotated method " +m.getClass().getName() + "#" +
+ LOG.finest("Ignored @NoConfig annotated method " + m.getClass().getName() + "#" +
m.toGenericString());
continue;
}
if (m.isSynthetic()) {
- LOG.finest(() -> "Ignored synthetic method " +m.getClass().getName() + "#" +
+ LOG.finest("Ignored synthetic method " + m.getClass().getName() + "#" +
m.toGenericString());
continue;
}
@@ -117,19 +117,19 @@ public class ConfiguredType {
// it is a template
if (observesAnnot != null && m.isDefault()) {
if(addObserverMethod(m)){
- LOG.finer(() -> "Added configured observer for template: " + m.getClass().getName() + "#" +
+ LOG.finer("Added configured observer for template: " + m.getClass().getName() + "#" +
m.toGenericString());
}
}
} else {
if (observesAnnot != null) {
if(addObserverMethod(m)){
- LOG.finer(() -> "Added configured observer: " + m.getClass().getName() + "#" +
+ LOG.finer("Added configured observer: " + m.getClass().getName() + "#" +
m.toGenericString());
}
} else {
if (addPropertySetter(m, propAnnot)) {
- LOG.finer(() -> "Added configured setter: " + m.getClass().getName() + "#"+
+ LOG.finer("Added configured setter: " + m.getClass().getName() + "#" +
m.toGenericString());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
index baa397d..853d223 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -26,7 +26,8 @@ import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Supplier;
+
+import org.apache.tamaya.inject.Supplier;
/**
* Simple injector singleton that also registers instances configured using weak references.
@@ -43,7 +44,13 @@ public final class DefaultConfigurationInjector implements ConfigurationInjector
* @return the configured type registered.
*/
public ConfiguredType registerTypeInternal(Class<?> type) {
- return configuredTypes.computeIfAbsent(type, ConfiguredType::new);
+ ConfiguredType confType = configuredTypes.get(type);
+ if (confType == null) {
+ confType = new ConfiguredType(type);
+ configuredTypes.put(type, confType);
+ }
+ return confType;
+// return configuredTypes.computeIfAbsent(type, ConfiguredType::new);
}
void registerType(Class<?> type) {
@@ -81,7 +88,11 @@ public final class DefaultConfigurationInjector implements ConfigurationInjector
@Override
- public <T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier) {
- return () -> configure(supplier.get());
+ public <T> Supplier<T> getConfiguredSupplier(final Supplier<T> supplier) {
+ return new Supplier<T>() {
+ public T get() {
+ return supplier.get();
+ }
+ };
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
index 499a6ad..8ca7703 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
@@ -20,12 +20,14 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.inject.Supplier;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.DynamicValue;
import org.apache.tamaya.inject.WithPropertyConverter;
import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -40,9 +42,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
import java.util.logging.Logger;
/**
@@ -93,15 +92,15 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
/**
* The current value, never null.
*/
- private transient Optional<T> value;
+ private transient T value;
/**
* The new value, or null.
*/
- private transient Optional<T> newValue;
+ private transient T newValue;
/**
* List of listeners that listen for changes.
*/
- private transient WeakList<Consumer<PropertyChangeEvent>> listeners;
+ private transient WeakList<PropertyChangeListener> listeners;
/**
* Constructor.
@@ -119,7 +118,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
this.configuration = Objects.requireNonNull(configuration);
this.propertyConverter = propertyConverter;
this.targetType = targetType;
- this.value = Optional.ofNullable(evaluateValue());
+ this.value = evaluateValue();
}
public static DynamicValue of(Field annotatedField, Configuration configuration){
@@ -203,15 +202,13 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
*/
public void commit() {
synchronized (this) {
- if (newValue != null) {
- PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value.orElse(null),
- newValue.orElse(null));
- value = newValue;
- newValue = null;
- if(listeners!=null) {
- for (Consumer<PropertyChangeEvent> consumer : listeners.get()) {
- consumer.accept(evt);
- }
+ PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value,
+ newValue);
+ value = newValue;
+ newValue = null;
+ if (listeners != null) {
+ for (PropertyChangeListener consumer : listeners.get()) {
+ consumer.propertyChange(evt);
}
}
}
@@ -248,7 +245,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
*
* @param l the listener, not null
*/
- public void addListener(Consumer<PropertyChangeEvent> l) {
+ public void addListener(PropertyChangeListener l) {
if (listeners == null) {
listeners = new WeakList<>();
}
@@ -260,7 +257,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
*
* @param l the listner to be removed, not null
*/
- public void removeListener(Consumer<PropertyChangeEvent> l) {
+ public void removeListener(PropertyChangeListener l) {
if (listeners != null) {
listeners.remove(l);
}
@@ -275,7 +272,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @see DefaultDynamicValue#isPresent()
*/
public T get() {
- return value.get();
+ return value;
}
/**
@@ -287,12 +284,12 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
*/
public boolean updateValue() {
T newValue = evaluateValue();
- if (Objects.equals(newValue, this.value.orElse(null))) {
+ if (Objects.equals(newValue, this.value)) {
return false;
}
switch (this.updatePolicy) {
case IMMEDIATE:
- this.newValue = Optional.ofNullable(newValue);
+ this.newValue = newValue;
commit();
break;
case LOG_AND_DISCARD:
@@ -304,7 +301,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
break;
case EXPLCIT:
default:
- this.newValue = Optional.ofNullable(newValue);
+ this.newValue = newValue;
break;
}
return true;
@@ -340,9 +337,9 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @return the uncommitted new value, or null.
*/
public T getNewValue() {
- Optional<T> nv = newValue;
+ T nv = newValue;
if (nv != null) {
- return nv.orElse(null);
+ return nv;
}
return null;
}
@@ -353,20 +350,9 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @return {@code true} if there is a value present, otherwise {@code false}
*/
public boolean isPresent() {
- return value.isPresent();
+ return value != null;
}
- /**
- * If a value is present, invoke the specified consumer with the value,
- * otherwise do nothing.
- *
- * @param consumer block to be executed if a value is present
- * @throws NullPointerException if value is present and {@code consumer} is
- * null
- */
- public void ifPresent(Consumer<? super T> consumer) {
- value.ifPresent(consumer);
- }
/**
* Return the value if present, otherwise return {@code other}.
@@ -376,7 +362,10 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @return the value, if present, otherwise {@code other}
*/
public T orElse(T other) {
- return value.orElse(other);
+ if (value == null) {
+ return other;
+ }
+ return value;
}
/**
@@ -390,7 +379,10 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* null
*/
public T orElseGet(Supplier<? extends T> other) {
- return value.orElseGet(other);
+ if (value == null) {
+ return other.get();
+ }
+ return value;
}
/**
@@ -410,15 +402,9 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* {@code exceptionSupplier} is null
*/
public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
- return value.orElseThrow(exceptionSupplier);
- }
-
- /**
- * Converts the instance to an {@link java.util.Optional} instance.
- *
- * @return the corresponding Optional value.
- */
- public Optional<T> toOptional() {
+ if (value == null) {
+ throw exceptionSupplier.get();
+ }
return value;
}
@@ -431,7 +417,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.writeObject(updatePolicy);
if (isPresent()) {
- oos.writeObject(this.value.get());
+ oos.writeObject(this.value);
} else {
oos.writeObject(null);
}
@@ -447,7 +433,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
this.updatePolicy = (UpdatePolicy) ois.readObject();
if (isPresent()) {
- this.value = Optional.of((T) ois.readObject());
+ this.value = (T) ois.readObject();
}
newValue = null;
}
@@ -512,4 +498,5 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
}
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
index ab21089..4895af2 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
@@ -39,7 +39,7 @@ import org.apache.tamaya.inject.WithLoadPolicy;
import org.apache.tamaya.inject.WithPropertyConverter;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
/**
@@ -253,7 +253,7 @@ final class InjectionUtils {
if (!RESOLUTION_MODULE_LOADED) {
return value;
}
- ExpressionEvaluator evaluator = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
+ ExpressionEvaluator evaluator = ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class);
if (evaluator != null) {
return evaluator.evaluateExpression("<injection>", value);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java
new file mode 100644
index 0000000..d2abe73
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java
@@ -0,0 +1,37 @@
+/*
+ * 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 of 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.
+ */
+package org.apache.tamaya.inject.internal;
+
+import org.apache.tamaya.event.PropertyChangeSet;
+
+/**
+ * Listner interface for {@link org.apache.tamaya.event.PropertyChangeSet} events.
+ */
+public interface PropertyChangeSetListener {
+
+ /**
+ * This method gets called when a bound property is changed.
+ *
+ * @param evt A PropertyChangeEvent object describing the event source
+ * and the property that has changed.
+ */
+
+ void propertyChange(PropertyChangeSet evt);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
index 3ea8ed7..412d074 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
@@ -24,7 +24,6 @@ import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.StampedLock;
-import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -37,7 +36,7 @@ public final class WeakConfigListenerManager {
private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
private StampedLock lock = new StampedLock();
- private Map<Object, Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
+ private Map<Object, PropertyChangeSetListener> listenerReferences = new WeakHashMap<>();
/**
* Private singleton constructor.
@@ -56,15 +55,21 @@ public final class WeakConfigListenerManager {
* @param instance the instance, not null.
* @param listener the consumer.
*/
- public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener) {
+ public void registerConsumer(Object instance, final PropertyChangeSetListener listener) {
Lock writeLock = lock.asWriteLock();
try {
writeLock.lock();
- Consumer<PropertyChangeSet> l = listenerReferences.get(instance);
+ final PropertyChangeSetListener l = listenerReferences.get(instance);
if (l == null) {
listenerReferences.put(instance, listener);
} else {
- listenerReferences.put(instance, l.andThen(listener));
+ listenerReferences.put(instance, new PropertyChangeSetListener() {
+ @Override
+ public void propertyChange(PropertyChangeSet evt) {
+ l.propertyChange(evt);
+ listener.propertyChange(evt);
+ }
+ });
}
} finally {
writeLock.unlock();
@@ -95,13 +100,13 @@ public final class WeakConfigListenerManager {
Lock readLock = lock.asReadLock();
try {
readLock.lock();
- listenerReferences.values().parallelStream().forEach(l -> {
+ for (PropertyChangeSetListener l : listenerReferences.values()) {
try {
- l.accept(change);
+ l.propertyChange(change);
} catch (Exception e) {
LOG.log(Level.SEVERE, "ConfigChangeListener failed: " + l.getClass().getName(), e);
}
- });
+ }
} finally {
readLock.unlock();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java b/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
index 94fc188..900fee9 100644
--- a/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
@@ -42,7 +42,7 @@ public interface AnnotatedConfigTemplate {
String simpleValue();
@ConfiguredProperty
- default String simplestValue(){return "HALLO!";}
+ String simplestValue();
@ConfiguredProperty(keys = "host.name")
String hostName();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java b/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
index 0ee2c24..ebcd04f 100644
--- a/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
@@ -33,13 +33,13 @@ public class TamayaInjectionTest {
@Test
public void testInjectionClass(){
- assertNotNull(ConfigurationInjector.getInstance());
+ assertNotNull(ConfigurationInjection.getConfigurationInjector());
AnnotatedConfigBean testInstance = new AnnotatedConfigBean();
assertEquals(testInstance.getHostName(), null);
assertEquals(testInstance.getAnotherValue(), null);
assertEquals(testInstance.myParameter, null);
assertEquals(testInstance.simpleValue, null);
- ConfigurationInjector.getInstance().configure(testInstance);
+ ConfigurationInjection.getConfigurationInjector().configure(testInstance);
assertEquals(testInstance.getHostName(), "tamaya01.incubator.apache.org");
assertEquals(testInstance.getAnotherValue(), "HALLO!");
assertEquals(testInstance.myParameter, "ET");
@@ -53,8 +53,8 @@ public class TamayaInjectionTest {
@Test
public void testConfigTemplate(){
- assertNotNull(ConfigurationInjector.getInstance());
- AnnotatedConfigTemplate testInstance = ConfigurationInjector.getInstance()
+ assertNotNull(ConfigurationInjection.getConfigurationInjector());
+ AnnotatedConfigTemplate testInstance = ConfigurationInjection.getConfigurationInjector()
.createTemplate(AnnotatedConfigTemplate.class);
assertEquals(testInstance.hostName(), "tamaya01.incubator.apache.org");
assertEquals(testInstance.myParameter(), "ET");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java b/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
index 7303f60..b58d8a4 100644
--- a/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
@@ -56,4 +56,9 @@ public class TestPropertySource implements PropertySource {
public Map<String, String> getProperties() {
return properties;
}
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
index 39062a7..9ec2f31 100644
--- a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
@@ -24,6 +24,7 @@ import org.apache.tamaya.builder.ConfigurationBuilder;
import org.apache.tamaya.core.internal.converters.DoubleConverter;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.inject.DynamicValue;
+import org.apache.tamaya.inject.Supplier;
import org.apache.tamaya.inject.WithPropertyConverter;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertySource;
@@ -32,9 +33,9 @@ import org.junit.Test;
import org.apache.tamaya.Configuration;
import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Consumer;
import static org.junit.Assert.*;
@@ -56,20 +57,40 @@ public class DefaultDynamicValueTest {
private PropertyChangeEvent event;
- private Consumer<PropertyChangeEvent> consumer = ev -> event = ev;
+ private PropertyChangeListener consumer = new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ event = evt;
+ }
+ };
private Map<String,String> properties = new HashMap<>();
private Configuration config = new ConfigurationBuilder().addPropertySources(
new PropertySource() {
@Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return "test";
}
@Override
+ public String get(String key) {
+ return properties.get(key);
+ }
+
+ @Override
public Map<String, String> getProperties() {
return properties;
}
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
}
).build();
@@ -119,12 +140,12 @@ public class DefaultDynamicValueTest {
assertNotNull(val);
assertEquals("aValue",val.evaluateValue());
// change config
- this.properties.put("a","aValue2");
+ this.properties.put("a", "aValue2");
assertTrue(val.updateValue());
assertEquals("aValue2", val.evaluateValue());
assertTrue(val.updateValue());
val.commit();
- assertEquals("aValue2",val.evaluateValue());
+ assertEquals("aValue2", val.evaluateValue());
}
@Test
@@ -178,7 +199,7 @@ public class DefaultDynamicValueTest {
@Test
public void testGet() throws Exception {
- properties.put("a","aValue");
+ properties.put("a", "aValue");
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(DynamicValue.UpdatePolicy.IMMEDIATE);
@@ -194,9 +215,9 @@ public class DefaultDynamicValueTest {
config);
val.setUpdatePolicy(DynamicValue.UpdatePolicy.EXPLCIT);
assertNotNull(val.get());
- assertEquals("aValue",val.get());
+ assertEquals("aValue", val.get());
val.updateValue();
- assertEquals("aValue",val.get());
+ assertEquals("aValue", val.get());
val.setUpdatePolicy(DynamicValue.UpdatePolicy.IMMEDIATE);
val.updateValue();
assertEquals("aValue",val.get());
@@ -210,8 +231,8 @@ public class DefaultDynamicValueTest {
val.setUpdatePolicy(DynamicValue.UpdatePolicy.EXPLCIT);
assertNotNull(val.get());
assertEquals("aValue",val.evaluateValue());
- properties.put("a","aValue2");
- assertEquals("aValue2",val.evaluateValue());
+ properties.put("a", "aValue2");
+ assertEquals("aValue2", val.evaluateValue());
}
@Test
@@ -262,10 +283,20 @@ public class DefaultDynamicValueTest {
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(DynamicValue.UpdatePolicy.IMMEDIATE);
- assertEquals("bla", val.orElseGet(() -> "bla"));
- properties.put("a","aValue");
+ assertEquals("bla", val.orElseGet(new Supplier() {
+ @Override
+ public Object get() {
+ return "bla";
+ }
+ }));
+ properties.put("a", "aValue");
val.updateValue();
- assertEquals("aValue", val.orElseGet(() -> "bla"));
+ assertEquals("aValue", val.orElseGet(new Supplier() {
+ @Override
+ public Object get() {
+ return "bla";
+ }
+ }));
}
@Test(expected = ConfigException.class)
@@ -273,24 +304,21 @@ public class DefaultDynamicValueTest {
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(DynamicValue.UpdatePolicy.EXPLCIT);
- properties.put("a","aValue");
- assertEquals("aValue", val.orElseThrow(() -> new ConfigException("bla")));
- properties.remove("a");
- val.updateValue();
- assertEquals("aValue", val.orElseThrow(() -> new ConfigException("bla")));
- }
-
- @Test
- public void testToOptional() throws Exception {
properties.put("a", "aValue");
- DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
- config);
- val.setUpdatePolicy(DynamicValue.UpdatePolicy.IMMEDIATE);
- assertTrue(val.toOptional().isPresent());
- assertEquals("aValue", val.toOptional().get());
+ assertEquals("aValue", val.orElseThrow(new Supplier() {
+ @Override
+ public ConfigException get() {
+ return new ConfigException("bla");
+ }
+ }));
properties.remove("a");
val.updateValue();
- assertFalse(val.toOptional().isPresent());
+ assertEquals("aValue", val.orElseThrow(new Supplier() {
+ @Override
+ public ConfigException get() {
+ return new ConfigException("bla");
+ }
+ }));
}
private static final class DoublicatingConverter implements PropertyConverter<String>{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
index c86b9e8..747c23e 100644
--- a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
@@ -23,13 +23,16 @@ import org.apache.tamaya.event.PropertyChangeSet;
import org.apache.tamaya.event.PropertyChangeSetBuilder;
import org.junit.Test;
-import java.util.function.Consumer;
-
import static org.junit.Assert.*;
public class WeakConfigListenerManagerTest {
- private Consumer<PropertyChangeSet> consumer = s -> loggedSet = s;
+ private PropertyChangeSetListener consumer = new PropertyChangeSetListener() {
+ @Override
+ public void propertyChange(PropertyChangeSet set) {
+ loggedSet = set;
+ }
+ };
private PropertyChangeSet loggedSet;
@Test
@@ -40,8 +43,12 @@ public class WeakConfigListenerManagerTest {
@Test
public void testRegisterConsumer() throws Exception {
SystemPropertySource sysSrc = new SystemPropertySource();
- WeakConfigListenerManager.of().registerConsumer(this,
- s -> loggedSet = s);
+ WeakConfigListenerManager.of().registerConsumer(this, new PropertyChangeSetListener() {
+ @Override
+ public void propertyChange(PropertyChangeSet set) {
+ loggedSet = set;
+ }
+ });
PropertyChangeSet change = PropertyChangeSetBuilder.of(sysSrc).add("aaa", "aaaValue").build();
WeakConfigListenerManager.of().registerConsumer(this, consumer);
WeakConfigListenerManager.of().publishChangeEvent(change);
@@ -54,7 +61,12 @@ public class WeakConfigListenerManagerTest {
public void testUnregisterConsumer() throws Exception {
SystemPropertySource sysSrc = new SystemPropertySource();
PropertyChangeSet change = PropertyChangeSetBuilder.of(sysSrc).add("aaa", "aaaValue").build();
- Consumer<PropertyChangeSet> tempConsumer = s -> loggedSet = s;
+ PropertyChangeSetListener tempConsumer = new PropertyChangeSetListener() {
+ @Override
+ public void propertyChange(PropertyChangeSet set) {
+ loggedSet = set;
+ }
+ };
WeakConfigListenerManager.of().registerConsumer(this, tempConsumer);
WeakConfigListenerManager.of().publishChangeEvent(change);
assertNotNull(loggedSet);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/json/pom.xml
----------------------------------------------------------------------
diff --git a/modules/json/pom.xml b/modules/json/pom.xml
index 6d081c0..e11f893 100644
--- a/modules/json/pom.xml
+++ b/modules/json/pom.xml
@@ -32,18 +32,23 @@ under the License.
<name>Apache Tamaya JSON Support</name>
<inceptionYear>2015</inceptionYear>
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-java7-api</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <artifactId>tamaya-java7-core</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java b/modules/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
index e9e0bcb..c207de0 100644
--- a/modules/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
+++ b/modules/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
@@ -76,8 +76,8 @@ public class JSONPropertySource implements PropertySource {
try{
return Integer.parseInt(configuredOrdinal);
} catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING, e,
- () -> "Configured Ordinal is not an int number: " + configuredOrdinal);
+ Logger.getLogger(getClass().getName()).log(Level.WARNING,
+ "Configured Ordinal is not an int number: " + configuredOrdinal, e);
}
}
return ordinal;
@@ -89,6 +89,11 @@ public class JSONPropertySource implements PropertySource {
}
@Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
public Map<String, String> getProperties() {
return Collections.unmodifiableMap(values);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/json/src/test/java/org/apache/tamaya/json/JSONFormatIT.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/json/JSONFormatIT.java b/modules/json/src/test/java/org/apache/tamaya/json/JSONFormatIT.java
index e5bb91e..a2e9ad5 100644
--- a/modules/json/src/test/java/org/apache/tamaya/json/JSONFormatIT.java
+++ b/modules/json/src/test/java/org/apache/tamaya/json/JSONFormatIT.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.json;
import org.apache.tamaya.format.ConfigurationFormat;
import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import org.junit.Test;
import java.util.List;
@@ -34,13 +35,16 @@ import static org.hamcrest.Matchers.notNullValue;
public class JSONFormatIT {
@Test
public void jsonFormatCanBeFoundViaServiceLoader() throws Exception {
- List<ConfigurationFormat> formats = ServiceContext.getInstance()
+ List<ConfigurationFormat> formats = ServiceContextManager.getServiceContext()
.getServices(ConfigurationFormat.class);
- ConfigurationFormat format = formats.stream()
- .filter(s -> s instanceof JSONFormat)
- .findFirst().get();
-
+ ConfigurationFormat format = null;
+ for (ConfigurationFormat f : formats) {
+ if (format instanceof JSONFormat) {
+ format = f;
+ break;
+ }
+ }
assertThat(format, notNullValue());
assertThat(format, instanceOf(JSONFormat.class));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/pom.xml
----------------------------------------------------------------------
diff --git a/modules/resolver/pom.xml b/modules/resolver/pom.xml
index 3a354c6..bbfe1eb 100644
--- a/modules/resolver/pom.xml
+++ b/modules/resolver/pom.xml
@@ -30,15 +30,19 @@ under the License.
<name>Apache Tamaya Resolver Services</name>
<packaging>jar</packaging>
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-java7-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
+ <artifactId>tamaya-java7-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
index 39844f9..e6375f7 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/Resolver.java
@@ -38,7 +38,7 @@ public final class Resolver {
* @return the filtered/evaluated value, including null.
*/
public static String evaluateExpression(String key, String value){
- return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class).get()
+ return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class)
.evaluateExpression(key, value);
}
@@ -48,7 +48,7 @@ public final class Resolver {
* @return the filtered/evaluated value, including null.
*/
public static String evaluateExpression(String value){
- return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class).get()
+ return ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class)
.evaluateExpression(null, value);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
index d4f5d51..575a176 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/DefaultExpressionEvaluator.java
@@ -19,12 +19,13 @@
package org.apache.tamaya.resolver.internal;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
-import org.apache.tamaya.spi.ServiceContext;
import org.apache.tamaya.resolver.spi.ExpressionResolver;
+import org.apache.tamaya.spi.ServiceContextManager;
import javax.annotation.Priority;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Level;
@@ -42,11 +43,24 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator {
private List<ExpressionResolver> resolvers = new ArrayList<>();
+ /**
+ * Comparator used (not needed with Java8).
+ */
+ private static final Comparator<ExpressionResolver> RESOLVER_COMPARATOR = new Comparator<ExpressionResolver>() {
+ @Override
+ public int compare(ExpressionResolver o1, ExpressionResolver o2) {
+ return compareExpressionResolver(o1, o2);
+ }
+ };
+
+ /**
+ * Default constructor.
+ */
public DefaultExpressionEvaluator() {
- for(ExpressionResolver resolver: ServiceContext.getInstance().getServices(ExpressionResolver.class)){
+ for (ExpressionResolver resolver : ServiceContextManager.getServiceContext().getServices(ExpressionResolver.class)) {
resolvers.add(resolver);
}
- Collections.sort(resolvers, this::compareExpressionResolver);
+ Collections.sort(resolvers, RESOLVER_COMPARATOR);
}
/**
@@ -56,7 +70,7 @@ public class DefaultExpressionEvaluator implements ExpressionEvaluator {
* @param res2 the second ExpressionResolver
* @return the comparison result.
*/
- private int compareExpressionResolver(ExpressionResolver res1, ExpressionResolver res2) {
+ private static int compareExpressionResolver(ExpressionResolver res1, ExpressionResolver res2) {
Priority prio1 = res1.getClass().getAnnotation(Priority.class);
Priority prio2 = res2.getClass().getAnnotation(Priority.class);
int ord1 = prio1 != null ? prio1.value() : 0;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
index 470560b..30909dc 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.resolver.internal;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import javax.annotation.Priority;
import java.util.logging.Logger;
@@ -35,7 +35,7 @@ public class ExpressionResolutionFilter implements PropertyFilter {
private static final Logger LOG = Logger.getLogger(ExpressionResolutionFilter.class.getName());
- private ExpressionEvaluator evaluator = ServiceContext.getInstance().getService(ExpressionEvaluator.class).get();
+ private ExpressionEvaluator evaluator = ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class);
/**
* Resolves an expression in the form current <code>${resolverId:expression}</code> or
@@ -77,7 +77,7 @@ public class ExpressionResolutionFilter implements PropertyFilter {
*/
@Override
public String filterProperty(String key, String valueToBeFiltered){
- LOG.finest(() -> "Resolving " + valueToBeFiltered + "(key="+key+")");
+ LOG.finest("Resolving " + valueToBeFiltered + "(key=" + key + ")");
return evaluator.evaluateExpression(key, valueToBeFiltered);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/FileResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/FileResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/FileResolver.java
index dac18ed..dffc74b 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/FileResolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/FileResolver.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.resolver.internal;
import org.apache.tamaya.resolver.spi.ExpressionResolver;
import org.apache.tamaya.resource.ResourceResolver;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import javax.annotation.Priority;
import java.io.BufferedReader;
@@ -93,7 +93,7 @@ public final class FileResolver implements ExpressionResolver {
private URL getUrl(String expression) {
if (IS_RESOURCE_MODULE_AVAILABLE) {
- ResourceResolver resolver = ServiceContext.getInstance().getService(ResourceResolver.class).get();
+ ResourceResolver resolver = ServiceContextManager.getServiceContext().getService(ResourceResolver.class);
Collection<URL> resources = resolver.getResources("file:" + expression);
if (!resources.isEmpty()) {
if (resources.size() != 1) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResourceResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResourceResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResourceResolver.java
index cbd083c..0068804 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResourceResolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResourceResolver.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.resolver.internal;
import org.apache.tamaya.resolver.spi.ExpressionResolver;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
import javax.annotation.Priority;
import java.io.BufferedReader;
@@ -105,7 +105,8 @@ public final class ResourceResolver implements ExpressionResolver {
private URL getUrl(String expression, List<ClassLoader> classLoaders) {
if (IS_RESOURCE_MODULE_AVAILABLE) {
- org.apache.tamaya.resource.ResourceResolver resolver = ServiceContext.getInstance().getService(org.apache.tamaya.resource.ResourceResolver.class).get();
+ org.apache.tamaya.resource.ResourceResolver resolver = ServiceContextManager.getServiceContext()
+ .getService(org.apache.tamaya.resource.ResourceResolver.class);
for (ClassLoader cl : classLoaders) {
Collection<URL> resources = resolver.getResources(cl, expression);
if (!resources.isEmpty()) {
@@ -138,7 +139,7 @@ public final class ResourceResolver implements ExpressionResolver {
}
}
if (expression.contains("*") || expression.contains("?")) {
- LOG.warning(() -> "Rouse not found: " + expression + "(Hint: expression contains expression" +
+ LOG.warning("Rouse not found: " + expression + "(Hint: expression contains expression" +
" placeholders, but resource module is not loaded.");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java b/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
index 6e35f4f..d32b88a 100644
--- a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
+++ b/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
@@ -82,4 +82,9 @@ public class MyTestPropertySource implements PropertySource{
public Map<String, String> getProperties() {
return properties;
}
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/pom.xml
----------------------------------------------------------------------
diff --git a/modules/resources/pom.xml b/modules/resources/pom.xml
index b395336..09adaa0 100644
--- a/modules/resources/pom.xml
+++ b/modules/resources/pom.xml
@@ -30,10 +30,14 @@ under the License.
<name>Apache Tamaya Resource Services</name>
<packaging>jar</packaging>
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
+ <artifactId>tamaya-java7-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java b/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
index 4aeaeb0..4db21e4 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
@@ -124,7 +124,9 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
*/
public PropertiesBasedPropertySource(String name, Properties props) {
this.name = name;
- props.forEach((k,v) -> this.properties.put(k.toString(), v.toString()));
+ for (Map.Entry en : props.entrySet()) {
+ this.properties.put(en.getKey().toString(), String.valueOf(en.getValue()));
+ }
}
/**
@@ -138,6 +140,29 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
}
@Override
+ public int getOrdinal() {
+ String configuredOrdinal = get(TAMAYA_ORDINAL);
+ if (configuredOrdinal != null) {
+ try {
+ return Integer.parseInt(configuredOrdinal);
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING,
+ "Configured Ordinal is not an int number: " + configuredOrdinal, e);
+ }
+ }
+ return getDefaultOrdinal();
+ }
+
+ /**
+ * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
+ *
+ * @return the default ordinal used, by default 0.
+ */
+ public int getDefaultOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return name;
}
@@ -153,6 +178,11 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
}
@Override
+ public boolean isScannable() {
+ return false;
+ }
+
+ @Override
public String toString(){
return "PropertiesBasedPropertySource["+name+']';
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/BaseResourceResolver.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/BaseResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/BaseResourceResolver.java
new file mode 100644
index 0000000..cb8c1f5
--- /dev/null
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/BaseResourceResolver.java
@@ -0,0 +1,111 @@
+/*
+ * 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 of 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.
+ */
+package org.apache.tamaya.resource;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+
+/**
+ * Interface to be implemented by modules. It supports loading of files or classpath resources either directly or by
+ * defining a Ant-styled resource pattern:
+ * <ul>
+ * <li>'*' is a placeholder for any character (0..n)</li>
+ * <li>'**' is a placeholder for any number of subdirectories going down a directory structure recursively.</li>
+ * <li>'?' is a placeholder for exact one character</li>
+ * </ul>
+ * Given that the following expressions are valid expressions:
+ * <pre>
+ * classpath:javax/annotations/*
+ * javax?/annotations/**/*.class
+ * org/apache/tamaya/**/tamayaconfig.properties
+ * file:C:/temp/*.txt
+ * file:C:\**\*.ini
+ * C:\Programs\**/*.ini
+ * /user/home/A*b101_?.pid
+ * /var/logs/**/*.log
+ * </pre>
+ */
+public abstract class BaseResourceResolver implements ResourceResolver {
+
+ /**
+ * Resolves resource expressions to a list of {@link URL}s. Hereby
+ * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that
+ * there is no determined ordering of format located within a classloader.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection of current {@link URL}s found, never
+ * null.
+ * .
+ */
+ @Override
+ public Collection<URL> getResources(Collection<String> expressions) {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) {
+ cl = getClass().getClassLoader();
+ }
+ return getResources(cl, expressions);
+ }
+
+ /**
+ * Resolves resource expressions to a list of {@link URL}s. Hereby
+ * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that
+ * there is no determined ordering of format located within a classloader.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection of current {@link URL}s found, never
+ * null.
+ * .
+ */
+ @Override
+ public Collection<URL> getResources(String... expressions) {
+ return getResources(Arrays.asList(expressions));
+ }
+
+ /**
+ * Resolves resource expressions to a list of {@link URL}s, considerubg
+ * the given classloader for classloader dependent format. Hereby
+ * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that
+ * there is no determined ordering of format located within a classloader.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection of current {@link URL}s found, never
+ * null.
+ * .
+ */
+ @Override
+ public Collection<URL> getResources(ClassLoader classLoader, String... expressions) {
+ return getResources(classLoader, Arrays.asList(expressions));
+ }
+
+ /**
+ * Resolves resource expressions to a list of {@link URL}s, considerubg
+ * the given classloader for classloader dependent format. Hereby
+ * the ordering of format matches the input of the resolved expressions. Nevertheless be aware that
+ * there is no determined ordering of format located within a classloader.
+ *
+ * @param expressions the expressions to be resolved, not empty.
+ * @return the corresponding collection of current {@link URL}s found, never
+ * null.
+ * .
+ */
+ @Override
+ public abstract Collection<URL> getResources(ClassLoader classLoader, Collection<String> expressions);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/ConfigResources.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/ConfigResources.java b/modules/resources/src/main/java/org/apache/tamaya/resource/ConfigResources.java
index f52bc0b..9f4650a 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/ConfigResources.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/ConfigResources.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.resource;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
/**
* Singleton Accessor for accessing the current {@link org.apache.tamaya.resource.ResourceResolver} instance.
@@ -37,8 +37,10 @@ public final class ConfigResources {
* @throws org.apache.tamaya.ConfigException, if no ResourceResolver is available (should not happen).
*/
public static ResourceResolver getResourceResolver(){
- return ServiceContext.getInstance().getService(ResourceResolver.class).orElseThrow(
- () -> new ConfigException("ResourceResolver not available.")
- );
+ ResourceResolver resolver = ServiceContextManager.getServiceContext().getService(ResourceResolver.class);
+ if (resolver == null) {
+ throw new ConfigException("ResourceResolver not available.");
+ }
+ return resolver;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
index 3dcf6fa..784b54b 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/ResourceResolver.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.resource;
import java.net.URL;
-import java.util.Arrays;
import java.util.Collection;
/**
@@ -54,13 +53,7 @@ public interface ResourceResolver {
* null.
* .
*/
- default Collection<URL> getResources(Collection<String> expressions) {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- cl = getClass().getClassLoader();
- }
- return getResources(cl, expressions);
- }
+ Collection<URL> getResources(Collection<String> expressions);
/**
* Resolves resource expressions to a list of {@link URL}s. Hereby
@@ -72,9 +65,7 @@ public interface ResourceResolver {
* null.
* .
*/
- default Collection<URL> getResources(String... expressions) {
- return getResources(Arrays.asList(expressions));
- }
+ Collection<URL> getResources(String... expressions);
/**
* Resolves resource expressions to a list of {@link URL}s, considerubg
@@ -87,9 +78,7 @@ public interface ResourceResolver {
* null.
* .
*/
- default Collection<URL> getResources(ClassLoader classLoader, String... expressions){
- return getResources(classLoader, Arrays.asList(expressions));
- }
+ Collection<URL> getResources(ClassLoader classLoader, String... expressions);
/**
* Resolves resource expressions to a list of {@link URL}s, considerubg
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java
index df87436..80b08c9 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.resource.internal;
-import org.apache.tamaya.resource.ResourceResolver;
+import org.apache.tamaya.resource.BaseResourceResolver;
import javax.annotation.Priority;
import java.io.File;
@@ -34,7 +34,7 @@ import java.util.logging.Logger;
* Simple default implementation of the resource loader, which does only support direct references to files.
*/
@Priority(0)
-public class DefaultResourceResolver implements ResourceResolver {
+public class DefaultResourceResolver extends BaseResourceResolver {
private static final Logger LOG = Logger.getLogger(DefaultResourceResolver.class.getName());
@@ -68,7 +68,7 @@ public class DefaultResourceResolver implements ResourceResolver {
resources.addAll(found);
return !found.isEmpty();
} catch (RuntimeException e) {
- LOG.finest(() -> "Failed to load resource from CP: " + expression);
+ LOG.finest("Failed to load resource from CP: " + expression);
}
return false;
}
@@ -89,7 +89,7 @@ public class DefaultResourceResolver implements ResourceResolver {
}
return !resources.isEmpty();
} catch (IOException | RuntimeException e) {
- LOG.finest(() -> "Failed to load resource from CP: " + expression);
+ LOG.finest("Failed to load resource from CP: " + expression);
}
return false;
}
@@ -108,7 +108,7 @@ public class DefaultResourceResolver implements ResourceResolver {
return true;
}
} catch (IOException | RuntimeException e) {
- LOG.finest(() -> "Failed to load resource from file: " + expression);
+ LOG.finest("Failed to load resource from file: " + expression);
}
return false;
}
@@ -125,7 +125,7 @@ public class DefaultResourceResolver implements ResourceResolver {
resources.add(url);
return true;
} catch (IOException | RuntimeException e) {
- LOG.finest(() -> "Failed to load resource from file: " + expression);
+ LOG.finest("Failed to load resource from file: " + expression);
}
return false;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java
index f1b753d..3bd0308 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/FileCollector.java
@@ -123,7 +123,7 @@ public class FileCollector {
try {
result.add(getURL(childFile));
} catch (Exception e) {
- LOG.warning(() -> "File not convertible to URL: " + childFile);
+ LOG.warning("File not convertible to URL: " + childFile);
}
}
} else if (childFile.isDirectory()) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
index 3e861d3..8b20920 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/Locator.java
@@ -19,10 +19,8 @@
package org.apache.tamaya.resource.internal;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
-import java.util.stream.Collectors;
/**
* Small helper class that manages the path parts of a location expression.
@@ -49,7 +47,11 @@ final class Locator {
* @return the tokenized instance.
*/
public static Locator of(String expression) {
- return new Locator(Arrays.asList(expression.split("/")).stream().collect(Collectors.toList()));
+ List<String> expressions = new ArrayList<>();
+ for (String expr : expression.split("/")) {
+ expressions.add(expr);
+ }
+ return new Locator(expressions);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java b/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
index d9d0876..9efec7b 100644
--- a/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
+++ b/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
@@ -27,6 +27,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -37,17 +39,7 @@ public class AbstractPathPropertySourceProviderTest {
@Override
protected Collection<PropertySource> getPropertySources(URL url) {
List<PropertySource> result = new ArrayList<>();
- result.add(new PropertySource() {
- @Override
- public String getName() {
- return "<empty>";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.emptyMap();
- }
- });
+ result.add(new EmptyPropertySource());
return result;
}
};
@@ -65,4 +57,75 @@ public class AbstractPathPropertySourceProviderTest {
assertNotNull(ps);
assertTrue(ps.getProperties().isEmpty());
}
+
+ private static final class EmptyPropertySource implements PropertySource {
+ /**
+ * Lookup order:
+ * TODO rethink whole default PropertySources and ordering:
+ * TODO introduce default values or constants for ordinals
+ * <ol>
+ * <li>System properties (ordinal 400)</li>
+ * <li>Environment properties (ordinal 300)</li>
+ * <li>JNDI values (ordinal 200)</li>
+ * <li>Properties file values (/META-INF/applicationConfiguration.properties) (ordinal 100)</li>
+ * </ol>
+ * <p/>
+ * <p><b>Important Hints for custom implementations</b>:</p>
+ * <p>
+ * If a custom implementation should be invoked <b>before</b> the default implementations, use a value > 400
+ * </p>
+ * <p>
+ * If a custom implementation should be invoked <b>after</b> the default implementations, use a value < 100
+ * </p>
+ * <p/>
+ * <p>Reordering of the default order of the config-sources:</p>
+ * <p>Example: If the properties file/s should be used <b>before</b> the other implementations,
+ * you have to configure an ordinal > 400. That means, you have to add e.g. deltaspike_ordinal=401 to
+ * /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
+ * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
+ *
+ * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
+ */
+ public int getOrdinal() {
+ String configuredOrdinal = get(TAMAYA_ORDINAL);
+ if (configuredOrdinal != null) {
+ try {
+ return Integer.parseInt(configuredOrdinal);
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.WARNING,
+ "Configured Ordinal is not an int number: " + configuredOrdinal, e);
+ }
+ }
+ return getDefaultOrdinal();
+ }
+
+ /**
+ * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
+ *
+ * @return the default ordinal used, by default 0.
+ */
+ public int getDefaultOrdinal() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return "<empty>";
+ }
+
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/910c69fa/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java b/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
index ff628ad..4933ae8 100644
--- a/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
+++ b/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
@@ -62,7 +62,14 @@ public class PathBasedPropertySourceProvider extends AbstractPathPropertySourceP
public PropertiesBasedPropertySource(String name, Properties props) {
this.name = name;
- props.forEach((k,v) -> this.properties.put(k.toString(), v.toString()));
+ for (Map.Entry en : props.entrySet()) {
+ this.properties.put(en.getKey().toString(), String.valueOf(en.getValue()));
+ }
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 0;
}
@Override
@@ -79,5 +86,10 @@ public class PathBasedPropertySourceProvider extends AbstractPathPropertySourceP
public Map<String, String> getProperties() {
return properties;
}
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
}
}