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 2016/07/20 00:59:15 UTC
[5/7] incubator-tamaya git commit: - Minimalized API. - Propagated
change to rest of modules.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyConverterManager.java b/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyConverterManager.java
deleted file mode 100644
index 1f975ae..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyConverterManager.java
+++ /dev/null
@@ -1,448 +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.builder.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.builder.internal.converters.EnumConverter;
-import org.apache.tamaya.builder.spi.ConversionContext;
-import org.apache.tamaya.builder.spi.PropertyConverter;
-import org.apache.tamaya.builder.spi.ServiceContextManager;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Manager that deals with {@link PropertyConverter} instances.
- * This class is thread-safe.
- */
-public class PropertyConverterManager {
- /**
- * The logger used.
- */
- private static final Logger LOG = Logger.getLogger(PropertyConverterManager.class.getName());
- /**
- * The registered converters.
- */
- private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
- /**
- * The transitive converters.
- */
- private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>();
- /**
- * The lock used.
- */
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
-
- private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- int prio = DefaultServiceContext.getPriority(o1) - DefaultServiceContext.getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
- };
-
- /**
- * Constructor.
- */
- public PropertyConverterManager() {
- this(true);
- }
-
- public PropertyConverterManager(boolean init) {
- if (init) {
- initConverters();
- }
- }
-
- /**
- * Registers the default converters provided out of the box.
- */
- protected void initConverters() {
- for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
- register(TypeLiteral.of(type), conv);
- }
- }
-
- /**
- * Registers a ew converter instance.
- *
- * @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
- */
- public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
- Objects.requireNonNull(converter);
- Lock writeLock = lock.writeLock();
- try {
- writeLock.lock();
- List converters = List.class.cast(this.converters.get(targetType));
- List<PropertyConverter<?>> newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- // evaluate transitive closure for all inherited supertypes and implemented interfaces
- // direct implemented interfaces
- for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- Class<?> superClass = targetType.getRawType().getSuperclass();
- while (superClass != null && !superClass.equals(Object.class)) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
- for (Class<?> ifaceType : superClass.getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- superClass = superClass.getSuperclass();
- }
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Allows to evaluate if a given target type is supported.
- *
- * @param targetType the target type, not null.
- * @return true, if a converter for the given type is registered, or a default one can be created.
- */
- public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
- return converters.containsKey(targetType) || transitiveConverters.containsKey(targetType) || createDefaultPropertyConverter(targetType) != null;
- }
-
- /**
- * Get a map of all property converters currently registered. This will not contain the converters that
- * may be created, when an instance is adapted, which provides a String constructor or compatible
- * factory methods taking a single String instance.
- *
- * @return the current map of instantiated and registered converters.
- * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
- */
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- Lock readLock = lock.readLock();
- try {
- readLock.lock();
- return new HashMap<>(this.converters);
- } finally {
- readLock.unlock();
- }
- }
-
- /**
- * Get the list of all current registered converters for the given target type.
- * If not converters are registered, they component tries to create and register a dynamic
- * converter based on String costructor or static factory methods available.
- * The converters provided are of the following type and returned in the following order:
- * <ul>
- * <li>Converters mapped explicitly to the required target type are returned first, ordered
- * by decreasing priority. This means, if explicit converters are registered these are used
- * primarly for converting a value.</li>
- * <li>The target type of each explicitly registered converter also can be transitively mapped to
- * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces
- * implemented by its superclasses. These groups of transitive converters is returned similarly in the
- * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li>
- * <li>java.lang wrapper classes and native types are automatically mapped.</li>
- * <li>If no explicit converters are registered, for Enum types a default implementation is provided that
- * compares the configuration values with the different enum members defined (cases sensitive mapping).</li>
- * </ul>
- * <p>
- * So given that list above directly registered mappings always are tried first, before any transitive mapping
- * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place.
- * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and
- * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored.
- *
- * @param targetType the target type, not null.
- * @param <T> the type class
- * @return the ordered list of converters (may be empty for not convertible types).
- * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
- */
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- Lock readLock = lock.readLock();
- List<PropertyConverter<T>> converterList = new ArrayList<>();
- List<PropertyConverter<T>> converters;
- // direct mapped converters
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList);
- } finally {
- readLock.unlock();
- }
- // transitive converter
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.transitiveConverters.get(targetType)), converterList);
- } finally {
- readLock.unlock();
- }
- // handling of java.lang wrapper classes
- TypeLiteral<T> boxedType = mapBoxedType(targetType);
- if (boxedType != null) {
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(boxedType)), converterList);
- } finally {
- readLock.unlock();
- }
- }
- if (converterList.isEmpty()) {
- // adding any converters created on the fly, e.g. for enum types.
- PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if (defaultConverter != null) {
- register(targetType, defaultConverter);
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList);
- } finally {
- readLock.unlock();
- }
- }
- }
- // check for parametrized types, ignoring param type
- // direct mapped converters
- if(targetType.getType()!=null) {
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(
- TypeLiteral.of(targetType.getRawType()))), converterList);
- } finally {
- readLock.unlock();
- }
- }
- return converterList;
- }
-
- private <T> void addConvertersToList(Collection<PropertyConverter<T>> converters, List<PropertyConverter<T>> converterList) {
- if (converters != null) {
- for(PropertyConverter<T> conv:converters) {
- if(!converterList.contains(conv)) {
- converterList.add(conv);
- }
- }
- }
- }
-
- /**
- * Maps native types to the corresponding boxed types.
- *
- * @param targetType the native type.
- * @param <T> the type
- * @return the boxed type, or null.
- */
- private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
- Type parameterType = targetType.getType();
- if (parameterType == int.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Integer.class));
- }
- if (parameterType == short.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Short.class));
- }
- if (parameterType == byte.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Byte.class));
- }
- if (parameterType == long.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Long.class));
- }
- if (parameterType == boolean.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
- }
- if (parameterType == char.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Character.class));
- }
- if (parameterType == float.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Float.class));
- }
- if (parameterType == double.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Double.class));
- }
- if (parameterType == int[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class));
- }
- if (parameterType == short[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Short[].class));
- }
- if (parameterType == byte[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class));
- }
- if (parameterType == long[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
- }
- if (parameterType == boolean.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
- }
- if (parameterType == char[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));
- }
- if (parameterType == float[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Float[].class));
- }
- if (parameterType == double[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Double[].class));
- }
- return null;
- }
-
- /**
- * Creates a dynamic PropertyConverter for the given target type.
- *
- * @param targetType the target type
- * @param <T> the type class
- * @return a new converter, or null.
- */
- protected <T> PropertyConverter<T> createDefaultPropertyConverter(final TypeLiteral<T> targetType) {
- if (Enum.class.isAssignableFrom(targetType.getRawType())) {
- return new EnumConverter<>(targetType.getRawType());
- }
- PropertyConverter<T> converter = null;
- final Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
- if (factoryMethod != null) {
- converter = new DefaultPropertyConverter<>(factoryMethod, targetType.getRawType());
- }
- if (converter == null) {
- final Constructor<T> constr;
- try {
- constr = targetType.getRawType().getDeclaredConstructor(String.class);
- } catch (NoSuchMethodException e) {
- LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e);
- return null;
- }
- converter = new PropertyConverter<T>() {
- @Override
- public T convert(String value, ConversionContext context) {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- constr.setAccessible(true);
- return null;
- }
- });
- return null;
- }
- });
- try {
- return constr.newInstance(value);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e);
- }
- return null;
- }
- };
- }
- return converter;
- }
-
- /**
- * Tries to evaluate a factory method that can be used to create an instance based on a String.
- *
- * @param type the target type
- * @param methodNames the possible static method names
- * @return the first method found, or null.
- */
- private Method getFactoryMethod(Class<?> type, String... methodNames) {
- Method m;
- for (String name : methodNames) {
- try {
- m = type.getDeclaredMethod(name, String.class);
- return m;
- } catch (NoSuchMethodException | RuntimeException e) {
- LOG.finest("No such factory method found on type: " + type.getName() + ", methodName: " + name);
- }
- }
- return null;
- }
-
- private static class DefaultPropertyConverter<T> implements PropertyConverter<T> {
-
- private final Method factoryMethod;
- private final Class<T> targetType;
-
- DefaultPropertyConverter(Method factoryMethod, Class<T> targetType){
- this.factoryMethod = Objects.requireNonNull(factoryMethod);
- this.targetType = Objects.requireNonNull(targetType);
- }
-
- @Override
- public T convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<String -> "+factoryMethod.toGenericString());
-
- if (!Modifier.isStatic(factoryMethod.getModifiers())) {
- throw new ConfigException(factoryMethod.toGenericString() +
- " is not a static method. Only static " +
- "methods can be used as factory methods.");
- }
- try {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- factoryMethod.setAccessible(true);
- return null;
- }
- });
- Object invoke = factoryMethod.invoke(null, value);
- return targetType.cast(invoke);
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + value + "'", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyFiltering.java b/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyFiltering.java
index 75d7ad7..a97cf77 100644
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyFiltering.java
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertyFiltering.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.builder.internal;
-import org.apache.tamaya.builder.spi.ConfigurationContext;
+import org.apache.tamaya.builder.PropertySourceBasedConfiguration;
import org.apache.tamaya.builder.spi.FilterContext;
import org.apache.tamaya.builder.spi.PropertyFilter;
import org.apache.tamaya.builder.spi.PropertySource;
@@ -31,7 +31,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
+ * Implementation of the Configuration API. This class uses the current {@link PropertySourceBasedConfiguration} to evaluate the
* chain of {@link PropertySource} and {@link PropertyFilter}
* instance to evaluate the current Configuration.
*/
@@ -51,7 +51,7 @@ public final class PropertyFiltering{
*/
private PropertyFiltering(){}
- public static String applyFilter(String key, Map<String,String> configData, ConfigurationContext configurationContext) {
+ public static String applyFilter(String key, Map<String,String> configData, PropertySourceBasedConfiguration configurationContext) {
// Apply filters to values, prevent values filtered to null!
String result = configData.get(key);
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
@@ -89,7 +89,7 @@ public final class PropertyFiltering{
return result;
}
- public static Map<String, String> applyFilters(Map<String, String> inputMap, ConfigurationContext configurationContext) {
+ public static Map<String, String> applyFilters(Map<String, String> inputMap, PropertySourceBasedConfiguration configurationContext) {
Map<String, String> resultMap = new HashMap<>(inputMap);
// Apply filters to values, prevent values filtered to null!
Map<String, String> metaData = filterMetadata(inputMap);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertySourceBasedConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertySourceBasedConfigurationAdapter.java b/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertySourceBasedConfigurationAdapter.java
new file mode 100644
index 0000000..d4eecf5
--- /dev/null
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/internal/PropertySourceBasedConfigurationAdapter.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.builder.internal;
+
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.adapter.spi.ConfigurationAdapter;
+import org.apache.tamaya.builder.PropertySourceBasedConfiguration;
+
+/**
+ * Created by atsticks on 19.07.16.
+ */
+public class PropertySourceBasedConfigurationAdapter implements ConfigurationAdapter {
+
+ @Override
+ public <T> T adapt(Configuration configuration, Class<T> targetType) {
+ if(PropertySourceBasedConfiguration.class.equals(targetType)){
+ if(configuration instanceof PropertySourceBasedConfiguration){
+ return (T)configuration;
+ }
+ return (T)new DelegatingPropertySourceBasedConfiguration(configuration);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/package-info.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/package-info.java b/modules/builder/src/main/java/org/apache/tamaya/builder/package-info.java
index 24c86a9..f0509d1 100644
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/package-info.java
+++ b/modules/builder/src/main/java/org/apache/tamaya/builder/package-info.java
@@ -17,12 +17,11 @@
* under the License.
*/
/**
- * This package provides
- * {@link org.apache.tamaya.builder.ConfigurationBuilder a configuration
- * builder} that allows to build a configuration manually without
- * using exclusively on the Service Provider Interface API of Tamaya.
+ * This package provides an adapter and builder for managing configuration
+ * organized as a well ordered list of {@link org.apache.tamaya.builder.spi.PropertySource}
+ * instances.
*
- * @see org.apache.tamaya.builder.ConfigurationBuilder
+ * @see org.apache.tamaya.builder.PropertySourceBasedConfigurationBuilder
* @see org.apache.tamaya.Configuration
*/
package org.apache.tamaya.builder;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContext.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContext.java
deleted file mode 100644
index c206e98..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContext.java
+++ /dev/null
@@ -1,159 +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.builder.spi;
-
-
-import org.apache.tamaya.TypeLiteral;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Central SPI for programmatically dealing with the setup of the configuration system.
- * This includes adding and enlisting {@link PropertySource}s,
- * managing {@link PropertyConverter}s, ConfigFilters, etc.
- */
-public interface ConfigurationContext {
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param propertySourcesToAdd the PropertySources to add
- */
- void addPropertySources(PropertySource... propertySourcesToAdd);
-
- /**
- * This method returns the current list of registered PropertySources ordered via their ordinal.
- * PropertySources with a lower ordinal come last. The PropertySource with the
- * highest ordinal comes first.
- * If two PropertySources have the same ordinal number they will get sorted
- * using their class name just to ensure the user at least gets the same ordering
- * after a JVM restart, hereby names before are added last.
- * PropertySources are loaded when this method is called the first time, which basically is
- * when the first time configuration is accessed.
- *
- * @return a sorted list of registered PropertySources. The returned list need not be modifiable
- */
- List<PropertySource> getPropertySources();
-
-
- /**
- * This method can be used for programmatically adding {@link PropertyConverter}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param <T> the type of the type literal
- * @param typeToConvert the type which the converter is for
- * @param propertyConverter the PropertyConverters to add for this type
- */
- <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter);
-
- /**
- * <p>
- * This method returns the Map of registered PropertyConverters
- * per type.
- * The List for each type is ordered via their {@link javax.annotation.Priority} and
- * cladd name.
- * </p>
- *
- * <p>A simplified scenario could be like:</p>
- * <pre>
- * {
- * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
- * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
- * Integer.class -> {DynamicDefaultConverter}
- * }
- * </pre>
- *
- * @return map with sorted list of registered PropertySources per type.
- */
- Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters();
-
- /**
- * <p>
- * This method returns the registered PropertyConverters for a given type.
- * The List for each type is ordered via their {@link javax.annotation.Priority}.
- * </p>
- *
- * <p>
- * PropertyConverters with a higher Priority come first. The PropertyConverter with the
- * lowest Priority comes last.
- * If two PropertyConverter have the same ordinal number they will get sorted
- * using their class name just to ensure the user at least gets the same ordering
- * after a JVM restart.
- * </p>
- *
- * <p>
- * Additionally if a PropertyProvider is accessed, which is not registered the implementation
- * should try to figure out, if there could be a default implementation as follows:</p>
- * <ol>
- * <li>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String),
- * instanceOf(String), fomr(String)}</li>
- * <li>Look for a matching constructor: {@code T(String)}.</li>
- * </ol>
- *
- * <p>
- * If a correspoding factory method or constructor could be found, a corresponding
- * PropertyConverter should be created and registered automatically for the given
- * type.
- * </p>
- *
- * <p> The scenario could be like:</p>
- *
- * <pre>
- * {
- * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter}
- * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
- * Integer.class -> {DynamicDefaultConverter}
- * }
- * </pre>
- *
- * <p>
- * The converters returned for a type should be used as a chain, whereas the result of the
- * first converter that is able to convert the configured value, is taken as the chain's result.
- * No more converters are called after a converter has successfully converted the input into
- * the required target type.
- * </p>
- *
- * @param <T> the type of the type literal
- * @param type type of the desired converter
- * @return a sorted list of registered PropertySources per type.
- */
- <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type);
-
- /**
- * Access the current PropertyFilter instances.
- * @return the list of registered PropertyFilters, never null.
- */
- List<PropertyFilter> getPropertyFilters();
-
- /**
- * Access the {@link PropertyValueCombinationPolicy} used to evaluate the final
- * property values.
- * @return the {@link PropertyValueCombinationPolicy} used, never null.
- */
- PropertyValueCombinationPolicy getPropertyValueCombinationPolicy();
-
- /**
- * Creates a {@link ConfigurationContextBuilder} preinitialized with the data from this instance.
- * @return a new builder instance, never null.
- */
- ConfigurationContextBuilder toBuilder();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContextBuilder.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContextBuilder.java
deleted file mode 100644
index 5dfda4f..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationContextBuilder.java
+++ /dev/null
@@ -1,174 +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.builder.spi;
-
-import org.apache.tamaya.TypeLiteral;
-
-import java.util.Collection;
-
-/**
- * A builder for creating new or adapting instances of {@link ConfigurationContext}.
- * Builders can be obtained in exactly two ways:
- * <ol>
- * <li>By accessing a preinitialized builder from an existing {@link ConfigurationContext},
- * by calling {@link ConfigurationContext#toBuilder()}.</li>
- * <li>By accessing an empty builder instance from
- * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationContextBuilder()}.</li>
- * </ol>
- * After all changes are applied to a builder a new {@link ConfigurationContext} instance can
- * be created and can be applied by calling
- * {@link org.apache.tamaya.ConfigurationProvider#setConfigurationContext(ConfigurationContext)}.
- *
- */
-
-/* @todo This is some Javadoc which is outdated. I am not sure if I can deleted it. The author
- * should take care. Oliver B. Fischer, 2015-12-23
- * Since this method can
- * throw an UnsupportedOperationException, you should check before if changing the current ConfigurationContext
- * programmatically is supported by calling
- * {@link org.apache.tamaya.ConfigurationProvider#is}.
- */
-public interface ConfigurationContextBuilder {
-
- /**
- * Init this builder instance with the given {@link ConfigurationContext} instance. This
- * method will replace any existing data in the current builder with the data contained in the given
- * {@link ConfigurationContext}.
- *
- * @param context the {@link ConfigurationContext} instance to be used, not null.
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder setContext(ConfigurationContext context);
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param propertySourcesToAdd the PropertySources to add
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder addPropertySources(PropertySource... propertySourcesToAdd);
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param propertySourcesToAdd the PropertySources to add
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder addPropertySources(Collection<PropertySource> propertySourcesToAdd);
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param propertySourcesNames the PropertySource names of the sources to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder removePropertySources(String... propertySourcesNames);
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param propertySourcesNames the PropertySource names of the sources to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder removePropertySources(Collection<String> propertySourcesNames);
-
- /**
- * Adds the given PropertyFilter instances.
- *
- * @param filters the filters to add
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters);
-
- /**
- * Adds the given PropertyFilter instances.
- *
- * @param filters the filters to add
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters);
-
- /**
- * Removes the given PropertyFilter instances.
- *
- * @param filters the filters to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters);
-
- /**
- * Removes the given PropertyFilter instances.
- *
- * @param filters the filters to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters);
-
- /**
- * This method can be used for programmatically adding {@link PropertyConverter}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param <T> the type of the type literal
- * @param typeToConvert the type for which the converter is for
- * @param propertyConverter the PropertyConverters to add for this type
- * @return this builder, for chaining, never null.
- */
- <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T> typeToConvert,
- PropertyConverter<T> propertyConverter);
-
- /**
- * Removes the given PropertyConverter instances.
- *
- * @param typeToConvert the type which the converter is for
- * @param converters the converters to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert,
- PropertyConverter<?>... converters);
-
- /**
- * Removes the given PropertyConverter instances.
- *
- * @param typeToConvert the type which the converter is for
- * @param converters the converters to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert,
- Collection<PropertyConverter<?>> converters);
-
- /**
- * Sets the {@link PropertyValueCombinationPolicy} used to evaluate the final
- * property values.
- *
- * @param policy the {@link PropertyValueCombinationPolicy} used, not null
- * @return this builder, for chaining, never null.
- */
- ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy);
-
- /**
- * Builds a {@link ConfigurationContext} based on the data set.
- * @return final context with the current builder's properties.
- */
- ConfigurationContext build();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationProviderSpi.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationProviderSpi.java
deleted file mode 100644
index 2769d0a..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConfigurationProviderSpi.java
+++ /dev/null
@@ -1,76 +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.builder.spi;
-
-import org.apache.tamaya.Configuration;
-
-/**
- * SPI that must be implemented to provide the component that manages all {@link org.apache.tamaya.Configuration}
- * instances in a system. In SE this may be a true singleton containing exact one {@link org.apache.tamaya.Configuration}
- * instance, whereas in Java EE and other more complex environments instances may be returned depending the current
- * runtime context.
- */
-public interface ConfigurationProviderSpi {
-
- /**
- * Access the current {@link org.apache.tamaya.Configuration}.
- *
- * @return the current {@link org.apache.tamaya.Configuration} instance, never null.
- */
- Configuration getConfiguration();
-
- /**
- * Get access to the current {@link ConfigurationContext}.
- *
- * @return the current {@link ConfigurationContext}, never null.
- * @deprecated Will be removed in favour of {@link Configuration#getContext()}.
- */
- @Deprecated
- ConfigurationContext getConfigurationContext();
-
- /**
- * This method allows to replace the current {@link ConfigurationContext} with a new
- * instance. This can be used to update the context with a new one, e.g. because some of the configuration
- * data has changed and must be updated. It is the responsibility of the ConfigurationProvider to trigger
- * corresponding update event for the current {@link ConfigurationContext} or
- * {@link org.apache.tamaya.Configuration}.
- *
- * @param context the new ConfigurationContext to be applied.
- * @throws java.lang.UnsupportedOperationException if the current provider is read-only.
- */
- void setConfigurationContext(ConfigurationContext context);
-
- /**
- * Method that allows to determine if a new {@link ConfigurationContext} can be applied
- * programmatically.
- *
- * @return true, if {@link #setConfigurationContext(ConfigurationContext)} is supported
- * by the current implementation.
- * @see #setConfigurationContext(ConfigurationContext)
- */
- boolean isConfigurationContextSettable();
-
- /**
- * Creates a new {@link ConfigurationContextBuilder} instance.
- *
- * @return a new {@link ConfigurationContextBuilder}, never null.
- */
- ConfigurationContextBuilder getConfigurationContextBuilder();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConversionContext.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConversionContext.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConversionContext.java
deleted file mode 100644
index 298e8bc..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ConversionContext.java
+++ /dev/null
@@ -1,255 +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.builder.spi;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-
-import java.lang.reflect.AnnotatedElement;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-
-/**
- * A conversion context containing all the required values for implementing conversion. Use the included #Builder
- * for creating new instances of. This class is thread-safe to use. Adding supported formats is synchronized.
- * @see PropertyConverter
- */
-public class ConversionContext {
-
- private final Configuration configuration;
- private final String key;
- private final TypeLiteral<?> targetType;
- private final AnnotatedElement annotatedElement;
- private final List<String> supportedFormats = new ArrayList<>();
- private final ConfigurationContext configurationContext;
-
- /**
- * Private constructor used from builder.
- * @param builder the builder, not null.
- */
- protected ConversionContext(Builder builder){
- this.key = builder.key;
- this.annotatedElement = builder.annotatedElement;
- this.targetType = builder.targetType;
- this.supportedFormats.addAll(builder.supportedFormats);
- this.configuration = builder.configuration;
- this.configurationContext = builder.configurationContext;
- }
-
- /**
- * Get the key accessed. This information is very useful to evaluate additional metadata needed to determine/
- * control further aspects of the conversion.
- * @return the key. This may be null in case where a default value has to be converted and no unique underlying
- * key/value configuration is present.
- */
- public String getKey(){
- return key;
- }
-
- /**
- * Get the target type required.
- * @return the target type required.
- */
- public TypeLiteral<?> getTargetType(){
- return targetType;
- }
-
- /**
- * Get the annotated element, if conversion is performed using injection mechanisms.
- * @return the annotated element, or null.
- */
- public AnnotatedElement getAnnotatedElement(){
- return annotatedElement;
- }
-
- /**
- * Get the configuration, which is targeted.
- * @return the configuration instance, or null.
- */
- public Configuration getConfiguration(){
- return configuration;
- }
-
- /**
- * Allows to add information on the supported/tried formats, which can be shown to the user, especially when
- * conversion failed. Adding of formats is synchronized, all formats are added in order to the overall list.
- * This means formats should be passed in order of precedence.
- * @param converterType the converter, which implements the formats provided.
- * @param formatDescriptors the format descriptions in a human readable form, e.g. as regular expressions.
- */
- public void addSupportedFormats(Class<? extends PropertyConverter> converterType, String... formatDescriptors){
- synchronized (supportedFormats){
- for(String format: formatDescriptors) {
- supportedFormats.add(format + " (" + converterType.getSimpleName() + ")");
- }
- }
- }
-
- /**
- * Get the supported/tried formats in precedence order. The contents of this method depends on the
- * {@link PropertyConverter} instances involved in a conversion.
- * @return the supported/tried formats, never null.
- */
- public List<String> getSupportedFormats(){
- synchronized (supportedFormats){
- return new ArrayList<>(supportedFormats);
- }
- }
-
- @Override
- public String toString() {
- return "ConversionContext{" +
- "configuration=" + configuration +
- ", key='" + key + '\'' +
- ", targetType=" + targetType +
- ", annotatedElement=" + annotatedElement +
- ", supportedFormats=" + supportedFormats +
- '}';
- }
-
- public ConfigurationContext getConfigurationContext() {
- return configurationContext;
- }
-
- /**
- * Builder to create new instances of {@link ConversionContext}.
- */
- public static final class Builder{
- /** The backing configuration. */
- private Configuration configuration;
- /** The configuration context. */
- private ConfigurationContext configurationContext;
- /** The accessed key, or null. */
- private String key;
- /** The target type. */
- private final TypeLiteral<?> targetType;
- /** The injection target (only set with injection used). */
- private AnnotatedElement annotatedElement;
- /** The ordered list of formats tried. */
- private final Set<String> supportedFormats = new HashSet<>();
-
- /**
- * Creates a new Builder instance.
- * @param targetType the target type
- */
- public Builder(TypeLiteral<?> targetType) {
- this(null, null, null, targetType);
- }
-
- /**
- * Creates a new Builder instance.
- * @param key the requested key, may be null.
- * @param targetType the target type
- */
- public Builder(String key, TypeLiteral<?> targetType) {
- this(null, null, key, targetType);
- }
-
- /**
- * Creates a new Builder instance.
- * @param configuration the configuration, not null.
- * @param configurationContext configuration context, not null.
- * @param key the requested key, may be null.
- * @param targetType the target type
- */
- public Builder(Configuration configuration, ConfigurationContext configurationContext, String key, TypeLiteral<?> targetType){
- this.key = key;
- this.configuration = configuration;
- this.configurationContext = configurationContext;
- this.targetType = Objects.requireNonNull(targetType);
- }
-
- /**
- * Sets the key.
- * @param key the key, not null.
- * @return the builder instance, for chaining
- */
- public Builder setKey(String key){
- this.key = Objects.requireNonNull(key);
- return this;
- }
-
- /**
- * Sets the configuration.
- * @param configuration the configuration, not null
- * @return the builder instance, for chaining
- */
- public Builder setConfiguration(Configuration configuration){
- this.configuration = Objects.requireNonNull(configuration);
- return this;
- }
-
- /**
- * Sets the configuration.
- * @param configurationContext the configuration, not null
- * @return the builder instance, for chaining
- */
- public Builder setConfigurationContext(ConfigurationContext configurationContext){
- this.configurationContext = Objects.requireNonNull(configurationContext);
- return this;
- }
-
- /**
- * Sets the annotated element, when configuration is injected.
- * @param annotatedElement the annotated element, not null
- * @return the builder instance, for chaining
- */
- public Builder setAnnotatedElement(AnnotatedElement annotatedElement){
- this.annotatedElement = Objects.requireNonNull(annotatedElement);
- return this;
- }
-
- /**
- * Add the formats provided by a {@link PropertyConverter}. This method should be called by each converter
- * performing/trying conversion, so the user can be given feedback on the supported formats on failure.
- * @param converterType the converter type, not null.
- * @param formatDescriptors the formats supported in a human readable form, e.g. as regular expressions.
- * @return the builder instance, for chaining
- */
- public Builder addSupportedFormats(Class<? extends PropertyConverter> converterType, String... formatDescriptors){
- for(String format: formatDescriptors) {
- supportedFormats.add(format + " (" + converterType.getSimpleName() + ")");
- }
- return this;
- }
-
- /**
- * Builds a new context instance.
- * @return a new context, never null.
- */
- public ConversionContext build(){
- return new ConversionContext(this);
- }
-
- @Override
- public String toString() {
- return "Builder{" +
- "configuration=" + configuration +
- "context=" + configurationContext +
- ", key='" + key + '\'' +
- ", targetType=" + targetType +
- ", annotatedElement=" + annotatedElement +
- ", supportedFormats=" + supportedFormats +
- '}';
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/PropertyConverter.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/PropertyConverter.java
deleted file mode 100644
index 83f6644..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/PropertyConverter.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.builder.spi;
-
-
-/**
- * Interface for an property that converts a configured String into something else.
- * This is used for implementing type conversion from a property (String) to a certain target
- * type. Hereby the target type can be multivalued (e.g. collections) or complex if needed.
- *
- * @param <T> the type of the type literal
- */
-public interface PropertyConverter<T>{
-
- /**
- * Convert the given configuration keys from its String representation into the required target type.
- * The context instance passed also allows to add a list of supported formats, which is very handy in case a
- * value could not be converted. This list of supported formats can then shown to the user to give some hints
- * how a value could be configured.
- *
- * @param value configuration key that needs to be converted
- * @param context the {@link ConversionContext}, containing the String value and the requested configuration key.
- * @return converted keys
- * @see ConversionContext#addSupportedFormats(Class, String...)
- */
- T convert(String value, ConversionContext context);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContext.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContext.java
deleted file mode 100644
index 9fbfce8..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContext.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.builder.spi;
-
-import java.util.List;
-
-
-/**
- * This class models the component that is managing the lifecycle current the
- * services used by the Configuration API.
- */
-public interface ServiceContext {
-
- /**
- * @return ordinal of the ServiceContext. The one with the highest ordinal will be taken.
- */
- int ordinal();
-
- /**
- * Access a service singleton via its type.
- * If multiple implementations for the very serviceType exist then
- * the one with the highest {@link javax.annotation.Priority} will be used.
- *
- * @param <T> the type of the service type.
- * @param serviceType the service type.
- * @return The instance to be used, or {@code null}
- * @throws org.apache.tamaya.ConfigException if there are multiple service implementations with the maximum priority.
- */
- <T> T getService(Class<T> serviceType);
-
- /**
- * Access a list current services, given its type. The bootstrap mechanism should
- * order the instance for precedence, hereby the most significant should be
- * first in order.
- *
- * @param serviceType
- * the service type.
- * @param <T> the type of the list element returned by this method
- * @return The instance to be used, never {@code null}
- */
- <T> List<T> getServices(Class<T> serviceType);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7144e3f9/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContextManager.java b/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContextManager.java
deleted file mode 100644
index 3d0e136..0000000
--- a/modules/builder/src/main/java/org/apache/tamaya/builder/spi/ServiceContextManager.java
+++ /dev/null
@@ -1,118 +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.builder.spi;
-
-import java.util.Objects;
-import java.util.ServiceLoader;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigException;
-
-
-/**
- * This singleton provides access to the services available in the current {@link ServiceContext}. The
- * behaviour can be adapted, by calling {@link ServiceContextManager#set(ServiceContext)} before accessing any
- * services.
- */
-public final class ServiceContextManager {
-
- /** The logger used. */
- private static final Logger LOG = Logger.getLogger(ServiceContextManager.class.getName());
-
- /**
- * The ServiceProvider used.
- */
- private static volatile ServiceContext serviceContextProviderDelegate;
-
- /**
- * Private singletons constructor.
- */
- private ServiceContextManager() {
- }
-
- /**
- * Load the {@link ServiceContext} to be used.
- *
- * @return {@link ServiceContext} to be used for loading the services.
- */
- private static ServiceContext loadDefaultServiceProvider() {
- ServiceContext highestServiceContext = null;
- try {
- int highestOrdinal = 0;
- for (ServiceContext serviceContext : ServiceLoader.load(ServiceContext.class)) {
- if(highestServiceContext==null){
- highestServiceContext = serviceContext;
- }else if (serviceContext.ordinal() > highestOrdinal) {
- highestServiceContext = serviceContext;
- highestOrdinal = serviceContext.ordinal();
- }
- }
- } catch (Exception e) {
- throw new ConfigException("ServiceContext not loadable", e);
- }
- if (highestServiceContext==null){
- throw new ConfigException("No ServiceContext found");
- }
- LOG.info("Using Service Context of type: " + highestServiceContext.getClass().getName());
- return highestServiceContext;
- }
-
- /**
- * Replace the current {@link ServiceContext} in use.
- *
- * @param serviceContextProvider the new {@link ServiceContext}, not null.
- * @return the currently used context after setting it.
- */
- public static ServiceContext set(ServiceContext serviceContextProvider) {
- ServiceContext currentContext = ServiceContextManager.serviceContextProviderDelegate;
- Objects.requireNonNull(serviceContextProvider);
-
- synchronized (ServiceContextManager.class) {
- if (ServiceContextManager.serviceContextProviderDelegate == null) {
- ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
- LOG.log(Level.INFO, "Using ServiceProvider: " + serviceContextProvider.getClass().getName());
- } else {
- LOG.log(Level.WARNING, "Replacing ServiceProvider " +
- ServiceContextManager.serviceContextProviderDelegate.getClass().getName() +
- " with: " + serviceContextProvider.getClass().getName());
- ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
- }
- }
-
- return currentContext;
- }
-
- /**
- * Ge {@link ServiceContext}. If necessary the {@link ServiceContext} will be laziliy loaded.
- *
- * @return the {@link ServiceContext} used.
- */
- public static ServiceContext getServiceContext() {
- if (serviceContextProviderDelegate == null) {
- synchronized (ServiceContextManager.class) {
- if (serviceContextProviderDelegate == null) {
- serviceContextProviderDelegate = loadDefaultServiceProvider();
- }
- }
- }
- return serviceContextProviderDelegate;
- }
-
-}