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 2014/12/24 02:12:16 UTC
[6/6] incubator-tamaya git commit: TAMAYA-19: - Moved out much of
unused/experimental code. - Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly). - Moved Environment model
to separate metamodel module.
TAMAYA-19:
- Moved out much of unused/experimental code.
- Reduced API (removing package private singletons)
- Aligned PropertySource with Deltaspike (mostly).
- Moved Environment model to separate metamodel module.
TAMAYA 36:
- Enabled direct mapped properties, including noconfig annotation. tbd further.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a3c10d6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a3c10d6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a3c10d6e
Branch: refs/heads/master
Commit: a3c10d6edc3af9064483db50f23894231301d76e
Parents: 22d2d1a
Author: anatole <an...@apache.org>
Authored: Wed Dec 24 02:11:59 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 24 02:12:01 2014 +0100
----------------------------------------------------------------------
api/src/main/java/org/apache/tamaya/Codec.java | 10 +-
api/src/main/java/org/apache/tamaya/Codecs.java | 83 -----
.../java/org/apache/tamaya/ConfigChangeSet.java | 13 +-
.../apache/tamaya/ConfigChangeSetBuilder.java | 48 +--
.../java/org/apache/tamaya/Configuration.java | 119 +------
.../org/apache/tamaya/ConfigurationManager.java | 139 --------
.../java/org/apache/tamaya/ConfiguredValue.java | 261 ++++++++++++++
.../java/org/apache/tamaya/Environment.java | 83 -----
.../org/apache/tamaya/EnvironmentManager.java | 53 ---
.../java/org/apache/tamaya/PropertySource.java | 114 +++---
.../org/apache/tamaya/annotation/NoConfig.java | 32 ++
.../java/org/apache/tamaya/spi/CodecSpi.java | 89 +++++
.../apache/tamaya/spi/CodecsSingletonSpi.java | 89 -----
.../spi/ConfigurationManagerSingletonSpi.java | 116 ------
.../org/apache/tamaya/spi/ConfigurationSpi.java | 116 ++++++
.../spi/EnvironmentManagerSingletonSpi.java | 49 ---
.../tamaya/TestConfigServiceSingletonSpi.java | 9 +-
.../tamaya/TestEnvironmentManagerSingleton.java | 37 --
.../TestPropertyAdaptersSingletonSpi.java | 6 +-
.../services/org.apache.tamaya.spi.CodecSpi | 19 +
.../org.apache.tamaya.spi.CodecsSingletonSpi | 19 -
....tamaya.spi.ConfigurationManagerSingletonSpi | 19 -
.../org.apache.tamaya.spi.ConfigurationSpi | 19 +
...he.tamaya.spi.EnvironmentManagerSingletonSpi | 19 -
.../core/config/AbstractConfiguration.java | 18 +-
.../tamaya/core/config/ConfigFunctions.java | 104 +++++-
.../core/config/ConfigurationBuilder.java | 41 +--
.../tamaya/core/config/ConfigurationFormat.java | 111 ++++++
.../core/config/ConfigurationFormats.java | 91 -----
.../core/config/FreezedConfiguration.java | 17 +-
.../tamaya/core/config/MappedConfiguration.java | 6 +-
.../tamaya/core/env/BuildableEnvironment.java | 111 ------
.../core/env/ConfiguredSystemProperties.java | 353 -------------------
.../tamaya/core/env/EnvironmentBuilder.java | 99 ------
.../apache/tamaya/core/internal/MetaConfig.java | 5 +-
.../core/internal/config/DefaultCodecSpi.java | 169 +++++++++
...DefaultConfigurationManagerSingletonSpi.java | 136 -------
.../config/DefaultConfigurationSpi.java | 132 +++++++
.../core/internal/config/FileConfiguration.java | 16 +-
...DependentApplicationEnvironmentProvider.java | 101 ------
...ssLoaderDependentEarEnvironmentProvider.java | 108 ------
.../env/InitialEnvironmentProvider.java | 74 ----
.../internal/env/SingleEnvironmentManager.java | 70 ----
.../SystemClassLoaderEnvironmentProvider.java | 74 ----
.../DefaultConfigFormatsSingletonSpi.java | 78 ----
.../format/DefaultConfigurationFormatSpi.java | 78 ++++
.../tamaya/core/internal/format/IniFormat.java | 2 +-
.../core/internal/format/PropertiesFormat.java | 2 +-
.../internal/format/PropertiesXmlFormat.java | 2 +-
.../inject/ConfigChangeCallbackMethod.java | 6 +-
.../internal/inject/ConfigurationInjector.java | 6 -
.../core/internal/inject/ConfiguredMethod.java | 116 ------
.../internal/inject/ConfiguredSetterMethod.java | 136 +++++++
.../core/internal/inject/ConfiguredType.java | 154 ++++----
.../core/internal/inject/InjectionUtils.java | 80 ++++-
.../properties/DefaultCodecsSingletonSpi.java | 170 ---------
.../resources/DefaultPathResourceLoader.java | 81 -----
.../resources/DefaultResourceLoader.java | 81 +++++
.../AbstractClasspathAwarePropertySource.java | 9 +-
.../core/properties/AbstractPropertySource.java | 36 +-
.../properties/AggregatedPropertySource.java | 11 +-
.../properties/BuildablePropertySource.java | 22 +-
.../properties/ContextualPropertySource.java | 37 +-
.../properties/DelegatingPropertySource.java | 34 +-
.../properties/EnvironmentPropertySource.java | 4 +-
.../core/properties/FilteredPropertySource.java | 10 +-
.../core/properties/FreezedPropertySource.java | 38 +-
.../properties/IntersectingPropertySource.java | 24 +-
.../core/properties/MapBasedPropertySource.java | 14 +-
.../properties/PathBasedPropertySource.java | 17 +-
.../core/properties/PropertySourceBuilder.java | 256 +++++---------
.../core/properties/PropertySourceFactory.java | 133 ++++---
.../properties/ReplacingPropertySource.java | 31 +-
.../properties/SubtractingPropertySource.java | 11 +-
.../SystemPropertiesPropertySource.java | 19 +-
.../core/properties/URLBasedPropertySource.java | 20 +-
.../tamaya/core/resource/ResourceLoader.java | 8 +-
.../tamaya/core/spi/AdapterProviderSpi.java | 36 --
.../tamaya/core/spi/CodecProviderSpi.java | 36 ++
.../tamaya/core/spi/ConfigurationFormat.java | 57 ---
.../tamaya/core/spi/ConfigurationFormatSpi.java | 61 ++++
.../spi/ConfigurationFormatsSingletonSpi.java | 60 ----
.../tamaya/core/spi/EnvironmentProvider.java | 46 ---
.../core/spi/ObjectConfiguratorService.java | 37 --
.../tamaya/core/spi/ObjectConfiguratorSpi.java | 37 ++
.../tamaya/core/spi/PropertyAdapterService.java | 128 +++----
.../resources/META-INF/java-config-1.0.0.xsd | 80 -----
.../src/main/resources/META-INF/java-config.xml | 33 --
.../resources/META-INF/meta-model.properties | 39 --
...pache.tamaya.core.config.ConfigurationFormat | 21 ++
...g.apache.tamaya.core.resource.ResourceLoader | 2 +-
...g.apache.tamaya.core.spi.ConfigurationFormat | 21 --
...pache.tamaya.core.spi.ConfigurationFormatSpi | 19 +
...ya.core.spi.ConfigurationFormatsSingletonSpi | 19 -
...g.apache.tamaya.core.spi.EnvironmentProvider | 22 --
.../services/org.apache.tamaya.spi.CodecSpi | 19 +
.../org.apache.tamaya.spi.CodecsSingletonSpi | 19 -
....tamaya.spi.ConfigurationManagerSingletonSpi | 19 -
.../org.apache.tamaya.spi.ConfigurationSpi | 19 +
...he.tamaya.spi.EnvironmentManagerSingletonSpi | 19 -
.../org.apache.tamaya.spi.StagesSingletonSpi | 19 -
...tionManagerSingletonSpiSingletonSpiTest.java | 35 +-
.../java/org/apache/tamaya/JavaOneDemo.java | 9 +-
.../config/ConfiguredSystemPropertiesTest.java | 94 +++++
.../core/config/EnvironmentManagerTest.java | 40 ---
.../env/ConfiguredSystemPropertiesTest.java | 46 ---
.../tamaya/core/env/EnvironmentManagerTest.java | 66 ----
.../internal/MutableTestConfigProvider.java | 8 +-
.../internal/TestEnvironmentProvider.java | 48 ---
.../annotations/AutoConfiguredClass.java | 91 +++++
.../samples/annotations/AutoConfiguredTest.java | 43 +++
.../simple/SimplePropertiesAndCLISample.java | 9 +-
.../apache/tamaya/ucs/UC1ReadProperties.java | 27 +-
.../apache/tamaya/ucs/UC2CombineProperties.java | 2 +-
...g.apache.tamaya.core.spi.EnvironmentProvider | 2 +-
core/src/test/resources/cfg/autoloaded.xml | 33 ++
core/src/test/resources/cfg/test.xml | 7 +
.../apache/tamaya/management/ManagedConfig.java | 2 +-
.../tamaya/management/ManagedConfigMBean.java | 2 +-
.../tamaya/management/ManagedEnvironment.java | 2 +-
.../management/ManagedEnvironmentMBean.java | 3 +-
modules/integration/pom.xml | 41 +--
.../se/ConfiguredSystemProperties.java | 353 +++++++++++++++++++
.../environment/BuildableEnvironment.java | 109 ++++++
.../metamodel/environment/Environment.java | 86 +++++
.../environment/EnvironmentBuilder.java | 97 +++++
...DependentApplicationEnvironmentProvider.java | 101 ++++++
...ssLoaderDependentEarEnvironmentProvider.java | 108 ++++++
.../internal/InitialEnvironmentProvider.java | 74 ++++
.../internal/SingleEnvironmentManager.java | 70 ++++
.../SystemClassLoaderEnvironmentProvider.java | 74 ++++
.../environment/spi/EnvironmentProvider.java | 44 +++
.../environment/spi/EnvironmentSpi.java | 49 +++
...g.apache.tamaya.core.spi.EnvironmentProvider | 22 ++
.../org.apache.tamaya.spi.EnvironmentSpi | 19 +
.../environment/EnvironmentManagerTest.java | 66 ++++
.../TestEnvironmentManagerSingleton.java | 37 ++
.../environment/TestEnvironmentProvider.java | 48 +++
modules/metamodels/pom.xml | 1 +
modules/pom.xml | 1 +
140 files changed, 3859 insertions(+), 4101 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Codec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Codec.java b/api/src/main/java/org/apache/tamaya/Codec.java
index 4afaacb..90b9676 100644
--- a/api/src/main/java/org/apache/tamaya/Codec.java
+++ b/api/src/main/java/org/apache/tamaya/Codec.java
@@ -20,6 +20,8 @@ package org.apache.tamaya;
import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecSpi;
+import org.apache.tamaya.spi.ServiceContext;
/**
* Interface for an codec that converts a configured String into something else and vice versa.
@@ -54,7 +56,7 @@ public interface Codec<T>{
* @return any adapter replaced with the new adapter, or null.
*/
public static <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
- return Codecs.register(targetType, adapter);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).register(targetType, adapter);
}
/**
@@ -63,7 +65,7 @@ public interface Codec<T>{
* @return true, if the given target type is supported.
*/
public static boolean isTargetTypeSupported(Class<?> targetType){
- return Codecs.isTargetTypeSupported(targetType);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).isTargetTypeSupported(targetType);
}
/**
@@ -74,7 +76,7 @@ public interface Codec<T>{
* @throws ConfigException if the target type is not supported.
*/
public static <T> Codec<T> getInstance(Class<T> targetType){
- return Codecs.getCodec(targetType);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).getCodec(targetType, null);
}
/**
@@ -88,7 +90,7 @@ public interface Codec<T>{
* instantiated.
*/
public static <T> Codec<T> getInstance(Class<T> targetType, WithCodec annotation){
- return Codecs.getCodec(targetType, annotation);
+ return ServiceContext.getInstance().getSingleton(CodecSpi.class).getCodec(targetType, annotation);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Codecs.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Codecs.java b/api/src/main/java/org/apache/tamaya/Codecs.java
deleted file mode 100644
index 444c7c8..0000000
--- a/api/src/main/java/org/apache/tamaya/Codecs.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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;
-
-import org.apache.tamaya.annotation.WithCodec;
-import org.apache.tamaya.spi.CodecsSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Singleton manager that provides {@link Codec} instance, usable for converting String
- * based configuration entries into any other target types and vice versa.
- * @see org.apache.tamaya.Codec
- */
-final class Codecs {
-
- /**
- * Orivate singleton constructor.
- */
- private Codecs(){}
-
- /**
- * Registers a new {@link Codec} for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- public static <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
- return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).register(targetType, adapter);
- }
-
- /**
- * Checks if a {@link Codec} for given target type is available.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- public static boolean isTargetTypeSupported(Class<?> targetType){
- return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).isTargetTypeSupported(targetType);
- }
-
- /**
- * Get an {@link Codec} converting to and from the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding {@link Codec}, never null.
- * @throws ConfigException if the target type is not supported.
- */
- public static <T> Codec<T> getCodec(Class<T> targetType){
- return getCodec(targetType, null);
- }
-
- /**
- * Get an {@link Codec} converting to the given target type.
- * @param targetType the target type class
- * @param annotation the {@link org.apache.tamaya.annotation.WithCodec} annotation, or null. If the annotation is not null and
- * defines an overriding adapter, this instance is created and returned.
- * @param <T> the target type
- * @return the corresponding {@link Codec}, never null.
- * @throws ConfigException if the target type is not supported, or the overriding adapter cannot be
- * instantiated.
- */
- public static <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation){
- return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).getCodec(targetType, annotation);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java b/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
index 4ff02ca..dda7701 100644
--- a/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
+++ b/api/src/main/java/org/apache/tamaya/ConfigChangeSet.java
@@ -19,6 +19,7 @@
package org.apache.tamaya;
import java.beans.PropertyChangeEvent;
+import java.io.Serializable;
import java.util.*;
/**
@@ -28,7 +29,9 @@ import java.util.*;
*
* Created by Anatole on 22.10.2014.
*/
-public final class ConfigChangeSet {
+public final class ConfigChangeSet implements Serializable{
+
+ private static final long serialVersionUID = 1l;
/** The base property provider/configuration. */
private PropertySource propertySource;
/** The base version, usable for optimistic locking. */
@@ -41,19 +44,17 @@ public final class ConfigChangeSet {
* @param propertyProvider The base property provider/configuration, not null.
* @return an empty ConfigChangeSet instance.
*/
- public static final ConfigChangeSet emptyChangeSet(PropertySource propertyProvider){
- return new ConfigChangeSet(propertyProvider, "<empty>", Collections.emptySet());
+ public static ConfigChangeSet emptyChangeSet(PropertySource propertyProvider){
+ return new ConfigChangeSet(propertyProvider, Collections.emptySet());
}
/**
* Constructor used by {@link ConfigChangeSetBuilder}.
* @param propertySource The base property provider/configuration, not null.
- * @param baseVersion The base version, usable for optimistic locking.
* @param changes The recorded changes, not null.
*/
- ConfigChangeSet(PropertySource propertySource, String baseVersion, Collection<PropertyChangeEvent> changes) {
+ ConfigChangeSet(PropertySource propertySource, Collection<PropertyChangeEvent> changes) {
this.propertySource = Objects.requireNonNull(propertySource);
- this.baseVersion = baseVersion;
changes.forEach((c) -> this.changes.put(c.getPropertyName(), c));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java b/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
index 9cd81b5..13d8fb3 100644
--- a/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
+++ b/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
@@ -43,10 +43,6 @@ public final class ConfigChangeSetBuilder {
*/
PropertySource source;
/**
- * The base version, if any. Used for optimistic version checking.
- */
- String baseVersion;
- /**
* Codesc provider, or null.
*/
Function<String, Codec> codecs;
@@ -55,13 +51,11 @@ public final class ConfigChangeSetBuilder {
* Constructor.
*
* @param source the underlying configuration/provider, not null.
- * @param baseVersion the base version, used for optimistic version checking.
* @param codecs function to provide customized codecs, when according values are changed, if not set the
* default codecs provided by {@link Codec#getInstance(Class)} are used.
*/
- private ConfigChangeSetBuilder(PropertySource source, String baseVersion, Function<String, Codec> codecs) {
+ private ConfigChangeSetBuilder(PropertySource source, Function<String, Codec> codecs) {
this.source = Objects.requireNonNull(source);
- this.baseVersion = baseVersion;
this.codecs = codecs;
}
@@ -72,7 +66,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(PropertySource source) {
- return new ConfigChangeSetBuilder(source, Instant.now().toString(), null);
+ return new ConfigChangeSetBuilder(source, null);
}
/**
@@ -84,31 +78,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(PropertySource source, Function<String, Codec> codecs) {
- return new ConfigChangeSetBuilder(source, Instant.now().toString(), codecs);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @param baseVersion the base version to be used.
- * @return the builder for chaining.
- */
- public static ConfigChangeSetBuilder of(PropertySource source, String baseVersion) {
- return new ConfigChangeSetBuilder(source, baseVersion, null);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @param baseVersion the base version to be used.
- * @param codecs function to provide customized codecs, when according values are changed, if not set the
- * default codecs provided by {@link Codec#getInstance(Class)} are used.
- * @return the builder for chaining.
- */
- public static ConfigChangeSetBuilder of(PropertySource source, String baseVersion, Function<String, Codec> codecs) {
- return new ConfigChangeSetBuilder(source, baseVersion, codecs);
+ return new ConfigChangeSetBuilder(source, codecs);
}
/**
@@ -118,7 +88,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(Configuration configuration) {
- return new ConfigChangeSetBuilder(configuration, configuration.getVersion(), null);
+ return new ConfigChangeSetBuilder(configuration, null);
}
/**
@@ -130,7 +100,7 @@ public final class ConfigChangeSetBuilder {
* @return the builder for chaining.
*/
public static ConfigChangeSetBuilder of(Configuration configuration, Function<String, Codec> codecs) {
- return new ConfigChangeSetBuilder(configuration, configuration.getVersion(), codecs);
+ return new ConfigChangeSetBuilder(configuration, codecs);
}
@@ -389,7 +359,7 @@ public final class ConfigChangeSetBuilder {
*/
public ConfigChangeSetBuilder deleteAll() {
this.delta.clear();
- this.source.toMap().forEach((k, v) ->
+ this.source.getProperties().forEach((k, v) ->
this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
return this;
}
@@ -417,7 +387,7 @@ public final class ConfigChangeSetBuilder {
* @return the new change set, never null.
*/
public ConfigChangeSet build() {
- return new ConfigChangeSet(this.source, baseVersion, Collections.unmodifiableCollection(this.delta.values()));
+ return new ConfigChangeSet(this.source, Collections.unmodifiableCollection(this.delta.values()));
}
/**
@@ -430,7 +400,7 @@ public final class ConfigChangeSetBuilder {
*/
public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
List<PropertyChangeEvent> changes = new ArrayList<>();
- for (Map.Entry<String, String> en : map1.toMap().entrySet()) {
+ for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
Optional<String> val = map2.get(en.getKey());
if (!val.isPresent()) {
changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
@@ -438,7 +408,7 @@ public final class ConfigChangeSetBuilder {
changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
}
}
- for (Map.Entry<String, String> en : map2.toMap().entrySet()) {
+ for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
Optional<String> val = map1.get(en.getKey());
if (!val.isPresent()) {
changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Configuration.java b/api/src/main/java/org/apache/tamaya/Configuration.java
index 775078b..543a515 100644
--- a/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
import java.util.*;
import java.util.function.Consumer;
-import java.util.function.Predicate;
import java.util.function.UnaryOperator;
-import java.util.stream.Collectors;
/**
* A configuration models a aggregated set current properties, identified by a unique key, but adds higher level access functions to
@@ -147,90 +148,7 @@ public interface Configuration extends PropertySource {
* type.
*/
default <T> Optional<T> get(String key, Class<T> type){
- return getAdapted(key, Codecs.getCodec(type));
- }
-
- /**
- * Return a set with all fully qualifies area names. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @return s set with all areas, never {@code null}.
- */
- default Set<String> getAreas(){
- final Set<String> areas = new HashSet<>();
- this.keySet().forEach(s -> {
- int index = s.lastIndexOf('.');
- if(index > 0){
- areas.add(s.substring(0, index));
- }
- else{
- areas.add("<root>");
- }
- });
- return areas;
- }
-
- /**
- * Return a set with all fully qualified area names, containing the transitive closure also including all
- * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate
- * as possible, but may not provide a complete set of areas that are finally accessible, especially when the
- * underlying storage does not support key iteration.
- *
- * @return s set with all transitive areas, never {@code null}.
- */
- default Set<String> getTransitiveAreas(){
- final Set<String> transitiveAreas = new HashSet<>();
- getAreas().forEach(s -> {
- int index = s.lastIndexOf('.');
- if (index < 0) {
- transitiveAreas.add("<root>");
- } else {
- while (index > 0) {
- s = s.substring(0, index);
- transitiveAreas.add(s);
- index = s.lastIndexOf('.');
- }
- }
- });
- return transitiveAreas;
- }
-
- /**
- * Return a set with all fully qualified area names, containing only the
- * areas that match the predicate and have properties attached. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
- * @return s set with all areas, never {@code null}.
- */
- default Set<String> getAreas(final Predicate<String> predicate){
- return getAreas().stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
- }
-
- /**
- * Return a set with all fully qualified area names, containing the transitive closure also including all
- * subarea names, regardless if properties are accessible or not. This method should return the areas as accurate as possible,
- * but may not provide a complete set of areas that are finally accessible, especially when the underlying storage
- * does not support key iteration.
- *
- * @param predicate A predicate to deternine, which areas should be returned, not {@code null}.
- * @return s set with all transitive areas, never {@code null}.
- */
- default Set<String> getTransitiveAreas(Predicate<String> predicate){
- return getTransitiveAreas().stream().filter(predicate).collect(Collectors.toCollection(TreeSet::new));
- }
-
- /**
- * Allows to evaluate if an area exists. In case where the underlying storage implementation does not allow
- * querying the keys available, {@code false} should be returned.
- *
- * @param areaKey the configuration area (sub)path.
- * @return {@code true}, if such a node exists.
- */
- default boolean containsArea(String areaKey){
- return getAreas().contains(areaKey);
+ return getAdapted(key, Codec.getInstance(type));
}
/**
@@ -254,14 +172,6 @@ public interface Configuration extends PropertySource {
return query.query(this);
}
- /**
- * Field that allows property config to be versioned, meaning that each change on a provider requires this keys
- * to be incremented by one. This can be easily used to implement versioning (and optimistic locking)
- * in distributed (remote) usage scenarios.
- * @return the version current the current instance, or 'N/A'.
- */
- default String getVersion(){return "N/A";}
-
/**
* Allows to check if a configuration with a given name is defined.
@@ -269,11 +179,10 @@ public interface Configuration extends PropertySource {
* @param name the configuration's name, not null, not empty.
* @return true, if such a configuration is defined.
*/
- public static boolean isDefined(String name){
- return ConfigurationManager.isConfigurationDefined(name);
+ public static boolean isAvailable(String name){
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).isConfigurationAvailable(name);
}
-
/**
* Access a configuration by name.
*
@@ -282,7 +191,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if no such configuration is defined.
*/
public static Configuration current(String name){
- return ConfigurationManager.getConfiguration(name);
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).getConfiguration(name);
}
/**
@@ -292,7 +201,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if no such configuration is defined.
*/
public static Configuration current(){
- return ConfigurationManager.getConfiguration();
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).getConfiguration();
}
/**
@@ -307,7 +216,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if the configuration could not be resolved.
*/
public static <T> T createTemplate(Class<T> type, Configuration... configurations){
- return ConfigurationManager.createTemplate(type, configurations);
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).createTemplate(type, configurations);
}
/**
@@ -322,7 +231,7 @@ public interface Configuration extends PropertySource {
* @throws ConfigException if the configuration could not be resolved.
*/
public static void configure(Object instance, Configuration... configurations){
- ConfigurationManager.configure(instance, configurations);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).configure(instance, configurations);
}
/**
@@ -335,7 +244,7 @@ public interface Configuration extends PropertySource {
* @return the evaluated config expression.
*/
public static String evaluateValue(String expression, Configuration... configurations){
- return ConfigurationManager.evaluateValue(expression, configurations);
+ return ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).evaluateValue(expression, configurations);
}
/**
@@ -343,7 +252,7 @@ public interface Configuration extends PropertySource {
* @param l the listener, not null.
*/
public static void addChangeListener(Consumer<ConfigChangeSet> l){
- ConfigurationManager.addChangeListener(l);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).addChangeListener(l);
}
/**
@@ -351,7 +260,7 @@ public interface Configuration extends PropertySource {
* @param l the listener, not null.
*/
public static void removeChangeListener(Consumer<ConfigChangeSet> l){
- ConfigurationManager.removeChangeListener(l);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).removeChangeListener(l);
}
/**
@@ -362,7 +271,7 @@ public interface Configuration extends PropertySource {
* @param configChange the change to be published, not null.
*/
public static void publishChange(ConfigChangeSet configChange){
- ConfigurationManager.publishChange(configChange);
+ ServiceContext.getInstance().getSingleton(ConfigurationSpi.class).publishChange(configChange);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigurationManager.java b/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
deleted file mode 100644
index c753b22..0000000
--- a/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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;
-
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
-
-import java.util.*;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-/**
- * Singleton accessor for accessing {@link Configuration} instances and
- * proxied configuration templates.
- */
-final class ConfigurationManager{
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationManager(){
- }
-
- /**
- * Allows to check if a configuration with a given name is defined.
- *
- * @param name the configuration's name, not null, not empty.
- * @return true, if such a configuration is defined.
- */
- public static boolean isConfigurationDefined(String name){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).isConfigurationDefined(name);
- }
-
-
- /**
- * Access a configuration by name.
- *
- * @param name the configuration's name, not null, not empty.
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static Configuration getConfiguration(String name){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).getConfiguration(name);
- }
-
- /**
- * Access a configuration.
- *
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static Configuration getConfiguration(){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).getConfiguration();
- }
-
- /**
- * Access a typed configuration, based on the default configuration.
- *
- * @param type the annotated configuration type (could be an interface or
- * a non abstract class), not null.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @return the corresponding typed Configuration instance, never null.
- * @throws ConfigException if the configuration could not be resolved.
- */
- public static <T> T createTemplate(Class<T> type, Configuration... configurations){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).createTemplate(type, configurations);
- }
-
- /**
- * Configures an instance, by resolving and injecting the configuration
- * entries.
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
- * If no items are passed, the default configuration is used.
- * @throws ConfigException if the configuration could not be resolved.
- */
- public static void configure(Object instance, Configuration... configurations){
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).configure(instance, configurations);
- }
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- *
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- public static String evaluateValue(String expression, Configuration... configurations){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).evaluateValue(expression, configurations);
- }
-
- /**
- * Add a ConfigChangeSet listener to the given configuration instance.
- * @param l the listener, not null.
- */
- public static void addChangeListener(Consumer<ConfigChangeSet> l) {
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).addChangeListener(Objects.requireNonNull(l));
- }
-
- /**
- * Removes a ConfigChangeSet listener from the given configuration instance.
- * @param l the listener, not null.
- */
- public static void removeChangeListener(Consumer<ConfigChangeSet> l) {
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).removeChangeListener(Objects.requireNonNull(l));
- }
-
- /**
- * Method to publish changes on a {@link org.apache.tamaya.Configuration} to all interested parties.
- * Basically this method gives an abstraction on the effective event bus design fo listeners. In a CDI context
- * the CDI enterprise event bus should be used internally to do the work, whereas in a SE only environment
- * a more puristic approach would be useful.
- * @param configChange the change to be published, not null.
- */
- public static void publishChange(ConfigChangeSet configChange) {
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).publishChange(Objects.requireNonNull(configChange));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfiguredValue.java b/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
new file mode 100644
index 0000000..839e67e
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/ConfiguredValue.java
@@ -0,0 +1,261 @@
+/*
+ * 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;
+
+import org.apache.tamaya.annotation.LoadPolicy;
+
+import java.beans.PropertyChangeEvent;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may be reinjected, reconfigured.
+ * <h3>Implementation Requirements</h3>
+ * Instances of this class must be
+ * <ul>
+ * <li>Serializable</li>
+ * <li>Immutable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ */
+public interface ConfiguredValue<T> {
+
+ /**
+ * Access the {@link org.apache.tamaya.annotation.LoadPolicy} used for updating this value.
+ * @return the load policy, never null.
+ */
+ LoadPolicy getLoadPolicy();
+
+ /**
+ * get the UTC timestamp in ms of the last access to a value, using get().
+ * @return the UTC timestamp of the last access
+ */
+ long getLastAccess();
+
+ /**
+ * get the UTC timestamp in ms of the last update to the value,.
+ * @return the UTC timestamp of the last update
+ */
+ long getLastUpdate();
+
+ /**
+ * Access if this instance has been updated since the given UTC timestamp in ms.
+ * @param timestamp
+ * @return true, if his instance has been updated since the given UTC timestamp in ms.
+ */
+ boolean isUpdatedSince(long timestamp);
+
+ /**
+ * Access if this instance has been accessed since the given UTC timestamp in ms.
+ * @param timestamp
+ * @return true, if his instance has been accessed since the given UTC timestamp in ms.
+ */
+ boolean isAccessedSince(long timestamp);
+
+ /**
+ * Add a listener to be called, when this value is changed.
+ * @param l the listner, not null
+ */
+ void addListener(Consumer<PropertyChangeEvent> l);
+
+ /**
+ * Removes a listener to be called, when this value is changed.
+ * @param l the listner to be removed, not null
+ */
+ void removeListener(Consumer<PropertyChangeEvent> l);
+
+ /**
+ * Get some descriptive meta info on the current value.
+ * @return the meta info, not null.
+ */
+ String getMetaInfo();
+
+ /**
+ * Evaluate if the item value has been updated since the last access.
+ * @return true, if item value has been updated since the last access.
+ */
+ default boolean isUpdated(){
+ return isUpdatedSince(getLastAccess());
+ }
+
+ /**
+ * If a value is present in this {@code ConfiguredValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see ConfiguredValue#isPresent()
+ */
+ T get();
+
+ /**
+ * If a value is present in this {@code ConfiguredValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see ConfiguredValue#isPresent()
+ */
+ default T updateAndGet(){
+ update();
+ return get();
+ }
+
+ /**
+ * Reevaluates the current value based on the instance's settings from the underlying configurations
+ * and applies the new value to its internal state. On change any registered listeners will be triggered.
+ */
+ void update();
+
+ /**
+ * Return {@code true} if there is a value present, otherwise {@code false}.
+ *
+ * @return {@code true} if there is a value present, otherwise {@code false}
+ */
+ 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
+ */
+ void ifPresent(Consumer<? super T> consumer);
+
+ /**
+ * If a value is present, and the value matches the given predicate,
+ * return an {@code Optional} describing the value, otherwise return an
+ * empty {@code Optional}.
+ *
+ * @param predicate a predicate to apply to the value, if present
+ * @return an {@code Optional} describing the value of this {@code Optional}
+ * if a value is present and the value matches the given predicate,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the predicate is null
+ */
+ ConfiguredValue<T> filter(Predicate<? super T> predicate);
+
+ /**
+ * If a value is present, apply the provided mapping function to it,
+ * and if the result is non-null, return an {@code Optional} describing the
+ * result. Otherwise return an empty {@code Optional}.
+ *
+ * @apiNote This method supports post-processing on optional values, without
+ * the need to explicitly check for a return status. For example, the
+ * following code traverses a stream of file names, selects one that has
+ * not yet been processed, and then opens that file, returning an
+ * {@code Optional<FileInputStream>}:
+ *
+ * <pre>{@code
+ * Optional<FileInputStream> fis =
+ * names.stream().filter(name -> !isProcessedYet(name))
+ * .findFirst()
+ * .map(name -> new FileInputStream(name));
+ * }</pre>
+ *
+ * Here, {@code findFirst} returns an {@code Optional<String>}, and then
+ * {@code map} returns an {@code Optional<FileInputStream>} for the desired
+ * file if one exists.
+ *
+ * @param <U> The type of the result of the mapping function
+ * @param mapper a mapping function to apply to the value, if present
+ * @return an {@code Optional} describing the result of applying a mapping
+ * function to the value of this {@code Optional}, if a value is present,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the mapping function is null
+ */
+ <U> ConfiguredValue<U> map(Function<? super T, ? extends U> mapper);
+
+ /**
+ * If a value is present, apply the provided {@code Optional}-bearing
+ * mapping function to it, return that result, otherwise return an empty
+ * {@code Optional}. This method is similar to {@link #map(Function)},
+ * but the provided mapper is one whose result is already an {@code Optional},
+ * and if invoked, {@code flatMap} does not wrap it with an additional
+ * {@code Optional}.
+ *
+ * @param <U> The type parameter to the {@code Optional} returned by
+ * @param mapper a mapping function to apply to the value, if present
+ * the mapping function
+ * @return the result of applying an {@code Optional}-bearing mapping
+ * function to the value of this {@code Optional}, if a value is present,
+ * otherwise an empty {@code Optional}
+ * @throws NullPointerException if the mapping function is null or returns
+ * a null result
+ */
+ <U> ConfiguredValue<U> flatMap(Function<? super T, ConfiguredValue<U>> mapper);
+
+ /**
+ * 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}
+ */
+ T orElse(T other);
+
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code Supplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ T orElseGet(Supplier<? extends T> other);
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ *
+ * @apiNote A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
+
+ /**
+ * Converts this value to an {@link java.util.Optional} instance.
+ * @return an {@link java.util.Optional} instance, never null.
+ */
+ default Optional<T> toOptional(){
+ if(isPresent()){
+ return Optional.of(get());
+ }
+ return Optional.empty();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/Environment.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Environment.java b/api/src/main/java/org/apache/tamaya/Environment.java
deleted file mode 100644
index 11e7100..0000000
--- a/api/src/main/java/org/apache/tamaya/Environment.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-/**
- * Models a runtime environment. Instances current this class are used to
- * evaluate the correct configuration artifacts.<br/>
- * <h3>Implementation Requirements</h3>
- * <p>
- * Implementations current this interface must be
- * <ul>
- * <li>Thread safe.
- * <li>Immutable
- * <li>serializable
- * </ul>
- */
-public interface Environment{
-
- /**
- * Access a property.
- * @param key the property's key, not null.
- * @return the property's keys.
- */
- Optional<String> get(String key);
-
- /**
- * Checks if a property is defined.
- * @param key the property's key, not null.
- * @return true, if the property is existing.
- */
- boolean containsKey(String key);
-
- /**
- * Access the set current property keys, defined by this provider.
- * @return the key set, never null.
- */
- Set<String> keySet();
-
- /**
- * Access the environment as Map.
- * @return the Map instance containing the environments properties, never null.
- */
- Map<String,String> toMap();
-
- /**
- * Get the current {@link org.apache.tamaya.Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static Environment current(){
- return EnvironmentManager.getCurrentEnvironment();
- }
-
- /**
- * Get the current {@link org.apache.tamaya.Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static Environment root(){
- return EnvironmentManager.getRootEnvironment();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/EnvironmentManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/EnvironmentManager.java b/api/src/main/java/org/apache/tamaya/EnvironmentManager.java
deleted file mode 100644
index 1c60d95..0000000
--- a/api/src/main/java/org/apache/tamaya/EnvironmentManager.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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;
-
-import org.apache.tamaya.spi.EnvironmentManagerSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-
-/**
- * Singleton accessor class for the current environment.
- */
-final class EnvironmentManager{
-
- /**
- * Private singleton constructor.
- */
- private EnvironmentManager(){}
-
- /**
- * Get the current {@link Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the current Environment, never null.
- */
- public static Environment getCurrentEnvironment(){
- return ServiceContext.getInstance().getSingleton(EnvironmentManagerSingletonSpi.class).getCurrentEnvironment();
- }
-
- /**
- * Get the root {@link Environment}. The environment is used to determine the current runtime state, which
- * is important for returning the correct configuration.
- * @return the root Environment, never null.
- */
- public static Environment getRootEnvironment(){
- return ServiceContext.getInstance().getSingleton(EnvironmentManagerSingletonSpi.class).getRootEnvironment();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/PropertySource.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertySource.java b/api/src/main/java/org/apache/tamaya/PropertySource.java
index 9179c8f..2cd3af7 100644
--- a/api/src/main/java/org/apache/tamaya/PropertySource.java
+++ b/api/src/main/java/org/apache/tamaya/PropertySource.java
@@ -18,10 +18,7 @@
*/
package org.apache.tamaya;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
/**
* This interface models a provider that serves configuration properties. The contained
@@ -48,30 +45,35 @@ public interface PropertySource {
*/
public static final PropertySource EMPTY_PROPERTYSOURCE = new PropertySource() {
- private MetaInfo metaInfo = MetaInfo.of("<empty>");
-
@Override
- public Optional<String> get(String key) {
- return Optional.empty();
+ public String getName() {
+ return "<empty>";
}
@Override
- public boolean containsKey(String key) {
- return false;
+ public Optional<String> get(String key) {
+ return Optional.empty();
}
@Override
- public Map<String, String> toMap() {
+ public Map<String, String> getProperties() {
return Collections.emptyMap();
}
@Override
- public MetaInfo getMetaInfo() {
- return metaInfo;
+ public String toString(){
+ return "PropertySource [name=<empty>]";
}
};
/**
+ * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
+ * to ensure unique identity, either locally or remotely.
+ * @return the configuration's name, never null.
+ */
+ String getName();
+
+ /**
* Access a property.
*
* @param key the property's key, not null.
@@ -80,47 +82,35 @@ public interface PropertySource {
Optional<String> get(String key);
/**
- * Get the meta-info current a configuration.
+ * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
+ * when the underlying storage does not support iteration of its entries.
*
- * @return the configuration's/config map's metaInfo, or null.
- */
- MetaInfo getMetaInfo();
-
- /**
- * Checks if a property is defined/accessible.
- * @throws java.lang.UnsupportedOperationException If the underlying storage does not support introspection.
- * @param key the property's key, not null.
- * @return true, if the property is existing.
+ * @return the a corresponding map, never null.
*/
- boolean containsKey(String key);
+ Map<String, String> getProperties();
/**
- * Allows to quickly check, if a provider is empty.
- * @return true, if the provier is empty.
+ * Determines if this config source should be scanned for its list of properties.
+ *
+ * Generally, slow ConfigSources should return false here.
+ *
+ * @return true if this ConfigSource should be scanned for its list of properties,
+ * false if it should not be scanned.
*/
- default boolean isEmpty(){
- return keySet().isEmpty();
+ default boolean isScannable(){
+ return true;
}
/**
- * Access the set current property keys, defined by this provider. The resulting Set may not return all keys
- * accessible, e.g. when the underlying storage does not support iteration of its entries.
+ * Allows to quickly check, if a provider is empty.
*
- * @return the key set, never null.
+ * @return true, if the provier is empty.
*/
- default Set<String> keySet() {
- return toMap().keySet();
+ default boolean isEmpty() {
+ return getProperties().isEmpty();
}
/**
- * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
- * when the underlying storage does not support iteration of its entries.
- * @return the a corresponding map, never null.
- */
- Map<String, String> toMap();
-
-
- /**
* Reloads the {@link PropertySource}.
*/
default ConfigChangeSet load() {
@@ -158,24 +148,48 @@ public interface PropertySource {
default Configuration toConfiguration() {
return new Configuration() {
@Override
- public Optional<String> get(String key) {
- return PropertySource.this.get(key);
+ public String getName() {
+ return PropertySource.this.getName();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return PropertySource.this.isScannable();
+ }
+
+ @Override
+ public boolean isMutable() {
+ return PropertySource.this.isMutable();
}
+
+ @Override
+ public void applyChanges(ConfigChangeSet changes) {
+ PropertySource.this.applyChanges(changes);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return PropertySource.this.isEmpty();
+ }
+
@Override
- public boolean containsKey(String key) {
- return PropertySource.this.containsKey(key);
+ public ConfigChangeSet load() {
+ return PropertySource.this.load();
}
+
@Override
- public Map<String, String> toMap() {
- return PropertySource.this.toMap();
+ public Optional<String> get(String key) {
+ return PropertySource.this.get(key);
}
+
@Override
- public MetaInfo getMetaInfo() {
- return PropertySource.this.getMetaInfo();
+ public Map<String, String> getProperties() {
+ return PropertySource.this.getProperties();
}
+
@Override
public String toString() {
- return "Configuration [source: PropertySource "+getMetaInfo()+"]";
+ return "Configuration [name: " + getName() + "]";
}
};
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java b/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
new file mode 100644
index 0000000..845ec4c
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/annotation/NoConfig.java
@@ -0,0 +1,32 @@
+/*
+ * 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.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
+ * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
+ * using property or method names without annotations. With that annotation none of these will be happen.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface NoConfig {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java b/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java
new file mode 100644
index 0000000..7a0670b
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/spi/CodecSpi.java
@@ -0,0 +1,89 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.annotation.WithCodec;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * SPI that is used by the {@link org.apache.tamaya.Codecs} singleton as delegation instance.
+ */
+public interface CodecSpi {
+
+ /**
+ * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
+ * this type.
+ * @param targetType The target class, not null.
+ * @param adapter The adapter, not null.
+ * @param <T> The target type
+ * @return any adapter replaced with the new adapter, or null.
+ */
+ <T> Codec<T> register(Class<T> targetType, Codec<T> adapter);
+
+ default <T> Codec<T> register(Class<T> targetType, Function<String,T> decoder, Function<T, String> encoder){
+ Objects.requireNonNull(targetType);
+ Objects.requireNonNull(decoder);
+ Objects.requireNonNull(encoder);
+ return register(targetType, new Codec<T>(){
+
+ @Override
+ public T deserialize(String value) {
+ return decoder.apply(value);
+ }
+
+ @Override
+ public String serialize(T value) {
+ return encoder.apply(value);
+ }
+
+ @Override
+ public String toString(){
+ return "Codec(decoder="+decoder.getClass().getName()+", encoder="+encoder.getClass().getName()+")";
+ }
+ });
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ default <T> Codec<T> getAdapter(Class<T> targetType){
+ return getCodec(targetType, null);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws org.apache.tamaya.ConfigException if the target type is not supported.
+ */
+ <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation);
+
+ /**
+ * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ boolean isTargetTypeSupported(Class<?> targetType);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
deleted file mode 100644
index 07993e5..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.spi;
-
-import org.apache.tamaya.Codec;
-import org.apache.tamaya.annotation.WithCodec;
-
-import java.util.Objects;
-import java.util.function.Function;
-
-/**
- * SPI that is used by the {@link org.apache.tamaya.Codecs} singleton as delegation instance.
- */
-public interface CodecsSingletonSpi {
-
- /**
- * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- <T> Codec<T> register(Class<T> targetType, Codec<T> adapter);
-
- default <T> Codec<T> register(Class<T> targetType, Function<String,T> decoder, Function<T, String> encoder){
- Objects.requireNonNull(targetType);
- Objects.requireNonNull(decoder);
- Objects.requireNonNull(encoder);
- return register(targetType, new Codec<T>(){
-
- @Override
- public T deserialize(String value) {
- return decoder.apply(value);
- }
-
- @Override
- public String serialize(T value) {
- return encoder.apply(value);
- }
-
- @Override
- public String toString(){
- return "Codec(decoder="+decoder.getClass().getName()+", encoder="+encoder.getClass().getName()+")";
- }
- });
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- default <T> Codec<T> getAdapter(Class<T> targetType){
- return getCodec(targetType, null);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws org.apache.tamaya.ConfigException if the target type is not supported.
- */
- <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation);
-
- /**
- * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- boolean isTargetTypeSupported(Class<?> targetType);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
deleted file mode 100644
index 6be15a8..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.spi;
-
-import org.apache.tamaya.ConfigChangeSet;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-
-/**
- * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
- * using the {@link ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
- * The {@link org.apache.tamaya.ConfigurationManager} Singleton in the API delegates its corresponding calls to the
- * instance returned by the current bootstrap service in place.
- *
- * @see org.apache.tamaya.ConfigurationManager
- * @see ServiceContextManager
- */
-public interface ConfigurationManagerSingletonSpi{
-
- /**
- * Allows to check if a configuration with a given name is defined.
- * @param name the configuration's name, not null, not empty.
- * @return true, if such a configuration is defined.
- */
- boolean isConfigurationDefined(String name);
-
- /**
- * Access a configuration by name.
- * @param name the configuration's name, not null, not empty.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- Configuration getConfiguration(String name);
-
- /**
- * Access the default configuration.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- default Configuration getConfiguration(){
- return getConfiguration("default");
- }
-
- /**
- * Configures an instance, by resolving and injecting the configuration
- * entries.
- *
- * @param instance the instance with configuration annotations, not null.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
- */
- void configure(Object instance, Configuration... configurations);
-
- /**
- * Access a configuration by name.
- *
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @return the corresponding Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
- */
- <T> T createTemplate(Class<T> template, Configuration... configurations);
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
- * If no such config is passed, the default configurationa provided by the current
- * registered providers are used.
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- String evaluateValue(String expression, Configuration... configurations);
-
- /**
- * Add a ConfigChangeSet listener to the given configuration instance.
- * @@param l the listener, not null.
- */
- void addChangeListener(Consumer<ConfigChangeSet> l);
-
- /**
- * Removes a ConfigChangeSet listener from the given configuration instance.
- * @param l the listener, not null.
- */
- void removeChangeListener(Consumer<ConfigChangeSet> l);
-
- /**
- * Method to publish changes on a {@link org.apache.tamaya.Configuration} to all interested parties.
- * Basically this method gives an abstraction on the effective event bus design fo listeners. In a CDI context
- * the CDI enterprise event bus should be used internally to do the work, whereas in a SE only environment
- * a more puristic approach would be useful.
- * @param configChangeSet the change to be published, not null.
- */
- void publishChange(ConfigChangeSet configChangeSet);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
new file mode 100644
index 0000000..a5979a8
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationSpi.java
@@ -0,0 +1,116 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.ConfigChangeSet;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
+
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+/**
+ * Manager for {@link org.apache.tamaya.Configuration} instances. Implementations must register an instance
+ * using the {@link ServiceContextManager} mechanism in place (by default this is based on the {@link java.util.ServiceLoader}.
+ * The {@link org.apache.tamaya.ConfigurationManager} Singleton in the API delegates its corresponding calls to the
+ * instance returned by the current bootstrap service in place.
+ *
+ * @see org.apache.tamaya.ConfigurationManager
+ * @see ServiceContextManager
+ */
+public interface ConfigurationSpi {
+
+ /**
+ * Allows to check if a configuration with a given name is defined.
+ * @param name the configuration's name, not null, not empty.
+ * @return true, if such a configuration is defined.
+ */
+ boolean isConfigurationAvailable(String name);
+
+ /**
+ * Access a configuration by name.
+ * @param name the configuration's name, not null, not empty.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ Configuration getConfiguration(String name);
+
+ /**
+ * Access the default configuration.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ default Configuration getConfiguration(){
+ return getConfiguration("default");
+ }
+
+ /**
+ * Configures an instance, by resolving and injecting the configuration
+ * entries.
+ *
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
+ */
+ void configure(Object instance, Configuration... configurations);
+
+ /**
+ * Access a configuration by name.
+ *
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @return the corresponding Configuration instance, never null.
+ * @throws org.apache.tamaya.ConfigException if no such configuration is defined.
+ */
+ <T> T createTemplate(Class<T> template, Configuration... configurations);
+
+ /**
+ * Evaluate the current expression based on the current configuration valid.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ * @param expression the expression, not null.
+ * @return the evaluated config expression.
+ */
+ String evaluateValue(String expression, Configuration... configurations);
+
+ /**
+ * Add a ConfigChangeSet listener to the given configuration instance.
+ * @@param l the listener, not null.
+ */
+ void addChangeListener(Consumer<ConfigChangeSet> l);
+
+ /**
+ * Removes a ConfigChangeSet listener from the given configuration instance.
+ * @param l the listener, not null.
+ */
+ void removeChangeListener(Consumer<ConfigChangeSet> l);
+
+ /**
+ * Method to publish changes on a {@link org.apache.tamaya.Configuration} to all interested parties.
+ * Basically this method gives an abstraction on the effective event bus design fo listeners. In a CDI context
+ * the CDI enterprise event bus should be used internally to do the work, whereas in a SE only environment
+ * a more puristic approach would be useful.
+ * @param configChangeSet the change to be published, not null.
+ */
+ void publishChange(ConfigChangeSet configChangeSet);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java
deleted file mode 100644
index 84ac864..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/EnvironmentManagerSingletonSpi.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.spi;
-
-
-import org.apache.tamaya.Environment;
-
-/**
- * Service for accessing {@link org.apache.tamaya.Environment}. Environments are used to
- * access/determine configurations.<br/>
- * <h3>Implementation PropertyMapSpec</h3> This class is
- * <ul>
- * <li>thread safe,
- * <li>and behaves contextual.
- * </ul>
- */
-public interface EnvironmentManagerSingletonSpi{
-
- /**
- * Get the current environment current the given environment type.
- * @return the corresponding environment, never null.
- * @throws IllegalArgumentException if not such type is present or active.
- */
- Environment getCurrentEnvironment();
-
- /**
- * Get the current environment current the given environment type.
- * @return the corresponding environment, never null.
- * @throws IllegalArgumentException if not such type is present or active.
- */
- Environment getRootEnvironment();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a3c10d6e/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
index 89f8078..0ec2aa0 100644
--- a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
+++ b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
@@ -22,14 +22,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
-import java.util.function.Predicate;
-import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
+import org.apache.tamaya.spi.ConfigurationSpi;
/**
* Created by Anatole on 09.09.2014.
*/
-public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingletonSpi{
+public class TestConfigServiceSingletonSpi implements ConfigurationSpi {
private Map<String, Configuration> configs = new ConcurrentHashMap<>();
@@ -55,7 +54,7 @@ public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingle
@Override
- public boolean isConfigurationDefined(String name){
+ public boolean isConfigurationAvailable(String name){
return configs.containsKey(name);
}
@@ -81,7 +80,7 @@ public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingle
public String evaluateValue(String expression, Configuration... configurations) {
// TODO improve this ugly implementation...
for (Configuration config : configurations) {
- for (Map.Entry<String, String> en : config.toMap().entrySet()) {
+ for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
expression = expression.replaceAll("\\$\\{" + en.getKey() + "\\}", en.getValue());
}
}