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 2018/11/18 21:20:26 UTC
[08/20] incubator-tamaya-extensions git commit: TAMAYA-274 Reduced
API footprint by using Java 8 features. Added some lambdas. TAMAYA-355 Enable
mapping of lists and arrays into internal datastructures. TAMAYA-353 Adding
support for different classloa
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ServiceLoaderServiceContext.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ServiceLoaderServiceContext.java b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ServiceLoaderServiceContext.java
index 1b96a16..54bced1 100644
--- a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ServiceLoaderServiceContext.java
+++ b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ServiceLoaderServiceContext.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.cdi;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ClassloaderAware;
import org.apache.tamaya.spi.ServiceContext;
import org.apache.tamaya.spisupport.PriorityServiceComparator;
@@ -28,6 +29,7 @@ import java.net.URL;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -50,10 +52,10 @@ final class ServiceLoaderServiceContext implements ServiceContext {
private ClassLoader classLoader;
@Override
- public <T> T getService(Class<T> serviceType) {
+ public <T> T getService(Class<T> serviceType, Supplier<T> supplier) {
Object cached = singletons.get(serviceType);
if (cached == null) {
- cached = create(serviceType);
+ cached = create(serviceType, supplier);
if(cached!=null) {
singletons.put(serviceType, cached);
}
@@ -62,11 +64,18 @@ final class ServiceLoaderServiceContext implements ServiceContext {
}
@Override
- public <T> T create(Class<T> serviceType) {
+ public <T> T create(Class<T> serviceType, Supplier<T> supplier) {
Class<? extends T> implType = factoryTypes.get(serviceType);
if(implType==null) {
Collection<T> services = getServices(serviceType);
if (services.isEmpty()) {
+ if(supplier!=null){
+ T instance = supplier.get();
+ if(instance instanceof ClassloaderAware){
+ ((ClassloaderAware)instance).init(this.classLoader);
+ }
+ return instance;
+ }
return null;
} else {
return getServiceWithHighestPriority(services, serviceType);
@@ -75,7 +84,10 @@ final class ServiceLoaderServiceContext implements ServiceContext {
try {
return implType.newInstance();
} catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to create instance of " + implType.getName(), e);
+ LOG.log(Level.SEVERE, "Failed to createObject instance of " + implType.getName(), e);
+ if(supplier!=null){
+ return supplier.get();
+ }
return null;
}
}
@@ -88,14 +100,23 @@ final class ServiceLoaderServiceContext implements ServiceContext {
* @return the items found, never {@code null}.
*/
@Override
- public <T> List<T> getServices(final Class<T> serviceType) {
+ public <T> List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier) {
List<T> found = (List<T>) servicesLoaded.get(serviceType);
if (found != null) {
return found;
}
+ List<T> services = loadServices(serviceType, supplier);
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
+ return previousServices != null ? previousServices : services;
+ }
+
+ private <T> List<T> loadServices(Class<T> serviceType, Supplier<List<T>> supplier) {
List<T> services = new ArrayList<>();
try {
for (T t : ServiceLoader.load(serviceType)) {
+ if(t instanceof ClassloaderAware){
+ ((ClassloaderAware)t).init(classLoader);
+ }
services.add(t);
}
Collections.sort(services, PriorityServiceComparator.getInstance());
@@ -107,12 +128,20 @@ final class ServiceLoaderServiceContext implements ServiceContext {
services = Collections.emptyList();
}
}
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
- return previousServices != null ? previousServices : services;
+ if(services.isEmpty() && supplier!=null){
+ List<T> ts = supplier.get();
+ for (T t : ts) {
+ if(t instanceof ClassloaderAware){
+ ((ClassloaderAware)t).init(classLoader);
+ }
+ services.add(t);
+ }
+ }
+ return services;
}
/**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
+ * Checks the given instance for a @Priority annotation. If present the annotation's createValue s evaluated. If no such
* annotation is present, a default priority is returned (1);
* @param o the instance, not null.
* @return a priority, by default 1.
@@ -136,7 +165,7 @@ final class ServiceLoaderServiceContext implements ServiceContext {
*/
private <T> T getServiceWithHighestPriority(Collection<T> services, Class<T> serviceType) {
T highestService = null;
- // we do not need the priority stuff if the list contains only one element
+ // we do not need the priority stuff if the createList contains only one element
if (services.size() == 1) {
highestService = services.iterator().next();
this.factoryTypes.put(serviceType, highestService.getClass());
@@ -197,4 +226,14 @@ final class ServiceLoaderServiceContext implements ServiceContext {
return classLoader.getResource(resource);
}
+ @Override
+ public <T> T register(Class<T> type, T instance, boolean force) {
+ return null;
+ }
+
+ @Override
+ public <T> List<T> register(Class<T> type, List<T> instances, boolean force) {
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java
index e639f49..6b51061 100644
--- a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java
+++ b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/TamayaCDIInjectionExtension.java
@@ -161,9 +161,9 @@ public class TamayaCDIInjectionExtension implements Extension {
* @param memberName the default member name, not null.
* @param keys the keys, may be empty, or null.
* @param sections the default sections, may be empty. May also be null.
- * @return the list of keys to be finally used for configuration resolution in order of
- * precedence. The first keys in the list that could be successfully resolved define the final
- * configuration value.
+ * @return the createList of keys to be finally used for configuration resolution in order of
+ * precedence. The first keys in the createList that could be successfully resolved define the final
+ * configuration createValue.
*/
public static List<String> evaluateKeys(String memberName, String[] keys, String[] sections) {
List<String> effKeys = new ArrayList<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/ConfigurationProducerTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/ConfigurationProducerTest.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/ConfigurationProducerTest.java
index b3459b7..7c2ca66 100644
--- a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/ConfigurationProducerTest.java
+++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/ConfigurationProducerTest.java
@@ -128,7 +128,7 @@ public class ConfigurationProducerTest {
private Provider<String> providerString;
@Inject
- @Config(value = "defaultString.value", defaultValue = "defaultString")
+ @Config(value = "defaultString.createValue", defaultValue = "defaultString")
private String defaultString;
@Inject
@@ -136,7 +136,7 @@ public class ConfigurationProducerTest {
private File file;
@Inject
- @Config(value = "defaultFile.value", defaultValue = "./")
+ @Config(value = "defaultFile.createValue", defaultValue = "./")
private File defaultFile;
@Inject
@@ -144,7 +144,7 @@ public class ConfigurationProducerTest {
private Boolean aBoolean;
@Inject
- @Config(value = "defaultBoolean.value", defaultValue = "true")
+ @Config(value = "defaultBoolean.createValue", defaultValue = "true")
private Boolean defaultBoolean;
@Inject
@@ -152,7 +152,7 @@ public class ConfigurationProducerTest {
private Integer integer;
@Inject
- @Config(value = "defaultInteger.value", defaultValue = "45")
+ @Config(value = "defaultInteger.createValue", defaultValue = "45")
private Integer defaultInteger;
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java
index ff97452..7f636d3 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java
@@ -46,9 +46,9 @@ import java.lang.annotation.Target;
* <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = Configuration.current();}</li>
* <li>The current possible property keys are evaluated by calling {@code cfg.current("a.b.ConfigureItem.aValue");},
* {@code cfg.current("ConfigureItem.aValue");}, {@code cfg.current("aValue");}</li>
- * <li>if not successful, and since no @ConfigDefault annotation is present, the configured default value is used.
- * <li>If no value could be evaluated a ({@link org.apache.tamaya.ConfigException} is thrown.</li>
- * <li>On success, since no type conversion is involved, the value is injected.</li>
+ * <li>if not successful, and since no @ConfigDefault annotation is present, the configured default createValue is used.
+ * <li>If no createValue could be evaluated a ({@link org.apache.tamaya.ConfigException} is thrown.</li>
+ * <li>On success, since no type conversion is involved, the createValue is injected.</li>
* </ul>
*
* <h3>Explicit annotations</h3>
@@ -57,14 +57,14 @@ import java.lang.annotation.Target;
* &ConfigDefaultSections("section1")
* public class ConfiguredItem {
*
- * &Config(value = {"b", "[a.b.deprecated.keys]", "a"}, defaultValue = "myDefaultValue")
+ * &Config(createValue = {"b", "[a.b.deprecated.keys]", "a"}, defaultValue = "myDefaultValue")
* private String aValue;
* }
* </pre>
*
* Within this example we evaluate multiple possible keys: {@code section1.b, a.b.deprecated.keys, section1.a}.
* Evaluation is aborted if a key is resolved successfully. Hereby the ordering of the annotation values
- * define the ordering of resolution. If no value can be found, the configured default {@code myDefaultValue} is
+ * define the ordering of resolution. If no createValue can be found, the configured default {@code myDefaultValue} is
* injected.
*
* <h3>Using explicit field annotation only</h3>
@@ -75,7 +75,7 @@ import java.lang.annotation.Target;
*
* public class ConfiguredItem {
*
- * &Config(value = {"b", "[a.b.deprecated.keys]", "a"}, defaultValue = "myDefaultValue")
+ * &Config(createValue = {"b", "[a.b.deprecated.keys]", "a"}, defaultValue = "myDefaultValue")
* private String aValue;
* }
* </pre>
@@ -93,8 +93,8 @@ public @interface Config {
String UNCONFIGURED_VALUE = "org.apache.tamaya.config.configproperty.unconfigureddvalue";
/**
- * Defines the configuration property keys to be used. Hereby the first non null value evaluated is injected as
- * property value.
+ * Defines the configuration property keys to be used. Hereby the first non null createValue evaluated is injected as
+ * property createValue.
*
* @return the property keys, not null. If empty, the field or property name (of a setter method) being injected
* is used by default.
@@ -103,13 +103,13 @@ public @interface Config {
String[] value() default {};
/**
- * The default value to be injected, if none of the configuration keys could be resolved. If no key has been
- * resolved and no default value is defined, it is, by default, handled as a deployment error. Depending on the
+ * The default createValue to be injected, if none of the configuration keys could be resolved. If no key has been
+ * resolved and no default createValue is defined, it is, by default, handled as a deployment error. Depending on the
* extension loaded default values can be fixed Strings or even themselves resolvable. For typed configuration of
- * type T entries that are not Strings the default value must be a valid input to a corresponding
+ * type T entries that are not Strings the default createValue must be a valid input to a corresponding
* {@link org.apache.tamaya.spi.PropertyConverter}.
*
- * @return default value used in case resolution fails.
+ * @return default createValue used in case resolution fails.
*/
@Nonbinding
String defaultValue() default UNCONFIGURED_VALUE;
@@ -118,7 +118,7 @@ public @interface Config {
* Flag that defines if a configuration property is required. If a required
* property is missing, a {@link org.apache.tamaya.ConfigException} is raised.
* Default is {@code true}.
- * @return the flag value.
+ * @return the flag createValue.
*/
@Nonbinding
boolean required() default true;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
index 45630ba..c92125d 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
@@ -23,10 +23,10 @@ import java.util.function.Supplier;
/**
- * <p>A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * <p>A accessor for a single configured createValue. 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 setCurrent 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.</p>
+ * new createValue. Depending on the {@link UpdatePolicy} the new createValue is immedeately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the createValue.</p>
*
* <p>Types of this interface can be used as injection targets in injected beans or as template resiult on configuration
* templates.</p>
@@ -38,74 +38,74 @@ import java.util.function.Supplier;
* <li>Thread safe</li>
* </ul>
*
- * @param <T> The type of the value.
+ * @param <T> The type of the createValue.
*/
public interface DynamicValue<T> {
/**
- * Performs a commit, if necessary, and returns the current value.
+ * Performs a commit, if necessary, and returns the current createValue.
*
- * @return the non-null value held by this {@code DynamicValue}
- * @throws org.apache.tamaya.ConfigException if there is no value present
+ * @return the non-null createValue held by this {@code DynamicValue}
+ * @throws org.apache.tamaya.ConfigException if there is no createValue present
*
* @see DynamicValue#isPresent()
*/
T commitAndGet();
/**
- * Commits a new value that has not been committed yet, make it the new value of the instance. On change any
+ * Commits a new createValue that has not been committed yet, make it the new createValue of the instance. On change any
* registered listeners will be triggered.
*/
void commit();
/**
- * Discards a new value that has been published and ignore all future evaluations to the last discarded
- * value. If a different new value than the discarded value will be evaluated a value change
+ * Discards a new createValue that has been published and ignore all future evaluations to the last discarded
+ * createValue. If a different new createValue than the discarded createValue will be evaluated a createValue change
* will be flagged and handled as defined by the {@link UpdatePolicy}.
* No listeners will be triggered.
*/
void discard();
/**
- * Access the {@link UpdatePolicy} used for updating this value.
+ * Access the {@link UpdatePolicy} used for updating this createValue.
* @return the update policy, never null.
*/
UpdatePolicy getUpdatePolicy();
/**
- * Add a listener to be called as weak reference, when this value has been changed.
+ * Add a listener to be called as weak reference, when this createValue has been changed.
* @param l the listener, not null
*/
void addListener(PropertyChangeListener l);
/**
- * Removes a listener to be called, when this value has been changed.
+ * Removes a listener to be called, when this createValue has been changed.
* @param l the listner to be removed, not null
*/
void removeListener(PropertyChangeListener l);
/**
- * If a value is present in this {@code DynamicValue}, returns the value,
+ * If a createValue is present in this {@code DynamicValue}, returns the createValue,
* 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
+ * @return the non-null createValue held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no createValue present
*
* @see DynamicValue#isPresent()
*/
T get();
/**
- * Method to check for and apply a new value. Depending on the {@link UpdatePolicy}
- * the value is immediately or deferred visible (or it may even be ignored completely).
- * @return true, if a new value has been detected. The value may not be visible depending on the current
+ * Method to check for and apply a new createValue. Depending on the {@link UpdatePolicy}
+ * the createValue is immediately or deferred visible (or it may even be ignored completely).
+ * @return true, if a new createValue has been detected. The createValue may not be visible depending on the current
* {@link UpdatePolicy} in place.
*/
boolean updateValue();
/**
- * Evaluates the current value dynamically from the underlying configuration.
- * @return the current actual value, or null.
+ * Evaluates the current createValue dynamically from the underlying configuration.
+ * @return the current actual createValue, or null.
*/
T evaluateValue();
@@ -116,53 +116,53 @@ public interface DynamicValue<T> {
void setUpdatePolicy(UpdatePolicy updatePolicy);
/**
- * Access a new value that has not yet been committed.
- * @return the uncommitted new value, or null.
+ * Access a new createValue that has not yet been committed.
+ * @return the uncommitted new createValue, or null.
*/
T getNewValue();
/**
- * Return {@code true} if there is a value present, otherwise {@code false}.
+ * Return {@code true} if there is a createValue present, otherwise {@code false}.
*
- * @return {@code true} if there is a value present, otherwise {@code false}
+ * @return {@code true} if there is a createValue present, otherwise {@code false}
*/
boolean isPresent();
/**
- * Return the value if present, otherwise return {@code other}.
+ * Return the createValue if present, otherwise return {@code other}.
*
- * @param other the value to be returned if there is no value present, may
+ * @param other the createValue to be returned if there is no createValue present, may
* be null
- * @return the value, if present, otherwise {@code other}
+ * @return the createValue, if present, otherwise {@code other}
*/
T orElse(T other);
/**
- * Return the value if present, otherwise invoke {@code other} and return
+ * Return the createValue if present, otherwise invoke {@code other} and return
* the result of that invocation.
*
- * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+ * @param other a {@code ConfiguredItemSupplier} whose result is returned if no createValue
* is present
- * @return the value if present otherwise the result of {@code other.current()}
- * @throws NullPointerException if value is not present and {@code other} is
+ * @return the createValue if present otherwise the result of {@code other.current()}
+ * @throws NullPointerException if createValue is not present and {@code other} is
* null
*/
T orElseGet(Supplier<? extends T> other);
/**
- * Return the contained value, if present, otherwise throw an exception
+ * Return the contained createValue, if present, otherwise throw an exception
* to be created by the provided supplier.
*
* NOTE A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
+ * argument createList 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
+ * @return the present createValue
+ * @throws X if there is no createValue present
+ * @throws NullPointerException if no createValue is present and
* {@code exceptionSupplier} is null
*/
<X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
index b445e14..90e1dbd 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
@@ -38,7 +38,7 @@ public enum LoadPolicy {
*/
LAZY,
/**
- * The configuration value is evaluated every time it is accessed.
+ * The configuration createValue is evaluated every time it is accessed.
*/
ALWAYS
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java
index ddee4e0..6ea699d 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java
@@ -29,7 +29,7 @@ public enum UpdatePolicy {
IMMEDEATE,
/** New values are applied immediately and registered listeners are informed about the change. */
IMMEDIATE,
- /** New values or not applied, but stored in the newValue property. Explicit call to DynamicValue#commit
+ /** New values or not applied, but stored in the createValue property. Explicit call to DynamicValue#commit
of DynamicValue#commitAndGet are required to accept the change and inform the listeners about the change.
* Registered listeners will be informed, when the commit was performed explicitly.
*/
@@ -44,7 +44,7 @@ public enum UpdatePolicy {
*/
NEVER,
/**
- * All listeners are informed about the change encountered, but the value will not be applied.
+ * All listeners are informed about the change encountered, but the createValue will not be applied.
*/
LOG_ONLY
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
index 0166d41..4a4df72 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
@@ -38,10 +38,10 @@ import java.util.logging.Logger;
/**
* Basic abstract implementation skeleton for a {@link DynamicValue}. This can be used to support values that may
* change during runtime. Hereby external code (could be Tamaya configuration listners or client
- * code), can apply a new value. Depending on the {@link org.apache.tamaya.inject.api.UpdatePolicy} the new value is applied immedeately, when the
+ * code), can apply a new createValue. Depending on the {@link org.apache.tamaya.inject.api.UpdatePolicy} the new createValue is applied immedeately, when the
* change has been identified, or it requires an programmatic commit by client code to
* activate the change in the {@link DynamicValue}. Similarly an instance also can ignore all
- * later changes to the value.
+ * later changes to the createValue.
*
* <h3>Implementation Specification</h3>
* This class is
@@ -50,7 +50,7 @@ import java.util.logging.Logger;
* <li>Thread safe</li>
* </ul>
*
- * @param <T> The type of the value.
+ * @param <T> The type of the createValue.
*/
public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
@@ -58,13 +58,15 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
private static final Logger LOG = Logger.getLogger(DynamicValue.class.getName());
- /** The value owner used for PropertyChangeEvents. */
+ /** The createValue owner used for PropertyChangeEvents. */
private Object owner;
/**
* The property name of the entry.
*/
private String propertyName;
+ private Configuration configuration;
+
/**
* Policy that defines how new values are applied, be default it is applied initially once, but never updated
* anymore.
@@ -73,16 +75,16 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
/** The targe type. */
private TypeLiteral<T> targetType;
/**
- * The current value, never null.
+ * The current createValue, never null.
*/
protected transient T value;
- /** The last discarded value. */
+ /** The last discarded createValue. */
protected transient T discarded;
- /** Any new value, not yet applied. */
+ /** Any new createValue, not yet applied. */
protected transient T newValue;
- /** The configured default value, before type conversion. */
+ /** The configured default createValue, before type conversion. */
private String defaultValue;
- /** The list of candidate keys to be used. */
+ /** The createList of candidate keys to be used. */
private List<String> keys = new ArrayList<>();
/** The registered listeners. */
private WeakList<PropertyChangeListener> listeners = new WeakList<>();
@@ -94,27 +96,29 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
* @param targetType the target type.
* @param keys the candidate keys.
*/
- public BaseDynamicValue(Object owner, String propertyName, TypeLiteral targetType, List<String> keys){
+ public BaseDynamicValue(Object owner, String propertyName, TypeLiteral targetType, List<String> keys,
+ Configuration configuration){
if(keys == null || keys.isEmpty()){
throw new ConfigException("At least one key is required.");
}
this.owner = owner;
+ this.configuration = Objects.requireNonNull(configuration);
this.propertyName = Objects.requireNonNull(propertyName);
this.targetType = Objects.requireNonNull(targetType);
this.keys.addAll(keys);
}
/**
- * Get the default value, used if no value could be evaluated.
- * @return the default value, or null.
+ * Get the default createValue, used if no createValue could be evaluated.
+ * @return the default createValue, or null.
*/
public String getDefaultValue() {
return defaultValue;
}
/**
- * Set the default value to be used.
- * @param defaultValue the default value.
+ * Set the default createValue to be used.
+ * @param defaultValue the default createValue.
*/
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
@@ -124,7 +128,9 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
* Get the configuration to evaluate.
* @return the configuration, never null.
*/
- protected abstract Configuration getConfiguration();
+ protected Configuration getConfiguration(){
+ return configuration;
+ }
/**
* Get the corresponding property name.
@@ -135,7 +141,7 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
}
/**
- * Get the owner of this dynamic value instance.
+ * Get the owner of this dynamic createValue instance.
* @return the owner, never null.
*/
protected Object getOwner(){
@@ -212,10 +218,10 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
value = val;
return true;
}else if(discarded!=null && discarded.equals(val)){
- // the evaluated value has been discarded and will be flagged out.
+ // the evaluated createValue has been discarded and will be flagged out.
return false;
}else{
- // Reset discarded state for a new value.
+ // Reset discarded state for a new createValue.
discarded = null;
}
if(!Objects.equals(val, value)){
@@ -228,10 +234,10 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
publishChangeEvent(this.value, val);
break;
case LOG_ONLY:
- LOG.info("New config value for keys " + keys + " detected, but not yet applied.");
+ LOG.info("New config createValue for keys " + keys + " detected, but not yet applied.");
break;
case NEVER:
- LOG.finest("New config value for keys " + keys + " detected, but ignored.");
+ LOG.finest("New config createValue for keys " + keys + " detected, but ignored.");
break;
}
return true;
@@ -241,8 +247,8 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
/**
* Publishes a change event to all listeners.
- * @param newValue the new value
- * @param oldValue the new old value
+ * @param newValue the new createValue
+ * @param oldValue the new old createValue
*/
protected void publishChangeEvent(T oldValue, T newValue) {
PropertyChangeEvent evt = new PropertyChangeEvent(getOwner(), getPropertyName(),oldValue, newValue);
@@ -325,10 +331,10 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
}
/**
- * Performs a commit, if necessary, and returns the current value.
+ * Performs a commit, if necessary, and returns the current createValue.
*
- * @return the non-null value held by this {@code DynamicValue}
- * @throws org.apache.tamaya.ConfigException if there is no value present
+ * @return the non-null createValue held by this {@code DynamicValue}
+ * @throws org.apache.tamaya.ConfigException if there is no createValue present
* @see DynamicValue#isPresent()
*/
@Override
@@ -338,9 +344,9 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
}
/**
- * Return {@code true} if there is a value present, otherwise {@code false}.
+ * Return {@code true} if there is a createValue present, otherwise {@code false}.
*
- * @return {@code true} if there is a value present, otherwise {@code false}
+ * @return {@code true} if there is a createValue present, otherwise {@code false}
*/
@Override
public boolean isPresent() {
@@ -349,11 +355,11 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
/**
- * Return the value if present, otherwise return {@code other}.
+ * Return the createValue if present, otherwise return {@code other}.
*
- * @param other the value to be returned if there is no value present, may
+ * @param other the createValue to be returned if there is no createValue present, may
* be null
- * @return the value, if present, otherwise {@code other}
+ * @return the createValue, if present, otherwise {@code other}
*/
@Override
public T orElse(T other) {
@@ -365,13 +371,13 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
}
/**
- * Return the value if present, otherwise invoke {@code other} and return
+ * Return the createValue if present, otherwise invoke {@code other} and return
* the result of that invocation.
*
- * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+ * @param other a {@code ConfiguredItemSupplier} whose result is returned if no createValue
* is present
- * @return the value if present otherwise the result of {@code other.current()}
- * @throws NullPointerException if value is not present and {@code other} is
+ * @return the createValue if present otherwise the result of {@code other.current()}
+ * @throws NullPointerException if createValue is not present and {@code other} is
* null
*/
@Override
@@ -384,19 +390,19 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
}
/**
- * Return the contained value, if present, otherwise throw an exception
+ * Return the contained createValue, if present, otherwise throw an exception
* to be created by the provided supplier.
* <p>
* NOTE A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
+ * argument createList 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
+ * @return the present createValue
+ * @throws X if there is no createValue present
+ * @throws NullPointerException if no createValue is present and
* {@code exceptionSupplier} is null
*/
@Override
@@ -466,9 +472,9 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
/**
- * Access a list (copy) of the current instances that were not discarded by the GC.
+ * Access a createList (copy) of the current instances that were not discarded by the GC.
*
- * @return the list of accessible items.
+ * @return the createList of accessible items.
*/
public List<I> get() {
synchronized (refs) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java
index 94c0091..cc59d68 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java
@@ -35,9 +35,9 @@ public interface ConfiguredField {
Class<?> getType();
/**
- * Get a list of all target keys for the given field. The first resolvable key normally determines the
- * configuration value injected.
- * @return a list of evaluated keys.
+ * Get a createList of all target keys for the given field. The first resolvable key normally determines the
+ * configuration createValue injected.
+ * @return a createList of evaluated keys.
*/
Collection<String> getConfiguredKeys();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java
index b6b2820..2702676 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java
@@ -40,7 +40,7 @@ public final class InjectionUtils {
* Collects all keys to be be accessed as defined by any annotations of type
* {@link ConfigDefaultSections}, {@link Config}.
* @param field the (optionally) annotated field instance
- * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}.
+ * @return the regarding key createList to be accessed fomr the {@link org.apache.tamaya.Configuration}.
*/
public static List<String> getKeys(Field field) {
ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
@@ -51,7 +51,7 @@ public final class InjectionUtils {
* Collects all keys to be be accessed as defined by any annotations of type
* {@link ConfigDefaultSections}, {@link Config}.
* @param method the (optionally) annotated method instance
- * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}.
+ * @return the regarding key createList to be accessed fomr the {@link org.apache.tamaya.Configuration}.
*/
public static List<String> getKeys(Method method) {
ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
@@ -63,7 +63,7 @@ public final class InjectionUtils {
*
* @param member member to analyze.
* @param sectionAnnot the (optional) annotation defining areas to be looked up.
- * @return the list of current keys in order how they should be processed/looked up.
+ * @return the createList of current keys in order how they should be processed/looked up.
*/
public static List<String> evaluateKeys(Member member, ConfigDefaultSections sectionAnnot) {
List<String> keys = new ArrayList<>();
@@ -89,7 +89,7 @@ public final class InjectionUtils {
* @param areasAnnot the (optional) annotation definining areas to be looked up.
* @param propertyAnnotation the annotation on field/method level that may defined one or
* several keys to be looked up (in absolute or relative form).
- * @return the list current keys in order how they should be processed/looked up.
+ * @return the createList current keys in order how they should be processed/looked up.
*/
public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot, Config propertyAnnotation) {
if(propertyAnnotation==null){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java b/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java
index c913303..33c63a4 100644
--- a/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java
+++ b/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.inject.spi;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.api.UpdatePolicy;
import org.junit.Test;
@@ -33,18 +32,18 @@ public class BaseDynamicValueTest {
@Test
public void create(){
- new MyDynamicValue("a", "b");
+ new MyDynamicValue(Configuration.current(),"a", "b");
}
@Test(expected = ConfigException.class)
public void create_nokeys(){
- new MyDynamicValue();
+ new MyDynamicValue(Configuration.current());
}
@Test
public void commitAndGet() throws Exception {
System.setProperty("commitAndGet", "yes");
- MyDynamicValue dv = new MyDynamicValue("commitAndGet");
+ MyDynamicValue dv = new MyDynamicValue(Configuration.current(),"commitAndGet");
System.setProperty("commitAndGet", "no");
dv.setUpdatePolicy(UpdatePolicy.EXPLICIT);
assertTrue(dv.updateValue());
@@ -57,29 +56,29 @@ public class BaseDynamicValueTest {
@Test
public void isPresent() throws Exception {
- assertFalse(new MyDynamicValue("a", "b").isPresent());
- assertTrue(new MyDynamicValue("java.version").isPresent());
+ assertFalse(new MyDynamicValue(Configuration.current(),"a", "b").isPresent());
+ assertTrue(new MyDynamicValue(Configuration.current(),"java.version").isPresent());
}
@Test
public void orElse() throws Exception {
- assertEquals(new MyDynamicValue("a", "b").orElse("foo"), "foo");
+ assertEquals(new MyDynamicValue(Configuration.current(),"a", "b").orElse("foo"), "foo");
}
@Test
public void orElseGet() throws Exception {
- assertEquals(new MyDynamicValue("a", "b").orElseGet(() -> "foo"), "foo");
+ assertEquals(new MyDynamicValue(Configuration.current(),"a", "b").orElseGet(() -> "foo"), "foo");
}
@Test(expected = NoSuchFieldException.class)
public void orElseThrow() throws Throwable {
- new MyDynamicValue("foo").orElseThrow(() -> new NoSuchFieldException("Test"));
+ new MyDynamicValue(Configuration.current(),"foo").orElseThrow(() -> new NoSuchFieldException("Test"));
}
private static final class MyDynamicValue extends BaseDynamicValue{
- public MyDynamicValue(String... keys){
- super(null, "test", TypeLiteral.of(String.class), Arrays.asList(keys));
+ public MyDynamicValue(Configuration config, String... keys){
+ super(null, "test", TypeLiteral.of(String.class), Arrays.asList(keys), config);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
index 79d6218..ee7e379 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjection.java
@@ -32,11 +32,23 @@ public final class ConfigurationInjection {
}
/**
- * Get the current injector instance.
+ * Get the current injector instance, using the default classloader.
*
* @return the current injector, not null.
*/
public static ConfigurationInjector getConfigurationInjector() {
- return ServiceContextManager.getServiceContext().getService(ConfigurationInjector.class);
+ return ServiceContextManager.getServiceContext(ServiceContextManager.getDefaultClassLoader())
+ .getService(ConfigurationInjector.class);
+ }
+
+ /**
+ * Get the current injector instance, using the given target classloader.
+ *
+ * @param classLoader the classloader, not null.
+ * @return the current injector, not null.
+ */
+ public static ConfigurationInjector getConfigurationInjector(ClassLoader classLoader) {
+ return ServiceContextManager.getServiceContext(classLoader)
+ .getService(ConfigurationInjector.class);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
index 898e937..205bea2 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
@@ -50,6 +50,7 @@ public interface ConfigurationInjector {
* @param instance the instance to be configured
* @param config the configuration to be used for injection.
* @return the configured instance (allows chaining of operations).
+ * @throws IllegalArgumentException if the configuration's and the injector's classloader do not match.
*/
<T> T configure(T instance, Configuration config);
@@ -69,6 +70,7 @@ public interface ConfigurationInjector {
* @param config the configuration to be used for backing the template.
* @param templateType the type of the template to be created.
* @return the configured template.
+ * @throws IllegalArgumentException if the configuration's and the injector's classloader do not match.
*/
<T> T createTemplate(Class<T> templateType, Configuration config);
@@ -76,7 +78,7 @@ public interface ConfigurationInjector {
/**
* Creates a supplier for configured instances of the given type {@code T}.
*
- * @param supplier the supplier to create new instances.
+ * @param supplier the supplier to createObject new instances.
* @param <T> the target type.
* @return a supplier creating configured instances of {@code T}.
*/
@@ -85,10 +87,11 @@ public interface ConfigurationInjector {
/**
* Creates a supplier for configured instances of the given type {@code T}.
*
- * @param supplier the supplier to create new instances.
+ * @param supplier the supplier to createObject new instances.
* @param config the configuration to be used for backing the supplier.
* @param <T> the target type.
* @return a supplier creating configured instances of {@code T}.
+ * @throws IllegalArgumentException if the configuration's and the injector's classloader do not match.
*/
<T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier, Configuration config);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
index 1a1d6e6..15b6c68 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
@@ -51,7 +51,7 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler
throw new IllegalArgumentException("Can only proxy interfaces as configuration templates.");
}
this.config = Objects.requireNonNull(config);
- InjectionHelper.sendConfigurationEvent(this.type);
+ InjectionHelper.sendConfigurationEvent(this.type, config.getContext().getServiceContext().getClassLoader());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
index 4988af5..6655643 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredFieldImpl.java
@@ -70,7 +70,7 @@ public class ConfiguredFieldImpl implements ConfiguredField{
/**
- * This method instantiates and assigns a dynamic value.
+ * This method instantiates and assigns a dynamic createValue.
*
* @param target the target instance, not null.
* @throws ConfigException if the configuration required could not be resolved or converted.
@@ -108,7 +108,8 @@ public class ConfiguredFieldImpl implements ConfiguredField{
String configValue = InjectionHelper.getConfigValue(this.annotatedField, retKey, config);
// Next step perform expression resolution, if any
String evaluatedValue = resolve && configValue != null
- ? InjectionHelper.evaluateValue(configValue)
+ ? InjectionHelper.evaluateValue(configValue,
+ config.getContext().getServiceContext().getClassLoader())
: configValue;
// Check for adapter/filter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 57ef63c..1aef542 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -61,7 +61,8 @@ public class ConfiguredSetterMethod implements ConfiguredMethod {
Objects.requireNonNull(target);
try {
String evaluatedString = configValue != null
- ? InjectionHelper.evaluateValue(configValue)
+ ? InjectionHelper.evaluateValue(configValue,
+ config.getContext().getServiceContext().getClassLoader())
: configValue;
// Check for adapter/filter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
index e29c64e..1697888 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
@@ -44,11 +44,11 @@ public class ConfiguredTypeImpl implements ConfiguredType{
/** The log used. */
private static final Logger LOG = Logger.getLogger(ConfiguredTypeImpl.class.getName());
/**
- * A list with all annotated instance variables.
+ * A createList with all annotated instance variables.
*/
private final List<ConfiguredField> configuredFields = new ArrayList<>();
/**
- * A list with all annotated methods (templates).
+ * A createList with all annotated methods (templates).
*/
private final List<ConfiguredMethod> configuredSetterMethods = new ArrayList<>();
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
index 15c04e9..4202052 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -36,6 +36,7 @@ import org.apache.tamaya.inject.api.NoConfig;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.apache.tamaya.inject.spi.ConfiguredType;
+import org.apache.tamaya.spi.ClassloaderAware;
import org.osgi.service.component.annotations.Component;
/**
@@ -43,7 +44,7 @@ import org.osgi.service.component.annotations.Component;
*/
@Priority(0)
@Component
-public class DefaultConfigurationInjector implements ConfigurationInjector {
+public class DefaultConfigurationInjector implements ConfigurationInjector, ClassloaderAware {
private final Map<Class<?>, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
@@ -51,6 +52,8 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
private boolean autoConfigureEnabled = true;
+ private ClassLoader classLoader;
+
/**
* Extract the configuration annotation config and registers it per class, for later reuse.
*
@@ -65,7 +68,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
}
confType = new ConfiguredTypeImpl(type);
configuredTypes.put(type, confType);
- InjectionHelper.sendConfigurationEvent(confType);
+ InjectionHelper.sendConfigurationEvent(confType, classLoader);
}
return confType;
}
@@ -117,7 +120,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
*/
@Override
public <T> T configure(T instance) {
- return configure(instance, Configuration.current());
+ return configure(instance, Configuration.current(classLoader));
}
/**
@@ -126,9 +129,13 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
*
* @param instance the instance to be configured
* @param config the target configuration, not null.
+ * @throws IllegalArgumentException if the configuration's and the injector's classloader do not match.
*/
@Override
public <T> T configure(T instance, Configuration config) {
+ if(config.getContext().getServiceContext().getClassLoader()!=this.classLoader){
+ throw new IllegalArgumentException("Classloader mismatch.");
+ }
Class<?> type = Objects.requireNonNull(instance).getClass();
ConfiguredType configuredType = registerType(type);
if(configuredType!=null){
@@ -146,7 +153,7 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
*/
@Override
public <T> T createTemplate(Class<T> templateType) {
- return createTemplate(templateType, Configuration.current());
+ return createTemplate(templateType, Configuration.current(classLoader));
}
/**
@@ -154,9 +161,13 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
*
* @param templateType the type of the template to be created.
* @param config the target configuration, not null.
+ * @throws IllegalArgumentException if the configuration's and the injector's classloader do not match.
*/
@Override
public <T> T createTemplate(Class<T> templateType, Configuration config) {
+ if(config.getContext().getServiceContext().getClassLoader()!=this.classLoader){
+ throw new IllegalArgumentException("Classloader mismatch.");
+ }
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if(cl==null){
cl = this.getClass().getClassLoader();
@@ -167,15 +178,28 @@ public class DefaultConfigurationInjector implements ConfigurationInjector {
@Override
public <T> Supplier<T> getConfiguredSupplier(final Supplier<T> supplier) {
- return getConfiguredSupplier(supplier, Configuration.current());
+ return getConfiguredSupplier(supplier, Configuration.current(classLoader));
}
@Override
public <T> Supplier<T> getConfiguredSupplier(final Supplier<T> supplier, final Configuration config) {
+ if(config.getContext().getServiceContext().getClassLoader()!=this.classLoader){
+ throw new IllegalArgumentException("Classloader mismatch.");
+ }
return new Supplier<T>() {
public T get() {
return configure(supplier.get(), config);
}
};
}
+
+ @Override
+ public void init(ClassLoader classLoader) {
+ this.classLoader = Objects.requireNonNull(classLoader);
+ }
+
+ @Override
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
index af8d24e..38408ae 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
@@ -41,10 +41,10 @@ import java.util.Objects;
import java.util.logging.Logger;
/**
- * A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * A accessor for a single configured createValue. This can be used to support values that may change during runtime,
* reconfigured or final. Hereby external code (could be Tamaya configuration listeners or client code), can setCurrent a
- * new value. Depending on the {@link UpdatePolicy} the new value is immediately active or it requires an active commit
- * by client code. Similarly an instance also can ignore all later changes to the value.
+ * new createValue. Depending on the {@link UpdatePolicy} the new createValue is immediately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the createValue.
* <h3>Implementation Details</h3>
* This class is
* <ul>
@@ -52,18 +52,13 @@ import java.util.logging.Logger;
* <li>Thread safe</li>
* </ul>
*
- * @param <T> The type of the value.
+ * @param <T> The type of the createValue.
*/
final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
private static final long serialVersionUID = -2071172847144537443L;
/**
- * Back reference to the base configuration instance. This reference is used reevaluate the given property and
- * compare the result with the previous value after a configuration change was triggered.
- */
- private final Configuration configuration;
- /**
* The property converter to be applied, may be null. In the ladder case targetType is not null.
*/
private final PropertyConverter<T> propertyConverter;
@@ -85,8 +80,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
private DefaultDynamicValue(Object owner, String propertyName, Configuration configuration, TypeLiteral<T> targetType,
PropertyConverter<T> propertyConverter, List<String> keys, LoadPolicy loadPolicy,
UpdatePolicy updatePolicy) {
- super(owner, propertyName, targetType, keys);
- this.configuration = Objects.requireNonNull(configuration);
+ super(owner, propertyName, targetType, keys, configuration);
this.propertyConverter = propertyConverter;
this.loadPolicy = Objects.requireNonNull(loadPolicy);
setUpdatePolicy(updatePolicy);
@@ -108,7 +102,8 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- public static DynamicValue<?> of(Object owner, Field annotatedField, Configuration configuration, LoadPolicy loadPolicy, UpdatePolicy updatePolicy) {
+ public static DynamicValue<?> of(Object owner, Field annotatedField, Configuration configuration,
+ LoadPolicy loadPolicy, UpdatePolicy updatePolicy) {
// Check for adapter/filter
Type targetType = annotatedField.getGenericType();
if (targetType == null) {
@@ -153,7 +148,8 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
}
@SuppressWarnings("unchecked")
- public static DynamicValue<?> of(Object owner, Method method, Configuration configuration, LoadPolicy loadPolicy, UpdatePolicy updatePolicy) {
+ public static DynamicValue<?> of(Object owner, Method method, Configuration configuration,
+ LoadPolicy loadPolicy, UpdatePolicy updatePolicy) {
// Check for adapter/filter
Type targetType = method.getGenericReturnType();
if (targetType == null) {
@@ -189,17 +185,12 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
return this.propertyConverter;
}
- @Override
- protected Configuration getConfiguration() {
- return configuration;
- }
-
/**
- * If a value is present in this {@code DynamicValue}, returns the value,
+ * If a createValue is present in this {@code DynamicValue}, returns the createValue,
* otherwise throws {@code ConfigException}.
*
- * @return the non-null value held by this {@code Optional}
- * @throws ConfigException if there is no value present
+ * @return the non-null createValue held by this {@code Optional}
+ * @throws ConfigException if there is no createValue present
* @see DefaultDynamicValue#isPresent()
*/
public T get() {
@@ -236,10 +227,10 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
}
/**
- * Method to check for and apply a new value. Depending on the {@link UpdatePolicy}
- * the value is immediately or deferred visible (or it may even be ignored completely).
+ * Method to check for and apply a new createValue. Depending on the {@link UpdatePolicy}
+ * the createValue is immediately or deferred visible (or it may even be ignored completely).
*
- * @return true, if a new value has been detected. The value may not be visible depending on the current
+ * @return true, if a new createValue has been detected. The createValue may not be visible depending on the current
* {@link UpdatePolicy} in place.
*/
public boolean updateValue() {
@@ -253,7 +244,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
}
switch (getUpdatePolicy()) {
case LOG_ONLY:
- Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue=" + newValue);
+ Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", createValue=" + newValue);
publishChangeEvent(value, newValue);
this.newValue = null;
break;
@@ -271,9 +262,9 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
}
/**
- * Access a new value that has not yet been committed.
+ * Access a new createValue that has not yet been committed.
*
- * @return the uncommitted new value, or null.
+ * @return the uncommitted new createValue, or null.
*/
public T getNewValue() {
@SuppressWarnings("unchecked")
@@ -295,7 +286,7 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
/**
* Reads an instance from the input stream.
*
- * @param ois the object input stream
+ * @param ois the createObject input stream
* @throws IOException if deserialization fails.
* @throws ClassNotFoundException
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
index ec5ddad..3a3d80e 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
@@ -59,10 +59,10 @@ final class InjectionHelper {
private static boolean checkForEvents() {
try{
Class.forName("org.apache.tamaya.events.FrozenConfiguration");
- LOG.info("Detected tamaya-events is loaded, will trigger ConfigEvents...");
+ LOG.info("Detected tamaya-events, will trigger ConfigEvents...");
return true;
} catch(Exception e){
- LOG.info("Detected tamaya-events not found, will not trigger any ConfigEvents...");
+ LOG.info("tamaya-events not installed, will not trigger any ConfigEvents...");
return false;
}
}
@@ -70,8 +70,10 @@ final class InjectionHelper {
private static boolean checkResolutionModuleLoaded() {
try {
Class.forName("org.apache.tamaya.resolver.internal.DefaultExpressionEvaluator");
+ LOG.info("Detected tamaya-resolver...");
return true;
} catch (ClassNotFoundException e) {
+ LOG.finest("tamaya-resolver not installed.");
return false;
}
}
@@ -124,7 +126,8 @@ final class InjectionHelper {
*
* @return the keys to be returned, or null.
*/
- private static String getConfigValueInternal(AnnotatedElement element, ConfigDefaultSections areasAnnot, String[] retKey, Configuration config) {
+ private static String getConfigValueInternal(AnnotatedElement element, ConfigDefaultSections areasAnnot,
+ String[] retKey, Configuration config) {
Config prop = element.getAnnotation(Config.class);
List<String> keys;
if (prop == null) {
@@ -209,7 +212,7 @@ final class InjectionHelper {
/**
* Method that allows to statically check, if the resolver module is loaded. If the module is loaded
- * value expressions are automatically forwarded to the resolver module for resolution.
+ * createValue expressions are automatically forwarded to the resolver module for resolution.
*
* @return true, if the resolver module is on the classpath.
*/
@@ -223,11 +226,12 @@ final class InjectionHelper {
* @param expression the expression, not null.
* @return the evaluated expression.
*/
- public static String evaluateValue(String expression) {
+ public static String evaluateValue(String expression, ClassLoader classLoader) {
if (!RESOLUTION_MODULE_LOADED) {
return expression;
}
- ExpressionEvaluator evaluator = ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class);
+ ExpressionEvaluator evaluator = ServiceContextManager.getServiceContext(classLoader)
+ .getService(ExpressionEvaluator.class);
if (evaluator != null) {
return evaluator.evaluateExpression("<injection>", expression, true);
}
@@ -239,9 +243,9 @@ final class InjectionHelper {
* When Tamaya events are not available, the call simply returns.
* @param event the event to be distributed, not null.
*/
- static void sendConfigurationEvent(ConfiguredType event) {
+ static void sendConfigurationEvent(ConfiguredType event, ClassLoader classLoader) {
if(EVENTS_AVAILABLE){
- ConfigEventManager.fireEvent(new BaseConfigEvent<ConfiguredType>(event, ConfiguredType.class) {});
+ ConfigEventManager.getInstance(classLoader).fireEvent(new BaseConfigEvent<ConfiguredType>(event, ConfiguredType.class) {});
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/Utils.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/Utils.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/Utils.java
index 2c08467..956f2b3 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/Utils.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/Utils.java
@@ -49,7 +49,7 @@ public final class Utils {
* @param annotationContainer the container annotation type
* @param <T> the repeatable annotation type
* @param <R> the repeatable container annotation type
- * @return a list with the annotations found (could be empty, but never null).
+ * @return a createList with the annotations found (could be empty, but never null).
*/
public static <T extends Annotation, R extends Annotation> Collection<T>
getAnnotations(AnnotatedElement annotated,
@@ -82,7 +82,7 @@ public final class Utils {
* @param annotationContainer the container annotation type
* @param <T> the repeatable annotation type
* @param <R> the repeatable container annotation type
- * @return a list with the annotations found (could be empty, but never null).
+ * @return a createList with the annotations found (could be empty, but never null).
*/
public static <T extends Annotation, R extends Annotation> Collection<T>
getAnnotations(AccessibleObject annotated,
@@ -113,7 +113,7 @@ public final class Utils {
* @param annotationType the annotation type.
* @param objects the accessible objects to be looked up
* @param <T> the repeatable annotation type
- * @return a list with the annotations found (could be empty, but never null).
+ * @return a createList with the annotations found (could be empty, but never null).
*/
public static <T extends Annotation> T getAnnotation(
Class<T> annotationType, AnnotatedElement... objects) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
index 5b6d55d..f56b43c 100644
--- a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
+++ b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
@@ -117,7 +117,7 @@ public class TamayaInjectionTest {
public void testConfigTemplate_WithCustomConfig(){
Map<String,String> properties = new HashMap<>();
properties.put("env.stage", "custom-stage");
- properties.put("simple_value", "custom-value");
+ properties.put("simple_value", "custom-createValue");
properties.put("host.name", "custom-hostname");
properties.put("anotherValue", "custom-HALLO!");
properties.put("foo.bar.myprop", "custom-parameter");
@@ -129,7 +129,7 @@ public class TamayaInjectionTest {
.createTemplate(AnnotatedConfigTemplate.class, customConfig);
assertEquals(testInstance.hostName(), "custom-hostname");
assertEquals(testInstance.myParameter(), "custom-parameter");
- assertEquals(testInstance.simpleValue(), "custom-value");
+ assertEquals(testInstance.simpleValue(), "custom-createValue");
assertNotNull(testInstance.getDynamicValue());
assertTrue(testInstance.getDynamicValue().isPresent());
assertEquals(testInstance.getDynamicValue().get(), "custom-hostname");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
index 8fd6aa5..0a810ca 100644
--- a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
+++ b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
@@ -89,7 +89,7 @@ public class JNDIPropertySource extends BasePropertySource {
* <ul>
* <li>For each leave entry one entry is created.</li>
* <li>The key is the fully path of getParent contexts, separated by a '.'.</li>
- * <li>The value is the value returned from {@code String.valueOf(leaveObject)}.</li>
+ * <li>The createValue is the createValue returned from {@code String.createValue(leaveObject)}.</li>
* </ul>
* @return a map representation of the JNDI tree.
*/
@@ -144,7 +144,7 @@ public class JNDIPropertySource extends BasePropertySource {
* <ul>
* <li>For each leave entry one entry is created.</li>
* <li>The key is the fully path of getParent contexts, separated by a '.'.</li>
- * <li>The value is the value returned from {@code String.valueOf(leaveObject)}.</li>
+ * <li>The createValue is the createValue returned from {@code String.createValue(leaveObject)}.</li>
* </ul>
* @param ctx the JNDI context, not null.
* @return the corresponding map, never null.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
index df9cc43..b0d3e7a 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileAdapter.java
@@ -158,9 +158,9 @@ public final class MicroprofileAdapter{
}
/**
- * Converts the given Tamaya key, value map into a corresponding String based map, hereby
+ * Converts the given Tamaya key, createValue map into a corresponding String based map, hereby
* omitting all getMeta-entries.
- * @param properties the Tamaya key, value map, not null.
+ * @param properties the Tamaya key, createValue map, not null.
* @return the corresponding String based map, never null.
*/
public static Map<String, String> toStringMap(Map<String, PropertyValue> properties) {
@@ -174,16 +174,16 @@ public final class MicroprofileAdapter{
}
/**
- * Converts the given String based key, value map into a corresponding String,PropertyValue
+ * Converts the given String based key, createValue map into a corresponding String,PropertyValue
* based map.
- * @param properties the String based key, value map, not null.
+ * @param properties the String based key, createValue map, not null.
* @param source the source of the entries, not null.
* @return the corresponding String,PropertyValue based map, never null.
*/
public static Map<String, PropertyValue> toPropertyValueMap(Map<String, String> properties, String source) {
Map<String, PropertyValue> valueMap = new HashMap<>(properties.size());
for(Map.Entry<String,String> en:properties.entrySet()){
- valueMap.put(en.getKey(), PropertyValue.create(en.getKey(), en.getValue()).setMeta("source", source));
+ valueMap.put(en.getKey(), PropertyValue.createValue(en.getKey(), en.getValue()).setMeta("source", source));
}
return valueMap;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
index 0a3aaf5..d444585 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
@@ -46,7 +46,6 @@ final class MicroprofileConfigBuilder implements ConfigBuilder {
this.configurationBuilder = Objects.requireNonNull(configurationBuilder);
configurationBuilder.addDefaultPropertyConverters();
}
-
public ConfigurationBuilder getConfigurationBuilder() {
return configurationBuilder;
}
@@ -80,11 +79,14 @@ final class MicroprofileConfigBuilder implements ConfigBuilder {
*/
@Override
public ConfigBuilder addDiscoveredSources() {
- for(ConfigSource configSource: ServiceContextManager.getServiceContext().getServices(ConfigSource.class)){
+ for(ConfigSource configSource: ServiceContextManager.getServiceContext(
+ configurationBuilder.getClassLoader()).getServices(ConfigSource.class)){
configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySource(configSource));
}
- for(ConfigSourceProvider configSourceProvider: ServiceContextManager.getServiceContext().getServices(ConfigSourceProvider.class)){
+ for(ConfigSourceProvider configSourceProvider: ServiceContextManager.getServiceContext(
+ configurationBuilder.getClassLoader()
+ ).getServices(ConfigSourceProvider.class)){
configurationBuilder.addPropertySources(MicroprofileAdapter.toPropertySources(configSourceProvider.getConfigSources(
Thread.currentThread().getContextClassLoader()
)));
@@ -100,7 +102,9 @@ final class MicroprofileConfigBuilder implements ConfigBuilder {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ConfigBuilder addDiscoveredConverters() {
- for(Converter<?> converter: ServiceContextManager.getServiceContext().getServices(Converter.class)){
+ for(Converter<?> converter: ServiceContextManager.getServiceContext(
+ configurationBuilder.getClassLoader()
+ ).getServices(Converter.class)){
TypeLiteral targetType = TypeLiteral.of(
TypeLiteral.getGenericInterfaceTypeParameters(converter.getClass(),Converter.class)[0]);
@@ -147,10 +151,10 @@ final class MicroprofileConfigBuilder implements ConfigBuilder {
@Override
public Config build() {
- Configuration.setCurrent(
- getConfigurationBuilder().build());
+ Configuration config = getConfigurationBuilder().build();
+ Configuration.setCurrent(config);
- return MicroprofileAdapter.toConfig(Configuration.current());
+ return MicroprofileAdapter.toConfig(config);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
index da2b5c3..33da10a 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
@@ -45,6 +45,7 @@ public class MicroprofileConfigProviderResolver extends ConfigProviderResolver {
Config config = this.configs.get(loader);
if(config==null){
ConfigurationBuilder builder = Configuration.createConfigurationBuilder();
+ builder.setClassLoader(loader);
builder.addDefaultPropertyConverters();
MicroprofileConfigBuilder microConfigBuilder = new MicroprofileConfigBuilder(builder);
microConfigBuilder.addDefaultSources();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
index aca839a..4732595 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
@@ -55,7 +55,7 @@ public class TamayaPropertySource implements PropertySource {
@Override
public PropertyValue get(String key) {
- return PropertyValue.create(key, delegate.getValue(key)).setMeta("source",getName());
+ return PropertyValue.createValue(key, delegate.getValue(key)).setMeta("source",getName());
}
@Override
@@ -66,7 +66,7 @@ public class TamayaPropertySource implements PropertySource {
private Map<String, PropertyValue> toValueMap(Map<String, String> properties) {
Map<String, PropertyValue> valueMap = new HashMap<>(properties.size());
for(Map.Entry<String,String> en:properties.entrySet()){
- valueMap.put(en.getKey(), PropertyValue.create(en.getKey(), en.getValue()).setMeta("source", getName()));
+ valueMap.put(en.getKey(), PropertyValue.createValue(en.getKey(), en.getValue()).setMeta("source", getName()));
}
return valueMap;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/36c32fcf/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
index ac6d4eb..f349d7d 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/cdi/MicroprofileConfigurationProducer.java
@@ -127,12 +127,12 @@ public class MicroprofileConfigurationProducer {
try {
value = converter.convert(textValue);
if (value != null) {
- LOGGER.log(Level.FINEST, "Parsed default value from '" + textValue + "' into " +
+ LOGGER.log(Level.FINEST, "Parsed default createValue from '" + textValue + "' into " +
injectionPoint);
break;
}
} catch (Exception e) {
- LOGGER.log(Level.FINEST, "Failed to convert value '" + textValue + "' for " +
+ LOGGER.log(Level.FINEST, "Failed to convert createValue '" + textValue + "' for " +
injectionPoint, e);
}
}