You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2015/12/20 14:05:48 UTC
[1/8] incubator-tamaya git commit: Moved module core to ./code/
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 84d52f16b -> eadbfe973
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
deleted file mode 100644
index 8d3f086..0000000
--- a/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-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(56) {
-
- @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(56, 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() {
- super(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() {
- super(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/eadbfe97/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
deleted file mode 100644
index 280351e..0000000
--- a/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}.
- */
-public class EnvironmentPropertySourceTest {
-
- private EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
-
- @Test
- public void testGetOrdinal() throws Exception {
- assertEquals(EnvironmentPropertySource.DEFAULT_ORDINAL, envPropertySource.getOrdinal());
- }
-
- @Test
- public void testGetName() throws Exception {
- assertEquals("environment-properties", envPropertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
- assertEquals(envPropertySource.get(envEntry.getKey()), envEntry.getValue());
- }
- }
-
- @Test
- public void testGetProperties() throws Exception {
- Map<String, String> props = envPropertySource.getProperties();
- assertEquals(System.getenv(), props);
- }
-
- @Test
- public void testIsScannable() throws Exception {
- assertTrue(envPropertySource.isScannable());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
deleted file mode 100644
index 36b0f5d..0000000
--- a/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class PropertiesFilePropertySourceTest {
-
- private SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
- .getContextClassLoader().getResource("testfile.properties"));
- private SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
- Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
-
-
- @Test
- public void testGetOrdinal() {
- Assert.assertEquals(0, 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 {
- Assert.assertEquals(5, testfilePropertySource.getProperties().size());
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
deleted file mode 100644
index c627972..0000000
--- a/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-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(SystemPropertySource.DEFAULT_ORDINAL, 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", testPropertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
-
- String property = testPropertySource.get(propertyKeyToCheck);
- Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
- SystemPropertySource.class.getSimpleName(), property);
- 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());
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java b/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
deleted file mode 100644
index f099da4..0000000
--- a/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.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/eadbfe97/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
deleted file mode 100644
index 6c8751c..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.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() {
- super(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/eadbfe97/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
deleted file mode 100644
index 6faa831..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.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/eadbfe97/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
deleted file mode 100644
index 5706478..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.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() {
- super(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/eadbfe97/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java
deleted file mode 100644
index 5a57ad1..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.testdata;
-
-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 TestRemovingPropertyFilter 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/eadbfe97/core/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/javaconfiguration.properties b/core/src/test/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index 33beabb..0000000
--- a/core/src/test/resources/META-INF/javaconfiguration.properties
+++ /dev/null
@@ -1,22 +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.
-
-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/eadbfe97/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
deleted file mode 100644
index f203fa6..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
+++ /dev/null
@@ -1,18 +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.
-org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl1
-org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface b/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
deleted file mode 100644
index b144790..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
+++ /dev/null
@@ -1,20 +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.
-
-org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl1
-org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl2
-org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl3
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
deleted file mode 100644
index d039696..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
+++ /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.CTestConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
deleted file mode 100644
index 18e61cb..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
+++ /dev/null
@@ -1,20 +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.testdata.TestPropertyFilter
-org.apache.tamaya.core.testdata.TestRemovingPropertyFilter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 409c9cb..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,22 +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.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/eadbfe97/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index 9c352f4..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /dev/null
@@ -1,20 +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.testdata.TestPropertySourceProvider
-org.apache.tamaya.core.provider.JavaConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/overrideOrdinal.properties b/core/src/test/resources/overrideOrdinal.properties
deleted file mode 100644
index 96935a8..0000000
--- a/core/src/test/resources/overrideOrdinal.properties
+++ /dev/null
@@ -1,25 +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.
-
-#override ordinal
-tamaya.ordinal=16784
-
-mykey1=myval1
-mykey2=myval2
-mykey3=myval3
-mykey4=myval4
-mykey5=myval5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/testfile.properties b/core/src/test/resources/testfile.properties
deleted file mode 100644
index abd7ee8..0000000
--- a/core/src/test/resources/testfile.properties
+++ /dev/null
@@ -1,22 +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.
-
-key1=val1
-key2=val2
-key3=val3
-key4=val4
-key5=val5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/resources/x34.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/x34.properties b/core/src/test/resources/x34.properties
deleted file mode 100644
index f2c4a0a..0000000
--- a/core/src/test/resources/x34.properties
+++ /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 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.
-
-x34=x34
-x34.a.b.c=C
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4da09d7..8b3f535 100644
--- a/pom.xml
+++ b/pom.xml
@@ -204,7 +204,6 @@ under the License.
<modules>
<module>buildconfigurations</module>
<module>code</module>
- <module>core</module>
<module>modules</module>
<module>docs</module>
<module>examples</module>
[2/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java b/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java
deleted file mode 100644
index 7ee2a35..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-/**
- * Created by Anatole on 13.06.2015.
- */
-public class CTestConverter implements PropertyConverter<C>{
- @Override
- public C convert(String value, ConversionContext context) {
- return new C(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
deleted file mode 100644
index 1d24884..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.junit.Assert;
-import org.junit.Test;
-
-import javax.annotation.Priority;
-import java.util.Collection;
-import java.util.List;
-
-public class DefaultServiceContextTest {
-
- /**
- * context to test
- */
- private DefaultServiceContext context = new DefaultServiceContext();
-
-
- @Test
- public void testGetService() {
- ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
- Assert.assertNotNull(providerSpi);
- Assert.assertTrue(providerSpi instanceof DefaultConfigurationProvider);
- }
-
- @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() {
- {
- Collection<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);
- }
- }
-
- {
- Collection<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_redundantAccessToServices() {
- for(int i=0;i<10;i++){
- Collection<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);
- }
- }
- }
-
- @Test
- public void testGetServices_noImpl_shouldReturnEmptyList() {
- Collection<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/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java b/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
deleted file mode 100644
index 82d834a..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.junit.Test;
-
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
-
-public class PropertyConverterManagerTest {
-
- private ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder(
- "someKey", TypeLiteral.of(Object.class)).build();
-
- @Test
- public void customTypeWithFactoryMethodOfIsRecognizedAsSupported() {
- PropertyConverterManager manager = new PropertyConverterManager();
-
- assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class)),
- is(true));
- }
-
- @Test
- public void factoryMethodOfIsUsedAsConverter() {
- PropertyConverterManager manager = new PropertyConverterManager();
-
- List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
- (TypeLiteral)TypeLiteral.of(MyType.class));
-
- assertThat(converters, hasSize(1));
-
- PropertyConverter<MyType> converter = converters.get(0);
-
- Object result = converter.convert("IN", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(MyType.class));
- assertThat(((MyType)result).getValue(), equalTo("IN"));
- }
-
- @Test
- public void testDirectConverterMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<C>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<C> converter = converters.get(0);
- C result = converter.convert("testDirectConverterMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testDirectConverterMapping"));
- }
-
- @Test
- public void testDirectSuperclassConverterMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
- converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<B> converter = converters.get(0);
- B result = converter.convert("testDirectSuperclassConverterMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testDirectSuperclassConverterMapping"));
- }
-
- @Test
- public void testMultipleConverterLoad(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
- manager = new PropertyConverterManager();
- converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
- }
-
- @Test
- public void testTransitiveSuperclassConverterMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<A> converter = converters.get(0);
- A result = converter.convert("testTransitiveSuperclassConverterMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testTransitiveSuperclassConverterMapping"));
- }
-
- @Test
- public void testDirectInterfaceMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<Readable> converter = converters.get(0);
- Readable result = converter.convert("testDirectInterfaceMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testDirectInterfaceMapping"));
- }
-
- @Test
- public void testTransitiveInterfaceMapping1(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<Runnable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<Runnable> converter = converters.get(0);
- Runnable result = converter.convert("testTransitiveInterfaceMapping1", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping1"));
- }
-
- @Test
- public void testTransitiveInterfaceMapping2(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<AutoCloseable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<AutoCloseable> converter = converters.get(0);
- AutoCloseable result = converter.convert("testTransitiveInterfaceMapping2", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping2"));
- }
-
- public static class MyType {
- private String typeValue;
-
- private MyType(String value) {
- typeValue = value;
- }
-
- public static MyType of(String source) {
- return new MyType(source);
- }
-
- public String getValue() {
- return typeValue;
- }
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
deleted file mode 100644
index 9c71688..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests the default converter for bytes.
- */
-public class BigDecimalConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_BigDecimal_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- BigDecimal valueRead = config.get("tests.converter.bd.decimal", BigDecimal.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, new BigDecimal(101));
- }
-
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_BigDecimal_Hex() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- BigDecimal valueRead = config.get("tests.converter.bd.hex.lowerX", BigDecimal.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, new BigDecimal("47"));
- valueRead = config.get("tests.converter.bd.hex.upperX", BigDecimal.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, new BigDecimal("63"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- BigDecimal valueRead = config.get("tests.converter.bd.foo", BigDecimal.class);
- assertFalse(valueRead != null);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_BigDecimal_BigValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- BigDecimal valueRead = config.get("tests.converter.bd.big", BigDecimal.class);
- assertTrue(valueRead != null);
- assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"),
- valueRead);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_BigDecimal_BigFloatValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- BigDecimal valueRead = config.get("tests.converter.bd.bigFloat", BigDecimal.class);
- assertTrue(valueRead != null);
- assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" +
- "63723628763821638923628193612983618293628763"), valueRead);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
deleted file mode 100644
index c3b3f96..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-/**
- * 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/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
deleted file mode 100644
index 132674d..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.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);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Byte_MinValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Byte valueRead = config.get("tests.converter.byte.min", Byte.class);
- assertTrue(valueRead!=null);
- assertEquals(Byte.MIN_VALUE, valueRead.byteValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Byte_MaxValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Byte valueRead = config.get("tests.converter.byte.max", Byte.class);
- assertTrue(valueRead!=null);
- assertEquals(Byte.MAX_VALUE, valueRead.byteValue());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
deleted file mode 100644
index f27a465..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests conversion of the {@link CharConverter}.
- */
-public class CharConverterTest {
-
- @Test
- public void testConvert_Character() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.f", Character.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.charValue(), 'f');
- }
-
- @Test
- public void testConvert_Character_Numeric() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.f-numeric", Character.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.charValue(), (char)101);
- }
-
- @Test
- public void testConvert_Character_Quoted() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.d", Character.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.charValue(), 'd');
- }
-
- @Test
- public void testConvert_Character_WithWhitspace_Before() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.f-before", Character.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.charValue(), 'f');
- }
-
- @Test
- public void testConvert_Character_WithWhitspace_After() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.f-after", Character.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.charValue(), 'f');
- }
-
- @Test
- public void testConvert_Character_WithWhitspace_Around() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.f-around", Character.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.charValue(), 'f');
- }
-
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Character valueRead = config.get("tests.converter.char.foo", Character.class);
- assertNull(valueRead);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
deleted file mode 100644
index 26ad140..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.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 "ConverterTestsPropertySource";
- }
-
- @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";
- case "tests.converter.byte.min":
- return "min";
- case "tests.converter.byte.max":
- return "MAX_Value";
- // 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";
- // Character
- case "tests.converter.char.f":
- return "f";
- case "tests.converter.char.d":
- return "'d'";
- case "tests.converter.char.f-before":
- return " f";
- case "tests.converter.char.f-after":
- return "f ";
- case "tests.converter.char.f-around":
- return " f ";
- case "tests.converter.char.f-numeric":
- return "101";
- // currency
- case "tests.converter.currency.code1":
- return "CHF";
- case "tests.converter.currency.code2":
- return "cHf";
- case "tests.converter.currency.code3":
- return " CHF";
- case "tests.converter.currency.code4":
- return "CHF ";
- case "tests.converter.currency.code5":
- return " CHF ";
- case "tests.converter.currency.code-numeric1":
- return "100";
- case "tests.converter.currency.code-numeric2":
- return " 100";
- case "tests.converter.currency.code-numeric3":
- return "100 ";
- case "tests.converter.currency.code-numeric4":
- return " 100 ";
- case "tests.converter.currency.code-locale1":
- return "DE";
- case "tests.converter.currency.code-locale2":
- return " DE";
- case "tests.converter.currency.code-locale3":
- return "DE ";
- case "tests.converter.currency.code-locale4":
- return " DE ";
- //double
- case "tests.converter.double.decimal":
- return "1.23456789";
- case "tests.converter.double.decimalNegative":
- return "-1.23456789";
- case "tests.converter.double.integer":
- return " 100";
- case "tests.converter.double.hex1":
- return " 0XFF";
- case "tests.converter.double.hex2":
- return "-0xFF ";
- case "tests.converter.double.hex3":
- return "#FF";
- case "tests.converter.double.octal":
- return "0013";
- case "tests.converter.double.min":
- return "MIN_Value";
- case "tests.converter.double.max":
- return "max";
- case "tests.converter.double.nan":
- return "NAN";
- case "tests.converter.double.pi":
- return "positive_infinity";
- case "tests.converter.double.ni":
- return "Negative_Infinity";
- //float
- case "tests.converter.float.decimal":
- return "1.23456789";
- case "tests.converter.float.decimalNegative":
- return "-1.23456789";
- case "tests.converter.float.integer":
- return " 100";
- case "tests.converter.float.hex1":
- return " 0XFF";
- case "tests.converter.float.hex2":
- return "-0xFF ";
- case "tests.converter.float.hex3":
- return "#FF";
- case "tests.converter.float.octal":
- return "0013";
- case "tests.converter.float.min":
- return "MIN_Value";
- case "tests.converter.float.max":
- return "max";
- case "tests.converter.float.nan":
- return "NAN";
- case "tests.converter.float.pi":
- return "positive_infinity";
- case "tests.converter.float.ni":
- return "Negative_Infinity";
- // Integer
- case "tests.converter.integer.decimal":
- return "101";
- case "tests.converter.integer.octal":
- return "02";
- case "tests.converter.integer.hex.lowerX":
- return "0x2F";
- case "tests.converter.integer.hex.upperX":
- return "0X3F";
- case "tests.converter.integer.min":
- return "min";
- case "tests.converter.integer.max":
- return "MAX_Value";
- // Long
- case "tests.converter.long.decimal":
- return "101";
- case "tests.converter.long.octal":
- return "02";
- case "tests.converter.long.hex.lowerX":
- return "0x2F";
- case "tests.converter.long.hex.upperX":
- return "0X3F";
- case "tests.converter.long.min":
- return "min";
- case "tests.converter.long.max":
- return "MAX_Value";
- // Short
- case "tests.converter.short.decimal":
- return "101";
- case "tests.converter.short.octal":
- return "02";
- case "tests.converter.short.hex.lowerX":
- return "0x2F";
- case "tests.converter.short.hex.upperX":
- return "0X3F";
- case "tests.converter.short.min":
- return "min";
- case "tests.converter.short.max":
- return "MAX_Value";
- // BigDecimal
- case "tests.converter.bd.decimal":
- return "101";
- case "tests.converter.bd.float":
- return "101.36438746";
- case "tests.converter.bd.big":
- return "101666666666666662333337263723628763821638923628193612983618293628763";
- case "tests.converter.bd.bigFloat":
- return "1016666666666666623333372637236287638216389293628763.101666666666666662333337263723628763821638923628193612983618293628763";
- case "tests.converter.bd.hex.lowerX":
- return "0x2F";
- case "tests.converter.bd.hex.upperX":
- return "0X3F";
- }
- return null;
- }
-
- @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/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java
deleted file mode 100644
index 9113ca2..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import java.util.Currency;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests the default converter for bytes.
- */
-public class CurrencyConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_CHF() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code1", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, Currency.getInstance("CHF"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_cHf() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code2", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, Currency.getInstance("CHF"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_CHF_Whitespace_Before() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code3", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, Currency.getInstance("CHF"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_CHF_Whitespace_After() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code4", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, Currency.getInstance("CHF"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_CHF_Whitespace_Around() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code5", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead, Currency.getInstance("CHF"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_Numeric() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code-numeric1", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
- valueRead = config.get("tests.converter.currency.code-numeric2", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
- valueRead = config.get("tests.converter.currency.code-numeric3", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
- valueRead = config.get("tests.converter.currency.code-numeric4", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Currency_Code_Locale() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Currency valueRead = config.get("tests.converter.currency.code-locale1", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getCurrencyCode(), "EUR");
- valueRead = config.get("tests.converter.currency.code-locale2", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getCurrencyCode(), "EUR");
- valueRead = config.get("tests.converter.currency.code-locale3", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getCurrencyCode(), "EUR");
- valueRead = config.get("tests.converter.currency.code-locale4", Currency.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.getCurrencyCode(), "EUR");
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Byte valueRead = config.get("tests.converter.byte.foo", Byte.class);
- assertFalse(valueRead!=null);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java
deleted file mode 100644
index ee2f33a..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests the default converter for bytes.
- */
-public class DoubleConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.decimal", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.doubleValue(), 1.23456789, 0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_DecimalNegative() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.decimalNegative", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.doubleValue(), -1.23456789, 0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_Integer() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.integer", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.doubleValue(),100d, 0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_Hex1() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.hex1", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.doubleValue(),255d, 0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_Hex2() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.hex2", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.doubleValue(),-255d, 0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_Hex3() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.hex3", Double.class);
- assertTrue(valueRead!=null);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_MinValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.min", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(Double.MIN_VALUE, valueRead.doubleValue(),0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_MaxValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.max", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(Double.MAX_VALUE, valueRead.doubleValue(),0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_NaNValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.nan", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(Double.NaN, valueRead.doubleValue(),0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_PositiveInfinityValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.pi", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(Double.POSITIVE_INFINITY, valueRead.doubleValue(),0.0d);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Double_NegativeInfinityValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Double valueRead = config.get("tests.converter.double.ni", Double.class);
- assertTrue(valueRead!=null);
- assertEquals(Double.NEGATIVE_INFINITY, valueRead.doubleValue(),0.0d);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java
deleted file mode 100644
index 208baa0..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConversionContext;
-import org.junit.Test;
-
-import java.math.RoundingMode;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-/**
- * Test class testing the {@link EnumConverter} class.
- */
-public class EnumConverterTest {
-
- private EnumConverter testConverter = new EnumConverter(RoundingMode.class);
-
- private ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class)).build();
-
- @Test
- public void testConvert() {
- assertEquals(testConverter.convert(RoundingMode.CEILING.toString(),
- DUMMY_CONTEXT), RoundingMode.CEILING);
- }
-
- @Test
- public void testConvert_LowerCase() {
- assertEquals(testConverter.convert("ceiling", DUMMY_CONTEXT), RoundingMode.CEILING);
- }
-
- @Test
- public void testConvert_MixedCase() {
- assertEquals(testConverter.convert("CeiLinG", DUMMY_CONTEXT), RoundingMode.CEILING);
- }
-
- @Test
- public void testConvert_OtherValue() {
- assertNull(testConverter.convert("fooBars", DUMMY_CONTEXT));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java
deleted file mode 100644
index 98ea720..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests the default converter for bytes.
- */
-public class FloatConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.decimal", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.floatValue(), 1.23456789f, 0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_DecimalNegative() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.decimalNegative", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.floatValue(), -1.23456789f, 0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_Integer() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.integer", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.floatValue(),100f, 0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_Hex1() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.hex1", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.floatValue(),255f, 0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_Hex2() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.hex2", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.floatValue(),-255f, 0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_Hex3() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.hex3", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead.floatValue(),255f, 0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_MinValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.min", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(Float.MIN_VALUE, valueRead.floatValue(),0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_MaxValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.max", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(Float.MAX_VALUE, valueRead.floatValue(),0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_NaNValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.nan", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(Float.NaN, valueRead.floatValue(),0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_PositiveInfinityValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.pi", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(Float.POSITIVE_INFINITY, valueRead.floatValue(),0.0f);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Float_NegativeInfinityValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Float valueRead = config.get("tests.converter.float.ni", Float.class);
- assertTrue(valueRead!=null);
- assertEquals(Float.NEGATIVE_INFINITY, valueRead.floatValue(),0.0f);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java
deleted file mode 100644
index 03b0f12..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.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 Integers.
- */
-public class IntegerConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Integer_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Integer valueRead = config.get("tests.converter.integer.decimal", Integer.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), 101);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Integer_Octal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Integer valueRead = config.get("tests.converter.integer.octal", Integer.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Integer.decode("02").intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Integer_Hex() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Integer valueRead = config.get("tests.converter.integer.hex.lowerX", Integer.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Integer.decode("0x2F").intValue());
- valueRead = config.get("tests.converter.integer.hex.upperX", Integer.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Integer.decode("0X3F").intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Integer valueRead = config.get("tests.converter.integer.foo", Integer.class);
- assertFalse(valueRead != null);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Integer_MinValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Integer valueRead = config.get("tests.converter.integer.min", Integer.class);
- assertTrue(valueRead != null);
- assertEquals(Integer.MIN_VALUE, valueRead.intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Integer_MaxValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Integer valueRead = config.get("tests.converter.integer.max", Integer.class);
- assertTrue(valueRead != null);
- assertEquals(Integer.MAX_VALUE, valueRead.intValue());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java
deleted file mode 100644
index 0df6b09..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.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 Longs.
- */
-public class LongConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Long_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Long valueRead = config.get("tests.converter.long.decimal", Long.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), 101);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Long_Octal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Long valueRead = config.get("tests.converter.long.octal", Long.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Long.decode("02").intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Long_Hex() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Long valueRead = config.get("tests.converter.long.hex.lowerX", Long.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Long.decode("0x2F").intValue());
- valueRead = config.get("tests.converter.long.hex.upperX", Long.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Long.decode("0X3F").intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Long valueRead = config.get("tests.converter.long.foo", Long.class);
- assertFalse(valueRead != null);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Long_MinValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Long valueRead = config.get("tests.converter.long.min", Long.class);
- assertTrue(valueRead != null);
- assertEquals(Long.MIN_VALUE, valueRead.longValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Long_MaxValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Long valueRead = config.get("tests.converter.long.max", Long.class);
- assertTrue(valueRead != null);
- assertEquals(Long.MAX_VALUE, valueRead.longValue());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java
deleted file mode 100644
index 25e6fd9..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import java.math.BigDecimal;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests the default converter for Number.
- */
-public class NumberConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Number valueRead = config.get("tests.converter.bd.decimal", Number.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead, Long.valueOf(101));
- }
-
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Hex() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Number valueRead = config.get("tests.converter.bd.hex.lowerX", Number.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead, Long.valueOf("47"));
- valueRead = config.get("tests.converter.bd.hex.upperX", Number.class);
- assertTrue(valueRead!=null);
- assertEquals(valueRead, Long.valueOf("63"));
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Number valueRead = config.get("tests.converter.bd.foo", Number.class);
- assertFalse(valueRead!=null);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_BigValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Number valueRead = config.get("tests.converter.bd.big", Number.class);
- assertTrue(valueRead!=null);
- assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"),
- valueRead);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_BigFloatValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Number valueRead = config.get("tests.converter.bd.bigFloat", Number.class);
- assertTrue(valueRead!=null);
- assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" +
- "63723628763821638923628193612983618293628763"), valueRead);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java b/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java
deleted file mode 100644
index 193a92e..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.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 Shorts.
- */
-public class ShortConverterTest {
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Short_Decimal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Short valueRead = config.get("tests.converter.short.decimal", Short.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), 101);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Short_Octal() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Short valueRead = config.get("tests.converter.short.octal", Short.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Short.decode("02").intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Short_Hex() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Short valueRead = config.get("tests.converter.short.hex.lowerX", Short.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Short.decode("0x2F").intValue());
- valueRead = config.get("tests.converter.short.hex.upperX", Short.class);
- assertTrue(valueRead != null);
- assertEquals(valueRead.intValue(), Short.decode("0X3F").intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_NotPresent() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Short valueRead = config.get("tests.converter.short.foo", Short.class);
- assertFalse(valueRead != null);
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Short_MinValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Short valueRead = config.get("tests.converter.short.min", Short.class);
- assertTrue(valueRead != null);
- assertEquals(Short.MIN_VALUE, valueRead.intValue());
- }
-
- /**
- * Test conversion. The value are provided by
- * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
- * @throws Exception
- */
- @Test
- public void testConvert_Short_MaxValue() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Short valueRead = config.get("tests.converter.short.max", Short.class);
- assertTrue(valueRead != null);
- assertEquals(Short.MAX_VALUE, valueRead.intValue());
- }
-}
\ No newline at end of file
[5/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java
new file mode 100644
index 0000000..ee2f33a
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/DoubleConverterTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class DoubleConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.decimal", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.doubleValue(), 1.23456789, 0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_DecimalNegative() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.decimalNegative", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.doubleValue(), -1.23456789, 0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_Integer() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.integer", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.doubleValue(),100d, 0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_Hex1() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.hex1", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.doubleValue(),255d, 0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_Hex2() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.hex2", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.doubleValue(),-255d, 0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_Hex3() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.hex3", Double.class);
+ assertTrue(valueRead!=null);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_MinValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.min", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Double.MIN_VALUE, valueRead.doubleValue(),0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_MaxValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.max", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Double.MAX_VALUE, valueRead.doubleValue(),0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_NaNValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.nan", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Double.NaN, valueRead.doubleValue(),0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_PositiveInfinityValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.pi", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Double.POSITIVE_INFINITY, valueRead.doubleValue(),0.0d);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Double_NegativeInfinityValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Double valueRead = config.get("tests.converter.double.ni", Double.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Double.NEGATIVE_INFINITY, valueRead.doubleValue(),0.0d);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.java
new file mode 100644
index 0000000..208baa0
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/EnumConverterTest.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.internal.converters;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.junit.Test;
+
+import java.math.RoundingMode;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test class testing the {@link EnumConverter} class.
+ */
+public class EnumConverterTest {
+
+ private EnumConverter testConverter = new EnumConverter(RoundingMode.class);
+
+ private ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class)).build();
+
+ @Test
+ public void testConvert() {
+ assertEquals(testConverter.convert(RoundingMode.CEILING.toString(),
+ DUMMY_CONTEXT), RoundingMode.CEILING);
+ }
+
+ @Test
+ public void testConvert_LowerCase() {
+ assertEquals(testConverter.convert("ceiling", DUMMY_CONTEXT), RoundingMode.CEILING);
+ }
+
+ @Test
+ public void testConvert_MixedCase() {
+ assertEquals(testConverter.convert("CeiLinG", DUMMY_CONTEXT), RoundingMode.CEILING);
+ }
+
+ @Test
+ public void testConvert_OtherValue() {
+ assertNull(testConverter.convert("fooBars", DUMMY_CONTEXT));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java
new file mode 100644
index 0000000..98ea720
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/FloatConverterTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class FloatConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.decimal", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.floatValue(), 1.23456789f, 0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_DecimalNegative() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.decimalNegative", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.floatValue(), -1.23456789f, 0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_Integer() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.integer", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.floatValue(),100f, 0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_Hex1() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.hex1", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.floatValue(),255f, 0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_Hex2() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.hex2", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.floatValue(),-255f, 0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_Hex3() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.hex3", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.floatValue(),255f, 0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_MinValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.min", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Float.MIN_VALUE, valueRead.floatValue(),0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_MaxValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.max", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Float.MAX_VALUE, valueRead.floatValue(),0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_NaNValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.nan", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Float.NaN, valueRead.floatValue(),0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_PositiveInfinityValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.pi", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Float.POSITIVE_INFINITY, valueRead.floatValue(),0.0f);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Float_NegativeInfinityValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Float valueRead = config.get("tests.converter.float.ni", Float.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Float.NEGATIVE_INFINITY, valueRead.floatValue(),0.0f);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java
new file mode 100644
index 0000000..03b0f12
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/IntegerConverterTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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 Integers.
+ */
+public class IntegerConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Integer_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Integer valueRead = config.get("tests.converter.integer.decimal", Integer.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), 101);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Integer_Octal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Integer valueRead = config.get("tests.converter.integer.octal", Integer.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Integer.decode("02").intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Integer_Hex() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Integer valueRead = config.get("tests.converter.integer.hex.lowerX", Integer.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Integer.decode("0x2F").intValue());
+ valueRead = config.get("tests.converter.integer.hex.upperX", Integer.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Integer.decode("0X3F").intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Integer valueRead = config.get("tests.converter.integer.foo", Integer.class);
+ assertFalse(valueRead != null);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Integer_MinValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Integer valueRead = config.get("tests.converter.integer.min", Integer.class);
+ assertTrue(valueRead != null);
+ assertEquals(Integer.MIN_VALUE, valueRead.intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Integer_MaxValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Integer valueRead = config.get("tests.converter.integer.max", Integer.class);
+ assertTrue(valueRead != null);
+ assertEquals(Integer.MAX_VALUE, valueRead.intValue());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java
new file mode 100644
index 0000000..0df6b09
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/LongConverterTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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 Longs.
+ */
+public class LongConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Long_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Long valueRead = config.get("tests.converter.long.decimal", Long.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), 101);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Long_Octal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Long valueRead = config.get("tests.converter.long.octal", Long.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Long.decode("02").intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Long_Hex() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Long valueRead = config.get("tests.converter.long.hex.lowerX", Long.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Long.decode("0x2F").intValue());
+ valueRead = config.get("tests.converter.long.hex.upperX", Long.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Long.decode("0X3F").intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Long valueRead = config.get("tests.converter.long.foo", Long.class);
+ assertFalse(valueRead != null);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Long_MinValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Long valueRead = config.get("tests.converter.long.min", Long.class);
+ assertTrue(valueRead != null);
+ assertEquals(Long.MIN_VALUE, valueRead.longValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Long_MaxValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Long valueRead = config.get("tests.converter.long.max", Long.class);
+ assertTrue(valueRead != null);
+ assertEquals(Long.MAX_VALUE, valueRead.longValue());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java
new file mode 100644
index 0000000..25e6fd9
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/NumberConverterTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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 java.math.BigDecimal;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the default converter for Number.
+ */
+public class NumberConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Number valueRead = config.get("tests.converter.bd.decimal", Number.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead, Long.valueOf(101));
+ }
+
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Hex() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Number valueRead = config.get("tests.converter.bd.hex.lowerX", Number.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead, Long.valueOf("47"));
+ valueRead = config.get("tests.converter.bd.hex.upperX", Number.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead, Long.valueOf("63"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Number valueRead = config.get("tests.converter.bd.foo", Number.class);
+ assertFalse(valueRead!=null);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_BigValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Number valueRead = config.get("tests.converter.bd.big", Number.class);
+ assertTrue(valueRead!=null);
+ assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"),
+ valueRead);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_BigFloatValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Number valueRead = config.get("tests.converter.bd.bigFloat", Number.class);
+ assertTrue(valueRead!=null);
+ assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" +
+ "63723628763821638923628193612983618293628763"), valueRead);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java
new file mode 100644
index 0000000..193a92e
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ShortConverterTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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 Shorts.
+ */
+public class ShortConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Short_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Short valueRead = config.get("tests.converter.short.decimal", Short.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), 101);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Short_Octal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Short valueRead = config.get("tests.converter.short.octal", Short.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Short.decode("02").intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Short_Hex() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Short valueRead = config.get("tests.converter.short.hex.lowerX", Short.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Short.decode("0x2F").intValue());
+ valueRead = config.get("tests.converter.short.hex.upperX", Short.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.intValue(), Short.decode("0X3F").intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Short valueRead = config.get("tests.converter.short.foo", Short.class);
+ assertFalse(valueRead != null);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Short_MinValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Short valueRead = config.get("tests.converter.short.min", Short.class);
+ assertTrue(valueRead != null);
+ assertEquals(Short.MIN_VALUE, valueRead.intValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Short_MaxValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Short valueRead = config.get("tests.converter.short.max", Short.class);
+ assertTrue(valueRead != null);
+ assertEquals(Short.MAX_VALUE, valueRead.intValue());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..8d3f086
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.propertysource.BasePropertySource;
+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(56) {
+
+ @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(56, 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() {
+ super(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() {
+ super(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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
new file mode 100644
index 0000000..280351e
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}.
+ */
+public class EnvironmentPropertySourceTest {
+
+ private EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+ assertEquals(EnvironmentPropertySource.DEFAULT_ORDINAL, envPropertySource.getOrdinal());
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ assertEquals("environment-properties", envPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
+ assertEquals(envPropertySource.get(envEntry.getKey()), envEntry.getValue());
+ }
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Map<String, String> props = envPropertySource.getProperties();
+ assertEquals(System.getenv(), props);
+ }
+
+ @Test
+ public void testIsScannable() throws Exception {
+ assertTrue(envPropertySource.isScannable());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..36b0f5d
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.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.propertysource;
+
+import org.apache.tamaya.core.propertysource.SimplePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PropertiesFilePropertySourceTest {
+
+ private SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
+ .getContextClassLoader().getResource("testfile.properties"));
+ private SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
+ Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(0, 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 {
+ Assert.assertEquals(5, testfilePropertySource.getProperties().size());
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..c627972
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.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(SystemPropertySource.DEFAULT_ORDINAL, 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", testPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ String property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
+ SystemPropertySource.class.getSimpleName(), property);
+ 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());
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..f099da4
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/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.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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
new file mode 100644
index 0000000..6c8751c
--- /dev/null
+++ b/code/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() {
+ super(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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
new file mode 100644
index 0000000..6faa831
--- /dev/null
+++ b/code/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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
new file mode 100644
index 0000000..5706478
--- /dev/null
+++ b/code/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() {
+ super(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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java
new file mode 100644
index 0000000..5a57ad1
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.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.core.testdata;
+
+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 TestRemovingPropertyFilter 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/eadbfe97/code/core/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/javaconfiguration.properties b/code/core/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..33beabb
--- /dev/null
+++ b/code/core/src/test/resources/META-INF/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/eadbfe97/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
new file mode 100644
index 0000000..f203fa6
--- /dev/null
+++ b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
@@ -0,0 +1,18 @@
+# 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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
new file mode 100644
index 0000000..b144790
--- /dev/null
+++ b/code/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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..d039696
--- /dev/null
+++ b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -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.CTestConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..18e61cb
--- /dev/null
+++ b/code/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.TestRemovingPropertyFilter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..409c9cb
--- /dev/null
+++ b/code/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/eadbfe97/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..9c352f4
--- /dev/null
+++ b/code/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/eadbfe97/code/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/overrideOrdinal.properties b/code/core/src/test/resources/overrideOrdinal.properties
new file mode 100644
index 0000000..96935a8
--- /dev/null
+++ b/code/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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/testfile.properties b/code/core/src/test/resources/testfile.properties
new file mode 100644
index 0000000..abd7ee8
--- /dev/null
+++ b/code/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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/resources/x34.properties
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/x34.properties b/code/core/src/test/resources/x34.properties
new file mode 100644
index 0000000..f2c4a0a
--- /dev/null
+++ b/code/core/src/test/resources/x34.properties
@@ -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.
+
+x34=x34
+x34.a.b.c=C
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/pom.xml
----------------------------------------------------------------------
diff --git a/code/pom.xml b/code/pom.xml
index fe2a58e..fe14514 100644
--- a/code/pom.xml
+++ b/code/pom.xml
@@ -35,6 +35,7 @@ under the License.
<modules>
<module>api</module>
+ <module>core</module>
</modules>
<build>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
deleted file mode 100644
index 5c8d85a..0000000
--- a/core/pom.xml
+++ /dev/null
@@ -1,103 +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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-all</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>tamaya-core</artifactId>
- <name>Apache Tamaya Core Implementation</name>
- <packaging>bundle</packaging>
-
- <properties>
- <osgi.compendium.version>5.0.0</osgi.compendium.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-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>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <scope>provided</scope>
- <version>${osgi.compendium.version}</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${osgi.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Import-Package>
- org.apache.tamaya,
- org.apache.tamaya.spi,
- javax.annotation,
- *
- </Import-Package>
- <Private-Package>
- org.apache.tamaya.core.internal,
- org.apache.tamaya.core.internal.converters
- </Private-Package>
- <Export-Package>
- org.apache.tamaya.core,
- org.apache.tamaya.core.propertysource,
- org.apache.tamaya.core.provider
- </Export-Package>
- <Bundle-Activator>
- org.apache.tamaya.core.internal.OSGIActivator
- </Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
[6/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
new file mode 100644
index 0000000..e9f53f9
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
@@ -0,0 +1,85 @@
+/*
+ * 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.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Abstract {@link org.apache.tamaya.spi.PropertySource} that allows to set a default ordinal that will be used, if no
+ * ordinal is provided with the config.
+ */
+public abstract class BasePropertySource implements PropertySource{
+ /** default ordinal that will be used, if no ordinal is provided with the config. */
+ private final int defaultOrdinal;
+
+ /**
+ * Constructor.
+ * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config.
+ */
+ protected BasePropertySource(int defaultOrdinal){
+ this.defaultOrdinal = defaultOrdinal;
+ }
+
+ /**
+ * Constructor, using a default ordinal of 0.
+ */
+ protected BasePropertySource(){
+ this(0);
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getSimpleName();
+ }
+
+ @Override
+ public int getOrdinal() {
+ String configuredOrdinal = get(TAMAYA_ORDINAL);
+ if(configuredOrdinal!=null){
+ try{
+ return Integer.parseInt(configuredOrdinal);
+ } catch(Exception e){
+ Logger.getLogger(getClass().getName()).log(Level.WARNING,
+ "Configured Ordinal is not an int number: " + configuredOrdinal, e);
+ }
+ }
+ return getDefaultOrdinal();
+ }
+
+ /**
+ * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
+ * @return the default ordinal used, by default 0.
+ */
+ public int getDefaultOrdinal(){
+ return defaultOrdinal;
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public boolean isScannable(){
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java b/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
new file mode 100644
index 0000000..a8a1b11
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import org.apache.tamaya.spi.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 implements PropertySource {
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}
+ */
+ public static final int DEFAULT_ORDINAL = 300;
+
+ @Override
+ public int getOrdinal() {
+ return DEFAULT_ORDINAL;
+ }
+
+ @Override
+ public String getName() {
+ return "environment-properties";
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @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/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
new file mode 100644
index 0000000..3ae4f2d
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
@@ -0,0 +1,128 @@
+/*
+ * 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.ConfigException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+
+/**
+ * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for properties-files.
+ */
+public class SimplePropertySource extends BasePropertySource {
+ /**
+ * The property source name.
+ */
+ private String name;
+ /**
+ * The current properties.
+ */
+ private Map<String, String> properties;
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public SimplePropertySource(File propertiesLocation) {
+ super(0);
+ try {
+ this.properties = load(propertiesLocation.toURI().toURL());
+ this.name = propertiesLocation.toString();
+ } catch (IOException e) {
+ throw new ConfigException("Failed to load properties from " + propertiesLocation, e);
+ }
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public SimplePropertySource(URL propertiesLocation) {
+ super(0);
+ this.properties = load(propertiesLocation);
+ this.name = propertiesLocation.toExternalForm();
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given properties map.
+ *
+ * @param name the name, not null.
+ * @param properties the properties, not null.
+ */
+ public SimplePropertySource(String name, Map<String, String> properties) {
+ super(0);
+ this.properties = new HashMap<>(properties);
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param name The property source name
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public SimplePropertySource(String name, URL propertiesLocation) {
+ super(0);
+ this.properties = load(propertiesLocation);
+ this.name = Objects.requireNonNull(name);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.properties;
+ }
+
+ /**
+ * 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
+ */
+ private Map<String, String> load(URL propertiesFile) {
+ Map<String, String> properties = new HashMap<>();
+ try (InputStream stream = propertiesFile.openStream()) {
+ Properties props = new Properties();
+ if (stream != null) {
+ props.load(stream);
+ }
+ for (String key : props.stringPropertyNames()) {
+ properties.put(key, props.getProperty(key));
+ }
+ } catch (IOException e) {
+ throw new ConfigException("Error loading properties " + propertiesFile, e);
+ }
+ return properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
new file mode 100644
index 0000000..9093f25
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -0,0 +1,93 @@
+/*
+ * 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.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
+ */
+public class SystemPropertySource implements PropertySource {
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
+ */
+ public static final int DEFAULT_ORDINAL = 1000;
+
+ private volatile Map<String,String> cachedProperties;
+
+ /**
+ * previous System.getProperties().hashCode()
+ * so we can check if we need to reload
+ */
+ private int previousHash;
+
+
+ public SystemPropertySource() {
+ cachedProperties = loadProperties();
+ previousHash = System.getProperties().hashCode();
+ }
+
+ private Map<String, String> loadProperties() {
+ Map<String,String> props = new HashMap<>();
+ Properties sysProps = System.getProperties();
+ for(String name: sysProps.stringPropertyNames()) {
+ props.put(name,sysProps.getProperty(name));
+ }
+ return props;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return DEFAULT_ORDINAL;
+ }
+
+ @Override
+ public String getName() {
+ return "system-properties";
+ }
+
+ @Override
+ public String get(String key) {
+ return getProperties().get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ // only need to reload and fill our map if something has changed
+ // synchronization was removed, Instance was marked as volatile. In the worst case it
+ // is reloaded twice, but the values will be the same.
+ if (previousHash != System.getProperties().hashCode()) {
+ Map<String, String> properties = loadProperties();
+ this.cachedProperties = Collections.unmodifiableMap(properties);
+ previousHash = System.getProperties().hashCode();
+ }
+ return this.cachedProperties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
new file mode 100644
index 0000000..9c04926
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
@@ -0,0 +1,61 @@
+/*
+ * 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 org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.propertysource.SimplePropertySource;
+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.Enumeration;
+import java.util.List;
+
+/**
+ * Provider which reads all {@code javaconfiguration.properties} files from classpath
+ */
+public class JavaConfigurationProvider implements PropertySourceProvider {
+ /** Default location in the classpath, where Tamaya looks for configuration by default. */
+ public static final String DEFAULT_PROPERTIES_FILE_NAME="META-INF/javaconfiguration.properties";
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ List<PropertySource> propertySources = new ArrayList<>();
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if(cl!=null) {
+ Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
+ .getResources(DEFAULT_PROPERTIES_FILE_NAME);
+ while (urls.hasMoreElements()) {
+ propertySources.add(new SimplePropertySource(urls.nextElement()));
+ }
+ }
+
+ } 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/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..e51a247
--- /dev/null
+++ b/code/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
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
new file mode 100644
index 0000000..4efa42e
--- /dev/null
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
@@ -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.DefaultConfigurationContextBuilder
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..7c0e249
--- /dev/null
+++ b/code/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/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..93f7b11
--- /dev/null
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,33 @@
+#
+# 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.ClassConverter
+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
+org.apache.tamaya.core.internal.converters.URIConverter
+org.apache.tamaya.core.internal.converters.URLConverter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..1b8f8c0
--- /dev/null
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -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.propertysource.EnvironmentPropertySource
+org.apache.tamaya.core.propertysource.SystemPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..4535a09
--- /dev/null
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -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.provider.JavaConfigurationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..f8e7e7f
--- /dev/null
+++ b/code/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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
new file mode 100644
index 0000000..98bb29c
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.ConfigurationProvider;
+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 ConfigurationProvider.getConfiguration();
+ }
+
+ @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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/A.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/A.java b/code/core/src/test/java/org/apache/tamaya/core/internal/A.java
new file mode 100644
index 0000000..aa77a5d
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/A.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Test class for testing transitively evaluated property converters.
+ */
+public class A implements AutoCloseable{
+ @Override
+ public void close() throws Exception {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/B.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/B.java b/code/core/src/test/java/org/apache/tamaya/core/internal/B.java
new file mode 100644
index 0000000..31bafb6
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/B.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Test class for testing transitively evaluated property converters.
+ */
+public class B extends A implements Runnable{
+ @Override
+ public void run() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/C.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/C.java b/code/core/src/test/java/org/apache/tamaya/core/internal/C.java
new file mode 100644
index 0000000..aad1ef9
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/C.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.internal;
+
+import java.io.IOException;
+import java.nio.CharBuffer;
+
+/**
+ * Test class for testing transitively evaluated property converters.
+ */
+public class C extends B implements Readable{
+
+ private String inValue;
+
+ public C(String inValue){
+ this.inValue = inValue;
+ }
+
+ @Override
+ public int read(CharBuffer cb) throws IOException {
+ return 0;
+ }
+
+ /**
+ * Returns the input value, set on creation. Used for test assertion.
+ * @return the in value.
+ */
+ public String getInValue() {
+ return inValue;
+ }
+
+ @Override
+ public String toString() {
+ return "C{" +
+ "inValue='" + inValue + '\'' +
+ '}';
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java
new file mode 100644
index 0000000..7ee2a35
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+/**
+ * Created by Anatole on 13.06.2015.
+ */
+public class CTestConverter implements PropertyConverter<C>{
+ @Override
+ public C convert(String value, ConversionContext context) {
+ return new C(value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
new file mode 100644
index 0000000..1d24884
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+import java.util.Collection;
+import java.util.List;
+
+public class DefaultServiceContextTest {
+
+ /**
+ * context to test
+ */
+ private DefaultServiceContext context = new DefaultServiceContext();
+
+
+ @Test
+ public void testGetService() {
+ ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
+ Assert.assertNotNull(providerSpi);
+ Assert.assertTrue(providerSpi instanceof DefaultConfigurationProvider);
+ }
+
+ @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() {
+ {
+ Collection<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);
+ }
+ }
+
+ {
+ Collection<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_redundantAccessToServices() {
+ for(int i=0;i<10;i++){
+ Collection<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);
+ }
+ }
+ }
+
+ @Test
+ public void testGetServices_noImpl_shouldReturnEmptyList() {
+ Collection<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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
new file mode 100644
index 0000000..82d834a
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/PropertyConverterManagerTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.ConfigurationProvider;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+
+public class PropertyConverterManagerTest {
+
+ private ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder(
+ "someKey", TypeLiteral.of(Object.class)).build();
+
+ @Test
+ public void customTypeWithFactoryMethodOfIsRecognizedAsSupported() {
+ PropertyConverterManager manager = new PropertyConverterManager();
+
+ assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class)),
+ is(true));
+ }
+
+ @Test
+ public void factoryMethodOfIsUsedAsConverter() {
+ PropertyConverterManager manager = new PropertyConverterManager();
+
+ List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
+ (TypeLiteral)TypeLiteral.of(MyType.class));
+
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<MyType> converter = converters.get(0);
+
+ Object result = converter.convert("IN", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(MyType.class));
+ assertThat(((MyType)result).getValue(), equalTo("IN"));
+ }
+
+ @Test
+ public void testDirectConverterMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<C>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<C> converter = converters.get(0);
+ C result = converter.convert("testDirectConverterMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testDirectConverterMapping"));
+ }
+
+ @Test
+ public void testDirectSuperclassConverterMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+ converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<B> converter = converters.get(0);
+ B result = converter.convert("testDirectSuperclassConverterMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testDirectSuperclassConverterMapping"));
+ }
+
+ @Test
+ public void testMultipleConverterLoad(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+ manager = new PropertyConverterManager();
+ converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+ }
+
+ @Test
+ public void testTransitiveSuperclassConverterMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<A> converter = converters.get(0);
+ A result = converter.convert("testTransitiveSuperclassConverterMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testTransitiveSuperclassConverterMapping"));
+ }
+
+ @Test
+ public void testDirectInterfaceMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<Readable> converter = converters.get(0);
+ Readable result = converter.convert("testDirectInterfaceMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testDirectInterfaceMapping"));
+ }
+
+ @Test
+ public void testTransitiveInterfaceMapping1(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<Runnable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<Runnable> converter = converters.get(0);
+ Runnable result = converter.convert("testTransitiveInterfaceMapping1", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping1"));
+ }
+
+ @Test
+ public void testTransitiveInterfaceMapping2(){
+ PropertyConverterManager manager = new PropertyConverterManager();
+ List<PropertyConverter<AutoCloseable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<AutoCloseable> converter = converters.get(0);
+ AutoCloseable result = converter.convert("testTransitiveInterfaceMapping2", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping2"));
+ }
+
+ public static class MyType {
+ private String typeValue;
+
+ private MyType(String value) {
+ typeValue = value;
+ }
+
+ public static MyType of(String source) {
+ return new MyType(source);
+ }
+
+ public String getValue() {
+ return typeValue;
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
new file mode 100644
index 0000000..9c71688
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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 java.math.BigDecimal;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class BigDecimalConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_BigDecimal_Decimal() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ BigDecimal valueRead = config.get("tests.converter.bd.decimal", BigDecimal.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, new BigDecimal(101));
+ }
+
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_BigDecimal_Hex() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ BigDecimal valueRead = config.get("tests.converter.bd.hex.lowerX", BigDecimal.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, new BigDecimal("47"));
+ valueRead = config.get("tests.converter.bd.hex.upperX", BigDecimal.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, new BigDecimal("63"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ BigDecimal valueRead = config.get("tests.converter.bd.foo", BigDecimal.class);
+ assertFalse(valueRead != null);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_BigDecimal_BigValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ BigDecimal valueRead = config.get("tests.converter.bd.big", BigDecimal.class);
+ assertTrue(valueRead != null);
+ assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"),
+ valueRead);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_BigDecimal_BigFloatValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ BigDecimal valueRead = config.get("tests.converter.bd.bigFloat", BigDecimal.class);
+ assertTrue(valueRead != null);
+ assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" +
+ "63723628763821638923628193612983618293628763"), valueRead);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
new file mode 100644
index 0000000..c3b3f96
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+/**
+ * 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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
new file mode 100644
index 0000000..132674d
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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);
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Byte_MinValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Byte valueRead = config.get("tests.converter.byte.min", Byte.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Byte.MIN_VALUE, valueRead.byteValue());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Byte_MaxValue() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Byte valueRead = config.get("tests.converter.byte.max", Byte.class);
+ assertTrue(valueRead!=null);
+ assertEquals(Byte.MAX_VALUE, valueRead.byteValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
new file mode 100644
index 0000000..f27a465
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests conversion of the {@link CharConverter}.
+ */
+public class CharConverterTest {
+
+ @Test
+ public void testConvert_Character() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.f", Character.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.charValue(), 'f');
+ }
+
+ @Test
+ public void testConvert_Character_Numeric() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.f-numeric", Character.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.charValue(), (char)101);
+ }
+
+ @Test
+ public void testConvert_Character_Quoted() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.d", Character.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.charValue(), 'd');
+ }
+
+ @Test
+ public void testConvert_Character_WithWhitspace_Before() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.f-before", Character.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.charValue(), 'f');
+ }
+
+ @Test
+ public void testConvert_Character_WithWhitspace_After() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.f-after", Character.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.charValue(), 'f');
+ }
+
+ @Test
+ public void testConvert_Character_WithWhitspace_Around() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.f-around", Character.class);
+ assertTrue(valueRead!=null);
+ assertEquals(valueRead.charValue(), 'f');
+ }
+
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Character valueRead = config.get("tests.converter.char.foo", Character.class);
+ assertNull(valueRead);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
new file mode 100644
index 0000000..26ad140
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
@@ -0,0 +1,252 @@
+/*
+ * 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 "ConverterTestsPropertySource";
+ }
+
+ @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";
+ case "tests.converter.byte.min":
+ return "min";
+ case "tests.converter.byte.max":
+ return "MAX_Value";
+ // 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";
+ // Character
+ case "tests.converter.char.f":
+ return "f";
+ case "tests.converter.char.d":
+ return "'d'";
+ case "tests.converter.char.f-before":
+ return " f";
+ case "tests.converter.char.f-after":
+ return "f ";
+ case "tests.converter.char.f-around":
+ return " f ";
+ case "tests.converter.char.f-numeric":
+ return "101";
+ // currency
+ case "tests.converter.currency.code1":
+ return "CHF";
+ case "tests.converter.currency.code2":
+ return "cHf";
+ case "tests.converter.currency.code3":
+ return " CHF";
+ case "tests.converter.currency.code4":
+ return "CHF ";
+ case "tests.converter.currency.code5":
+ return " CHF ";
+ case "tests.converter.currency.code-numeric1":
+ return "100";
+ case "tests.converter.currency.code-numeric2":
+ return " 100";
+ case "tests.converter.currency.code-numeric3":
+ return "100 ";
+ case "tests.converter.currency.code-numeric4":
+ return " 100 ";
+ case "tests.converter.currency.code-locale1":
+ return "DE";
+ case "tests.converter.currency.code-locale2":
+ return " DE";
+ case "tests.converter.currency.code-locale3":
+ return "DE ";
+ case "tests.converter.currency.code-locale4":
+ return " DE ";
+ //double
+ case "tests.converter.double.decimal":
+ return "1.23456789";
+ case "tests.converter.double.decimalNegative":
+ return "-1.23456789";
+ case "tests.converter.double.integer":
+ return " 100";
+ case "tests.converter.double.hex1":
+ return " 0XFF";
+ case "tests.converter.double.hex2":
+ return "-0xFF ";
+ case "tests.converter.double.hex3":
+ return "#FF";
+ case "tests.converter.double.octal":
+ return "0013";
+ case "tests.converter.double.min":
+ return "MIN_Value";
+ case "tests.converter.double.max":
+ return "max";
+ case "tests.converter.double.nan":
+ return "NAN";
+ case "tests.converter.double.pi":
+ return "positive_infinity";
+ case "tests.converter.double.ni":
+ return "Negative_Infinity";
+ //float
+ case "tests.converter.float.decimal":
+ return "1.23456789";
+ case "tests.converter.float.decimalNegative":
+ return "-1.23456789";
+ case "tests.converter.float.integer":
+ return " 100";
+ case "tests.converter.float.hex1":
+ return " 0XFF";
+ case "tests.converter.float.hex2":
+ return "-0xFF ";
+ case "tests.converter.float.hex3":
+ return "#FF";
+ case "tests.converter.float.octal":
+ return "0013";
+ case "tests.converter.float.min":
+ return "MIN_Value";
+ case "tests.converter.float.max":
+ return "max";
+ case "tests.converter.float.nan":
+ return "NAN";
+ case "tests.converter.float.pi":
+ return "positive_infinity";
+ case "tests.converter.float.ni":
+ return "Negative_Infinity";
+ // Integer
+ case "tests.converter.integer.decimal":
+ return "101";
+ case "tests.converter.integer.octal":
+ return "02";
+ case "tests.converter.integer.hex.lowerX":
+ return "0x2F";
+ case "tests.converter.integer.hex.upperX":
+ return "0X3F";
+ case "tests.converter.integer.min":
+ return "min";
+ case "tests.converter.integer.max":
+ return "MAX_Value";
+ // Long
+ case "tests.converter.long.decimal":
+ return "101";
+ case "tests.converter.long.octal":
+ return "02";
+ case "tests.converter.long.hex.lowerX":
+ return "0x2F";
+ case "tests.converter.long.hex.upperX":
+ return "0X3F";
+ case "tests.converter.long.min":
+ return "min";
+ case "tests.converter.long.max":
+ return "MAX_Value";
+ // Short
+ case "tests.converter.short.decimal":
+ return "101";
+ case "tests.converter.short.octal":
+ return "02";
+ case "tests.converter.short.hex.lowerX":
+ return "0x2F";
+ case "tests.converter.short.hex.upperX":
+ return "0X3F";
+ case "tests.converter.short.min":
+ return "min";
+ case "tests.converter.short.max":
+ return "MAX_Value";
+ // BigDecimal
+ case "tests.converter.bd.decimal":
+ return "101";
+ case "tests.converter.bd.float":
+ return "101.36438746";
+ case "tests.converter.bd.big":
+ return "101666666666666662333337263723628763821638923628193612983618293628763";
+ case "tests.converter.bd.bigFloat":
+ return "1016666666666666623333372637236287638216389293628763.101666666666666662333337263723628763821638923628193612983618293628763";
+ case "tests.converter.bd.hex.lowerX":
+ return "0x2F";
+ case "tests.converter.bd.hex.upperX":
+ return "0X3F";
+ }
+ return null;
+ }
+
+ @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/eadbfe97/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java
new file mode 100644
index 0000000..9113ca2
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CurrencyConverterTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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 java.util.Currency;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class CurrencyConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_CHF() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code1", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, Currency.getInstance("CHF"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_cHf() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code2", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, Currency.getInstance("CHF"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_CHF_Whitespace_Before() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code3", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, Currency.getInstance("CHF"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_CHF_Whitespace_After() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code4", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, Currency.getInstance("CHF"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_CHF_Whitespace_Around() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code5", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead, Currency.getInstance("CHF"));
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_Numeric() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code-numeric1", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
+ valueRead = config.get("tests.converter.currency.code-numeric2", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
+ valueRead = config.get("tests.converter.currency.code-numeric3", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
+ valueRead = config.get("tests.converter.currency.code-numeric4", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getNumericCode(), Currency.getInstance("BGL").getNumericCode());
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Currency_Code_Locale() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Currency valueRead = config.get("tests.converter.currency.code-locale1", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getCurrencyCode(), "EUR");
+ valueRead = config.get("tests.converter.currency.code-locale2", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getCurrencyCode(), "EUR");
+ valueRead = config.get("tests.converter.currency.code-locale3", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getCurrencyCode(), "EUR");
+ valueRead = config.get("tests.converter.currency.code-locale4", Currency.class);
+ assertTrue(valueRead != null);
+ assertEquals(valueRead.getCurrencyCode(), "EUR");
+ }
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_NotPresent() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Byte valueRead = config.get("tests.converter.byte.foo", Byte.class);
+ assertFalse(valueRead!=null);
+ }
+}
\ No newline at end of file
[8/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
Moved module core to ./code/
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/eadbfe97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/eadbfe97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/eadbfe97
Branch: refs/heads/master
Commit: eadbfe97395bded760b9492297f31b6421ce2a0f
Parents: 84d52f1
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Sun Dec 20 14:05:42 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Sun Dec 20 14:05:42 2015 +0100
----------------------------------------------------------------------
code/core/pom.xml | 103 +++++
.../core/internal/DefaultConfiguration.java | 197 ++++++++
.../internal/DefaultConfigurationContext.java | 278 ++++++++++++
.../DefaultConfigurationContextBuilder.java | 153 +++++++
.../internal/DefaultConfigurationProvider.java | 68 +++
.../core/internal/DefaultServiceContext.java | 156 +++++++
.../tamaya/core/internal/OSGIActivator.java | 53 +++
.../core/internal/OSGIServiceComparator.java | 69 +++
.../core/internal/OSGIServiceContext.java | 83 ++++
.../tamaya/core/internal/OSGIServiceLoader.java | 158 +++++++
.../internal/PriorityServiceComparator.java | 67 +++
.../core/internal/PropertyConverterManager.java | 448 +++++++++++++++++++
.../core/internal/PropertyFilterComparator.java | 60 +++
.../tamaya/core/internal/PropertyFiltering.java | 131 ++++++
.../core/internal/PropertySourceComparator.java | 54 +++
.../tamaya/core/internal/ReflectionUtil.java | 42 ++
.../converters/BigDecimalConverter.java | 63 +++
.../converters/BigIntegerConverter.java | 94 ++++
.../internal/converters/BooleanConverter.java | 57 +++
.../core/internal/converters/ByteConverter.java | 71 +++
.../core/internal/converters/CharConverter.java | 69 +++
.../internal/converters/ClassConverter.java | 63 +++
.../internal/converters/CurrencyConverter.java | 89 ++++
.../internal/converters/DoubleConverter.java | 81 ++++
.../core/internal/converters/EnumConverter.java | 68 +++
.../internal/converters/FloatConverter.java | 81 ++++
.../internal/converters/IntegerConverter.java | 74 +++
.../core/internal/converters/LongConverter.java | 72 +++
.../internal/converters/NumberConverter.java | 72 +++
.../internal/converters/ShortConverter.java | 72 +++
.../core/internal/converters/URIConverter.java | 47 ++
.../core/internal/converters/URLConverter.java | 47 ++
.../core/propertysource/BasePropertySource.java | 85 ++++
.../EnvironmentPropertySource.java | 64 +++
.../propertysource/SimplePropertySource.java | 128 ++++++
.../propertysource/SystemPropertySource.java | 93 ++++
.../provider/JavaConfigurationProvider.java | 61 +++
.../services/org.apache.tamaya.Configuration | 19 +
...pache.tamaya.spi.ConfigurationContextBuilder | 19 +
...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 +
.../org.apache.tamaya.spi.PropertyConverter | 33 ++
.../org.apache.tamaya.spi.PropertySource | 20 +
...org.apache.tamaya.spi.PropertySourceProvider | 19 +
.../org.apache.tamaya.spi.ServiceContext | 19 +
.../apache/tamaya/core/ConfigurationTest.java | 67 +++
.../java/org/apache/tamaya/core/internal/A.java | 29 ++
.../java/org/apache/tamaya/core/internal/B.java | 29 ++
.../java/org/apache/tamaya/core/internal/C.java | 56 +++
.../tamaya/core/internal/CTestConverter.java | 32 ++
.../internal/DefaultServiceContextTest.java | 140 ++++++
.../internal/PropertyConverterManagerTest.java | 179 ++++++++
.../converters/BigDecimalConverterTest.java | 103 +++++
.../converters/BooleanConverterTest.java | 108 +++++
.../internal/converters/ByteConverterTest.java | 81 ++++
.../internal/converters/CharConverterTest.java | 86 ++++
.../ConverterTestsPropertySource.java | 252 +++++++++++
.../converters/CurrencyConverterTest.java | 154 +++++++
.../converters/DoubleConverterTest.java | 175 ++++++++
.../internal/converters/EnumConverterTest.java | 60 +++
.../internal/converters/FloatConverterTest.java | 176 ++++++++
.../converters/IntegerConverterTest.java | 111 +++++
.../internal/converters/LongConverterTest.java | 111 +++++
.../converters/NumberConverterTest.java | 103 +++++
.../internal/converters/ShortConverterTest.java | 111 +++++
.../propertysource/BasePropertySourceTest.java | 104 +++++
.../EnvironmentPropertySourceTest.java | 62 +++
.../PropertiesFilePropertySourceTest.java | 58 +++
.../SystemPropertySourceTest.java | 99 ++++
.../provider/JavaConfigurationProviderTest.java | 60 +++
.../testdata/TestPropertyDefaultSource.java | 56 +++
.../core/testdata/TestPropertyFilter.java | 37 ++
.../testdata/TestPropertySourceProvider.java | 78 ++++
.../testdata/TestRemovingPropertyFilter.java | 41 ++
.../META-INF/javaconfiguration.properties | 22 +
...tServiceContextTest$InvalidPriorityInterface | 18 +
...efaultServiceContextTest$MultiImplsInterface | 20 +
.../org.apache.tamaya.spi.PropertyConverter | 19 +
.../org.apache.tamaya.spi.PropertyFilter | 20 +
.../org.apache.tamaya.spi.PropertySource | 22 +
...org.apache.tamaya.spi.PropertySourceProvider | 20 +
.../test/resources/overrideOrdinal.properties | 25 ++
.../core/src/test/resources/testfile.properties | 22 +
code/core/src/test/resources/x34.properties | 19 +
code/pom.xml | 1 +
core/pom.xml | 103 -----
.../core/internal/DefaultConfiguration.java | 197 --------
.../internal/DefaultConfigurationContext.java | 278 ------------
.../DefaultConfigurationContextBuilder.java | 153 -------
.../internal/DefaultConfigurationProvider.java | 68 ---
.../core/internal/DefaultServiceContext.java | 156 -------
.../tamaya/core/internal/OSGIActivator.java | 53 ---
.../core/internal/OSGIServiceComparator.java | 69 ---
.../core/internal/OSGIServiceContext.java | 83 ----
.../tamaya/core/internal/OSGIServiceLoader.java | 158 -------
.../internal/PriorityServiceComparator.java | 67 ---
.../core/internal/PropertyConverterManager.java | 448 -------------------
.../core/internal/PropertyFilterComparator.java | 60 ---
.../tamaya/core/internal/PropertyFiltering.java | 131 ------
.../core/internal/PropertySourceComparator.java | 54 ---
.../tamaya/core/internal/ReflectionUtil.java | 42 --
.../converters/BigDecimalConverter.java | 63 ---
.../converters/BigIntegerConverter.java | 94 ----
.../internal/converters/BooleanConverter.java | 57 ---
.../core/internal/converters/ByteConverter.java | 71 ---
.../core/internal/converters/CharConverter.java | 69 ---
.../internal/converters/ClassConverter.java | 63 ---
.../internal/converters/CurrencyConverter.java | 89 ----
.../internal/converters/DoubleConverter.java | 81 ----
.../core/internal/converters/EnumConverter.java | 68 ---
.../internal/converters/FloatConverter.java | 81 ----
.../internal/converters/IntegerConverter.java | 74 ---
.../core/internal/converters/LongConverter.java | 72 ---
.../internal/converters/NumberConverter.java | 72 ---
.../internal/converters/ShortConverter.java | 72 ---
.../core/internal/converters/URIConverter.java | 47 --
.../core/internal/converters/URLConverter.java | 47 --
.../core/propertysource/BasePropertySource.java | 85 ----
.../EnvironmentPropertySource.java | 64 ---
.../propertysource/SimplePropertySource.java | 128 ------
.../propertysource/SystemPropertySource.java | 93 ----
.../provider/JavaConfigurationProvider.java | 61 ---
.../services/org.apache.tamaya.Configuration | 19 -
...pache.tamaya.spi.ConfigurationContextBuilder | 19 -
...g.apache.tamaya.spi.ConfigurationProviderSpi | 19 -
.../org.apache.tamaya.spi.PropertyConverter | 33 --
.../org.apache.tamaya.spi.PropertySource | 20 -
...org.apache.tamaya.spi.PropertySourceProvider | 19 -
.../org.apache.tamaya.spi.ServiceContext | 19 -
.../apache/tamaya/core/ConfigurationTest.java | 67 ---
.../java/org/apache/tamaya/core/internal/A.java | 29 --
.../java/org/apache/tamaya/core/internal/B.java | 29 --
.../java/org/apache/tamaya/core/internal/C.java | 56 ---
.../tamaya/core/internal/CTestConverter.java | 32 --
.../internal/DefaultServiceContextTest.java | 140 ------
.../internal/PropertyConverterManagerTest.java | 179 --------
.../converters/BigDecimalConverterTest.java | 103 -----
.../converters/BooleanConverterTest.java | 108 -----
.../internal/converters/ByteConverterTest.java | 81 ----
.../internal/converters/CharConverterTest.java | 86 ----
.../ConverterTestsPropertySource.java | 252 -----------
.../converters/CurrencyConverterTest.java | 154 -------
.../converters/DoubleConverterTest.java | 175 --------
.../internal/converters/EnumConverterTest.java | 60 ---
.../internal/converters/FloatConverterTest.java | 176 --------
.../converters/IntegerConverterTest.java | 111 -----
.../internal/converters/LongConverterTest.java | 111 -----
.../converters/NumberConverterTest.java | 103 -----
.../internal/converters/ShortConverterTest.java | 111 -----
.../propertysource/BasePropertySourceTest.java | 104 -----
.../EnvironmentPropertySourceTest.java | 62 ---
.../PropertiesFilePropertySourceTest.java | 58 ---
.../SystemPropertySourceTest.java | 99 ----
.../provider/JavaConfigurationProviderTest.java | 60 ---
.../testdata/TestPropertyDefaultSource.java | 56 ---
.../core/testdata/TestPropertyFilter.java | 37 --
.../testdata/TestPropertySourceProvider.java | 78 ----
.../testdata/TestRemovingPropertyFilter.java | 41 --
.../META-INF/javaconfiguration.properties | 22 -
...tServiceContextTest$InvalidPriorityInterface | 18 -
...efaultServiceContextTest$MultiImplsInterface | 20 -
.../org.apache.tamaya.spi.PropertyConverter | 19 -
.../org.apache.tamaya.spi.PropertyFilter | 20 -
.../org.apache.tamaya.spi.PropertySource | 22 -
...org.apache.tamaya.spi.PropertySourceProvider | 20 -
.../test/resources/overrideOrdinal.properties | 25 --
core/src/test/resources/testfile.properties | 22 -
core/src/test/resources/x34.properties | 19 -
pom.xml | 1 -
168 files changed, 6785 insertions(+), 6785 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/pom.xml
----------------------------------------------------------------------
diff --git a/code/core/pom.xml b/code/core/pom.xml
new file mode 100644
index 0000000..3088bd6
--- /dev/null
+++ b/code/core/pom.xml
@@ -0,0 +1,103 @@
+<!--
+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>code</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-core</artifactId>
+ <name>Apache Tamaya Core Implementation</name>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <osgi.compendium.version>5.0.0</osgi.compendium.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-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>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ <version>${osgi.compendium.version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.tamaya.core.internal,
+ org.apache.tamaya.core.internal.converters
+ </Private-Package>
+ <Export-Package>
+ org.apache.tamaya.core,
+ org.apache.tamaya.core.propertysource,
+ org.apache.tamaya.core.provider
+ </Export-Package>
+ <Bundle-Activator>
+ org.apache.tamaya.core.internal.OSGIActivator
+ </Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
new file mode 100644
index 0000000..f7c363c
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -0,0 +1,197 @@
+/*
+ * 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.TypeLiteral;
+import org.apache.tamaya.spi.*;
+
+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.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 PropertySource} and {@link 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 current {@link ConfigurationContext} of the current instance.
+ */
+ private final ConfigurationContext configurationContext;
+
+
+ /**
+ * Constructor.
+ * @param configurationContext The configuration Context to be used.
+ */
+ public DefaultConfiguration(ConfigurationContext configurationContext){
+ this.configurationContext = Objects.requireNonNull(configurationContext);
+ }
+
+
+ public String get(String key) {
+ return PropertyFiltering.applyFilter(key, evaluteRawValue(key), configurationContext);
+ }
+
+ protected String evaluteRawValue(String key) {
+ List<PropertySource> propertySources = configurationContext.getPropertySources();
+ String unfilteredValue = null;
+ PropertyValueCombinationPolicy combinationPolicy = this.configurationContext
+ .getPropertyValueCombinationPolicy();
+ for (PropertySource propertySource : propertySources) {
+ unfilteredValue = combinationPolicy.collect(unfilteredValue, key, propertySource);
+ }
+ return unfilteredValue;
+ }
+
+
+ @Override
+ public String getOrDefault(String key, String defaultValue) {
+ String val = get(key);
+ if(val==null){
+ return defaultValue;
+ }
+ return val;
+ }
+
+ @Override
+ public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
+ T val = get(key, type);
+ if(val==null){
+ return defaultValue;
+ }
+ return val;
+ }
+
+ /**
+ * Get the current properties, composed by the loaded {@link PropertySource} and filtered
+ * by registered {@link PropertyFilter}.
+ *
+ * @return the final properties.
+ */
+ @Override
+ public Map<String, String> getProperties() {
+ return PropertyFiltering.applyFilters(evaluateUnfilteredMap(), configurationContext);
+ }
+
+ protected Map<String, String> evaluateUnfilteredMap() {
+ 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 result;
+ }
+
+ /**
+ * Accesses the current String value for the given key and tries to convert it
+ * using the {@link PropertyConverter} instances provided by the current
+ * {@link 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) {
+ return get(key, (TypeLiteral<T>)TypeLiteral.of(type));
+ }
+
+ /**
+ * Accesses the current String value for the given key and tries to convert it
+ * using the {@link PropertyConverter} instances provided by the current
+ * {@link 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, TypeLiteral<T> type) {
+ return convertValue(key, get(key), type);
+ }
+
+ protected <T> T convertValue(String key, String value, TypeLiteral<T> type) {
+ if (value != null) {
+ List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
+ ConversionContext context = new ConversionContext.Builder(this, key, type).build();
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value, context);
+ 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.getRawType().getName() + ": " + key +
+ ", supported formats: " + context.getSupportedFormats());
+ }
+ return null;
+ }
+
+ @Override
+ public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
+ T val = get(key, type);
+ if(val==null){
+ return defaultValue;
+ }
+ return val;
+ }
+
+ @Override
+ public Configuration with(ConfigOperator operator) {
+ return operator.operate(this);
+ }
+
+ @Override
+ public <T> T query(ConfigQuery<T> query) {
+ return query.query(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
new file mode 100644
index 0000000..ac68a73
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -0,0 +1,278 @@
+/*
+ * 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.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+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.PropertyValueCombinationPolicy;
+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;
+import java.util.logging.Logger;
+
+/**
+ * Default Implementation of a simple ConfigurationContext.
+ */
+public class DefaultConfigurationContext implements ConfigurationContext {
+ /** The logger used. */
+ private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
+ /**
+ * 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;
+
+ /**
+ * The overriding policy used when combining PropertySources registered to evalute the final configuration
+ * values.
+ */
+ private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+
+ /** Comparator used for ordering property sources. */
+ private final PropertySourceComparator propertySourceComparator = new PropertySourceComparator();
+
+ /** Comparator used for ordering property filters. */
+ private final PropertyFilterComparator propertyFilterComparator = new PropertyFilterComparator();
+
+
+ /**
+ * 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);
+ LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
+ immutablePropertySources);
+
+ // 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);
+ LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
+ immutablePropertyFilters);
+
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
+ immutablePropertyFilters);
+ propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
+ if(propertyValueCombinationPolicy==null) {
+ propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+ }
+ LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
+ }
+
+ DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
+ List<PropertySource> propertySources = new ArrayList<>();
+ // first we load all PropertySources which got registered via java.util.ServiceLoader
+ propertySources.addAll(builder.propertySources.values());
+ // now sort them according to their ordinal values
+ Collections.sort(propertySources, propertySourceComparator);
+ immutablePropertySources = Collections.unmodifiableList(propertySources);
+ LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
+ immutablePropertySources);
+
+ // 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, propertyFilterComparator);
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
+ immutablePropertyFilters);
+
+ propertyValueCombinationPolicy = builder.combinationPolicy;
+ if(propertyValueCombinationPolicy==null){
+ propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
+ }
+ if(propertyValueCombinationPolicy==null){
+ propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+ }
+ LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
+ }
+
+ /**
+ * 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<>();
+ Collection<PropertySourceProvider> propertySourceProviders = ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class);
+ for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
+ Collection<PropertySource> sources = propertySourceProvider.getPropertySources();
+ LOG.finer("PropertySourceProvider " + propertySourceProvider.getClass().getName() +
+ " provided the following property sources: " + sources);
+ propertySources.addAll(sources);
+ }
+
+ 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 source1.getClass().getName().compareTo(source2.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(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return immutablePropertyFilters;
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
+ return propertyValueCombinationPolicy;
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ return ConfigurationProvider.getConfigurationContextBuilder().setContext(this);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
new file mode 100644
index 0000000..2c44689
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
@@ -0,0 +1,153 @@
+/*
+ * 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.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Default implementation of {@link org.apache.tamaya.spi.ConfigurationContextBuilder}.
+ */
+public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
+
+ Map<String, PropertySource> propertySources = new HashMap<>();
+ List<PropertyFilter> propertyFilters = new ArrayList<>();
+ Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
+ PropertyValueCombinationPolicy combinationPolicy;
+
+ public DefaultConfigurationContextBuilder(){
+ }
+
+ @Override
+ public ConfigurationContextBuilder setContext(ConfigurationContext context) {
+ this.propertySources.clear();
+ for(PropertySource ps:context.getPropertySources()) {
+ this.propertySources.put(ps.getName(), ps);
+ }
+ this.propertyFilters.clear();
+ this.propertyFilters.addAll(context.getPropertyFilters());
+ this.propertyConverters.clear();
+ this.propertyConverters.putAll(context.getPropertyConverters());
+ this.combinationPolicy = context.getPropertyValueCombinationPolicy();
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> propertySourcesToAdd) {
+ for(PropertySource ps:propertySourcesToAdd){
+ if(this.propertySources.containsKey(ps.getName())){
+ throw new ConfigException("Duplicate PropertySource: " + ps.getName());
+ }
+ }
+ for(PropertySource ps:propertySourcesToAdd) {
+ this.propertySources.put(ps.getName(), ps);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertySources(PropertySource... propertySourcesToAdd) {
+ return addPropertySources(Arrays.asList(propertySourcesToAdd));
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertySources(Collection<String> propertySourcesToRemove) {
+ for(String key: propertySourcesToRemove){
+ this.propertySources.remove(key);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertySources(String... propertySourcesToRemove) {
+ return removePropertySources(Arrays.asList(propertySourcesToRemove));
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters) {
+ this.propertyFilters.addAll(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters) {
+ return addPropertyFilters(Arrays.asList(filters));
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
+ this.propertyFilters.removeAll(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) {
+ return removePropertyFilters(Arrays.asList(filters));
+ }
+
+ @Override
+ public <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ List<PropertyConverter<?>> converters = this.propertyConverters.get(typeToConvert);
+ if(converters==null){
+ converters = new ArrayList<>();
+ this.propertyConverters.put(typeToConvert, converters);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, PropertyConverter<?>... converters) {
+ return removePropertyConverters(typeToConvert, Arrays.asList(converters));
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, Collection<PropertyConverter<?>> converters) {
+ List<PropertyConverter<?>> existing = this.propertyConverters.get(typeToConvert);
+ if(existing!=null) {
+ existing.removeAll(converters);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
+ this.combinationPolicy = Objects.requireNonNull(policy);
+ return this;
+ }
+
+ @Override
+ public ConfigurationContext build() {
+ return new DefaultConfigurationContext(this);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
new file mode 100644
index 0000000..2dc15bd
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.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.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * 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;
+ }
+
+ @Override
+ public ConfigurationContextBuilder getConfigurationContextBuilder() {
+ ConfigurationContextBuilder contextBuilder =
+ ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
+
+ return contextBuilder;
+ }
+
+ @Override
+ public void setConfigurationContext(ConfigurationContext context){
+ // TODO think on a SPI or move event part into API...
+ this.config = new DefaultConfiguration(context);
+ this.context = context;
+ }
+
+
+ @Override
+ public boolean isConfigurationContextSettable() {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
new file mode 100644
index 0000000..9738b76
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
@@ -0,0 +1,156 @@
+/*
+ * 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.Collection;
+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) {
+ Collection<T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = null;
+ } else {
+ cached = getServiceWithHighestPriority(services, serviceType);
+ }
+ if(cached!=null) {
+ singletons.put(serviceType, cached);
+ }
+ }
+ return serviceType.cast(cached);
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param <T> the concrete type.
+ * @param serviceType The service 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;
+ }
+
+ /**
+ * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
+ * annotation is present, a default priority is returned (1);
+ * @param o the instance, not null.
+ * @return a priority, by default 1.
+ */
+ public static int getPriority(Object o){
+ int prio = 1; //X TODO discuss default priority
+ Priority priority = o.getClass().getAnnotation(Priority.class);
+ if (priority != null) {
+ prio = priority.value();
+ }
+ return prio;
+ }
+
+ /**
+ * @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(Collection<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.iterator().next();
+ }
+
+ Integer highestPriority = null;
+ int highestPriorityServiceCount = 0;
+ T highestService = null;
+
+ for (T service : services) {
+ int prio = getPriority(service);
+ 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/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
new file mode 100644
index 0000000..8a54d35
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
@@ -0,0 +1,53 @@
+/*
+ * 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.ServiceContextManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import java.util.logging.Logger;
+
+/**
+ * A bundle activator that registers the {@link OSGIServiceLoader}.
+ */
+public class OSGIActivator implements BundleActivator {
+
+ private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName());
+
+ private OSGIServiceLoader serviceLoader;
+
+ @Override
+ public void start(BundleContext context) {
+ // Register marker service
+ ServiceContextManager.set(new OSGIServiceContext(context));
+ LOG.info("Registered OSGI enabled ServiceContext...");
+ serviceLoader = new OSGIServiceLoader();
+ context.addBundleListener(serviceLoader);
+ }
+
+ @Override
+ public void stop(BundleContext context) {
+ if(serviceLoader!=null) {
+ context.removeBundleListener(serviceLoader);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java
new file mode 100644
index 0000000..bfc34bc
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java
@@ -0,0 +1,69 @@
+/*
+ * 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.osgi.framework.ServiceReference;
+
+import javax.annotation.Priority;
+import java.util.Comparator;
+
+/**
+ * Comparator implementation for odering services loaded based on their increasing priority values.
+ */
+class OSGIServiceComparator implements Comparator<ServiceReference> {
+
+ @Override
+ public int compare(ServiceReference o1, ServiceReference o2) {
+ int prio = getPriority(o1) - getPriority(o2);
+ if (prio < 0) {
+ return 1;
+ } else if (prio > 0) {
+ return -1;
+ } else {
+ return 0; //o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
+ * annotation is present, a default priority is returned (1);
+ *
+ * @param o the instance, not null.
+ * @return a priority, by default 1.
+ */
+ public static int getPriority(Object o) {
+ return getPriority(o.getClass());
+ }
+
+ /**
+ * Checks the given type optionally annotated with a @Priority. If present the annotation's value s evaluated.
+ * If no such annotation is present, a default priority is returned (1);
+ *
+ * @param type the type, not null.
+ * @return a priority, by default 1.
+ */
+ public static int getPriority(Class type) {
+ int prio = 1;
+ Priority priority = (Priority)type.getAnnotation(Priority.class);
+ if (priority != null) {
+ prio = priority.value();
+ }
+ return prio;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
new file mode 100644
index 0000000..083cd54
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
@@ -0,0 +1,83 @@
+/*
+ * 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.ServiceContext;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * ServiceContext implementation based on OSGI Service mechanisms.
+ */
+public class OSGIServiceContext implements ServiceContext{
+
+ private static final OSGIServiceComparator REF_COMPARATOR = new OSGIServiceComparator();
+
+ private BundleContext bundleContext;
+
+ public OSGIServiceContext(BundleContext bundleContext){
+ this.bundleContext = Objects.requireNonNull(bundleContext);
+ }
+
+ public boolean isInitialized(){
+ return bundleContext != null;
+ }
+
+
+ @Override
+ public int ordinal() {
+ return 10;
+ }
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ ServiceReference<T> ref = this.bundleContext.getServiceReference(serviceType);
+ if(ref!=null){
+ return this.bundleContext.getService(ref);
+ }
+ return null;
+ }
+
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ List<ServiceReference<T>> refs = new ArrayList<>();
+ try {
+ refs.addAll(this.bundleContext.getServiceReferences(serviceType, null));
+ Collections.sort(refs, REF_COMPARATOR);
+ List<T> services = new ArrayList<>(refs.size());
+ for(ServiceReference<T> ref:refs){
+ T service = bundleContext.getService(ref);
+ if(service!=null) {
+ services.add(service);
+ }
+ }
+ return services;
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ return Collections.emptyList();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
new file mode 100644
index 0000000..dcc702f
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
@@ -0,0 +1,158 @@
+/*
+ * 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.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ConcurrentModificationException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * An bundle listener that registers services defined in META-INF/services, when a bundle is starting.
+ *
+ * @author anatole@apache.org
+ */
+public class OSGIServiceLoader implements BundleListener {
+ // Provide logging
+ private static final Logger log = Logger.getLogger(OSGIServiceLoader.class.getName());
+
+ private Map<Class, ServiceTracker<Object,Object>> services = new ConcurrentHashMap<>();
+
+ @Override
+ public void bundleChanged(BundleEvent bundleEvent) {
+ // Parse and create metadta on STARTING
+ if (bundleEvent.getType() == BundleEvent.STARTED) {
+ Bundle bundle = bundleEvent.getBundle();
+ if (bundle.getEntry("META-INF/services/") == null) {
+ return;
+ }
+ Enumeration<String> entryPaths = bundle.getEntryPaths("META-INF/services/");
+ while (entryPaths.hasMoreElements()) {
+ String entryPath = entryPaths.nextElement();
+ if(!entryPath.endsWith("/")) {
+ processEntryPath(bundle, entryPath);
+ }
+ }
+ }
+ }
+
+ private void processEntryPath(Bundle bundle, String entryPath) {
+ try {
+ String serviceName = entryPath.substring("META-INF/services/".length());
+ Class<?> serviceClass = bundle.loadClass(serviceName);
+
+ URL child = bundle.getEntry(entryPath);
+ InputStream inStream = child.openStream();
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
+ String implClassName = br.readLine();
+ while (implClassName != null){
+ int hashIndex = implClassName.indexOf("#");
+ if (hashIndex > 0) {
+ implClassName = implClassName.substring(0, hashIndex-1);
+ }
+ else if (hashIndex == 0) {
+ implClassName = "";
+ }
+ implClassName = implClassName.trim();
+ if (implClassName.length() > 0) {
+ try {
+ // Load the service class
+ Class<?> implClass = (Class<?>) bundle.loadClass(implClassName);
+ if (serviceClass.isAssignableFrom(implClass) == false) {
+ log.warning("Configured service: " + implClassName + " is not assignble to " +
+ serviceClass.getName());
+ continue;
+ }
+ // Provide service properties
+ Hashtable<String, String> props = new Hashtable<String, String>();
+ props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
+ String vendor = (String) bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
+ props.put(Constants.SERVICE_VENDOR, (vendor != null ? vendor : "anonymous"));
+ // Translate annotated @Priority into a service ranking
+ props.put(Constants.SERVICE_RANKING,
+ String.valueOf(PriorityServiceComparator.getPriority(implClass)));
+
+ // Register the service factory on behalf of the intercepted bundle
+ JDKUtilServiceFactory factory = new JDKUtilServiceFactory(implClass);
+ BundleContext bundleContext = bundle.getBundleContext();
+ bundleContext.registerService(serviceName, factory, props);
+ }
+ catch(Exception e){
+ log.log(Level.SEVERE,
+ "Failed to load service class using ServiceLoader logic: " + implClassName, e);
+ }
+ }
+ implClassName = br.readLine();
+ }
+ br.close();
+ }
+ catch (RuntimeException rte) {
+ throw rte;
+ }
+ catch (Exception e) {
+ log.log(Level.SEVERE, "Failed to read services from: " + entryPath, e);
+ }
+ }
+
+
+ /**
+ * Service factory simply instantiating the configured service.
+ */
+ static class JDKUtilServiceFactory implements ServiceFactory
+ {
+ private Class<?> serviceClass;
+
+ public JDKUtilServiceFactory(Class<?> serviceClass) {
+ this.serviceClass = serviceClass;
+ }
+
+ @Override
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ try {
+ Object serviceInstance = serviceClass.newInstance();
+ return serviceInstance;
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ throw new IllegalStateException("Cannot instanciate service", ex);
+ }
+ }
+
+ @Override
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java b/code/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java
new file mode 100644
index 0000000..c0cfca6
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java
@@ -0,0 +1,67 @@
+/*
+ * 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 javax.annotation.Priority;
+import java.util.Comparator;
+
+/**
+ * Comparator implementation for odering services loaded based on their increasing priority values.
+ */
+public class PriorityServiceComparator implements Comparator<Object> {
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ int prio = getPriority(o1) - getPriority(o2);
+ if (prio < 0) {
+ return 1;
+ } else if (prio > 0) {
+ return -1;
+ } else {
+ return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
+ }
+ }
+
+ /**
+ * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
+ * annotation is present, a default priority is returned (1);
+ *
+ * @param o the instance, not null.
+ * @return a priority, by default 1.
+ */
+ public static int getPriority(Object o) {
+ return getPriority(o.getClass());
+ }
+
+ /**
+ * Checks the given type optionally annotated with a @Priority. If present the annotation's value s evaluated.
+ * If no such annotation is present, a default priority is returned (1);
+ *
+ * @param type the type, not null.
+ * @return a priority, by default 1.
+ */
+ public static int getPriority(Class type) {
+ int prio = 1;
+ Priority priority = (Priority)type.getAnnotation(Priority.class);
+ if (priority != null) {
+ prio = priority.value();
+ }
+ return prio;
+ }
+}
[4/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
deleted file mode 100644
index f7c363c..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.ConfigQuery;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.*;
-
-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.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 PropertySource} and {@link 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 current {@link ConfigurationContext} of the current instance.
- */
- private final ConfigurationContext configurationContext;
-
-
- /**
- * Constructor.
- * @param configurationContext The configuration Context to be used.
- */
- public DefaultConfiguration(ConfigurationContext configurationContext){
- this.configurationContext = Objects.requireNonNull(configurationContext);
- }
-
-
- public String get(String key) {
- return PropertyFiltering.applyFilter(key, evaluteRawValue(key), configurationContext);
- }
-
- protected String evaluteRawValue(String key) {
- List<PropertySource> propertySources = configurationContext.getPropertySources();
- String unfilteredValue = null;
- PropertyValueCombinationPolicy combinationPolicy = this.configurationContext
- .getPropertyValueCombinationPolicy();
- for (PropertySource propertySource : propertySources) {
- unfilteredValue = combinationPolicy.collect(unfilteredValue, key, propertySource);
- }
- return unfilteredValue;
- }
-
-
- @Override
- public String getOrDefault(String key, String defaultValue) {
- String val = get(key);
- if(val==null){
- return defaultValue;
- }
- return val;
- }
-
- @Override
- public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- T val = get(key, type);
- if(val==null){
- return defaultValue;
- }
- return val;
- }
-
- /**
- * Get the current properties, composed by the loaded {@link PropertySource} and filtered
- * by registered {@link PropertyFilter}.
- *
- * @return the final properties.
- */
- @Override
- public Map<String, String> getProperties() {
- return PropertyFiltering.applyFilters(evaluateUnfilteredMap(), configurationContext);
- }
-
- protected Map<String, String> evaluateUnfilteredMap() {
- 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 result;
- }
-
- /**
- * Accesses the current String value for the given key and tries to convert it
- * using the {@link PropertyConverter} instances provided by the current
- * {@link 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) {
- return get(key, (TypeLiteral<T>)TypeLiteral.of(type));
- }
-
- /**
- * Accesses the current String value for the given key and tries to convert it
- * using the {@link PropertyConverter} instances provided by the current
- * {@link 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, TypeLiteral<T> type) {
- return convertValue(key, get(key), type);
- }
-
- protected <T> T convertValue(String key, String value, TypeLiteral<T> type) {
- if (value != null) {
- List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
- ConversionContext context = new ConversionContext.Builder(this, key, type).build();
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value, context);
- 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.getRawType().getName() + ": " + key +
- ", supported formats: " + context.getSupportedFormats());
- }
- return null;
- }
-
- @Override
- public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
- T val = get(key, type);
- if(val==null){
- return defaultValue;
- }
- return val;
- }
-
- @Override
- public Configuration with(ConfigOperator operator) {
- return operator.operate(this);
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- return query.query(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
deleted file mode 100644
index ac68a73..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-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.PropertyValueCombinationPolicy;
-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;
-import java.util.logging.Logger;
-
-/**
- * Default Implementation of a simple ConfigurationContext.
- */
-public class DefaultConfigurationContext implements ConfigurationContext {
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
- /**
- * 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;
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
-
- /**
- * Lock for internal synchronization.
- */
- private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
-
- /** Comparator used for ordering property sources. */
- private final PropertySourceComparator propertySourceComparator = new PropertySourceComparator();
-
- /** Comparator used for ordering property filters. */
- private final PropertyFilterComparator propertyFilterComparator = new PropertyFilterComparator();
-
-
- /**
- * 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);
- LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
- immutablePropertySources);
-
- // 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);
- LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
- immutablePropertyFilters);
-
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
- immutablePropertyFilters);
- propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
- if(propertyValueCombinationPolicy==null) {
- propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- }
- LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
- DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
- List<PropertySource> propertySources = new ArrayList<>();
- // first we load all PropertySources which got registered via java.util.ServiceLoader
- propertySources.addAll(builder.propertySources.values());
- // now sort them according to their ordinal values
- Collections.sort(propertySources, propertySourceComparator);
- immutablePropertySources = Collections.unmodifiableList(propertySources);
- LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
- immutablePropertySources);
-
- // 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, propertyFilterComparator);
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
- immutablePropertyFilters);
-
- propertyValueCombinationPolicy = builder.combinationPolicy;
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
- }
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- }
- LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
- /**
- * 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<>();
- Collection<PropertySourceProvider> propertySourceProviders = ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class);
- for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
- Collection<PropertySource> sources = propertySourceProvider.getPropertySources();
- LOG.finer("PropertySourceProvider " + propertySourceProvider.getClass().getName() +
- " provided the following property sources: " + sources);
- propertySources.addAll(sources);
- }
-
- 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 source1.getClass().getName().compareTo(source2.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(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- propertyConverterManager.register(typeToConvert, propertyConverter);
- LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
- return propertyValueCombinationPolicy;
- }
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- return ConfigurationProvider.getConfigurationContextBuilder().setContext(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
deleted file mode 100644
index 2c44689..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- * Default implementation of {@link org.apache.tamaya.spi.ConfigurationContextBuilder}.
- */
-public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
-
- Map<String, PropertySource> propertySources = new HashMap<>();
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- Map<TypeLiteral<?>, List<PropertyConverter<?>>> propertyConverters = new HashMap<>();
- PropertyValueCombinationPolicy combinationPolicy;
-
- public DefaultConfigurationContextBuilder(){
- }
-
- @Override
- public ConfigurationContextBuilder setContext(ConfigurationContext context) {
- this.propertySources.clear();
- for(PropertySource ps:context.getPropertySources()) {
- this.propertySources.put(ps.getName(), ps);
- }
- this.propertyFilters.clear();
- this.propertyFilters.addAll(context.getPropertyFilters());
- this.propertyConverters.clear();
- this.propertyConverters.putAll(context.getPropertyConverters());
- this.combinationPolicy = context.getPropertyValueCombinationPolicy();
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> propertySourcesToAdd) {
- for(PropertySource ps:propertySourcesToAdd){
- if(this.propertySources.containsKey(ps.getName())){
- throw new ConfigException("Duplicate PropertySource: " + ps.getName());
- }
- }
- for(PropertySource ps:propertySourcesToAdd) {
- this.propertySources.put(ps.getName(), ps);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(PropertySource... propertySourcesToAdd) {
- return addPropertySources(Arrays.asList(propertySourcesToAdd));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(Collection<String> propertySourcesToRemove) {
- for(String key: propertySourcesToRemove){
- this.propertySources.remove(key);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(String... propertySourcesToRemove) {
- return removePropertySources(Arrays.asList(propertySourcesToRemove));
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters) {
- this.propertyFilters.addAll(filters);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters) {
- return addPropertyFilters(Arrays.asList(filters));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
- this.propertyFilters.removeAll(filters);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) {
- return removePropertyFilters(Arrays.asList(filters));
- }
-
- @Override
- public <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- List<PropertyConverter<?>> converters = this.propertyConverters.get(typeToConvert);
- if(converters==null){
- converters = new ArrayList<>();
- this.propertyConverters.put(typeToConvert, converters);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, PropertyConverter<?>... converters) {
- return removePropertyConverters(typeToConvert, Arrays.asList(converters));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, Collection<PropertyConverter<?>> converters) {
- List<PropertyConverter<?>> existing = this.propertyConverters.get(typeToConvert);
- if(existing!=null) {
- existing.removeAll(converters);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
- this.combinationPolicy = Objects.requireNonNull(policy);
- return this;
- }
-
- @Override
- public ConfigurationContext build() {
- return new DefaultConfigurationContext(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
deleted file mode 100644
index 2dc15bd..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-/**
- * 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;
- }
-
- @Override
- public ConfigurationContextBuilder getConfigurationContextBuilder() {
- ConfigurationContextBuilder contextBuilder =
- ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
-
- return contextBuilder;
- }
-
- @Override
- public void setConfigurationContext(ConfigurationContext context){
- // TODO think on a SPI or move event part into API...
- this.config = new DefaultConfiguration(context);
- this.context = context;
- }
-
-
- @Override
- public boolean isConfigurationContextSettable() {
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
deleted file mode 100644
index 9738b76..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-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.Collection;
-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) {
- Collection<T> services = getServices(serviceType);
- if (services.isEmpty()) {
- cached = null;
- } else {
- cached = getServiceWithHighestPriority(services, serviceType);
- }
- if(cached!=null) {
- singletons.put(serviceType, cached);
- }
- }
- return serviceType.cast(cached);
- }
-
- /**
- * Loads and registers services.
- *
- * @param <T> the concrete type.
- * @param serviceType The service 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;
- }
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
- * annotation is present, a default priority is returned (1);
- * @param o the instance, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o){
- int prio = 1; //X TODO discuss default priority
- Priority priority = o.getClass().getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-
- /**
- * @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(Collection<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.iterator().next();
- }
-
- Integer highestPriority = null;
- int highestPriorityServiceCount = 0;
- T highestService = null;
-
- for (T service : services) {
- int prio = getPriority(service);
- 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/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
deleted file mode 100644
index 8a54d35..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIActivator.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-
-
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-import java.util.logging.Logger;
-
-/**
- * A bundle activator that registers the {@link OSGIServiceLoader}.
- */
-public class OSGIActivator implements BundleActivator {
-
- private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName());
-
- private OSGIServiceLoader serviceLoader;
-
- @Override
- public void start(BundleContext context) {
- // Register marker service
- ServiceContextManager.set(new OSGIServiceContext(context));
- LOG.info("Registered OSGI enabled ServiceContext...");
- serviceLoader = new OSGIServiceLoader();
- context.addBundleListener(serviceLoader);
- }
-
- @Override
- public void stop(BundleContext context) {
- if(serviceLoader!=null) {
- context.removeBundleListener(serviceLoader);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java
deleted file mode 100644
index bfc34bc..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceComparator.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.osgi.framework.ServiceReference;
-
-import javax.annotation.Priority;
-import java.util.Comparator;
-
-/**
- * Comparator implementation for odering services loaded based on their increasing priority values.
- */
-class OSGIServiceComparator implements Comparator<ServiceReference> {
-
- @Override
- public int compare(ServiceReference o1, ServiceReference o2) {
- int prio = getPriority(o1) - getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return 0; //o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
- * annotation is present, a default priority is returned (1);
- *
- * @param o the instance, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o) {
- return getPriority(o.getClass());
- }
-
- /**
- * Checks the given type optionally annotated with a @Priority. If present the annotation's value s evaluated.
- * If no such annotation is present, a default priority is returned (1);
- *
- * @param type the type, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Class type) {
- int prio = 1;
- Priority priority = (Priority)type.getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
deleted file mode 100644
index 083cd54..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.ServiceContext;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * ServiceContext implementation based on OSGI Service mechanisms.
- */
-public class OSGIServiceContext implements ServiceContext{
-
- private static final OSGIServiceComparator REF_COMPARATOR = new OSGIServiceComparator();
-
- private BundleContext bundleContext;
-
- public OSGIServiceContext(BundleContext bundleContext){
- this.bundleContext = Objects.requireNonNull(bundleContext);
- }
-
- public boolean isInitialized(){
- return bundleContext != null;
- }
-
-
- @Override
- public int ordinal() {
- return 10;
- }
-
- @Override
- public <T> T getService(Class<T> serviceType) {
- ServiceReference<T> ref = this.bundleContext.getServiceReference(serviceType);
- if(ref!=null){
- return this.bundleContext.getService(ref);
- }
- return null;
- }
-
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- List<ServiceReference<T>> refs = new ArrayList<>();
- try {
- refs.addAll(this.bundleContext.getServiceReferences(serviceType, null));
- Collections.sort(refs, REF_COMPARATOR);
- List<T> services = new ArrayList<>(refs.size());
- for(ServiceReference<T> ref:refs){
- T service = bundleContext.getService(ref);
- if(service!=null) {
- services.add(service);
- }
- }
- return services;
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- return Collections.emptyList();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
deleted file mode 100644
index dcc702f..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ConcurrentModificationException;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * An bundle listener that registers services defined in META-INF/services, when a bundle is starting.
- *
- * @author anatole@apache.org
- */
-public class OSGIServiceLoader implements BundleListener {
- // Provide logging
- private static final Logger log = Logger.getLogger(OSGIServiceLoader.class.getName());
-
- private Map<Class, ServiceTracker<Object,Object>> services = new ConcurrentHashMap<>();
-
- @Override
- public void bundleChanged(BundleEvent bundleEvent) {
- // Parse and create metadta on STARTING
- if (bundleEvent.getType() == BundleEvent.STARTED) {
- Bundle bundle = bundleEvent.getBundle();
- if (bundle.getEntry("META-INF/services/") == null) {
- return;
- }
- Enumeration<String> entryPaths = bundle.getEntryPaths("META-INF/services/");
- while (entryPaths.hasMoreElements()) {
- String entryPath = entryPaths.nextElement();
- if(!entryPath.endsWith("/")) {
- processEntryPath(bundle, entryPath);
- }
- }
- }
- }
-
- private void processEntryPath(Bundle bundle, String entryPath) {
- try {
- String serviceName = entryPath.substring("META-INF/services/".length());
- Class<?> serviceClass = bundle.loadClass(serviceName);
-
- URL child = bundle.getEntry(entryPath);
- InputStream inStream = child.openStream();
-
- BufferedReader br = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
- String implClassName = br.readLine();
- while (implClassName != null){
- int hashIndex = implClassName.indexOf("#");
- if (hashIndex > 0) {
- implClassName = implClassName.substring(0, hashIndex-1);
- }
- else if (hashIndex == 0) {
- implClassName = "";
- }
- implClassName = implClassName.trim();
- if (implClassName.length() > 0) {
- try {
- // Load the service class
- Class<?> implClass = (Class<?>) bundle.loadClass(implClassName);
- if (serviceClass.isAssignableFrom(implClass) == false) {
- log.warning("Configured service: " + implClassName + " is not assignble to " +
- serviceClass.getName());
- continue;
- }
- // Provide service properties
- Hashtable<String, String> props = new Hashtable<String, String>();
- props.put(Constants.VERSION_ATTRIBUTE, bundle.getVersion().toString());
- String vendor = (String) bundle.getHeaders().get(Constants.BUNDLE_VENDOR);
- props.put(Constants.SERVICE_VENDOR, (vendor != null ? vendor : "anonymous"));
- // Translate annotated @Priority into a service ranking
- props.put(Constants.SERVICE_RANKING,
- String.valueOf(PriorityServiceComparator.getPriority(implClass)));
-
- // Register the service factory on behalf of the intercepted bundle
- JDKUtilServiceFactory factory = new JDKUtilServiceFactory(implClass);
- BundleContext bundleContext = bundle.getBundleContext();
- bundleContext.registerService(serviceName, factory, props);
- }
- catch(Exception e){
- log.log(Level.SEVERE,
- "Failed to load service class using ServiceLoader logic: " + implClassName, e);
- }
- }
- implClassName = br.readLine();
- }
- br.close();
- }
- catch (RuntimeException rte) {
- throw rte;
- }
- catch (Exception e) {
- log.log(Level.SEVERE, "Failed to read services from: " + entryPath, e);
- }
- }
-
-
- /**
- * Service factory simply instantiating the configured service.
- */
- static class JDKUtilServiceFactory implements ServiceFactory
- {
- private Class<?> serviceClass;
-
- public JDKUtilServiceFactory(Class<?> serviceClass) {
- this.serviceClass = serviceClass;
- }
-
- @Override
- public Object getService(Bundle bundle, ServiceRegistration registration) {
- try {
- Object serviceInstance = serviceClass.newInstance();
- return serviceInstance;
- }
- catch (Exception ex) {
- ex.printStackTrace();
- throw new IllegalStateException("Cannot instanciate service", ex);
- }
- }
-
- @Override
- public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java b/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java
deleted file mode 100644
index c0cfca6..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PriorityServiceComparator.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import javax.annotation.Priority;
-import java.util.Comparator;
-
-/**
- * Comparator implementation for odering services loaded based on their increasing priority values.
- */
-public class PriorityServiceComparator implements Comparator<Object> {
-
- @Override
- public int compare(Object o1, Object o2) {
- int prio = getPriority(o1) - getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
- * annotation is present, a default priority is returned (1);
- *
- * @param o the instance, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o) {
- return getPriority(o.getClass());
- }
-
- /**
- * Checks the given type optionally annotated with a @Priority. If present the annotation's value s evaluated.
- * If no such annotation is present, a default priority is returned (1);
- *
- * @param type the type, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Class type) {
- int prio = 1;
- Priority priority = (Priority)type.getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
deleted file mode 100644
index 2a15e1d..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.internal.converters.EnumConverter;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-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.ReadWriteLock;
-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<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
- /**
- * The transitive converters.
- */
- private Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>();
- /**
- * The lock used.
- */
- private ReadWriteLock lock = new ReentrantReadWriteLock();
-
- private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- int prio = DefaultServiceContext.getPriority(o1) - DefaultServiceContext.getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
- };
-
- /**
- * Constructor.
- */
- public PropertyConverterManager() {
- this(true);
- }
-
- public PropertyConverterManager(boolean init) {
- if (init) {
- initConverters();
- }
- }
-
- /**
- * Registers the default converters provided out of the box.
- */
- protected void initConverters() {
- for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
- register(TypeLiteral.of(type), conv);
- }
- }
-
- /**
- * Registers a ew converter instance.
- *
- * @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
- */
- public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
- Objects.requireNonNull(converter);
- Lock writeLock = lock.writeLock();
- try {
- writeLock.lock();
- List converters = List.class.cast(this.converters.get(targetType));
- List<PropertyConverter<?>> newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- // evaluate transitive closure for all inherited supertypes and implemented interfaces
- // direct implemented interfaces
- for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- Class<?> superClass = targetType.getRawType().getSuperclass();
- while (superClass != null && !superClass.equals(Object.class)) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
- for (Class<?> ifaceType : superClass.getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- superClass = superClass.getSuperclass();
- }
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Allows to evaluate if a given target type is supported.
- *
- * @param targetType the target type, not null.
- * @return true, if a converter for the given type is registered, or a default one can be created.
- */
- public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
- if (converters.containsKey(targetType) || transitiveConverters.containsKey(targetType)) {
- return true;
- }
- return createDefaultPropertyConverter(targetType) != null;
- }
-
- /**
- * Get a map of all property converters currently registered. This will not contain the converters that
- * may be created, when an instance is adapted, which provides a String constructor or compatible
- * factory methods taking a single String instance.
- *
- * @return the current map of instantiated and registered converters.
- * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
- */
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- Lock readLock = lock.readLock();
- try {
- readLock.lock();
- return new HashMap<>(this.converters);
- } finally {
- readLock.unlock();
- }
- }
-
- /**
- * Get the list of all current registered converters for the given target type.
- * If not converters are registered, they component tries to create and register a dynamic
- * converter based on String costructor or static factory methods available.<br/>
- * The converters provided are of the following type and returned in the following order:
- * <ul>
- * <li>Converters mapped explicitly to the required target type are returned first, ordered
- * by decreasing priority. This means, if explicit converters are registered these are used
- * primarly for converting a value.</li>
- * <li>The target type of each explicitly registered converter also can be transitively mapped to
- * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces
- * implemented by its superclasses. These groups of transitive converters is returned similarly in the
- * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li>
- * <li>java.lang wrapper classes and native types are automatically mapped.</li>
- * <li>If no explicit converters are registered, for Enum types a default implementation is provided that
- * compares the configuration values with the different enum members defined (cases sensitive mapping).</li>
- * </ul>
- * <p>
- * So given that list above directly registered mappings always are tried first, before any transitive mapping
- * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place.
- * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and
- * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored.
- *
- * @param targetType the target type, not null.
- * @param <T> the type class
- * @return the ordered list of converters (may be empty for not convertible types).
- * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
- */
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- Lock readLock = lock.readLock();
- List<PropertyConverter<T>> converterList = new ArrayList<>();
- List<PropertyConverter<T>> converters;
- // direct mapped converters
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(targetType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- // transitive converter
- try {
- readLock.lock();
- converters = List.class.cast(this.transitiveConverters.get(targetType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- // handling of java.lang wrapper classes
- TypeLiteral<T> boxedType = mapBoxedType(targetType);
- if (boxedType != null) {
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(boxedType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- }
- if (converterList.isEmpty()) {
- // adding any converters created on the fly, e.g. for enum types.
- PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if (defaultConverter != null) {
- register(targetType, defaultConverter);
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(targetType));
- } finally {
- readLock.unlock();
- }
- }
- if (converters != null) {
- converterList.addAll(converters);
- }
- }
- return converterList;
- }
-
- /**
- * Maps native types to the corresponding boxed types.
- *
- * @param targetType the native type.
- * @param <T> the type
- * @return the boxed type, or null.
- */
- private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
- Type parameterType = targetType.getType();
- if (parameterType == int.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Integer.class));
- }
- if (parameterType == short.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Short.class));
- }
- if (parameterType == byte.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Byte.class));
- }
- if (parameterType == long.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Long.class));
- }
- if (parameterType == boolean.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
- }
- if (parameterType == char.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Character.class));
- }
- if (parameterType == float.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Float.class));
- }
- if (parameterType == double.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Double.class));
- }
- if (parameterType == int[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class));
- }
- if (parameterType == short[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Short[].class));
- }
- if (parameterType == byte[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class));
- }
- if (parameterType == long[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
- }
- if (parameterType == boolean.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
- }
- if (parameterType == char[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));
- }
- if (parameterType == float[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Float[].class));
- }
- if (parameterType == double[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Double[].class));
- }
- return null;
- }
-
- /**
- * Creates a dynamic PropertyConverter for the given target type.
- *
- * @param targetType the target type
- * @param <T> the type class
- * @return a new converter, or null.
- */
- protected <T> PropertyConverter<T> createDefaultPropertyConverter(final TypeLiteral<T> targetType) {
- if (Enum.class.isAssignableFrom(targetType.getRawType())) {
- return new EnumConverter<>(targetType.getRawType());
- }
- PropertyConverter<T> converter = null;
- final Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
- if (factoryMethod != null) {
- converter = new DefaultPropertyConverter<>(factoryMethod, targetType.getRawType());
- }
- if (converter == null) {
- final Constructor<T> constr;
- try {
- constr = targetType.getRawType().getDeclaredConstructor(String.class);
- } catch (NoSuchMethodException e) {
- LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e);
- return null;
- }
- converter = new PropertyConverter<T>() {
- @Override
- public T convert(String value, ConversionContext context) {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- constr.setAccessible(true);
- return null;
- }
- });
- return null;
- }
- });
- try {
- return constr.newInstance(value);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e);
- }
- return null;
- }
- };
- }
- return converter;
- }
-
- /**
- * Tries to evaluate a factory method that can be used to create an instance based on a String.
- *
- * @param type the target type
- * @param methodNames the possible static method names
- * @return the first method found, or null.
- */
- private Method getFactoryMethod(Class<?> type, String... methodNames) {
- Method m;
- for (String name : methodNames) {
- try {
- m = type.getDeclaredMethod(name, String.class);
- return m;
- } catch (NoSuchMethodException | RuntimeException e) {
- LOG.finest("No such factory method found on type: " + type.getName() + ", methodName: " + name);
- }
- }
- return null;
- }
-
- private static class DefaultPropertyConverter<T> implements PropertyConverter<T> {
-
- private Method factoryMethod;
- private Class<T> targetType;
-
- DefaultPropertyConverter(Method factoryMethod, Class<T> targetType){
- this.factoryMethod = Objects.requireNonNull(factoryMethod);
- this.targetType = Objects.requireNonNull(targetType);
- }
-
- @Override
- public T convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<String -> "+factoryMethod.toGenericString());
-
- if (!Modifier.isStatic(factoryMethod.getModifiers())) {
- throw new ConfigException(factoryMethod.toGenericString() +
- " is not a static method. Only static " +
- "methods can be used as factory methods.");
- }
- try {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- factoryMethod.setAccessible(true);
- return null;
- }
- });
- Object invoke = factoryMethod.invoke(null, value);
- return targetType.cast(invoke);
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + value + "'", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java
deleted file mode 100644
index abf22be..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-import javax.annotation.Priority;
-import java.io.Serializable;
-import java.util.Comparator;
-
-/**
- * Comparator for PropertyFilters based on their priority annotations.
- */
-public 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);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
deleted file mode 100644
index 9f84e7c..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.HashMap;
-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 PropertySource} and {@link PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public final class PropertyFiltering{
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(PropertyFiltering.class.getName());
- /**
- * The maximal number of filter cycles performed before aborting.
- */
- private static final int MAX_FILTER_LOOPS = 10;
-
- /**
- * Private singleton constructor.
- */
- private PropertyFiltering(){}
-
- public static String applyFilter(String key, String unfilteredValue, ConfigurationContext configurationContext) {
- // 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;
- }
-
- public static Map<String, String> applyFilters(Map<String, String> inputMap, ConfigurationContext configurationContext) {
- Map<String, String> resultMap = new HashMap<>(inputMap);
- // 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);
- }
- else{
- resultMap.remove(k);
- }
- }
- }
- 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java
deleted file mode 100644
index 24ee1f2..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.io.Serializable;
-import java.util.Comparator;
-
-/**
- * Comparator for ordering of PropertySources based on their ordinal method and class name.
- */
-public 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 source1.getClass().getName().compareTo(source2.getClass().getName());
- }
- }
-
- @Override
- public int compare(PropertySource source1, PropertySource source2) {
- return comparePropertySources(source1, source2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java b/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
deleted file mode 100644
index 6c7a1d2..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-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;
- }
-}
[7/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
new file mode 100644
index 0000000..2a15e1d
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -0,0 +1,448 @@
+/*
+ * 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.TypeLiteral;
+import org.apache.tamaya.core.internal.converters.EnumConverter;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+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.ReadWriteLock;
+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<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ /**
+ * The transitive converters.
+ */
+ private Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>();
+ /**
+ * The lock used.
+ */
+ private ReadWriteLock lock = new ReentrantReadWriteLock();
+
+ private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() {
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ int prio = DefaultServiceContext.getPriority(o1) - DefaultServiceContext.getPriority(o2);
+ if (prio < 0) {
+ return 1;
+ } else if (prio > 0) {
+ return -1;
+ } else {
+ return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
+ }
+ }
+ };
+
+ /**
+ * Constructor.
+ */
+ public PropertyConverterManager() {
+ this(true);
+ }
+
+ public PropertyConverterManager(boolean init) {
+ if (init) {
+ initConverters();
+ }
+ }
+
+ /**
+ * Registers the default converters provided out of the box.
+ */
+ protected void initConverters() {
+ for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
+ register(TypeLiteral.of(type), conv);
+ }
+ }
+
+ /**
+ * Registers a ew converter instance.
+ *
+ * @param targetType the target type, not null.
+ * @param converter the converter, not null.
+ * @param <T> the type.
+ */
+ public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
+ Objects.requireNonNull(converter);
+ Lock writeLock = lock.writeLock();
+ try {
+ writeLock.lock();
+ List converters = List.class.cast(this.converters.get(targetType));
+ List<PropertyConverter<?>> newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.converters.put(targetType, Collections.unmodifiableList(newConverters));
+ // evaluate transitive closure for all inherited supertypes and implemented interfaces
+ // direct implemented interfaces
+ for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
+ }
+ Class<?> superClass = targetType.getRawType().getSuperclass();
+ while (superClass != null && !superClass.equals(Object.class)) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
+ for (Class<?> ifaceType : superClass.getInterfaces()) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
+ }
+ superClass = superClass.getSuperclass();
+ }
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Allows to evaluate if a given target type is supported.
+ *
+ * @param targetType the target type, not null.
+ * @return true, if a converter for the given type is registered, or a default one can be created.
+ */
+ public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
+ if (converters.containsKey(targetType) || transitiveConverters.containsKey(targetType)) {
+ return true;
+ }
+ return createDefaultPropertyConverter(targetType) != null;
+ }
+
+ /**
+ * Get a map of all property converters currently registered. This will not contain the converters that
+ * may be created, when an instance is adapted, which provides a String constructor or compatible
+ * factory methods taking a single String instance.
+ *
+ * @return the current map of instantiated and registered converters.
+ * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
+ */
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ Lock readLock = lock.readLock();
+ try {
+ readLock.lock();
+ return new HashMap<>(this.converters);
+ } finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * Get the list of all current registered converters for the given target type.
+ * If not converters are registered, they component tries to create and register a dynamic
+ * converter based on String costructor or static factory methods available.<br/>
+ * The converters provided are of the following type and returned in the following order:
+ * <ul>
+ * <li>Converters mapped explicitly to the required target type are returned first, ordered
+ * by decreasing priority. This means, if explicit converters are registered these are used
+ * primarly for converting a value.</li>
+ * <li>The target type of each explicitly registered converter also can be transitively mapped to
+ * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces
+ * implemented by its superclasses. These groups of transitive converters is returned similarly in the
+ * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li>
+ * <li>java.lang wrapper classes and native types are automatically mapped.</li>
+ * <li>If no explicit converters are registered, for Enum types a default implementation is provided that
+ * compares the configuration values with the different enum members defined (cases sensitive mapping).</li>
+ * </ul>
+ * <p>
+ * So given that list above directly registered mappings always are tried first, before any transitive mapping
+ * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place.
+ * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and
+ * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored.
+ *
+ * @param targetType the target type, not null.
+ * @param <T> the type class
+ * @return the ordered list of converters (may be empty for not convertible types).
+ * @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
+ */
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ Lock readLock = lock.readLock();
+ List<PropertyConverter<T>> converterList = new ArrayList<>();
+ List<PropertyConverter<T>> converters;
+ // direct mapped converters
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ // transitive converter
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.transitiveConverters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ // handling of java.lang wrapper classes
+ TypeLiteral<T> boxedType = mapBoxedType(targetType);
+ if (boxedType != null) {
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(boxedType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ }
+ if (converterList.isEmpty()) {
+ // adding any converters created on the fly, e.g. for enum types.
+ PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
+ if (defaultConverter != null) {
+ register(targetType, defaultConverter);
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ }
+ return converterList;
+ }
+
+ /**
+ * Maps native types to the corresponding boxed types.
+ *
+ * @param targetType the native type.
+ * @param <T> the type
+ * @return the boxed type, or null.
+ */
+ private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
+ Type parameterType = targetType.getType();
+ if (parameterType == int.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Integer.class));
+ }
+ if (parameterType == short.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Short.class));
+ }
+ if (parameterType == byte.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Byte.class));
+ }
+ if (parameterType == long.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Long.class));
+ }
+ if (parameterType == boolean.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
+ }
+ if (parameterType == char.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Character.class));
+ }
+ if (parameterType == float.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Float.class));
+ }
+ if (parameterType == double.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Double.class));
+ }
+ if (parameterType == int[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class));
+ }
+ if (parameterType == short[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Short[].class));
+ }
+ if (parameterType == byte[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class));
+ }
+ if (parameterType == long[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
+ }
+ if (parameterType == boolean.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
+ }
+ if (parameterType == char[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));
+ }
+ if (parameterType == float[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Float[].class));
+ }
+ if (parameterType == double[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Double[].class));
+ }
+ return null;
+ }
+
+ /**
+ * Creates a dynamic PropertyConverter for the given target type.
+ *
+ * @param targetType the target type
+ * @param <T> the type class
+ * @return a new converter, or null.
+ */
+ protected <T> PropertyConverter<T> createDefaultPropertyConverter(final TypeLiteral<T> targetType) {
+ if (Enum.class.isAssignableFrom(targetType.getRawType())) {
+ return new EnumConverter<>(targetType.getRawType());
+ }
+ PropertyConverter<T> converter = null;
+ final Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
+ if (factoryMethod != null) {
+ converter = new DefaultPropertyConverter<>(factoryMethod, targetType.getRawType());
+ }
+ if (converter == null) {
+ final Constructor<T> constr;
+ try {
+ constr = targetType.getRawType().getDeclaredConstructor(String.class);
+ } catch (NoSuchMethodException e) {
+ LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e);
+ return null;
+ }
+ converter = new PropertyConverter<T>() {
+ @Override
+ public T convert(String value, ConversionContext context) {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ constr.setAccessible(true);
+ return null;
+ }
+ });
+ return null;
+ }
+ });
+ try {
+ return constr.newInstance(value);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e);
+ }
+ return null;
+ }
+ };
+ }
+ return converter;
+ }
+
+ /**
+ * Tries to evaluate a factory method that can be used to create an instance based on a String.
+ *
+ * @param type the target type
+ * @param methodNames the possible static method names
+ * @return the first method found, or null.
+ */
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for (String name : methodNames) {
+ try {
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ } catch (NoSuchMethodException | RuntimeException e) {
+ LOG.finest("No such factory method found on type: " + type.getName() + ", methodName: " + name);
+ }
+ }
+ return null;
+ }
+
+ private static class DefaultPropertyConverter<T> implements PropertyConverter<T> {
+
+ private Method factoryMethod;
+ private Class<T> targetType;
+
+ DefaultPropertyConverter(Method factoryMethod, Class<T> targetType){
+ this.factoryMethod = Objects.requireNonNull(factoryMethod);
+ this.targetType = Objects.requireNonNull(targetType);
+ }
+
+ @Override
+ public T convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<String -> "+factoryMethod.toGenericString());
+
+ if (!Modifier.isStatic(factoryMethod.getModifiers())) {
+ throw new ConfigException(factoryMethod.toGenericString() +
+ " is not a static method. Only static " +
+ "methods can be used as factory methods.");
+ }
+ try {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ factoryMethod.setAccessible(true);
+ return null;
+ }
+ });
+ Object invoke = factoryMethod.invoke(null, value);
+ return targetType.cast(invoke);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + value + "'", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.java
new file mode 100644
index 0000000..abf22be
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFilterComparator.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.internal;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Comparator for PropertyFilters based on their priority annotations.
+ */
+public 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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
new file mode 100644
index 0000000..9f84e7c
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertyFiltering.java
@@ -0,0 +1,131 @@
+/*
+ * 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.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.HashMap;
+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 PropertySource} and {@link PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+public final class PropertyFiltering{
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(PropertyFiltering.class.getName());
+ /**
+ * The maximal number of filter cycles performed before aborting.
+ */
+ private static final int MAX_FILTER_LOOPS = 10;
+
+ /**
+ * Private singleton constructor.
+ */
+ private PropertyFiltering(){}
+
+ public static String applyFilter(String key, String unfilteredValue, ConfigurationContext configurationContext) {
+ // 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;
+ }
+
+ public static Map<String, String> applyFilters(Map<String, String> inputMap, ConfigurationContext configurationContext) {
+ Map<String, String> resultMap = new HashMap<>(inputMap);
+ // 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);
+ }
+ else{
+ resultMap.remove(k);
+ }
+ }
+ }
+ 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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.java
new file mode 100644
index 0000000..24ee1f2
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/PropertySourceComparator.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.internal;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+/**
+ * Comparator for ordering of PropertySources based on their ordinal method and class name.
+ */
+public 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 source1.getClass().getName().compareTo(source2.getClass().getName());
+ }
+ }
+
+ @Override
+ public int compare(PropertySource source1, PropertySource source2) {
+ return comparePropertySources(source1, source2);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java b/code/core/src/main/java/org/apache/tamaya/core/internal/ReflectionUtil.java
new file mode 100644
index 0000000..6c7a1d2
--- /dev/null
+++ b/code/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/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
new file mode 100644
index 0000000..7057e73
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.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.core.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to BigDecimal, the supported format is one of the following:
+ * <ul>
+ * <li>232573527352.76352753</li>
+ * <li>-23257352.735276352753</li>
+ * <li>-0xFFFFFF (integral numbers only)</li>
+ * <li>-0XFFFFAC (integral numbers only)</li>
+ * <li>0xFFFFFF (integral numbers only)</li>
+ * <li>0XFFFFAC (integral numbers only)</li>
+ * </ul>
+ */
+public class BigDecimalConverter implements PropertyConverter<BigDecimal>{
+ /** The logger. */
+ private static final Logger LOG = Logger.getLogger(BigDecimalConverter.class.getName());
+ /** Converter to be used if the format is not directly supported by BigDecimal, e.g. for integral hex values. */
+ private BigIntegerConverter integerConverter = new BigIntegerConverter();
+
+ @Override
+ public BigDecimal convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)");
+
+ String trimmed = Objects.requireNonNull(value).trim();
+ try{
+ return new BigDecimal(trimmed);
+ } catch(Exception e){
+ LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value);
+ BigInteger bigInt = integerConverter.convert(value, context);
+ if(bigInt!=null){
+ return new BigDecimal(bigInt);
+ }
+ LOG.finest("Failed to parse BigDecimal from: " + value);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
new file mode 100644
index 0000000..57ff2fb
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
@@ -0,0 +1,94 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.math.BigInteger;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to BigInteger, the supported format is one of the following:
+ * <ul>
+ * <li>0xFFFFFF</li>
+ * <li>0XFFFFAC</li>
+ * <li>23257352735276352753</li>
+ * <li>-0xFFFFFF</li>
+ * <li>-0XFFFFAC</li>
+ * <li>-23257352735276352753</li>
+ * </ul>
+ */
+public class BigIntegerConverter implements PropertyConverter<BigInteger>{
+
+ /** The logger. */
+ private static final Logger LOG = Logger.getLogger(BigIntegerConverter.class.getName());
+ /** Converter used to decode hex, octal values. */
+ private ByteConverter byteConverter = new ByteConverter();
+
+ @Override
+ public BigInteger convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "[-]0X.. (hex)", "[-]0x... (hex)", "<bigint> -> new BigInteger(bigint)");
+ String trimmed = Objects.requireNonNull(value).trim();
+ if(trimmed.startsWith("0x") || trimmed.startsWith("0X")){
+ LOG.finest("Parsing Hex value to BigInteger: " + value);
+ trimmed = trimmed.substring(2);
+ StringBuilder decimal = new StringBuilder();
+ for(int offset = 0;offset < trimmed.length();offset+=2){
+ if(offset==trimmed.length()-1){
+ LOG.finest("Invalid Hex-Byte-String: " + value);
+ return null;
+ }
+ byte val = byteConverter.convert("0x" + trimmed.substring(offset, offset + 2), context);
+ if(val<10){
+ decimal.append('0').append(val);
+ } else{
+ decimal.append(val);
+ }
+ }
+ return new BigInteger(decimal.toString());
+ } else if(trimmed.startsWith("-0x") || trimmed.startsWith("-0X")){
+ LOG.finest("Parsing Hex value to BigInteger: " + value);
+ trimmed = trimmed.substring(3);
+ StringBuilder decimal = new StringBuilder();
+ for(int offset = 0;offset < trimmed.length();offset+=2){
+ if(offset==trimmed.length()-1){
+ LOG.finest("Invalid Hex-Byte-String: " + trimmed);
+ return null;
+ }
+ byte val = byteConverter.convert("0x" + trimmed.substring(offset, offset + 2), context);
+ if(val<10){
+ decimal.append('0').append(val);
+ } else{
+ decimal.append(val);
+ }
+ }
+ return new BigInteger('-' + decimal.toString());
+ }
+ try{
+ return new BigInteger(trimmed);
+ } catch(Exception e){
+ LOG.log(Level.FINEST, "Failed to parse BigInteger from: " + value, e);
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
new file mode 100644
index 0000000..d0f596d
--- /dev/null
+++ b/code/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.ConversionContext;
+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, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)");
+ 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.finest("Unknown boolean value encountered: " + value);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
new file mode 100644
index 0000000..ed193d8
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.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.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Byte, the supported format is one of the following:
+ * <ul>
+ * <li>123 (byte value)</li>
+ * <li>0xFF (byte value)</li>
+ * <li>0XDF (byte value)</li>
+ * <li>0D1 (byte value)</li>
+ * <li>-123 (byte value)</li>
+ * <li>-0xFF (byte value)</li>
+ * <li>-0XDF (byte value)</li>
+ * <li>-0D1 (byte value)</li>
+ * <li>MIN_VALUE (ignoring case)</li>
+ * <li>MIN (ignoring case)</li>
+ * <li>MAX_VALUE (ignoring case)</li>
+ * <li>MAX (ignoring case)</li>
+ * </ul>
+ */
+public class ByteConverter implements PropertyConverter<Byte>{
+
+ private Logger LOG = Logger.getLogger(getClass().getName());
+
+ @Override
+ public Byte convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(),"<byte>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX");
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch(trimmed.toUpperCase(Locale.ENGLISH)){
+ case "MIN_VALUE":
+ case "MIN":
+ return Byte.MIN_VALUE;
+ case "MAX_VALUE":
+ case "MAX":
+ return Byte.MAX_VALUE;
+ default:
+ try{
+ return Byte.decode(trimmed);
+ }
+ catch(Exception e){
+ LOG.log(Level.FINEST, "Unparseable Byte: " + value);
+ return null;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
new file mode 100644
index 0000000..dd6f557
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
@@ -0,0 +1,69 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Character, the supported format is one of the following:
+ * <ul>
+ * <li>'a'</li>
+ * <li>123 (byte value)</li>
+ * <li>0xFF (byte value)</li>
+ * <li>0XDF (byte value)</li>
+ * <li>0D1 (byte value)</li>
+ * </ul>
+ */
+public class CharConverter implements PropertyConverter<Character>{
+
+ private static final Logger LOG = Logger.getLogger(CharConverter.class.getName());
+
+ @Override
+ public Character convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(),"\\'<char>\\'", "<char>", "<charNum>");
+ String trimmed = Objects.requireNonNull(value).trim();
+ if(trimmed.isEmpty()){
+ return null;
+ }
+ if(trimmed.startsWith("'")) {
+ try {
+ trimmed = trimmed.substring(1, trimmed.length() - 1);
+ if (trimmed.isEmpty()) {
+ return null;
+ }
+ return trimmed.charAt(0);
+ } catch (Exception e) {
+ LOG.finest("Invalid character format encountered: '" + value + "', valid formats are 'a', 101 and a.");
+ return null;
+ }
+ }
+ try {
+ Integer val = Integer.parseInt(trimmed);
+ return (char) val.shortValue();
+ } catch (Exception e) {
+ LOG.finest("Character format is not numeric: '" + value + "', using first character.");
+ return trimmed.charAt(0);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
new file mode 100644
index 0000000..8fd3cb8
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.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.core.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Class, hereby using the following classloaders:
+ * <ul>
+ * <li>The current ThreadContext ClassLoader</li>
+ * <li>The Classloader of this class</li>
+ * <li>The system Classloader</li>
+ * </ul>
+ */
+public class ClassConverter implements PropertyConverter<Class<?>>{
+
+ private Logger LOG = Logger.getLogger(getClass().getName());
+
+ @Override
+ public Class<?> convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(),"<fullyQualifiedClassName>");
+ String trimmed = Objects.requireNonNull(value).trim();
+ try{
+ return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader());
+ }
+ catch(Exception e){
+ LOG.finest("Class not found in context CL: " + trimmed);
+ }
+ try{
+ return Class.forName(trimmed, false, ClassConverter.class.getClassLoader());
+ }
+ catch(Exception e){
+ LOG.finest("Class not found in ClassConverter's CL: " + trimmed);
+ }
+ try{
+ return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader());
+ }
+ catch(Exception e){
+ LOG.finest("Class not found in System CL (giving up): " + trimmed);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
new file mode 100644
index 0000000..50fded7
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Currency;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Currency, the supported format is one of the following:
+ * <ul>
+ * <li>CHF (currency code)</li>
+ * <li>123 (numeric currency value >= 0)</li>
+ * <li>DE (ISO 2-digit country)</li>
+ * <li>de_DE, de_DE_123 (Locale)</li>
+ * </ul>
+ */
+public class CurrencyConverter implements PropertyConverter<Currency> {
+
+ private static final Logger LOG = Logger.getLogger(CurrencyConverter.class.getName());
+
+ @Override
+ public Currency convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<currencyCode>, using Locale.ENGLISH", "<numericValue>", "<locale>");
+ String trimmed = Objects.requireNonNull(value).trim();
+ try {
+ return Currency.getInstance(trimmed.toUpperCase(Locale.ENGLISH));
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, "Not a valid textual currency code: " + trimmed + ", checking for numeric...", e);
+ }
+ try {
+ // Check for numeric code
+ Integer numCode = Integer.parseInt(trimmed);
+ for (Currency currency : Currency.getAvailableCurrencies()) {
+ if (currency.getNumericCode() == numCode) {
+ return currency;
+ }
+ }
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, "Not a valid numeric currency code: " + trimmed + ", checking for locale...", e);
+ }
+ try {
+ // Check for numeric code
+ String[] parts = trimmed.split("\\_");
+ Locale locale;
+ switch (parts.length) {
+ case 1:
+ locale = new Locale("", parts[0]);
+ break;
+ case 2:
+ locale = new Locale(parts[0], parts[1]);
+ break;
+ case 3:
+ locale = new Locale(parts[0], parts[1], parts[2]);
+ break;
+ default:
+ locale = null;
+ }
+ if (locale != null) {
+ return Currency.getInstance(locale);
+ }
+ LOG.finest("Not a valid currency: " + trimmed + ", giving up...");
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, "Not a valid country locale for currency: " + trimmed + ", giving up...", e);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
new file mode 100644
index 0000000..b843d91
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
@@ -0,0 +1,81 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Double, using the Java number syntax:
+ * (-)?[0-9]*\.[0-9]*. In case of error the value given also is tried being parsed as integral number using
+ * {@link LongConverter}. Additionally the following values are supported:
+ * <ul>
+ * <li>NaN (ignoring case)</li>
+ * <li>POSITIVE_INFINITY (ignoring case)</li>
+ * <li>NEGATIVE_INFINITY (ignoring case)</li>
+ * </ul>
+ */
+public class DoubleConverter implements PropertyConverter<Double> {
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(DoubleConverter.class.getName());
+ /**
+ * The converter used, when floating point parse failed.
+ */
+ private LongConverter integerConverter = new LongConverter();
+
+ @Override
+ public Double convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<double>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE", "POSITIVE_INFINITY", "NEGATIVE_INFINITY", "NAN");
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch (trimmed.toUpperCase(Locale.ENGLISH)) {
+ case "POSITIVE_INFINITY":
+ return Double.POSITIVE_INFINITY;
+ case "NEGATIVE_INFINITY":
+ return Double.NEGATIVE_INFINITY;
+ case "NAN":
+ return Double.NaN;
+ case "MIN_VALUE":
+ case "MIN":
+ return Double.MIN_VALUE;
+ case "MAX_VALUE":
+ case "MAX":
+ return Double.MAX_VALUE;
+ default:
+ try {
+ return Double.valueOf(trimmed);
+ } catch (Exception e) {
+ // OK perhaps we have an integral number that must be converted to the double type...
+ LOG.finest("Parsing of double as floating number failed, trying parsing integral" +
+ " number/hex instead...");
+ }
+ Long val = integerConverter.convert(trimmed, context);
+ if(val!=null){
+ return val.doubleValue();
+ }
+ return null;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
new file mode 100644
index 0000000..1cf68fe
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.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.internal.converters;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Level;
+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, ConversionContext context) {
+ context.addSupportedFormats(getClass(),"<enumValue>");
+ try {
+ return (T) factory.invoke(null, value);
+ } catch (InvocationTargetException | IllegalAccessException e) {
+ LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
+ }
+ try {
+ return (T) factory.invoke(null, value.toUpperCase(Locale.ENGLISH));
+ } catch (InvocationTargetException | IllegalAccessException e) {
+ LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
new file mode 100644
index 0000000..1cbb273
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
@@ -0,0 +1,81 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Float, using the Java number syntax:
+ * (-)?[0-9]*\.[0-9]*. In case of error the value given also is tried being parsed as integral number using
+ * {@link LongConverter}. Additionally the following values are supported:
+ * <ul>
+ * <li>NaN (ignoring case)</li>
+ * <li>POSITIVE_INFINITY (ignoring case)</li>
+ * <li>NEGATIVE_INFINITY (ignoring case)</li>
+ * </ul>
+ */
+public class FloatConverter implements PropertyConverter<Float> {
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(FloatConverter.class.getName());
+ /**
+ * The converter used, when floating point parse failed.
+ */
+ private IntegerConverter integerConverter = new IntegerConverter();
+
+ @Override
+ public Float convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<float>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE", "POSITIVE_INFINITY", "NEGATIVE_INFINITY", "NAN");
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch(trimmed.toUpperCase(Locale.ENGLISH)){
+ case "POSITIVE_INFINITY":
+ return Float.POSITIVE_INFINITY;
+ case "NEGATIVE_INFINITY":
+ return Float.NEGATIVE_INFINITY;
+ case "NAN":
+ return Float.NaN;
+ case "MIN_VALUE":
+ case "MIN":
+ return Float.MIN_VALUE;
+ case "MAX_VALUE":
+ case "MAX":
+ return Float.MAX_VALUE;
+ default:
+ try {
+ return Float.valueOf(trimmed);
+ } catch(Exception e){
+ // OK perhaps we have an integral number that must be converted to the double type...
+ LOG.finest("Parsing of float as floating number failed, trying parsing integral" +
+ " number/hex instead...");
+ }
+ Integer val = integerConverter.convert(trimmed, context);
+ if(val!=null) {
+ return val.floatValue();
+ }
+ LOG.finest("Unparseable float value: " + trimmed);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
new file mode 100644
index 0000000..313cb63
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
@@ -0,0 +1,74 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Integer, the supported format is one of the following:
+ * <ul>
+ * <li>123 (byte value)</li>
+ * <li>0xFF (byte value)</li>
+ * <li>0XDF (byte value)</li>
+ * <li>0D1 (byte value)</li>
+ * <li>-123 (byte value)</li>
+ * <li>-0xFF (byte value)</li>
+ * <li>-0XDF (byte value)</li>
+ * <li>-0D1 (byte value)</li>
+ * <li>MIN_VALUE (ignoring case)</li>
+ * <li>MIN (ignoring case)</li>
+ * <li>MAX_VALUE (ignoring case)</li>
+ * <li>MAX (ignoring case)</li>
+ * </ul>
+ */
+public class IntegerConverter implements PropertyConverter<Integer>{
+
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(IntegerConverter.class.getName());
+
+ @Override
+ public Integer convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX");
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch(trimmed.toUpperCase(Locale.ENGLISH)){
+ case "MIN_VALUE":
+ case "MIN":
+ return Integer.MIN_VALUE;
+ case "MAX_VALUE":
+ case "MAX":
+ return Integer.MAX_VALUE;
+ default:
+ try{
+ return Integer.decode(trimmed);
+ }
+ catch(Exception e){
+ LOG.finest("Unparseable Integer value: " + trimmed);
+ return null;
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
new file mode 100644
index 0000000..11cda90
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Long, the supported format is one of the following:
+ * <ul>
+ * <li>123 (byte value)</li>
+ * <li>0xFF (byte value)</li>
+ * <li>0XDF (byte value)</li>
+ * <li>0D1 (byte value)</li>
+ * <li>-123 (byte value)</li>
+ * <li>-0xFF (byte value)</li>
+ * <li>-0XDF (byte value)</li>
+ * <li>-0D1 (byte value)</li>
+ * <li>MIN_VALUE (ignoring case)</li>
+ * <li>MIN (ignoring case)</li>
+ * <li>MAX_VALUE (ignoring case)</li>
+ * <li>MAX (ignoring case)</li>
+ * </ul>
+ */
+public class LongConverter implements PropertyConverter<Long>{
+
+ private static final Logger LOGGER = Logger.getLogger(LongConverter.class.getName());
+
+ @Override
+ public Long convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<long>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE");
+
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch (trimmed.toUpperCase(Locale.ENGLISH)) {
+ case "MIN_VALUE":
+ case "MIN":
+ return Long.MIN_VALUE;
+ case "MAX_VALUE":
+ case "MAX":
+ return Long.MAX_VALUE;
+ default:
+ try {
+ return Long.decode(trimmed);
+ }
+ catch(Exception e){
+ LOGGER.finest("Unable to parse Long value: " + value);
+ return null;
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
new file mode 100644
index 0000000..83fd3c0
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Number. Valid inputs are:
+ * <pre>
+ * POSITIVE_INFINITY -> Double.POSITIVE_INFINITY
+ * NEGATIVE_INFINITY -> Double.NEGATIVE_INFINITY
+ * NaN -> Double.NaN
+ * 0xFFDCD3D2 -> Long
+ * 1234566789.23642327352735273752 -> new BigDecimal(input)
+ * </pre>
+ */
+public class NumberConverter implements PropertyConverter<Number>{
+ /** the logger. */
+ private static final Logger LOGGER = Logger.getLogger(NumberConverter.class.getName());
+ /** Converter used for trying to parse as an integral value. */
+ private LongConverter longConverter = new LongConverter();
+
+ @Override
+ public Number convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<double>, <long>", "0x (hex)", "0X... (hex)", "POSITIVE_INFINITY",
+ "NEGATIVE_INFINITY", "NAN");
+
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch(trimmed.toUpperCase(Locale.ENGLISH)) {
+ case "POSITIVE_INFINITY":
+ return Double.POSITIVE_INFINITY;
+ case "NEGATIVE_INFINITY":
+ return Double.NEGATIVE_INFINITY;
+ case "NAN":
+ return Double.NaN;
+ default:
+ Long lVal = longConverter.convert(trimmed, context);
+ if (lVal != null) {
+ return lVal;
+ }
+ try{
+ return new BigDecimal(trimmed);
+ }
+ catch(Exception e){
+ LOGGER.finest("Unparseable Number: " + trimmed);
+ return null;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
new file mode 100644
index 0000000..dd9ebdd
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to Short, the supported format is one of the following:
+ * <ul>
+ * <li>123 (byte value)</li>
+ * <li>0xFF (byte value)</li>
+ * <li>0XDF (byte value)</li>
+ * <li>0D1 (byte value)</li>
+ * <li>-123 (byte value)</li>
+ * <li>-0xFF (byte value)</li>
+ * <li>-0XDF (byte value)</li>
+ * <li>-0D1 (byte value)</li>
+ * <li>MIN_VALUE (ignoring case)</li>
+ * <li>MIN (ignoring case)</li>
+ * <li>MAX_VALUE (ignoring case)</li>
+ * <li>MAX (ignoring case)</li>
+ * </ul>
+ */
+public class ShortConverter implements PropertyConverter<Short>{
+
+ /** the logger. */
+ private static final Logger LOG = Logger.getLogger(ShortConverter.class.getName());
+
+ @Override
+ public Short convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "short", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE");
+ String trimmed = Objects.requireNonNull(value).trim();
+ switch(trimmed.toUpperCase(Locale.ENGLISH)){
+ case "MIN_VALUE":
+ case "MIN":
+ return Short.MIN_VALUE;
+ case "MAX_VALUE":
+ case "MAX":
+ return Short.MAX_VALUE;
+ default:
+ try{
+ return Short.decode(trimmed);
+ }
+ catch(Exception e){
+ LOG.finest("Unparseable Short: " + trimmed);
+ return null;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
new file mode 100644
index 0000000..74b1337
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.net.URI;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to URI, using new URI(value).
+ */
+public class URIConverter implements PropertyConverter<URI> {
+
+ private Logger LOG = Logger.getLogger(getClass().getName());
+
+ @Override
+ public URI convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(), "<uri> -> new URI(uri)");
+ String trimmed = Objects.requireNonNull(value).trim();
+ try {
+ return new URI(trimmed);
+ } catch (Exception e) {
+ LOG.log(Level.FINE, "Unparseable URI: " + trimmed, e);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
new file mode 100644
index 0000000..4125c8a
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.net.URL;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to URI, using new URL(value).
+ */
+public class URLConverter implements PropertyConverter<URL> {
+
+ private Logger LOG = Logger.getLogger(getClass().getName());
+
+ @Override
+ public URL convert(String value, ConversionContext context) {
+ context.addSupportedFormats(getClass(),"<URL>");
+ String trimmed = Objects.requireNonNull(value).trim();
+ try {
+ return new URL(trimmed);
+ } catch (Exception e) {
+ LOG.log(Level.FINE, "Unparseable URL: " + trimmed, e);
+ }
+ return null;
+ }
+}
[3/8] incubator-tamaya git commit: Moved module core to ./code/
Posted by pl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
deleted file mode 100644
index 7057e73..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/BigDecimalConverter.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to BigDecimal, the supported format is one of the following:
- * <ul>
- * <li>232573527352.76352753</li>
- * <li>-23257352.735276352753</li>
- * <li>-0xFFFFFF (integral numbers only)</li>
- * <li>-0XFFFFAC (integral numbers only)</li>
- * <li>0xFFFFFF (integral numbers only)</li>
- * <li>0XFFFFAC (integral numbers only)</li>
- * </ul>
- */
-public class BigDecimalConverter implements PropertyConverter<BigDecimal>{
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(BigDecimalConverter.class.getName());
- /** Converter to be used if the format is not directly supported by BigDecimal, e.g. for integral hex values. */
- private BigIntegerConverter integerConverter = new BigIntegerConverter();
-
- @Override
- public BigDecimal convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<bigDecimal> -> new BigDecimal(String)");
-
- String trimmed = Objects.requireNonNull(value).trim();
- try{
- return new BigDecimal(trimmed);
- } catch(Exception e){
- LOG.finest("Parsing BigDecimal failed, trying BigInteger for: " + value);
- BigInteger bigInt = integerConverter.convert(value, context);
- if(bigInt!=null){
- return new BigDecimal(bigInt);
- }
- LOG.finest("Failed to parse BigDecimal from: " + value);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
deleted file mode 100644
index 57ff2fb..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/BigIntegerConverter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.math.BigInteger;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to BigInteger, the supported format is one of the following:
- * <ul>
- * <li>0xFFFFFF</li>
- * <li>0XFFFFAC</li>
- * <li>23257352735276352753</li>
- * <li>-0xFFFFFF</li>
- * <li>-0XFFFFAC</li>
- * <li>-23257352735276352753</li>
- * </ul>
- */
-public class BigIntegerConverter implements PropertyConverter<BigInteger>{
-
- /** The logger. */
- private static final Logger LOG = Logger.getLogger(BigIntegerConverter.class.getName());
- /** Converter used to decode hex, octal values. */
- private ByteConverter byteConverter = new ByteConverter();
-
- @Override
- public BigInteger convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "[-]0X.. (hex)", "[-]0x... (hex)", "<bigint> -> new BigInteger(bigint)");
- String trimmed = Objects.requireNonNull(value).trim();
- if(trimmed.startsWith("0x") || trimmed.startsWith("0X")){
- LOG.finest("Parsing Hex value to BigInteger: " + value);
- trimmed = trimmed.substring(2);
- StringBuilder decimal = new StringBuilder();
- for(int offset = 0;offset < trimmed.length();offset+=2){
- if(offset==trimmed.length()-1){
- LOG.finest("Invalid Hex-Byte-String: " + value);
- return null;
- }
- byte val = byteConverter.convert("0x" + trimmed.substring(offset, offset + 2), context);
- if(val<10){
- decimal.append('0').append(val);
- } else{
- decimal.append(val);
- }
- }
- return new BigInteger(decimal.toString());
- } else if(trimmed.startsWith("-0x") || trimmed.startsWith("-0X")){
- LOG.finest("Parsing Hex value to BigInteger: " + value);
- trimmed = trimmed.substring(3);
- StringBuilder decimal = new StringBuilder();
- for(int offset = 0;offset < trimmed.length();offset+=2){
- if(offset==trimmed.length()-1){
- LOG.finest("Invalid Hex-Byte-String: " + trimmed);
- return null;
- }
- byte val = byteConverter.convert("0x" + trimmed.substring(offset, offset + 2), context);
- if(val<10){
- decimal.append('0').append(val);
- } else{
- decimal.append(val);
- }
- }
- return new BigInteger('-' + decimal.toString());
- }
- try{
- return new BigInteger(trimmed);
- } catch(Exception e){
- LOG.log(Level.FINEST, "Failed to parse BigInteger from: " + value, e);
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
deleted file mode 100644
index d0f596d..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/BooleanConverter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-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, ConversionContext context) {
- context.addSupportedFormats(getClass(), "yes (ignore case)", "y (ignore case)", "true (ignore case)", "t (ignore case)", "no (ignore case)", "n (ignore case)", "false (ignore case)", "f (ignore case)");
- 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.finest("Unknown boolean value encountered: " + value);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
deleted file mode 100644
index ed193d8..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/ByteConverter.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Byte, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class ByteConverter implements PropertyConverter<Byte>{
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public Byte convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(),"<byte>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX");
- String trimmed = Objects.requireNonNull(value).trim();
- switch(trimmed.toUpperCase(Locale.ENGLISH)){
- case "MIN_VALUE":
- case "MIN":
- return Byte.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Byte.MAX_VALUE;
- default:
- try{
- return Byte.decode(trimmed);
- }
- catch(Exception e){
- LOG.log(Level.FINEST, "Unparseable Byte: " + value);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
deleted file mode 100644
index dd6f557..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Character, the supported format is one of the following:
- * <ul>
- * <li>'a'</li>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * </ul>
- */
-public class CharConverter implements PropertyConverter<Character>{
-
- private static final Logger LOG = Logger.getLogger(CharConverter.class.getName());
-
- @Override
- public Character convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(),"\\'<char>\\'", "<char>", "<charNum>");
- String trimmed = Objects.requireNonNull(value).trim();
- if(trimmed.isEmpty()){
- return null;
- }
- if(trimmed.startsWith("'")) {
- try {
- trimmed = trimmed.substring(1, trimmed.length() - 1);
- if (trimmed.isEmpty()) {
- return null;
- }
- return trimmed.charAt(0);
- } catch (Exception e) {
- LOG.finest("Invalid character format encountered: '" + value + "', valid formats are 'a', 101 and a.");
- return null;
- }
- }
- try {
- Integer val = Integer.parseInt(trimmed);
- return (char) val.shortValue();
- } catch (Exception e) {
- LOG.finest("Character format is not numeric: '" + value + "', using first character.");
- return trimmed.charAt(0);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
deleted file mode 100644
index 8fd3cb8..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/ClassConverter.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Class, hereby using the following classloaders:
- * <ul>
- * <li>The current ThreadContext ClassLoader</li>
- * <li>The Classloader of this class</li>
- * <li>The system Classloader</li>
- * </ul>
- */
-public class ClassConverter implements PropertyConverter<Class<?>>{
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public Class<?> convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(),"<fullyQualifiedClassName>");
- String trimmed = Objects.requireNonNull(value).trim();
- try{
- return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader());
- }
- catch(Exception e){
- LOG.finest("Class not found in context CL: " + trimmed);
- }
- try{
- return Class.forName(trimmed, false, ClassConverter.class.getClassLoader());
- }
- catch(Exception e){
- LOG.finest("Class not found in ClassConverter's CL: " + trimmed);
- }
- try{
- return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader());
- }
- catch(Exception e){
- LOG.finest("Class not found in System CL (giving up): " + trimmed);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
deleted file mode 100644
index 50fded7..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/CurrencyConverter.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Currency;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Currency, the supported format is one of the following:
- * <ul>
- * <li>CHF (currency code)</li>
- * <li>123 (numeric currency value >= 0)</li>
- * <li>DE (ISO 2-digit country)</li>
- * <li>de_DE, de_DE_123 (Locale)</li>
- * </ul>
- */
-public class CurrencyConverter implements PropertyConverter<Currency> {
-
- private static final Logger LOG = Logger.getLogger(CurrencyConverter.class.getName());
-
- @Override
- public Currency convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<currencyCode>, using Locale.ENGLISH", "<numericValue>", "<locale>");
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return Currency.getInstance(trimmed.toUpperCase(Locale.ENGLISH));
- } catch (Exception e) {
- LOG.log(Level.FINEST, "Not a valid textual currency code: " + trimmed + ", checking for numeric...", e);
- }
- try {
- // Check for numeric code
- Integer numCode = Integer.parseInt(trimmed);
- for (Currency currency : Currency.getAvailableCurrencies()) {
- if (currency.getNumericCode() == numCode) {
- return currency;
- }
- }
- } catch (Exception e) {
- LOG.log(Level.FINEST, "Not a valid numeric currency code: " + trimmed + ", checking for locale...", e);
- }
- try {
- // Check for numeric code
- String[] parts = trimmed.split("\\_");
- Locale locale;
- switch (parts.length) {
- case 1:
- locale = new Locale("", parts[0]);
- break;
- case 2:
- locale = new Locale(parts[0], parts[1]);
- break;
- case 3:
- locale = new Locale(parts[0], parts[1], parts[2]);
- break;
- default:
- locale = null;
- }
- if (locale != null) {
- return Currency.getInstance(locale);
- }
- LOG.finest("Not a valid currency: " + trimmed + ", giving up...");
- } catch (Exception e) {
- LOG.log(Level.FINEST, "Not a valid country locale for currency: " + trimmed + ", giving up...", e);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
deleted file mode 100644
index b843d91..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/DoubleConverter.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Double, using the Java number syntax:
- * (-)?[0-9]*\.[0-9]*. In case of error the value given also is tried being parsed as integral number using
- * {@link LongConverter}. Additionally the following values are supported:
- * <ul>
- * <li>NaN (ignoring case)</li>
- * <li>POSITIVE_INFINITY (ignoring case)</li>
- * <li>NEGATIVE_INFINITY (ignoring case)</li>
- * </ul>
- */
-public class DoubleConverter implements PropertyConverter<Double> {
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(DoubleConverter.class.getName());
- /**
- * The converter used, when floating point parse failed.
- */
- private LongConverter integerConverter = new LongConverter();
-
- @Override
- public Double convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<double>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE", "POSITIVE_INFINITY", "NEGATIVE_INFINITY", "NAN");
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "POSITIVE_INFINITY":
- return Double.POSITIVE_INFINITY;
- case "NEGATIVE_INFINITY":
- return Double.NEGATIVE_INFINITY;
- case "NAN":
- return Double.NaN;
- case "MIN_VALUE":
- case "MIN":
- return Double.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Double.MAX_VALUE;
- default:
- try {
- return Double.valueOf(trimmed);
- } catch (Exception e) {
- // OK perhaps we have an integral number that must be converted to the double type...
- LOG.finest("Parsing of double as floating number failed, trying parsing integral" +
- " number/hex instead...");
- }
- Long val = integerConverter.convert(trimmed, context);
- if(val!=null){
- return val.doubleValue();
- }
- return null;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
deleted file mode 100644
index 1cf68fe..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/EnumConverter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-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, ConversionContext context) {
- context.addSupportedFormats(getClass(),"<enumValue>");
- try {
- return (T) factory.invoke(null, value);
- } catch (InvocationTargetException | IllegalAccessException e) {
- LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
- }
- try {
- return (T) factory.invoke(null, value.toUpperCase(Locale.ENGLISH));
- } catch (InvocationTargetException | IllegalAccessException e) {
- LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
deleted file mode 100644
index 1cbb273..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/FloatConverter.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Float, using the Java number syntax:
- * (-)?[0-9]*\.[0-9]*. In case of error the value given also is tried being parsed as integral number using
- * {@link LongConverter}. Additionally the following values are supported:
- * <ul>
- * <li>NaN (ignoring case)</li>
- * <li>POSITIVE_INFINITY (ignoring case)</li>
- * <li>NEGATIVE_INFINITY (ignoring case)</li>
- * </ul>
- */
-public class FloatConverter implements PropertyConverter<Float> {
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(FloatConverter.class.getName());
- /**
- * The converter used, when floating point parse failed.
- */
- private IntegerConverter integerConverter = new IntegerConverter();
-
- @Override
- public Float convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<float>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE", "POSITIVE_INFINITY", "NEGATIVE_INFINITY", "NAN");
- String trimmed = Objects.requireNonNull(value).trim();
- switch(trimmed.toUpperCase(Locale.ENGLISH)){
- case "POSITIVE_INFINITY":
- return Float.POSITIVE_INFINITY;
- case "NEGATIVE_INFINITY":
- return Float.NEGATIVE_INFINITY;
- case "NAN":
- return Float.NaN;
- case "MIN_VALUE":
- case "MIN":
- return Float.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Float.MAX_VALUE;
- default:
- try {
- return Float.valueOf(trimmed);
- } catch(Exception e){
- // OK perhaps we have an integral number that must be converted to the double type...
- LOG.finest("Parsing of float as floating number failed, trying parsing integral" +
- " number/hex instead...");
- }
- Integer val = integerConverter.convert(trimmed, context);
- if(val!=null) {
- return val.floatValue();
- }
- LOG.finest("Unparseable float value: " + trimmed);
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
deleted file mode 100644
index 313cb63..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/IntegerConverter.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Integer, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class IntegerConverter implements PropertyConverter<Integer>{
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(IntegerConverter.class.getName());
-
- @Override
- public Integer convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<int>", "MIN_VALUE", "MIN", "MAX_VALUE", "MAX");
- String trimmed = Objects.requireNonNull(value).trim();
- switch(trimmed.toUpperCase(Locale.ENGLISH)){
- case "MIN_VALUE":
- case "MIN":
- return Integer.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Integer.MAX_VALUE;
- default:
- try{
- return Integer.decode(trimmed);
- }
- catch(Exception e){
- LOG.finest("Unparseable Integer value: " + trimmed);
- return null;
- }
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
deleted file mode 100644
index 11cda90..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/LongConverter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Long, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class LongConverter implements PropertyConverter<Long>{
-
- private static final Logger LOGGER = Logger.getLogger(LongConverter.class.getName());
-
- @Override
- public Long convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<long>", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE");
-
- String trimmed = Objects.requireNonNull(value).trim();
- switch (trimmed.toUpperCase(Locale.ENGLISH)) {
- case "MIN_VALUE":
- case "MIN":
- return Long.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Long.MAX_VALUE;
- default:
- try {
- return Long.decode(trimmed);
- }
- catch(Exception e){
- LOGGER.finest("Unable to parse Long value: " + value);
- return null;
- }
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
deleted file mode 100644
index 83fd3c0..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/NumberConverter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.math.BigDecimal;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Number. Valid inputs are:
- * <pre>
- * POSITIVE_INFINITY -> Double.POSITIVE_INFINITY
- * NEGATIVE_INFINITY -> Double.NEGATIVE_INFINITY
- * NaN -> Double.NaN
- * 0xFFDCD3D2 -> Long
- * 1234566789.23642327352735273752 -> new BigDecimal(input)
- * </pre>
- */
-public class NumberConverter implements PropertyConverter<Number>{
- /** the logger. */
- private static final Logger LOGGER = Logger.getLogger(NumberConverter.class.getName());
- /** Converter used for trying to parse as an integral value. */
- private LongConverter longConverter = new LongConverter();
-
- @Override
- public Number convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<double>, <long>", "0x (hex)", "0X... (hex)", "POSITIVE_INFINITY",
- "NEGATIVE_INFINITY", "NAN");
-
- String trimmed = Objects.requireNonNull(value).trim();
- switch(trimmed.toUpperCase(Locale.ENGLISH)) {
- case "POSITIVE_INFINITY":
- return Double.POSITIVE_INFINITY;
- case "NEGATIVE_INFINITY":
- return Double.NEGATIVE_INFINITY;
- case "NAN":
- return Double.NaN;
- default:
- Long lVal = longConverter.convert(trimmed, context);
- if (lVal != null) {
- return lVal;
- }
- try{
- return new BigDecimal(trimmed);
- }
- catch(Exception e){
- LOGGER.finest("Unparseable Number: " + trimmed);
- return null;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
deleted file mode 100644
index dd9ebdd..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/ShortConverter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to Short, the supported format is one of the following:
- * <ul>
- * <li>123 (byte value)</li>
- * <li>0xFF (byte value)</li>
- * <li>0XDF (byte value)</li>
- * <li>0D1 (byte value)</li>
- * <li>-123 (byte value)</li>
- * <li>-0xFF (byte value)</li>
- * <li>-0XDF (byte value)</li>
- * <li>-0D1 (byte value)</li>
- * <li>MIN_VALUE (ignoring case)</li>
- * <li>MIN (ignoring case)</li>
- * <li>MAX_VALUE (ignoring case)</li>
- * <li>MAX (ignoring case)</li>
- * </ul>
- */
-public class ShortConverter implements PropertyConverter<Short>{
-
- /** the logger. */
- private static final Logger LOG = Logger.getLogger(ShortConverter.class.getName());
-
- @Override
- public Short convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "short", "MIN", "MIN_VALUE", "MAX", "MAX_VALUE");
- String trimmed = Objects.requireNonNull(value).trim();
- switch(trimmed.toUpperCase(Locale.ENGLISH)){
- case "MIN_VALUE":
- case "MIN":
- return Short.MIN_VALUE;
- case "MAX_VALUE":
- case "MAX":
- return Short.MAX_VALUE;
- default:
- try{
- return Short.decode(trimmed);
- }
- catch(Exception e){
- LOG.finest("Unparseable Short: " + trimmed);
- return null;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
deleted file mode 100644
index 74b1337..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/URIConverter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.net.URI;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to URI, using new URI(value).
- */
-public class URIConverter implements PropertyConverter<URI> {
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public URI convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<uri> -> new URI(uri)");
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return new URI(trimmed);
- } catch (Exception e) {
- LOG.log(Level.FINE, "Unparseable URI: " + trimmed, e);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java b/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
deleted file mode 100644
index 4125c8a..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/converters/URLConverter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal.converters;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.net.URL;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to URI, using new URL(value).
- */
-public class URLConverter implements PropertyConverter<URL> {
-
- private Logger LOG = Logger.getLogger(getClass().getName());
-
- @Override
- public URL convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(),"<URL>");
- String trimmed = Objects.requireNonNull(value).trim();
- try {
- return new URL(trimmed);
- } catch (Exception e) {
- LOG.log(Level.FINE, "Unparseable URL: " + trimmed, e);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
deleted file mode 100644
index e9f53f9..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Abstract {@link org.apache.tamaya.spi.PropertySource} that allows to set a default ordinal that will be used, if no
- * ordinal is provided with the config.
- */
-public abstract class BasePropertySource implements PropertySource{
- /** default ordinal that will be used, if no ordinal is provided with the config. */
- private final int defaultOrdinal;
-
- /**
- * Constructor.
- * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config.
- */
- protected BasePropertySource(int defaultOrdinal){
- this.defaultOrdinal = defaultOrdinal;
- }
-
- /**
- * Constructor, using a default ordinal of 0.
- */
- protected BasePropertySource(){
- this(0);
- }
-
- @Override
- public String getName() {
- return getClass().getSimpleName();
- }
-
- @Override
- public int getOrdinal() {
- String configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try{
- return Integer.parseInt(configuredOrdinal);
- } catch(Exception e){
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal, e);
- }
- }
- return getDefaultOrdinal();
- }
-
- /**
- * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
- * @return the default ordinal used, by default 0.
- */
- public int getDefaultOrdinal(){
- return defaultOrdinal;
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public boolean isScannable(){
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
deleted file mode 100644
index a8a1b11..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.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 implements PropertySource {
-
- /**
- * default ordinal for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}
- */
- public static final int DEFAULT_ORDINAL = 300;
-
- @Override
- public int getOrdinal() {
- return DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- return "environment-properties";
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @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/eadbfe97/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
deleted file mode 100644
index 3ae4f2d..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/SimplePropertySource.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.ConfigException;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-
-/**
- * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for properties-files.
- */
-public class SimplePropertySource extends BasePropertySource {
- /**
- * The property source name.
- */
- private String name;
- /**
- * The current properties.
- */
- private Map<String, String> properties;
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(File propertiesLocation) {
- super(0);
- try {
- this.properties = load(propertiesLocation.toURI().toURL());
- this.name = propertiesLocation.toString();
- } catch (IOException e) {
- throw new ConfigException("Failed to load properties from " + propertiesLocation, e);
- }
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(URL propertiesLocation) {
- super(0);
- this.properties = load(propertiesLocation);
- this.name = propertiesLocation.toExternalForm();
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given properties map.
- *
- * @param name the name, not null.
- * @param properties the properties, not null.
- */
- public SimplePropertySource(String name, Map<String, String> properties) {
- super(0);
- this.properties = new HashMap<>(properties);
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param name The property source name
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(String name, URL propertiesLocation) {
- super(0);
- this.properties = load(propertiesLocation);
- this.name = Objects.requireNonNull(name);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.properties;
- }
-
- /**
- * 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
- */
- private Map<String, String> load(URL propertiesFile) {
- Map<String, String> properties = new HashMap<>();
- try (InputStream stream = propertiesFile.openStream()) {
- Properties props = new Properties();
- if (stream != null) {
- props.load(stream);
- }
- for (String key : props.stringPropertyNames()) {
- properties.put(key, props.getProperty(key));
- }
- } catch (IOException e) {
- throw new ConfigException("Error loading properties " + propertiesFile, e);
- }
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
deleted file mode 100644
index 9093f25..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
- */
-public class SystemPropertySource implements PropertySource {
-
- /**
- * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
- */
- public static final int DEFAULT_ORDINAL = 1000;
-
- private volatile Map<String,String> cachedProperties;
-
- /**
- * previous System.getProperties().hashCode()
- * so we can check if we need to reload
- */
- private int previousHash;
-
-
- public SystemPropertySource() {
- cachedProperties = loadProperties();
- previousHash = System.getProperties().hashCode();
- }
-
- private Map<String, String> loadProperties() {
- Map<String,String> props = new HashMap<>();
- Properties sysProps = System.getProperties();
- for(String name: sysProps.stringPropertyNames()) {
- props.put(name,sysProps.getProperty(name));
- }
- return props;
- }
-
- @Override
- public int getOrdinal() {
- return DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- return "system-properties";
- }
-
- @Override
- public String get(String key) {
- return getProperties().get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- // only need to reload and fill our map if something has changed
- // synchronization was removed, Instance was marked as volatile. In the worst case it
- // is reloaded twice, but the values will be the same.
- if (previousHash != System.getProperties().hashCode()) {
- Map<String, String> properties = loadProperties();
- this.cachedProperties = Collections.unmodifiableMap(properties);
- previousHash = System.getProperties().hashCode();
- }
- return this.cachedProperties;
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java b/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
deleted file mode 100644
index 9c04926..0000000
--- a/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.provider;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
-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.Enumeration;
-import java.util.List;
-
-/**
- * Provider which reads all {@code javaconfiguration.properties} files from classpath
- */
-public class JavaConfigurationProvider implements PropertySourceProvider {
- /** Default location in the classpath, where Tamaya looks for configuration by default. */
- public static final String DEFAULT_PROPERTIES_FILE_NAME="META-INF/javaconfiguration.properties";
-
- @Override
- public Collection<PropertySource> getPropertySources() {
- List<PropertySource> propertySources = new ArrayList<>();
- try {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if(cl!=null) {
- Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
- .getResources(DEFAULT_PROPERTIES_FILE_NAME);
- while (urls.hasMoreElements()) {
- propertySources.add(new SimplePropertySource(urls.nextElement()));
- }
- }
-
- } 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/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration b/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
deleted file mode 100644
index e51a247..0000000
--- a/core/src/main/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.core.internal.DefaultConfiguration
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
deleted file mode 100644
index 4efa42e..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
+++ /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.DefaultConfigurationContextBuilder
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
deleted file mode 100644
index 7c0e249..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
+++ /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.DefaultConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
deleted file mode 100644
index 93f7b11..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
+++ /dev/null
@@ -1,33 +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.converters.BooleanConverter
-org.apache.tamaya.core.internal.converters.ByteConverter
-org.apache.tamaya.core.internal.converters.CharConverter
-org.apache.tamaya.core.internal.converters.ClassConverter
-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
-org.apache.tamaya.core.internal.converters.URIConverter
-org.apache.tamaya.core.internal.converters.URLConverter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 1b8f8c0..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,20 +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.propertysource.EnvironmentPropertySource
-org.apache.tamaya.core.propertysource.SystemPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index 4535a09..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /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.provider.JavaConfigurationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
deleted file mode 100644
index f8e7e7f..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
+++ /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.DefaultServiceContext
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
deleted file mode 100644
index 98bb29c..0000000
--- a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-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 ConfigurationProvider.getConfiguration();
- }
-
- @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/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/A.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/A.java b/core/src/test/java/org/apache/tamaya/core/internal/A.java
deleted file mode 100644
index aa77a5d..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/A.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-/**
- * Test class for testing transitively evaluated property converters.
- */
-public class A implements AutoCloseable{
- @Override
- public void close() throws Exception {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/B.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/B.java b/core/src/test/java/org/apache/tamaya/core/internal/B.java
deleted file mode 100644
index 31bafb6..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/B.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-/**
- * Test class for testing transitively evaluated property converters.
- */
-public class B extends A implements Runnable{
- @Override
- public void run() {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/eadbfe97/core/src/test/java/org/apache/tamaya/core/internal/C.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/internal/C.java b/core/src/test/java/org/apache/tamaya/core/internal/C.java
deleted file mode 100644
index aad1ef9..0000000
--- a/core/src/test/java/org/apache/tamaya/core/internal/C.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import java.io.IOException;
-import java.nio.CharBuffer;
-
-/**
- * Test class for testing transitively evaluated property converters.
- */
-public class C extends B implements Readable{
-
- private String inValue;
-
- public C(String inValue){
- this.inValue = inValue;
- }
-
- @Override
- public int read(CharBuffer cb) throws IOException {
- return 0;
- }
-
- /**
- * Returns the input value, set on creation. Used for test assertion.
- * @return the in value.
- */
- public String getInValue() {
- return inValue;
- }
-
- @Override
- public String toString() {
- return "C{" +
- "inValue='" + inValue + '\'' +
- '}';
- }
-
-
-}