You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/01/12 01:34:38 UTC
incubator-tamaya git commit: TAMAYA-45: Reactivated injection module.
Wrote small test for basic injection.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master a693f9d25 -> e586a4486
TAMAYA-45: Reactivated injection module. Wrote small test for basic injection.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/e586a448
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/e586a448
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/e586a448
Branch: refs/heads/master
Commit: e586a44862113dd34fc7196f84236cf7475048cf
Parents: a693f9d
Author: anatole <an...@apache.org>
Authored: Mon Jan 12 01:34:31 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Jan 12 01:34:31 2015 +0100
----------------------------------------------------------------------
modules/injection/pom.xml | 13 ++-
.../tamaya/inject/ConfigurationInjector.java | 51 +++++++++
.../tamaya/inject/ConfiguredProperties.java | 41 -------
.../tamaya/inject/ConfiguredProperty.java | 15 +--
.../org/apache/tamaya/inject/DynamicValue.java | 113 ++++++++++---------
.../java/org/apache/tamaya/inject/NoConfig.java | 6 +-
.../apache/tamaya/inject/PropertyChangeSet.java | 2 +-
.../tamaya/inject/WithPropertyConverter.java | 5 +-
.../internal/ConfigChangeCallbackMethod.java | 4 +-
.../inject/internal/ConfigurationInjector.java | 59 ----------
.../tamaya/inject/internal/ConfiguredField.java | 28 +----
.../inject/internal/ConfiguredSetterMethod.java | 18 +--
.../tamaya/inject/internal/ConfiguredType.java | 22 +---
.../internal/DefaultConfigurationInjector.java | 64 +++++++++++
.../tamaya/inject/internal/InjectionUtils.java | 31 +++--
.../apache/tamaya/inject/internal/Utils.java | 60 +++++-----
.../internal/WeakConfigListenerManager.java | 38 ++++---
...g.apache.tamaya.inject.ConfigurationInjector | 19 ++++
.../test/java/annottext/AnnotatedConfig.java | 51 ---------
.../java/annottext/AnnotatedConfigBean.java | 57 ++++++++++
.../java/annottext/AnnotatedConfigTemplate.java | 49 ++++++++
.../java/annottext/AnnotatedFullConfig.java | 52 ---------
.../tamaya/inject/TamayaInjectionTest.java | 48 ++++++++
.../tamaya/inject/TestPropertySource.java | 59 ++++++++++
.../src/test/resources/META-INF/beans.xml | 25 ----
.../org.apache.tamaya.spi.PropertySource | 19 ++++
modules/pom.xml | 2 +-
27 files changed, 528 insertions(+), 423 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml
index 0627d50..480d535 100644
--- a/modules/injection/pom.xml
+++ b/modules/injection/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-extensions</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
+ <version>0.1-incubating-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>tamaya-injection</artifactId>
@@ -37,11 +37,20 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-resolver</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
new file mode 100644
index 0000000..f7f7ee7
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject;
+
+import org.apache.tamaya.spi.ServiceContext;
+
+
+/**
+ * Accessor interface for injection of configuration and configuration templates.
+ */
+public interface ConfigurationInjector {
+
+ /**
+ * Extract the configuration annotation config and registers it per class, for later reuse.
+ * @param type the type to be configured.
+ * @return the configured type registered.
+ */
+ void registerType(Class<?> type);
+
+ /**
+ * Configured the current instance and reigsterd necessary listener to forward config change events as
+ * defined by the current annotations in place.
+ * @param instance the instance to be configured
+ */
+ void configure(Object instance);
+
+ /**
+ * Get the current injector instance.
+ * @return the current injector, not null.
+ */
+ public static ConfigurationInjector getInstance(){
+ return ServiceContext.getInstance().getService(ConfigurationInjector.class).get();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java
deleted file mode 100644
index 213b34e..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperties.java
+++ /dev/null
@@ -1,41 +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.inject;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation container to enable injection current multiple {@link ConfiguredProperty}
- * annotations. Hereby the ordering current annotations imply the defaulting. The first keys that
- * could be resolved successfully in the chain current annotations will be used.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface ConfiguredProperties {
-
- /**
- * Get the different configuration keys to be looked up, in order current precedence. The first non null keys
- * found will be used.
- */
- ConfiguredProperty[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
index 72c6541..25c812f 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredProperty.java
@@ -18,7 +18,11 @@
*/
package org.apache.tamaya.inject;
-import java.lang.annotation.*;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
/**
* Annotation to enable injection current a configured property or define the returned data for
@@ -62,20 +66,11 @@ import java.lang.annotation.*;
* fromMap the configuration, it uses the keys fromMap the {@code DefaultValue} annotation. Interesting here
* is that this keys is not static, it is evaluated.
*/
-@Repeatable(ConfiguredProperties.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.METHOD })
public @interface ConfiguredProperty {
/**
- * Annotation to reference an explicit {@link org.apache.tamaya.Configuration} to be used to
- * resolve the required properties. the configured keys is passed to {@code Configuration.current(String)}
- * to evaluate the required configuration required.
- * @return the configurations to be looked up for the given keys.
- */
- String config() default "";
-
- /**
* Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
*
* @return the property names, not null. If missing the field or method name being injected is used by default.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
index c652f9d..285e2bd 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
@@ -24,7 +24,12 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -32,9 +37,9 @@ import java.util.function.Supplier;
import java.util.logging.Logger;
/**
- * A accessor for a single configured value. This can be used to support values that may change during runtime, reconfigured or
- * final. Hereby external code (could be Tamaya configuration listners or client code), can set a new value. Depending on the
- * {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
+ * A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
+ * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
* by client code. Similarly an instance also can ignore all later changes to the value.
* <h3>Implementation Details</h3>
* This class is
@@ -69,7 +74,8 @@ public final class DynamicValue<T> implements Serializable{
/** The property name of the entry. */
private String propertyName;
/**
- * Policy that defines how new values are applied, be default it is applied initially once, but never updated anymore.
+ * Policy that defines how new values are applied, be default it is applied initially once, but never updated
+ * anymore.
*/
private UpdatePolicy updatePolicy = UpdatePolicy.NEVER;
/** The current value, never null. */
@@ -80,25 +86,24 @@ public final class DynamicValue<T> implements Serializable{
private transient WeakList<Consumer<PropertyChangeEvent>> listeners;
/**
- * Returns an empty {@code Optional} instance. No value is present for this
- * Optional.
+ * Returns an empty {@code DynamicValue} instance. No value is present for this
+ * DynamicValue.
*
- * @apiNote Though it may be tempting to do so, avoid testing if an object
+ * NOTE: Though it may be tempting to do so, avoid testing if an object
* is empty by comparing with {@code ==} against instances returned by
* {@code Option.empty()}. There is no guarantee that it is a singleton.
* Instead, use {@link #isPresent()}.
*
* @param <T> Type of the non-existent value
- * @return an empty {@code Optional}
+ * @return an empty {@code DynamicValue}
*/
public static <T> DynamicValue<T> empty(String propertyName) {
- DynamicValue v = new DynamicValue<T>(propertyName, null);
- return v;
+ return new DynamicValue<T>(propertyName, null);
}
/**
* Constructor.
- * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
+ * @param propertyName the key of the property, not null.
* @param item the initial value.
*/
private DynamicValue(String propertyName, Optional<T> item){
@@ -108,18 +113,18 @@ public final class DynamicValue<T> implements Serializable{
/**
* Creates a new instance.
- * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
+ * @param propertyName the key of the property, not null.
* @param value the initial value, not null.
* @param <T> the type
* @return a new instance, never null
*/
public static <T> DynamicValue<T> of(String propertyName, T value){
- return new DynamicValue(propertyName, Optional.of(value));
+ return new DynamicValue<T>(propertyName, Optional.of(value));
}
/**
* Creates a new instance.
- * @param propertyName the name of the value in the format {@code <configName>:<propertyName>}.</config>
+ * @param propertyName the key of the property, not null.
* @param value the initial value
* @param <T> the target type.
* @return a new instance, never null
@@ -129,10 +134,9 @@ public final class DynamicValue<T> implements Serializable{
}
/**
- * Performs a commit, if necessary and returns the current value.
- * otherwise throws {@code ConfigException}.
+ * Performs a commit, if necessary, and returns the current value.
*
- * @return the non-null value held by this {@code Optional}
+ * @return the non-null value held by this {@code DynamicValue}
* @throws org.apache.tamaya.ConfigException if there is no value present
*
* @see DynamicValue#isPresent()
@@ -143,12 +147,14 @@ public final class DynamicValue<T> implements Serializable{
}
/**
- * Commits a new value that has not been committed yet, make it the new value of the instance. On change any registered listeners will be triggered.
+ * Commits a new value that has not been committed yet, make it the new value of the instance. On change any
+ * registered listeners will be triggered.
*/
public void commit(){
- synchronized (value){
+ synchronized (this){
if(newValue!=null){
- PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value.orElse(null), newValue.orElse(null));
+ PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value.orElse(null),
+ newValue.orElse(null));
value = newValue;
newValue = null;
for(Consumer<PropertyChangeEvent> consumer: listeners.get()){
@@ -177,7 +183,7 @@ public final class DynamicValue<T> implements Serializable{
/**
* Add a listener to be called as weak reference, when this value has been changed.
- * @param l the listner, not null
+ * @param l the listener, not null
*/
public void addListener(Consumer<PropertyChangeEvent> l) {
if(listeners==null){
@@ -197,7 +203,7 @@ public final class DynamicValue<T> implements Serializable{
}
/**
- * If a value is present in this {@code ConfiguredValue}, returns the value,
+ * If a value is present in this {@code DynamicValue}, returns the value,
* otherwise throws {@code ConfigException}.
*
* @return the non-null value held by this {@code Optional}
@@ -220,9 +226,6 @@ public final class DynamicValue<T> implements Serializable{
this.newValue = Optional.ofNullable(newValue);
commit();
break;
- case EXPLCIT:
- this.newValue = Optional.ofNullable(newValue);
- break;
case LOG_AND_DISCARD:
Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue="+newValue);
this.newValue = null;
@@ -230,6 +233,10 @@ public final class DynamicValue<T> implements Serializable{
case NEVER:
this.newValue = null;
break;
+ case EXPLCIT:
+ default:
+ this.newValue = Optional.ofNullable(newValue);
+ break;
}
}
@@ -288,10 +295,10 @@ public final class DynamicValue<T> implements Serializable{
*/
public DynamicValue<T> filter(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate);
- if (!isPresent())
+ if (!isPresent()) {
return this;
- else
- return predicate.test(value.get()) ? this : empty(propertyName);
+ }
+ return predicate.test(value.get()) ? this : empty(propertyName);
}
/**
@@ -299,7 +306,7 @@ public final class DynamicValue<T> implements Serializable{
* 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
+ * NOTE 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
@@ -325,11 +332,10 @@ public final class DynamicValue<T> implements Serializable{
*/
public <U> DynamicValue<U> map(Function<? super T, ? extends U> mapper) {
Objects.requireNonNull(mapper);
- if (!isPresent())
+ if (!isPresent()) {
return empty(propertyName);
- else {
- return DynamicValue.ofNullable(propertyName, mapper.apply(value.get()));
}
+ return DynamicValue.ofNullable(propertyName, mapper.apply(value.get()));
}
/**
@@ -351,11 +357,10 @@ public final class DynamicValue<T> implements Serializable{
*/
public <U> DynamicValue<U> flatMap(Function<? super T, DynamicValue<U>> mapper) {
Objects.requireNonNull(mapper);
- if (!isPresent())
+ if (!isPresent()) {
return empty(propertyName);
- else {
- return Objects.requireNonNull(mapper.apply(value.get()));
}
+ return Objects.requireNonNull(mapper.apply(value.get()));
}
/**
@@ -387,7 +392,7 @@ public final class DynamicValue<T> implements Serializable{
* 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
+ * NOTE A method reference to the exception constructor with an empty
* argument list can be used as the supplier. For example,
* {@code IllegalStateException::new}
*
@@ -420,8 +425,7 @@ public final class DynamicValue<T> implements Serializable{
oos.writeObject(updatePolicy);
if(isPresent()) {
oos.writeObject(this.value.get());
- }
- else{
+ } else{
oos.writeObject(null);
}
}
@@ -444,28 +448,28 @@ public final class DynamicValue<T> implements Serializable{
/**
* Simple helper that allows keeping the listeners registered as weak references, hereby avoiding any
* memory leaks.
- * @param <T> the type
+ * @param <I> the type
*/
- private class WeakList<T>{
- List<WeakReference<T>> refs = new LinkedList<>();
+ private class WeakList<I>{
+ final List<WeakReference<I>> refs = new LinkedList<>();
/**
* Adds a new instance.
* @param t the new instance, not null.
*/
- void add(T t){
- refs.add(new WeakReference(t));
+ void add(I t){
+ refs.add(new WeakReference<I>(t));
}
/**
* Removes a instance.
* @param t the instance to be removed.
*/
- void remove(T t){
+ void remove(I t){
synchronized (refs){
- for(Iterator<WeakReference<T>> iterator = refs.iterator();iterator.hasNext();){
- WeakReference<T> ref = iterator.next();
- T instance = ref.get();
+ for(Iterator<WeakReference<I>> iterator = refs.iterator();iterator.hasNext();){
+ WeakReference<I> ref = iterator.next();
+ I instance = ref.get();
if(instance==null || instance == t){
iterator.remove();
break;
@@ -479,16 +483,15 @@ public final class DynamicValue<T> implements Serializable{
* Access a list (copy) of the current instances that were not discarded by the GC.
* @return the list of accessible items.
*/
- public List<T> get() {
+ public List<I> get() {
synchronized (refs) {
- List<T> res = new ArrayList<>();
- for (Iterator<WeakReference<T>> iterator = refs.iterator(); iterator.hasNext(); ) {
- WeakReference<T> ref = iterator.next();
- T instance = ref.get();
+ List<I> res = new ArrayList<>();
+ for (Iterator<WeakReference<I>> iterator = refs.iterator(); iterator.hasNext(); ) {
+ WeakReference<I> ref = iterator.next();
+ I instance = ref.get();
if(instance==null){
iterator.remove();
- }
- else{
+ } else{
res.add(instance);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java b/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
index f0cf552..76d2c5e 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
@@ -18,7 +18,11 @@
*/
package org.apache.tamaya.inject;
-import java.lang.annotation.*;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
/**
* This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/PropertyChangeSet.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/PropertyChangeSet.java b/modules/injection/src/main/java/org/apache/tamaya/inject/PropertyChangeSet.java
index 57f4d19..bccb161 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/PropertyChangeSet.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/PropertyChangeSet.java
@@ -30,7 +30,7 @@ import java.util.*;
*/
public final class PropertyChangeSet implements Serializable{
/** The serialVersionUID. */
- private static final long serialVersionUID = 1l;
+ private static final long serialVersionUID = 1L;
/** The base property source name. */
private String propertySourceName;
/** The timestamp of the change. */
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
index acc0cab..f0c3796 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
@@ -32,7 +32,7 @@ import java.lang.annotation.Target;
* injecting the field keys.
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
+@Target(value = {ElementType.FIELD, ElementType.METHOD})
public @interface WithPropertyConverter {
/**
@@ -40,7 +40,6 @@ public @interface WithPropertyConverter {
* general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
* registered, it is handled as a deployment error.
*/
- @SuppressWarnings("rawtypes")
- Class<? extends PropertyConverter<?>> value();
+ Class<? extends PropertyConverter<?>> value();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
index 0d517c7..74ae68f 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.inject.internal;
-import org.apache.tamaya.Configuration;
import org.apache.tamaya.inject.PropertyChangeSet;
import java.lang.reflect.Method;
@@ -55,7 +54,8 @@ public final class ConfigChangeCallbackMethod {
callbackMethod.setAccessible(true);
callbackMethod.invoke(instance, configChangeEvent);
} catch (Exception e) {
- LOG.log(Level.SEVERE, e, () -> "Error calling ConfigChange callback method " + callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance);
+ LOG.log(Level.SEVERE, e, () -> "Error calling ConfigChange callback method " +
+ callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java
deleted file mode 100644
index 3377e63..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigurationInjector.java
+++ /dev/null
@@ -1,59 +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.inject.internal;
-
-import org.apache.tamaya.Configuration;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Simple injector singleton that also registers instances configured using weak references.
- */
-@SuppressWarnings("rawtypes")
-public final class ConfigurationInjector {
-
- private static final ConfigurationInjector INSTANCE = new ConfigurationInjector();
-
- private Map<Class, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
-
- /**
- * Extract the configuration annotation config and registers it per class, for later reuse.
- * @param type the type to be configured.
- * @return the configured type registered.
- */
- public static ConfiguredType registerType(Class<?> type){
- return INSTANCE.configuredTypes.computeIfAbsent(type, ConfiguredType::new);
- }
-
- /**
- * Configured the current instance and reigsterd necessary listener to forward config change events as
- * defined by the current annotations in place.
- * @param instance the instance to be configured
- */
- public static void configure(Object instance){
- Class type = Objects.requireNonNull(instance).getClass();
- ConfiguredType configuredType = registerType(type);
- Objects.requireNonNull(configuredType).configure(instance);
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
index 8880fe8..96b5f38 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -19,13 +19,10 @@
package org.apache.tamaya.inject.internal;
import java.lang.reflect.Field;
-import java.util.Collection;
import java.util.List;
import java.util.Objects;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.ConfiguredProperties;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.inject.DefaultAreas;
@@ -98,26 +95,11 @@ public class ConfiguredField {
* @param key the (qualified) configuration key, not null.
* @return true, if the key is referenced.
*/
- public boolean matchesKey(String configName, String key) {
- Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(this.annotatedField, ConfiguredProperty.class,
- ConfiguredProperties.class );
- for(ConfiguredProperty prop: configuredProperties){
- String currentName = prop.config().trim();
- if(currentName.isEmpty()){
- if(!"default".equals(configName)){
- continue;
- }
- }
- else if(!currentName.equals(configName)){
- continue;
- }
- DefaultAreas areasAnnot = this.annotatedField.getDeclaringClass().getAnnotation(DefaultAreas.class);
- List<String> keys = InjectionUtils.evaluateKeys(this.annotatedField, areasAnnot, prop);
- if( keys.contains(key)){
- return true;
- }
- }
- return false;
+ public boolean matchesKey(String key) {
+ ConfiguredProperty prop = this.annotatedField.getAnnotation(ConfiguredProperty.class);
+ DefaultAreas areasAnnot = this.annotatedField.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ List<String> keys = InjectionUtils.evaluateKeys(this.annotatedField, areasAnnot, prop);
+ return keys.contains(key);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 8f49f14..cc3ed05 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -19,19 +19,14 @@
package org.apache.tamaya.inject.internal;
import java.lang.reflect.Method;
-import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
-//import org.apache.tamaya.core.properties.PropertyChangeSet;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.ConfiguredProperties;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.inject.DefaultAreas;
import org.apache.tamaya.inject.PropertyChangeSet;
-//import org.apache.tamaya.core.internal.Utils;
/**
* Small class that contains and manages all information and access to a configured field and a concrete instance current
@@ -113,19 +108,12 @@ public class ConfiguredSetterMethod {
*/
public boolean matchesKey(String key) {
DefaultAreas areasAnnot = this.setterMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
- Collection<ConfiguredProperty> configuredProperties =
- Utils.getAnnotations(this.setterMethod, ConfiguredProperty.class, ConfiguredProperties.class);
- for(ConfiguredProperty prop: configuredProperties) {
- if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot, prop).contains(key)) {
- return true;
- }
- }
- if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot).contains(key)) {
+ ConfiguredProperty prop = this.setterMethod.getAnnotation(ConfiguredProperty.class);
+ if (InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot, prop).contains(key)) {
return true;
}
- return false;
+ return InjectionUtils.evaluateKeys(this.setterMethod, areasAnnot).contains(key);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
index 777430b..ff155c4 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
@@ -24,7 +24,6 @@ import java.util.*;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.ConfiguredProperties;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.inject.DefaultAreas;
import org.apache.tamaya.inject.NoConfig;
@@ -90,7 +89,7 @@ public class ConfiguredType {
continue;
}
ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
- Collection<ConfiguredProperty> propertiesAnnots = Utils.getAnnotations(m, ConfiguredProperty.class, ConfiguredProperties.class);
+ ConfiguredProperty prop = m.getAnnotation(ConfiguredProperty.class);
if (type.isInterface()) {
// it is a template
if (mAnnot != null) {
@@ -99,21 +98,21 @@ public class ConfiguredType {
}
} else {
if (m.isDefault()) {
- addPropertySetter(m, propertiesAnnots);
+ addPropertySetter(m, prop);
}
}
} else {
if (mAnnot != null) {
addObserverMethod(m);
} else {
- addPropertySetter(m, propertiesAnnots);
+ addPropertySetter(m, prop);
}
}
}
}
- private boolean addPropertySetter(Method m, Collection<ConfiguredProperty> propertiesAnnots) {
- if (!propertiesAnnots.isEmpty()) {
+ private boolean addPropertySetter(Method m, ConfiguredProperty prop) {
+ if (prop!=null) {
if (m.getParameterTypes().length == 0) {
// getter method
Class<?> returnType = m.getReturnType();
@@ -193,17 +192,6 @@ public class ConfiguredType {
}
// if no class level annotation is there we might have field level annotations only
for (Field field : type.getDeclaredFields()) {
- if (field.isAnnotationPresent(ConfiguredProperties.class)) {
- return true;
- }
- }
- // if no class level annotation is there we might have method level annotations only
- for (Method method : type.getDeclaredMethods()) {
- if (method.isAnnotationPresent(ConfiguredProperties.class)) {
- return true;
- }
- }
- for (Field field : type.getDeclaredFields()) {
if (field.isAnnotationPresent(ConfiguredProperty.class)) {
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
new file mode 100644
index 0000000..f62838c
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject.internal;
+
+import org.apache.tamaya.inject.ConfigurationInjector;
+
+import javax.annotation.Priority;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Simple injector singleton that also registers instances configured using weak references.
+ */
+@Priority(0)
+public final class DefaultConfigurationInjector implements ConfigurationInjector {
+
+ private Map<Class, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
+
+ /**
+ * Extract the configuration annotation config and registers it per class, for later reuse.
+ *
+ * @param type the type to be configured.
+ * @return the configured type registered.
+ */
+ public ConfiguredType registerTypeInternal(Class<?> type) {
+ return configuredTypes.computeIfAbsent(type, ConfiguredType::new);
+ }
+
+ @Override
+ public void registerType(Class<?> type) {
+ registerTypeInternal(type);
+ }
+
+ /**
+ * Configured the current instance and reigsterd necessary listener to forward config change events as
+ * defined by the current annotations in place.
+ *
+ * @param instance the instance to be configured
+ */
+ public void configure(Object instance) {
+ Class type = Objects.requireNonNull(instance).getClass();
+ ConfiguredType configuredType = registerTypeInternal(type);
+ Objects.requireNonNull(configuredType).configure(instance);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
index 3d905d8..3944cd6 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
@@ -24,7 +24,6 @@ import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.logging.Level;
@@ -32,7 +31,6 @@ import java.util.logging.Logger;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.ConfiguredProperties;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.inject.DefaultAreas;
import org.apache.tamaya.inject.DefaultValue;
@@ -52,7 +50,7 @@ final class InjectionUtils {
private static final Logger LOG = Logger.getLogger(InjectionUtils.class.getName());
- private static final boolean resolutionModuleLoaded = checkResolutionModuleLoaded();
+ private static final boolean RESOLUTION_MODULE_LOADED = checkResolutionModuleLoaded();
private static boolean checkResolutionModuleLoaded() {
try {
@@ -76,8 +74,7 @@ final class InjectionUtils {
*/
public static List<String> evaluateKeys(Member member, DefaultAreas areasAnnot, ConfiguredProperty propertyAnnotation) {
List<String> keys = new ArrayList<>(Arrays.asList(propertyAnnotation.keys()));
- if (keys.isEmpty()) //noinspection UnusedAssignment
- {
+ if (keys.isEmpty()) {
keys.add(member.getName());
}
ListIterator<String> iterator = keys.listIterator();
@@ -158,18 +155,15 @@ final class InjectionUtils {
* @return the keys to be returned, or null.
*/
private static String getConfigValueInternal(AnnotatedElement element, DefaultAreas areasAnnot, WithLoadPolicy loadPolicy) {
- Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(
- element, ConfiguredProperty.class, ConfiguredProperties.class);
+ ConfiguredProperty prop = element.getAnnotation(ConfiguredProperty.class);
DefaultValue defaultAnnot = element.getAnnotation(DefaultValue.class);
String configValue = null;
- if (configuredProperties.isEmpty()) {
+ if (prop == null) {
List<String> keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot);
- configValue = evaluteConfigValue(configValue, keys);
+ configValue = evaluteConfigValue(keys);
} else {
- for (ConfiguredProperty prop : configuredProperties) {
- List<String> keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
- configValue = evaluteConfigValue(configValue, keys);
- }
+ List<String> keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
+ configValue = evaluteConfigValue(keys);
}
if (configValue == null && defaultAnnot != null) {
return defaultAnnot.value();
@@ -177,9 +171,10 @@ final class InjectionUtils {
return configValue;
}
- private static String evaluteConfigValue(String configValue, List<String> keys) {
+ private static String evaluteConfigValue(List<String> keys) {
+ String configValue = null;
for (String key : keys) {
- configValue = Configuration.current().get(key).orElse(null);
+ configValue = Configuration.current().get(key);
if (configValue != null) {
break;
}
@@ -225,16 +220,16 @@ final class InjectionUtils {
}
public static boolean isResolutionModuleLoaded() {
- return resolutionModuleLoaded;
+ return RESOLUTION_MODULE_LOADED;
}
public static String evaluateValue(String value) {
- if (!resolutionModuleLoaded) {
+ if (!RESOLUTION_MODULE_LOADED) {
return value;
}
ExpressionEvaluator evaluator = ServiceContext.getInstance().getService(ExpressionEvaluator.class).orElse(null);
if (evaluator != null) {
- return evaluator.filterProperty("<injection>", value, (k) -> Configuration.current().get(k).orElse(null));
+ return evaluator.evaluateExpression("<injection>", value);
}
return value;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/Utils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/Utils.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/Utils.java
index 47eec95..2c08467 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/Utils.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/Utils.java
@@ -38,35 +38,36 @@ public final class Utils {
private static final Logger LOG = Logger.getLogger(Utils.class.getName());
- private Utils(){}
+ private Utils() {
+ }
/**
* Utility method to read out repeatable annotations.
- * @param annotated the annotated instance.
+ *
+ * @param annotated the annotated instance.
* @param repeatableAnnotation the repeatable annotation type
- * @param annotationContainer the container annotation type
- * @param <T> the repeatable annotation type
- * @param <R> the repeatable container annotation type
+ * @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).
*/
- public static <T extends Annotation, R extends Annotation> Collection<T>
- getAnnotations(AnnotatedElement annotated,
- Class<T> repeatableAnnotation,
- Class<R> annotationContainer){
+ public static <T extends Annotation, R extends Annotation> Collection<T>
+ getAnnotations(AnnotatedElement annotated,
+ Class<T> repeatableAnnotation,
+ Class<R> annotationContainer) {
List<T> result = new ArrayList<>();
R containerAnnot = annotated.getAnnotation(annotationContainer);
- if(containerAnnot!=null){
+ if (containerAnnot != null) {
Method valueMethod;
try {
valueMethod = annotationContainer.getMethod("keys");
- result.addAll(Arrays.asList((T[])valueMethod.invoke(containerAnnot)));
+ result.addAll(Arrays.asList((T[]) valueMethod.invoke(containerAnnot)));
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to evaluate repeatable annotation.", e);
}
- }
- else{
+ } else {
T annot = annotated.getAnnotation(repeatableAnnotation);
- if(annot!=null){
+ if (annot != null) {
result.add(annot);
}
}
@@ -75,31 +76,31 @@ public final class Utils {
/**
* Utility method to read out repeatable annotations.
- * @param annotated the annotated instance.
+ *
+ * @param annotated the annotated instance.
* @param repeatableAnnotation the repeatable annotation type
- * @param annotationContainer the container annotation type
- * @param <T> the repeatable annotation type
- * @param <R> the repeatable container annotation type
+ * @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).
*/
public static <T extends Annotation, R extends Annotation> Collection<T>
getAnnotations(AccessibleObject annotated,
Class<T> repeatableAnnotation,
- Class<R> annotationContainer){
+ Class<R> annotationContainer) {
List<T> result = new ArrayList<>();
R containerAnnot = annotated.getAnnotation(annotationContainer);
- if(containerAnnot!=null){
+ if (containerAnnot != null) {
Method valueMethod;
try {
valueMethod = annotationContainer.getMethod("keys");
- result.addAll(Arrays.asList((T[])valueMethod.invoke(containerAnnot)));
+ result.addAll(Arrays.asList((T[]) valueMethod.invoke(containerAnnot)));
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to evaluate repeatable annotation.", e);
}
- }
- else{
+ } else {
T annot = annotated.getAnnotation(repeatableAnnotation);
- if(annot!=null){
+ if (annot != null) {
result.add(annot);
}
}
@@ -108,16 +109,17 @@ public final class Utils {
/**
* Utility method to read out repeatable annotations.
+ *
* @param annotationType the annotation type.
- * @param objects the accessible objects to be looked up
- * @param <T> the repeatable 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).
*/
public static <T extends Annotation> T getAnnotation(
- Class<T> annotationType, AnnotatedElement... objects){
- for(AnnotatedElement obj:objects){
+ Class<T> annotationType, AnnotatedElement... objects) {
+ for (AnnotatedElement obj : objects) {
T annot = obj.getAnnotation(annotationType);
- if(annot!=null){
+ if (annot != null) {
return annot;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
index cf8f9ae..dd8bf31 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
@@ -31,28 +31,32 @@ import java.util.logging.Logger;
/**
* Simple listener container that only holds weak references on the listeners.
*/
-public final class WeakConfigListenerManager{
+public final class WeakConfigListenerManager {
private static final WeakConfigListenerManager INSTANCE = new WeakConfigListenerManager();
private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
private StampedLock lock = new StampedLock();
- private Map<Object,Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
+ private Map<Object, Consumer<PropertyChangeSet>> listenerReferences = new WeakHashMap<>();
- /** Private singleton constructor. */
- private WeakConfigListenerManager(){}
+ /**
+ * Private singleton constructor.
+ */
+ private WeakConfigListenerManager() {
+ }
- public static WeakConfigListenerManager of(){
+ public static WeakConfigListenerManager of() {
return INSTANCE;
}
/**
* Registers the given consumer for the instance. If a consumer already exists for this instance the given
* consumer is appended.
+ *
* @param instance the instance, not null.
* @param listener the consumer.
*/
- public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener){
+ public void registerConsumer(Object instance, Consumer<PropertyChangeSet> listener) {
Lock writeLock = lock.asWriteLock();
try {
writeLock.lock();
@@ -62,14 +66,14 @@ public final class WeakConfigListenerManager{
} else {
listenerReferences.put(instance, l.andThen(listener));
}
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
/**
* Unregisters all consumers for the given instance.
+ *
* @param instance the instance, not null.
*/
public void unregisterConsumer(Object instance) {
@@ -77,37 +81,35 @@ public final class WeakConfigListenerManager{
try {
writeLock.lock();
listenerReferences.remove(instance);
- }
- finally{
+ } finally {
writeLock.unlock();
}
}
/**
* Publishes a change event to all consumers registered.
+ *
* @param change the change event, not null.
*/
- public void publishChangeEvent(PropertyChangeSet change){
+ public void publishChangeEvent(PropertyChangeSet change) {
Lock readLock = lock.asReadLock();
- try{
+ try {
readLock.lock();
listenerReferences.values().parallelStream().forEach(l -> {
- try{
+ try {
l.accept(change);
- }
- catch(Exception e){
+ } catch (Exception e) {
LOG.log(Level.SEVERE, "ConfigChangeListener failed: " + l.getClass().getName(), e);
}
});
- }
- finally{
+ } finally {
readLock.unlock();
}
}
@Override
- public String toString(){
+ public String toString() {
return "WeakConfigListenerManager{" +
"listenerReferences=" + listenerReferences +
'}';
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.inject.ConfigurationInjector
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.inject.ConfigurationInjector b/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.inject.ConfigurationInjector
new file mode 100644
index 0000000..7204749
--- /dev/null
+++ b/modules/injection/src/main/resources/META-INF/services/org.apache.tamaya.inject.ConfigurationInjector
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.inject.internal.DefaultConfigurationInjector
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/java/annottext/AnnotatedConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfig.java b/modules/injection/src/test/java/annottext/AnnotatedConfig.java
deleted file mode 100644
index 782c5c7..0000000
--- a/modules/injection/src/test/java/annottext/AnnotatedConfig.java
+++ /dev/null
@@ -1,51 +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 annottext;
-
-import org.apache.tamaya.inject.ConfiguredProperty;
-import org.apache.tamaya.inject.DefaultValue;
-import org.apache.tamaya.inject.LoadPolicy;
-import org.apache.tamaya.inject.WithLoadPolicy;
-
-/**
- * An example showing some basic annotations, using an interface to be proxied by the
- * configuration system.
- * Created by Anatole on 15.02.14.
- */
-@WithLoadPolicy(LoadPolicy.INITIAL)
-public interface AnnotatedConfig {
-
- @ConfiguredProperty(keys = "foo.bar.myprop")
- @ConfiguredProperty(keys = "mp")
- @ConfiguredProperty(keys = "common.testdata.myProperty")
- @DefaultValue("myValue_$[env.stage]")
- // @ConfigLoadPolicy(listener = MyListener.class)
- String myParameter();
-
- @ConfiguredProperty(keys = "simple_value")
- @WithLoadPolicy(LoadPolicy.LAZY)
- String simpleValue();
-
- @ConfiguredProperty
- String simplestValue();
-
- @ConfiguredProperty(keys = "env.host.name")
- String hostName();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java b/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
new file mode 100644
index 0000000..c1eb39c
--- /dev/null
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
@@ -0,0 +1,57 @@
+/*
+ * 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 annottext;
+
+import org.apache.tamaya.inject.ConfiguredProperty;
+import org.apache.tamaya.inject.DefaultValue;
+import org.apache.tamaya.inject.LoadPolicy;
+import org.apache.tamaya.inject.WithLoadPolicy;
+
+/**
+ * An example showing some basic annotations, using an interface to be proxied by the
+ * configuration system, nevertheless extending the overall Configuration interface.
+ * Created by Anatole on 15.02.14.
+ */
+@WithLoadPolicy(LoadPolicy.INITIAL)
+public class AnnotatedConfigBean {
+
+ @ConfiguredProperty(keys = {"foo.bar.myprop", "mp", "common.testdata.myProperty"})
+ @DefaultValue("ET")
+ // @ConfigLoadPolicy(listener = MyListener.class)
+ public String myParameter;
+
+ @ConfiguredProperty(keys = "simple_value")
+ @WithLoadPolicy(LoadPolicy.LAZY)
+ public String simpleValue;
+
+ @ConfiguredProperty
+ String anotherValue;
+
+ @ConfiguredProperty(keys = "host.name")
+ private String hostName;
+
+ public String getAnotherValue(){
+ return anotherValue;
+ }
+
+ public String getHostName(){
+ return hostName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java b/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
new file mode 100644
index 0000000..8aa3f54
--- /dev/null
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
@@ -0,0 +1,49 @@
+/*
+ * 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 annottext;
+
+import org.apache.tamaya.inject.ConfiguredProperty;
+import org.apache.tamaya.inject.DefaultValue;
+import org.apache.tamaya.inject.LoadPolicy;
+import org.apache.tamaya.inject.WithLoadPolicy;
+
+/**
+ * An example showing some basic annotations, using an interface to be proxied by the
+ * configuration system.
+ * Created by Anatole on 15.02.14.
+ */
+@WithLoadPolicy(LoadPolicy.INITIAL)
+public interface AnnotatedConfigTemplate {
+
+ @ConfiguredProperty(keys = {"foo.bar.myprop", "mp","common.testdata.myProperty"})
+ @DefaultValue("myValue_${env.stage}")
+ // @ConfigLoadPolicy(listener = MyListener.class)
+ String myParameter();
+
+ @ConfiguredProperty(keys = "simple_value")
+ @WithLoadPolicy(LoadPolicy.LAZY)
+ String simpleValue();
+
+ @ConfiguredProperty
+ String simplestValue();
+
+ @ConfiguredProperty(keys = "host.name")
+ String hostName();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java b/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java
deleted file mode 100644
index 92e71b3..0000000
--- a/modules/injection/src/test/java/annottext/AnnotatedFullConfig.java
+++ /dev/null
@@ -1,52 +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 annottext;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.ConfiguredProperty;
-import org.apache.tamaya.inject.DefaultValue;
-import org.apache.tamaya.inject.LoadPolicy;
-import org.apache.tamaya.inject.WithLoadPolicy;
-
-/**
- * An example showing some basic annotations, using an interface to be proxied by the
- * configuration system, nevertheless extending the overall Configuration interface.
- * Created by Anatole on 15.02.14.
- */
-@WithLoadPolicy(LoadPolicy.INITIAL)
-public interface AnnotatedFullConfig extends Configuration{
-
- @ConfiguredProperty(keys = "foo.bar.myprop")
- @ConfiguredProperty(keys = "mp")
- @ConfiguredProperty(keys = "common.testdata.myProperty")
- @DefaultValue("myValue_$[env.stage]")
- // @ConfigLoadPolicy(listener = MyListener.class)
- String myParameter();
-
- @ConfiguredProperty(keys = "simple_value")
- @WithLoadPolicy(LoadPolicy.LAZY)
- String simpleValue();
-
- @ConfiguredProperty
- String simplestValue();
-
- @ConfiguredProperty(keys = "env.host.name")
- String hostName();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java b/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
new file mode 100644
index 0000000..654e97a
--- /dev/null
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/TamayaInjectionTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject;
+
+import annottext.AnnotatedConfigBean;
+import annottext.AnnotatedConfigTemplate;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Created by Anatole on 12.01.2015.
+ */
+public class TamayaInjectionTest {
+
+ @Test
+ public void testInjectionClass(){
+ assertNotNull(ConfigurationInjector.getInstance());
+ AnnotatedConfigBean testInstance = new AnnotatedConfigBean();
+ assertEquals(testInstance.getHostName(), null);
+ assertEquals(testInstance.getAnotherValue(), null);
+ assertEquals(testInstance.myParameter, null);
+ assertEquals(testInstance.simpleValue, null);
+ ConfigurationInjector.getInstance().configure(testInstance);
+ assertEquals(testInstance.getHostName(), "tamaya01.incubator.apache.org");
+ assertEquals(testInstance.getAnotherValue(), "HALLO!");
+ assertEquals(testInstance.myParameter, "ET");
+ assertEquals(testInstance.simpleValue, "aSimpleValue");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java b/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
new file mode 100644
index 0000000..7303f60
--- /dev/null
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by Anatole on 12.01.2015.
+ */
+public class TestPropertySource implements PropertySource {
+
+ private Map<String,String> properties = new HashMap<>();
+
+ public TestPropertySource(){
+ properties.put("env.stage", "ET");
+ properties.put("simple_value", "aSimpleValue");
+ properties.put("host.name", "tamaya01.incubator.apache.org");
+ properties.put("anotherValue", "HALLO!");
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ return properties.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/resources/META-INF/beans.xml b/modules/injection/src/test/resources/META-INF/beans.xml
deleted file mode 100644
index 5207c9a..0000000
--- a/modules/injection/src/test/resources/META-INF/beans.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<beans xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-</beans>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..5dfb894
--- /dev/null
+++ b/modules/injection/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.inject.TestPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e586a448/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index e1dd591..10bca33 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -34,7 +34,7 @@ under the License.
<packaging>pom</packaging>
<modules>
- <!-- module>injection</module -->
+ <module>injection</module>
<module>formats</module>
<module>json</module>
<module>resolver</module>