You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by st...@apache.org on 2015/01/07 23:21:41 UTC
[8/9] incubator-tamaya git commit: TAMAYA-49 ipmlement java7 api as
well
TAMAYA-49 ipmlement java7 api as well
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/67855faa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/67855faa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/67855faa
Branch: refs/heads/master
Commit: 67855faa5e8f18bcccf11cb05f0d055949598208
Parents: 328a4ac
Author: Mark Struberg <st...@apache.org>
Authored: Tue Jan 6 22:19:11 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jan 7 23:17:58 2015 +0100
----------------------------------------------------------------------
README.md | 15 ++
java7/api/pom.xml | 43 ++++++
.../java/org/apache/tamaya/ConfigException.java | 44 ++++++
.../java/org/apache/tamaya/Configuration.java | 72 ++++++++++
.../apache/tamaya/ConfigurationProvider.java | 32 +++++
.../apache/tamaya/spi/ConfigurationContext.java | 140 +++++++++++++++++++
.../apache/tamaya/spi/PropertyConverter.java | 41 ++++++
.../org/apache/tamaya/spi/PropertyFilter.java | 49 +++++++
.../org/apache/tamaya/spi/PropertySource.java | 125 +++++++++++++++++
.../tamaya/spi/PropertySourceProvider.java | 43 ++++++
.../org/apache/tamaya/spi/ServiceContext.java | 57 ++++++++
.../tamaya/spi/ServiceContextManager.java | 109 +++++++++++++++
.../org/apache/tamaya/ConfigurationTest.java | 64 +++++++++
.../org/apache/tamaya/TestConfiguration.java | 86 ++++++++++++
.../apache/tamaya/spi/ServiceContextTest.java | 95 +++++++++++++
.../apache/tamaya/spi/TestServiceContext.java | 89 ++++++++++++
.../services/org.apache.tamaya.Configuration | 19 +++
.../org.apache.tamaya.spi.ServiceContext | 1 +
java7/pom.xml | 68 +++++++++
.../java/org/apache/tamaya/Configuration.java | 54 +++++--
.../apache/tamaya/ConfigurationProvider.java | 34 +++++
.../org/apache/tamaya/spi/PropertyFilter.java | 2 +-
.../org/apache/tamaya/spi/PropertySource.java | 5 +-
.../tamaya/spi/ServiceContextManager.java | 2 +-
.../org/apache/tamaya/TestConfiguration.java | 6 +-
.../core/internal/DefaultConfiguration.java | 14 +-
.../core/propertysource/BasePropertySource.java | 13 +-
.../apache/tamaya/core/ConfigurationTest.java | 22 +--
.../propertysource/BasePropertySourceTest.java | 7 +-
.../PropertiesFilePropertySourceTest.java | 8 +-
.../SystemPropertySourceTest.java | 7 +-
.../provider/JavaConfigurationProviderTest.java | 4 +-
.../testdata/TestPropertyFilterRemoving.java | 3 +-
.../apache/tamaya/format/PropertiesFormat.java | 5 +-
.../tamaya/format/PropertiesXmlFormat.java | 5 +-
.../tamaya/modules/json/JSONPropertySource.java | 5 +-
.../tamaya/resolver/MyTestPropertySource.java | 5 +-
pom.xml | 1 +
toolchains.xml | 27 ++++
39 files changed, 1345 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d23963e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+Building Apache Tamaya (incubating)
+
+
+
+The Apache Tamaya project contains classes which are intended to be built with Java7 and others
+which are for Java8. This means you need to have both JDK-1.7 and JDK-1.8 installed on your computer.
+
+To tell maven which JDK it should use for each of the projects we do leverage the
+maven-toolchains-plugin and Mavens toolchains support.
+
+See the following links for more information
+http://maven.apache.org/ref/3.2.5/maven-core/toolchains.html
+http://maven.apache.org/guides/mini/guide-using-toolchains.html
+
+Please copy the provided toolchains.xml sample to ~.m2/toolchains.xml
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/pom.xml
----------------------------------------------------------------------
diff --git a/java7/api/pom.xml b/java7/api/pom.xml
new file mode 100644
index 0000000..3dbfa4c
--- /dev/null
+++ b/java7/api/pom.xml
@@ -0,0 +1,43 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-java7-api</artifactId>
+ <description>
+ The API defines a complete Java7 based API for reading of configuration data.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/ConfigException.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/ConfigException.java b/java7/api/src/main/java/org/apache/tamaya/ConfigException.java
new file mode 100644
index 0000000..bac2ef4
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/ConfigException.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;
+
+/**
+ * Exception class (runtime exception) for configuration issues.
+ */
+public class ConfigException extends RuntimeException{
+
+ private static final long serialVersionUID = -5886094818057522680L;
+
+ /**
+ * Creates a new configuration exception.
+ * @param message the exception message, not null.
+ */
+ public ConfigException(String message){
+ super(message);
+ }
+
+ /**
+ * Creates a new configuration exception.
+ * @param message the exception message, not null.
+ * @param t the throwable.
+ */
+ public ConfigException(String message, Throwable t){
+ super(message, t);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/Configuration.java b/java7/api/src/main/java/org/apache/tamaya/Configuration.java
new file mode 100644
index 0000000..291fb78
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import java.util.Map;
+
+
+/**
+ * A configuration models a aggregated set current properties, identified by a unique key, but adds higher level access functions to
+ * a {@link org.apache.tamaya.spi.PropertySource}. Hereby in most cases a configuration is a wrapper around a composite
+ * {@link org.apache.tamaya.spi.PropertySource} instance, which may combine multiple child config in well defined tree like structure,
+ * where nodes define logically the rules current priority, filtering, combination and overriding.
+ * <br/>
+ * <h3>Implementation Requirements</h3>
+ * Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.
+ * <li>Immutable
+ * </ul>
+ * It is not recommended that implementations also are serializable, since the any configuration can be <i>freezed</i>
+ * by reading out its complete configuration map into a serializable and remotable structure. This helps significantly
+ * simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current
+ * this library at all.
+ */
+public interface Configuration {
+
+ /**
+ * Access a property.
+ *
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ String get(String key);
+
+ /**
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * org.apache.tamaya.spi.PropertyConverter} 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 value, never null..
+ * @throws ConfigException if the keys could not be converted to the required target type.
+ */
+ <T> T get(String key, Class<T> type);
+
+ /**
+ * Access all current known Configuration properties as a full {@code Map<String,String>}.
+ * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
+ * instances may not be contained in the result, but nevertheless be accessible calling one of the
+ * {@code get(...)} methods.
+ */
+ Map<String,String> getProperties();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
new file mode 100644
index 0000000..1293f49
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya;
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Static access to the {@link Configuration} for the very application.
+ */
+public final class ConfigurationProvider {
+ private ConfigurationProvider() {
+ // just to prevent initialisation
+ }
+
+ public static Configuration getConfiguration() {
+ return ServiceContextManager.getServiceContext().getService(Configuration.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
new file mode 100644
index 0000000..efad465
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -0,0 +1,140 @@
+/*
+ * 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 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 org.apache.tamaya.spi.PropertySource}s,
+ * managing {@link org.apache.tamaya.spi.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 typeToConvert the type which the converter is for
+ * @param propertyConverter the PropertyConverters to add for this type
+ */
+ <T> void addPropertyConverter(Class<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. Refer also to {@link #getPropertyConverters()}.
+ * </p>
+ * <p>
+ * A simplified scenario could be like:
+ * <pre>
+ * {
+ * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * @return map with sorted list of registered PropertySources per type.
+ */
+ Map<Class<?>, 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:
+ * <ol>
+ * <le>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String),
+ * instanceOf(String), fomr(String)}</le>
+ * <le>Look for a matching constructor: {@code T(String)}.</le>
+ * </ol>
+ * 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:
+ * <pre>
+ * {
+ * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter}
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * <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>
+ *
+ * @return a sorted list of registered PropertySources per type.
+ */
+ <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> type);
+
+ /**
+ * Access the current PropertyFilter instances.
+ * @return the list of registered PropertyFilters, never null.
+ */
+ List<PropertyFilter> getPropertyFilters();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
new file mode 100644
index 0000000..167e0a8
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.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.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 (eg collections) or complex if needed.
+ */
+public interface PropertyConverter<T>{
+
+ /**
+ * Convert the given configuration keys from it' String representation into the required target type.
+ * @param value the configuration keys
+ * @return converted keys
+ */
+ T convert(String value);
+
+ //X TODO probably add some diagnostic info which explains what kind of
+ //X format(s) is supported.
+ //X This could be useful if e.g. no converter in the chain felt responsible
+ //X because a wrongly formatted configuration string had been used.
+ //X This could probably also be handled via an additional Annotation on the converter.
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
new file mode 100644
index 0000000..55f4295
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+
+/**
+ * <p>Interface for filtering the current map of properties during the evaluation of the chain of PropertySources.
+ * Filters can be registered using the {@link org.apache.tamaya.spi.ServiceContext}. The ordinal
+ * hereby is defined by the corresponding {@code @Priority} annotation.</p>
+ * <p>Filters </p>
+ */
+public interface PropertyFilter {
+
+ /**
+ * <p>Maps the current {@code valueToBeFiltered} value to a new value. The resulting value will be used as the result
+ * passed to the user.</p>
+ * <p>If a filter is currently not available, it should just pass the input map to the method's
+ * output.</p>
+ * <p>Returning {@code null} will remove the entry.</p>
+ * <h3>Implementation specification</h3>
+ * Implementations of this class must be
+ * <ul>
+ * <li>reentrant</li>
+ * <li>thread-safe</li>
+ * </ul>
+ *
+ * @param key the key accessed, not null.
+ * @param valueToBeFiltered the value to be filtered, not null.
+ * @return the filtered value, or {@code null} if the value should be removed alltogether.
+ */
+ String filterProperty(String key, String valueToBeFiltered);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
new file mode 100644
index 0000000..4457919
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -0,0 +1,125 @@
+/*
+* 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 java.util.Map;
+
+
+/**
+ * This interface models a provider that serves configuration properties. The contained
+ * properties may be read fromMap single or several sources (composite).<br/>
+ * PropertySources are the building blocks of the final configuration.
+ * <p/>
+ * <h3>Implementation Requirements</h3>
+ * <p></p>Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * <p>A PropertySourceProvider will get picked up via the
+ * {@link java.util.ServiceLoader} mechanism and can be registered via
+ * META-INF/services/org.apache.tamaya.spi.PropertySource
+ * </p>
+ * <p>
+ * If you like to register multiple PropertySources at the same time
+ * you can use the {@link org.apache.tamaya.spi.PropertySourceProvider}
+ * interface.
+ * </p>
+ */
+public interface PropertySource {
+
+ /**
+ * property name to override default tamaya ordinals
+ */
+ static final String TAMAYA_ORDINAL = "tamaya.ordinal";
+
+
+ /**
+ * Lookup order:
+ * TODO rethink whole default PropertySources and ordering:
+ * TODO introduce default values or constants for ordinals
+ * <ol>
+ * <li>System properties (ordinal 400)</li>
+ * <li>Environment properties (ordinal 300)</li>
+ * <li>JNDI values (ordinal 200)</li>
+ * <li>Properties file values (/META-INF/applicationConfiguration.properties) (ordinal 100)</li>
+ * </ol>
+ * <p/>
+ * <p><b>Important Hints for custom implementations</b>:</p>
+ * <p>
+ * If a custom implementation should be invoked <b>before</b> the default implementations, use a value > 400
+ * </p>
+ * <p>
+ * If a custom implementation should be invoked <b>after</b> the default implementations, use a value < 100
+ * </p>
+ * <p/>
+ * <p>Reordering of the default order of the config-sources:</p>
+ * <p>Example: If the properties file/s should be used <b>before</b> the other implementations,
+ * you have to configure an ordinal > 400. That means, you have to add e.g. deltaspike_ordinal=401 to
+ * /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
+ * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
+ *
+ * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
+ * //X TODO think about making this a default method which returns default priority
+ */
+ int getOrdinal();
+
+
+ /**
+ * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
+ * to ensure unique identity, either locally or remotely.
+ * @return the configuration's name, never null.
+ */
+ String getName();
+
+ /**
+ * Access a property.
+ *
+ * //X TODO discuss if the key can be null
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ String get(String key);
+
+ /**
+ * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
+ * when the underlying storage does not support iteration of its entries.
+ *
+ * @return the a corresponding map, never null.
+ * //X TODO or should we just do getPropertyKeys()? Think about security (key) vs easier merging (full map)?
+ */
+ Map<String,String> getProperties();
+
+ /**
+ * Determines if this config source could be scanned for its list of properties.
+ *
+ * <p>
+ * PropertySources which are not scannable might not be able to find all the
+ * configured values to provide via {@link #getProperties()}. This can e.g. happen
+ * if the underlying storage doesn't support listing.
+ * </p>
+ *
+ * @return {@code true} if this PropertySource could be scanned for its list of properties,
+ * {@code false} if it should not be scanned.
+ */
+ boolean isScannable();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
new file mode 100644
index 0000000..42e3b4d
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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 java.util.Collection;
+
+/**
+ * <p>Implement this interfaces to provide a PropertySource provider which
+ * is able to register multiple PropertySources. This is e.g. needed if
+ * there are multiple property files of a given config file name.</p>
+ *
+ * <p>If a PropertySource like JNDI only exists once, then there is no need
+ * to implement it via the PropertySourceProvider but should directly
+ * expose a {@link PropertySource}.</p>
+ *
+ * <p>A PropertySourceProvider will get picked up via the
+ * {@link java.util.ServiceLoader} mechanism and must get registered via
+ * META-INF/services/org.apache.tamaya.spi.PropertySourceProvider</p>
+ */
+public interface PropertySourceProvider {
+
+ /**
+ * @return For each e.g. property file, we return a single PropertySource
+ * or an empty list if no PropertySource exists.
+ */
+ Collection<PropertySource> getPropertySources();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
new file mode 100644
index 0000000..ad73575
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.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 serviceType the service type.
+ * @return The instance to be used, never {@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.
+ * @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/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
new file mode 100644
index 0000000..11648a4
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
@@ -0,0 +1,109 @@
+/*
+ * 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 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 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 (serviceContext.ordinal() > highestOrdinal) {
+ highestServiceContext = serviceContext;
+ }
+ }
+ } catch (Exception e) {
+ throw new ConfigException("ServiceContext not loadable", e);
+ }
+ if(highestServiceContext==null){
+ throw new ConfigException("No ServiceContext found");
+ }
+ return highestServiceContext;
+ }
+
+ /**
+ * Replace the current {@link ServiceContext} in use.
+ *
+ * @param serviceContextProvider the new {@link ServiceContext}, not null.
+ */
+ public static ServiceContext set(ServiceContext serviceContextProvider) {
+ ServiceContext currentContext = ServiceContextManager.serviceContextProviderDelegate;
+ Objects.requireNonNull(serviceContextProvider);
+ synchronized (ServiceContextManager.class) {
+ if (ServiceContextManager.serviceContextProviderDelegate == null) {
+ ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
+ Logger.getLogger(ServiceContextManager.class.getName())
+ .log(Level.INFO, "Using ServiceProvider: " + serviceContextProvider.getClass().getName());
+ } else {
+ Logger.getLogger(ServiceContextManager.class.getName())
+ .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;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
new file mode 100644
index 0000000..11a16b9
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test class that tests the default methods implemented on {@link org.apache.tamaya.Configuration}. The provided
+ * {@link org.apache.tamaya.TestConfiguration} is implemeted with maximal use of the default methods.
+ */
+public class ConfigurationTest {
+
+ @Test
+ public void testget() throws Exception {
+ assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().get("booleanTrue", Boolean.class));
+ assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().get("booleanFalse", Boolean.class));
+ assertEquals((int)Byte.MAX_VALUE, (int)ConfigurationProvider.getConfiguration().get("byte", Byte.class));
+ assertEquals((int)Integer.MAX_VALUE, (int)ConfigurationProvider.getConfiguration().get("int", Integer.class));
+ assertEquals((long)Long.MAX_VALUE, (long)ConfigurationProvider.getConfiguration().get("long", Long.class));
+ assertEquals((double)Float.MAX_VALUE, (double)ConfigurationProvider.getConfiguration().get("float", Float.class), 0.0d);
+ assertEquals((double)Double.MAX_VALUE, (double)ConfigurationProvider.getConfiguration().get("double", Double.class), 0.0d);
+ }
+
+ @Test
+ public void testGetBoolean() throws Exception {
+ assertTrue(ConfigurationProvider.getConfiguration().get("booleanTrue", Boolean.class));
+ assertFalse(ConfigurationProvider.getConfiguration().get("booleanFalse", Boolean.class));
+ assertFalse(ConfigurationProvider.getConfiguration().get("foorBar", Boolean.class));
+ }
+
+ @Test
+ public void testGetInteger() throws Exception {
+ assertEquals(Integer.MAX_VALUE,(int) ConfigurationProvider.getConfiguration().get("int", Integer.class));
+ }
+
+ @Test
+ public void testGetLong() throws Exception {
+ assertEquals(Long.MAX_VALUE,(long) ConfigurationProvider.getConfiguration().get("long", Long.class));
+ }
+
+ @Test
+ public void testGetDouble() throws Exception {
+ assertEquals(Double.MAX_VALUE,(double) ConfigurationProvider.getConfiguration().get("double", Double.class), 0.0d);
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
new file mode 100644
index 0000000..863bd93
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test Configuration class, that is used to testdata the default methods provided by the API.
+ */
+public class TestConfiguration implements Configuration{
+
+ private static final Map<String, String> VALUES;
+ static {
+ VALUES = new HashMap<String, String>();
+ VALUES.put("long", String.valueOf(Long.MAX_VALUE));
+ VALUES.put("int", String.valueOf(Integer.MAX_VALUE));
+ VALUES.put("double", String.valueOf(Double.MAX_VALUE));
+ VALUES.put("float", String.valueOf(Float.MAX_VALUE));
+ VALUES.put("short", String.valueOf(Short.MAX_VALUE));
+ VALUES.put("byte", String.valueOf(Byte.MAX_VALUE));
+ VALUES.put("booleanTrue", "true");
+ VALUES.put("booleanFalse", "false");
+ VALUES.put("String", "aStringValue");
+ }
+
+ @Override
+ public String get(String key) {
+ return VALUES.get(key);
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ if(type.equals(Long.class)){
+ return (T)(Object)Long.MAX_VALUE;
+ }
+ else if(type.equals(Integer.class)){
+ return (T)(Object) Integer.MAX_VALUE;
+ }
+ else if(type.equals(Double.class)){
+ return (T)(Object) Double.MAX_VALUE;
+ }
+ else if(type.equals(Float.class)){
+ return (T)(Object) Float.MAX_VALUE;
+ }
+ else if(type.equals(Short.class)){
+ return (T)(Object) Short.MAX_VALUE;
+ }
+ else if(type.equals(Byte.class)){
+ return (T)(Object) Byte.MAX_VALUE;
+ }
+ else if(type.equals(Boolean.class)){
+ if("booleanTrue".equals(key)) {
+ return (T)(Object) Boolean.TRUE;
+ }
+ else{
+ return (T)(Object) Boolean.FALSE;
+ }
+ }
+ else if(type.equals(String.class)){
+ return (T)(Object) "aStringValue";
+ }
+ throw new ConfigException("No such property: " + key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
new file mode 100644
index 0000000..0269c4c
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+public class ServiceContextTest {
+
+ private ServiceContext serviceContext = new ServiceContext(){
+
+ @Override
+ public int ordinal() {
+ return 1;
+ }
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ if(String.class.equals(serviceType)){
+ return serviceType.cast("ServiceContextTest");
+ }
+ return null;
+ }
+
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ if(String.class.equals(serviceType)){
+ List<String> list = new ArrayList<>();
+ list.add("ServiceContextTest");
+ return List.class.cast(list);
+ }
+ return Collections.EMPTY_LIST;
+ }
+ };
+
+ @Test
+ public void testOrdinal() throws Exception {
+ assertEquals(1, serviceContext.ordinal());
+ }
+
+ @Test
+ public void testgetService() throws Exception {
+ assertEquals("ServiceContextTest", serviceContext.getService(String.class));
+ assertNull(serviceContext.getService(Integer.class));
+ }
+
+ @Test
+ public void testGetService() throws Exception {
+ String service = serviceContext.getService(String.class);
+ assertNotNull(service);
+ assertEquals("ServiceContextTest", service);
+ Integer intService = serviceContext.getService(Integer.class);
+ assertNull(intService);
+ }
+
+ @Test
+ public void testGetServices() throws Exception {
+ Collection<String> services = serviceContext.getServices(String.class);
+ assertNotNull(services);
+ assertFalse(services.isEmpty());
+ assertEquals("ServiceContextTest", services.iterator().next());
+ Collection<Integer> intServices = serviceContext.getServices(Integer.class);
+ assertNotNull(intServices);
+ assertTrue(intServices.isEmpty());
+ }
+
+ @Test
+ public void testGetInstance() throws Exception {
+ assertNotNull(ServiceContextManager.getServiceContext());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
new file mode 100644
index 0000000..8790945
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
+ * {@link java.util.ServiceLoader} to load the services required.
+ */
+public final class TestServiceContext implements ServiceContext {
+ /** List current services loaded, per class. */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+
+ private final Map<Class, Object> singletons = new ConcurrentHashMap<>();
+
+ @Override
+ public int ordinal() {
+ return 1;
+ }
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ T cached = (T) singletons.get(serviceType);
+ if(cached==null) {
+ List<? extends T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = (T) Object.class; // as marker for 'nothing here'
+ }
+ else{
+ cached = services.get(0);
+ }
+ singletons.put((Class)serviceType, cached);
+ }
+ if (cached == Object.class) {
+ cached = null;
+ }
+ return cached;
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
+ *
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ try {
+ List<T> services = new ArrayList<>();
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ services = Collections.unmodifiableList(services);
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
+ return previousServices != null ? previousServices : services;
+ } catch (Exception e) {
+ Logger.getLogger(TestServiceContext.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ return Collections.EMPTY_LIST;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..1f42438
--- /dev/null
+++ b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
@@ -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.TestConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..0f7abe9
--- /dev/null
+++ b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1 @@
+org.apache.tamaya.spi.TestServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/pom.xml
----------------------------------------------------------------------
diff --git a/java7/pom.xml b/java7/pom.xml
new file mode 100644
index 0000000..df137c2
--- /dev/null
+++ b/java7/pom.xml
@@ -0,0 +1,68 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-all</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-java7</artifactId>
+ <packaging>pom</packaging>
+
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
+ <modules>
+ <module>api</module>
+<!--
+ <module>core</module>
+-->
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <!-- use java7 to compile the modules in this tree -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <version>[1.7,)</version>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
index 2786af7..d5bd4f7 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -48,17 +48,34 @@ public interface Configuration {
* Access a property.
*
* @param key the property's key, not null.
- * @return the property's keys.
+ * @return the property's value or {@code null}.
*/
- Optional<String> get(String key);
+ default String get(String key) {
+ return getOptional(key).orElse(null);
+ }
/**
- * Access all current known Configuration properties as a full {@code Map<String,String>}.
- * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
- * instances may not be contained in the result, but nevertheless be accessible calling one of the
- * {@code get(...)} methods.
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * org.apache.tamaya.spi.PropertyConverter} 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 value, never null..
+ * @throws ConfigException if the keys could not be converted to the required target type.
*/
- Map<String,String> getProperties();
+ default <T> T get(String key, Class<T> type) {
+ return getOptional(key, type).orElse(null);
+ }
+
+ /**
+ * Access a property.
+ *
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ Optional<String> getOptional(String key);
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -69,10 +86,17 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
* @return the property value, never null..
- * @throws ConfigException if the keys could not be converted to the required target
- * type.
+ * @throws ConfigException if the keys could not be converted to the required target type.
*/
- <T> Optional<T> get(String key, Class<T> type);
+ <T> Optional<T> getOptional(String key, Class<T> type);
+
+ /**
+ * Access all current known Configuration properties as a full {@code Map<String,String>}.
+ * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
+ * instances may not be contained in the result, but nevertheless be accessible calling one of the
+ * {@code get(...)} methods.
+ */
+ Map<String,String> getProperties();
/**
* Get the property keys as type {@code Class<T>}.
@@ -92,7 +116,7 @@ public interface Configuration {
* type, or no such property exists.
*/
default <T> Optional<T> get(String key, PropertyConverter<T> converter) {
- Optional<String> value = get(key);
+ Optional<String> value = getOptional(key);
if (value.isPresent()) {
return Optional.ofNullable(converter.convert(value.get()));
}
@@ -109,7 +133,7 @@ public interface Configuration {
* @throws ConfigException if the configured value could not be converted to the target type.
*/
default Boolean getBoolean(String key) {
- Optional<Boolean> val = get(key, Boolean.class);
+ Optional<Boolean> val = getOptional(key, Boolean.class);
if (val.isPresent()) {
return val.get();
}
@@ -125,7 +149,7 @@ public interface Configuration {
* @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalInt getInteger(String key) {
- Optional<Integer> val = get(key, Integer.class);
+ Optional<Integer> val = getOptional(key, Integer.class);
if (val.isPresent()){
return OptionalInt.of(val.get());
}
@@ -142,7 +166,7 @@ public interface Configuration {
* @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalLong getLong(String key) {
- Optional<Long> val = get(key, Long.class);
+ Optional<Long> val = getOptional(key, Long.class);
if (val.isPresent()){
return OptionalLong.of(val.get());
}
@@ -160,7 +184,7 @@ public interface Configuration {
*/
default OptionalDouble getDouble(String key) {
- Optional<Double> val = get(key, Double.class);
+ Optional<Double> val = getOptional(key, Double.class);
if (val.isPresent()){
return OptionalDouble.of(val.get());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
new file mode 100644
index 0000000..199e686
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya;
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Static access to the {@link org.apache.tamaya.Configuration} for the very application.
+ *
+ * Exists for Java7 backward compatibility
+ */
+public final class ConfigurationProvider {
+ private ConfigurationProvider() {
+ // just to prevent initialisation
+ }
+
+ public static Configuration getConfiguration() {
+ return ServiceContextManager.getServiceContext().getService(Configuration.class).get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
index 50a03dd..d106e70 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -42,7 +42,7 @@ public interface PropertyFilter{
*
* @param key the key accessed, not null.
* @param valueToBeFiltered the value to be filtered, not null.
- * @return the filtered map, never null.
+ * @return the filtered value, or {@code null} if the value should be removed alltogether.
*/
String filterProperty(String key, String valueToBeFiltered);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index ae80159..350759e 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.spi;
import java.util.Map;
-import java.util.Optional;
/**
@@ -96,9 +95,9 @@ public interface PropertySource {
*
* //X TODO discuss if the key can be null
* @param key the property's key, not null.
- * @return the property's keys.
+ * @return the value assigned to the property or {@code null}. An empty String will kind of 'erase' previous values.
*/
- Optional<String> get(String key);
+ String get(String key);
/**
* Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
index 68e7552..11648a4 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
@@ -31,7 +31,7 @@ import org.apache.tamaya.ConfigException;
* behaviour can be adapted, by calling {@link ServiceContextManager#set(ServiceContext)} before accessing any
* services.
*/
-final class ServiceContextManager {
+public final class ServiceContextManager {
/**
* The ServiceProvider used.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index cdcb0e9..459cb9f 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -25,7 +25,7 @@ import java.util.Optional;
/**
* Test Configuration class, that is used to testdata the default methods provided by the API.
*/
-public class TestConfiguration implements Configuration{
+public class TestConfiguration implements Configuration {
private static final Map<String, String> VALUES;
static {
@@ -42,12 +42,12 @@ public class TestConfiguration implements Configuration{
}
@Override
- public Optional<String> get(String key) {
+ public Optional<String> getOptional(String key) {
return Optional.ofNullable(VALUES.get(key));
}
@Override
- public <T> Optional<T> get(String key, Class<T> type) {
+ public <T> Optional<T> getOptional(String key, Class<T> type) {
if(type.equals(Long.class)){
return Optional.class.cast(Optional.ofNullable(Long.MAX_VALUE));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index ec23e25..a0bf190 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -68,13 +68,13 @@ public class DefaultConfiguration implements Configuration {
* @return the optional configuration value, never null.
*/
@Override
- public Optional<String> get(String key) {
+ public Optional<String> getOptional(String key) {
List<PropertySource> propertySources = configurationContext.getPropertySources();
String unfilteredValue = null;
for (PropertySource propertySource : propertySources) {
- Optional<String> value = propertySource.get(key);
- if (value.isPresent()) {
- unfilteredValue = value.get();
+ String value = propertySource.get(key);
+ if (value != null) {
+ unfilteredValue = value.length() > 0 ? value : null;
break;
}
}
@@ -193,7 +193,7 @@ public class DefaultConfiguration implements Configuration {
}
/**
- * Accesses the current String value for the given key (see {@link #get(String)}) and tries to convert it
+ * Accesses the current String value for the given key (see {@link #getOptional(String)}) and tries to convert it
* using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
* {@link org.apache.tamaya.spi.ConfigurationContext}.
*
@@ -204,8 +204,8 @@ public class DefaultConfiguration implements Configuration {
* @return the converted value, never null.
*/
@Override
- public <T> Optional<T> get(String key, Class<T> type) {
- Optional<String> value = get(key);
+ public <T> Optional<T> getOptional(String key, Class<T> type) {
+ Optional<String> value = getOptional(key);
if (value.isPresent()) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
for (PropertyConverter<T> converter : converters) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
index e58be54..7fe3a46 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.core.propertysource;
import org.apache.tamaya.spi.PropertySource;
import java.util.Objects;
-import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -45,9 +44,9 @@ public abstract class BasePropertySource implements PropertySource {
@Override
- public Optional<String> get(String key) {
+ public String get(String key) {
Objects.requireNonNull(key, "key must not be null");
- return Optional.ofNullable(getProperties().get(key));
+ return getProperties().get(key);
}
@@ -62,15 +61,15 @@ public abstract class BasePropertySource implements PropertySource {
protected void initializeOrdinal(final int defaultOrdinal) {
this.ordinal = defaultOrdinal;
- Optional<String> ordinal = get(PropertySource.TAMAYA_ORDINAL);
- if (ordinal.isPresent()) {
+ String ordinal = get(PropertySource.TAMAYA_ORDINAL);
+ if (ordinal != null) {
try {
- this.ordinal = Integer.valueOf(ordinal.get());
+ this.ordinal = Integer.valueOf(ordinal);
} catch (NumberFormatException e) {
LOG.log(Level.WARNING,
"Specified {0} is not a valid Integer value: {1} - using defaultOrdinal {2}",
- new Object[]{PropertySource.TAMAYA_ORDINAL, ordinal.get(), defaultOrdinal});
+ new Object[]{PropertySource.TAMAYA_ORDINAL, ordinal, defaultOrdinal});
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
index 5a6fc70..c2ddbf8 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -37,17 +37,17 @@ public class ConfigurationTest {
@Test
public void testContent(){
- assertEquals("Robin", Configuration.current().get("name").get());
- assertEquals("Sabine", Configuration.current().get("name2").get()); // from default
- assertEquals("Mapped to name: Robin", Configuration.current().get("name3").get()); // oderridden default, mapped by filter to name property
- assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", Configuration.current().get("name4").get()); // final only
- assertNull(Configuration.current().get("name5").orElse(null)); // final only, but removed from filter
-
- System.out.println("name : " + Configuration.current().get("name").get());
- System.out.println("name2: " + Configuration.current().get("name2").get());
- System.out.println("name3: " + Configuration.current().get("name3").get());
- System.out.println("name4: " + Configuration.current().get("name4").get());
- System.out.println("name5: " + Configuration.current().get("name5").orElse(null));
+ assertEquals("Robin", Configuration.current().getOptional("name").get());
+ assertEquals("Sabine", Configuration.current().getOptional("name2").get()); // from default
+ assertEquals("Mapped to name: Robin", Configuration.current().getOptional("name3").get()); // oderridden default, mapped by filter to name property
+ assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", Configuration.current().getOptional("name4").get()); // final only
+ assertNull(Configuration.current().getOptional("name5").orElse(null)); // final only, but removed from filter
+
+ System.out.println("name : " + Configuration.current().getOptional("name").get());
+ System.out.println("name2: " + Configuration.current().getOptional("name2").get());
+ System.out.println("name3: " + Configuration.current().getOptional("name3").get());
+ System.out.println("name4: " + Configuration.current().getOptional("name4").get());
+ System.out.println("name5: " + Configuration.current().getOptional("name5").orElse(null));
System.out.println("ALL :");
Configuration.current().getProperties().entrySet().forEach(e ->
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
index d6dc867..1a6a33c 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
@@ -27,7 +27,6 @@ import org.junit.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
public class BasePropertySourceTest {
@@ -42,8 +41,8 @@ public class BasePropertySourceTest {
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(null);
+ public String get(String key) {
+ return null;
}
@Override
@@ -61,7 +60,7 @@ public class BasePropertySourceTest {
@Test
public void testGet() {
- Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL).get());
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
}
private static class OverriddenOrdinalPropertySource extends BasePropertySource {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
index 6a1c9e7..6ad7790 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
@@ -46,15 +46,15 @@ public class PropertiesFilePropertySourceTest {
@Test
public void testGetOrdinal() {
Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
- Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL).get()), overrideOrdinalPropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
}
@Test
public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3").get());
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get());
- Assert.assertFalse(testfilePropertySource.get("nonpresentkey").isPresent());
+ Assert.assertEquals("val3", testfilePropertySource.get("key3"));
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
index a7712db..5495595 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
@@ -25,7 +25,6 @@ import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
-import java.util.Optional;
import java.util.Properties;
public class SystemPropertySourceTest {
@@ -56,10 +55,10 @@ public class SystemPropertySourceTest {
public void testGet() throws Exception {
String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
- Optional<String> property = testPropertySource.get(propertyKeyToCheck);
+ String property = testPropertySource.get(propertyKeyToCheck);
Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
- property.isPresent());
- Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.get());
+ property != null);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
index 5c5fefc..ae9dccb 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
@@ -41,11 +41,11 @@ public class JavaConfigurationProviderTest {
String key = "confkey" + i;
String value = "javaconf-value" + i;
- Assert.assertEquals(value, propertySource.get(key).get());
+ Assert.assertEquals(value, propertySource.get(key));
// check if we had our key in configuration.current
Assert.assertTrue(Configuration.current().getProperties().containsKey(key));
- Assert.assertEquals(value, Configuration.current().get(key).get());
+ Assert.assertEquals(value, Configuration.current().getOptional(key).get());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
index 0244d6a..4667ca6 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.PropertyFilter;
import javax.annotation.Priority;
-import java.util.function.Function;
/**
* Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
@@ -35,7 +34,7 @@ public class TestPropertyFilterRemoving implements PropertyFilter{
return null;
}
else if("name3".equals(key)){
- return "Mapped to name: " + Configuration.current().get("name").orElse("NoName found!");
+ return "Mapped to name: " + Configuration.current().getOptional("name").orElse("NoName found!");
}
return valueToBeFiltered;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
index 6412e77..34c9e21 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.logging.Level;
@@ -90,8 +89,8 @@ public class PropertiesFormat implements ConfigurationFormat {
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(p.getProperty(key));
+ public String get(String key) {
+ return p.getProperty(key);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
index 1de9145..8b3468b 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.logging.Level;
@@ -91,8 +90,8 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(p.getProperty(key));
+ public String get(String key) {
+ return p.getProperty(key);
}
@Override