You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/01/24 21:06:31 UTC
[1/9] incubator-tamaya git commit: TAMAYA-61: Added Interface for
value combination.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 43acbddb5 -> 4929d3cd2
TAMAYA-61: Added Interface for value combination.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b60af86e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b60af86e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b60af86e
Branch: refs/heads/master
Commit: b60af86e36d94abb4afd7b889f99a914d1bdcda5
Parents: 43acbdd
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 11:09:52 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:13 2015 +0100
----------------------------------------------------------------------
.../src/main/resources/checkstyle/style.xml | 2 +-
.../resources/findbugs/findbugs-exclude.xml | 7 ++-
.../spi/PropertyValueCombinationPolicy.java | 63 ++++++++++++++++++++
.../spi/PropertyValueCombinationPolicy.java | 59 ++++++++++++++++++
4 files changed, 128 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b60af86e/buildconfigurations/src/main/resources/checkstyle/style.xml
----------------------------------------------------------------------
diff --git a/buildconfigurations/src/main/resources/checkstyle/style.xml b/buildconfigurations/src/main/resources/checkstyle/style.xml
index b96b02c..5a43f94 100644
--- a/buildconfigurations/src/main/resources/checkstyle/style.xml
+++ b/buildconfigurations/src/main/resources/checkstyle/style.xml
@@ -41,7 +41,7 @@ under the License.
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<!-- module name="JavadocMethod"/ -->
- <!-- module name="JavadocType"/ -->
+ <module name="JavadocType"/>
<!-- module name="JavadocVariable"/ -->
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b60af86e/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
index 50d545c..0ad63f2 100644
--- a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
+++ b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
@@ -79,13 +79,16 @@ under the License.
</Match>
+ <!-- False positive returnin null for Boolean is required by the implemented interface. -->
+ <Match>
+ <Class name="org.apache.tamaya.core.internal.converters.BooleanConverter"/>
+ </Match>
+
<!-- Issues to review -->
<Match>
<Class name="org.apache.tamaya.core.internal.PropertiesFileLoader"/>
</Match>
-
-
<Match>
<Class name="org.apache.tamaya.resolver.internal.URLResolver" />
</Match>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b60af86e/java7/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
new file mode 100644
index 0000000..dbda457
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+/**
+ * Policy that determines how the final value of a configuration entry is evaluated. An instances of this
+ * interface can be registered to get control how multiple PropertySources are combined. This is useful in cases
+ * where the default overriding policy as implemented in {@link #DEFAULT_OVERRIDING_COLLECTOR} is not matching
+ * the need of the current application, e.g. then entries containing multiple values should be combined to new
+ * values instead of overridden.
+ */
+public interface PropertyValueCombinationPolicy {
+
+ /**
+ * Default overriding collector, where each existing entry ({@code current} is overridden by a subsequent non-null
+ * entry evaluated by {@code propertySource.get(key)}.
+ */
+ public static final PropertyValueCombinationPolicy DEFAULT_OVERRIDING_COLLECTOR = new PropertyValueCombinationPolicy(){
+
+ @Override
+ public String collect(String currentValue, String key, PropertySource propertySource) {
+ String value = propertySource.get(key);
+ return value!=null?value:currentValue;
+ }
+
+ };
+
+ /**
+ * Method that is called for each value evaluated by a PropertySource for the given key. This method is called
+ * either when a single key is accessed, e.g. by calling {@code org.apache.tamaya.Configuration.getXXX}, but also
+ * when the full configuration property map is accessed by calling
+ * {@link org.apache.tamaya.Configuration#getProperties()}.
+ *
+ * @param currentValue the current value, including null.
+ * The collector should either combine the existing value with value from {@code currentValue}
+ * or replace the value in {@code currentValue} with {@code valueRead}, hereby returning the
+ * result to be used as new {@code currentValue}.
+ * @param key The current key to be evaluated.
+ * @param propertySource The PropertySource that may return an value for the given key. The PropertySource given
+ * may be evaluated for additional meta-data, how the given values are to be combined.
+ * Note that the value returned by a PropertySource can be null. In that case
+ * {@code currentValue} should be returned in almost all cases.
+ * @return the value to be used for future evaluation.
+ */
+ String collect(String currentValue, String key, PropertySource propertySource);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b60af86e/java8/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
new file mode 100644
index 0000000..660cc11
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyValueCombinationPolicy.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import java.util.Optional;
+
+/**
+ * Policy that determines how the final value of a configuration entry is evaluated. An instances of this
+ * interface can be registered to get control how multiple PropertySources are combined. This is useful in cases
+ * where the default overriding policy as implemented in {@link #DEFAULT_OVERRIDING_COLLECTOR} is not matching
+ * the need of the current application, e.g. then entries containing multiple values should be combined to new
+ * values instead of overridden.
+ */
+@FunctionalInterface
+public interface PropertyValueCombinationPolicy {
+
+ /**
+ * Default overriding collector, where each existing entry ({@code current} is overridden by a subsequent non-null
+ * entry evaluated by {@code propertySource.get(key)}.
+ */
+ public final PropertyValueCombinationPolicy DEFAULT_OVERRIDING_COLLECTOR = (current, key, propertySource) ->
+ Optional.ofNullable(propertySource.get(key)).orElse(current);
+
+ /**
+ * Method that is called for each value evaluated by a PropertySource for the given key. This method is called
+ * either when a single key is accessed, e.g. by calling {@code org.apache.tamaya.Configuration.getXXX}, but also
+ * when the full configuration property map is accessed by calling
+ * {@link org.apache.tamaya.Configuration#getProperties()}.
+ *
+ * @param currentValue the current value, including null.
+ * The collector should either combine the existing value with value from {@code currentValue}
+ * or replace the value in {@code currentValue} with {@code valueRead}, hereby returning the
+ * result to be used as new {@code currentValue}.
+ * @param key The current key to be evaluated.
+ * @param propertySource The PropertySource that may return an value for the given key. The PropertySource given
+ * may be evaluated for additional meta-data, how the given values are to be combined.
+ * Note that the value returned by a PropertySource can be null. In that case
+ * {@code currentValue} should be returned in almost all cases.
+ * @return the value to be used for future evaluation.
+ */
+ String collect(String currentValue, String key, PropertySource propertySource);
+
+}
[7/9] incubator-tamaya git commit: TAMAYA-63: Bugfixes and alignment
with latest Java 8 version.
Posted by an...@apache.org.
TAMAYA-63: Bugfixes and alignment with latest Java 8 version.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a8c1a9c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a8c1a9c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a8c1a9c0
Branch: refs/heads/master
Commit: a8c1a9c0840c928a5fe74fcfb8d8bbb89a748e4b
Parents: bc62f71
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 19:40:32 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:17 2015 +0100
----------------------------------------------------------------------
.../apache/tamaya/ConfigurationProvider.java | 31 +++++++++++++-
.../tamaya/spi/ConfigurationProviderSpi.java | 45 ++++++++++++++++++++
.../tamaya/TestConfigurationProvider.java | 41 ++++++++++++++++++
.../services/org.apache.tamaya.Configuration | 19 ---------
...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +++++++++
.../core/internal/DefaultConfiguration.java | 11 ++++-
.../internal/DefaultConfigurationProvider.java | 45 ++++++++++++++++++++
.../org.apache.tamaya.spi.ConfigurationContext | 19 ---------
...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +++++++++
.../apache/tamaya/core/ConfigurationTest.java | 3 +-
.../internal/DefaultServiceContextTest.java | 8 ++--
11 files changed, 215 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/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
index 1293f49..69045b5 100644
--- a/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
+++ b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -16,17 +16,46 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
import org.apache.tamaya.spi.ServiceContextManager;
/**
* Static access to the {@link Configuration} for the very application.
*/
public final class ConfigurationProvider {
+
+ private static final ConfigurationProviderSpi PROVIDER_SPI = loadSpi();
+
+ private static ConfigurationProviderSpi loadSpi() {
+ ConfigurationProviderSpi spi = ServiceContextManager.getServiceContext()
+ .getService(ConfigurationProviderSpi.class);
+ if(spi==null){
+ throw new IllegalStateException("ConfigurationProviderSpi not available.");
+ }
+ return spi;
+ }
+
private ConfigurationProvider() {
// just to prevent initialisation
}
+ /**
+ * Access the current configuration.
+ *
+ * @return the corresponding Configuration instance, never null.
+ */
public static Configuration getConfiguration() {
- return ServiceContextManager.getServiceContext().getService(Configuration.class);
+ return PROVIDER_SPI.getConfiguration();
}
+
+ /**
+ * Get access to the current ConfigurationContext.
+ *
+ * @return the current ConfigurationContext, never null.
+ */
+ public static ConfigurationContext getConfigurationContext(){
+ return PROVIDER_SPI.getConfigurationContext();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
new file mode 100644
index 0000000..3e96abd
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.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.
+ */
+ ConfigurationContext getConfigurationContext();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
new file mode 100644
index 0000000..7c356c8
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.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;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+
+/**
+ * Test Configuration class, that is used to testdata the default methods provided by the API.
+ */
+public class TestConfigurationProvider implements ConfigurationProviderSpi {
+
+ private static final Configuration config = new TestConfiguration();
+
+
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/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
deleted file mode 100644
index 1f42438..0000000
--- a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..b9c5ba5
--- /dev/null
+++ b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -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.TestConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 720efe0..4215a73 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -55,7 +56,15 @@ public class DefaultConfiguration implements Configuration {
/**
* The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
*/
- private final ConfigurationContext configurationContext = ServiceContextManager.getServiceContext().getService(ConfigurationContext.class);
+ private final ConfigurationContext configurationContext;
+
+ /**
+ * Constructor.
+ * @param configurationContext The configuration Context to be used.
+ */
+ public DefaultConfiguration(ConfigurationContext configurationContext){
+ this.configurationContext = Objects.requireNonNull(configurationContext);
+ }
/**
* This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
new file mode 100644
index 0000000..c06755d
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+
+/**
+ * Implementation of the Configuration API. This class uses the current {@link org.apache.tamaya.spi.ConfigurationContext} to evaluate the
+ * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
+
+ private ConfigurationContext context = new DefaultConfigurationContext();
+ private Configuration config = new DefaultConfiguration(context);
+
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return context;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
deleted file mode 100644
index 2f0f44e..0000000
--- a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.DefaultConfigurationContext
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..7c0e249
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
index 4c0e813..0eb2181 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.core;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.core.internal.DefaultConfiguration;
import org.apache.tamaya.spi.ServiceContext;
import org.apache.tamaya.spi.ServiceContextManager;
@@ -42,7 +43,7 @@ public class ConfigurationTest {
}
private Configuration current() {
- return ServiceContextManager.getServiceContext().getService(Configuration.class);
+ return ConfigurationProvider.getConfiguration();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a8c1a9c0/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
index 4f4079a..795c80f 100644
--- a/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.core.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
import org.junit.Assert;
import org.junit.Test;
@@ -37,10 +38,9 @@ public class DefaultServiceContextTest {
@Test
public void testGetService() {
- ConfigurationContext configurationContext = context.getService(ConfigurationContext.class);
-
- Assert.assertNotNull(configurationContext);
- Assert.assertTrue(configurationContext instanceof DefaultConfigurationContext);
+ ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
+ Assert.assertNotNull(providerSpi);
+ Assert.assertTrue(providerSpi instanceof DefaultConfigurationProvider);
}
@Test(expected = ConfigException.class)
[4/9] incubator-tamaya git commit: TAMAYA-63: Implemented backport
for Java 7.
Posted by an...@apache.org.
TAMAYA-63: Implemented backport for Java 7.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ffffdc8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ffffdc8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ffffdc8e
Branch: refs/heads/master
Commit: ffffdc8eb7df1b0a9d30286cbd312437017efd1f
Parents: b9735e0
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 11:17:05 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:15 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/TypeLiteral.java | 137 +++++++++++++++++++
.../services/org.apache.tamaya.Configuration | 19 +++
2 files changed, 156 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffffdc8e/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
new file mode 100644
index 0000000..32c32a6
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -0,0 +1,137 @@
+/*
+* 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.io.Serializable;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+
+/**
+ * <p>Class for instantiation of objects that represent parameterized types
+ * with current parameters.</p>
+ * <p>
+ * <p>An object that represents a parameterized type may be obtained by
+ * subclassing <tt>TypeLiteral</tt>.</p>
+ * <p>
+ * <pre>
+ * TypeLiteral<List<Integer>> stringListType = new TypeLiteral<List<Integer>>() {};
+ * </pre>
+ *
+ * @param <T> the type, including all type parameters
+ */
+public class TypeLiteral<T> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private Type type;
+
+ protected TypeLiteral(Type type) {
+ this.type = type;
+ }
+
+ protected TypeLiteral() { }
+
+ public static <T> TypeLiteral<T> of(Type type){
+ return new TypeLiteral<>(type);
+ }
+
+ private static Class<?> getTypeLiteralSubclass(Class<?> clazz) {
+ Class<?> superclass = clazz.getSuperclass();
+ if (superclass.equals(TypeLiteral.class)) {
+ return clazz;
+ } else if (superclass.equals(Object.class)) {
+ return null;
+ } else {
+ return (getTypeLiteralSubclass(superclass));
+ }
+ }
+
+ private static Type getTypeParameter(Class<?> superclass) {
+ Type type = superclass.getGenericSuperclass();
+ if (type instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ if (parameterizedType.getActualTypeArguments().length == 1) {
+ return parameterizedType.getActualTypeArguments()[0];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the actual type represented by this object
+ */
+ public final Type getType() {
+ if (type == null) {
+ Class<?> typeLiteralSubclass = getTypeLiteralSubclass(this.getClass());
+ if (typeLiteralSubclass == null) {
+ throw new RuntimeException(getClass() + " is not a subclass of TypeLiteral");
+ }
+ type = getTypeParameter(typeLiteralSubclass);
+ if (type == null) {
+ throw new RuntimeException(getClass() + " does not specify the type parameter T of TypeLiteral<T>");
+ }
+ }
+ return type;
+ }
+
+ /**
+ * @return the raw type represented by this object
+ */
+ @SuppressWarnings("unchecked")
+ public final Class<T> getRawType() {
+ Type type = getType();
+ if (type instanceof Class) {
+ return (Class<T>) type;
+ } else if (type instanceof ParameterizedType) {
+ return (Class<T>) ((ParameterizedType) type).getRawType();
+ } else if (type instanceof GenericArrayType) {
+ return (Class<T>) Object[].class;
+ } else {
+ throw new RuntimeException("Illegal type");
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o){
+ return true;
+ }
+ if (!(o instanceof TypeLiteral)){
+ return false;
+ }
+ TypeLiteral that = (TypeLiteral) o;
+ if (type != null ? !type.equals(that.type) : that.type != null){
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type != null ? type.hashCode() : 0;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "TypeLiteral{" +
+ "type=" + type +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ffffdc8e/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..e51a247
--- /dev/null
+++ b/java7/core/src/main/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.core.internal.DefaultConfiguration
[3/9] incubator-tamaya git commit: TAMAYA-62: Unified Configuration
access. Fixed some FindBugs and checkstyle issues.
Posted by an...@apache.org.
TAMAYA-62: Unified Configuration access.
Fixed some FindBugs and checkstyle issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b9735e02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b9735e02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b9735e02
Branch: refs/heads/master
Commit: b9735e025ba331f4c4cd011fa4e0c5eb2b898e32
Parents: b60af86
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 11:13:51 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:14 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/ConfigQuery.java | 1 +
.../java/org/apache/tamaya/Configuration.java | 67 ++++-----
.../apache/tamaya/ConfigurationProvider.java | 25 ++--
.../org/apache/tamaya/PropertyConverter.java | 49 +++++++
.../java/org/apache/tamaya/TypeLiteral.java | 137 +++++++++++++++++++
.../apache/tamaya/spi/ConfigurationContext.java | 21 ++-
.../tamaya/spi/ConfigurationProviderSpi.java | 45 ++++++
.../apache/tamaya/spi/PropertyConverter.java | 48 -------
.../org/apache/tamaya/spi/PropertySource.java | 2 +-
.../org/apache/tamaya/ConfigurationTest.java | 34 ++---
.../org/apache/tamaya/TestConfiguration.java | 21 +--
.../tamaya/TestConfigurationProvider.java | 44 ++++++
.../services/org.apache.tamaya.Configuration | 19 ---
...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +++
.../core/internal/DefaultConfiguration.java | 17 ++-
.../internal/DefaultConfigurationContext.java | 11 +-
.../internal/DefaultConfigurationProvider.java | 44 ++++++
.../core/internal/PropertiesFileLoader.java | 3 +
.../core/internal/PropertyConverterManager.java | 35 ++---
.../converters/BigDecimalConverter.java | 2 +-
.../converters/BigIntegerConverter.java | 2 +-
.../internal/converters/BooleanConverter.java | 2 +-
.../core/internal/converters/ByteConverter.java | 2 +-
.../core/internal/converters/CharConverter.java | 2 +-
.../internal/converters/CurrencyConverter.java | 2 +-
.../internal/converters/DoubleConverter.java | 2 +-
.../core/internal/converters/EnumConverter.java | 3 +-
.../internal/converters/FloatConverter.java | 2 +-
.../internal/converters/IntegerConverter.java | 2 +-
.../internal/converters/LocalDateConverter.java | 2 +-
.../converters/LocalDateTimeConverter.java | 2 +-
.../internal/converters/LocalTimeConverter.java | 2 +-
.../core/internal/converters/LongConverter.java | 2 +-
.../internal/converters/NumberConverter.java | 2 +-
.../internal/converters/ShortConverter.java | 2 +-
.../internal/converters/ZoneIdConverter.java | 2 +-
.../org.apache.tamaya.PropertyConverter | 34 +++++
...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +++
.../apache/tamaya/core/ConfigurationTest.java | 28 ++--
.../converters/BooleanConverterTest.java | 4 +-
.../internal/converters/ByteConverterTest.java | 3 +-
.../provider/JavaConfigurationProviderTest.java | 6 +-
.../testdata/TestPropertyFilterRemoving.java | 4 +-
.../tamaya/inject/WithPropertyConverter.java | 2 +-
.../ConfigTemplateInvocationHandler.java | 3 +-
.../tamaya/inject/internal/ConfiguredField.java | 3 +-
.../inject/internal/ConfiguredSetterMethod.java | 3 +-
.../tamaya/inject/internal/InjectionUtils.java | 20 +--
.../resolver/internal/ConfigResolver.java | 3 +-
49 files changed, 572 insertions(+), 237 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/main/java/org/apache/tamaya/ConfigQuery.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/ConfigQuery.java b/java8/api/src/main/java/org/apache/tamaya/ConfigQuery.java
index 140ccba..6151d03 100644
--- a/java8/api/src/main/java/org/apache/tamaya/ConfigQuery.java
+++ b/java8/api/src/main/java/org/apache/tamaya/ConfigQuery.java
@@ -22,6 +22,7 @@ package org.apache.tamaya;
* Models a function that maps a given {@link org.apache.tamaya.Configuration} to something else. This can be used
* to model additional functionality and applying it to a given {@link org.apache.tamaya.Configuration} instance by
* calling the {@link org.apache.tamaya.Configuration#query(org.apache.tamaya.ConfigQuery)} method.
+ * @param <T> the result type of the query.
*/
@FunctionalInterface
public interface ConfigQuery<T> {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 ed1f918..4ee7f21 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -18,14 +18,11 @@
*/
package org.apache.tamaya;
-import org.apache.tamaya.spi.ServiceContext;
-
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
-import java.util.function.Function;
/**
@@ -48,52 +45,34 @@ import java.util.function.Function;
public interface Configuration {
/**
- * Access a configuration.
+ * Access a property.
*
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
+ * @param key the property's key, not null.
+ * @return the property's value or {@code null}.
*/
- public static Configuration current() {
- return ServiceContext.getInstance().getService(Configuration.class).get();
+ default String get(String key) {
+ return get(key, String.class);
}
+
/**
- * Access a property.
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * PropertyConverter} to be available that is capable current providing type T
+ * fromMap the given String keys.
*
- * @param key the property's key, not null.
- * @return the property's value or {@code null}.
+ * @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.
*/
- 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 getListProperty(String key, TypeLiteral<T> type);
-//
-// /**
-// * 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 converter the converter to be used.
-// * @return the property value, never null..
-// * @throws ConfigException if the keys could not be converted to the required target type.
-// */
-// <T> T getListProperty(String key, Function<List<String>, T> converter);
+ default <T> T get(String key, Class<T> type) {
+ return get(key, TypeLiteral.of(type));
+ }
/**
* 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
+ * 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
@@ -102,7 +81,7 @@ public interface Configuration {
* @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);
+ <T> T get(String key, TypeLiteral<T> type);
/**
* Access a property.
@@ -116,7 +95,7 @@ public interface Configuration {
/**
* 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
+ * 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
@@ -135,6 +114,7 @@ public interface Configuration {
* instances may not be contained in the result, but nevertheless be accessible calling one of the
* {@code get(...)} methods.
*/
+ @SuppressWarnings("JavaDoc")
Map<String, String> getProperties();
/**
@@ -154,14 +134,15 @@ public interface Configuration {
* @throws ConfigException if the keys could not be converted to the required target
* type, or no such property exists.
*/
- default <T> Optional<T> getOptional(String key, Function<String, T> converter) {
+ default <T> Optional<T> getOptional(String key, PropertyConverter<T> converter) {
Optional<String> value = getOptional(key);
if (value.isPresent()) {
- return Optional.ofNullable(converter.apply(value.get()));
+ return Optional.ofNullable(converter.convert(value.get()));
}
return Optional.empty();
}
+
/**
* Get the property keys as {@link Boolean}.
*
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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
index 7a64caa..183786c 100644
--- a/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
+++ b/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -16,17 +16,18 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
import org.apache.tamaya.spi.ServiceContextManager;
/**
* Static access to the {@link org.apache.tamaya.Configuration} for the very application.
- * <p>
- * Exists for Java7 backward compatibility only.
- *
- * @deprecated Since Java 8, you better use {@link org.apache.tamaya.Configuration#current()}.
*/
-@Deprecated
public final class ConfigurationProvider {
+
+ private static final ConfigurationProviderSpi PROVIDER_SPI = ServiceContextManager.getServiceContext()
+ .getService(ConfigurationProviderSpi.class).get();
+
private ConfigurationProvider() {
// just to prevent initialisation
}
@@ -35,10 +36,18 @@ public final class ConfigurationProvider {
* Access the current configuration.
*
* @return the corresponding Configuration instance, never null.
- * @deprecated Since Java 8, you better use {@link org.apache.tamaya.Configuration#current()}.
*/
- @Deprecated
public static Configuration getConfiguration() {
- return ServiceContextManager.getServiceContext().getService(Configuration.class).get();
+ return PROVIDER_SPI.getConfiguration();
}
+
+ /**
+ * Get access to the current ConfigurationContext.
+ *
+ * @return the current ConfigurationContext, never null.
+ */
+ public static ConfigurationContext getConfigurationContext(){
+ return PROVIDER_SPI.getConfigurationContext();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/main/java/org/apache/tamaya/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/PropertyConverter.java b/java8/api/src/main/java/org/apache/tamaya/PropertyConverter.java
new file mode 100644
index 0000000..4f6ea80
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/PropertyConverter.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;
+
+
+/**
+ * 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.
+ * @param <T> the result/target type of the converter.
+ */
+public interface PropertyConverter<T> {
+
+ /**
+ * Convert the given configuration keys from it's String representation into the required target type.
+ * <b>IMPORTANT NOTE: </b> Multiple instances of this type are ordered in a chain of converters that
+ * try to parse/convert a configured value. The first non-null result returned by a converter is
+ * used as the final result of the conversion. As a consequence implementations of this class must
+ * only return non-null values that are the result of a successful conversion of an entry.
+ *
+ * @param value the configuration value, not null.
+ * @return the converted value, or {@code null} if the value could not be converted. Returning a non-null
+ * value will stop the conversion process and return the value as result (converted value).
+ */
+ 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.
+ //X Collection<String> getSupportedFormats();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
new file mode 100644
index 0000000..57e7ec7
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/TypeLiteral.java
@@ -0,0 +1,137 @@
+/*
+* 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.io.Serializable;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+
+/**
+* <p>Class for instantiation of objects that represent parameterized types
+* with current parameters.</p>
+* <p>
+* <p>An object that represents a parameterized type may be obtained by
+* subclassing <tt>TypeLiteral</tt>.</p>
+* <p>
+* <pre>
+* TypeLiteral<List<Integer>> stringListType = new TypeLiteral<List<Integer>>() {};
+* </pre>
+*
+* @param <T> the type, including all type parameters
+*/
+public class TypeLiteral<T> implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private Type type;
+
+ protected TypeLiteral(Type type) {
+ this.type = type;
+ }
+
+ protected TypeLiteral() { }
+
+ public static <T> TypeLiteral<T> of(Type type){
+ return new TypeLiteral<>(type);
+ }
+
+ private static Class<?> getTypeLiteralSubclass(Class<?> clazz) {
+ Class<?> superclass = clazz.getSuperclass();
+ if (superclass.equals(TypeLiteral.class)) {
+ return clazz;
+ } else if (superclass.equals(Object.class)) {
+ return null;
+ } else {
+ return (getTypeLiteralSubclass(superclass));
+ }
+ }
+
+ private static Type getTypeParameter(Class<?> superclass) {
+ Type type = superclass.getGenericSuperclass();
+ if (type instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ if (parameterizedType.getActualTypeArguments().length == 1) {
+ return parameterizedType.getActualTypeArguments()[0];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the actual type represented by this object
+ */
+ public final Type getType() {
+ if (type == null) {
+ Class<?> typeLiteralSubclass = getTypeLiteralSubclass(this.getClass());
+ if (typeLiteralSubclass == null) {
+ throw new RuntimeException(getClass() + " is not a subclass of TypeLiteral");
+ }
+ type = getTypeParameter(typeLiteralSubclass);
+ if (type == null) {
+ throw new RuntimeException(getClass() + " does not specify the type parameter T of TypeLiteral<T>");
+ }
+ }
+ return type;
+ }
+
+ /**
+ * @return the raw type represented by this object
+ */
+ @SuppressWarnings("unchecked")
+ public final Class<T> getRawType() {
+ Type type = getType();
+ if (type instanceof Class) {
+ return (Class<T>) type;
+ } else if (type instanceof ParameterizedType) {
+ return (Class<T>) ((ParameterizedType) type).getRawType();
+ } else if (type instanceof GenericArrayType) {
+ return (Class<T>) Object[].class;
+ } else {
+ throw new RuntimeException("Illegal type");
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o){
+ return true;
+ }
+ if (!(o instanceof TypeLiteral)){
+ return false;
+ }
+ TypeLiteral that = (TypeLiteral) o;
+ if (type != null ? !type.equals(that.type) : that.type != null){
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type != null ? type.hashCode() : 0;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "TypeLiteral{" +
+ "type=" + type +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index e5d9ece..1848428 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -19,22 +19,21 @@
package org.apache.tamaya.spi;
+import org.apache.tamaya.PropertyConverter;
+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 org.apache.tamaya.spi.PropertySource}s,
- * managing {@link org.apache.tamaya.spi.PropertyConverter}s, ConfigFilters, etc.
+ * managing {@link org.apache.tamaya.PropertyConverter}s, ConfigFilters, etc.
*/
public interface ConfigurationContext {
- public static ConfigurationContext context() {
- return ServiceContext.getInstance().getService(ConfigurationContext.class).get();
- }
-
/**
- * This method can be used for programmatically adding {@link PropertySource}s.
+ * This method can be used for programmatically adding {@link org.apache.tamaya.spi.PropertySource}s.
* It is not needed for normal 'usage' by end users, but only for Extension Developers!
*
* @param propertySourcesToAdd the PropertySources to add
@@ -56,20 +55,20 @@ public interface ConfigurationContext {
List<PropertySource> getPropertySources();
/**
- * This method can be used for programmatically adding {@link PropertyConverter}s.
+ * This method can be used for programmatically adding {@link org.apache.tamaya.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);
+ <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. Refer also to {@link #getPropertyConverters()}.
+ * class name. Refer also to {@link #getPropertyConverters()}.
* </p>
* <p>
* A simplified scenario could be like:
@@ -84,7 +83,7 @@ public interface ConfigurationContext {
*
* @return map with sorted list of registered PropertySources per type.
*/
- Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters();
+ Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters();
/**
* <p>
@@ -133,7 +132,7 @@ public interface ConfigurationContext {
*
* @return a sorted list of registered PropertySources per type.
*/
- <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> type);
+ <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type);
/**
* Access the current PropertyFilter instances.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java b/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
new file mode 100644
index 0000000..577163b
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.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 org.apache.tamaya.spi.ConfigurationContext}.
+ *
+ * @return the current {@link org.apache.tamaya.spi.ConfigurationContext}, never null.
+ */
+ ConfigurationContext getConfigurationContext();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
deleted file mode 100644
index 235eebc..0000000
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spi;
-
-
-/**
- * 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's String representation into the required target type.
- * <b>IMPORTANT NOTE: </b> Multiple instances of this type are ordered in a chain of converters that
- * try to parse/convert a configured value. The first non-null result returned by a converter is
- * used as the final result of the conversion. As a consequence implementations of this class must
- * only return non-null values that are the result of a successful conversion of an entry.
- *
- * @param value the configuration value
- * @return the converted value, or {@code null} if the value could not be converted. Returning a non-null
- * value will stop the conversion process and return the value as result (converted value).
- */
- 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.
- //X Collection<String> getSupportedFormats();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 270a1ff..b8622a9 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
@@ -85,7 +85,7 @@ public interface PropertySource {
/**
* Get the name of the property source. The name should be unique for the type of source, whereas multiple instances
- * of the same type (and thus name) may exist in a system. Give a {@link org.apache.tamaya.spi.ConfigurationContext}
+ * of the same type (and thus name) may exist in a system. Give a {@link ConfigurationContext}
* the name of a PropertySource is unique.
*
* @return the property source's name, never null.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
index 1ca8d29..28d25ba 100644
--- a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -28,51 +28,51 @@ public class ConfigurationTest {
@org.junit.Test
public void testget() throws Exception {
- assertEquals(Boolean.TRUE, Configuration.current().getOptional("booleanTrue", (s) -> Boolean.valueOf(s)).get());
- assertEquals(Boolean.FALSE, Configuration.current().getOptional("booleanFalse", (s) -> Boolean.valueOf(s)).get());
- assertEquals((int) Byte.MAX_VALUE, (int) Configuration.current().getOptional("byte", (s) -> Byte.valueOf(s)).get());
- assertEquals((int) Integer.MAX_VALUE, (int) Configuration.current().getOptional("int", (s) -> Integer.valueOf(s)).get());
- assertEquals((long) Long.MAX_VALUE, (long) Configuration.current().getOptional("long", (s) -> Long.valueOf(s)).get());
- assertEquals((double) Float.MAX_VALUE, (double) Configuration.current().getOptional("float", (s) -> Float.valueOf(s)).get(), 0.0d);
- assertEquals((double) Double.MAX_VALUE, (double) Configuration.current().getOptional("double", (s) -> Double.valueOf(s)).get(), 0.0d);
+ assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().getOptional("booleanTrue", (s) -> Boolean.valueOf(s)).get());
+ assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().getOptional("booleanFalse", (s) -> Boolean.valueOf(s)).get());
+ assertEquals((int) Byte.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("byte", (s) -> Byte.valueOf(s)).get());
+ assertEquals((int) Integer.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("int", (s) -> Integer.valueOf(s)).get());
+ assertEquals((long) Long.MAX_VALUE, (long) ConfigurationProvider.getConfiguration().getOptional("long", (s) -> Long.valueOf(s)).get());
+ assertEquals((double) Float.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("float", (s) -> Float.valueOf(s)).get(), 0.0d);
+ assertEquals((double) Double.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("double", (s) -> Double.valueOf(s)).get(), 0.0d);
}
@org.junit.Test
public void testGetBoolean() throws Exception {
- assertTrue(Configuration.current().getBoolean("booleanTrue"));
- assertFalse(Configuration.current().getBoolean("booleanFalse"));
- assertFalse(Configuration.current().getBoolean("foorBar"));
+ assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue"));
+ assertFalse(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse"));
+ assertFalse(ConfigurationProvider.getConfiguration().getBoolean("foorBar"));
}
@org.junit.Test
public void testGetInteger() throws Exception {
- assertEquals(Integer.MAX_VALUE, Configuration.current().getInteger("int").getAsInt());
+ assertEquals(Integer.MAX_VALUE, ConfigurationProvider.getConfiguration().getInteger("int").getAsInt());
}
@org.junit.Test
public void testGetLong() throws Exception {
- assertEquals(Long.MAX_VALUE, Configuration.current().getLong("long").getAsLong());
+ assertEquals(Long.MAX_VALUE, ConfigurationProvider.getConfiguration().getLong("long").getAsLong());
}
@org.junit.Test
public void testGetDouble() throws Exception {
- assertEquals(Double.MAX_VALUE, Configuration.current().getDouble("double").getAsDouble(), 0.0d);
+ assertEquals(Double.MAX_VALUE, ConfigurationProvider.getConfiguration().getDouble("double").getAsDouble(), 0.0d);
}
@org.junit.Test
public void testWith() throws Exception {
- assertEquals(Configuration.current(), Configuration.current().with(c -> c));
+ assertEquals(ConfigurationProvider.getConfiguration(), ConfigurationProvider.getConfiguration().with(c -> c));
}
@org.junit.Test
public void testQuery() throws Exception {
- assertEquals("myFooResult", Configuration.current().query(c -> "myFooResult"));
+ assertEquals("myFooResult", ConfigurationProvider.getConfiguration().query(c -> "myFooResult"));
}
@org.junit.Test
public void testGetAdapted() throws Exception {
- assertEquals("yes", Configuration.current().getOptional("booleanTrue", (v) -> Boolean.parseBoolean(v) ? "yes" : "no").get());
- assertEquals("no", Configuration.current().getOptional("booleanFalse", (v) -> Boolean.parseBoolean(v) ? "yes" : "no").get());
+ assertEquals("yes", ConfigurationProvider.getConfiguration().getOptional("booleanTrue", (v) -> Boolean.parseBoolean(v) ? "yes" : "no").get());
+ assertEquals("no", ConfigurationProvider.getConfiguration().getOptional("booleanFalse", (v) -> Boolean.parseBoolean(v) ? "yes" : "no").get());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 c572dff..2501b32 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationContext;
+
import java.util.HashMap;
import java.util.Map;
@@ -47,26 +49,26 @@ public class TestConfiguration implements Configuration {
}
@Override
- public <T> T get(String key, Class<T> type) {
- if (type.equals(Long.class)) {
+ public <T> T get(String key, TypeLiteral<T> type) {
+ if (type.getType().equals(Long.class)) {
return (T) (Object) Long.MAX_VALUE;
- } else if (type.equals(Integer.class)) {
+ } else if (type.getType().equals(Integer.class)) {
return (T) (Object) Integer.MAX_VALUE;
- } else if (type.equals(Double.class)) {
+ } else if (type.getType().equals(Double.class)) {
return (T) (Object) Double.MAX_VALUE;
- } else if (type.equals(Float.class)) {
+ } else if (type.getType().equals(Float.class)) {
return (T) (Object) Float.MAX_VALUE;
- } else if (type.equals(Short.class)) {
+ } else if (type.getType().equals(Short.class)) {
return (T) (Object) Short.MAX_VALUE;
- } else if (type.equals(Byte.class)) {
+ } else if (type.getType().equals(Byte.class)) {
return (T) (Object) Byte.MAX_VALUE;
- } else if (type.equals(Boolean.class)) {
+ } else if (type.getType().equals(Boolean.class)) {
if ("booleanTrue".equals(key)) {
return (T) (Object) Boolean.TRUE;
} else {
return (T) (Object) Boolean.FALSE;
}
- } else if (type.equals(String.class)) {
+ } else if (type.getType().equals(String.class)) {
return (T) (Object) "aStringValue";
}
throw new ConfigException("No such property: " + key);
@@ -76,4 +78,5 @@ public class TestConfiguration implements Configuration {
public Map<String, String> getProperties() {
return null;
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
new file mode 100644
index 0000000..f2dac28
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.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;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+
+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 TestConfigurationProvider implements ConfigurationProviderSpi {
+
+ private static final Configuration config = new TestConfiguration();
+
+
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
deleted file mode 100644
index 1f42438..0000000
--- a/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.TestConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..b9c5ba5
--- /dev/null
+++ b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -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.TestConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 e862d02..60fcac5 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
@@ -20,17 +20,18 @@ package org.apache.tamaya.core.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.ServiceContext;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
@@ -55,7 +56,11 @@ public class DefaultConfiguration implements Configuration {
/**
* The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
*/
- private final ConfigurationContext configurationContext = ServiceContext.getInstance().getService(ConfigurationContext.class).get();
+ private final ConfigurationContext configurationContext;
+
+ public DefaultConfiguration(ConfigurationContext context){
+ this.configurationContext = Objects.requireNonNull(context);
+ }
/**
* This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
@@ -194,7 +199,7 @@ public class DefaultConfiguration implements Configuration {
/**
* 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
+ * using the {@link org.apache.tamaya.PropertyConverter} instances provided by the current
* {@link org.apache.tamaya.spi.ConfigurationContext}.
*
* @param key the property's absolute, or relative path, e.g. @code
@@ -204,7 +209,7 @@ public class DefaultConfiguration implements Configuration {
* @return the converted value, never null.
*/
@Override
- public <T> T get(String key, Class<T> type) {
+ public <T> T get(String key, TypeLiteral<T> type) {
Optional<String> value = getOptional(key);
if (value.isPresent()) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
@@ -219,7 +224,7 @@ public class DefaultConfiguration implements Configuration {
" failed to convert value: " + value.get());
}
}
- throw new ConfigException("Unparseable config value for type: " + type.getName() + ": " + key);
+ throw new ConfigException("Unparseable config value for type: " + type.getType() + ": " + key);
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
index b6acae5..8b17c77 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -18,8 +18,9 @@
*/
package org.apache.tamaya.core.internal;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
@@ -40,7 +41,7 @@ import java.util.concurrent.locks.StampedLock;
*/
public class DefaultConfigurationContext implements ConfigurationContext {
/**
- * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ * Cubcomponent handling {@link org.apache.tamaya.PropertyConverter} instances.
*/
private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
@@ -161,17 +162,17 @@ public class DefaultConfigurationContext implements ConfigurationContext {
}
@Override
- public <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
propertyConverterManager.register(typeToConvert, propertyConverter);
}
@Override
- public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
return propertyConverterManager.getPropertyConverters();
}
@Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
return propertyConverterManager.getPropertyConverters(targetType);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
new file mode 100644
index 0000000..bcef9af
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.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.core.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+
+/**
+ * Implementation of the Configuration API. This class uses the current {@link org.apache.tamaya.spi.ConfigurationContext} to evaluate the
+ * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
+
+ private ConfigurationContext context = new DefaultConfigurationContext();
+ private Configuration config = new DefaultConfiguration(context);
+
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return context;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
index b79a756..f1abdd7 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
@@ -27,6 +27,9 @@ import java.util.Objects;
import java.util.Properties;
import java.util.Set;
+/**
+ * Minimalistic loader for property files from the classpath.
+ */
public final class PropertiesFileLoader {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
index 15af9ac..e698634 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -34,19 +34,20 @@ import java.util.concurrent.locks.StampedLock;
import java.util.logging.Logger;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.core.internal.converters.EnumConverter;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import org.apache.tamaya.spi.ServiceContext;
/**
- * Manager that deals with {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ * Manager that deals with {@link org.apache.tamaya.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 Map<Class<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ private Map<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
/** The lock used. */
private StampedLock lock = new StampedLock();
private static final String CHAR_NULL_ERROR = "Cannot convert null property";
@@ -68,7 +69,7 @@ public class PropertyConverterManager {
conv.getClass().getName());
} else {
Type targetType = type.getActualTypeArguments()[0];
- register((Class<?>)targetType, conv);
+ register(TypeLiteral.of(targetType), conv);
}
}
}
@@ -80,7 +81,7 @@ public class PropertyConverterManager {
* @param converter the converter, not null.
* @param <T> the type.
*/
- public <T> void register(Class<T> targetType, PropertyConverter<T> converter) {
+ public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
Objects.requireNonNull(converter);
Lock writeLock = lock.asWriteLock();
try {
@@ -103,7 +104,7 @@ public class PropertyConverterManager {
* @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(Class<?> targetType) {
+ public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
return converters.containsKey(targetType)
|| createDefaultPropertyConverter(targetType) != null;
}
@@ -114,9 +115,9 @@ public class PropertyConverterManager {
* factory methods taking a single String instance.
*
* @return the current map of instantiated and registered converters.
- * @see #createDefaultPropertyConverter(Class)
+ * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
*/
- public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
Lock readLock = lock.asReadLock();
try {
readLock.lock();
@@ -134,9 +135,9 @@ public class PropertyConverterManager {
* @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(Class)
+ * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
*/
- public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
Lock readLock = lock.asReadLock();
List<PropertyConverter<T>> converters;
try {
@@ -170,17 +171,17 @@ public class PropertyConverterManager {
* @param <T> the type class
* @return a new converter, or null.
*/
- protected <T> PropertyConverter<T> createDefaultPropertyConverter(Class<T> targetType) {
- if(Enum.class.isAssignableFrom(targetType)){
- return new EnumConverter<T>(targetType);
+ protected <T> PropertyConverter<T> createDefaultPropertyConverter(TypeLiteral<T> targetType) {
+ if(Enum.class.isAssignableFrom(targetType.getRawType())){
+ return new EnumConverter<T>(targetType.getRawType());
}
PropertyConverter<T> converter = null;
- Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
+ Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
if (factoryMethod != null) {
converter = (value) -> {
try {
factoryMethod.setAccessible(true);
- return targetType.cast(factoryMethod.invoke(value));
+ return targetType.getRawType().cast(factoryMethod.invoke(value));
} catch (Exception e) {
throw new ConfigException("Failed to decode '" + value + "'", e);
}
@@ -188,7 +189,7 @@ public class PropertyConverterManager {
}
if (converter == null) {
try {
- Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ Constructor<T> constr = targetType.getRawType().getDeclaredConstructor(String.class);
converter = (value) -> {
try {
constr.setAccessible(true);
@@ -198,7 +199,7 @@ public class PropertyConverterManager {
}
};
} catch (Exception e) {
- LOG.finest(() -> "Failed to construct instance of type: " + targetType.getName()+": " + e);
+ LOG.finest(() -> "Failed to construct instance of type: " + targetType.getRawType().getName()+": " + e);
}
}
return converter;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
index f927e22..87f3d14 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.math.BigDecimal;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
index f0eba47..4db9bcd 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.math.BigInteger;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
index 76fd4d7..754b4b7 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import javax.annotation.CheckForNull;
import java.util.Locale;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
index 514f2df..6e52ef1 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
index 829c16b..f3773bb 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
index c3c6e56..4d033eb 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Currency;
import java.util.Locale;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
index 8eb016b..1814cba 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
index 652c808..05f29ad 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.core.internal.converters;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -28,6 +28,7 @@ import java.util.logging.Logger;
/**
* Converter, converting from String to tge given enum type.
+ * @param <T> the enumeration type.
*/
public class EnumConverter<T> implements PropertyConverter<T> {
private Logger LOG = Logger.getLogger(EnumConverter.class.getName());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
index 839dbe0..955197b 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
index c67e587..923b132 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
index 7c223dd..c652732 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.time.LocalDate;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
index 0dd3351..5125231 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalDateTimeConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.time.LocalDateTime;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
index 031b028..d46fcc0 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LocalTimeConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.time.LocalTime;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
index 600d875..67434d2 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
index 6c8094f..3fdc68d 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.math.BigDecimal;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
index 8a71ef7..e41c1d6 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
index d2134e0..aa9ee66 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/converters/ZoneIdConverter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.internal.converters;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.time.ZoneId;
import java.util.Objects;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.PropertyConverter
----------------------------------------------------------------------
diff --git a/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.PropertyConverter b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.PropertyConverter
new file mode 100644
index 0000000..964843c
--- /dev/null
+++ b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.PropertyConverter
@@ -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 current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.converters.BooleanConverter
+org.apache.tamaya.core.internal.converters.ByteConverter
+org.apache.tamaya.core.internal.converters.CharConverter
+org.apache.tamaya.core.internal.converters.DoubleConverter
+org.apache.tamaya.core.internal.converters.FloatConverter
+org.apache.tamaya.core.internal.converters.IntegerConverter
+org.apache.tamaya.core.internal.converters.LongConverter
+org.apache.tamaya.core.internal.converters.ShortConverter
+org.apache.tamaya.core.internal.converters.BigDecimalConverter
+org.apache.tamaya.core.internal.converters.BigIntegerConverter
+org.apache.tamaya.core.internal.converters.CurrencyConverter
+org.apache.tamaya.core.internal.converters.LocalDateConverter
+org.apache.tamaya.core.internal.converters.LocalDateTimeConverter
+org.apache.tamaya.core.internal.converters.LocalTimeConverter
+org.apache.tamaya.core.internal.converters.ZoneIdConverter
+org.apache.tamaya.core.internal.converters.NumberConverter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..7c0e249
--- /dev/null
+++ b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 c2ddbf8..3e2b160 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
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -32,25 +32,25 @@ public class ConfigurationTest {
@Test
public void testAccess(){
- assertNotNull(Configuration.current());
+ assertNotNull(ConfigurationProvider.getConfiguration());
}
@Test
public void testContent(){
- 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));
+ assertEquals("Robin", ConfigurationProvider.getConfiguration().getOptional("name").get());
+ assertEquals("Sabine", ConfigurationProvider.getConfiguration().getOptional("name2").get()); // from default
+ assertEquals("Mapped to name: Robin", ConfigurationProvider.getConfiguration().getOptional("name3").get()); // oderridden default, mapped by filter to name property
+ assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", ConfigurationProvider.getConfiguration().getOptional("name4").get()); // final only
+ assertNull(ConfigurationProvider.getConfiguration().getOptional("name5").orElse(null)); // final only, but removed from filter
+
+ System.out.println("name : " + ConfigurationProvider.getConfiguration().getOptional("name").get());
+ System.out.println("name2: " + ConfigurationProvider.getConfiguration().getOptional("name2").get());
+ System.out.println("name3: " + ConfigurationProvider.getConfiguration().getOptional("name3").get());
+ System.out.println("name4: " + ConfigurationProvider.getConfiguration().getOptional("name4").get());
+ System.out.println("name5: " + ConfigurationProvider.getConfiguration().getOptional("name5").orElse(null));
System.out.println("ALL :");
- Configuration.current().getProperties().entrySet().forEach(e ->
+ ConfigurationProvider.getConfiguration().getProperties().entrySet().forEach(e ->
System.out.println(" " + e.getKey()+" = " + e.getValue()));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java b/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
index ba4279f..a9671f0 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
@@ -19,11 +19,11 @@
package org.apache.tamaya.core.internal.converters;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.junit.Test;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -39,7 +39,7 @@ public class BooleanConverterTest {
*/
@Test
public void testConvert_Byte() throws Exception {
- Configuration config = Configuration.current();
+ Configuration config = ConfigurationProvider.getConfiguration();
// trues
Optional<Boolean> valueRead = config.getOptional("tests.converter.boolean.y1", Boolean.class);
assertTrue(valueRead.isPresent());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java b/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
index 5bdee37..fd16d8b 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.core.internal.converters;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.junit.Test;
import java.util.Optional;
@@ -37,7 +38,7 @@ public class ByteConverterTest {
*/
@Test
public void testConvert_Byte() throws Exception {
- Configuration config = Configuration.current();
+ Configuration config = ConfigurationProvider.getConfiguration();
Optional<Byte> valueRead = config.getOptional("tests.converter.byte.decimal", Byte.class);
assertTrue(valueRead.isPresent());
assertEquals(valueRead.get().byteValue(), 101);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 bfd9fd0..dfb5ff1 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
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.test.provider;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.core.provider.JavaConfigurationProvider;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Assert;
@@ -51,8 +51,8 @@ public class JavaConfigurationProviderTest {
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().getOptional(key).get());
+ Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
+ Assert.assertEquals(value, ConfigurationProvider.getConfiguration().getOptional(key).get());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/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 4667ca6..2cf76f1 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
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.core.testdata;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.PropertyFilter;
import javax.annotation.Priority;
@@ -34,7 +34,7 @@ public class TestPropertyFilterRemoving implements PropertyFilter{
return null;
}
else if("name3".equals(key)){
- return "Mapped to name: " + Configuration.current().getOptional("name").orElse("NoName found!");
+ return "Mapped to name: " + ConfigurationProvider.getConfiguration().getOptional("name").orElse("NoName found!");
}
return valueToBeFiltered;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
index f0c3796..2759cc3 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.inject;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
index 2c62fdf..9e9ee73 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.inject.internal;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -66,6 +67,6 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler
return "Configured Proxy -> " + this.type.getType().getName();
}
String configValue = InjectionUtils.getConfigValue(method);
- return InjectionUtils.adaptValue(method, method.getReturnType(), configValue);
+ return InjectionUtils.adaptValue(method, TypeLiteral.of(method.getReturnType()), configValue);
}
}
[9/9] incubator-tamaya git commit: TAMAYA-8: Added javadocs.
TAMAYA-62: Adaptions in modules.
Posted by an...@apache.org.
TAMAYA-8: Added javadocs.
TAMAYA-62: Adaptions in modules.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4929d3cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4929d3cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4929d3cd
Branch: refs/heads/master
Commit: 4929d3cd29171b7417cc58f1c27e5bfb4e388697
Parents: 2f2dbd1
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 21:05:45 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:19 2015 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/inject/DynamicValue.java | 1 +
.../tamaya/modules/json/FileBasedResource.java | 3 +++
.../tamaya/modules/json/InputResource.java | 3 +++
.../tamaya/modules/json/JSONPropertySource.java | 3 +++
.../apache/tamaya/modules/json/JSONVisitor.java | 6 +++++
.../JSONPropertySourceConfigurationTest.java | 10 ++++----
.../resolver/internal/ConfigResolver.java | 1 -
.../tamaya/resolver/ConfigResolutionTest.java | 24 ++++++++++----------
8 files changed, 33 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
index 95dd6a6..6075666 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
@@ -47,6 +47,7 @@ import java.util.logging.Logger;
* <li>Serializable, when also the item stored is serializable</li>
* <li>Thread safe</li>
* </ul>
+ * @param <T> The type of the value.
*/
public final class DynamicValue<T> implements Serializable {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/json/src/main/java/org/apache/tamaya/modules/json/FileBasedResource.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/FileBasedResource.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/FileBasedResource.java
index 38dfcaa..6684145 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/FileBasedResource.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/FileBasedResource.java
@@ -25,6 +25,9 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+/**
+ * Implements an InputResource based on a file.
+ */
public class FileBasedResource implements InputResource {
private final File sourceFile;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/json/src/main/java/org/apache/tamaya/modules/json/InputResource.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/InputResource.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/InputResource.java
index 2138c47..46bfa0c 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/InputResource.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/InputResource.java
@@ -20,6 +20,9 @@ package org.apache.tamaya.modules.json;
import java.io.InputStream;
+/**
+ * Simple Resource Abstraction.
+ */
public interface InputResource {
InputStream getInputStream();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
index 3daa9e2..f18f138 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
@@ -36,6 +36,9 @@ import java.util.concurrent.locks.StampedLock;
import static java.lang.String.format;
+/**
+ * Property source based on a JSON file.
+ */
public class JSONPropertySource
implements PropertySource {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
index f52afbf..25b6be3 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
@@ -25,6 +25,9 @@ import org.apache.tamaya.ConfigException;
import java.util.*;
+/**
+ * Visitor implementation to read a JSON formatted input source.
+ */
public class JSONVisitor {
private final ObjectNode rootNode;
private final HashMap<String, String> targetStore;
@@ -66,6 +69,9 @@ public class JSONVisitor {
}
}
+ /**
+ * Context for a sub context visited.
+ */
private static class VisitingContext {
private String namespace;
private final ObjectNode node;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
index 5d77489..1dd20d7 100644
--- a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceConfigurationTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.modules.json;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.ConfigurationContext;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
@@ -28,6 +29,9 @@ import java.net.URL;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
+/**
+ * Tests for {@link org.apache.tamaya.modules.json.JSONPropertySource}.
+ */
public class JSONPropertySourceConfigurationTest {
@@ -36,15 +40,11 @@ public class JSONPropertySourceConfigurationTest {
URL configURL = JSONPropertySourceTest.class.getResource("/configs/valid/simple-flat-string-only-config.json");
assertThat(configURL, CoreMatchers.notNullValue());
-
File configFile = new File(configURL.toURI());
-
JSONPropertySource source = new JSONPropertySource(configFile, 10);
-
assertThat(source.getProperties().keySet(), hasSize(3));
- ConfigurationContext context = ConfigurationContext.context();
-
+ ConfigurationContext context = ConfigurationProvider.getConfigurationContext();
context.addPropertySources(source);
// @todo Finish!
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
index bdabc28..4708a39 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.resolver.internal;
-import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.resolver.spi.ExpressionResolver;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4929d3cd/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java b/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
index 23fc42b..7e3db08 100644
--- a/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
+++ b/modules/resolver/src/test/java/org/apache/tamaya/resolver/ConfigResolutionTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.resolver;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -33,57 +33,57 @@ public class ConfigResolutionTest {
@Test
public void test_Prefix_Resolution() {
- assertEquals(Configuration.current().get("Before Text (prefixed)"), "My Java version is " + System.getProperty("java.version"));
+ assertEquals(ConfigurationProvider.getConfiguration().get("Before Text (prefixed)"), "My Java version is " + System.getProperty("java.version"));
}
@Test
public void test_Midfix_Resolution() {
- assertEquals(Configuration.current().get("Before and After Text (prefixed)"), "My Java version is " + System.getProperty("java.version") + ".");
+ assertEquals(ConfigurationProvider.getConfiguration().get("Before and After Text (prefixed)"), "My Java version is " + System.getProperty("java.version") + ".");
}
@Test
public void test_Prefix_ExpressionOnly_Resolution() {
- assertEquals(Configuration.current().get("Expression Only"), System.getProperty("java.version"));
+ assertEquals(ConfigurationProvider.getConfiguration().get("Expression Only"), System.getProperty("java.version"));
}
@Test
public void testConfig_Refs() {
- assertEquals(Configuration.current().get("config-ref"), "Expression Only -> " + System.getProperty("java.version"));
- assertEquals(Configuration.current().get("config-ref3"), "Config Ref 3 -> Ref 2: Config Ref 2 -> Ref 1: Expression Only -> " + System.getProperty("java.version"));
- assertEquals(Configuration.current().get("config-ref2"), "Config Ref 2 -> Ref 1: Expression Only -> " + System.getProperty("java.version"));
+ assertEquals(ConfigurationProvider.getConfiguration().get("config-ref"), "Expression Only -> " + System.getProperty("java.version"));
+ assertEquals(ConfigurationProvider.getConfiguration().get("config-ref3"), "Config Ref 3 -> Ref 2: Config Ref 2 -> Ref 1: Expression Only -> " + System.getProperty("java.version"));
+ assertEquals(ConfigurationProvider.getConfiguration().get("config-ref2"), "Config Ref 2 -> Ref 1: Expression Only -> " + System.getProperty("java.version"));
}
@Test
public void testClasspath_Refs() {
- String value = Configuration.current().get("cp-ref");
+ String value = ConfigurationProvider.getConfiguration().get("cp-ref");
assertNotNull(value);
assertTrue(value.contains("This content comes from Testresource.txt!"));
}
@Test
public void testResource_Refs() {
- String value = Configuration.current().get("res-ref");
+ String value = ConfigurationProvider.getConfiguration().get("res-ref");
assertNotNull(value);
assertTrue(value.contains("This content comes from Testresource.txt!"));
}
@Test
public void testFile_Refs() {
- String value = Configuration.current().get("file-ref");
+ String value = ConfigurationProvider.getConfiguration().get("file-ref");
assertNotNull(value);
assertTrue(value.contains("This content comes from Testresource2.txt!"));
}
@Test
public void testURL_Refs() {
- String value = Configuration.current().get("url-ref");
+ String value = ConfigurationProvider.getConfiguration().get("url-ref");
assertNotNull(value);
assertTrue(value.contains("doctype html"));
}
@Test
public void testEscaping(){
- assertEquals(Configuration.current().get("escaped"),
+ assertEquals(ConfigurationProvider.getConfiguration().get("escaped"),
"Config Ref 3 -> Ref 2: \\${conf:config-ref2 will not be evaluated and will not contain\\t tabs \\n " +
"newlines or \\r returns...YEP!");
}
[8/9] incubator-tamaya git commit: TAMAYA-62: Bugfixes and adaptions
of tests.
Posted by an...@apache.org.
TAMAYA-62: Bugfixes and adaptions of tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/2f2dbd1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/2f2dbd1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/2f2dbd1f
Branch: refs/heads/master
Commit: 2f2dbd1ffe553d7d925cd533889d2200861598ca
Parents: a8c1a9c
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 19:41:05 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:18 2015 +0100
----------------------------------------------------------------------
.../tamaya/core/internal/DefaultServiceContextTest.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2f2dbd1f/java8/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/java8/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
index 69f02c0..d8f1fd7 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.core.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
import org.junit.Assert;
import org.junit.Test;
@@ -37,11 +38,10 @@ public class DefaultServiceContextTest {
@Test
public void testGetService() {
- Optional<ConfigurationContext> configurationContext = context.getService(ConfigurationContext.class);
-
- Assert.assertNotNull(configurationContext);
- Assert.assertTrue(configurationContext.isPresent());
- Assert.assertTrue(configurationContext.get() instanceof DefaultConfigurationContext);
+ Optional<ConfigurationProviderSpi> providerSpi = context.getService(ConfigurationProviderSpi.class);
+ Assert.assertNotNull(providerSpi);
+ Assert.assertTrue(providerSpi.isPresent());
+ Assert.assertTrue(providerSpi.get() instanceof DefaultConfigurationProvider);
}
@Test(expected = ConfigException.class)
[6/9] incubator-tamaya git commit: TAMAYA-63: Implemented backport
for Java 7.
Posted by an...@apache.org.
TAMAYA-63: Implemented backport for Java 7.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bc62f716
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bc62f716
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bc62f716
Branch: refs/heads/master
Commit: bc62f716262666003ad6cbcc9364e80e867e7e45
Parents: ffffdc8
Author: anatole <an...@apache.org>
Authored: Sat Jan 24 11:18:08 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Jan 24 21:06:16 2015 +0100
----------------------------------------------------------------------
java7/core/pom.xml | 54 ++++
.../core/internal/DefaultConfiguration.java | 242 +++++++++++++++++
.../internal/DefaultConfigurationContext.java | 205 ++++++++++++++
.../core/internal/DefaultServiceContext.java | 146 ++++++++++
.../core/internal/PropertiesFileLoader.java | 102 +++++++
.../core/internal/PropertyConverterManager.java | 267 +++++++++++++++++++
.../tamaya/core/internal/ReflectionUtil.java | 42 +++
.../converters/BigDecimalConverter.java | 37 +++
.../converters/BigIntegerConverter.java | 38 +++
.../internal/converters/BooleanConverter.java | 57 ++++
.../core/internal/converters/ByteConverter.java | 34 +++
.../core/internal/converters/CharConverter.java | 38 +++
.../internal/converters/CurrencyConverter.java | 37 +++
.../internal/converters/DoubleConverter.java | 36 +++
.../core/internal/converters/EnumConverter.java | 58 ++++
.../internal/converters/FloatConverter.java | 36 +++
.../internal/converters/IntegerConverter.java | 35 +++
.../core/internal/converters/LongConverter.java | 35 +++
.../internal/converters/NumberConverter.java | 37 +++
.../internal/converters/ShortConverter.java | 35 +++
.../core/propertysource/BasePropertySource.java | 82 ++++++
.../core/propertysource/DefaultOrdinal.java | 54 ++++
.../EnvironmentPropertySource.java | 52 ++++
.../PropertiesFilePropertySource.java | 51 ++++
.../PropertiesPropertySource.java | 51 ++++
.../propertysource/SystemPropertySource.java | 91 +++++++
.../provider/JavaConfigurationProvider.java | 58 ++++
....apache.tamaya.core.resources.ResourceLoader | 19 ++
.../org.apache.tamaya.spi.ConfigurationContext | 19 ++
.../org.apache.tamaya.spi.PropertyConverter | 30 +++
.../org.apache.tamaya.spi.ServiceContext | 19 ++
.../apache/tamaya/core/ConfigurationTest.java | 68 +++++
.../internal/DefaultServiceContextTest.java | 129 +++++++++
.../core/internal/PropetiesFileLoaderTest.java | 75 ++++++
.../converters/BooleanConverterTest.java | 106 ++++++++
.../internal/converters/ByteConverterTest.java | 55 ++++
.../ConverterTestsPropertySource.java | 117 ++++++++
.../propertysource/BasePropertySourceTest.java | 106 ++++++++
.../PropertiesFilePropertySourceTest.java | 71 +++++
.../SystemPropertySourceTest.java | 101 +++++++
.../provider/JavaConfigurationProviderTest.java | 60 +++++
.../testdata/TestPropertyDefaultSource.java | 56 ++++
.../core/testdata/TestPropertyFilter.java | 37 +++
.../testdata/TestPropertyFilterRemoving.java | 42 +++
.../testdata/TestPropertySourceProvider.java | 78 ++++++
...tServiceContextTest$InvalidPriorityInterface | 19 ++
...efaultServiceContextTest$MultiImplsInterface | 20 ++
.../org.apache.tamaya.spi.PropertyFilter | 20 ++
.../org.apache.tamaya.spi.PropertySource | 22 ++
...org.apache.tamaya.spi.PropertySourceProvider | 20 ++
.../test/resources/javaconfiguration.properties | 22 ++
.../test/resources/overrideOrdinal.properties | 25 ++
.../core/src/test/resources/testfile.properties | 22 ++
java7/pom.xml | 2 -
54 files changed, 3368 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/pom.xml
----------------------------------------------------------------------
diff --git a/java7/core/pom.xml b/java7/core/pom.xml
new file mode 100644
index 0000000..4727712
--- /dev/null
+++ b/java7/core/pom.xml
@@ -0,0 +1,54 @@
+<!--
+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.1-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-java7-core</artifactId>
+ <name>Apache Tamaya Java 7 Core</name>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
new file mode 100644
index 0000000..720efe0
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.ConfigQuery;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+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
+ * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+public class DefaultConfiguration implements Configuration {
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(DefaultConfiguration.class.getName());
+ /**
+ * The maximal number of filter cycles performed before aborting.
+ */
+ private static final int MAX_FILTER_LOOPS = 10;
+
+ /**
+ * The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
+ */
+ private final ConfigurationContext configurationContext = ServiceContextManager.getServiceContext().getService(ConfigurationContext.class);
+
+ /**
+ * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
+ * provided by the current {@link org.apache.tamaya.spi.ConfigurationContext}. The first non-null-value returned
+ * is taken as an intermediate value. Finally the value is filtered through the
+ * {@link org.apache.tamaya.spi.PropertyFilter} instances installed, before it is returned as the final result of
+ * this method.
+ *
+ * @param key the property's key, not null.
+ * @return the optional configuration value, never null.
+ */
+ @Override
+ public String get(String key) {
+ List<PropertySource> propertySources = configurationContext.getPropertySources();
+ String unfilteredValue = null;
+ for (PropertySource propertySource : propertySources) {
+ String value = propertySource.get(key);
+ if (value != null) {
+ unfilteredValue = value.length() > 0 ? value : null;
+ break;
+ }
+ }
+ return applyFilter(key, unfilteredValue);
+ }
+
+ /**
+ * Apply filters to a single property value.
+ *
+ * @param key the key, used for logging, not null.
+ * @param unfilteredValue the unfiltered property value.
+ * @return the filtered value, or null.
+ */
+ private String applyFilter(String key, String unfilteredValue) {
+ // Apply filters to values, prevent values filtered to null!
+ for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
+ boolean changed = false;
+ // Apply filters to values, prevent values filtered to null!
+ for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
+ String newValue = filter.filterProperty(key, unfilteredValue);
+ if (newValue != null && !newValue.equals(unfilteredValue)) {
+ changed = true;
+ if (LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
+ }
+ } else if (unfilteredValue != null && !unfilteredValue.equals(newValue)) {
+ changed = true;
+ if (LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
+ }
+ }
+ unfilteredValue = newValue;
+ }
+ if (!changed) {
+ LOG.finest("Finishing filter loop, no changes detected.");
+ break;
+ } else {
+ if (i == (MAX_FILTER_LOOPS - 1)) {
+ if (LOG.isLoggable(Level.WARNING)) {
+ LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
+ }
+ } else {
+ LOG.finest("Repeating filter loop, changes detected.");
+ }
+ }
+ }
+ return unfilteredValue;
+ }
+
+ /**
+ * Get the current properties, composed by the loaded {@link org.apache.tamaya.spi.PropertySource} and filtered
+ * by registered {@link org.apache.tamaya.spi.PropertyFilter}.
+ *
+ * @return the final properties.
+ */
+ @Override
+ public Map<String, String> getProperties() {
+ List<PropertySource> propertySources = new ArrayList<>(configurationContext.getPropertySources());
+ Collections.reverse(propertySources);
+ Map<String, String> result = new HashMap<>();
+ for (PropertySource propertySource : propertySources) {
+ try {
+ int origSize = result.size();
+ Map<String, String> otherMap = propertySource.getProperties();
+ LOG.log(Level.FINEST, null, "Overriding with properties from " + propertySource.getName());
+ result.putAll(otherMap);
+ LOG.log(Level.FINEST, null, "Handled properties from " + propertySource.getName() + "(new: " +
+ (result.size() - origSize) + ", overrides: " + origSize + ", total: " + result.size());
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error adding properties from PropertySource: " + propertySource + ", ignoring PropertySource.", e);
+ }
+ }
+ return applyFilters(result);
+ }
+
+ /**
+ * Filter a full configuration property map.
+ *
+ * @param inputMap the unfiltered map
+ * @return the filtered map.
+ */
+ private Map<String, String> applyFilters(Map<String, String> inputMap) {
+ final Map<String, String> resultMap = new HashMap<>();
+ // Apply filters to values, prevent values filtered to null!
+ for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
+ AtomicInteger changes = new AtomicInteger();
+ for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
+
+
+ for (Map.Entry<String, String> entry : inputMap.entrySet()) {
+ final String k = entry.getKey();
+ final String v = entry.getValue();
+
+ String newValue = filter.filterProperty(k, v);
+ if (newValue != null && !newValue.equals(v)) {
+ changes.incrementAndGet();
+ LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
+ } else if (v != null && !v.equals(newValue)) {
+ changes.incrementAndGet();
+ LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
+ }
+ // Remove null values
+ if (null != newValue) {
+ resultMap.put(k, newValue);
+ }
+ }
+ }
+ if (changes.get() == 0) {
+ LOG.finest("Finishing filter loop, no changes detected.");
+ break;
+ } else {
+ if (i == (MAX_FILTER_LOOPS - 1)) {
+ if (LOG.isLoggable(Level.WARNING)) {
+ LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
+ }
+ } else {
+ LOG.finest("Repeating filter loop, changes detected: " + changes.get());
+ }
+ changes.set(0);
+ }
+ }
+
+ return resultMap;
+ }
+
+ /**
+ * Accesses the current String value for the given key and tries to convert it
+ * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext}.
+ *
+ * @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.
+ * @param <T> the value type
+ * @return the converted value, never null.
+ */
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ String value = get(key);
+ if (value != null) {
+ List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value);
+ if (t != null) {
+ return t;
+ }
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e);
+ }
+ }
+ throw new ConfigException("Unparseable config value for type: " + type.getName() + ": " + key);
+ }
+
+ return null;
+ }
+
+ public Configuration with(ConfigOperator operator) {
+ return operator.operate(this);
+ }
+
+ public <T> T query(ConfigQuery<T> query) {
+ return query.query(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
new file mode 100644
index 0000000..3abae9d
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.annotation.Priority;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * Default Implementation of a simple ConfigurationContext.
+ */
+public class DefaultConfigurationContext implements ConfigurationContext {
+ /**
+ * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ */
+ private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
+ */
+ private List<PropertySource> immutablePropertySources;
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
+ */
+ private List<PropertyFilter> immutablePropertyFilters;
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+
+
+ /**
+ * The first time the Configuration system gets invoked we do initialize
+ * all our {@link org.apache.tamaya.spi.PropertySource}s and
+ * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
+ */
+ public DefaultConfigurationContext() {
+ List<PropertySource> propertySources = new ArrayList<>();
+
+ // first we load all PropertySources which got registered via java.util.ServiceLoader
+ propertySources.addAll(ServiceContextManager.getServiceContext().getServices(PropertySource.class));
+
+ // after that we add all PropertySources which get dynamically registered via their PropertySourceProviders
+ propertySources.addAll(evaluatePropertySourcesFromProviders());
+
+ // now sort them according to their ordinal values
+ Collections.sort(propertySources, new PropertySourceComparator());
+
+ immutablePropertySources = Collections.unmodifiableList(propertySources);
+
+ // as next step we pick up the PropertyFilters pretty much the same way
+ List<PropertyFilter> propertyFilters = new ArrayList<>();
+ propertyFilters.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class));
+ Collections.sort(propertyFilters, new PropertyFilterComparator());
+
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ }
+
+ /**
+ * Pick up all {@link org.apache.tamaya.spi.PropertySourceProvider}s and return all the
+ * {@link org.apache.tamaya.spi.PropertySource}s they like to register.
+ */
+ private Collection<? extends PropertySource> evaluatePropertySourcesFromProviders() {
+ List<PropertySource> propertySources = new ArrayList<>();
+ List<PropertySourceProvider> propertySourceProviders = ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class);
+ for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
+ propertySources.addAll(propertySourceProvider.getPropertySources());
+ }
+
+ return propertySources;
+ }
+
+ @Override
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ Lock writeLock = propertySourceLock.writeLock();
+ try {
+ writeLock.lock();
+ List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
+ newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
+ Collections.sort(newPropertySources, new PropertySourceComparator());
+
+ this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ private static class PropertySourceComparator implements Comparator<PropertySource>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Order property source reversely, the most important come first.
+ *
+ * @param source1 the first PropertySource
+ * @param source2 the second PropertySource
+ * @return the comparison result.
+ */
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+ if (source1.getOrdinal() < source2.getOrdinal()) {
+ return 1;
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
+ return -1;
+ } else {
+ return source2.getClass().getName().compareTo(source1.getClass().getName());
+ }
+ }
+
+ @Override
+ public int compare(PropertySource source1, PropertySource source2) {
+ return comparePropertySources(source1, source2);
+ }
+ }
+
+ private static class PropertyFilterComparator implements Comparator<PropertyFilter>, Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Compare 2 filters for ordering the filter chain.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return the comparison result
+ */
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
+ Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
+ Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+
+ if (ord1 < ord2) {
+ return -1;
+ } else if (ord1 > ord2) {
+ return 1;
+ } else {
+ return filter1.getClass().getName().compareTo(filter2.getClass().getName());
+ }
+ }
+
+ @Override
+ public int compare(PropertyFilter filter1, PropertyFilter filter2) {
+ return comparePropertyFilters(filter1, filter2);
+ }
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return immutablePropertySources;
+ }
+
+ @Override
+ public <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ }
+
+ @Override
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return immutablePropertyFilters;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
new file mode 100644
index 0000000..2e59fa2
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ServiceContext;
+
+import javax.annotation.Priority;
+import java.text.MessageFormat;
+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 DefaultServiceContext implements ServiceContext {
+ /**
+ * List current services loaded, per class.
+ */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /**
+ * Singletons.
+ */
+ private final Map<Class, Object> singletons = new ConcurrentHashMap<>();
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ Object cached = singletons.get(serviceType);
+ if (cached == null) {
+ List<? extends T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = null;
+ } else {
+ cached = getServiceWithHighestPriority(services, serviceType);
+ }
+ if(cached!=null) {
+ singletons.put(serviceType, cached);
+ }
+ }
+ return (T)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(final Class<T> serviceType) {
+ List<T> found = (List<T>) servicesLoaded.get(serviceType);
+ if (found != null) {
+ return found;
+ }
+ List<T> services = new ArrayList<>();
+ try {
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ services = Collections.unmodifiableList(services);
+ } catch (Exception e) {
+ Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ }
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
+ return previousServices != null ? previousServices : services;
+ }
+
+
+ /**
+ * @param services to scan
+ * @param <T> type of the service
+ *
+ * @return the service with the highest {@link javax.annotation.Priority#value()}
+ *
+ * @throws ConfigException if there are multiple service implementations with the maximum priority
+ */
+ private <T> T getServiceWithHighestPriority(List<? extends T> services, Class<T> serviceType) {
+
+ // we do not need the priority stuff if the list contains only one element
+ if (services.size() == 1) {
+ return services.get(0);
+ }
+
+ Integer highestPriority = null;
+ int highestPriorityServiceCount = 0;
+ T highestService = null;
+
+ for (T service : services) {
+ int prio = 1; //X TODO discuss default priority
+ Priority priority = service.getClass().getAnnotation(Priority.class);
+ if (priority != null) {
+ prio = priority.value();
+ }
+
+ if (highestPriority == null || highestPriority < prio) {
+ highestService = service;
+ highestPriorityServiceCount = 1;
+ highestPriority = prio;
+ } else if (highestPriority == prio) {
+ highestPriorityServiceCount++;
+ }
+ }
+
+ if (highestPriorityServiceCount > 1) {
+ throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}",
+ highestPriorityServiceCount,
+ serviceType.getName(),
+ highestPriority,
+ services));
+ }
+
+ return highestService;
+ }
+
+ @Override
+ public int ordinal() {
+ return 1;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
new file mode 100644
index 0000000..ffd9a41
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+public final class PropertiesFileLoader {
+
+
+ private PropertiesFileLoader() {
+ // no instantiation
+ }
+
+
+ /**
+ * loads all properties-files with the given name.
+ * If the name do not end with {@code .properties} it will be appended
+ *
+ * @param name of the properties file
+ *
+ * @return URLs of properties-files or
+ * an empty {@link java.util.Set} if no files has been found
+ *
+ * @throws java.io.IOException in case of problems loading the properties-files
+ */
+ public static Set<URL> resolvePropertiesFiles(String name) throws IOException {
+ Objects.requireNonNull(name);
+
+ if (!name.endsWith(".properties")) {
+ name = name + ".properties";
+ }
+
+ Set<URL> urls = new HashSet<>();
+
+ Enumeration<URL> files = Thread.currentThread().getContextClassLoader().getResources(name);
+ while (files.hasMoreElements()) {
+ urls.add(files.nextElement());
+ }
+
+ return urls;
+ }
+
+
+ /**
+ * loads the Properties from the given URL
+ *
+ * @param propertiesFile {@link java.net.URL} to load Properties from
+ *
+ * @return loaded {@link java.util.Properties}
+ *
+ * @throws IllegalStateException in case of an error while reading properties-file
+ */
+ public static Properties load(URL propertiesFile) {
+
+ Properties properties = new Properties();
+
+ InputStream stream = null;
+ try {
+ stream = propertiesFile.openStream();
+
+ if (stream != null) {
+ properties.load(stream);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error loading Properties " + propertiesFile, e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // bad luck -> stream is already closed
+ }
+ }
+ }
+
+ return properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
new file mode 100644
index 0000000..67d77b6
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.internal.converters.EnumConverter;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manager that deals with {@link org.apache.tamaya.spi.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 Map<Class<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ /**
+ * The lock used.
+ */
+ private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private static final String CHAR_NULL_ERROR = "Cannot convert null property";
+
+ /**
+ * Constructor.
+ */
+ public PropertyConverterManager() {
+ initConverters();
+ }
+
+ /**
+ * Registers the default converters provided out of the box.
+ */
+ protected void initConverters() {
+ for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
+ ParameterizedType type = ReflectionUtil.getParametrizedType(conv.getClass());
+ if (type == null || type.getActualTypeArguments().length == 0) {
+ LOG.warning("Failed to register PropertyConverter, no generic type information available: " +
+ conv.getClass().getName());
+ } else {
+ Type targetType = type.getActualTypeArguments()[0];
+ register((Class<?>) targetType, 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(Class<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);
+ this.converters.put(targetType, Collections.unmodifiableList(newConverters));
+ } 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(Class<?> targetType) {
+ return converters.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(Class)
+ */
+ public Map<Class<?>, 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.
+ *
+ * @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(Class)
+ */
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ Lock readLock = lock.readLock();
+ List<PropertyConverter<T>> converters;
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ return converters;
+ }
+ PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
+ if (defaultConverter != null) {
+ register(targetType, defaultConverter);
+ try {
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ }
+ if (converters != null) {
+ return converters;
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * 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 Class<T> targetType) {
+ if (Enum.class.isAssignableFrom(targetType)) {
+ return new EnumConverter<T>(targetType);
+ }
+ PropertyConverter<T> converter = null;
+ final Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
+ if (factoryMethod != null) {
+ converter = new ViaMethodPropertyConverter<>(factoryMethod, targetType);
+ }
+ if (converter == null) {
+ try {
+ final Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ converter = new ViaConstructorPropertyConverter<>(constr);
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, "Failed to construct instance of type: " + targetType.getName(), e);
+ }
+ }
+ 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.log(Level.FINEST, "No such factory method found on type: " + type.getName() + ", methodName: " + name, e);
+ }
+ }
+ return null;
+ }
+
+ private static class ViaMethodPropertyConverter<T> implements PropertyConverter<T> {
+ private final Method factoryMethod;
+ private final Class<T> targetType;
+
+ public ViaMethodPropertyConverter(Method factoryMethod, Class<T> targetType) {
+ this.factoryMethod = factoryMethod;
+ this.targetType = targetType;
+ }
+
+ public T convert(final String value) {
+ try {
+ AccessController.doPrivileged(
+ new PrivilegedAction() {
+ @Override
+ public Object run() {
+ factoryMethod.setAccessible(true);
+ return null;
+ }
+ });
+ return targetType.cast(factoryMethod.invoke(value));
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new ConfigException("Failed to decode '" + value + "'", e);
+ }
+ }
+ }
+
+ private static class ViaConstructorPropertyConverter<T> implements PropertyConverter<T> {
+ private final Constructor<T> constr;
+
+ public ViaConstructorPropertyConverter(Constructor<T> constr) {
+ this.constr = constr;
+ }
+
+ @Override
+ public T convert(String value) {
+ try {
+ constr.setAccessible(true);
+ return constr.newInstance(value);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + value + "'", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
new file mode 100644
index 0000000..6c7a1d2
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+
+/**
+ * Small utility class used by other parts.
+ */
+public final class ReflectionUtil {
+
+ private ReflectionUtil(){}
+
+ public static ParameterizedType getParametrizedType(Class<?> clazz) {
+ Type[] genericTypes = clazz.getGenericInterfaces();
+ for (Type type : genericTypes) {
+ if (type instanceof ParameterizedType) {
+ return (ParameterizedType) type;
+ }
+
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
new file mode 100644
index 0000000..f927e22
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.math.BigDecimal;
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to BigDecimal.
+ * //X TODO not good enough as this is Locale dependent!
+ */
+public class BigDecimalConverter implements PropertyConverter<BigDecimal>{
+
+ @Override
+ public BigDecimal convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return new BigDecimal(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
new file mode 100644
index 0000000..f0eba47
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.math.BigInteger;
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to BigInteger.
+ * //X TODO not good enough as this is Locale dependent!
+ */
+public class BigIntegerConverter implements PropertyConverter<BigInteger>{
+
+ @Override
+ public BigInteger convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return new BigInteger(trimmed);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
new file mode 100644
index 0000000..6c33d7f
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.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.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Boolean.
+ */
+public class BooleanConverter implements PropertyConverter<Boolean> {
+
+ private Logger LOG = Logger.getLogger(getClass().getName());
+
+ @Override
+ public Boolean convert(String value) {
+ String ignoreCaseValue = Objects.requireNonNull(value)
+ .trim()
+ .toLowerCase(Locale.ENGLISH);
+
+ switch(ignoreCaseValue) {
+ case "yes":
+ case "y":
+ case "true":
+ case "t":
+ return Boolean.TRUE;
+ case "no":
+ case "n":
+ case "false":
+ case "f":
+ return Boolean.FALSE;
+ default:
+ LOG.warning("Unknown boolean value encountered: " + value);
+ }
+
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
new file mode 100644
index 0000000..1d9bf65
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.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.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Byte.
+ */
+public class ByteConverter implements PropertyConverter<Byte>{
+
+ @Override
+ public Byte convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return Byte.decode(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
new file mode 100644
index 0000000..829c16b
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Character.
+ */
+public class CharConverter implements PropertyConverter<Character>{
+
+ @Override
+ public Character convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ if(trimmed.length()!=1){
+ return null;
+ }
+ return Character.valueOf(value.charAt(0));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
new file mode 100644
index 0000000..c3c6e56
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Currency;
+import java.util.Locale;
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Currency.
+ */
+public class CurrencyConverter implements PropertyConverter<Currency>{
+
+ @Override
+ public Currency convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return Currency.getInstance(trimmed.toUpperCase(Locale.ENGLISH));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
new file mode 100644
index 0000000..8eb016b
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Double.
+ */
+public class DoubleConverter implements PropertyConverter<Double>{
+
+ @Override
+ public Double convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ //X TODO not good enough as this is Locale dependent!
+ return Double.valueOf(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
new file mode 100644
index 0000000..652c808
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to tge given enum type.
+ */
+public class EnumConverter<T> implements PropertyConverter<T> {
+ private Logger LOG = Logger.getLogger(EnumConverter.class.getName());
+ private Class<T> enumType;
+ private Method factory;
+
+ public EnumConverter(Class<T> enumType) {
+ if (!Enum.class.isAssignableFrom(enumType)) {
+ throw new IllegalArgumentException("Not an Enum: " + enumType.getName());
+ }
+ this.enumType = Objects.requireNonNull(enumType);
+ try {
+ this.factory = enumType.getMethod("valueOf", String.class);
+ } catch (NoSuchMethodException e) {
+ throw new ConfigException("Uncovertible enum type without valueOf method found, please provide a custom " +
+ "PropertyConverter for: " + enumType.getName());
+ }
+ }
+
+ @Override
+ public T convert(String value) {
+ try {
+ return (T) factory.invoke(null, value);
+ } catch (InvocationTargetException | IllegalAccessException e) {
+ throw new ConfigException("Invalid enum value '" + value + "' for " + enumType.getName(), e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
new file mode 100644
index 0000000..839dbe0
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Float.
+ */
+public class FloatConverter implements PropertyConverter<Float>{
+
+ @Override
+ public Float convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ //X TODO not good enough as this is Locale dependent!
+ return Float.valueOf(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
new file mode 100644
index 0000000..c67e587
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Integer.
+ */
+public class IntegerConverter implements PropertyConverter<Integer>{
+
+ @Override
+ public Integer convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return Integer.decode(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
new file mode 100644
index 0000000..600d875
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Long.
+ */
+public class LongConverter implements PropertyConverter<Long>{
+
+ @Override
+ public Long convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return Long.decode(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
new file mode 100644
index 0000000..6c8094f
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.math.BigDecimal;
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to BigDecimal.
+ * //X TODO not good enough as this is Locale dependent!
+ */
+public class NumberConverter implements PropertyConverter<Number>{
+
+ @Override
+ public Number convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return new BigDecimal(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
new file mode 100644
index 0000000..8a71ef7
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+
+/**
+ * Converter, converting from String to Short.
+ */
+public class ShortConverter implements PropertyConverter<Short>{
+
+ @Override
+ public Short convert(String value) {
+ String trimmed = Objects.requireNonNull(value).trim();
+ return Short.decode(trimmed);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
new file mode 100644
index 0000000..2172094
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A base class for {@link PropertySource}s. It provides a {@link #initializeOrdinal(int)} method that
+ * reads the ordinal from the config source itself, allowing the ordinal to be "self-configured" by
+ * the configuration read.
+ */
+public abstract class BasePropertySource implements PropertySource {
+
+ private static final Logger LOG = Logger.getLogger(BasePropertySource.class.getName());
+
+
+ private int ordinal = DefaultOrdinal.PROPERTY_SOURCE;
+
+
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+
+ @Override
+ public String get(String key) {
+ Objects.requireNonNull(key, "key must not be null");
+ return getProperties().get(key);
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+
+
+ /**
+ * Initializing the ordinal of this {@link PropertySource} with the given defaultOrdinal.
+ *
+ * If {@link PropertySource#TAMAYA_ORDINAL} is present via {@link #get(String)} and the
+ * value is a valid {@link Integer} then, the defaultOrdinal will be overridden.
+ *
+ * @param defaultOrdinal of the {@link PropertySource}
+ */
+ protected void initializeOrdinal(final int defaultOrdinal) {
+ this.ordinal = defaultOrdinal;
+
+ String ordinal = get(PropertySource.TAMAYA_ORDINAL);
+ if (ordinal != null) {
+
+ try {
+ this.ordinal = Integer.parseInt(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, defaultOrdinal});
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
new file mode 100644
index 0000000..ff35e3f
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+
+/**
+ * This interface defines the default ordinals for the 'standard'
+ * {@link org.apache.tamaya.spi.PropertySource}s
+ *
+ * DefaultOrdinals can be overwritten via {@link org.apache.tamaya.spi.PropertySource#TAMAYA_ORDINAL}
+ */
+public final class DefaultOrdinal {
+
+ /** Private constructor. */
+ private DefaultOrdinal(){}
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.BasePropertySource} if
+ * not overriden in each class
+ */
+ public static final int PROPERTY_SOURCE = 1000;
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
+ */
+ public static final int SYSTEM_PROPERTIES = 400;
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}
+ */
+ public static final int ENVIRONMENT_PROPERTIES = 300;
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.PropertiesFilePropertySource}
+ */
+ public static final int FILE_PROPERTIES = 100;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
new file mode 100644
index 0000000..3f60b29
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Map;
+
+/**
+ * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
+ * via <br />
+ * {@code export myprop=myval} on UNIX Systems or<br />
+ * {@code set myprop=myval} on Windows
+ */
+public class EnvironmentPropertySource extends BasePropertySource {
+
+ public EnvironmentPropertySource() {
+ initializeOrdinal(DefaultOrdinal.ENVIRONMENT_PROPERTIES);
+ }
+
+
+ @Override
+ public String getName() {
+ return "environment-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return System.getenv(); // already a map and unmodifiable
+
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
new file mode 100644
index 0000000..86597f1
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+
+import java.net.URL;
+
+/**
+ * {@link org.apache.tamaya.spi.PropertySource} for properties-files
+ */
+public class PropertiesFilePropertySource extends PropertiesPropertySource {
+
+
+ private String fileName;
+
+
+ public PropertiesFilePropertySource(URL propertiesFile) {
+ super(PropertiesFileLoader.load(propertiesFile));
+
+ initializeOrdinal(DefaultOrdinal.FILE_PROPERTIES);
+ this.fileName = propertiesFile.toExternalForm();
+ }
+
+
+ @Override
+ public String getName() {
+ return fileName;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
new file mode 100644
index 0000000..cf68bd6
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * base class for {@link org.apache.tamaya.spi.PropertySource}s which are based on
+ * {@link java.util.Properties}
+ */
+abstract class PropertiesPropertySource extends BasePropertySource {
+
+ protected Map<String, String> properties;
+
+
+ // package private to not expose this class
+ PropertiesPropertySource(Properties properties) {
+ Map<String, String> props = new HashMap<>();
+
+ for (String key : properties.stringPropertyNames()) {
+ props.put(key, properties.getProperty(key));
+ }
+
+ this.properties = Collections.unmodifiableMap(props);
+ }
+
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+}
[5/9] incubator-tamaya git commit: TAMAYA-63: Implemented backport
for Java 7.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
new file mode 100644
index 0000000..962a6af
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
+ */
+public class SystemPropertySource extends PropertiesPropertySource {
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+
+
+ /**
+ * previous System.getProperties().hashCode()
+ * so we can check if we need to reload
+ */
+ private int previousHash;
+
+
+ public SystemPropertySource() {
+ super(System.getProperties());
+ previousHash = System.getProperties().hashCode();
+ initializeOrdinal(DefaultOrdinal.SYSTEM_PROPERTIES);
+ }
+
+
+ @Override
+ public String getName() {
+ return "system-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+
+ Lock writeLock = propertySourceLock.writeLock();
+ // only need to reload and fill our map if something has changed
+ try {
+ writeLock.lock();
+ if (previousHash != System.getProperties().hashCode()) {
+
+ if (previousHash != System.getProperties().hashCode()) {
+
+ Properties systemProperties = System.getProperties();
+ Map<String, String> properties = new HashMap<>();
+
+ for (String propertyName : systemProperties.stringPropertyNames()) {
+ properties.put(propertyName, System.getProperty(propertyName));
+ }
+
+ this.properties = Collections.unmodifiableMap(properties);
+ previousHash = systemProperties.hashCode();
+ }
+ }
+ } finally {
+ writeLock.unlock();
+ }
+
+ return super.getProperties();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java b/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
new file mode 100644
index 0000000..bb741de
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.provider;
+
+import static org.apache.tamaya.core.internal.PropertiesFileLoader.resolvePropertiesFiles;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Provider which reads all {@code javaconfiguration.properties} files from classpath
+ */
+public class JavaConfigurationProvider implements PropertySourceProvider {
+
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+
+ List<PropertySource> propertySources = new ArrayList<>();
+
+ //X TODO maybe put javaconf... in META-INF
+
+ try {
+ for (URL url : resolvePropertiesFiles("javaconfiguration.properties")) {
+ propertySources.add(new PropertiesFilePropertySource(url));
+ }
+ } catch (IOException e) {
+ throw new ConfigException("Error while loading javaconfiguration.properties", e);
+ }
+
+ return Collections.unmodifiableList(propertySources);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
new file mode 100644
index 0000000..a964d3c
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
@@ -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.resource.internal.DefaultResourceLoader
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
new file mode 100644
index 0000000..2f0f44e
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfigurationContext
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..0f0cb26
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.converters.BooleanConverter
+org.apache.tamaya.core.internal.converters.ByteConverter
+org.apache.tamaya.core.internal.converters.CharConverter
+org.apache.tamaya.core.internal.converters.DoubleConverter
+org.apache.tamaya.core.internal.converters.FloatConverter
+org.apache.tamaya.core.internal.converters.IntegerConverter
+org.apache.tamaya.core.internal.converters.LongConverter
+org.apache.tamaya.core.internal.converters.ShortConverter
+org.apache.tamaya.core.internal.converters.BigDecimalConverter
+org.apache.tamaya.core.internal.converters.BigIntegerConverter
+org.apache.tamaya.core.internal.converters.CurrencyConverter
+org.apache.tamaya.core.internal.converters.NumberConverter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..f8e7e7f
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultServiceContext
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
new file mode 100644
index 0000000..4c0e813
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -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.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.internal.DefaultConfiguration;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration.
+ */
+public class ConfigurationTest {
+
+ @Test
+ public void testAccess(){
+ assertNotNull(current());
+ }
+
+ private Configuration current() {
+ return ServiceContextManager.getServiceContext().getService(Configuration.class);
+ }
+
+ @Test
+ public void testContent(){
+ assertEquals("Robin", current().get("name"));
+ assertEquals("Sabine", current().get("name2")); // from default
+ assertEquals("Mapped to name: Robin", current().get("name3")); // oderridden default, mapped by filter to name property
+ assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", current().get("name4")); // final only
+ assertNull(current().get("name5")); // final only, but removed from filter
+
+ System.out.println("name : " + current().get("name"));
+ System.out.println("name2: " + current().get("name2"));
+ System.out.println("name3: " + current().get("name3"));
+ System.out.println("name4: " + current().get("name4"));
+ System.out.println("name5: " + current().get("name5"));
+
+ System.out.println("ALL :");
+ Set<Map.Entry<String, String>> entries = current().getProperties().entrySet();
+ for (Map.Entry<String, String> entry : entries) {
+ System.out.println(" " + entry.getKey()+" = " + entry.getValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
new file mode 100644
index 0000000..4f4079a
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+import java.util.List;
+import java.util.Optional;
+
+public class DefaultServiceContextTest {
+
+ /**
+ * context to test
+ */
+ private DefaultServiceContext context = new DefaultServiceContext();
+
+
+ @Test
+ public void testGetService() {
+ ConfigurationContext configurationContext = context.getService(ConfigurationContext.class);
+
+ Assert.assertNotNull(configurationContext);
+ Assert.assertTrue(configurationContext instanceof DefaultConfigurationContext);
+ }
+
+ @Test(expected = ConfigException.class)
+ public void testGetService_multipleServicesWithoutPriority_shouldThrowConfigException() {
+ context.getService(InvalidPriorityInterface.class);
+ }
+
+ @Test
+ public void testGetService_multipleService_shouldReturnServiceWithHighestPriority() {
+ MultiImplsInterface service = context.getService(MultiImplsInterface.class);
+
+ Assert.assertNotNull(service);
+ Assert.assertTrue(service instanceof MultiImpl2);
+ }
+
+ @Test
+ public void testGetService_noImpl_shouldReturnEmptyOpional() {
+ NoImplInterface service = context.getService(NoImplInterface.class);
+ Assert.assertNull(service);
+ }
+
+
+ @Test
+ public void testGetServices_shouldReturnServices() {
+ {
+ List<InvalidPriorityInterface> services = context.getServices(InvalidPriorityInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(2, services.size());
+
+ for (InvalidPriorityInterface service : services) {
+ Assert.assertTrue(service instanceof InvalidPriorityImpl1 || service instanceof InvalidPriorityImpl2);
+ }
+ }
+
+ {
+ List<MultiImplsInterface> services = context.getServices(MultiImplsInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(3, services.size());
+
+ for (MultiImplsInterface service : services) {
+ Assert.assertTrue(service instanceof MultiImpl1 ||
+ service instanceof MultiImpl2 ||
+ service instanceof MultiImpl3);
+ }
+ }
+ }
+
+ @Test
+ public void testGetServices_noImpl_shouldReturnEmptyList() {
+ List<NoImplInterface> services = context.getServices(NoImplInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertTrue(services.isEmpty());
+ }
+
+
+ // some test interfaces and classes
+
+ public static interface InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl1 implements InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl2 implements InvalidPriorityInterface {
+ }
+
+
+ public static interface MultiImplsInterface {
+ }
+
+ public static class MultiImpl1 implements MultiImplsInterface {
+ }
+
+ @Priority(value = 500)
+ public static class MultiImpl2 implements MultiImplsInterface {
+ }
+
+ @Priority(value = -10)
+ public static class MultiImpl3 implements MultiImplsInterface {
+ }
+
+ private static interface NoImplInterface {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
new file mode 100644
index 0000000..c125641
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Properties;
+import java.util.Set;
+
+public class PropetiesFileLoaderTest {
+
+
+ @Test
+ public void testResolvePropertiesFiles() throws Exception {
+ Properties expectedProperties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+ {
+ // with .properties
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
+ Assert.assertNotNull(urls);
+ Assert.assertFalse(urls.isEmpty());
+
+ Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+ Assert.assertEquals(expectedProperties.size(), properties.size());
+ }
+
+ {
+ // without .properties
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
+ Assert.assertNotNull(urls);
+ Assert.assertFalse(urls.isEmpty());
+
+ Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+ Assert.assertEquals(expectedProperties.size(), properties.size());
+ }
+
+ {
+ // with a while which doesn't exist
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
+ Assert.assertNotNull(urls);
+ Assert.assertTrue(urls.isEmpty());
+ }
+
+ }
+
+ @Test
+ public void testLoad() {
+ Properties properties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+ Assert.assertNotNull(properties);
+ Assert.assertEquals(5, properties.size());
+
+ for (int i = 1; i < 6; i++) {
+ Assert.assertEquals(properties.getProperty("key" + i), "val" + i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
new file mode 100644
index 0000000..a1ac83c
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class BooleanConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Byte() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ // trues
+ Boolean valueRead = config.get("tests.converter.boolean.y1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.y2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.yes1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.yes2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.yes3", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.true1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.true2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.true3", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.t1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.t2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ // falses
+ valueRead = config.get("tests.converter.boolean.n1", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.n2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.no1", Boolean.class);
+ assertFalse(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.no2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.no3", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.false1", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.false2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.false3", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.f1", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.f2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.foo", Boolean.class);
+ assertNull(valueRead);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
new file mode 100644
index 0000000..70f54c2
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class ByteConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Byte() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Byte valueRead = config.get("tests.converter.byte.decimal", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), 101);
+ valueRead = config.get("tests.converter.byte.octal", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), Byte.decode("02").byteValue());
+ valueRead = config.get("tests.converter.byte.hex.lowerX", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), Byte.decode("0x2F").byteValue());
+ valueRead = config.get("tests.converter.byte.hex.upperX", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), Byte.decode("0X3F").byteValue());
+ valueRead = config.get("tests.converter.byte.foo", Byte.class);
+ assertNull(valueRead);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
new file mode 100644
index 0000000..ec7c01f
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Test Property Source used by converter tests.
+ */
+public class ConverterTestsPropertySource implements PropertySource{
+ @Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ switch(key){
+ // Bytes
+ case "tests.converter.byte.decimal":
+ return "101";
+ case "tests.converter.byte.octal":
+ return "02";
+ case "tests.converter.byte.hex.lowerX":
+ return "0x2F";
+ case "tests.converter.byte.hex.upperX":
+ return "0X3F";
+ // Boolean
+ case "tests.converter.boolean.y1":
+ return "y";
+ case "tests.converter.boolean.y2":
+ return "Y";
+ case "tests.converter.boolean.yes1":
+ return "yes";
+ case "tests.converter.boolean.yes2":
+ return "Yes";
+ case "tests.converter.boolean.yes3":
+ return "yeS";
+ case "tests.converter.boolean.true1":
+ return "true";
+ case "tests.converter.boolean.true2":
+ return "True";
+ case "tests.converter.boolean.true3":
+ return "trUe";
+ case "tests.converter.boolean.t1":
+ return "t";
+ case "tests.converter.boolean.t2":
+ return "T";
+ case "tests.converter.boolean.n1":
+ return "n";
+ case "tests.converter.boolean.n2":
+ return "N";
+ case "tests.converter.boolean.no1":
+ return "no";
+ case "tests.converter.boolean.no2":
+ return "No";
+ case "tests.converter.boolean.no3":
+ return "nO";
+ case "tests.converter.boolean.false1":
+ return "false";
+ case "tests.converter.boolean.false2":
+ return "False";
+ case "tests.converter.boolean.false3":
+ return "falSe";
+ case "tests.converter.boolean.f1":
+ return "f";
+ case "tests.converter.boolean.f2":
+ return "F";
+ }
+ return null;
+ }
+
+ /*
+ case "yes":
+ case "y":
+ case "true":
+ case "t":
+ return Boolean.TRUE;
+ case "no":
+ case "n":
+ case "false":
+ case "f":
+ */
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..e6b789c
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BasePropertySourceTest {
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource() {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ Assert.assertEquals(DefaultOrdinal.PROPERTY_SOURCE, defaultPropertySource.getOrdinal());
+ Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
+
+ // propertySource with invalid ordinal
+ Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
+ }
+
+ private static class OverriddenOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ initializeOrdinal(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "1000");
+ return map;
+ }
+
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ initializeOrdinal(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
+ return map;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..6ad7790
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+public class PropertiesFilePropertySourceTest {
+
+ private PropertiesFilePropertySource testfilePropertySource;
+ private PropertiesFilePropertySource overrideOrdinalPropertySource;
+
+
+ @Before
+ public void initTest() {
+ testfilePropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+ overrideOrdinalPropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+ }
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
+ }
+
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("val3", testfilePropertySource.get("key3"));
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
+ }
+
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Properties expectedProperties = PropertiesFileLoader.load(new URL(testfilePropertySource.getName()));
+
+ Assert.assertEquals(expectedProperties.size(), testfilePropertySource.getProperties().size());
+
+ for (Map.Entry<String, String> entry : testfilePropertySource.getProperties().entrySet()) {
+ Assert.assertEquals(expectedProperties.getProperty(entry.getKey()), entry.getValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..35ebc80
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class SystemPropertySourceTest {
+
+ private SystemPropertySource testPropertySource = new SystemPropertySource();
+
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+
+ // test the default ordinal
+ Assert.assertEquals(DefaultOrdinal.SYSTEM_PROPERTIES, testPropertySource.getOrdinal());
+
+ // set the ordinal to 1000
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
+ Assert.assertEquals(1000, new SystemPropertySource().getOrdinal()); // currently its not possible to change ordinal at runtime
+
+ // reset it to not destroy other tests!!
+ System.clearProperty(PropertySource.TAMAYA_ORDINAL);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ Assert.assertEquals("system-properties", new SystemPropertySource().getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ String property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
+ property != null);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
+
+
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // modify system properties
+ System.setProperty("test", "myTestVal");
+
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // cleanup
+ System.clearProperty("test");
+
+ // no modifaction
+ try {
+ testPropertySource.getProperties().put("add.new.keys", "must throw exception");
+ Assert.fail(UnsupportedOperationException.class.getName() + " expected");
+ }
+ catch (UnsupportedOperationException e) {
+ // expected -> all is fine
+ }
+ }
+
+ private void checkWithSystemProperties(Map<String, String> toCheck) {
+ Properties systemEntries = System.getProperties();
+
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.entrySet().size(), toCheck.size());
+
+ for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
+
+ Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
+ systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..6e558d7
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.provider;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.provider.JavaConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+
+public class JavaConfigurationProviderTest {
+
+ @Test
+ public void testJavaConfigurationProvider() {
+
+ Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
+
+ assertThat(propertySources, notNullValue());
+ assertThat(propertySources, hasSize(1));
+
+ PropertySource propertySource = propertySources.iterator().next();
+
+ assertThat(propertySource.getProperties().keySet(), hasSize(5));
+
+ for (int i = 1; i < 6; i++) {
+ String key = "confkey" + i;
+ String value = "javaconf-value" + i;
+
+ Assert.assertEquals(value, propertySource.get(key));
+
+ // check if we had our key in configuration.current
+ Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
+ Assert.assertEquals(value, ConfigurationProvider.getConfiguration().get(key));
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
new file mode 100644
index 0000000..74f3aff
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test provider reading properties from classpath:cfg/defaults/**.properties.
+ */
+public class TestPropertyDefaultSource extends BasePropertySource{
+
+ private Map<String,String> properties = new HashMap<>();
+
+ public TestPropertyDefaultSource() {
+ initializeOrdinal(100);
+ properties.put("name","Anatole");
+ properties.put("name2","Sabine");
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "default-testdata-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
new file mode 100644
index 0000000..6faa831
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+
+/**
+ * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
+ */
+@Priority(100)
+public class TestPropertyFilter implements PropertyFilter{
+ @Override
+ public String filterProperty(String key, String valueToBeFiltered) {
+ if("name4".equals(key)){
+ return valueToBeFiltered + "(filtered)";
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
new file mode 100644
index 0000000..948ff26
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+
+/**
+ * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
+ */
+@Priority(200)
+public class TestPropertyFilterRemoving implements PropertyFilter{
+ @Override
+ public String filterProperty(String key, String valueToBeFiltered) {
+ if("name5".equals(key)){
+ return null;
+ }
+ else if("name3".equals(key)){
+ return "Mapped to name: " + ConfigurationProvider.getConfiguration().get("name");
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
new file mode 100644
index 0000000..7288b9f
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test provider reading properties from classpath:cfg/final/**.properties.
+ */
+public class TestPropertySourceProvider implements PropertySourceProvider {
+
+ private List<PropertySource> list = new ArrayList<>();
+
+ public TestPropertySourceProvider(){
+ list.add(new MyPropertySource());
+ list = Collections.unmodifiableList(list);
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return list;
+ }
+
+ private static class MyPropertySource extends BasePropertySource {
+
+ private Map<String, String> properties = new HashMap<>();
+
+ public MyPropertySource() {
+ initializeOrdinal(200);
+ properties.put("name", "Robin");
+ properties.put("name3", "Lukas");
+ properties.put("name4", "Sereina");
+ properties.put("name5", "Benjamin");
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "final-testdata-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
new file mode 100644
index 0000000..9d96b65
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
@@ -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 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.
+
+org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl1
+org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl2
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
new file mode 100644
index 0000000..2e24ed0
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
@@ -0,0 +1,20 @@
+# 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.
+
+org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl1
+org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl2
+org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl3
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..59bbab3
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.testdata.TestPropertyFilter
+org.apache.tamaya.core.testdata.TestPropertyFilterRemoving
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..409c9cb
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.testdata.TestPropertyDefaultSource
+org.apache.tamaya.core.propertysource.SystemPropertySource
+org.apache.tamaya.core.propertysource.EnvironmentPropertySource
+org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..9c352f4
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.testdata.TestPropertySourceProvider
+org.apache.tamaya.core.provider.JavaConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/javaconfiguration.properties b/java7/core/src/test/resources/javaconfiguration.properties
new file mode 100644
index 0000000..33beabb
--- /dev/null
+++ b/java7/core/src/test/resources/javaconfiguration.properties
@@ -0,0 +1,22 @@
+# 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.
+
+confkey1=javaconf-value1
+confkey2=javaconf-value2
+confkey3=javaconf-value3
+confkey4=javaconf-value4
+confkey5=javaconf-value5
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/overrideOrdinal.properties b/java7/core/src/test/resources/overrideOrdinal.properties
new file mode 100644
index 0000000..5384d91
--- /dev/null
+++ b/java7/core/src/test/resources/overrideOrdinal.properties
@@ -0,0 +1,25 @@
+# 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.
+
+#override ordinal
+tamaya.ordinal=16784
+
+mykey1=myval1
+mykey2=myval2
+mykey3=myval3
+mykey4=myval4
+mykey5=myval5
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/testfile.properties b/java7/core/src/test/resources/testfile.properties
new file mode 100644
index 0000000..4dc3b91
--- /dev/null
+++ b/java7/core/src/test/resources/testfile.properties
@@ -0,0 +1,22 @@
+# 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.
+
+key1=val1
+key2=val2
+key3=val3
+key4=val4
+key5=val5
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/pom.xml
----------------------------------------------------------------------
diff --git a/java7/pom.xml b/java7/pom.xml
index d4a8c7b..740ff1d 100644
--- a/java7/pom.xml
+++ b/java7/pom.xml
@@ -38,9 +38,7 @@ under the License.
<modules>
<module>api</module>
-<!--
<module>core</module>
--->
</modules>
<build>
[2/9] incubator-tamaya git commit: TAMAYA-62: Unified Configuration
access. Fixed some FindBugs and checkstyle issues.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
index 5e4db2a..2ee5aa2 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Objects;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.ConfigRoot;
import org.apache.tamaya.inject.ConfiguredProperty;
@@ -77,7 +78,7 @@ public class ConfiguredField {
configValue = InjectionUtils.evaluateValue(configValue);
}
// Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.annotatedField, this.annotatedField.getType(), configValue);
+ Object value = InjectionUtils.adaptValue(this.annotatedField, TypeLiteral.of(this.annotatedField.getType()), configValue);
annotatedField.setAccessible(true);
annotatedField.set(target, value);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 7a41ac9..2784e2d 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -24,6 +24,7 @@ import java.util.Optional;
import java.util.function.Consumer;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.ConfigRoot;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.event.PropertyChangeSet;
@@ -87,7 +88,7 @@ public class ConfiguredSetterMethod {
configValue = InjectionUtils.evaluateValue(configValue);
}
// Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.setterMethod, this.setterMethod.getParameterTypes()[0], configValue);
+ Object value = InjectionUtils.adaptValue(this.setterMethod, TypeLiteral.of(this.setterMethod.getParameterTypes()[0]), configValue);
setterMethod.setAccessible(true);
setterMethod.invoke(target, value);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
index bf4f77d..765331b 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
@@ -30,7 +30,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.inject.ConfigRoot;
import org.apache.tamaya.inject.ConfiguredProperty;
import org.apache.tamaya.inject.DefaultValue;
@@ -38,7 +39,7 @@ import org.apache.tamaya.inject.WithLoadPolicy;
import org.apache.tamaya.inject.WithPropertyConverter;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
import org.apache.tamaya.spi.ServiceContext;
@@ -174,7 +175,7 @@ final class InjectionUtils {
private static String evaluteConfigValue(List<String> keys) {
String configValue = null;
for (String key : keys) {
- configValue = Configuration.current().get(key);
+ configValue = ConfigurationProvider.getConfiguration().get(key);
if (configValue != null) {
break;
}
@@ -184,27 +185,28 @@ final class InjectionUtils {
@SuppressWarnings("rawtypes")
- public static <T> T adaptValue(AnnotatedElement element, Class<T> targetType, String configValue) {
+ public static <T> T adaptValue(AnnotatedElement element, TypeLiteral<T> targetType, String configValue) {
// Check for adapter/filter
T adaptedValue = null;
WithPropertyConverter converterAnnot = element.getAnnotation(WithPropertyConverter.class);
Class<? extends PropertyConverter<T>> converterType;
if (converterAnnot != null) {
converterType = (Class<? extends PropertyConverter<T>>) converterAnnot.value();
- if (!converterType.equals(WithPropertyConverter.class)) {
+ if (!converterType.getName().equals(WithPropertyConverter.class.getName())) {
try {
// TODO cache here...
- PropertyConverter<T> codec = PropertyConverter.class.cast(converterType.newInstance());
- adaptedValue = (T) codec.convert(configValue);
+ PropertyConverter<T> converter = PropertyConverter.class.cast(converterType.newInstance());
+ adaptedValue = (T) converter.convert(configValue);
} catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to convert using explicit PropertyConverter on " + element + ", trying default conversion.", e);
+ LOG.log(Level.SEVERE, "Failed to convert using explicit PropertyConverter on " + element +
+ ", trying default conversion.", e);
}
}
}
if (adaptedValue != null) {
return adaptedValue;
}
- if (String.class.equals(targetType)) {
+ if (String.class == targetType.getType()) {
return (T) configValue;
} else {
List<PropertyConverter<T>> converters = ServiceContext.getInstance().getService(ConfigurationContext.class).get()
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
index 592fd0c..bdabc28 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.resolver.internal;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.resolver.spi.ExpressionResolver;
import javax.annotation.Priority;
@@ -37,7 +38,7 @@ public final class ConfigResolver implements ExpressionResolver{
@Override
public String evaluate(String expression){
- return Configuration.current().get(expression);
+ return ConfigurationProvider.getConfiguration().get(expression);
}
}