http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java index 10a5236..2010b1d 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java @@ -19,7 +19,10 @@ package org.apache.tamaya.core.internal.converters; import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.core.converters.URIConverter; +import org.apache.tamaya.base.convert.ConversionContext; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.net.URI; @@ -32,37 +35,47 @@ import static org.junit.Assert.assertNull; */ public class URIConverterTest { - ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(URI.class)) + ConversionContext context = new ConversionContext.Builder("<nokey>", URI.class) .build(); + @Before + public void before(){ + ConversionContext.setContext(context); + } + + @After + public void after(){ + ConversionContext.reset(); + } + @Test public void testConvert_URI() throws Exception { URIConverter converter = new URIConverter(); - assertEquals(new URI("test:path"), converter.convert("test:path", context)); + assertEquals(new URI("test:path"), converter.convert("test:path")); } @Test public void testConvert_URI_WithSpaces() throws Exception { URIConverter converter = new URIConverter(); - assertEquals(new URI("test:path"), converter.convert(" test:path\t", context)); + assertEquals(new URI("test:path"), converter.convert(" test:path\t")); } @Test public void testConvert_URI_WithSpacesBefore() throws Exception { URIConverter converter = new URIConverter(); - assertEquals(new URI("test:path"), converter.convert(" test:path", context)); + assertEquals(new URI("test:path"), converter.convert(" test:path")); } @Test public void testConvert_URI_WithSpacesAfter() throws Exception { URIConverter converter = new URIConverter(); - assertEquals(new URI("test:path"), converter.convert("test:path ", context)); + assertEquals(new URI("test:path"), converter.convert("test:path ")); } @Test public void testConvert_NotPresent() throws Exception { URIConverter converter = new URIConverter(); - assertNull(converter.convert("", context)); - assertNull(converter.convert(null, context)); + assertNull(converter.convert("")); + assertNull(converter.convert(null)); } }
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java index 3b66a98..b12c114 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java @@ -19,7 +19,8 @@ package org.apache.tamaya.core.internal.converters; import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.core.converters.URLConverter; +import org.apache.tamaya.base.convert.ConversionContext; import org.junit.Test; import java.net.URI; @@ -33,37 +34,37 @@ import static org.junit.Assert.assertNull; */ public class URLConverterTest { - ConversionContext context = new ConversionContext.Builder(TypeLiteral.of(URI.class)) + ConversionContext context = new ConversionContext.Builder("<nokey>", URI.class) .build(); @Test public void testConvert_URL() throws Exception { URLConverter converter = new URLConverter(); - assertEquals(new URL("http://google.com:4000/path"), converter.convert("http://google.com:4000/path", context)); + assertEquals(new URL("http://google.com:4000/path"), converter.convert("http://google.com:4000/path")); } @Test public void testConvert_URL_WithSpaces() throws Exception { URLConverter converter = new URLConverter(); - assertEquals(new URL("http://google.com:4000/path"), converter.convert(" http://google.com:4000/path\t", context)); + assertEquals(new URL("http://google.com:4000/path"), converter.convert(" http://google.com:4000/path\t")); } @Test public void testConvert_URL_WithSpacesBefore() throws Exception { URLConverter converter = new URLConverter(); - assertEquals(new URL("http://google.com:4000/path"), converter.convert(" http://google.com:4000/path", context)); + assertEquals(new URL("http://google.com:4000/path"), converter.convert(" http://google.com:4000/path")); } @Test public void testConvert_URL_WithSpacesAfter() throws Exception { URLConverter converter = new URLConverter(); - assertEquals(new URL("http://google.com:4000/path"), converter.convert("http://google.com:4000/path ", context)); + assertEquals(new URL("http://google.com:4000/path"), converter.convert("http://google.com:4000/path ")); } @Test public void testConvert_NotPresent() throws Exception { URLConverter converter = new URLConverter(); - assertNull(converter.convert("", context)); - assertNull(converter.convert(null, context)); + assertNull(converter.convert("")); + assertNull(converter.convert(null)); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 deleted file mode 100644 index c315ff6..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.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.testdata; - -import org.apache.tamaya.spisupport.propertysource.BasePropertySource; -import org.apache.tamaya.spi.PropertyValue; - -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,PropertyValue> properties = new HashMap<>(); - - public TestPropertyDefaultSource() { - super(100); - properties.put("name",PropertyValue.of("name", "Anatole", "test")); - properties.put("name2",PropertyValue.of("name2", "Sabine", "test")); - properties = Collections.unmodifiableMap(properties); - } - - @Override - public String getName() { - return "default-testdata-properties"; - } - - @Override - public Map<String, PropertyValue> getProperties() { - return properties; - } - - @Override - public boolean isScannable() { - return true; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 deleted file mode 100644 index 96f80a6..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.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.spi.FilterContext; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; - -import javax.annotation.Priority; - -/** - * Simple PropertyFilter that filters exact one value, registered using ServiceLoader. - */ -@Priority(100) -public class TestPropertyFilter implements PropertyFilter{ - @Override - public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { - if("name4".equals(context.getProperty().getKey())){ - return valueToBeFiltered.toBuilder() - .setValue(valueToBeFiltered.getValue() + "(filtered)") - .build(); - } - return valueToBeFiltered; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 index 5a427e0..d1ad8ba 100644 --- 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 @@ -18,13 +18,11 @@ */ package org.apache.tamaya.core.testdata; -import org.apache.tamaya.spisupport.propertysource.BasePropertySource; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertySourceProvider; -import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.base.configsource.BaseConfigSource; +import javax.config.spi.ConfigSource; +import javax.config.spi.ConfigSourceProvider; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -33,30 +31,30 @@ import java.util.Map; /** * Test provider reading properties from classpath:cfg/final/**.properties. */ -public class TestPropertySourceProvider implements PropertySourceProvider { +public class TestPropertySourceProvider implements ConfigSourceProvider { - private List<PropertySource> list = new ArrayList<>(); + private List<ConfigSource> list = new ArrayList<>(); public TestPropertySourceProvider(){ - list.add(new MyPropertySource()); + list.add(new MyConfigSource()); list = Collections.unmodifiableList(list); } @Override - public Collection<PropertySource> getPropertySources() { + public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) { return list; } - private static class MyPropertySource extends BasePropertySource { + private static class MyConfigSource extends BaseConfigSource { - private Map<String, PropertyValue> properties = new HashMap<>(); + private Map<String, String> properties = new HashMap<>(); - public MyPropertySource() { + public MyConfigSource() { super(200); - properties.put("name", PropertyValue.of("name", "Robin", "test")); - properties.put("name3", PropertyValue.of("name3", "Lukas", "test")); - properties.put("name4", PropertyValue.of("name4", "Sereina", "test")); - properties.put("name5", PropertyValue.of("name5", "Benjamin", "test")); + properties.put("name", "Robin"); + properties.put("name3", "Lukas"); + properties.put("name4", "Sereina"); + properties.put("name5", "Benjamin"); properties = Collections.unmodifiableMap(properties); } @@ -66,14 +64,10 @@ public class TestPropertySourceProvider implements PropertySourceProvider { } @Override - public Map<String, PropertyValue> getProperties() { + public Map<String, String> getProperties() { return properties; } - @Override - public boolean isScannable() { - return true; - } } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 deleted file mode 100644 index 488ea0b..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java +++ /dev/null @@ -1,45 +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.FilterContext; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; - -import javax.annotation.Priority; - -/** - * Simple PropertyFilter that filters exact one value, registered using ServiceLoader. - */ -@Priority(200) -public class TestRemovingPropertyFilter implements PropertyFilter{ - @Override - public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { - if("name5".equals(context.getProperty().getKey())){ - return null; - } - else if("name3".equals(context.getProperty().getKey())){ - return valueToBeFiltered.toBuilder().setValue( - "Mapped to name: " + ConfigurationProvider.getConfiguration().get("name")) - .build(); - } - return valueToBeFiltered; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 deleted file mode 100644 index 33beabb..0000000 --- a/code/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/9bc56a38/code/core/src/test/resources/META-INF/javaconfiguration.xml ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/javaconfiguration.xml b/code/core/src/test/resources/META-INF/javaconfiguration.xml deleted file mode 100644 index f6cdc97..0000000 --- a/code/core/src/test/resources/META-INF/javaconfiguration.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the 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. ---> - -<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> -<properties> - <entry key="aaeehh">ä</entry> - <entry key="ö">o</entry> -</properties> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi deleted file mode 100644 index 968be8f..0000000 --- a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi +++ /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.CoreConfigurationProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 deleted file mode 100644 index d039696..0000000 --- a/code/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/9bc56a38/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 deleted file mode 100644 index 18e61cb..0000000 --- a/code/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/9bc56a38/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 deleted file mode 100644 index 14e0c24..0000000 --- a/code/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.spisupport.propertysource.SystemPropertySource -org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource -org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/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 deleted file mode 100644 index c9f255a..0000000 --- a/code/core/src/test/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.testdata.TestPropertySourceProvider http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/bnd.bnd ---------------------------------------------------------------------- diff --git a/code/old/api/bnd.bnd b/code/old/api/bnd.bnd new file mode 100644 index 0000000..b606a72 --- /dev/null +++ b/code/old/api/bnd.bnd @@ -0,0 +1,24 @@ +-buildpath: \ + osgi.annotation; version=6.0.0,\ + osgi.core; version=6.0,\ + osgi.cmpn; version=6.0 + +-testpath: \ + ${junit} + +javac.source: 1.8 +javac.target: 1.8 + +Bundle-Version: ${version}.${tstamp} +Bundle-SymbolicName: org.apache.tamaya +Bundle-Name: Apache Tamaya - API +Bundle-Description: Apacha Tamaya Configuration Java API +Bundle-Category: API +Bundle-Copyright: (C) Apache Foundation +Bundle-License: Apache Licence version 2 +Bundle-Vendor: Apache Software Foundation +Bundle-ContactAddress: [email protected] +Bundle-DocURL: http://tamaya.apache.org +Export-Package: \ + org.apache.tamaya,\ + org.apache.tamaya.spi http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/pom.xml ---------------------------------------------------------------------- diff --git a/code/old/api/pom.xml b/code/old/api/pom.xml new file mode 100644 index 0000000..581e18d --- /dev/null +++ b/code/old/api/pom.xml @@ -0,0 +1,65 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy 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-code</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + </parent> + + <artifactId>tamaya-api</artifactId> + <name>Apache Tamaya Core API</name> + <packaging>jar</packaging> + + <description> + The API for accessing configuration data. + </description> + + + <url>http://tamaya.incubator.apache.org</url> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>java-hamcrest</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.annotation</artifactId> + <scope>provided</scope> + <optional>true</optional> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/ConfigException.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/ConfigException.java b/code/old/api/src/main/java/org/apache/tamaya/ConfigException.java new file mode 100644 index 0000000..38b0801 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/ConfigException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya; + +/** + * Exception class (runtime exception) for configuration issues. + */ +public class ConfigException extends RuntimeException{ + + private static final long serialVersionUID = -5886094818057522680L; + + /** + * Creates a new configuration exception. + * @param message the exception message, not {@code null}. + */ + public ConfigException(String message){ + super(message); + } + + /** + * Creates a new configuration exception. + * @param message the exception message, not {@code null}. + * @param t the throwable. + */ + public ConfigException(String message, Throwable t){ + super(message, t); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/ConfigOperator.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/ConfigOperator.java b/code/old/api/src/main/java/org/apache/tamaya/ConfigOperator.java new file mode 100644 index 0000000..b14c155 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/ConfigOperator.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya; + +/** + * Models a function that maps a given {@link org.apache.tamaya.Configuration} to another {@link org.apache.tamaya.Configuration}. This can be used + * to modell additional functionality and applying it to a given {@link org.apache.tamaya.Configuration} instance by calling + * the {@link org.apache.tamaya.Configuration#with(org.apache.tamaya.ConfigOperator)} method. + */ +@FunctionalInterface +public interface ConfigOperator { + + /** + * Creates a new {@link org.apache.tamaya.Configuration} based on the given Configuration. Operators basically acts similar to + * decorators, whereas operated instances may have non compatible behaviour, e.g. by applying security constraints + * or view restrictions. + * + * @param config the input configuration, not {@code null}. + * @return the operated configuration, never {@code null}. + */ + Configuration operate(Configuration config); +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/ConfigQuery.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/ConfigQuery.java b/code/old/api/src/main/java/org/apache/tamaya/ConfigQuery.java new file mode 100644 index 0000000..28b8b93 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/ConfigQuery.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; + +/** + * Models a function that maps a given {@link Configuration} to something else. This can be used + * to model additional functionality and applying it to a given {@link Configuration} instance by + * calling the {@link Configuration#query(ConfigQuery)} method. + */ +@FunctionalInterface +public interface ConfigQuery<T> { + + /** + * Creates a result based on the given Configuration. Queries basically acts similar to + * operators, whereas they returns any kind of result. + * + * @param config the input configuration, not {@code null}. + * @return the query result. + */ + T query(Configuration config); +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/Configuration.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/Configuration.java b/code/old/api/src/main/java/org/apache/tamaya/Configuration.java new file mode 100644 index 0000000..b891d43 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/Configuration.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; + +import org.apache.tamaya.spi.ConfigurationBuilder; +import org.apache.tamaya.spi.ConfigurationContext; + +import java.util.Map; + + +/** + * <p>A configuration models a aggregated set current properties, identified by + * a unique key, but adds higher level access functions to + * a {@link org.apache.tamaya.spi.PropertySource}. Hereby in most + * cases a configuration is a wrapper around a composite + * {@link org.apache.tamaya.spi.PropertySource} instance, which may combine + * multiple child config in well defined tree like structure, + * where nodes define logically the rules current priority, filtering, + * combination and overriding. + * </p> + * <h3>Implementation Requirements</h3> + * Implementations current this interface must be + * <ul> + * <li>Thread safe</li> + * <li>Immutable</li> + * </ul> + * + * <p>It is not recommended that implementations also are serializable, since the any configuration can be <i>frozen</i> + * by reading out its complete configuration map into a serializable and remotable structure. This helps significantly + * simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current + * this library at all.</p> + */ +public interface Configuration { + + /** + * Access a property. + * + * @param key the property's key, not {@code null}. + * @return the property's value. + */ + default String get(String key){ + return get(key, TypeLiteral.of(String.class)); + } + + /** + * Access a property. + * + * @param key the property's key, not {@code null}. + * @param defaultValue value to be returned, if no value is present, not {@code null} + * @return the property's keys. + */ + default String getOrDefault(String key, String defaultValue){ + return getOrDefault(key, TypeLiteral.of(String.class), defaultValue); + } + + /** + * Get the property keys as type T. This will implicitly require a corresponding {@link + * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T + * fromMap the given String keys. + * + * @param <T> the type of the class modeled by the type parameter + * @param key the property's absolute, or relative path, e.g. @code + * a/b/c/d.myProperty}, not {@code null}. + * @param type The target type required, not {@code null}. + * @param defaultValue value to be used, if no value is present, not {@code null} + * @return the property value, never {@code null}. + * @throws ConfigException if the keys could not be converted to the required target type. + */ + default <T> T getOrDefault(String key, Class<T> type, T defaultValue){ + return getOrDefault(key, TypeLiteral.of(type), defaultValue); + } + + /** + * Get the property keys as type T. This will implicitly require a corresponding {@link + * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T + * fromMap the given String keys. + * + * @param <T> the type of the class modeled by the type parameter + * @param key the property's absolute, or relative path, e.g. @code + * a/b/c/d.myProperty}. + * @param type The target type required, not {@code null}. + * @return the property value, never {@code null}. + * @throws ConfigException if the keys could not be converted to the required target type. + */ + default <T> T get(String key, Class<T> type){ + return get(key, TypeLiteral.of(type)); + } + + /** + * Get the property keys as type T. This will implicitly require a corresponding {@link + * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T + * fromMap the given String keys. + * + * @param <T> the type of the type literal + * @param key the property's absolute, or relative path, e.g. @code + * a/b/c/d.myProperty}, not {@code null}. + * @param type The target type required, not {@code null}. + * @return the property value, never {@code null}. + * @throws ConfigException if the keys could not be converted to the required target type. + */ + <T> T get(String key, TypeLiteral<T> type); + + /** + * Get the property keys as type T. This will implicitly require a corresponding {@link + * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T + * fromMap the given String keys. + * + * @param <T> the type of the type literal + * @param key the property's absolute, or relative path, e.g. + * {@code a/b/c/d.myProperty}, not {@code null}. + * @param type The target type required, not {@code null}. + * @param defaultValue default value to be used, if no value is present. + * @return the property value, never null. + * @throws ConfigException if the keys could not be converted to the required target type. + */ + <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue); + + /** + * Access all currently known configuration properties as a full {@code Map<String,String>}. + * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource} + * instances may not be contained in the result, but nevertheless be accessible calling one of the + * {@code get(...)} methods. + * @return all currently known configuration properties. + */ + Map<String,String> getProperties(); + + /** + * Extension point for adjusting configuration. + * + * @param operator A configuration operator, e.g. a filter, or an adjuster + * combining configurations, never {@code null}. + * @return the new adjusted configuration returned by the {@code operator}, never {@code null}. + */ + default Configuration with(ConfigOperator operator){ + return operator.operate(this); + } + + /** + * Query a configuration. + * + * @param <T> the type of the configuration. + * @param query the query, not {@code null}. + * @return the result returned by the {@code query}. + */ + default <T> T query(ConfigQuery<T> query){ + return query.query(this); + } + + /** + * Access a configuration's context. + * @return the configuration context, never null. + */ + ConfigurationContext getContext(); + + /** + * Create a new builder using this instance as it's base. + * @return a new builder, never null. + */ + default ConfigurationBuilder toBuilder() { + return ConfigurationProvider.getConfigurationBuilder().setConfiguration(this); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/code/old/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java new file mode 100644 index 0000000..bacb944 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya; + +import org.apache.tamaya.spi.*; + +import java.util.logging.Logger; + +/** + * Static access to the {@link Configuration} for the very application. + */ +public final class ConfigurationProvider { + + private static final Logger LOG = Logger.getLogger(ConfigurationProvider.class.getName()); + + private static ConfigurationProviderSpi spi() { + ConfigurationProviderSpi spi = ServiceContextManager.getServiceContext() + .getService(ConfigurationProviderSpi.class); + if(spi==null){ + throw new IllegalStateException("ConfigurationProviderSpi not available."); + } + return spi; + } + + private ConfigurationProvider() { + // just to prevent initialisation + } + + /** + * Access the current configuration. + * + * @return the corresponding Configuration instance, never {@code null}. + */ + public static Configuration getConfiguration() { + return spi().getConfiguration(); + } + + /** + * Creates a new configuration instance based on the given context. + * + * @param context the configuration context, not {@code null}. + * @return a new Configuration instance, never {@code null}. + */ + public static Configuration createConfiguration(ConfigurationContext context) { + return spi().createConfiguration(context); + } + + /** + * Get access to the current ConfigurationContext. + * + * @return the current ConfigurationContext, never null. + * @deprecated Use {@link Configuration#getContext()} instead of. + */ + @Deprecated + public static ConfigurationContext getConfigurationContext() { + return spi().getConfigurationContext(); + } + + /** + * This method allows to replace the current {@link org.apache.tamaya.spi.ConfigurationContext} with a new + * instance. This can be used to update the context with a new one, e.g. because some of the configuration + * data has changed and should be updated. It is the responsibility of the ConfigurationProvider to trigger + * corresponding update events for the current {@link org.apache.tamaya.Configuration}, so observing + * listeners can do whatever is appropriate to react to any given configuration changes. + * + * @param context the new ConfigurationContext to be applied. + * @throws java.lang.UnsupportedOperationException if the current provider is read-only and does not support + * applying a new ConfigurationContext. + * @deprecated Use #setConfiguration(Configuration) instead of. + */ + @Deprecated + public static void setConfigurationContext(ConfigurationContext context) { + spi().setConfigurationContext(context); + } + + /** + * This method allows to replace the current default {@link org.apache.tamaya.Configuration} with a new + * instance. It is the responsibility of the ConfigurationProvider to trigger + * corresponding update events for the current {@link org.apache.tamaya.Configuration}, so observing + * listeners can do whatever is appropriate to react to any given configuration change. + * + * @param config the new Configuration to be applied, not {@code null} + * @throws java.lang.UnsupportedOperationException if the current provider is read-only and + * does not support + * applying a new Configuration. + */ + public static void setConfiguration(Configuration config) { + LOG.info("TAMAYA Applying new Configuration: " + config); + spi().setConfiguration(config); + } + + /** + * Create a new {@link ConfigurationBuilder} instance. This method creates + * a new builder instance that is not related to any concrete {@link org.apache.tamaya.spi.ConfigurationContext}. + * You can use {@link #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)} to change the + * current configuration context. + * + * @return a new, empty {@link ConfigurationBuilder}, never null. + * @see #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext) + * @see org.apache.tamaya.spi.ConfigurationContext + * @deprecated Will be removed. + */ + @Deprecated + public static ConfigurationContextBuilder getConfigurationContextBuilder() { + return spi().getConfigurationContextBuilder(); + } + + /** + * Create a new {@link ConfigurationBuilder} instance. This method creates + * a new builder instance that is not related to any concrete {@link org.apache.tamaya.spi.ConfigurationContext}. + * You can use {@link #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)} to change the + * current configuration context. + * + * @return a new, empty {@link ConfigurationBuilder}, never null. + * @see #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext) + * @see org.apache.tamaya.spi.ConfigurationContext + */ + public static ConfigurationBuilder getConfigurationBuilder() { + return spi().getConfigurationBuilder(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/TypeLiteral.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/TypeLiteral.java b/code/old/api/src/main/java/org/apache/tamaya/TypeLiteral.java new file mode 100644 index 0000000..f530a29 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/TypeLiteral.java @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya; + +import java.io.Serializable; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Objects; + + +/** + * <p>Class for instantiation of objects that represent parameterized types + * with current parameters.</p> + * + * <p>An object that represents a parameterized type may be obtained by + * subclassing <tt>TypeLiteral</tt>.</p> + * + * <pre> + * TypeLiteral<List<Integer>> stringListType = new TypeLiteral<List<Integer>>() {}; + * </pre> + * + * @param <T> the type, including all type parameters + */ +public class TypeLiteral<T> implements Serializable { + + private static final long serialVersionUID = 1L; + private static final Type[] EMPTY_TYPE_ARRAY = new Type[0]; + /** The current defined type. */ + private final Type definedType; + + /** + * Constructor. + * @param definedType the defined type. + */ + public TypeLiteral(Type definedType) { + Objects.requireNonNull(definedType, "Type must be given"); + + this.definedType = definedType; + } + + /** + * Constructor only for directly implemeting a TypeLiteral hereby dynamically implementing a generic interface. + */ + public TypeLiteral() { + this.definedType = getDefinedType(this.getClass()); + } + + /** + * Creates a new TypeLiteral based on a given type. + * + * @param type the type , not {@code null}. + * @param <R> the literal generic type. + * @return the corresponding TypeLiteral, never {@code null}. + */ + public static <R> TypeLiteral<R> of(Type type) { + Objects.requireNonNull(type, "Type must be given."); + + return new TypeLiteral<>(type); + } + + /** + * Checks the current implemented generic interfaces and evaluates the given single type parameter. + * + * @param clazz the class to check, not {@code null}. + * @param interfaceType the interface type to be checked, not {@code null}. + * @return the generic type parameters, or an empty array, if it cannot be evaluated. + */ + public static Type[] getGenericInterfaceTypeParameters(Class<?> clazz, Class<?> interfaceType) { + Objects.requireNonNull(clazz, "Class parameter must be given."); + Objects.requireNonNull(interfaceType, "Interface parameter must be given."); + + for (Type type : clazz.getGenericInterfaces()) { + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) type; + if(parameterizedType.getRawType().equals(interfaceType)){ + return parameterizedType.getActualTypeArguments(); + } + } + } + return EMPTY_TYPE_ARRAY; + } + + /** + * Method that checks the class's type for a generic interface implementation type. + * + * @param type the type, not {@code null}. + * @return the generic type parameter of the given single type generic interfaceType, or an empty array. + */ + public static Type[] getTypeParameters(Type type) { + Objects.requireNonNull(type, "Type must be given."); + + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) type; + return parameterizedType.getActualTypeArguments(); + } + return EMPTY_TYPE_ARRAY; + } + + public final Type getType() { + return definedType; + } + + /** + * Returns basic raw Java type. + * + * @return the actual type represented by this object + */ + @SuppressWarnings("unchecked") + public final Class<T> getRawType() { + Class<T> rawType; + + if (this.definedType instanceof ParameterizedType) { + ParameterizedType pt = (ParameterizedType) this.definedType; + rawType = (Class<T>) pt.getRawType(); + } else if (this.definedType instanceof GenericArrayType) { + rawType = (Class<T>) Object[].class; + } else if (this.definedType instanceof Class) { + rawType = (Class<T>) this.definedType; + } else { + throw new RuntimeException("Illegal type for the Type Literal Class"); + } + + return rawType; + } + + + protected Type getDefinedType(Class<?> clazz) { + Type type; + + if (clazz == null) { + throw new RuntimeException("Class parameter clazz can not be null"); + } + + Type superClazz = clazz.getGenericSuperclass(); + + if (superClazz instanceof ParameterizedType) { + ParameterizedType pt = (ParameterizedType) superClazz; + Type[] actualArgs = pt.getActualTypeArguments(); + + if (actualArgs.length == 1) { + type = actualArgs[0]; + + } else { + throw new RuntimeException("More than one parametric type"); + } + + } else if (superClazz.equals(Object.class)) { + throw new RuntimeException("Super class must be parametrized type"); + } else { + type = getDefinedType((Class<?>) superClazz); + } + + return type; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((definedType == null) ? 0 : definedType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + TypeLiteral<?> other = (TypeLiteral<?>) obj; + if (definedType == null) { + if (other.definedType != null) { + return false; + } + } else if (!definedType.equals(other.definedType)) { + return false; + } + return true; + } + + + @Override + public String toString() { + return "TypeLiteral{" + + "type=" + definedType + + '}'; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/package-info.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/package-info.java b/code/old/api/src/main/java/org/apache/tamaya/package-info.java new file mode 100644 index 0000000..60692a4 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the 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. + */ + +/** + * This package contains the Apache Tamaya API. + */ [email protected]("0.4") +package org.apache.tamaya; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java b/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java new file mode 100644 index 0000000..a2b3257 --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java @@ -0,0 +1,348 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spi; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.TypeLiteral; + +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +/** + * A builder for creating new instance of {@link Configuration}. + * Builders can be obtained in exactly two ways: + * <ol> + * <li>By accessing a preinitialized builder from an existing {@link Configuration}, + * by calling {@link org.apache.tamaya.spi.Configuration#toBuilder()}.</li> + * <li>By accessing an empty builder instance from + * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationBuilder()}.</li> + * </ol> + * After all changes are applied to a builder a new {@link Configuration} instance can + * be created and can be applied by calling + * {@link #build()}}. + * + */ +public interface ConfigurationBuilder { + + /** + * Init this builder instance with the given {@link Configuration} instance. This + * method will use any existing property sources, filters, converters and the combination + * policy of the given {@link Configuration} and initialize the current builder + * with them. All previous property sources, filters, converters and the combination + * policy of this instance will be replaced. + * + * @param config the {@link Configuration} instance to be used, not {@code null}. + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder setConfiguration(Configuration config); + + /** + * Init this builder instance with the given {@link ConfigurationContext} instance. This + * method will use any existing property sources, filters, converters and the combination + * policy of the given {@link ConfigurationContext} and initialize the current builder + * with them. All previous property sources, filters, converters and the combination + * policy of this instance will be replaced. + * + * @param context the {@link ConfigurationContext} instance to be used, not {@code null}. + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder setContext(ConfigurationContext context); + + /** + * This method can be used for adding {@link PropertySource}s. + * Hereby the property source is added to the tail of property sources with + * lowest priority regardless of its current ordinal value. To sort the property + * sources based on their ordinals call {@link #sortPropertySources}. + * + * @param propertySources the PropertySources to add + * @return this builder, for chaining, never null. + * @throws IllegalArgumentException If a property source with a given name already + * exists. + */ + ConfigurationBuilder addPropertySources(PropertySource... propertySources); + + /** + * This method can be used for programmatically adding {@link PropertySource}s. + * Hereby the property source is added to the tail of property sources with + * lowest priority regardless of its current ordinal value. To sort the property + * sources based on their ordinals call {@link #sortPropertySources}. + * + * @param propertySources the PropertySources to add + * @return this builder, for chaining, never null. + * @throws IllegalArgumentException If a property source with a given name already + * exists. + */ + ConfigurationBuilder addPropertySources(Collection<PropertySource> propertySources); + + /** + * Add all registered (default) property sources to the context built. The sources are ordered + * based on their ordinal values and added to the chain of property sources with + * higher priority. + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder addDefaultPropertySources(); + + /** + * Removes the given property sources, if existing. The existing order of property + * sources is preserved. + * + * @param propertySources the property sources to remove, not {@code null}. + * @return the builder for chaining. + */ + ConfigurationBuilder removePropertySources(PropertySource... propertySources); + + /** + * Removes the given property sources, if existing. The existing order of property + * sources is preserved. + * + * @param propertySources the property sources to remove, not {@code null}. + * @return the builder for chaining. + */ + ConfigurationBuilder removePropertySources(Collection<PropertySource> propertySources); + + /** + * Access the current chain of property sources. Items at the end of the list have + * precedence/more significance. + * + * @return the property source chain, never {@code null}. + */ + List<PropertySource> getPropertySources(); + + /** + * Access the current chain of property filters. Items at the end of the list have + * precedence/more significance. + * + * @return the property filter chain, never {@code null}. + */ + List<PropertyFilter> getPropertyFilters(); + + /** + * Access the current registered property converters. + * + * @return the current registered property converters. + */ + Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter(); + + /** + * Increases the priority of the given property source, by moving it towards the end + * of the chain of property sources. If the property source given is already at the end + * this method has no effect. This operation does not change any ordinal values. + * + * @param propertySource the property source to be incresed regarding its significance. + * @return the builder for chaining. + * @throws IllegalArgumentException If no such property source exists in the current + * chain. + */ + ConfigurationBuilder increasePriority(PropertySource propertySource); + + /** + * Decreases the priority of the given property source, by moving it towards the start + * of the chain of property sources. If the property source given is already the first + * this method has no effect. This operation does not change any ordinal values. + * + * @param propertySource the property source to be decresed regarding its significance. + * @return the builder for chaining. + * @throws IllegalArgumentException If no such property source exists in the current + * chain. + */ + ConfigurationBuilder decreasePriority(PropertySource propertySource); + + /** + * Increases the priority of the given property source to be maximal, by moving it to + * the tail of the of property source chain. If the property source given is + * already the last item this method has no effect. This operation does not change + * any ordinal values. + * + * @param propertySource the property source to be maximized regarding its significance. + * @return the builder for chaining. + * @throws IllegalArgumentException If no such property source exists in the current + * chain. + */ + ConfigurationBuilder highestPriority(PropertySource propertySource); + + /** + * Decreases the priority of the given property source to be minimal, by moving it to + * the start of the chain of property source chain. If the property source given is + * already the first item this method has no effect. This operation does not change + * any ordinal values. + * + * @param propertySource the property source to be minimized regarding its significance. + * @return the builder for chaining. + * @throws IllegalArgumentException If no such property source exists in the current + * chain. + */ + ConfigurationBuilder lowestPriority(PropertySource propertySource); + + /** + * Adds the given PropertyFilter instances, hereby the instances are added + * to the end of the list with highest priority. The ordering of existing + * property filters remains unchanged. To sort the property + * filters call {@link #sortPropertyFilter}. + * + * @param filters the filters to add + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder addPropertyFilters(PropertyFilter... filters); + + /** + * Adds the given PropertyFilter instances, hereby the instances are added + * to the end of the list with highest priority. The ordering of existing + * property filters remains unchanged. To sort the property + * filters call {@link #sortPropertyFilter}. + * + * @param filters the filters to add + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters); + + /** + * Add all auto-discoverable property filters to the context built. + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder addDefaultPropertyFilters(); + + + /** + * Removes the given PropertyFilter instances, if existing. The order of the remaining + * filters is preserved. + * + * @param filters the filter to remove + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder removePropertyFilters(PropertyFilter... filters); + + /** + * Removes the given PropertyFilter instances, if existing. The order of the remaining + * filters is preserved. + * + * @param filters the filter to remove + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder removePropertyFilters(Collection<PropertyFilter> filters); + + /** + * This method can be used for adding {@link PropertyConverter}s. + * Converters are added at the end after any existing converters. + * For converters already registered for the current target type the + * method has no effect. + * + * @param typeToConvert the type for which the converter is for + * @param propertyConverters the PropertyConverters to add for this type + * @param <T> the target type. + * @return this builder, for chaining, never null. + */ + <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert, + @SuppressWarnings("unchecked") PropertyConverter<T>... propertyConverters); + + /** + * This method can be used for adding {@link PropertyConverter}s. + * Converters are added at the end after any existing converters. + * For converters already registered for the current target type the + * method has no effect. + * + * @param typeToConvert the type for which the converter is for + * @param propertyConverters the PropertyConverters to add for this type + * @param <T> the target type. + * @return this builder, for chaining, never null. + */ + <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert, + Collection<PropertyConverter<T>> propertyConverters); + + /** + * Add all auto-discoverable property converters to the context built. + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder addDefaultPropertyConverters(); + + /** + * Removes the given PropertyConverter instances for the given type, + * if existing. + * + * @param typeToConvert the type which the converter is for + * @param propertyConverters the converter to remove + * @param <T> the target type. + * @return this builder, for chaining, never null. + */ + <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert, + @SuppressWarnings("unchecked") PropertyConverter<T>... propertyConverters); + + /** + * Removes the given PropertyConverter instances for the given type, + * if existing. + * + * @param typeToConvert the type which the converter is for + * @param propertyConverters the converter to remove + * @param <T> the target type. + * @return this builder, for chaining, never null. + */ + <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert, + Collection<PropertyConverter<T>> propertyConverters); + + /** + * Removes all converters for the given type, which actually renders a given type + * unsupported for type conversion. + * + * @param typeToConvert the type which the converter is for + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder removePropertyConverters(TypeLiteral<?> typeToConvert); + + /** + * Sorts the current registered property sources using the given comparator. + * + * NOTE: property sources at the beginning have minimal significance. + * + * @param comparator the comparator to be used, not {@code null}. + * @return this instance for chaining. + */ + ConfigurationBuilder sortPropertySources(Comparator<PropertySource> comparator); + + /** + * Sorts the current registered property filters using the given comparator. + * + * NOTE: property filters at the beginning have minimal significance. + * + * @param comparator the comparator to be used, not {@code null}. + * @return this instance for chaining. + */ + ConfigurationBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator); + + /** + * Sets the {@link PropertyValueCombinationPolicy} used to evaluate the final + * property values. + * + * @param policy the {@link PropertyValueCombinationPolicy} used, not {@code null}. + * @return this builder, for chaining, never null. + */ + ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy); + + /** + * Builds a new {@link Configuration} based on the data in this builder. The ordering of property + * sources and property filters is not changed, regardless of their ordinals. For ensure a certain + * ordering/significance use {@link #sortPropertyFilter(Comparator)} and/or {@link #sortPropertySources(Comparator)} + * before building the context. + * + * @return the final configuration, never null. + */ + Configuration build(); + +} + http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java new file mode 100644 index 0000000..f077a1d --- /dev/null +++ b/code/old/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spi; + + +import org.apache.tamaya.TypeLiteral; + +import java.util.List; +import java.util.Map; + +/** + * Central SPI for programmatically dealing with the setup of the configuration system. + * This includes adding and enlisting {@link org.apache.tamaya.spi.PropertySource}s, + * managing {@link PropertyConverter}s, ConfigFilters, etc. + */ +public interface ConfigurationContext { + + /** + * This method can be used for programmatically adding {@link PropertySource}s. + * It is not needed for normal 'usage' by end users, but only for Extension Developers! + * + * @param propertySources the PropertySources to add + * @deprecated Use {@link ConfigurationContextBuilder} to create a new {@link ConfigurationContext}. + * @see #toBuilder() + */ + @Deprecated + void addPropertySources(PropertySource... propertySources); + + /** + * This method returns the current list of registered PropertySources ordered via their ordinal. + * PropertySources with a lower ordinal come last. The PropertySource with the + * highest ordinal comes first. + * If two PropertySources have the same ordinal number they will get sorted + * using their class name just to ensure the user at least gets the same ordering + * after a JVM restart, hereby names before are added last. + * PropertySources are loaded when this method is called the first time, which basically is + * when the first time configuration is accessed. + * + * @return a sorted list of registered PropertySources. The returned list need not be modifiable + */ + List<PropertySource> getPropertySources(); + + /** + * Access a {@link PropertySource} using its (unique) name. + * @param name the propoerty source's name, not {@code null}. + * @return the propoerty source found, or {@code null}. + */ + PropertySource getPropertySource(String name); + + /** + * This method can be used for programmatically adding {@link PropertyConverter}s. + * It is not needed for normal 'usage' by end users, but only for Extension Developers! + * + * @param <T> the type of the type literal + * @param type the type which the converters is for + * @param propertyConverter the PropertyConverters to add for this type + * @deprecated Use {@link ConfigurationContextBuilder} to create a new {@link ConfigurationContext}. + * @see #toBuilder() + */ + @Deprecated + <T> void addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter); + + + /** + * <p> + * This method returns the Map of registered PropertyConverters + * per type. + * The List for each type is ordered via their {@link javax.annotation.Priority} and + * cladd name. + * </p> + * + * <p>A simplified scenario could be like:</p> + * <pre> + * { + * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter } + * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter} + * Integer.class -> {DynamicDefaultConverter} + * } + * </pre> + * + * @return map with sorted list of registered PropertySources per type. + */ + Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters(); + + /** + * <p> + * This method returns the registered PropertyConverters for a given type. + * The List for each type is ordered via their {@link javax.annotation.Priority}. + * </p> + * + * <p> + * PropertyConverters with a higher Priority come first. The PropertyConverter with the + * lowest Priority comes last. + * If two PropertyConverter have the same ordinal number they will get sorted + * using their class name just to ensure the user at least gets the same ordering + * after a JVM restart. + * </p> + * + * <p> + * Additionally if a PropertyProvider is accessed, which is not registered the implementation + * should try to figure out, if there could be a default implementation as follows:</p> + * <ol> + * <li>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String), + * instanceOf(String), fomr(String)}</li> + * <li>Look for a matching constructor: {@code T(String)}.</li> + * </ol> + * + * <p> + * If a correspoding factory method or constructor could be found, a corresponding + * PropertyConverter should be created and registered automatically for the given + * type. + * </p> + * + * <p> The scenario could be like:</p> + * + * <pre> + * { + * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter} + * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter} + * Integer.class -> {DynamicDefaultConverter} + * } + * </pre> + * + * <p> + * The converters returned for a type should be used as a chain, whereas the result of the + * first converters that is able to convert the configured value, is taken as the chain's result. + * No more converters are called after a converters has successfully converted the input into + * the required target type. + * </p> + * + * @param <T> the type of the type literal + * @param type type of the desired converters + * @return a sorted list of registered PropertySources per type. + */ + <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type); + + /** + * Access the current PropertyFilter instances. + * @return the list of registered PropertyFilters, never null. + */ + List<PropertyFilter> getPropertyFilters(); + + /** + * Access the {@link org.apache.tamaya.spi.PropertyValueCombinationPolicy} used to evaluate the final + * property values. + * @return the {@link org.apache.tamaya.spi.PropertyValueCombinationPolicy} used, never null. + */ + PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(); + + /** + * Creates a {@link ConfigurationContextBuilder} preinitialized with the data from this instance. + * @return a new builder instance, never null. + * @deprecated Will be removed. + */ + @Deprecated + ConfigurationContextBuilder toBuilder(); + +}
