You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2014/12/20 15:31:06 UTC
[1/5] incubator-tamaya git commit: TAMAYA-8: Added some javadocs.
TAMAYA-30: Added Codecs TAMAYA 31: Reduced number of annotations TAMAYA 34:
Added Config overrides.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 31161dfdb -> c8c513565
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java
new file mode 100644
index 0000000..a257852
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultCodecsSingletonSpi.java
@@ -0,0 +1,162 @@
+/*
+ * 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.core.internal.properties;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecsSingletonSpi;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.Currency;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+/**
+ * Default codecs singleton, which provides default codesc for all kind of classes out of the box, which will be
+ * instantiatable from configuration, if one of the following is given:
+ * <ul>
+ * <li>static factory methods using a String as simgle argument, called {@code of, valueOf, getInstance, instance, parse}</li>
+ * <li>have constructors taking a single String</li>
+ * </ul>
+ */
+public class DefaultCodecsSingletonSpi implements CodecsSingletonSpi {
+
+ private Map<Class,Codec> adapters = new ConcurrentHashMap<>();
+
+ public DefaultCodecsSingletonSpi(){
+ // Add default adapters
+ register(char.class, (s) -> s.charAt(0), (ch) -> String.valueOf(ch));
+ register(int.class, Integer::parseInt, Object::toString);
+ register(byte.class, Byte::parseByte, Object::toString);
+ register(short.class, Short::parseShort, Object::toString);
+ register(boolean.class, Boolean::parseBoolean, b -> String.valueOf(b));
+ register(float.class, Float::parseFloat, f -> String.valueOf(f));
+ register(double.class, Double::parseDouble, d -> String.valueOf(d));
+
+ register(Character.class, (s) -> s.charAt(0), Object::toString);
+ register(Integer.class, Integer::valueOf, Object::toString);
+ register(Byte.class, Byte::valueOf, Object::toString);
+ register(Short.class, Short::valueOf, String::valueOf);
+ register(Boolean.class, Boolean::valueOf, b -> String.valueOf(b));
+ register(Float.class, Float::valueOf, f -> String.valueOf(f));
+ register(Double.class, Double::valueOf, d -> String.valueOf(d));
+ register(BigDecimal.class, BigDecimal::new, String::valueOf);
+ register(BigInteger.class, BigInteger::new, String::valueOf);
+
+ register(Currency.class, Currency::getInstance, Object::toString);
+
+ register(LocalDate.class, LocalDate::parse, Object::toString);
+ register(LocalTime.class, LocalTime::parse, Object::toString);
+ register(LocalDateTime.class, LocalDateTime::parse, Object::toString);
+ register(ZoneId.class, ZoneId::of, ZoneId::getId);
+ }
+
+ @Override
+ public <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
+ return adapters.put(targetType, adapter);
+ }
+
+ @Override
+ public <T> Codec<T> getCodec(Class<T> targetType, WithCodec adapterAnnot){
+ Codec codec = null;
+ Class<? extends Codec> configuredCodec = null;
+ if(adapterAnnot != null){
+ configuredCodec = adapterAnnot.value();
+ if(!configuredCodec.equals(Codec.class)){
+ try{
+ codec = configuredCodec.newInstance();
+ }
+ catch(Exception e){
+ throw new ConfigException("Invalid codec configured.", e);
+ }
+ }
+ }
+ if(codec == null){
+ codec = adapters.get(targetType);
+ }
+ if(codec == null){
+ codec = getDefaultCodec(targetType);
+ }
+ return codec;
+ }
+
+ private <T> Codec getDefaultCodec(Class<T> targetType) {
+ Function<String, T> decoder = null;
+ Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "parse");
+ if(factoryMethod!=null){
+ decoder = (s) -> {
+ try{
+ factoryMethod.setAccessible(true);
+ return targetType.cast(factoryMethod.invoke(s));
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ }
+ if(decoder==null) {
+ try {
+ Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ decoder = (s) -> {
+ try{
+ constr.setAccessible(true);
+ return (T)constr.newInstance(s);
+ }
+ catch (Exception e){
+ throw new ConfigException("Failed to decode '"+s+"'", e);
+ }
+ };
+ } catch (Exception e) {
+ // ignore, TODO log finest
+ }
+ }
+ if(decoder!=null) {
+ return register(targetType, decoder, String::valueOf);
+ }
+ return null;
+ }
+
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for(String name:methodNames){
+ try{
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ }
+ catch(Exception e){
+ // ignore, TODO log finest
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isTargetTypeSupported(Class<?> targetType){
+ return adapters.containsKey(targetType);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultPropertyAdaptersSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultPropertyAdaptersSingletonSpi.java
deleted file mode 100644
index a8791a8..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultPropertyAdaptersSingletonSpi.java
+++ /dev/null
@@ -1,100 +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.core.internal.properties;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.PropertyAdapter;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.spi.PropertyAdaptersSingletonSpi;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.util.Currency;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Created by Anatole on 30.09.2014.
- */
-public class DefaultPropertyAdaptersSingletonSpi implements PropertyAdaptersSingletonSpi{
-
- private Map<Class,PropertyAdapter> adapters = new ConcurrentHashMap<>();
-
- public DefaultPropertyAdaptersSingletonSpi(){
- // Add default adapters
- register(char.class, (s) -> s.charAt(0));
- register(int.class, Integer::parseInt);
- register(byte.class, Byte::parseByte);
- register(short.class, Short::parseShort);
- register(boolean.class, Boolean::parseBoolean);
- register(float.class, Float::parseFloat);
- register(double.class, Double::parseDouble);
-
- register(Character.class, (s) -> s.charAt(0));
- register(Integer.class, Integer::parseInt);
- register(Byte.class, Byte::parseByte);
- register(Short.class, Short::parseShort);
- register(Boolean.class, Boolean::parseBoolean);
- register(Float.class, Float::parseFloat);
- register(Double.class, Double::parseDouble);
- register(BigDecimal.class, BigDecimal::new);
- register(BigInteger.class, BigInteger::new);
-
- register(Currency.class, Currency::getInstance);
-
- register(LocalDate.class, LocalDate::parse);
- register(LocalTime.class, LocalTime::parse);
- register(LocalDateTime.class, LocalDateTime::parse);
- register(ZoneId.class, ZoneId::of);
- }
-
- @Override
- public <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter){
- return adapters.put(targetType, adapter);
- }
-
- @Override
- public <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter adapterAnnot){
- PropertyAdapter adapter = null;
- Class<? extends PropertyAdapter> configuredAdapter = null;
- if(adapterAnnot != null){
- configuredAdapter = adapterAnnot.value();
- if(!configuredAdapter.equals(PropertyAdapter.class)){
- try{
- adapter = configuredAdapter.newInstance();
- }
- catch(Exception e){
- throw new ConfigException("Invalid adapter configured.", e);
- }
- }
- }
- if(adapter == null){
- adapter = adapters.get(targetType);
- }
- return adapter;
- }
-
- @Override
- public boolean isTargetTypeSupported(Class<?> targetType){
- return adapters.containsKey(targetType);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
index 7626e19..0fd542b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/AntPathMatcher.java
@@ -105,8 +105,8 @@ class AntPathMatcher {
/**
* Specify whether to cache parsed pattern metadata for patterns passed
- * into this matcher's {@link #match} method. A value current {@code true}
- * activates an unlimited pattern cache; a value current {@code false} turns
+ * into this matcher's {@link #match} method. A keys current {@code true}
+ * activates an unlimited pattern cache; a keys current {@code false} turns
* the pattern cache off completely.
* <p>Default is for the cache to be on, but with the variant to automatically
* turn it off when encountering too many patterns to cache at runtime
@@ -286,7 +286,7 @@ class AntPathMatcher {
if (tokenized == null) {
tokenized = tokenizePath(pattern);
if (cachePatterns == null && this.tokenizedPatternCache.size() >= CACHE_TURNOFF_THRESHOLD) {
- // Try to adapt to the runtime situation that we're encountering:
+ // Try to deserialize to the runtime situation that we're encountering:
// There are obviously too many different patterns coming in here...
// So let's turn off the cache since the patterns are unlikely to be reoccurring.
deactivatePatternCache();
@@ -340,7 +340,7 @@ class AntPathMatcher {
if (matcher == null) {
matcher = new AntPathStringMatcher(pattern);
if (cachePatterns == null && this.stringMatcherCache.size() >= CACHE_TURNOFF_THRESHOLD) {
- // Try to adapt to the runtime situation that we're encountering:
+ // Try to deserialize to the runtime situation that we're encountering:
// There are obviously too many different patterns coming in here...
// So let's turn off the cache since the patterns are unlikely to be reoccurring.
deactivatePatternCache();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
index 82b9d6e..919ed30 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
@@ -63,24 +63,24 @@ public class ClassUtils {
/**
* Map with primitive wrapper type as key and corresponding primitive
- * type as value, for example: Integer.class -> int.class.
+ * type as keys, for example: Integer.class -> int.class.
*/
private static final Map<Class<?>, Class<?>> primitiveWrapperTypeMap = new HashMap<>(8);
/**
* Map with primitive type as key and corresponding wrapper
- * type as value, for example: int.class -> Integer.class.
+ * type as keys, for example: int.class -> Integer.class.
*/
private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new HashMap<>(8);
/**
* Map with primitive type name as key and corresponding primitive
- * type as value, for example: "int" -> "int.class".
+ * type as keys, for example: "int" -> "int.class".
*/
private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<>(32);
//
// /**
-// * Map with common "java.lang" class name as key and corresponding Class as value.
+// * Map with common "java.lang" class name as key and corresponding Class as keys.
// * Primarily for efficient deserialization current remote invocations.
// */
// private static final Map<String, Class<?>> commonClassCache = new HashMap<String, Class<?>>(32);
@@ -509,14 +509,14 @@ public class ClassUtils {
// * Return a descriptive name for the given object's type: usually simply
// * the class name, but component type class name + "[]" for arrays,
// * and an appended list current implemented interfaces for JDK proxies.
-// * @param value the value to introspect
+// * @param keys the keys to introspect
// * @return the qualified name current the class
// */
-// public static String getDescriptiveType(Object value) {
-// if (value == null) {
+// public static String getDescriptiveType(Object keys) {
+// if (keys == null) {
// return null;
// }
-// Class<?> clazz = value.getClass();
+// Class<?> clazz = keys.getClass();
// if (Proxy.isProxyClass(clazz)) {
// StringBuilder result = new StringBuilder(clazz.getName());
// result.append(" implementing ");
@@ -892,8 +892,8 @@ public class ClassUtils {
// * type, assuming setting by reflection. Considers primitive wrapper
// * classes as assignable to the corresponding primitive types.
// * @param lhsType the target type
-// * @param rhsType the value type that should be assigned to the target type
-// * @return if the target type is assignable from the value type
+// * @param rhsType the keys type that should be assigned to the target type
+// * @return if the target type is assignable from the keys type
// */
// public static boolean isAssignable(Class<?> lhsType, Class<?> rhsType) {
// Objects.requireNonNull(lhsType, "Left-hand side type must not be null");
@@ -917,16 +917,16 @@ public class ClassUtils {
// }
//
// /**
-// * Determine if the given type is assignable from the given value,
+// * Determine if the given type is assignable from the given keys,
// * assuming setting by reflection. Considers primitive wrapper classes
// * as assignable to the corresponding primitive types.
// * @param type the target type
-// * @param value the value that should be assigned to the type
-// * @return if the type is assignable from the value
+// * @param keys the keys that should be assigned to the type
+// * @return if the type is assignable from the keys
// */
-// public static boolean isAssignableValue(Class<?> type, Object value) {
+// public static boolean isAssignableValue(Class<?> type, Object keys) {
// Objects.requireNonNull(type, "Type must not be null");
-// return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive());
+// return (keys != null ? isAssignable(type, keys.getClass()) : !type.isPrimitive());
// }
//
//
@@ -953,7 +953,7 @@ public class ClassUtils {
// /**
// * Return a path suitable for use with {@code ClassLoader.getResource}
// * (also suitable for use with {@code Class.getResource} by prepending a
-// * slash ('/') to the return value). Built by taking the package current the specified
+// * slash ('/') to the return keys). Built by taking the package current the specified
// * class file, converting all dots ('.') to slashes ('/'), adding a trailing slash
// * if necessary, and concatenating the specified resource name to this.
// * <br/>As such, this function may be used to build a path suitable for
@@ -981,8 +981,8 @@ public class ClassUtils {
* could be concatenated with a slash and the name current a resource and fed
* directly to {@code ClassLoader.getResource()}. For it to be fed to
* {@code Class.getResource} instead, a leading slash would also have
- * to be prepended to the returned value.
- * @param clazz the input class. A {@code null} value or the default
+ * to be prepended to the returned keys.
+ * @param clazz the input class. A {@code null} keys or the default
* (empty) package will result in an empty string ("") being returned.
* @return a path which represents the package name
* @see ClassLoader#getResource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
index 9ae49e7..d8fa274 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/DefaultResourceLoader.java
@@ -23,7 +23,7 @@ import java.net.URL;
import java.util.Objects;
/**
- * <p>Will return a {@code UrlResource} if the location value is a URL,
+ * <p>Will return a {@code UrlResource} if the location keys is a URL,
* and a {@code ClassPathResource} if it is a non-URL path or a
* "classpath:" pseudo-URL.
*
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
index d1a401d..dd466f4 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/FileSystemResource.java
@@ -46,7 +46,7 @@ public class FileSystemResource extends AbstractResource {
/**
* Create a new {@code FileSystemResource} from a {@link File} handle.
* <p>Note: When building relative resources via {@link #createRelative},
- * the relative path will apply <i>at the same directory level</i>:
+ * the relative path will applyChanges <i>at the same directory level</i>:
* e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"!
* If you prefer to have relative paths built underneath the given root
* directory, use the {@link #FileSystemResource(String) constructor with a file path}
@@ -66,7 +66,7 @@ public class FileSystemResource extends AbstractResource {
* it makes a difference whether the specified resource base path here
* ends with a slash or not. In the case current "C:/dir1/", relative paths
* will be built underneath that root: e.g. relative path "dir2" ->
- * "C:/dir1/dir2". In the case current "C:/dir1", relative paths will apply
+ * "C:/dir1/dir2". In the case current "C:/dir1", relative paths will applyChanges
* at the same directory level: relative path "dir2" -> "C:/dir2".
* @param path a file path
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
index 5d37917..0784e57 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
@@ -77,7 +77,7 @@ class StringUtils {
// * will never return {@code true} for a non-null non-String object.
// * <p>The Object signature is useful for general attribute handling code
// * that commonly deals with Strings but generally has to iterate over
-// * Objects since attributes may e.g. be primitive value objects as well.
+// * Objects since attributes may e.g. be primitive keys objects as well.
// * @param str the candidate String
// * @since 3.2.1
// */
@@ -579,7 +579,7 @@ class StringUtils {
* Apply the given relative path to the given path,
* assuming standard Java folder separation (i.e. "/" separators).
* @param path the path to start from (usually a full file path)
- * @param relativePath the relative path to apply
+ * @param relativePath the relative path to applyChanges
* (relative to the full file path above)
* @return the full file path that results from applying the relative path
*/
@@ -673,7 +673,7 @@ class StringUtils {
// }
//
// /**
-// * Parse the given {@code localeString} value into a {@link Locale}.
+// * Parse the given {@code localeString} keys into a {@link Locale}.
// * <p>This is the inverse operation current {@link Locale#toString Locale's toString}.
// * @param localeString the locale String, following {@code Locale's}
// * {@code toString()} format ("en", "en_UK", etc);
@@ -722,7 +722,7 @@ class StringUtils {
// }
//
// /**
-// * Parse the given {@code timeZoneString} value into a {@link TimeZone}.
+// * Parse the given {@code timeZoneString} keys into a {@link TimeZone}.
// * @param timeZoneString the time zone String, following {@link TimeZone#getTimeZone(String)}
// * but throwing {@link IllegalArgumentException} in case current an invalid time zone specification
// * @return a corresponding {@link TimeZone} instance
@@ -909,8 +909,8 @@ class StringUtils {
// /**
// * Take an array Strings and split each element based on the given delimiter.
// * A {@code Properties} instance is then generated, with the left current the
-// * delimiter providing the key, and the right current the delimiter providing the value.
-// * <p>Will trim both the key and value before adding them to the
+// * delimiter providing the key, and the right current the delimiter providing the keys.
+// * <p>Will trim both the key and keys before adding them to the
// * {@code Properties} instance.
// * @param array the array to process
// * @param delimiter to split each element using (typically the equals symbol)
@@ -924,8 +924,8 @@ class StringUtils {
// /**
// * Take an array Strings and split each element based on the given delimiter.
// * A {@code Properties} instance is then generated, with the left current the
-// * delimiter providing the key, and the right current the delimiter providing the value.
-// * <p>Will trim both the key and value before adding them to the
+// * delimiter providing the key, and the right current the delimiter providing the keys.
+// * <p>Will trim both the key and keys before adding them to the
// * {@code Properties} instance.
// * @param array the array to process
// * @param delimiter to split each element using (typically the equals symbol)
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
index cecff40..325c4e6 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/resources/io/WritableResource.java
@@ -36,7 +36,7 @@ public interface WritableResource extends Resource {
* e.g. via {@link #getOutputStream()} or {@link #getFile()}.
* <p>Will be {@code true} for typical resource descriptors;
* note that actual content writing may still fail when attempted.
- * However, a value current {@code false} is a definitive indication
+ * However, a keys current {@code false} is a definitive indication
* that the resource content cannot be modified.
* @see #getOutputStream()
* @see #isReadable()
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
index 1e9acd3..b12fcd6 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
@@ -92,7 +92,7 @@ public abstract class AbstractPropertySource implements PropertySource, Serializ
@Override
public String toString(){
StringBuilder b = new StringBuilder(getClass().getSimpleName()).append("{\n");
- b.append(" ").append("(").append(MetaInfoBuilder.NAME).append(" = ").append(getMetaInfo().get(MetaInfoBuilder.NAME)).append(")\n");
+ b.append(" ").append("(").append(MetaInfo.NAME).append(" = ").append(getMetaInfo().getName()).append(")\n");
printContents(b);
return b.append('}').toString();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
index 3039b6c..cb6928b 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/AggregatedPropertySource.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.core.properties;
import org.apache.tamaya.*;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
import java.util.*;
@@ -86,11 +85,11 @@ class AggregatedPropertySource extends AbstractPropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
*/
@Override
- public void apply(ConfigChangeSet change){
+ public void applyChanges(ConfigChangeSet change){
if(mutableProvider!=null)
- mutableProvider.apply(change);
+ mutableProvider.applyChanges(change);
else
- super.apply(change);
+ super.applyChanges(change);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
index 504e1f7..fc2492d 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ContextualPropertySource.java
@@ -125,8 +125,8 @@ class ContextualPropertySource implements PropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
*/
@Override
- public void apply(ConfigChangeSet change){
- getContextualMap().apply(change);
+ public void applyChanges(ConfigChangeSet change){
+ getContextualMap().applyChanges(change);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
index f8dc36c..3558046 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/FilteredPropertySource.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.ConfigChangeSet;
import org.apache.tamaya.MetaInfo;
import org.apache.tamaya.MetaInfoBuilder;
import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
import java.util.HashMap;
import java.util.Map;
@@ -67,8 +66,8 @@ class FilteredPropertySource extends AbstractPropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
*/
@Override
- public void apply(ConfigChangeSet change){
- this.unit.apply(change);
+ public void applyChanges(ConfigChangeSet change){
+ this.unit.applyChanges(change);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
index 378d8b3..9f2e90c 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/MapBasedPropertySource.java
@@ -89,7 +89,7 @@ class MapBasedPropertySource extends AbstractPropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
*/
@Override
- public void apply(ConfigChangeSet change){
+ public void applyChanges(ConfigChangeSet change){
change.getEvents().forEach(this::applyChange);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
index 392b298..e5c9290 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
@@ -124,7 +124,7 @@ public final class PropertySourceBuilder {
/**
* Sets the aggregation policy to be used, when adding additional property sets. The policy will
- * be active a slong as the builder is used or it is reset to another value.
+ * be active a slong as the builder is used or it is reset to another keys.
*
* @param aggregationPolicy the aggregation policy, not null.
* @return the builder for chaining.
@@ -181,7 +181,7 @@ public final class PropertySourceBuilder {
MetaInfo mi = this.metaInfo;
if (mi == null) {
mi = MetaInfoBuilder.of("aggregate")
- .set(MetaInfoBuilder.SOURCE,source).build();
+ .setSources(source).build();
}
this.current = PropertySourceFactory.aggregate(mi, this.aggregationPolicy, allProviders);
@@ -507,7 +507,7 @@ public final class PropertySourceBuilder {
* created.
*
* @param key the key to be added, not null.
- * @param value the value to be added, not null.
+ * @param value the keys to be added, not null.
* @return this builder for chaining
*/
public PropertySourceBuilder setMeta(String key, String value){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
index cee7891..1219e0e 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
@@ -101,8 +101,8 @@ class ReplacingPropertySource implements PropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
*/
@Override
- public void apply(ConfigChangeSet change){
- this.mainMap.apply(change);
+ public void applyChanges(ConfigChangeSet change){
+ this.mainMap.applyChanges(change);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java b/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
index 5cdb349..dc02693 100644
--- a/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/properties/SubtractingPropertySource.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.ConfigChangeSet;
import org.apache.tamaya.MetaInfo;
import org.apache.tamaya.MetaInfoBuilder;
import org.apache.tamaya.PropertySource;
-import org.apache.tamaya.core.properties.AbstractPropertySource;
import java.util.*;
import java.util.stream.Collectors;
@@ -71,8 +70,8 @@ class SubtractingPropertySource extends AbstractPropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
*/
@Override
- public void apply(ConfigChangeSet change){
- this.unit.apply(change);
+ public void applyChanges(ConfigChangeSet change){
+ this.unit.applyChanges(change);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/resource/Resource.java b/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
index 511be7e..9dde674 100644
--- a/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
+++ b/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
@@ -52,7 +52,7 @@ public interface Resource extends InputStreamSource {
* e.g. via {@link #getInputStream()} or {@link #getFile()}.
* <p>Will be {@code true} for typical resource descriptors;
* note that actual content reading may still fail when attempted.
- * However, a value current {@code false} is a definitive indication
+ * However, a keys current {@code false} is a definitive indication
* that the resource content cannot be read.
* @see #getInputStream()
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java b/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
index 1638eec..6cb6dc1 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
@@ -18,11 +18,10 @@
*/
package org.apache.tamaya.core.spi;
-import org.apache.tamaya.PropertyAdapter;
-import java.util.function.Function;
+import org.apache.tamaya.Codec;
/**
- * This service provides different {@link org.apache.tamaya.PropertyAdapter} instances for types.
+ * This service provides different {@link org.apache.tamaya.Codec} instances for types.
*/
public interface AdapterProviderSpi{
@@ -32,6 +31,6 @@ public interface AdapterProviderSpi{
* @return the corresponding {@link java.util.function.Function<String, T>}, or {@code null}, if
* not available for the given target type.
*/
- <T> PropertyAdapter<T> getAdapter(Class<T> type);
+ <T> Codec<T> getAdapter(Class<T> type);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java b/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
index f46d69c..5baa956 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/ExpressionEvaluator.java
@@ -18,10 +18,21 @@
*/
package org.apache.tamaya.core.spi;
+import org.apache.tamaya.Configuration;
+
/**
- * Created by Anatole on 12.10.2014.
+ * This interfaces provides a model for expression evaluation. This enables transparently plugin expression languages
+ * as needed. In a Java EE context full fledged EL may be used, whereas in ME only simple replacement mechanisms
+ * are better suited to the runtime requirements.
*/
@FunctionalInterface
public interface ExpressionEvaluator {
- String evaluate(String expression);
+ /**
+ * Evaluates the given expression.
+ * @param expression the expression to be evaluated, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
+ * @return the evaluated expression.
+ */
+ String evaluate(String expression, Configuration... configurations);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java b/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
index fa5bd7c..a6ba9bb 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/ExpressionResolver.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya.core.spi;
+import org.apache.tamaya.Configuration;
+
/**
* This interface defines a small plugin for resolving current expressions within configuration.
* Resolver expression always have the form current <code>${resolverId:expression}</code>. The
@@ -42,9 +44,12 @@ public interface ExpressionResolver {
* as {@code blabla to be interpreted AND executed.} only.
*
* @param expression the stripped expression.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurations provided by the current
+ * registered providers are used.
* @return the resolved expression.
* @throws org.apache.tamaya.ConfigException when the expression passed is not resolvable, e.g. due to syntax issues
* or data not present or valid.
*/
- String resolve(String expression);
+ String resolve(String expression, Configuration... configurations);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java b/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
index fef8c9c..1c06afa 100644
--- a/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
+++ b/core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
@@ -25,39 +25,39 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.tamaya.PropertyAdapter;
+import org.apache.tamaya.Codec;
public interface PropertyAdapterService{
- public default PropertyAdapter<URL> getURLAdapter(){
- return PropertyAdapter.class.cast(getClassAdapter(URL.class));
+ public default Codec<URL> getURLAdapter(){
+ return Codec.class.cast(getClassAdapter(URL.class));
}
- public default PropertyAdapter<InputStream> getClasspathResourceAdapter(){
- return PropertyAdapter.class.cast(getClassAdapter(InputStream.class));
+ public default Codec<InputStream> getClasspathResourceAdapter(){
+ return Codec.class.cast(getClassAdapter(InputStream.class));
}
- public default PropertyAdapter<File> getFileAdapter(){
- return PropertyAdapter.class.cast(getClassAdapter(File.class));
+ public default Codec<File> getFileAdapter(){
+ return Codec.class.cast(getClassAdapter(File.class));
}
- public default PropertyAdapter<Set<String>> getSetAdapter(){
- return PropertyAdapter.class.cast(getClassAdapter(Set.class));
+ public default Codec<Set<String>> getSetAdapter(){
+ return Codec.class.cast(getClassAdapter(Set.class));
}
- public default PropertyAdapter<Map<String, String>> getMapAdapter(){
- return PropertyAdapter.class.cast(getClassAdapter(Map.class));
+ public default Codec<Map<String, String>> getMapAdapter(){
+ return Codec.class.cast(getClassAdapter(Map.class));
}
- public default PropertyAdapter<List<String>> getListAdapter(){
- return PropertyAdapter.class.cast(getClassAdapter(List.class));
+ public default Codec<List<String>> getListAdapter(){
+ return Codec.class.cast(getClassAdapter(List.class));
}
- public default <T> PropertyAdapter<Class<? extends T>> getClassAdapter(Class<T> requiredType){
+ public default <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType){
return getClassAdapter(requiredType, Thread.currentThread().getContextClassLoader());
}
- public <T> PropertyAdapter<Class<? extends T>> getClassAdapter(Class<T> requiredType,
+ public <T> Codec<Class<? extends T>> getClassAdapter(Class<T> requiredType,
ClassLoader... classLoaders);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
new file mode 100644
index 0000000..599b50f
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
@@ -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.core.internal.properties.DefaultCodecsSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi
deleted file mode 100644
index 207176e..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi
+++ /dev/null
@@ -1,19 +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 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.core.internal.properties.DefaultPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java b/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
index adcca93..0f81a10 100644
--- a/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
+++ b/core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.core.config;
import org.apache.tamaya.ConfigChangeSet;
import org.apache.tamaya.ConfigChangeSetBuilder;
import org.apache.tamaya.Configuration;
-import org.junit.Ignore;
import org.junit.Test;
import java.beans.PropertyChangeEvent;
@@ -42,7 +41,7 @@ public class MutableConfigTest {
.put("execTime", System.currentTimeMillis()).put("execution", "once").build();
List<PropertyChangeEvent> changes = new ArrayList<>();
Configuration.addChangeListener(cfg -> cfg == config, change -> changes.addAll(change.getEvents()));
- config.apply(changeSet);
+ config.applyChanges(changeSet);
assertFalse(changes.isEmpty());
System.out.println(changes);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
index 226faf9..9d3b494 100644
--- a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
@@ -90,7 +90,7 @@ public class MutableTestConfigProvider implements ConfigurationProviderSpi{
}
@Override
- public void apply(ConfigChangeSet changeSet) {
+ public void applyChanges(ConfigChangeSet changeSet) {
for(PropertyChangeEvent change: changeSet.getEvents()){
if(change.getNewValue()==null){
this.data.remove(change.getPropertyName());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
index 60e6cb8..d185de1 100644
--- a/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/TestConfigProvider.java
@@ -34,18 +34,18 @@ public class TestConfigProvider implements ConfigurationProviderSpi{
public TestConfigProvider(){
final Map<String,String> config = new HashMap<>();
- config.put("a.b.c.key1", "value current a.b.c.key1");
- config.put("a.b.c.key2", "value current a.b.c.key2");
- config.put("a.b.key3", "value current a.b.key3");
- config.put("a.b.key4", "value current a.b.key4");
- config.put("a.key5", "value current a.key5");
- config.put("a.key6", "value current a.key6");
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("a.b.key3", "keys current a.b.key3");
+ config.put("a.b.key4", "keys current a.b.key4");
+ config.put("a.key5", "keys current a.key5");
+ config.put("a.key6", "keys current a.key6");
config.put("int1", "123456");
config.put("int2", "111222");
config.put("booleanT", "true");
config.put("double1", "1234.5678");
config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
- config.put("testProperty", "value current testProperty");
+ config.put("testProperty", "keys current testProperty");
config.put("runtimeVersion", "${java.version}");
testConfig = PropertySourceBuilder.of("test").addMap(
config).build().toConfiguration();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/samples/annotations/ConfigTemplate.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfigTemplate.java b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfigTemplate.java
index b28714e..9dfa5d0 100644
--- a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfigTemplate.java
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfigTemplate.java
@@ -31,15 +31,16 @@ public interface ConfigTemplate {
@ConfiguredProperty
String testProperty();
- @ConfiguredProperty("Foo")
+ @ConfiguredProperty(keys = "Foo")
@DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
String value1();
// COMPUTERNAME is only under Windows available
- @ConfiguredProperty("COMPUTERNAME")
+ @ConfiguredProperty
+ @DefaultValue("${env:COMPUTERNAME}")
String computerName();
- @ConfiguredProperty("HOME")
+ @ConfiguredProperty(keys = "HOME")
String homeDir();
@ConfiguredProperty
@@ -61,6 +62,6 @@ public interface ConfigTemplate {
@ConfiguredProperty
boolean booleanT();
- @ConfiguredProperty("BD")
+ @ConfiguredProperty(keys = "BD")
BigDecimal bigNumber();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
index c1db60b..c01ee63 100644
--- a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredClass.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.samples.annotations;
import org.apache.tamaya.annotation.ObservesConfigChange;
import org.apache.tamaya.annotation.ConfiguredProperty;
import org.apache.tamaya.annotation.DefaultValue;
-import org.apache.tamaya.annotation.WithConfig;
import java.beans.PropertyChangeEvent;
import java.math.BigDecimal;
@@ -34,15 +33,14 @@ public class ConfiguredClass{
@ConfiguredProperty
private String testProperty;
- @ConfiguredProperty("a.b.c.key1")
- @ConfiguredProperty("a.b.c.key2")
- @ConfiguredProperty("a.b.c.key3")
+ @ConfiguredProperty(keys = "a.b.c.key1")
+ @ConfiguredProperty(keys = "a.b.c.key2")
+ @ConfiguredProperty(keys = "a.b.c.key3")
@DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
String value1;
- @WithConfig("test")
- @ConfiguredProperty("foo")
- @ConfiguredProperty("a.b.c.key2")
+ @ConfiguredProperty(config="test", keys = "foo")
+ @ConfiguredProperty(keys = "a.b.c.key2")
private String value2;
@ConfiguredProperty
@@ -57,16 +55,13 @@ public class ConfiguredClass{
@DefaultValue("5")
private Integer int1;
- @WithConfig("test")
- @ConfiguredProperty
+ @ConfiguredProperty(config = "test")
private int int2;
- @WithConfig("test")
- @ConfiguredProperty
+ @ConfiguredProperty(config = "test")
private boolean booleanT;
- @WithConfig("test")
- @ConfiguredProperty("BD")
+ @ConfiguredProperty(config="test", keys ="BD")
private BigDecimal bigNumber;
@ObservesConfigChange
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
index 208fa4d..76cb225 100644
--- a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
@@ -34,7 +34,7 @@ public class ConfiguredTest {
@Test
public void testTemplateOnAllSystems(){
- ConfigTemplate template = Configuration.current(ConfigTemplate.class);
+ ConfigTemplate template = Configuration.createTemplate(ConfigTemplate.class);
assertNotNull(template);
assertEquals(2233, template.int2());
assertEquals(Integer.valueOf(5), template.int1());
@@ -44,16 +44,14 @@ public class ConfiguredTest {
@Test
public void testTemplateWithEnvironmentVariableOnWindows(){
assumeTrue(OS.contains("win"));
-
- ConfigTemplate template = Configuration.current(ConfigTemplate.class);
+ ConfigTemplate template = Configuration.createTemplate(ConfigTemplate.class);
assertNotNull(template.computerName());
}
@Test
public void testTemplateWithEnvironmentVariableOnMac(){
assumeTrue(OS.contains("mac"));
-
- ConfigTemplate template = Configuration.current(ConfigTemplate.class);
+ ConfigTemplate template = Configuration.createTemplate(ConfigTemplate.class);
assertNotNull(template.homeDir());
}
@@ -61,7 +59,7 @@ public class ConfiguredTest {
public void testTemplateWithEnvironmentVariableOnUnixoidSystem(){
assumeTrue(OS.contains("nix") || OS.contains("nux") || OS.indexOf("aix") > 0);
- ConfigTemplate template = Configuration.current(ConfigTemplate.class);
+ ConfigTemplate template = Configuration.createTemplate(ConfigTemplate.class);
assertNotNull(template.homeDir());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index c487bdb..d794eff 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@ -33,13 +33,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
- * Configuration is organized as key/value pairs. This basically can be modeled as {@code Map<String,String>}
+ * Configuration is organized as key/keys pairs. This basically can be modeled as {@code Map<String,String>}
* Configuration should be as simple as possible. A {@code Map<String,String>} instance has methods that may not
* be used in many use cases and/or are not easy to implement. Currently the following functionality
* must be supported:
* <ul>
- * <li>access a value by key (+get+)</li>
- * <li>check if a value is present (+containsKey+)</li>
+ * <li>access a keys by key (+get+)</li>
+ * <li>check if a keys is present (+containsKey+)</li>
* <li>get a set current all defined keys (+keySet+)</li>
* <li>a property provider must be convertible to a +Map+, by calling +toMap()+</li>
* <li>a property provider must get access to its meta information.</li>
@@ -48,8 +48,8 @@ import static org.junit.Assert.assertNotNull;
* <ul>
* <li>The API must never return null.</li>
* <li>The API should support undefined values.</li>
- * <li>The API must support passing default values, to be returned if a value is undefined.</li>
- * <li>The API must allow to throw exceptions, when a value is undefined.
+ * <li>The API must support passing default values, to be returned if a keys is undefined.</li>
+ * <li>The API must allow to throw exceptions, when a keys is undefined.
* Customized exceptions hereby should be supported.</li>
* <li>Properties can be stored in the classpath, on a file.</li>
* <li>Properties can be stored as properties, xml-properties or as ini-files.</li>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
index 993048b..ccb4909 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
@@ -25,7 +25,7 @@ import org.junit.Test;
import static junit.framework.TestCase.assertTrue;
/**
- * Configuration is organized as key/value pairs. This basically can be modeled as {@code Map<String,String>}
+ * Configuration is organized as key/keys pairs. This basically can be modeled as {@code Map<String,String>}
* Configuration should be as simple as possible. Advanced use cases can often easily implemented by combining
* multiple property maps and applying hereby some combination policy. This test class demonstrates the different
* options Tamaya is providing and the according mechanisms.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
index 20dfa71..be65f0a 100644
--- a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
@@ -39,15 +39,15 @@ public class ConfiguredClass{
@ConfiguredProperty
private String testProperty;
- @ConfiguredProperty("a.b.c.key1")
- @ConfiguredProperty("a.b.c.key2")
- @ConfiguredProperty("a.b.c.key3")
+ @ConfiguredProperty(keys = "a.b.c.key1")
+ @ConfiguredProperty(keys = "a.b.c.key2")
+ @ConfiguredProperty(keys = "a.b.c.key3")
@DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
String value1;
@WithConfig("test")
- @ConfiguredProperty("foo")
- @ConfiguredProperty("a.b.c.key2")
+ @ConfiguredProperty(keys = "foo")
+ @ConfiguredProperty(keys = "a.b.c.key2")
private String value2;
@ConfiguredProperty
@@ -71,11 +71,11 @@ public class ConfiguredClass{
private boolean booleanT;
@WithConfig("test")
- @ConfiguredProperty("BD")
+ @ConfiguredProperty(keys = "BD")
private BigDecimal bigNumber;
@WithConfig("test")
- @ConfiguredProperty("double1")
+ @ConfiguredProperty(keys = "double1")
private double doubleValue;
@ObservesConfigChange
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
index 6c92379..a0de005 100644
--- a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/TestConfigProvider.java
@@ -35,19 +35,19 @@ public class TestConfigProvider implements ConfigurationProviderSpi
public TestConfigProvider(){
final Map<String,String> config = new HashMap<>();
- config.put("a.b.c.key1", "value current a.b.c.key1");
- config.put("a.b.c.key2", "value current a.b.c.key2");
- config.put("a.b.key3", "value current a.b.key3");
- config.put("a.b.key4", "value current a.b.key4");
- config.put("a.key5", "value current a.key5");
- config.put("a.key6", "value current a.key6");
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("a.b.key3", "keys current a.b.key3");
+ config.put("a.b.key4", "keys current a.b.key4");
+ config.put("a.key5", "keys current a.key5");
+ config.put("a.key6", "keys current a.key6");
config.put("int1", "123456");
config.put("int2", "111222");
config.put("testProperty", "testPropertyValue!");
config.put("booleanT", "true");
config.put("double1", "1234.5678");
config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
- config.put("testProperty", "value current testProperty");
+ config.put("testProperty", "keys current testProperty");
config.put("runtimeVersion", "${java.version}");
testConfig = PropertySourceBuilder.of("test").addMap(config).build().toConfiguration();
}
[5/5] incubator-tamaya git commit: Fixed merge issue.
Posted by an...@apache.org.
Fixed merge issue.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/c8c51356
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/c8c51356
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/c8c51356
Branch: refs/heads/master
Commit: c8c513565f4df5e92ef1474b61ef105ab739b17f
Parents: f8c9103
Author: anatole <an...@apache.org>
Authored: Sat Dec 20 15:30:50 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Dec 20 15:30:50 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/core/config/MappedConfiguration.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c8c51356/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
index 5833e2c..e668b91 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
@@ -51,8 +51,8 @@ class MappedConfiguration extends AbstractConfiguration implements Configuration
}
@Override
- public void apply(ConfigChangeSet change) {
- this.config.apply(change);
+ public void applyChanges(ConfigChangeSet change) {
+ this.config.applyChanges(change);
}
@Override
[2/5] incubator-tamaya git commit: TAMAYA-8: Added some javadocs.
TAMAYA-30: Added Codecs TAMAYA 31: Reduced number of annotations TAMAYA 34:
Added Config overrides.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
index d044982..43c6248 100644
--- a/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
+++ b/api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
@@ -36,53 +36,54 @@ public class TestConfigServiceSingletonSpi implements ConfigurationManagerSingle
public TestConfigServiceSingletonSpi(){
Map<String,String> config = new HashMap<>();
- config.put("a.b.c.key1", "value current a.b.c.key1");
- config.put("a.b.c.key2", "value current a.b.c.key2");
- config.put("a.b.key3", "value current a.b.key3");
- config.put("a.b.key4", "value current a.b.key4");
- config.put("a.key5", "value current a.key5");
- config.put("a.key6", "value current a.key6");
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("a.b.key3", "keys current a.b.key3");
+ config.put("a.b.key4", "keys current a.b.key4");
+ config.put("a.key5", "keys current a.key5");
+ config.put("a.key6", "keys current a.key6");
config.put("int1", "123456");
config.put("int2", "111222");
config.put("booleanT", "true");
config.put("double1", "1234.5678");
config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
- config.put("testProperty", "value current testProperty");
+ config.put("testProperty", "keys current testProperty");
config.put("runtimeVersion", "${java.version}");
// configs.put("test", new MapConfiguration(MetaInfoBuilder.current().setName("test").build(), config));
}
+
+
@Override
public boolean isConfigurationDefined(String name){
return configs.containsKey(name);
}
@Override
- public <T> T getConfiguration(String name, Class<T> type){
- if(type.equals(Configuration.class)) {
- Configuration config = configs.get(name);
- return (T)Optional.ofNullable(config).orElseThrow(() -> new ConfigException("No such config: " + name));
- }
- throw new ConfigException("Not such config name="+name+", type="+ type.getName());
+ public Configuration getConfiguration(String name) {
+ // TODO
+ throw new UnsupportedOperationException("Not yet implemented");
}
@Override
- public <T> T getConfiguration(Class<T> type) {
+ public <T> T createTemplate(Class<T> type, Configuration... configurations) {
// TODO
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
- public void configure(Object instance) {
+ public void configure(Object instance, Configuration... configurations) {
// TODO
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
- public String evaluateValue(Configuration config, String expression){
+ public String evaluateValue(String expression, Configuration... configurations) {
// TODO improve this ugly implementation...
- for(Map.Entry<String, String> en: config.toMap().entrySet()){
- expression = expression.replaceAll("\\$\\{"+en.getKey()+"\\}", en.getValue());
+ for (Configuration config : configurations) {
+ for (Map.Entry<String, String> en : config.toMap().entrySet()) {
+ expression = expression.replaceAll("\\$\\{" + en.getKey() + "\\}", en.getValue());
+ }
}
return expression;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
index 2d3cfbc..b05c356 100644
--- a/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
+++ b/api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
@@ -18,8 +18,9 @@
*/
package org.apache.tamaya;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.spi.PropertyAdaptersSingletonSpi;
+import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecsSingletonSpi;
+
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
@@ -32,66 +33,66 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Test implementation current {@link PropertyAdaptersSingletonSpi}, which provides adapters
+ * Test implementation current {@link org.apache.tamaya.spi.CodecsSingletonSpi}, which provides codecs
* for some basic types.
*/
-public final class TestPropertyAdaptersSingletonSpi implements PropertyAdaptersSingletonSpi{
+public final class TestPropertyAdaptersSingletonSpi implements CodecsSingletonSpi {
- private Map<Class, PropertyAdapter<?>> adapters = new ConcurrentHashMap<>();
+ private Map<Class, Codec<?>> codecs = new ConcurrentHashMap<>();
private TestPropertyAdaptersSingletonSpi(){
- register(char.class, (s) -> s.charAt(0));
- register(int.class, Integer::parseInt);
- register(byte.class, Byte::parseByte);
- register(short.class, Short::parseShort);
- register(boolean.class, Boolean::parseBoolean);
- register(float.class, Float::parseFloat);
- register(double.class, Double::parseDouble);
+ register(char.class, (s) -> s.charAt(0), (ch) -> String.valueOf(ch));
+ register(int.class, Integer::parseInt, Object::toString);
+ register(byte.class, Byte::parseByte, Object::toString);
+ register(short.class, Short::parseShort, Object::toString);
+ register(boolean.class, Boolean::parseBoolean, b -> String.valueOf(b));
+ register(float.class, Float::parseFloat, f -> String.valueOf(f));
+ register(double.class, Double::parseDouble, d -> String.valueOf(d));
- register(Character.class, (s) -> s.charAt(0));
- register(Integer.class, Integer::parseInt);
- register(Byte.class, Byte::parseByte);
- register(Short.class, Short::parseShort);
- register(Boolean.class, Boolean::parseBoolean);
- register(Float.class, Float::parseFloat);
- register(Double.class, Double::parseDouble);
- register(BigDecimal.class, BigDecimal::new);
- register(BigInteger.class, BigInteger::new);
+ register(Character.class, (s) -> s.charAt(0), Object::toString);
+ register(Integer.class, Integer::valueOf, Object::toString);
+ register(Byte.class, Byte::valueOf, Object::toString);
+ register(Short.class, Short::valueOf, String::valueOf);
+ register(Boolean.class, Boolean::valueOf, String::valueOf);
+ register(Float.class, Float::valueOf, String::valueOf);
+ register(Double.class, Double::valueOf, String::valueOf);
+ register(BigDecimal.class, BigDecimal::new, String::valueOf);
+ register(BigInteger.class, BigInteger::new, String::valueOf);
- register(Currency.class, Currency::getInstance);
+ register(Currency.class, Currency::getInstance, Object::toString);
- register(LocalDate.class, LocalDate::parse);
- register(LocalTime.class, LocalTime::parse);
- register(LocalDateTime.class, LocalDateTime::parse);
- register(ZoneId.class, ZoneId::of);
+ register(LocalDate.class, LocalDate::parse, Object::toString);
+ register(LocalTime.class, LocalTime::parse, Object::toString);
+ register(LocalDateTime.class, LocalDateTime::parse, Object::toString);
+ register(ZoneId.class, ZoneId::of, ZoneId::getId);
}
@Override
- public <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter){
+ public <T> Codec<T> register(Class<T> targetType, Codec<T> codec){
Objects.requireNonNull(targetType);
- Objects.requireNonNull(adapter);
- return (PropertyAdapter<T>)adapters.put(targetType, adapter);
+ Objects.requireNonNull(codec);
+ return (Codec<T>) codecs.put(targetType, codec);
}
@Override
- public <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter annotation){
+ public <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation){
if(annotation!=null){
Class<?> adapterType = annotation.value();
- if(!adapterType.equals(PropertyAdapter.class)){
+ if(!adapterType.equals(Codec.class)){
try{
- return (PropertyAdapter<T>)adapterType.newInstance();
+ return (Codec<T>)adapterType.newInstance();
}
catch(Exception e){
throw new ConfigException("Failed to load PropertyAdapter: " + adapterType, e);
}
}
}
- return (PropertyAdapter<T>) adapters.get(targetType);
+ return (Codec<T>) codecs.get(targetType);
}
@Override
public boolean isTargetTypeSupported(Class<?> targetType){
- return adapters.containsKey(targetType);
+ return codecs.containsKey(targetType);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
new file mode 100644
index 0000000..e9b04b4
--- /dev/null
+++ b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.CodecsSingletonSpi
@@ -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.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi
deleted file mode 100644
index e9b04b4..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyAdaptersSingletonSpi
+++ /dev/null
@@ -1,19 +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 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.TestPropertyAdaptersSingletonSpi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
index cfd0da3..836db3f 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
@@ -48,10 +48,10 @@ public abstract class AbstractConfiguration extends AbstractPropertySource imple
@Override
public <T> Optional<T> get(String key, Class<T> type){
AdapterProviderSpi as = ServiceContext.getInstance().getSingleton(AdapterProviderSpi.class);
- PropertyAdapter<T> adapter = as.getAdapter(type);
+ Codec<T> adapter = as.getAdapter(type);
if(adapter == null){
throw new ConfigException(
- "Can not adapt config property '" + key + "' to " + type.getName() + ": no such " +
+ "Can not deserialize config property '" + key + "' to " + type.getName() + ": no such " +
"adapter.");
}
return getAdapted(key, adapter);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
index c9d924f..ddd83e2 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigFunctions.java
@@ -132,7 +132,7 @@ public final class ConfigFunctions {
/**
* Creates a {@link UnaryOperator} that creates a {@link org.apache.tamaya.Configuration} that maps any keys as
* defined by the {@code keyMapper} given. If the {@code keyMapper} returns
- * {@code null} for a value, it is removed from the resulting map.
+ * {@code null} for a keys, it is removed from the resulting map.
*
* @param keyMapper the key mapper, not null
* @return the area configuration, with the areaKey stripped away.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
index 3355e6b..176cc38 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
@@ -108,7 +108,7 @@ public final class ConfigurationBuilder {
/**
* Sets the aggregation policy to be used, when adding additional property sets. The policy will
- * be active a slong as the builder is used or it is reset to another value.
+ * be active a slong as the builder is used or it is reset to another keys.
*
* @param aggregationPolicy the aggregation policy, not null.
* @return the builder for chaining.
@@ -341,7 +341,7 @@ public final class ConfigurationBuilder {
* created.
*
* @param key the key to be added, not null.
- * @param value the value to be added, not null.
+ * @param value the keys to be added, not null.
* @return this builder for chaining
*/
public ConfigurationBuilder setMeta(String key, String value){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
index 24c715e..8d1207f 100644
--- a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
@@ -3,8 +3,6 @@ package org.apache.tamaya.core.config;
import org.apache.tamaya.*;
import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Predicate;
import java.util.function.UnaryOperator;
/**
@@ -46,8 +44,8 @@ class MappedConfiguration extends AbstractConfiguration implements Configuration
}
@Override
- public void apply(ConfigChangeSet change) {
- this.config.apply(change);
+ public void applyChanges(ConfigChangeSet change) {
+ this.config.applyChanges(change);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java b/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
index 7445430..895ac76 100644
--- a/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
+++ b/core/src/main/java/org/apache/tamaya/core/env/EnvironmentBuilder.java
@@ -52,7 +52,7 @@ public final class EnvironmentBuilder{
/**
* Sets a new environment property.
* @param key the key, not null.
- * @param value the value, not null.
+ * @param value the keys, not null.
* @return the builder for chaining
*/
public EnvironmentBuilder set(String key, String value){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/Utils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/Utils.java b/core/src/main/java/org/apache/tamaya/core/internal/Utils.java
index 6990de2..0089b8f 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/Utils.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/Utils.java
@@ -57,7 +57,7 @@ public final class Utils {
if(containerAnnot!=null){
Method valueMethod;
try {
- valueMethod = annotationContainer.getMethod("value");
+ valueMethod = annotationContainer.getMethod("keys");
result.addAll(Arrays.asList((T[])valueMethod.invoke(containerAnnot)));
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to evaluate repeatable annotation.", e);
@@ -90,7 +90,7 @@ public final class Utils {
if(containerAnnot!=null){
Method valueMethod;
try {
- valueMethod = annotationContainer.getMethod("value");
+ valueMethod = annotationContainer.getMethod("keys");
result.addAll(Arrays.asList((T[])valueMethod.invoke(containerAnnot)));
} catch (Exception e) {
LOG.log(Level.SEVERE, "Failed to evaluate repeatable annotation.", e);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/config/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/ConfigTemplateInvocationHandler.java b/core/src/main/java/org/apache/tamaya/core/internal/config/ConfigTemplateInvocationHandler.java
deleted file mode 100644
index 18e9d03..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/ConfigTemplateInvocationHandler.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 org.apache.tamaya.core.internal.config;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.internal.inject.ConfiguredType;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.Objects;
-
-/**
- * Invocation handler that handles request against a configuration template.
- */
-class ConfigTemplateInvocationHandler implements InvocationHandler {
- /** The underlying configuration. */
- private Configuration config;
- /** The configured type. */
- private ConfiguredType type;
-
- public ConfigTemplateInvocationHandler(Class<?> type, Configuration config) {
- this.config = Objects.requireNonNull(config);
- this.type = new ConfiguredType(Objects.requireNonNull(type));
- if(!type.isInterface()){
- throw new IllegalArgumentException("Can only proxy interfaces as configuration templates.");
- }
- }
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if("toString".equals(method.getName())){
- return "Configured Proxy -> " + this.type.getType().getName();
- }
- return this.type.getConfiguredValue(method, args);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
index 1a04cef..e3e0bba 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.core.internal.config;
import org.apache.tamaya.*;
import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
+import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
@@ -64,43 +65,21 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
}
@Override
- public <T> T getConfiguration(String name, Class<T> type) {
- ConfigurationProviderSpi provider = configProviders.get(name);
- if (provider == null) {
- if (DEFAULT_CONFIG_NAME.equals(name)) {
- provider = new FallbackSimpleConfigProvider();
- configProviders.put(DEFAULT_CONFIG_NAME, provider);
- } else {
- throw new ConfigException("No such config: " + name);
- }
- }
- Configuration config = provider.getConfiguration();
- if (config == null) {
- throw new ConfigException("No such config: " + name);
- }
- if (Configuration.class.equals(type)) {
- return (T) config;
- }
- return createAdapterProxy(config, type);
+ public <T> T createTemplate(Class<T> type, Configuration... configurations) {
+ ClassLoader cl = Optional.ofNullable(Thread.currentThread()
+ .getContextClassLoader()).orElse(getClass().getClassLoader());
+ return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, configurations));
}
/**
- * Creates a proxy implementing the given target interface.
*
- * @param config the configuration to be used for providing values.
- * @param type the target interface.
- * @param <T> the target interface type.
- * @return the corresponding implementing proxy, never null.
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
*/
- private <T> T createAdapterProxy(Configuration config, Class<T> type) {
- ClassLoader cl = Optional.ofNullable(Thread.currentThread()
- .getContextClassLoader()).orElse(getClass().getClassLoader());
- return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, config));
- }
-
@Override
- public void configure(Object instance) {
- ConfigurationInjector.configure(instance);
+ public void configure(Object instance, Configuration... configurations) {
+ ConfigurationInjector.configure(instance, configurations);
}
private String getConfigId(Annotation... qualifiers) {
@@ -119,8 +98,8 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
}
@Override
- public String evaluateValue(Configuration config, String expression) {
- return expressionEvaluator.evaluate(expression);
+ public String evaluateValue(String expression, Configuration... configurations) {
+ return expressionEvaluator.evaluate(expression, configurations);
}
@Override
@@ -162,9 +141,34 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
return spi != null;
}
+ @Override
+ public Configuration getConfiguration(String name) {
+ ConfigurationProviderSpi provider = configProviders.get(name);
+ if (provider == null) {
+ if (DEFAULT_CONFIG_NAME.equals(name)) {
+ provider = new FallbackSimpleConfigProvider();
+ configProviders.put(DEFAULT_CONFIG_NAME, provider);
+ } else {
+ throw new ConfigException("No such config: " + name);
+ }
+ }
+ Configuration config = provider.getConfiguration();
+ if (config == null) {
+ throw new ConfigException("No such config: " + name);
+ }
+ return config;
+ }
+
/**
* Implementation of a default config provider used as fallback, if no {@link org.apache.tamaya.core.spi.ConfigurationProviderSpi}
- * instance is registered for providing the {@code default} {@link org.apache.tamaya.Configuration}.
+ * instance is registered for providing the {@code default} {@link org.apache.tamaya.Configuration}. The providers loads the follwing
+ * config resources:
+ * <ul>
+ * <li>Classpath: META-INF/cfg/default/**/*.xml, META-INF/cfg/default/**/*.properties, META-INF/cfg/default/**/*.ini</li>
+ * <li>Classpath: META-INF/cfg/config/#42;#42;/#42;.xml, META-INF/cfg/config/#42;#42;/#42;.properties, META-INF/cfg/config/#42;#42;/#42;.ini</li>
+ * <li>Files: defined by the system property -Dconfig.dir</li>
+ * <li>system properties</li>
+ * </ul>
*/
private static final class FallbackSimpleConfigProvider implements ConfigurationProviderSpi {
/**
@@ -190,19 +194,22 @@ public class DefaultConfigurationManagerSingletonSpi implements ConfigurationMan
@Override
public void reload() {
- this.configuration =
+ PropertySourceBuilder builder =
PropertySourceBuilder.of(DEFAULT_CONFIG_NAME)
.addProviders(PropertySourceBuilder.of("CL default")
.withAggregationPolicy(AggregationPolicy.LOG_ERROR)
- .addPaths("META-INF/cfg/default/**/*.xml", "META-INF/cfg/default/**/*.properties", "META-INF/cfg/default/**/*.ini")
+ .addPaths("classpath:META-INF/cfg/default/**/*.xml", "classpath:META-INF/cfg/default/**/*.properties", "classpath:META-INF/cfg/default/**/*.ini")
.build())
.addProviders(PropertySourceBuilder.of("CL default")
.withAggregationPolicy(AggregationPolicy.LOG_ERROR)
- .addPaths("META-INF/cfg/config/**/*.xml", "META-INF/cfg/config/**/*.properties", "META-INF/cfg/config/**/*.ini")
- .build())
- .addSystemProperties()
- .addEnvironmentProperties()
- .build().toConfiguration();
+ .addPaths("classpath:META-INF/cfg/config/**/*.xml", "classpath:META-INF/cfg/config/**/*.properties", "classpath:META-INF/cfg/config/**/*.ini")
+ .build());
+ String configDir = System.getProperty("config.dir");
+ if(configDir!=null && !configDir.trim().isEmpty()){
+ builder.addPaths("file:"+configDir);
+ }
+ builder.addSystemProperties();
+ this.configuration = builder.build().toConfiguration();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java b/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
index e5baecc..457aa6c 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/el/DefaultExpressionEvaluator.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.core.internal.el;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.ServiceContext;
import org.apache.tamaya.core.spi.ExpressionEvaluator;
import org.apache.tamaya.core.spi.ExpressionResolver;
@@ -27,7 +28,9 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Created by Anatole on 28.09.2014.
+ * Default expression evaluator that manages several instances of {@link org.apache.tamaya.core.spi.ExpressionResolver}.
+ * Each resolver is identified by a resolver id. Each expression passed has the form resolverId:resolverExpression, which
+ * has the advantage that different resolvers can be active in parallel.
*/
public final class DefaultExpressionEvaluator implements ExpressionEvaluator{
@@ -61,11 +64,14 @@ public final class DefaultExpressionEvaluator implements ExpressionEvaluator{
* </ul>
*
* @param expression the expression to be evaluated, not null
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurations provided by the current
+ * registered providers are used.
* @return the evaluated expression.
* @throws org.apache.tamaya.ConfigException if resolution fails.
*/
@Override
- public String evaluate(String expression) {
+ public String evaluate(String expression, Configuration... configurations) {
StringTokenizer tokenizer = new StringTokenizer(expression, "${}\\", true);
boolean escaped = false;
StringBuilder resolvedValue = new StringBuilder();
@@ -106,7 +112,7 @@ public final class DefaultExpressionEvaluator implements ExpressionEvaluator{
if (!"}".equals(tokenizer.nextToken())) {
throw new ConfigException("Invalid expression encountered: " + expression);
}
- // evalute subexpression
+ // evaluate sub-expression
current.append(evaluteInternal(subExpression));
break;
default:
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
index 4aa41ab..68d37a4 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/el/EnvironmentPropertyResolver.java
@@ -19,12 +19,13 @@
package org.apache.tamaya.core.internal.el;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.spi.ExpressionResolver;
import java.util.Optional;
/**
- * Created by Anatole on 28.09.2014.
+ * Property resolver implementation that interprets the resolver expressions as environment properties.
*/
public final class EnvironmentPropertyResolver implements ExpressionResolver{
@@ -34,7 +35,7 @@ public final class EnvironmentPropertyResolver implements ExpressionResolver{
}
@Override
- public String resolve(String expression){
+ public String resolve(String expression, Configuration... configurations){
return Optional.ofNullable(System.getenv(expression)).orElseThrow(
() -> new ConfigException("No such environment property: " + expression)
);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java b/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
index 450504e..ef1ffc6 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
@@ -25,7 +25,7 @@ import org.apache.tamaya.core.spi.ExpressionResolver;
import java.util.*;
/**
- * Created by Anatole on 28.09.2014.
+ * Property resolver implementation that interprets the resolver expression as system property name.
*/
public final class SystemPropertyResolver implements ExpressionResolver{
@@ -35,7 +35,7 @@ public final class SystemPropertyResolver implements ExpressionResolver{
}
@Override
- public String resolve(String expression){
+ public String resolve(String expression, Configuration... configurations){
return Optional.ofNullable(System.getProperty(expression)).orElseThrow(
() -> new ConfigException("No such system property: " + expression)
);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
new file mode 100644
index 0000000..70070c5
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
@@ -0,0 +1,65 @@
+/*
+ * 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.core.internal.inject;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.internal.inject.ConfiguredType;
+import org.apache.tamaya.core.internal.inject.InjectionUtils;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Objects;
+
+/**
+ * Invocation handler that handles request against a configuration template.
+ */
+public final class ConfigTemplateInvocationHandler implements InvocationHandler {
+ /**
+ * Any overriding configurations.
+ */
+ private Configuration[] configurations;
+ /**
+ * The configured type.
+ */
+ private ConfiguredType type;
+
+ /**
+ * Creates a new handler instance.
+ * @param type the target type, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
+ */
+ public ConfigTemplateInvocationHandler(Class<?> type, Configuration... configurations) {
+ this.configurations = Objects.requireNonNull(configurations).clone();
+ this.type = new ConfiguredType(Objects.requireNonNull(type));
+ if (!type.isInterface()) {
+ throw new IllegalArgumentException("Can only proxy interfaces as configuration templates.");
+ }
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ("toString".equals(method.getName())) {
+ return "Configured Proxy -> " + this.type.getType().getName();
+ }
+ String configValue = InjectionUtils.getConfigValue(method, configurations);
+ return InjectionUtils.adaptValue(method, method.getReturnType(), configValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
index 10d2374..026b4e0 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya.core.internal.inject;
+import org.apache.tamaya.Configuration;
+
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@@ -31,6 +33,11 @@ public final class 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){
if (!ConfiguredType.isConfigured(type)) {
return null;
@@ -38,20 +45,22 @@ public final class ConfigurationInjector {
return INSTANCE.configuredTypes.computeIfAbsent(type, ConfiguredType::new);
}
- public static void configure(Object instance){
+ /**
+ * 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
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ */
+ public static void configure(Object instance, Configuration... configurations){
Class type = Objects.requireNonNull(instance).getClass();
if (!ConfiguredType.isConfigured(type)) {
throw new IllegalArgumentException("Not a configured type: " + type.getName());
}
- ConfiguredType configType = registerType(type);
- initializeConfiguredFields(configType, instance);
+ ConfiguredType configuredType = registerType(type);
+ Objects.requireNonNull(configuredType).configure(instance, configurations);
}
- private static <T> void initializeConfiguredFields(final ConfiguredType configuredType, Object instance) {
- Objects.requireNonNull(configuredType).configure(instance);
- ConfiguredInstancesManager.register(configuredType, instance);
-
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
index ee5aeda..581021b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.core.internal.inject;
+import org.apache.tamaya.Codec;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyAdapter;
import org.apache.tamaya.annotation.*;
import org.apache.tamaya.core.internal.Utils;
@@ -31,8 +31,8 @@ import java.util.stream.Collectors;
/**
* Small class that contains and manages all information anc access to a configured field and a concrete instance current
- * it (referenced by a weak reference). It also implements all aspects current value filtering, converting any applying the
- * final value by reflection.
+ * it (referenced by a weak reference). It also implements all aspects current keys filtering, converting any applying the
+ * final keys by reflection.
*/
@SuppressWarnings("UnusedDeclaration")
public class ConfiguredField {
@@ -55,133 +55,44 @@ public class ConfiguredField {
}
/**
- * Evaluate the initial value fromMap the configuration and apply it to the field.
+ * Evaluate the initial keys fromMap the configuration and applyChanges it to the field.
*
* @param target the target instance.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
* @throws ConfigException if evaluation or conversion failed.
*/
- public void applyInitialValue(Object target) throws ConfigException {
- Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(
- annotatedField, ConfiguredProperty.class, ConfiguredProperties.class);
- DefaultAreas areasAnnot = this.annotatedField.getDeclaringClass().getAnnotation(DefaultAreas.class);
- WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, this.annotatedField, this.annotatedField.getDeclaringClass());
- DefaultValue defaultValue = this.annotatedField.getAnnotation(DefaultValue.class);
- String configValue = getConfigValue(loadPolicy, areasAnnot, configuredProperties, defaultValue);
- applyValue(target, configValue, false);
+ public void applyInitialValue(Object target, Configuration... configurations) throws ConfigException {
+ String configValue = InjectionUtils.getConfigValue(this.annotatedField, configurations);
+ applyValue(target, configValue, false, configurations);
}
- /**
- * Internally evaluated the current vaslid configuration value based on the given annotations present.
- *
- * @param loadPolicyAnnot The load policy, determining any explicit listeners to be informed.
- * @param areasAnnot Any default areas to be looked up.
- * @param propertiesAnnot The configured property keys (qualified or relative).
- * @param defaultAnnot any configured default value.
- * @return the value to be applied, or null.
- */
- private String getConfigValue(WithLoadPolicy loadPolicyAnnot, DefaultAreas areasAnnot, Collection<ConfiguredProperty> propertiesAnnot, DefaultValue defaultAnnot) {
- List<String> keys = evaluateKeys(areasAnnot, propertiesAnnot);
- annotatedField.setAccessible(true);
- Configuration config = getConfiguration();
- String configValue = null;
- for (String key : keys) {
- if (config.containsKey(key)) {
- configValue = config.get(key).orElse(null);
- }
- if (configValue != null) {
- break;
- }
- }
- if (configValue == null && defaultAnnot != null) {
- configValue = defaultAnnot.value();
- }
- if (configValue != null) {
- // net step perform expression resolution, if any
- return Configuration.evaluateValue(configValue);
- }
- return null;
- }
/**
- * This method reapplies a changed configuration value to the field.
+ * This method reapplies a changed configuration keys to the field.
*
* @param target the target instance, not null.
- * @param configValue the new value to be applied, null will trigger the evaluation current the configured default value.
- * @param resolve set to true, if expression resolution should be applied on the value passed.
+ * @param configValue the new keys to be applied, null will trigger the evaluation current the configured default keys.
+ * @param resolve set to true, if expression resolution should be applied on the keys passed.
* @throws ConfigException if the configuration required could not be resolved or converted.
*/
- public void applyValue(Object target, String configValue, boolean resolve) throws ConfigException {
+ public void applyValue(Object target, String configValue, boolean resolve, Configuration... configurations) throws ConfigException {
Objects.requireNonNull(target);
try {
if (resolve && configValue != null) {
// net step perform exression resolution, if any
- configValue = Configuration.evaluateValue(configValue);
+ configValue = Configuration.evaluateValue(configValue, configurations);
}
// Check for adapter/filter
- WithPropertyAdapter adapterAnnot = this.annotatedField.getAnnotation(WithPropertyAdapter.class);
- Class<? extends PropertyAdapter> propertyAdapterType;
- if (adapterAnnot != null) {
- propertyAdapterType = adapterAnnot.value();
- if (!propertyAdapterType.equals(PropertyAdapter.class)) {
- // TODO cache here...
- PropertyAdapter<String> filter = propertyAdapterType.newInstance();
- configValue = filter.adapt(configValue);
- }
- }
- if (configValue == null) {
- // TODO Check for optional injection!
- // annotatedField.set(target, null);
- LOG.info("No config found for " +
- this.annotatedField.getDeclaringClass().getName() + '#' +
- this.annotatedField.getName());
- } else {
- Class baseType = annotatedField.getType();
- if (String.class.equals(baseType) || baseType.isAssignableFrom(configValue.getClass())) {
- annotatedField.set(target, configValue);
- } else {
- PropertyAdapter<?> adapter = PropertyAdapter.getAdapter(baseType);
- annotatedField.set(target, adapter.adapt(configValue));
- }
- }
+ Object value = InjectionUtils.adaptValue(this.annotatedField, this.annotatedField.getType(), configValue);
+ annotatedField.setAccessible(true);
+ annotatedField.set(target, value);
} catch (Exception e) {
throw new ConfigException("Failed to annotation configured field: " + this.annotatedField.getDeclaringClass()
.getName() + '.' + annotatedField.getName(), e);
}
}
- /**
- * Evaluates all absolute configuration key based on the annotations found on a class.
- *
- * @param areasAnnot the (optional) annotation definining areas to be looked up.
- * @param propertyAnnotations the annotation on field/method level that may defined the
- * exact key to be looked up (in absolute or relative form).
- * @return the list current keys in order how they should be processed/looked up.
- */
- private List<String> evaluateKeys(DefaultAreas areasAnnot,Collection<ConfiguredProperty> propertyAnnotations) {
- Objects.requireNonNull(propertyAnnotations);
- List<String> keys = propertyAnnotations.stream().map(ConfiguredProperty::value).filter(s -> !s.isEmpty())
- .collect(Collectors.toList());
- if (keys.isEmpty()) //noinspection UnusedAssignment
- keys.add(annotatedField.getName());
- ListIterator<String> iterator = keys.listIterator();
- while (iterator.hasNext()) {
- String next = iterator.next();
- if (next.startsWith("[") && next.endsWith("]")) {
- // absolute key, strip away brackets, take key as is
- iterator.set(next.substring(1, next.length() - 1));
- } else {
- if (areasAnnot != null) {
- // Remove original entry, since it will be replaced with prefixed entries
- iterator.remove();
- // Add prefixed entries, including absolute (root) entry for "" area value.
- for (String area : areasAnnot.value()) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return keys;
- }
/**
* This method checks if the given (qualified) configuration key is referenced fromMap this field.
@@ -191,26 +102,26 @@ public class ConfiguredField {
* @param key the (qualified) configuration key, not null.
* @return true, if the key is referenced.
*/
- public boolean matchesKey(String key) {
- DefaultAreas areasAnnot = this.annotatedField.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ public boolean matchesKey(String configName, String key) {
Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(this.annotatedField, ConfiguredProperty.class,
ConfiguredProperties.class );
- List<String> keys = evaluateKeys(areasAnnot, configuredProperties);
- return keys.contains(key);
- }
-
- /**
- * This method evaluates the {@link Configuration} that currently is valid for the given target field/method.
- *
- * @return the {@link Configuration} instance to be used, never null.
- */
- public Configuration getConfiguration() {
- WithConfig name = annotatedField.getAnnotation(WithConfig.class);
- if(name!=null) {
- return Configuration.current(name.value());
+ 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 Configuration.current();
+ return false;
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
deleted file mode 100644
index 2153777..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
+++ /dev/null
@@ -1,85 +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.core.internal.inject;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertySource;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.lang.ref.WeakReference;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * This service class manages the configured instances that are currently attached to the configuration
- * system. References to instances are rest as WeakReference instances, and cleanup current internal structures
- * is performed implictly during event triggering for configuration changes.
- * Created by Anatole on 03.10.2014.
- */
-public final class ConfiguredInstancesManager implements PropertyChangeListener{
-
- private static final ConfiguredInstancesManager INSTANCE = new ConfiguredInstancesManager();
- private Map<ConfiguredType,List<WeakReference<Object>>> configuredInstances = new ConcurrentHashMap<>();
- private final Object LOCK = new Object();
-
- private ConfiguredInstancesManager(){
-// Configuration.addConfigChangeListener(this);
- }
-
- public static <T> void register(ConfiguredType configuredType, Object instance) {
- List<WeakReference<Object>> instances = INSTANCE.configuredInstances.get(configuredType);
- if(instances==null){
- synchronized(INSTANCE.configuredInstances){
- instances = INSTANCE.configuredInstances.get(configuredType);
- if(instances==null){
- instances = Collections.synchronizedList(new ArrayList<>());
- INSTANCE.configuredInstances.put(configuredType, instances);
- }
- }
- }
- synchronized(instances) {
- instances.add(new WeakReference<>(instance));
- }
- }
-
- @Override
- public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
- for(Map.Entry<ConfiguredType,List<WeakReference<Object>>> en: configuredInstances.entrySet()){
- PropertySource propertyProvider = (PropertySource)propertyChangeEvent.getSource();
- if((propertyProvider instanceof Configuration) && en.getKey().isConfiguredBy((Configuration)propertyProvider)){
- List<WeakReference<Object>> instances = en.getValue();
- synchronized (instances){
- Iterator<WeakReference<Object>> iterator = instances.iterator();
- while (iterator.hasNext()) {
- WeakReference<Object> ref = iterator.next();
- Object instance = ref.get();
- if(instance==null){
- iterator.remove();
- }
- else{
- en.getKey().triggerConfigUpdate(propertyChangeEvent, instance);
- }
- }
- }
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
index 3bc4472..3b83ee5 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.core.internal.inject;
+import org.apache.tamaya.Codec;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.PropertyAdapter;
import org.apache.tamaya.annotation.*;
import org.apache.tamaya.core.internal.Utils;
@@ -31,8 +31,8 @@ import java.util.stream.Collectors;
/**
* Small class that contains and manages all information anc access to a configured field and a concrete instance current
- * it (referenced by a weak reference). It also implements all aspects current value filtering, conversiong any applying the
- * final value by reflection.
+ * it (referenced by a weak reference). It also implements all aspects current keys filtering, conversiong any applying the
+ * final keys by reflection.
* Created by Anatole on 01.10.2014.
*/
@SuppressWarnings("UnusedDeclaration")
@@ -55,71 +55,9 @@ public class ConfiguredMethod {
}
- /**
- * Internally evaluated the current valid configuration value based on the given annotations present.
- *
- * @return the value to be returned, or null.
- */
- private String getConfigValue() {
- DefaultAreas areasAnnot = this.annotatedMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
- DefaultValue defaultAnnot = this.annotatedMethod.getAnnotation(DefaultValue.class);
- Collection<ConfiguredProperty> configuredProperties =
- Utils.getAnnotations(this.annotatedMethod, ConfiguredProperty.class, ConfiguredProperties.class);
- List<String> keys = evaluateKeys(areasAnnot, configuredProperties);
- Configuration config = getConfiguration();
- String configValue = null;
- for (String key : keys) {
- if (config.containsKey(key)) {
- configValue = config.get(key).orElse(null);
- }
- if (configValue != null) {
- break;
- }
- }
- if (configValue == null && defaultAnnot != null) {
- configValue = defaultAnnot.value();
- }
- if (configValue != null) {
- // net step perform expression resolution, if any
- return Configuration.evaluateValue(configValue);
- }
- return null;
- }
- /**
- * Evaluates all absolute configuration key based on the annotations found on a class.
- *
- * @param areasAnnot the (optional) annotation definining areas to be looked up.
- * @param propertyAnnotations the annotation on field/method level that may defined the
- * exact key to be looked up (in absolute or relative form).
- * @return the list current keys in order how they should be processed/looked up.
- */
- private List<String> evaluateKeys(DefaultAreas areasAnnot, Collection<ConfiguredProperty> propertyAnnotations) {
- List<String> keys =
- Objects.requireNonNull(propertyAnnotations).stream()
- .filter(p -> !p.value().isEmpty())
- .map(ConfiguredProperty::value).collect(Collectors.toList());
- if (keys.isEmpty()) //noinspection UnusedAssignment
- keys.add(annotatedMethod.getName());
- ListIterator<String> iterator = keys.listIterator();
- while (iterator.hasNext()) {
- String next = iterator.next();
- if (next.startsWith("[") && next.endsWith("]")) {
- // absolute key, strip away brackets, take key as is
- iterator.set(next.substring(1, next.length() - 1));
- } else {
- if (areasAnnot != null) {
- // Remove original entry, since it will be replaced with prefixed entries
- iterator.remove();
- // Add prefixed entries, including absolute (root) entry for "" area value.
- for (String area : areasAnnot.value()) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return keys;
- }
+
+
/**
* This method checks if the given (qualified) configuration key is referenced fromMap this field.
@@ -133,62 +71,23 @@ public class ConfiguredMethod {
DefaultAreas areasAnnot = this.annotatedMethod.getDeclaringClass().getAnnotation(DefaultAreas.class);
Collection<ConfiguredProperty> configuredProperties =
Utils.getAnnotations(this.annotatedMethod, ConfiguredProperty.class, ConfiguredProperties.class);
- List<String> keys = evaluateKeys(areasAnnot, configuredProperties);
- return keys.contains(key);
- }
-
- /**
- * This method evaluates the {@link org.apache.tamaya.Configuration} that currently is valid for the given target field/method.
- *
- * @return the {@link org.apache.tamaya.Configuration} instance to be used, never null.
- */
- public Configuration getConfiguration() {
- WithConfig name = annotatedMethod.getAnnotation(WithConfig.class);
- if (name != null) {
- return Configuration.current(name.value());
- }
- return Configuration.current();
- }
-
- /**
- * This method reapplies a changed configuration value to the field.
- *
- * @throws org.apache.tamaya.ConfigException if the configuration required could not be resolved or converted.
- */
- public Object getValue(Object[] args) throws ConfigException {
- // TODO do something with additional args?
- String configValue = getConfigValue();
- try {
- // Check for adapter/filter
- WithPropertyAdapter adapterAnnot = this.annotatedMethod.getAnnotation(WithPropertyAdapter.class);
- Class<? extends PropertyAdapter> propertyAdapterType;
- if (adapterAnnot != null) {
- propertyAdapterType = adapterAnnot.value();
- if (!propertyAdapterType.equals(PropertyAdapter.class)) {
- // TODO cache here...
- PropertyAdapter<String> filter = propertyAdapterType.newInstance();
- configValue = filter.adapt(configValue);
- }
- }
- if (configValue == null) {
- // TODO optionally return null...
- LOG.info("No config value found for " +
- this.annotatedMethod.getDeclaringClass().getName() + '#' +
- this.annotatedMethod.getName());
- return null;
- } else {
- Class<?> baseType = annotatedMethod.getReturnType();
- if (String.class.equals(baseType) || baseType.isAssignableFrom(configValue.getClass())) {
- return configValue;
- } else {
- PropertyAdapter<?> adapter = PropertyAdapter.getAdapter(baseType);
- return adapter.adapt(configValue);
- }
+ for(ConfiguredProperty prop: configuredProperties) {
+ if (InjectionUtils.evaluateKeys(this.annotatedMethod, areasAnnot, prop).contains(key)) {
+ return true;
}
- } catch (Exception e) {
- throw new ConfigException("Failed to annotation configured field: " + this.annotatedMethod.getDeclaringClass()
- .getName() + '.' + annotatedMethod.getName(), e);
}
+ return false;
}
+
+// /**
+// * This method reapplies a changed configuration keys to the field.
+// *
+// * @throws org.apache.tamaya.ConfigException if the configuration required could not be resolved or converted.
+// */
+// public Object getValue(Object[] args, Configuration... configurations) throws ConfigException {
+// // TODO do something with additional args?
+// return InjectionUtils.adaptValue(this.annotatedMethod, this.annotatedMethod.getReturnType(), configValue);
+// }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
index b199c23..ad89c3d 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.core.internal.inject;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.PropertySource;
import org.apache.tamaya.annotation.*;
import java.beans.PropertyChangeEvent;
@@ -32,41 +33,30 @@ import java.util.*;
* Created by Anatole on 03.10.2014.
*/
public class ConfiguredType {
-
+ /** A list with all annotated instance variables. */
private List<ConfiguredField> configuredFields = new ArrayList<>();
+ /** A list with all annotated methods (templates). */
private Map<Method, ConfiguredMethod> configuredMethods = new HashMap<>();
+ /** A list with all callback methods listening to config changes. */
private List<ConfigChangeCallbackMethod> callbackMethods = new ArrayList<>();
+ /** The basic type. */
private Class type;
+ /**
+ * Creates an instance of this class hereby evaluating the config annotations given for later effective
+ * injection (configuration) of instances.
+ * @param type the instance type.
+ */
public ConfiguredType(Class type) {
this.type = Objects.requireNonNull(type);
- for (Field f : type.getDeclaredFields()) {
- ConfiguredProperties propertiesAnnot = f.getAnnotation(ConfiguredProperties.class);
- if (propertiesAnnot != null) {
- try {
- ConfiguredField configuredField = new ConfiguredField(f);
- configuredFields.add(configuredField);
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured field: " +
- f.getDeclaringClass().getName() + '.' + f.getName(), e);
- }
- }
- else{
- ConfiguredProperty propertyAnnot = f.getAnnotation(ConfiguredProperty.class);
- if (propertyAnnot != null) {
- try {
- ConfiguredField configuredField = new ConfiguredField(f);
- configuredFields.add(configuredField);
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured field: " +
- f.getDeclaringClass().getName() + '.' + f.getName(), e);
- }
- }
- }
- }
+ initFields(type);
+ initMethods(type);
+ }
+
+ private void initMethods(Class type) {
for (Method m : type.getDeclaredMethods()) {
ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
- if(mAnnot!=null) {
+ if (mAnnot != null) {
if (m.getParameterTypes().length != 1) {
continue;
}
@@ -82,8 +72,7 @@ public class ConfiguredType {
throw new ConfigException("Failed to initialized configured callback method: " +
m.getDeclaringClass().getName() + '.' + m.getName(), e);
}
- }
- else{
+ } else {
ConfiguredProperties propertiesAnnot = m.getAnnotation(ConfiguredProperties.class);
if (propertiesAnnot != null) {
try {
@@ -93,8 +82,7 @@ public class ConfiguredType {
throw new ConfigException("Failed to initialized configured method: " +
m.getDeclaringClass().getName() + '.' + m.getName(), e);
}
- }
- else{
+ } else {
ConfiguredProperty propertyAnnot = m.getAnnotation(ConfiguredProperty.class);
if (propertyAnnot != null) {
try {
@@ -110,23 +98,59 @@ public class ConfiguredType {
}
}
- public Object getConfiguredValue(Method method, Object[] args) {
- ConfiguredMethod m = this.configuredMethods.get(method);
- return m.getValue(args);
+ private void initFields(Class type) {
+ for (Field f : type.getDeclaredFields()) {
+ ConfiguredProperties propertiesAnnot = f.getAnnotation(ConfiguredProperties.class);
+ if (propertiesAnnot != null) {
+ try {
+ ConfiguredField configuredField = new ConfiguredField(f);
+ configuredFields.add(configuredField);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured field: " +
+ f.getDeclaringClass().getName() + '.' + f.getName(), e);
+ }
+ } else {
+ ConfiguredProperty propertyAnnot = f.getAnnotation(ConfiguredProperty.class);
+ if (propertyAnnot != null) {
+ try {
+ ConfiguredField configuredField = new ConfiguredField(f);
+ configuredFields.add(configuredField);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to initialized configured field: " +
+ f.getDeclaringClass().getName() + '.' + f.getName(), e);
+ }
+ }
+ }
+ }
}
- public void configure(Object instance) {
+ /**
+ * Method called to configure an instance.
+ *
+ * @param instance The instance to be configured.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ */
+ public void configure(Object instance, Configuration... configurations) {
for (ConfiguredField field : configuredFields) {
field.applyInitialValue(instance);
}
}
- public void triggerConfigUpdate(PropertyChangeEvent configChangeEvent, Object instance) {
+ public void triggerConfigUpdate(PropertyChangeEvent evt, Object instance) {
// TODO do check for right config ;)
- configuredFields.stream().filter(field -> field.matchesKey(configChangeEvent.getPropertyName())).forEach(field -> field.applyValue(instance, (String) configChangeEvent.getNewValue(), false));
+ configuredFields.stream().filter(field -> field.matchesKey(getName(evt.getSource()), evt.getPropertyName())).forEach(field -> field.applyValue(instance, (String) evt.getNewValue(), false));
for (ConfigChangeCallbackMethod callBack : this.callbackMethods) {
- callBack.call(instance, configChangeEvent);
+ callBack.call(instance, evt);
+ }
+ }
+
+ private String getName(Object source){
+ if(source instanceof PropertySource){
+ PropertySource ps = (PropertySource)source;
+ return ps.getMetaInfo().getName();
}
+ return "N/A";
}
public boolean isConfiguredBy(Configuration configuration) {
@@ -135,7 +159,7 @@ public class ConfiguredType {
}
public static boolean isConfigured(Class type) {
- if(type.getAnnotation(DefaultAreas.class)!=null){
+ if (type.getAnnotation(DefaultAreas.class) != null) {
return true;
}
// if no class level annotation is there we might have field level annotations only
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
new file mode 100644
index 0000000..3c073b6
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/InjectionUtils.java
@@ -0,0 +1,170 @@
+package org.apache.tamaya.core.internal.inject;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.annotation.*;
+import org.apache.tamaya.core.internal.Utils;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.*;
+
+/**
+ * Created by Anatole on 19.12.2014.
+ */
+final class InjectionUtils {
+
+ private InjectionUtils(){}
+
+ /**
+ * This method evaluates the {@link org.apache.tamaya.Configuration} that currently is valid for the given target field/method.
+ *
+ * @return the {@link org.apache.tamaya.Configuration} instance to be used, never null.
+ */
+ public static Configuration getConfiguration(ConfiguredProperty prop, Configuration... configuration) {
+ String name = prop.config();
+ if (name != null && !name.trim().isEmpty()) {
+ return Configuration.current(name.trim());
+ }
+ return Configuration.current();
+ }
+
+ /**
+ * Evaluates all absolute configuration key based on the annotations found on a class.
+ *
+ * @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.
+ */
+ 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
+ keys.add(member.getName());
+ ListIterator<String> iterator = keys.listIterator();
+ while (iterator.hasNext()) {
+ String next = iterator.next();
+ if (next.startsWith("[") && next.endsWith("]")) {
+ // absolute key, strip away brackets, take key as is
+ iterator.set(next.substring(1, next.length() - 1));
+ } else {
+ if (areasAnnot != null) {
+ // Remove original entry, since it will be replaced with prefixed entries
+ iterator.remove();
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : areasAnnot.value()) {
+ iterator.add(area.isEmpty() ? next : area + '.' + next);
+ }
+ }
+ }
+ }
+ return keys;
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ public static String getConfigValue(Method method, Configuration... configurations) {
+ DefaultAreas areasAnnot = method.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, method, method.getDeclaringClass());
+ return getConfigValueInternal(method, areasAnnot, loadPolicy, configurations);
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ public static String getConfigValue(Field field, Configuration... configurations) {
+ DefaultAreas areasAnnot = field.getDeclaringClass().getAnnotation(DefaultAreas.class);
+ WithLoadPolicy loadPolicy = Utils.getAnnotation(WithLoadPolicy.class, field, field.getDeclaringClass());
+ return getConfigValueInternal(field, areasAnnot, loadPolicy, configurations);
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ private static String getConfigValueInternal(AnnotatedElement element, DefaultAreas areasAnnot, WithLoadPolicy loadPolicy, Configuration... configurations) {
+ Collection<ConfiguredProperty> configuredProperties = Utils.getAnnotations(
+ element, ConfiguredProperty.class, ConfiguredProperties.class);
+ DefaultValue defaultAnnot = element.getAnnotation(DefaultValue.class);
+ String configValue = null;
+ for(ConfiguredProperty prop: configuredProperties){
+ List<String> keys = InjectionUtils.evaluateKeys((Member)element, areasAnnot, prop);
+ Configuration config = InjectionUtils.getConfiguration(prop, configurations);
+ for (String key : keys) {
+ if (config.containsKey(key)) {
+ configValue = config.get(key).orElse(null);
+ }
+ if (configValue != null) {
+ break;
+ }
+ }
+ if (configValue != null) {
+ // net step perform expression resolution, if any
+ return Configuration.evaluateValue(configValue, config);
+ }
+ }
+ if (configValue == null && defaultAnnot != null) {
+ return defaultAnnot.value();
+ }
+ return null;
+ }
+
+ public static <T> T adaptValue(AnnotatedElement element, Class<T> targetType, String configValue){
+ try {
+ // Check for adapter/filter
+ T adaptedValue = null;
+ WithCodec codecAnnot = element.getAnnotation(WithCodec.class);
+ Class<? extends Codec> codecType;
+ if (codecAnnot != null) {
+ codecType = codecAnnot.value();
+ if (!codecType.equals(Codec.class)) {
+ // TODO cache here...
+ Codec<String> codec = codecType.newInstance();
+ adaptedValue = (T) codec.deserialize(configValue);
+ }
+ }
+ if (String.class.equals(targetType)) {
+ return (T)configValue;
+ } else {
+ Codec<?> adapter = Codec.getInstance(targetType);
+ return (T)adapter.deserialize(configValue);
+ }
+ } catch (Exception e) {
+ throw new ConfigException("Failed to annotate configured member: " + element, e);
+ }
+ }
+
+ /**
+ * This method evaluates the {@link Configuration} that currently is valid for the given target field/method.
+ * @param configurations Configuration instances that replace configuration served by services. This allows
+ * more easily testing and adaption.
+ * @return the {@link Configuration} instance to be used, never null.
+ */
+ public static Configuration getConfiguration(String name, Configuration... configurations) {
+ if(name!=null) {
+ for(Configuration conf: configurations){
+ if(name.equals(conf.getMetaInfo().getName())){
+ return conf;
+ }
+ }
+ return Configuration.current(name);
+ }
+ else{
+ for(Configuration conf: configurations){
+ if("default".equals(conf.getMetaInfo().getName())){
+ return conf;
+ }
+ }
+ }
+ return Configuration.current();
+ }
+}
[3/5] incubator-tamaya git commit: TAMAYA-8: Added some javadocs.
TAMAYA-30: Added Codecs TAMAYA 31: Reduced number of annotations TAMAYA 34:
Added Config overrides.
Posted by an...@apache.org.
TAMAYA-8: Added some javadocs.
TAMAYA-30: Added Codecs
TAMAYA 31: Reduced number of annotations
TAMAYA 34: Added Config overrides.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/c9e62e24
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/c9e62e24
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/c9e62e24
Branch: refs/heads/master
Commit: c9e62e24f4e71647acb94aec1197a4330146e3cd
Parents: eb59d86
Author: anatole <an...@apache.org>
Authored: Sat Dec 20 15:22:43 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Dec 20 15:22:43 2014 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/AggregationPolicy.java | 16 +-
api/src/main/java/org/apache/tamaya/Codec.java | 92 ++++++++++
api/src/main/java/org/apache/tamaya/Codecs.java | 82 +++++++++
.../apache/tamaya/ConfigChangeSetBuilder.java | 54 +++---
.../java/org/apache/tamaya/Configuration.java | 87 ++++------
.../org/apache/tamaya/ConfigurationManager.java | 45 ++---
.../java/org/apache/tamaya/Environment.java | 2 +-
.../main/java/org/apache/tamaya/MetaInfo.java | 68 +++++++-
.../java/org/apache/tamaya/MetaInfoBuilder.java | 47 +----
.../java/org/apache/tamaya/PropertyAdapter.java | 87 ----------
.../org/apache/tamaya/PropertyAdapters.java | 82 ---------
.../java/org/apache/tamaya/PropertySource.java | 6 +-
.../tamaya/annotation/ConfiguredProperties.java | 4 +-
.../tamaya/annotation/ConfiguredProperty.java | 34 ++--
.../apache/tamaya/annotation/DefaultValue.java | 6 +-
.../apache/tamaya/annotation/LoadPolicy.java | 8 +-
.../org/apache/tamaya/annotation/WithCodec.java | 44 +++++
.../apache/tamaya/annotation/WithConfig.java | 41 -----
.../tamaya/annotation/WithConfigOperator.java | 4 +-
.../tamaya/annotation/WithPropertyAdapter.java | 44 -----
.../apache/tamaya/spi/CodecsSingletonSpi.java | 89 ++++++++++
.../spi/ConfigurationManagerSingletonSpi.java | 37 ++--
.../java/org/apache/tamaya/spi/Orderable.java | 4 +-
.../spi/PropertyAdaptersSingletonSpi.java | 63 -------
.../test/java/annottext/AnnotatedConfig.java | 10 +-
.../java/annottext/AnnotatedFullConfig.java | 10 +-
.../tamaya/TestConfigServiceSingletonSpi.java | 37 ++--
.../TestPropertyAdaptersSingletonSpi.java | 69 ++++----
.../org.apache.tamaya.spi.CodecsSingletonSpi | 19 +++
...ache.tamaya.spi.PropertyAdaptersSingletonSpi | 19 ---
.../core/config/AbstractConfiguration.java | 4 +-
.../tamaya/core/config/ConfigFunctions.java | 2 +-
.../core/config/ConfigurationBuilder.java | 4 +-
.../tamaya/core/config/MappedConfiguration.java | 6 +-
.../tamaya/core/env/EnvironmentBuilder.java | 2 +-
.../org/apache/tamaya/core/internal/Utils.java | 4 +-
.../config/ConfigTemplateInvocationHandler.java | 52 ------
...DefaultConfigurationManagerSingletonSpi.java | 89 +++++-----
.../internal/el/DefaultExpressionEvaluator.java | 12 +-
.../el/EnvironmentPropertyResolver.java | 5 +-
.../internal/el/SystemPropertyResolver.java | 4 +-
.../inject/ConfigTemplateInvocationHandler.java | 65 +++++++
.../internal/inject/ConfigurationInjector.java | 25 ++-
.../core/internal/inject/ConfiguredField.java | 157 ++++-------------
.../inject/ConfiguredInstancesManager.java | 85 ----------
.../core/internal/inject/ConfiguredMethod.java | 141 +++------------
.../core/internal/inject/ConfiguredType.java | 100 ++++++-----
.../core/internal/inject/InjectionUtils.java | 170 +++++++++++++++++++
.../properties/DefaultCodecsSingletonSpi.java | 162 ++++++++++++++++++
.../DefaultPropertyAdaptersSingletonSpi.java | 100 -----------
.../internal/resources/io/AntPathMatcher.java | 8 +-
.../core/internal/resources/io/ClassUtils.java | 36 ++--
.../resources/io/DefaultResourceLoader.java | 2 +-
.../resources/io/FileSystemResource.java | 4 +-
.../core/internal/resources/io/StringUtils.java | 16 +-
.../internal/resources/io/WritableResource.java | 2 +-
.../core/properties/AbstractPropertySource.java | 2 +-
.../properties/AggregatedPropertySource.java | 7 +-
.../properties/ContextualPropertySource.java | 4 +-
.../core/properties/FilteredPropertySource.java | 5 +-
.../core/properties/MapBasedPropertySource.java | 2 +-
.../core/properties/PropertySourceBuilder.java | 6 +-
.../properties/ReplacingPropertySource.java | 4 +-
.../properties/SubtractingPropertySource.java | 5 +-
.../apache/tamaya/core/resource/Resource.java | 2 +-
.../tamaya/core/spi/AdapterProviderSpi.java | 7 +-
.../tamaya/core/spi/ExpressionEvaluator.java | 15 +-
.../tamaya/core/spi/ExpressionResolver.java | 7 +-
.../tamaya/core/spi/PropertyAdapterService.java | 30 ++--
.../org.apache.tamaya.spi.CodecsSingletonSpi | 19 +++
...ache.tamaya.spi.PropertyAdaptersSingletonSpi | 19 ---
.../tamaya/core/config/MutableConfigTest.java | 3 +-
.../internal/MutableTestConfigProvider.java | 2 +-
.../tamaya/internal/TestConfigProvider.java | 14 +-
.../samples/annotations/ConfigTemplate.java | 9 +-
.../samples/annotations/ConfiguredClass.java | 21 +--
.../samples/annotations/ConfiguredTest.java | 10 +-
.../apache/tamaya/ucs/UC1ReadProperties.java | 10 +-
.../apache/tamaya/ucs/UC2CombineProperties.java | 2 +-
.../tamaya/integration/cdi/ConfiguredClass.java | 14 +-
.../integration/cdi/TestConfigProvider.java | 14 +-
81 files changed, 1347 insertions(+), 1353 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/AggregationPolicy.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/AggregationPolicy.java b/api/src/main/java/org/apache/tamaya/AggregationPolicy.java
index 67d644e..efb79ef 100644
--- a/api/src/main/java/org/apache/tamaya/AggregationPolicy.java
+++ b/api/src/main/java/org/apache/tamaya/AggregationPolicy.java
@@ -28,9 +28,9 @@ public interface AggregationPolicy {
/**
* Method which decides how keys/values are aggregated.
* @param key the key current the entry, must not be {@code null}.
- * @param currentValue the current value, or {@code null}.
- * @param newValue the new value, never {@code null}.
- * @return the target value to be used in the resulting property set, or null, to remove the property.
+ * @param currentValue the current keys, or {@code null}.
+ * @param newValue the new keys, never {@code null}.
+ * @return the target keys to be used in the resulting property set, or null, to remove the property.
*/
public String aggregate(String key, String currentValue, String newValue);
@@ -54,7 +54,7 @@ public interface AggregationPolicy {
public static final AggregationPolicy EXCEPTION =
(String key, String value, String newValue) -> {
if(value!=null && newValue!=null && !value.equals(newValue)){
- throw new ConfigException("Conflicting values encountered key="+key+", value="+value+", newValue="+newValue);
+ throw new ConfigException("Conflicting values encountered key="+key+", keys="+value+", newValue="+newValue);
}
return newValue;
};
@@ -66,7 +66,7 @@ public interface AggregationPolicy {
(String key, String value, String newValue) -> {
if(value!=null && newValue!=null && !value.equals(newValue)){
Logger.getLogger(AggregationPolicy.class.getName())
- .severe(() -> "Conflicting values encountered key=" + key + ", value=" + value + ", newValue=" + newValue);
+ .severe(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
return value;
}
return newValue;
@@ -79,7 +79,7 @@ public interface AggregationPolicy {
(String key, String value, String newValue) -> {
if(value!=null && newValue!=null && !value.equals(newValue)){
Logger.getLogger(AggregationPolicy.class.getName())
- .warning(() -> "Conflicting values encountered key=" + key + ", value=" + value + ", newValue=" + newValue);
+ .warning(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
return value;
}
return newValue;
@@ -92,7 +92,7 @@ public interface AggregationPolicy {
(String key, String value, String newValue) -> {
if(value!=null && newValue!=null && !value.equals(newValue)){
Logger.getLogger(AggregationPolicy.class.getName())
- .info(() -> "Conflicting values encountered key=" + key + ", value=" + value + ", newValue=" + newValue);
+ .info(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
return value;
}
return newValue;
@@ -105,7 +105,7 @@ public interface AggregationPolicy {
(String key, String value, String newValue) -> {
if(value!=null && newValue!=null && !value.equals(newValue)){
Logger.getLogger(AggregationPolicy.class.getName())
- .finest(() -> "Conflicting values encountered key=" + key + ", value=" + value + ", newValue=" + newValue);
+ .finest(() -> "Conflicting values encountered key=" + key + ", keys=" + value + ", newValue=" + newValue);
return value;
}
return newValue;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/Codec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Codec.java b/api/src/main/java/org/apache/tamaya/Codec.java
new file mode 100644
index 0000000..55b1684
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/Codec.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+
+import org.apache.tamaya.annotation.WithCodec;
+
+/**
+ * Interface for an codec that converts a configured String into something else and vice versa.
+ * This is typically used for implementing type conversion fromMap String to a certain target
+ * type current the configured property, e.g. multivalued types, complex subtypes or subconfigurations
+ * abd collection types.
+ */
+public interface Codec<T>{
+
+ /**
+ * Adapt the given configuration keys to the required target type.
+ * @param value the configuration keys
+ * @return adapted keys
+ */
+ T deserialize(String value);
+
+ /**
+ * Adapt the given configuration keys to the required target type.
+ * @param value the configuration keys
+ * @return adapted keys
+ */
+ String serialize(T value);
+
+ /**
+ * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
+ * this type.
+ * @param targetType The target class, not null.
+ * @param adapter The adapter, not null.
+ * @param <T> The target type
+ * @return any adapter replaced with the new adapter, or null.
+ */
+ public static <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
+ return Codecs.register(targetType, adapter);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ public static boolean isTargetTypeSupported(Class<?> targetType){
+ return Codecs.isTargetTypeSupported(targetType);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws ConfigException if the target type is not supported.
+ */
+ public static <T> Codec<T> getInstance(Class<T> targetType){
+ return Codecs.getCodec(targetType);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param annotation the {@link org.apache.tamaya.annotation.WithCodec} annotation, or null. If the annotation is not null and
+ * defines an overriding adapter, this instance is created and returned.
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws ConfigException if the target type is not supported, or the overriding adapter cannot be
+ * instantiated.
+ */
+ public static <T> Codec<T> getInstance(Class<T> targetType, WithCodec annotation){
+ return Codecs.getAdapter(targetType, annotation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/Codecs.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Codecs.java b/api/src/main/java/org/apache/tamaya/Codecs.java
new file mode 100644
index 0000000..85657d0
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/Codecs.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import org.apache.tamaya.annotation.WithCodec;
+import org.apache.tamaya.spi.CodecsSingletonSpi;
+import org.apache.tamaya.spi.ServiceContext;
+
+/**
+ * Singleton manager that provides {@link Codec} instance, usable for converting String
+ * based configuration entries into any other target types.
+ */
+final class Codecs {
+
+ /**
+ * Orivate singleton constructor.
+ */
+ private Codecs(){}
+
+ /**
+ * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
+ * this type.
+ * @param targetType The target class, not null.
+ * @param adapter The adapter, not null.
+ * @param <T> The target type
+ * @return any adapter replaced with the new adapter, or null.
+ */
+ public static <T> Codec<T> register(Class<T> targetType, Codec<T> adapter){
+ return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).register(targetType, adapter);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ public static boolean isTargetTypeSupported(Class<?> targetType){
+ return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).isTargetTypeSupported(targetType);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws ConfigException if the target type is not supported.
+ */
+ public static <T> Codec<T> getCodec(Class<T> targetType){
+ return getAdapter(targetType, null);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param annotation the {@link org.apache.tamaya.annotation.WithCodec} annotation, or null. If the annotation is not null and
+ * defines an overriding adapter, this instance is created and returned.
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws ConfigException if the target type is not supported, or the overriding adapter cannot be
+ * instantiated.
+ */
+ public static <T> Codec<T> getAdapter(Class<T> targetType, WithCodec annotation){
+ return ServiceContext.getInstance().getSingleton(CodecsSingletonSpi.class).getCodec(targetType, annotation);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java b/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
index f9ba38a..28c1810 100644
--- a/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
+++ b/api/src/main/java/org/apache/tamaya/ConfigChangeSetBuilder.java
@@ -25,7 +25,7 @@ import java.util.*;
/**
* Models a set current changes to be applied to a configuration/property provider. Such a set can be applied
* to any {@link PropertySource} instance. If the provider is mutable it may check the
- * version given and apply the changes to the provider/configuration, including triggering current regarding
+ * version given and applyChanges the changes to the provider/configuration, including triggering current regarding
* change events.
*
* Created by Anatole on 06.09.2014.
@@ -84,6 +84,7 @@ public final class ConfigChangeSetBuilder {
*/
public ConfigChangeSetBuilder addChange(PropertyChangeEvent changeEvent) {
Objects.requireNonNull(changeEvent);
+ // todo consider any codecs
this.delta.put(changeEvent.getPropertyName(), changeEvent);
return this;
}
@@ -102,7 +103,7 @@ public final class ConfigChangeSetBuilder {
/**
* Get the current values, also considering any changes recorded within this change set.
* @param key the key current the entry, not null.
- * @return the value, or null.
+ * @return the keys, or null.
*/
public String get(String key) {
PropertyChangeEvent change = this.delta.get(key);
@@ -135,20 +136,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
- * @return the builder for chaining.
- */
- public ConfigChangeSetBuilder put(String key, String value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null), Objects.requireNonNull(value)));
- return this;
- }
-
- /**
- * Applies the given value.
- * @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, boolean value) {
@@ -157,9 +147,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, byte value) {
@@ -168,9 +158,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, char value) {
@@ -179,9 +169,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, short value) {
@@ -190,9 +180,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, int value) {
@@ -201,9 +191,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, long value) {
@@ -212,9 +202,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, float value) {
@@ -223,9 +213,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, double value) {
@@ -234,9 +224,9 @@ public final class ConfigChangeSetBuilder {
}
/**
- * Applies the given value.
+ * Applies the given keys.
* @param key the key current the entry, not null.
- * @param value the value to be applied, not null.
+ * @param value the keys to be applied, not null.
* @return the builder for chaining.
*/
public ConfigChangeSetBuilder put(String key, Object value) {
@@ -249,7 +239,7 @@ public final class ConfigChangeSetBuilder {
* @param changes the changes to be applied, not null.
* @return the builder for chaining.
*/
- public ConfigChangeSetBuilder putAll(Map<String,String> changes) {
+ public ConfigChangeSetBuilder putAll(Map<String,Object> changes) {
changes.forEach((k,v) ->
this.delta.put(k, new PropertyChangeEvent(this.source, k, this.source.get(k).orElse(null), v)));
return this;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Configuration.java b/api/src/main/java/org/apache/tamaya/Configuration.java
index ac988ac..f3a11c5 100644
--- a/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -44,11 +44,11 @@ import java.util.stream.Collectors;
public interface Configuration extends PropertySource {
/**
- * Get the property value as {@link Boolean}.
+ * Get the property keys as {@link Boolean}.
*
* @param key the property's absolute, or relative path, e.g. {@code
* a/b/c/d.myProperty}.
- * @return the property's value.
+ * @return the property's keys.
*/
default Boolean getBoolean(String key) {
Optional<Boolean> val = get(key, Boolean.class);
@@ -59,11 +59,11 @@ public interface Configuration extends PropertySource {
}
/**
- * Get the property value as {@link Integer}.
+ * Get the property keys as {@link Integer}.
*
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
- * @return the property's value.
+ * @return the property's keys.
*/
default OptionalInt getInteger(String key){
Optional<Integer> val = get(key, Integer.class);
@@ -75,11 +75,11 @@ public interface Configuration extends PropertySource {
/**
- * Get the property value as {@link Long}.
+ * Get the property keys as {@link Long}.
*
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
- * @return the property's value.
+ * @return the property's keys.
*/
default OptionalLong getLong(String key){
Optional<Long> val = get(key, Long.class);
@@ -91,11 +91,11 @@ public interface Configuration extends PropertySource {
/**
- * Get the property value as {@link Double}.
+ * Get the property keys as {@link Double}.
*
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
- * @return the property's value.
+ * @return the property's keys.
* @throws IllegalArgumentException if no such property exists.
*/
default OptionalDouble getDouble(String key){
@@ -109,7 +109,7 @@ public interface Configuration extends PropertySource {
/**
- * Get the property value as type {@code Class<T>}.
+ * Get the property keys as type {@code Class<T>}.
* <p>
* If {@code Class<T>} is not one current
* {@code Boolean, Short, Integer, Long, Float, Double, BigInteger,
@@ -121,33 +121,33 @@ public interface Configuration extends PropertySource {
* a/b/c/d.myProperty}.
* @param adapter the PropertyAdapter to perform the conversion fromMap
* {@link String} to {@code Class<T>}, not {@code null}.
- * @return the property's value.
- * @throws IllegalArgumentException if the value could not be converted to the required target
+ * @return the property's keys.
+ * @throws IllegalArgumentException if the keys could not be converted to the required target
* type, or no such property exists.
*/
- default <T> Optional<T> getAdapted(String key, PropertyAdapter<T> adapter){
+ default <T> Optional<T> getAdapted(String key, Codec<T> adapter){
Optional<String> value = get(key);
if(value.isPresent()) {
- return Optional.ofNullable(adapter.adapt(value.get()));
+ return Optional.ofNullable(adapter.deserialize(value.get()));
}
return Optional.empty();
}
/**
- * Get the property value as type T. This will implicitly require a corresponding {@link
- * PropertyAdapter} to be available that is capable current providing type T
- * fromMap the given String value.
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * Codec} to be available that is capable current providing type T
+ * fromMap the given String keys.
*
* @param key the property's absolute, or relative path, e.g. @code
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
- * @return the property's value.
- * @throws IllegalArgumentException if the value could not be converted to the required target
+ * @return the property's keys.
+ * @throws IllegalArgumentException if the keys could not be converted to the required target
* type.
*/
default <T> Optional<T> get(String key, Class<T> type){
- return getAdapted(key, PropertyAdapters.getAdapter(type));
+ return getAdapted(key, Codecs.getCodec(type));
}
/**
@@ -245,7 +245,7 @@ public interface Configuration extends PropertySource {
}
/**
- * Query some value fromMap a configuration.
+ * Query some keys fromMap a configuration.
*
* @param query the query, never {@code null}.
* @return the result
@@ -255,7 +255,7 @@ public interface Configuration extends PropertySource {
}
/**
- * Field that allows property config to be versioned, meaning that each change on a provider requires this value
+ * Field that allows property config to be versioned, meaning that each change on a provider requires this keys
* to be incremented by one. This can be easily used to implement versioning (and optimistic locking)
* in distributed (remote) usage scenarios.
* @return the version current the current instance, or 'N/A'.
@@ -273,19 +273,6 @@ public interface Configuration extends PropertySource {
return ConfigurationManager.isConfigurationDefined(name);
}
- /**
- * Access a configuration by name.
- *
- * @param name the configuration's name, not null, not empty.
- * @param template the annotated configuration's
- * template interface, not null.
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static <T> T current(String name, Class<T> template){
- return ConfigurationManager.getConfiguration(name, template);
- }
-
/**
* Access a configuration by name.
@@ -313,11 +300,14 @@ public interface Configuration extends PropertySource {
*
* @param type the annotated configuration type (could be an interface or
* a non abstract class), not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @return the corresponding typed Configuration instance, never null.
* @throws ConfigException if the configuration could not be resolved.
*/
- public static <T> T current(Class<T> type){
- return ConfigurationManager.getConfiguration(type);
+ public static <T> T createTemplate(Class<T> type, Configuration... configurations){
+ return ConfigurationManager.createTemplate(type, configurations);
}
/**
@@ -325,32 +315,27 @@ public interface Configuration extends PropertySource {
* entries.
*
* @param instance the instance with configuration annotations, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @return the corresponding typed Configuration instance, never null.
* @throws ConfigException if the configuration could not be resolved.
*/
- public static void configure(Object instance){
- ConfigurationManager.configure(instance);
- }
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- *
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- public static String evaluateValue(String expression){
- return ConfigurationManager.evaluateValue(expression);
+ public static void configure(Object instance, Configuration... configurations){
+ ConfigurationManager.configure(instance, configurations);
}
/**
* Evaluate the current expression based on the current configuration valid.
*
- * @param config The configuration to be used for evluating, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @param expression the expression, not null.
* @return the evaluated config expression.
*/
- public static String evaluateValue(Configuration config, String expression){
- return ConfigurationManager.evaluateValue(config, expression);
+ public static String evaluateValue(String expression, Configuration... configurations){
+ return ConfigurationManager.evaluateValue(expression, configurations);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigurationManager.java b/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
index 9915d64..6c3c009 100644
--- a/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
+++ b/api/src/main/java/org/apache/tamaya/ConfigurationManager.java
@@ -47,19 +47,6 @@ final class ConfigurationManager{
return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).isConfigurationDefined(name);
}
- /**
- * Access a configuration by name.
- *
- * @param name the configuration's name, not null, not empty.
- * @param template the annotated configuration's
- * template interface, not null.
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static <T> T getConfiguration(String name, Class<T> template){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).getConfiguration(name, template);
- }
-
/**
* Access a configuration by name.
@@ -87,11 +74,14 @@ final class ConfigurationManager{
*
* @param type the annotated configuration type (could be an interface or
* a non abstract class), not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @return the corresponding typed Configuration instance, never null.
* @throws ConfigException if the configuration could not be resolved.
*/
- public static <T> T getConfiguration(Class<T> type){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).getConfiguration(type);
+ public static <T> T createTemplate(Class<T> type, Configuration... configurations){
+ return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).createTemplate(type, configurations);
}
/**
@@ -99,32 +89,25 @@ final class ConfigurationManager{
* entries.
*
* @param instance the instance with configuration annotations, not null.
- * @return the corresponding typed Configuration instance, never null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
* @throws ConfigException if the configuration could not be resolved.
*/
- public static void configure(Object instance){
- ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).configure(instance);
- }
-
- /**
- * Evaluate the current expression based on the current configuration valid.
- *
- * @param expression the expression, not null.
- * @return the evaluated config expression.
- */
- public static String evaluateValue(String expression){
- return evaluateValue(getConfiguration(), expression);
+ public static void configure(Object instance, Configuration... configurations){
+ ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).configure(instance, configurations);
}
/**
* Evaluate the current expression based on the current configuration valid.
*
- * @param config The configuration to be used for evluating, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @param expression the expression, not null.
* @return the evaluated config expression.
*/
- public static String evaluateValue(Configuration config, String expression){
- return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).evaluateValue(config, expression);
+ public static String evaluateValue(String expression, Configuration... configurations){
+ return ServiceContext.getInstance().getSingleton(ConfigurationManagerSingletonSpi.class).evaluateValue(expression, configurations);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/Environment.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Environment.java b/api/src/main/java/org/apache/tamaya/Environment.java
index c52b21e..11e7100 100644
--- a/api/src/main/java/org/apache/tamaya/Environment.java
+++ b/api/src/main/java/org/apache/tamaya/Environment.java
@@ -39,7 +39,7 @@ public interface Environment{
/**
* Access a property.
* @param key the property's key, not null.
- * @return the property's value.
+ * @return the property's keys.
*/
Optional<String> get(String key);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/MetaInfo.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/MetaInfo.java b/api/src/main/java/org/apache/tamaya/MetaInfo.java
index 9dd98fb..e701529 100644
--- a/api/src/main/java/org/apache/tamaya/MetaInfo.java
+++ b/api/src/main/java/org/apache/tamaya/MetaInfo.java
@@ -25,8 +25,16 @@ import java.util.*;
* configuration or some if its entries.
*/
public final class MetaInfo{
- /** The key used for storing the data owner. */
- private static final String OWNER_KEY = "_owner";
+ public static final String TIMESTAMP = "timestamp";
+ public static final String CONTEXT = "context";
+ public static final String NAME = "name";
+ public static final String INFO = "info";
+ public static final String TYPE = "type";
+ public static final String SOURCE = "source";
+ public static final String SOURCE_EXPRESSION = "source-expression";
+
+// /** The key used for storing the data owner. */
+// private static final String OWNER_KEY = "_owner";
/** The meta information data. */
private final Map<String, String> metaInfo = new HashMap<>();
@@ -51,7 +59,7 @@ public final class MetaInfo{
/**
* Access a meta data property.
* @param key the property key, not null.
- * @return the corresponding property value, or null.
+ * @return the corresponding property keys, or null.
*/
public String get(String key){
return this.metaInfo.get(key);
@@ -62,8 +70,56 @@ public final class MetaInfo{
* Get the information about the data owner.
* @return the data owner info, or null.
*/
- public String getOwnerInfo(){
- return this.metaInfo.get(OWNER_KEY);
+ public String getName(){
+ return this.metaInfo.get(NAME);
+ }
+
+ /**
+ * Get the type of configuration.
+ * @return the type, or null.
+ */
+ public String getType(){
+ return this.metaInfo.get(TYPE);
+ }
+
+ /**
+ * Get the info of configuration.
+ * @return the info, or null.
+ */
+ public String getInfo(){
+ return this.metaInfo.get(INFO);
+ }
+
+ /**
+ * Get the source of configuration.
+ * @return the source, or null.
+ */
+ public String getSource(){
+ return this.metaInfo.get(SOURCE);
+ }
+
+ /**
+ * Get the source expression to load thr configuration.
+ * @return the info, or null.
+ */
+ public String getSourceExpression(){
+ return this.metaInfo.get(SOURCE_EXPRESSION);
+ }
+
+ /**
+ * Get the context of configuration.
+ * @return the context, or null.
+ */
+ public String getContext(){
+ return this.metaInfo.get(CONTEXT);
+ }
+
+ /**
+ * Get the context of configuration.
+ * @return the context, or null.
+ */
+ public String getTimestamp(){
+ return this.metaInfo.get(TIMESTAMP);
}
/**
@@ -97,7 +153,7 @@ public final class MetaInfo{
/**
* Helper method to escape "=\\[]".
- * @param val the input value, not null.
+ * @param val the input keys, not null.
* @return the escaped String, not null.
*/
static String escape(String val){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java b/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
index 277f34d..b5433ef 100644
--- a/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
+++ b/api/src/main/java/org/apache/tamaya/MetaInfoBuilder.java
@@ -28,16 +28,6 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public final class MetaInfoBuilder{
- public static final String METAINFO = "_metainfo";
- public static final String TIMESTAMP = "timestamp";
- public static final String CONTEXT = "context";
- public static final String NAME = "name";
- public static final String INFO = "info";
- public static final String TYPE = "type";
- public static final String SOURCE = "source";
- public static final String ENVIRONMENT = "environment";
- public static final String SOURCE_EXPRESSION = "source-expression";
-
Map<String,String> map = new ConcurrentHashMap<>();
private MetaInfoBuilder(MetaInfo metaInfo){
@@ -47,7 +37,7 @@ public final class MetaInfoBuilder{
}
private MetaInfoBuilder(String name){
- this.map.put(NAME, Objects.requireNonNull(name));
+ this.map.put(MetaInfo.NAME, Objects.requireNonNull(name));
}
public static MetaInfoBuilder of(MetaInfo metaInfo){
@@ -62,48 +52,27 @@ public final class MetaInfoBuilder{
return new MetaInfoBuilder("<noname>");
}
- public MetaInfoBuilder withName(String name){
- Objects.requireNonNull(name);
- map.put(NAME, name);
- return this;
- }
-
public MetaInfoBuilder setName(String name){
Objects.requireNonNull(name);
- map.put(NAME, name);
+ map.put(MetaInfo.NAME, name);
return this;
}
public MetaInfoBuilder setType(String type){
Objects.requireNonNull(type);
- map.put(TYPE, type);
+ map.put(MetaInfo.TYPE, type);
return this;
}
public MetaInfoBuilder setInfo(String info){
Objects.requireNonNull(info);
- map.put(INFO, info);
+ map.put(MetaInfo.INFO, info);
return this;
}
public MetaInfoBuilder setSources(String... sources){
Objects.requireNonNull(sources);
- map.put(SOURCE, Arrays.toString(sources));
- return this;
- }
-
- public MetaInfoBuilder setMetaInfo(String key, String metaInfo){
- Objects.requireNonNull(metaInfo);
- Objects.requireNonNull(key);
- map.put(key + '.' + METAINFO, metaInfo);
- return this;
- }
-
- public MetaInfoBuilder setMetaInfo(String metaInfo){
- if(metaInfo!=null){
- Objects.requireNonNull(metaInfo);
- map.put(METAINFO, metaInfo);
- }
+ map.put(MetaInfo.SOURCE, Arrays.toString(sources));
return this;
}
@@ -117,18 +86,18 @@ public final class MetaInfoBuilder{
public MetaInfoBuilder setSourceExpressions(String... sourceExpressions){
Objects.requireNonNull(sourceExpressions);
- map.put(SOURCE_EXPRESSION, Arrays.toString(sourceExpressions));
+ map.put(MetaInfo.SOURCE_EXPRESSION, Arrays.toString(sourceExpressions));
return this;
}
public MetaInfoBuilder setTimestamp(long timestamp){
- map.put(TIMESTAMP, String.valueOf(timestamp));
+ map.put(MetaInfo.TIMESTAMP, String.valueOf(timestamp));
return this;
}
public MetaInfoBuilder setContext(String context){
Objects.requireNonNull(context);
- map.put(CONTEXT, context);
+ map.put(MetaInfo.CONTEXT, context);
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/PropertyAdapter.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertyAdapter.java b/api/src/main/java/org/apache/tamaya/PropertyAdapter.java
deleted file mode 100644
index 5ee0eb7..0000000
--- a/api/src/main/java/org/apache/tamaya/PropertyAdapter.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.spi.PropertyAdaptersSingletonSpi;
-import org.apache.tamaya.spi.ServiceContext;
-
-/**
- * Interface for an adapter that converts a configured String into something else.
- * This is typically used for implementing type conversion fromMap String to a certain target
- * type current the configured property.
- */
-@FunctionalInterface
-public interface PropertyAdapter<T>{
-
- /**
- * Adapt the given configuration value to the required target type.
- * @param value the configuration value
- * @return adapted value
- */
- T adapt(String value);
-
- /**
- * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- public static <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter){
- return PropertyAdapters.register(targetType, adapter);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- public static boolean isTargetTypeSupported(Class<?> targetType){
- return PropertyAdapters.isTargetTypeSupported(targetType);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws ConfigException if the target type is not supported.
- */
- public static <T> PropertyAdapter<T> getAdapter(Class<T> targetType){
- return PropertyAdapters.getAdapter(targetType);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param annotation the {@link org.apache.tamaya.annotation.WithPropertyAdapter} annotation, or null. If the annotation is not null and
- * defines an overriding adapter, this instance is created and returned.
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws ConfigException if the target type is not supported, or the overriding adapter cannot be
- * instantiated.
- */
- public static <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter annotation){
- return PropertyAdapters.getAdapter(targetType, annotation);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/PropertyAdapters.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertyAdapters.java b/api/src/main/java/org/apache/tamaya/PropertyAdapters.java
deleted file mode 100644
index 90b29d7..0000000
--- a/api/src/main/java/org/apache/tamaya/PropertyAdapters.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spi.PropertyAdaptersSingletonSpi;
-
-/**
- * Singleton manager that provides {@link PropertyAdapter} instance, usable for converting String
- * based configuration entries into any other target types.
- */
-final class PropertyAdapters{
-
- /**
- * Orivate singleton constructor.
- */
- private PropertyAdapters(){}
-
- /**
- * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- public static <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter){
- return ServiceContext.getInstance().getSingleton(PropertyAdaptersSingletonSpi.class).register(targetType, adapter);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- public static boolean isTargetTypeSupported(Class<?> targetType){
- return ServiceContext.getInstance().getSingleton(PropertyAdaptersSingletonSpi.class).isTargetTypeSupported(targetType);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws ConfigException if the target type is not supported.
- */
- public static <T> PropertyAdapter<T> getAdapter(Class<T> targetType){
- return getAdapter(targetType, null);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param annotation the {@link org.apache.tamaya.annotation.WithPropertyAdapter} annotation, or null. If the annotation is not null and
- * defines an overriding adapter, this instance is created and returned.
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws ConfigException if the target type is not supported, or the overriding adapter cannot be
- * instantiated.
- */
- public static <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter annotation){
- return ServiceContext.getInstance().getSingleton(PropertyAdaptersSingletonSpi.class).getAdapter(targetType, annotation);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/PropertySource.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/PropertySource.java b/api/src/main/java/org/apache/tamaya/PropertySource.java
index f44d561..9179c8f 100644
--- a/api/src/main/java/org/apache/tamaya/PropertySource.java
+++ b/api/src/main/java/org/apache/tamaya/PropertySource.java
@@ -75,7 +75,7 @@ public interface PropertySource {
* Access a property.
*
* @param key the property's key, not null.
- * @return the property's value.
+ * @return the property's keys.
*/
Optional<String> get(String key);
@@ -132,7 +132,7 @@ public interface PropertySource {
* Allows to evaluate if the provider is mutable.
*
* @return true, if the provider is mutable.
- * @see #apply(ConfigChangeSet)
+ * @see #applyChanges(ConfigChangeSet)
*/
default boolean isMutable() {
return false;
@@ -146,7 +146,7 @@ public interface PropertySource {
* @throws UnsupportedOperationException when the configuration is not writable.
* @see #isMutable()
*/
- default void apply(ConfigChangeSet change) {
+ default void applyChanges(ConfigChangeSet change) {
throw new UnsupportedOperationException("Config/properties not mutable: " + this);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java b/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
index a1af097..e1d773d 100644
--- a/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
+++ b/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperties.java
@@ -25,7 +25,7 @@ import java.lang.annotation.Target;
/**
* Annotation container to enable injection current multiple {@link org.apache.tamaya.annotation.ConfiguredProperty}
- * annotations. Hereby the ordering current annotations imply the defaulting. The first value that
+ * 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)
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
public @interface ConfiguredProperties {
/**
- * Get the different configuration keys to be looked up, in order current precedence. The first non null value
+ * 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/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java b/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
index 14c9c55..a29ef8b 100644
--- a/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
+++ b/api/src/main/java/org/apache/tamaya/annotation/ConfiguredProperty.java
@@ -25,7 +25,7 @@ import java.lang.annotation.*;
* a configuration template method. Hereby this annotation can be used in multiple ways and combined
* with other annotations such as {@link org.apache.tamaya.annotation.DefaultValue},
* {@link org.apache.tamaya.annotation.WithLoadPolicy}, {@link org.apache.tamaya.annotation.WithConfig},
- * {@link org.apache.tamaya.annotation.WithConfigOperator}, {@link org.apache.tamaya.annotation.WithPropertyAdapter}.
+ * {@link org.apache.tamaya.annotation.WithConfigOperator}, {@link WithCodec}.
*
* Below the most simple variant current a configured class is given:
* {@code
@@ -38,31 +38,31 @@ import java.lang.annotation.*;
* the following is happening:
* <ul>
* <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = Configuration.current();}</li>
- * <li>The current property String value is evaluated by calling {@code cfg.get("aValue");}</li>
+ * <li>The current property String keys is evaluated by calling {@code cfg.get("aValue");}</li>
* <li>if not successful, an error is thrown ({@link org.apache.tamaya.ConfigException}.</li>
- * <li>On success, since no type conversion is involved, the value is injected.</li>
+ * <li>On success, since no type conversion is involved, the keys is injected.</li>
* <li>The configured bean is registered as a weak change listener in the config system's underlying
* configuration, so future config changes can be propagated (controlled by {@link org.apache.tamaya.annotation.WithLoadPolicy}
* annotations).</li>
* </ul>
*
- * In the next example we explicitly define the property value:
+ * In the next example we explicitly define the property keys:
* {@code
* pubic class ConfiguredItem{
*
* @ConfiguredProperty
- * @ConfiguredProperty("a.b.value")
- * @configuredProperty("a.b.deprecated.value")
- * @DefaultValue("${env:java.version}")
+ * @ConfiguredProperty({"a.b.value", "a.b.deprecated.keys", "${env:java.version}"})
+ * @ConfiguredProperty(configuration={"a", "b"}
+ * @ConfiguredProperty(configuration={"a", "b", keys={"a.b.keys", "a.b.deprecated.keys", "${env:java.version}"}}
* private String aValue;
* }
*
* Within this example we evaluate multiple possible keys. Evaluation is aborted if a key could be successfully
* resolved. Hereby the ordering current the annotations define the ordering current resolution, so in the example above
- * resolution equals to {@code "aValue", "a.b.value", "a.b.deprecated.value"}. If no value could be read
- * fromMap the configuration, it uses the value fromMap the {@code DefaultValue} annotation. Interesting here
- * is that this value is not static, it is evaluated by calling
- * {@link org.apache.tamaya.Configuration#evaluateValue(org.apache.tamaya.Configuration, String)}.
+ * resolution equals to {@code "aValue", "a.b.keys", "a.b.deprecated.keys"}. If no keys could be read
+ * fromMap the configuration, it uses the keys fromMap the {@code DefaultValue} annotation. Interesting here
+ * is that this keys is not static, it is evaluated by calling
+ * {@link org.apache.tamaya.Configuration#evaluateValue(String, org.apache.tamaya.Configuration...)}.
*/
@Repeatable(ConfiguredProperties.class)
@Retention(RetentionPolicy.RUNTIME)
@@ -70,10 +70,18 @@ import java.lang.annotation.*;
public @interface ConfiguredProperty {
/**
- * Get the property names to be used. Hereby the first non null value evaluated is injected as property value.
+ * 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.
*/
- String value() default "";
+ String[] keys() default {};
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java b/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
index 19ee341..c4b2e3a 100644
--- a/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
+++ b/api/src/main/java/org/apache/tamaya/annotation/DefaultValue.java
@@ -24,8 +24,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Annotation to define a default value to be returned, when no configured value could be
- * determined for a property/template accessor. The value hereby can also contain a
+ * Annotation to define a default keys to be returned, when no configured keys could be
+ * determined for a property/template accessor. The keys hereby can also contain a
* dynamic expression that is evaluated by the configuration system.
*/
@Retention(RetentionPolicy.RUNTIME)
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
public @interface DefaultValue {
/**
- * The default value to be injected, if no such configuration entry was found. If value was found and no default
+ * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
* is defined, it is handled as a deployment error.
*/
String value() default "";
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java b/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
index 2e0089a..116a2c1 100644
--- a/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
+++ b/api/src/main/java/org/apache/tamaya/annotation/LoadPolicy.java
@@ -25,22 +25,22 @@ package org.apache.tamaya.annotation;
*/
public enum LoadPolicy {
/**
- * The configuration value is evaluated once, when the owning component is loaded/configured, but never updated later.
+ * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later.
*/
INITIAL,
/**
- * The configuration value is evaluated exactly once on its first use lazily, but never updated later.
+ * The configuration keys is evaluated exactly once on its first use lazily, but never updated later.
* This feature is not applicable on field injection, but only on configuration template methods.
*/
LAZY,
/**
- * The configuration value is evaluated once, when the owning component is loaded/configured.
+ * The configuration keys is evaluated once, when the owning component is loaded/configured.
* Later changes on this configuration entry will be reinjected/updated and additionally triggered
* as {@link java.beans.PropertyChangeEvent}.
*/
MANAGED,
/**
- * The configuration value is evaluated once, when the owning component is loaded/configured.
+ * The configuration keys is evaluated once, when the owning component is loaded/configured.
* Later changes on this configuration entry will be reinjected/updated, but no {@link java.beans.PropertyChangeEvent}
* will be triggered.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/WithCodec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/WithCodec.java b/api/src/main/java/org/apache/tamaya/annotation/WithCodec.java
new file mode 100644
index 0000000..3a092b2
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/annotation/WithCodec.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.annotation;
+
+import org.apache.tamaya.Codec;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define a type adapter to be used before injecting a configured keys, or for applying changes.
+ * This will override any other adapter for performing the type conversion before
+ * injecting the field keys.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface WithCodec {
+
+ /**
+ * Define a custom adapter or codec that should be used to deserialize the configuration entry injected. This overrides any
+ * 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.
+ */
+ Class<? extends Codec> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/WithConfig.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/WithConfig.java b/api/src/main/java/org/apache/tamaya/annotation/WithConfig.java
deleted file mode 100644
index 00180a5..0000000
--- a/api/src/main/java/org/apache/tamaya/annotation/WithConfig.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.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to reference an explicit {@link org.apache.tamaya.Configuration} to be used to
- * resolve the required properties. the configured value is passed to {@code Configuration.current(String)}
- * to evaluate the required configuration required.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
-public @interface WithConfig {
-
- /**
- * The name current the {@link org.apache.tamaya.Configuration} to be used to
- * resolve the required properties, not null or empty.
- */
- String value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java b/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
index 28bf814..0ede2c2 100644
--- a/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
+++ b/api/src/main/java/org/apache/tamaya/annotation/WithConfigOperator.java
@@ -27,7 +27,7 @@ import java.lang.annotation.Target;
import java.util.function.UnaryOperator;
/**
- * Annotation to define an configuration operator to be used before accessing a configured value.
+ * Annotation to define an configuration operator to be used before accessing a configured keys.
* This allows filtering current configuration, e.g. for realizing views or ensuring security
* constraints.
*/
@@ -36,7 +36,7 @@ import java.util.function.UnaryOperator;
public @interface WithConfigOperator {
/**
- * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any
+ * Define a custom adapter that should be used to deserialize the configuration entry injected. This overrides any
* 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.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java b/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java
deleted file mode 100644
index 4001742..0000000
--- a/api/src/main/java/org/apache/tamaya/annotation/WithPropertyAdapter.java
+++ /dev/null
@@ -1,44 +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.annotation;
-
-import org.apache.tamaya.PropertyAdapter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a type adapter to be used before injecting a configured value.
- * This will override any other adapter for performing the type conversion before
- * injecting the field value.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface WithPropertyAdapter {
-
- /**
- * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any
- * 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.
- */
- Class<? extends PropertyAdapter> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
new file mode 100644
index 0000000..07993e5
--- /dev/null
+++ b/api/src/main/java/org/apache/tamaya/spi/CodecsSingletonSpi.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.Codec;
+import org.apache.tamaya.annotation.WithCodec;
+
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * SPI that is used by the {@link org.apache.tamaya.Codecs} singleton as delegation instance.
+ */
+public interface CodecsSingletonSpi {
+
+ /**
+ * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
+ * this type.
+ * @param targetType The target class, not null.
+ * @param adapter The adapter, not null.
+ * @param <T> The target type
+ * @return any adapter replaced with the new adapter, or null.
+ */
+ <T> Codec<T> register(Class<T> targetType, Codec<T> adapter);
+
+ default <T> Codec<T> register(Class<T> targetType, Function<String,T> decoder, Function<T, String> encoder){
+ Objects.requireNonNull(targetType);
+ Objects.requireNonNull(decoder);
+ Objects.requireNonNull(encoder);
+ return register(targetType, new Codec<T>(){
+
+ @Override
+ public T deserialize(String value) {
+ return decoder.apply(value);
+ }
+
+ @Override
+ public String serialize(T value) {
+ return encoder.apply(value);
+ }
+
+ @Override
+ public String toString(){
+ return "Codec(decoder="+decoder.getClass().getName()+", encoder="+encoder.getClass().getName()+")";
+ }
+ });
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ default <T> Codec<T> getAdapter(Class<T> targetType){
+ return getCodec(targetType, null);
+ }
+
+ /**
+ * Get an adapter converting to the given target type.
+ * @param targetType the target type class
+ * @param <T> the target type
+ * @return the corresponding adapter, never null.
+ * @throws org.apache.tamaya.ConfigException if the target type is not supported.
+ */
+ <T> Codec<T> getCodec(Class<T> targetType, WithCodec annotation);
+
+ /**
+ * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
+ * @param targetType the target type class
+ * @return true, if the given target type is supported.
+ */
+ boolean isTargetTypeSupported(Class<?> targetType);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
index 46f9a10..2bbc180 100644
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
+++ b/api/src/main/java/org/apache/tamaya/spi/ConfigurationManagerSingletonSpi.java
@@ -49,9 +49,7 @@ public interface ConfigurationManagerSingletonSpi{
* @return the corresponding Configuration instance, never null.
* @throws org.apache.tamaya.ConfigException if no such configuration is defined.
*/
- default Configuration getConfiguration(String name){
- return getConfiguration(name, Configuration.class);
- }
+ Configuration getConfiguration(String name);
/**
* Access the default configuration.
@@ -59,7 +57,7 @@ public interface ConfigurationManagerSingletonSpi{
* @throws org.apache.tamaya.ConfigException if no such configuration is defined.
*/
default Configuration getConfiguration(){
- return getConfiguration("default", Configuration.class);
+ return getConfiguration("default");
}
/**
@@ -67,40 +65,33 @@ public interface ConfigurationManagerSingletonSpi{
* entries.
*
* @param instance the instance with configuration annotations, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @throws org.apache.tamaya.ConfigException if any required configuration could not be resolved/injected.
*/
- void configure(Object instance);
+ void configure(Object instance, Configuration... configurations);
/**
* Access a configuration by name.
*
- * @param name the configuration's name, not null, not empty.
- * @param template the annotated configuration's
- * template interface, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @return the corresponding Configuration instance, never null.
* @throws org.apache.tamaya.ConfigException if no such configuration is defined.
*/
- <T> T getConfiguration(String name, Class<T> template);
-
- /**
- * Access a typed configuration.
- *
- * @param type the annotated configuration type (could be an interface or
- * a non abstract class), not null.
- * @return the corresponding typed Configuration instance, never null.
- * @throws org.apache.tamaya.ConfigException if the configuration could not be resolved.
- */
- default <T> T getConfiguration(Class<T> type){
- return getConfiguration("default", type);
- }
+ <T> T createTemplate(Class<T> template, Configuration... configurations);
/**
* Evaluate the current expression based on the current configuration valid.
- * @param config The configuration to be used for evaluating, using EL, not null.
+ * @param configurations overriding configurations to be used for evaluating the values for injection into {@code instance}, not null.
+ * If no such config is passed, the default configurationa provided by the current
+ * registered providers are used.
* @param expression the expression, not null.
* @return the evaluated config expression.
*/
- String evaluateValue(Configuration config, String expression);
+ String evaluateValue(String expression, Configuration... configurations);
/**
* Add a ConfigChangeSet listener to the given configuration instance.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/spi/Orderable.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/Orderable.java b/api/src/main/java/org/apache/tamaya/spi/Orderable.java
index 4a314f6..56a99d7 100644
--- a/api/src/main/java/org/apache/tamaya/spi/Orderable.java
+++ b/api/src/main/java/org/apache/tamaya/spi/Orderable.java
@@ -27,8 +27,8 @@ package org.apache.tamaya.spi;
@FunctionalInterface
public interface Orderable {
/**
- * Get the ordinal value for the component, by default 0.
- * @return the ordinal value
+ * Get the ordinal keys for the component, by default 0.
+ * @return the ordinal keys
*/
int order();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/main/java/org/apache/tamaya/spi/PropertyAdaptersSingletonSpi.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/PropertyAdaptersSingletonSpi.java b/api/src/main/java/org/apache/tamaya/spi/PropertyAdaptersSingletonSpi.java
deleted file mode 100644
index edc5ed9..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/PropertyAdaptersSingletonSpi.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-import org.apache.tamaya.PropertyAdapter;
-import org.apache.tamaya.annotation.WithPropertyAdapter;
-
-/**
- * SPI that is used by the {@link org.apache.tamaya.PropertyAdapters} singleton as delegation instance.
- */
-public interface PropertyAdaptersSingletonSpi{
-
- /**
- * Registers a new PropertyAdapter for the given target type, hereby replacing any existing adapter for
- * this type.
- * @param targetType The target class, not null.
- * @param adapter The adapter, not null.
- * @param <T> The target type
- * @return any adapter replaced with the new adapter, or null.
- */
- <T> PropertyAdapter<T> register(Class<T> targetType, PropertyAdapter<T> adapter);
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- default <T> PropertyAdapter<T> getAdapter(Class<T> targetType){
- return getAdapter(targetType, null);
- }
-
- /**
- * Get an adapter converting to the given target type.
- * @param targetType the target type class
- * @param <T> the target type
- * @return the corresponding adapter, never null.
- * @throws org.apache.tamaya.ConfigException if the target type is not supported.
- */
- <T> PropertyAdapter<T> getAdapter(Class<T> targetType, WithPropertyAdapter annotation);
-
- /**
- * Checks if the given target type is supported, i.e. a adapter is registered and accessible.
- * @param targetType the target type class
- * @return true, if the given target type is supported.
- */
- boolean isTargetTypeSupported(Class<?> targetType);
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/test/java/annottext/AnnotatedConfig.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/annottext/AnnotatedConfig.java b/api/src/test/java/annottext/AnnotatedConfig.java
index 408cc97..20b135f 100644
--- a/api/src/test/java/annottext/AnnotatedConfig.java
+++ b/api/src/test/java/annottext/AnnotatedConfig.java
@@ -31,21 +31,21 @@ import org.apache.tamaya.annotation.LoadPolicy;
@WithLoadPolicy(LoadPolicy.INITIAL)
public interface AnnotatedConfig {
- @ConfiguredProperty("foo.bar.myprop")
- @ConfiguredProperty("mp")
- @ConfiguredProperty("common.test.myProperty")
+ @ConfiguredProperty(keys = "foo.bar.myprop")
+ @ConfiguredProperty(keys = "mp")
+ @ConfiguredProperty(keys = "common.test.myProperty")
@DefaultValue("myValue_$[env.stage]")
// @ConfigLoadPolicy(listener = MyListener.class)
String myParameter();
- @ConfiguredProperty("simple_value")
+ @ConfiguredProperty(keys = "simple_value")
@WithLoadPolicy(LoadPolicy.LAZY)
String simpleValue();
@ConfiguredProperty
String simplestValue();
- @ConfiguredProperty("env.host.name")
+ @ConfiguredProperty(keys = "env.host.name")
String hostName();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c9e62e24/api/src/test/java/annottext/AnnotatedFullConfig.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/annottext/AnnotatedFullConfig.java b/api/src/test/java/annottext/AnnotatedFullConfig.java
index 474356f..df39d12 100644
--- a/api/src/test/java/annottext/AnnotatedFullConfig.java
+++ b/api/src/test/java/annottext/AnnotatedFullConfig.java
@@ -32,21 +32,21 @@ import org.apache.tamaya.annotation.LoadPolicy;
@WithLoadPolicy(LoadPolicy.INITIAL)
public interface AnnotatedFullConfig extends Configuration{
- @ConfiguredProperty("foo.bar.myprop")
- @ConfiguredProperty("mp")
- @ConfiguredProperty("common.test.myProperty")
+ @ConfiguredProperty(keys = "foo.bar.myprop")
+ @ConfiguredProperty(keys = "mp")
+ @ConfiguredProperty(keys = "common.test.myProperty")
@DefaultValue("myValue_$[env.stage]")
// @ConfigLoadPolicy(listener = MyListener.class)
String myParameter();
- @ConfiguredProperty("simple_value")
+ @ConfiguredProperty(keys = "simple_value")
@WithLoadPolicy(LoadPolicy.LAZY)
String simpleValue();
@ConfiguredProperty
String simplestValue();
- @ConfiguredProperty("env.host.name")
+ @ConfiguredProperty(keys = "env.host.name")
String hostName();
}
[4/5] incubator-tamaya git commit: Merge remote-tracking branch
'origin/master'
Posted by an...@apache.org.
Merge remote-tracking branch 'origin/master'
Conflicts:
api/src/main/java/org/apache/tamaya/Codec.java
api/src/main/java/org/apache/tamaya/annotation/WithCodec.java
api/src/test/java/org/apache/tamaya/TestConfigServiceSingletonSpi.java
api/src/test/java/org/apache/tamaya/TestPropertyAdaptersSingletonSpi.java
core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigTemplateInvocationHandler.java
core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredField.java
core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredInstancesManager.java
core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredMethod.java
core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
core/src/main/java/org/apache/tamaya/core/internal/properties/DefaultPropertyAdaptersSingletonSpi.java
core/src/main/java/org/apache/tamaya/core/spi/AdapterProviderSpi.java
core/src/main/java/org/apache/tamaya/core/spi/PropertyAdapterService.java
core/src/test/java/org/apache/tamaya/core/config/MutableConfigTest.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/f8c91031
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/f8c91031
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/f8c91031
Branch: refs/heads/master
Commit: f8c9103103680bb905c95d38c32bf7f07607911f
Parents: c9e62e2 31161df
Author: anatole <an...@apache.org>
Authored: Sat Dec 20 15:29:49 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Dec 20 15:29:49 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 2 +-
.../org/apache/tamaya/EnvironmentManager.java | 6 +--
.../spi/DefaultServiceContextProvider.java | 6 +--
.../spi/EnvironmentManagerSingletonSpi.java | 2 -
.../tamaya/TestEnvironmentManagerSingleton.java | 6 ---
.../core/config/AbstractConfiguration.java | 15 +++---
.../core/config/ConfigurationBuilder.java | 19 ++++---
.../tamaya/core/config/MappedConfiguration.java | 19 ++++---
.../tamaya/core/env/BuildableEnvironment.java | 1 -
.../core/env/ConfiguredSystemProperties.java | 31 ++++++++----
.../org/apache/tamaya/core/internal/Utils.java | 3 +-
...DefaultConfigurationManagerSingletonSpi.java | 50 +++++++++---------
.../config/WeakConfigListenerManager.java | 20 --------
.../internal/el/SystemPropertyResolver.java | 5 +-
...DependentApplicationEnvironmentProvider.java | 27 +++++-----
...ssLoaderDependentEarEnvironmentProvider.java | 4 +-
.../env/InitialEnvironmentProvider.java | 13 +++--
.../internal/env/SingleEnvironmentManager.java | 1 -
.../core/internal/format/PropertiesFormat.java | 1 +
.../internal/format/PropertiesXmlFormat.java | 3 +-
.../internal/inject/ConfigurationInjector.java | 3 +-
.../core/internal/logging/Log4j2Logger.java | 2 +-
.../core/internal/resources/io/ClassUtils.java | 12 ++---
.../resources/io/InputStreamResource.java | 1 -
.../core/internal/resources/io/StringUtils.java | 8 ---
.../core/properties/AbstractPropertySource.java | 15 ++++--
.../properties/DelegatingPropertySource.java | 1 -
.../core/properties/FreezedPropertySource.java | 14 ++++--
.../properties/IntersectingPropertySource.java | 7 +--
.../properties/PathBasedPropertySource.java | 3 +-
.../core/properties/PropertySourceBuilder.java | 22 ++++----
.../core/properties/PropertySourceFactory.java | 19 ++++---
.../properties/ReplacingPropertySource.java | 1 -
.../core/properties/URLBasedPropertySource.java | 3 +-
.../apache/tamaya/core/resource/Resource.java | 2 -
.../tamaya/core/spi/EnvironmentProvider.java | 5 +-
...tionManagerSingletonSpiSingletonSpiTest.java | 5 +-
.../java/org/apache/tamaya/JavaOneDemo.java | 12 ++---
.../env/ConfiguredSystemPropertiesTest.java | 7 ++-
.../internal/MutableTestConfigProvider.java | 16 +++---
.../samples/annotations/ConfiguredTest.java | 9 ++--
.../simple/SimplePropertiesAndCLISample.java | 13 ++---
.../apache/tamaya/ucs/UC1ReadProperties.java | 28 ++++++-----
.../apache/tamaya/ucs/UC2CombineProperties.java | 7 +--
docs/pom.xml | 53 ++++++++++++++++++--
docs/src/main/asciidoc/example/example.adoc | 15 +++++-
.../integration/cdi/ConfigurationExtension.java | 2 +-
pom.xml | 15 ++++++
48 files changed, 294 insertions(+), 240 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/config/ConfigurationBuilder.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/internal/Utils.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
index e3e0bba,d3551e7..d4d2f1d
--- a/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/config/DefaultConfigurationManagerSingletonSpi.java
@@@ -18,24 -18,29 +18,38 @@@
*/
package org.apache.tamaya.core.internal.config;
- import org.apache.tamaya.*;
+ import java.lang.reflect.Proxy;
+ import java.util.ArrayList;
+ import java.util.Collections;
+ import java.util.List;
+ import java.util.Map;
+ import java.util.Optional;
+ import java.util.concurrent.ConcurrentHashMap;
+ import java.util.function.Consumer;
+ import java.util.function.Predicate;
+
+ import org.apache.tamaya.AggregationPolicy;
+ import org.apache.tamaya.ConfigChangeSet;
+ import org.apache.tamaya.ConfigException;
+ import org.apache.tamaya.Configuration;
+ import org.apache.tamaya.PropertySource;
import org.apache.tamaya.core.internal.el.DefaultExpressionEvaluator;
+import org.apache.tamaya.core.internal.inject.ConfigTemplateInvocationHandler;
import org.apache.tamaya.core.internal.inject.ConfigurationInjector;
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
import org.apache.tamaya.core.spi.ExpressionEvaluator;
+
- import org.apache.tamaya.spi.ServiceContext;
import org.apache.tamaya.spi.ConfigurationManagerSingletonSpi;
+ import org.apache.tamaya.spi.ServiceContext;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Proxy;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
/**
* Default SPI that implements the behaviour of {@link org.apache.tamaya.spi.ConfigurationManagerSingletonSpi}.
@@@ -72,34 -93,28 +87,20 @@@ public class DefaultConfigurationManage
}
/**
- * Creates a proxy implementing the given target interface.
*
- * @param config the configuration to be used for providing values.
- * @param type the target interface.
- * @param <T> the target interface type.
- * @return the corresponding implementing proxy, never null.
+ * @param instance the instance with configuration annotations, not null.
+ * @param configurations the configurations to be used for evaluating the values for injection into {@code instance}.
+ * If no items are passed, the default configuration is used.
*/
- private <T> T createAdapterProxy(Configuration config, Class<T> type) {
- ClassLoader cl = Optional.ofNullable(Thread.currentThread()
- .getContextClassLoader()).orElse(getClass().getClassLoader());
- return (T) Proxy.newProxyInstance(cl, new Class[]{type}, new ConfigTemplateInvocationHandler(type, config));
- }
-
@Override
- public void configure(Object instance) {
- ConfigurationInjector.configure(instance);
+ public void configure(Object instance, Configuration... configurations) {
+ ConfigurationInjector.configure(instance, configurations);
}
- private String getConfigId(Annotation... qualifiers) {
- if (qualifiers == null || qualifiers.length == 0) {
- return "";
- }
- StringBuilder b = new StringBuilder();
- for (Annotation annot : qualifiers) {
- b.append('[');
- b.append(annot.annotationType().getName());
- b.append(':');
- b.append(annot.toString());
- b.append(']');
- }
- return b.toString();
- }
@Override
- public String evaluateValue(Configuration config, String expression) {
- return expressionEvaluator.evaluate(expression);
+ public String evaluateValue(String expression, Configuration... configurations) {
+ return expressionEvaluator.evaluate(expression, configurations);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
index ef1ffc6,cf60a52..c384a1d
--- a/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/el/SystemPropertyResolver.java
@@@ -18,14 -18,13 +18,13 @@@
*/
package org.apache.tamaya.core.internal.el;
+ import java.util.Optional;
+
import org.apache.tamaya.ConfigException;
- import org.apache.tamaya.Configuration;
import org.apache.tamaya.core.spi.ExpressionResolver;
- import java.util.*;
-
/**
- * Created by Anatole on 28.09.2014.
+ * Property resolver implementation that interprets the resolver expression as system property name.
*/
public final class SystemPropertyResolver implements ExpressionResolver{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
index 026b4e0,ccc8251..1345625
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
@@@ -31,13 -30,8 +32,13 @@@ public final class ConfigurationInjecto
private static final ConfigurationInjector INSTANCE = new ConfigurationInjector();
- private Map<Class, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
+ 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){
if (!ConfiguredType.isConfigured(type)) {
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/internal/resources/io/ClassUtils.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/internal/resources/io/StringUtils.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/properties/AbstractPropertySource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/properties/PropertySourceBuilder.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/properties/ReplacingPropertySource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/main/java/org/apache/tamaya/core/resource/Resource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --cc core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index d794eff,61785ac..80ec280
--- a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@@ -32,8 -23,19 +23,19 @@@ import static org.junit.Assert.assertEq
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+ import java.util.Map;
+ import java.util.stream.Collectors;
+
+ import org.apache.tamaya.AggregationPolicy;
+ import org.apache.tamaya.Configuration;
+ import org.apache.tamaya.MetaInfo;
+ import org.apache.tamaya.PropertySource;
+ import org.apache.tamaya.core.config.ConfigFunctions;
+ import org.apache.tamaya.core.properties.PropertySourceBuilder;
+ import org.junit.Test;
+
/**
- * Configuration is organized as key/value pairs. This basically can be modeled as {@code Map<String,String>}
+ * Configuration is organized as key/keys pairs. This basically can be modeled as {@code Map<String,String>}
* Configuration should be as simple as possible. A {@code Map<String,String>} instance has methods that may not
* be used in many use cases and/or are not easy to implement. Currently the following functionality
* must be supported:
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f8c91031/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
----------------------------------------------------------------------
diff --cc core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
index ccb4909,73f475f..ba522a7
--- a/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC2CombineProperties.java
@@@ -22,10 -25,8 +25,8 @@@ import org.apache.tamaya.PropertySource
import org.apache.tamaya.core.properties.PropertySourceBuilder;
import org.junit.Test;
- import static junit.framework.TestCase.assertTrue;
-
/**
- * Configuration is organized as key/value pairs. This basically can be modeled as {@code Map<String,String>}
+ * Configuration is organized as key/keys pairs. This basically can be modeled as {@code Map<String,String>}
* Configuration should be as simple as possible. Advanced use cases can often easily implemented by combining
* multiple property maps and applying hereby some combination policy. This test class demonstrates the different
* options Tamaya is providing and the according mechanisms.