http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/NotFoundNoDefault.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/NotFoundNoDefault.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/NotFoundNoDefault.java index 6e4e50e..46f6c2a 100644 --- a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/NotFoundNoDefault.java +++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/NotFoundNoDefault.java @@ -16,8 +16,7 @@ */ package org.apache.tamaya.cdi; -import org.apache.tamaya.inject.api.Config; - +import javax.config.inject.ConfigProperty; import javax.enterprise.inject.Alternative; import javax.inject.Inject; import java.io.File; @@ -28,23 +27,23 @@ import java.time.Duration; public class NotFoundNoDefault { @Inject - @Config("string.bla") + @ConfigProperty(name="string.bla") private String string; @Inject - @Config("file.bla") + @ConfigProperty(name="file.bla") private File file; @Inject - @Config("duration.bla") + @ConfigProperty(name="duration.bla") private Duration duration; @Inject - @Config("boolean.bla") + @ConfigProperty(name="boolean.bla") private Boolean aBoolean; @Inject - @Config("integer.bla") + @ConfigProperty(name="integer.bla") private Integer integer; public String getString() {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedConfigSource.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedConfigSource.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedConfigSource.java new file mode 100644 index 0000000..b9333d1 --- /dev/null +++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedConfigSource.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 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. + * + */ +package org.apache.tamaya.cdi.cfg; + +import javax.config.spi.ConfigSource; +import javax.enterprise.inject.Vetoed; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Anatole on 17.09.2015. + */ +@Vetoed +class ProvidedConfigSource implements ConfigSource{ + + final Map<String,String> config = new HashMap<>(); + + public ProvidedConfigSource(){ + config.put("a.b.c.key3", "keys current a.b.c.key3"); + config.put("a.b.c.key4", "keys current a.b.c.key4"); + } + + @Override + public int getOrdinal() { + return 10; + } + + @Override + public String getName() { + return getClass().getName(); + } + + @Override + public String getValue(String key) { + return config.get(key); + } + + @Override + public Map<String, String> getProperties() { + return config; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedPropertySource.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedPropertySource.java deleted file mode 100644 index 8ed0588..0000000 --- a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/ProvidedPropertySource.java +++ /dev/null @@ -1,66 +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. - * - */ -package org.apache.tamaya.cdi.cfg; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import javax.enterprise.inject.Vetoed; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by Anatole on 17.09.2015. - */ -@Vetoed -class ProvidedPropertySource implements PropertySource{ - - final Map<String,PropertyValue> config = new HashMap<>(); - - public ProvidedPropertySource(){ - config.put("a.b.c.key3", PropertyValue.of("a.b.c.key3","keys current a.b.c.key3",getName())); - config.put("a.b.c.key4", PropertyValue.of("a.b.c.key4","keys current a.b.c.key4", getName())); - } - - @Override - public int getOrdinal() { - return 10; - } - - @Override - public String getName() { - return getClass().getName(); - } - - @Override - public PropertyValue get(String key) { - return config.get(key); - } - - @Override - public Map<String, PropertyValue> getProperties() { - return config; - } - - @Override - public boolean isScannable() { - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestConfigProvider.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestConfigProvider.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestConfigProvider.java index 036b9da..31bf136 100644 --- a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestConfigProvider.java +++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestConfigProvider.java @@ -18,9 +18,8 @@ */ package org.apache.tamaya.cdi.cfg; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertySourceProvider; - +import javax.config.spi.ConfigSource; +import javax.config.spi.ConfigSourceProvider; import javax.enterprise.context.ApplicationScoped; import java.util.ArrayList; import java.util.Collection; @@ -30,16 +29,16 @@ import java.util.List; * Created by Anatole on 29.09.2014. */ @ApplicationScoped -public class TestConfigProvider implements PropertySourceProvider { +public class TestConfigProvider implements ConfigSourceProvider { - private List<PropertySource> configs = new ArrayList<>(); + private List<ConfigSource> configs = new ArrayList<>(); public TestConfigProvider(){ - configs.add(new ProvidedPropertySource()); + configs.add(new ProvidedConfigSource()); } @Override - public Collection<PropertySource> getPropertySources() { + public Collection<ConfigSource> getConfigSources(ClassLoader cl) { return configs; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestPropertySource.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestPropertySource.java index e31070a..0ecfd9b 100644 --- a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestPropertySource.java +++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/cfg/TestPropertySource.java @@ -19,9 +19,7 @@ */ package org.apache.tamaya.cdi.cfg; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - +import javax.config.spi.ConfigSource; import javax.inject.Singleton; import java.util.HashMap; import java.util.Map; @@ -30,7 +28,7 @@ import java.util.Map; * Created by Anatole on 17.09.2015. */ @Singleton -public class TestPropertySource implements PropertySource{ +public class TestPropertySource implements ConfigSource{ final Map<String,String> config = new HashMap<>(); @@ -62,21 +60,13 @@ public class TestPropertySource implements PropertySource{ } @Override - public PropertyValue get(String key) { - String val = this.config.get(key); - if(val!=null) { - return PropertyValue.of(key, val, getName()); - } - return null; + public String getValue(String key) { + return this.config.get(key); } @Override - public Map<String, PropertyValue> getProperties() { - return PropertyValue.map(config ,getName()); + public Map<String, String> getProperties() { + return config; } - @Override - public boolean isScannable() { - return true; - } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java index 11f7dfd..15b4d47 100644 --- a/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java +++ b/modules/injection/cdi/src/test/java/org/apache/tamaya/cdi/extra/ConfiguredVetoExtensionTest.java @@ -18,12 +18,11 @@ */ package org.apache.tamaya.cdi.extra; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.spi.ConfigurationContext; import org.junit.Test; +import javax.config.Config; +import javax.config.spi.ConfigProviderResolver; import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.ProcessAnnotatedType; @@ -34,13 +33,12 @@ public class ConfiguredVetoExtensionTest { @Test public void willBeVetoedIfTypeHasBeenConfiguredAsConcreteClassName() { - ConfigurationContext context = mock(ConfigurationContext.class); - Configuration configuration = mock(Configuration.class); + Config configuration = mock(Config.class); - when(configuration.getContext()).thenReturn(context); - when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn("org.apache.tamaya.cdi.extra.TestKlazz"); + when(configuration.getValue("javax.enterprise.inject.vetoed", String.class)) + .thenReturn("org.apache.tamaya.cdi.extra.TestKlazz"); - ConfigurationProvider.setConfiguration(configuration); + ConfigProviderResolver.instance().registerConfig(configuration, getClass().getClassLoader()); AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class); when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class); @@ -55,13 +53,12 @@ public class ConfiguredVetoExtensionTest { @Test public void willNotBeVetoedIfTypeHasNotBeenConfigured() { - ConfigurationContext context = mock(ConfigurationContext.class); - Configuration configuration = mock(Configuration.class); + Config configuration = mock(Config.class); - when(configuration.getContext()).thenReturn(context); - when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn("org.apache.tamaya.cdi.extra.O"); + when(configuration.getValue("javax.enterprise.inject.vetoed", String.class)) + .thenReturn("org.apache.tamaya.cdi.extra.O"); - ConfigurationProvider.setConfiguration(configuration); + ConfigProviderResolver.instance().registerConfig(configuration, getClass().getClassLoader()); AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class); when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class); @@ -79,13 +76,11 @@ public class ConfiguredVetoExtensionTest { String configuredValue = " " + TestKlazz.class.getName() + ",\t" + TestKlazz2.class.getName(); - ConfigurationContext context = mock(ConfigurationContext.class); - Configuration configuration = mock(Configuration.class); + Config configuration = mock(Config.class); - when(configuration.getContext()).thenReturn(context); - when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn(configuredValue); + when(configuration.getValue("javax.enterprise.inject.vetoed", String.class)).thenReturn(configuredValue); - ConfigurationProvider.setConfiguration(configuration); + ConfigProviderResolver.instance().registerConfig(configuration, getClass().getClassLoader()); AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class); when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class); @@ -103,13 +98,12 @@ public class ConfiguredVetoExtensionTest { String configuredValue = " " + TestKlazz.class.getPackage().getName() + "\\..+"; - ConfigurationContext context = mock(ConfigurationContext.class); - Configuration configuration = mock(Configuration.class); + Config configuration = mock(Config.class); - when(configuration.getContext()).thenReturn(context); - when(configuration.get("javax.enterprise.inject.vetoed")).thenReturn(configuredValue); + when(configuration.getValue("javax.enterprise.inject.vetoed", String.class)) + .thenReturn(configuredValue); - ConfigurationProvider.setConfiguration(configuration); + ConfigProviderResolver.instance().registerConfig(configuration, getClass().getClassLoader()); AnnotatedType<TestKlazz> annotatedType = mock(AnnotatedType.class); when(annotatedType.getJavaClass()).thenReturn(TestKlazz.class); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/resources/META-INF/javaconfig.properties ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/resources/META-INF/javaconfig.properties b/modules/injection/cdi/src/test/resources/META-INF/javaconfig.properties new file mode 100644 index 0000000..c72446e --- /dev/null +++ b/modules/injection/cdi/src/test/resources/META-INF/javaconfig.properties @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +double1=1234.5678 +int2=13 +booleanT=y +remote.wsdl.location = classpath:/service-wsdl.xml +remote.port=1443 +remote.address=${remote.host}:${remote.port} +remote.target.url = https://${remote.address}/remote/service/url +remote.username = joecool + +# ciphered using built in StaticDESPasswordCipher +remote.password = NjAq6q2agYVnvSMz+eYUZg== +cipher=org.apache.openejb.cipher.StaticDESPasswordCipher + +string.value = hello +file.value = ./conf +duration.value = 10 minutes and 57 seconds +boolean.value = true +integer.value = 123 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/cdi/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/modules/injection/cdi/src/test/resources/META-INF/javaconfiguration.properties b/modules/injection/cdi/src/test/resources/META-INF/javaconfiguration.properties deleted file mode 100644 index c72446e..0000000 --- a/modules/injection/cdi/src/test/resources/META-INF/javaconfiguration.properties +++ /dev/null @@ -1,35 +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. -# -double1=1234.5678 -int2=13 -booleanT=y -remote.wsdl.location = classpath:/service-wsdl.xml -remote.port=1443 -remote.address=${remote.host}:${remote.port} -remote.target.url = https://${remote.address}/remote/service/url -remote.username = joecool - -# ciphered using built in StaticDESPasswordCipher -remote.password = NjAq6q2agYVnvSMz+eYUZg== -cipher=org.apache.openejb.cipher.StaticDESPasswordCipher - -string.value = hello -file.value = ./conf -duration.value = 10 minutes and 57 seconds -boolean.value = true -integer.value = 123 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/pom.xml ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/pom.xml b/modules/injection/injection-api/pom.xml index 82c89c3..4bd3ece 100644 --- a/modules/injection/injection-api/pom.xml +++ b/modules/injection/injection-api/pom.xml @@ -40,13 +40,7 @@ under the License. <dependencies> <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${tamaya-apicore.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-core</artifactId> + <artifactId>tamaya-base</artifactId> <version>${tamaya-apicore.version}</version> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java deleted file mode 100644 index 10ba0c8..0000000 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java +++ /dev/null @@ -1,125 +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.inject.api; - - -import javax.enterprise.util.Nonbinding; -import javax.inject.Qualifier; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to define injection of a configured property or define the configuration data - * backing a configuration template method. Hereby this annotation can be used in multiple - * ways and combined with other annotations such as {@link WithConfigOperator}, {@link WithPropertyConverter}. - * - * <h3>Simplest variant</h3> - * Below the most simple variant of a configured class is given: - * <pre> - * package a.b; - * - * public class ConfiguredItem { - * &Config - * private String aValue; - * } - * </pre> - * Configuration resolution is implemented as follows: - * <ul> - * <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = ConfigurationProvider.getConfiguration();}</li> - * <li>The current possible property keys are evaluated by calling {@code cfg.get("a.b.ConfigureItem.aValue");}, - * {@code cfg.get("ConfigureItem.aValue");}, {@code cfg.get("aValue");}</li> - * <li>if not successful, and since no @ConfigDefault annotation is present, the configured default value is used. - * <li>If no value could be evaluated a ({@link org.apache.tamaya.ConfigException} is thrown.</li> - * <li>On success, since no type conversion is involved, the value is injected.</li> - * </ul> - * - * <h3>Explicit annotations</h3> - * In the next example we explicitly define the configuration keys to be used: - * <pre> - * &ConfigDefaultSections("section1") - * public class ConfiguredItem { - * - * &Config(value = {"b", "[a.b.deprecated.keys]", "a"}, defaultValue = "myDefaultValue") - * private String aValue; - * } - * </pre> - * - * Within this example we evaluate multiple possible keys: {@code section1.b, a.b.deprecated.keys, section1.a}. - * Evaluation is aborted if a key is resolved successfully. Hereby the ordering of the annotation values - * define the ordering of resolution. If no value can be found, the configured default {@code myDefaultValue} is - * injected. - * - * <h3>Using explicit field annotation only</h3> - * In the last example we explicitly define the configuration keys but omit the section part, letting the default - * section names to be taken: - * <pre> - * package a.b; - * - * public class ConfiguredItem { - * - * &Config(value = {"b", "[a.b.deprecated.keys]", "a"}, defaultValue = "myDefaultValue") - * private String aValue; - * } - * </pre> - * - * Key resolution is similar to above, but now the default package names are used, resulting in - * {@code a.b.ConfiguredItem.b, ConfiguredItem.b, a.b.deprecated.keys, a.b.ConfiguredItem.a, ConfiguredItem.a} - * being evaluated. - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) -public @interface Config { - - /** Value that is set by default as default, so it is possible to use empty Strings as default values. */ - String UNCONFIGURED_VALUE = "org.apache.tamaya.config.configproperty.unconfigureddvalue"; - - /** - * Defines the configuration property keys to be used. Hereby the first non null value evaluated is injected as - * property value. - * - * @return the property keys, not null. If empty, the field or property name (of a setter method) being injected - * is used by default. - */ - @Nonbinding - String[] value() default {}; - - /** - * The default value to be injected, if none of the configuration keys could be resolved. If no key has been - * resolved and no default value is defined, it is, by default, handled as a deployment error. Depending on the - * extension loaded default values can be fixed Strings or even themselves resolvable. For typed configuration of - * type T entries that are not Strings the default value must be a valid input to a corresponding - * {@link org.apache.tamaya.spi.PropertyConverter}. - * - * @return default value used in case resolution fails. - */ - @Nonbinding - String defaultValue() default UNCONFIGURED_VALUE; - - /** - * Flag that defines if a configuration property is required. If a required - * property is missing, a {@link org.apache.tamaya.ConfigException} is raised. - * Default is {@code true}. - * @return the flag value. - */ - @Nonbinding - boolean required() default true; -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoDetect.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoDetect.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoDetect.java new file mode 100644 index 0000000..f3dee88 --- /dev/null +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoDetect.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.inject.api; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Adding this annotation tells the Tamaya injection system to inject all + * fields found, also including fields not annotated with {@code @Config}. + * The configuration keys to be used for resolution are basically determined + * by the {@link Config} annotation(s). If missing the keys are evaluated in the + * following order: + * <ul> + * <li>packagename.simpleClassname.fieldName</li> + * <li>simpleClassname.fieldName</li> + * <li>fieldName</li> + * </ul> + * Fields not to be injected can be annotated with {@code @NoConfig} to exclude + * them being elected for injection. + * @see Config + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE }) +public @interface ConfigAutoDetect { + + /** + * Flag that tells the injection system if a {@link IllegalStateException} should + * be thrown when a property cannot be resolved. Default is {@code false}. + * @return {@code false} if no exception is thrown on unresolvable properties, {@code true} otherwise. + */ + boolean failIfMissing() default false; +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java deleted file mode 100644 index 251caf9..0000000 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java +++ /dev/null @@ -1,51 +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.inject.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Adding this annotation tells the Tamaya injection system to inject all - * fields found, also including fields not annotated with {@code @Config}. - * The configuration keys to be used for resolution are basically determined - * by the {@link Config} annotation(s). If missing the keys are evaluated in the - * following order: - * <ul> - * <li>packagename.simpleClassname.fieldName</li> - * <li>simpleClassname.fieldName</li> - * <li>fieldName</li> - * </ul> - * Fields not to be injected can be annotated with {@code @NoConfig} to exclude - * them being elected for injection. - * @see Config - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = { ElementType.TYPE }) -public @interface ConfigAutoInject { - - /** - * Flag that tells the injection system if a {@link org.apache.tamaya.ConfigException} should - * be thrown when a property cannot be resolved. Default is {@code false}. - * @return {@code false} if no exception is thrown on unresolvable properties, {@code true} otherwise. - */ - boolean failIfMissing() default false; -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java index a9025f6..9071c4e 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java @@ -30,7 +30,7 @@ import java.lang.annotation.Target; * annotation(s). This annotation allows * to define the configuration section that is prefixed to all <b>relative</b> configuration keys. * @see Config - * @see ConfigAutoInject + * @see ConfigAutoDetect */ @Retention(RetentionPolicy.RUNTIME) @Target(value = { ElementType.TYPE }) http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigFallbackKeys.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigFallbackKeys.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigFallbackKeys.java new file mode 100644 index 0000000..8d0aa4a --- /dev/null +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigFallbackKeys.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.inject.api; + + +import javax.enterprise.util.Nonbinding; +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to define additional keys to be used as fallback keys to evaluate a configuration entry. + */ +@Qualifier +@Retention(RetentionPolicy.RUNTIME) +@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) +public @interface ConfigFallbackKeys { + + /** + * Defines the configuration property keys to be used as fallback keys. + * + * @return the property keys, not null. If empty, the field or property name (of a setter method) being injected + * is used by default. + */ + @Nonbinding + String[] value() default {}; +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java index ef249ac..1efcb11 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.inject.api; +import javax.inject.Provider; import java.beans.PropertyChangeListener; import java.util.function.Supplier; @@ -40,13 +41,13 @@ import java.util.function.Supplier; * * @param <T> The type of the value. */ -public interface DynamicValue<T> { +public interface DynamicValue<T>{ /** * Performs a commit, if necessary, and returns the current value. * * @return the non-null value held by this {@code DynamicValue} - * @throws org.apache.tamaya.ConfigException if there is no value present + * @throws java.util.NoSuchElementException if there is no value present * * @see DynamicValue#isPresent() */ @@ -89,7 +90,7 @@ public interface DynamicValue<T> { * otherwise throws {@code ConfigException}. * * @return the non-null value held by this {@code Optional} - * @throws org.apache.tamaya.ConfigException if there is no value present + * @throws java.util.NoSuchElementException if there is no value present * * @see DynamicValue#isPresent() */ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java index b445e14..985252a 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java @@ -23,9 +23,7 @@ package org.apache.tamaya.inject.api; * for a {@link DynamicValue}. * The policy also affects the cases were any configured listeners/listener methods are called for * propagation current configuration changes. - * @deprecated Currently only used internally. Future usage unclear. */ -@Deprecated public enum LoadPolicy { /** * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later. @@ -38,7 +36,7 @@ public enum LoadPolicy { */ LAZY, /** - * The configuration value is evaluated every time it is accessed. + * The configuration value is (re)evaluated every time it is accessed. */ ALWAYS } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/OptionalConfig.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/OptionalConfig.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/OptionalConfig.java new file mode 100644 index 0000000..8ab2e98 --- /dev/null +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/OptionalConfig.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.inject.api; +// +// +//import javax.enterprise.util.Nonbinding; +//import javax.inject.Qualifier; +//import java.lang.annotation.ElementType; +//import java.lang.annotation.Retention; +//import java.lang.annotation.RetentionPolicy; +//import java.lang.annotation.Target; +// +///** +// * Annotation to mark a configuration entry as optional, thus not throwing any exceptions if not satisfied. +// */ +//@Qualifier +//@Retention(RetentionPolicy.RUNTIME) +//@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) +//public @interface OptionalConfig { +// +//} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java index ddee4e0..3183938 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/UpdatePolicy.java @@ -22,11 +22,6 @@ package org.apache.tamaya.inject.api; * Policy to control how new values are applied to a {@link DynamicValue}. */ public enum UpdatePolicy { - /** - * @deprecated Use {@link #IMMEDIATE} instead of. - */ - @Deprecated - IMMEDEATE, /** New values are applied immediately and registered listeners are informed about the change. */ IMMEDIATE, /** New values or not applied, but stored in the newValue property. Explicit call to DynamicValue#commit @@ -35,11 +30,6 @@ public enum UpdatePolicy { */ EXPLICIT, /** - * @deprecated Use {@link #EXPLICIT} instead of. - */ - @Deprecated - EXPLCIT, - /** * New values are always immediately discarded, listeners are not triggered. */ NEVER, http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java deleted file mode 100644 index 6630e53..0000000 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.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.inject.api; - -import org.apache.tamaya.ConfigOperator; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to define an configuration operator to be used before accessing a configured key. - * This allows filtering the current configuration, e.g. to realize views or ensure security - * constraints. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = {ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) -public @interface WithConfigOperator { - - /** - * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any - * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is - * registered, it is handled as a deployment error. - * @return adapter used to transform the configuration entry. - */ - Class<? extends ConfigOperator> value(); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConverter.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConverter.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConverter.java new file mode 100644 index 0000000..b831afc --- /dev/null +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.inject.api; + + +import javax.config.spi.Converter; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to define a type adapter to be used before injecting a configured key, or for applying changes. + * This will override any other adapter for performing the type conversion before + * injecting the field keys. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) +public @interface WithConverter { + + /** + * Define a custom adapter or codec that should be used to adapt the configuration entry injected. This overrides any + * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is + * registered, it is handled as a deployment error. + * @return adapter used to change the configuration entry. + */ + Class<? extends Converter<?>> value(); + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java deleted file mode 100644 index 499360c..0000000 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java +++ /dev/null @@ -1,46 +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.inject.api; - - -import org.apache.tamaya.spi.PropertyConverter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to define a type adapter to be used before injecting a configured key, or for applying changes. - * This will override any other adapter for performing the type conversion before - * injecting the field keys. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) -public @interface WithPropertyConverter { - - /** - * Define a custom adapter or codec that should be used to adapt the configuration entry injected. This overrides any - * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is - * registered, it is handled as a deployment error. - * @return adapter used to change the configuration entry. - */ - Class<? extends PropertyConverter<?>> value(); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java index b5d8bc3..b0cac4e 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java @@ -17,6 +17,6 @@ * under the License. */ /** - * Common njection API. + * Common injection API. */ package org.apache.tamaya.inject.api; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java index e8a081a..87da886 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java @@ -18,18 +18,15 @@ */ package org.apache.tamaya.inject.spi; -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.TypeLiteral; +import javax.config.Config; import org.apache.tamaya.inject.api.DynamicValue; import org.apache.tamaya.inject.api.UpdatePolicy; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; +import javax.config.spi.Converter; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.io.Serializable; import java.lang.ref.WeakReference; +import java.lang.reflect.Type; import java.util.*; import java.util.function.Consumer; import java.util.function.Supplier; @@ -72,7 +69,7 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { */ private UpdatePolicy updatePolicy = UpdatePolicy.NEVER; /** The targe type. */ - private TypeLiteral<T> targetType; + private Type targetType; /** * The current value, never null. */ @@ -95,9 +92,9 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { * @param targetType the target type. * @param keys the candidate keys. */ - public BaseDynamicValue(Object owner, String propertyName, TypeLiteral targetType, List<String> keys){ + public BaseDynamicValue(Object owner, String propertyName, Type targetType, List<String> keys){ if(keys == null || keys.isEmpty()){ - throw new ConfigException("At least one key is required."); + throw new IllegalArgumentException("At least one key is required."); } this.owner = owner; this.propertyName = Objects.requireNonNull(propertyName); @@ -125,7 +122,7 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { * Get the configuration to evaluate. * @return the configuration, never null. */ - protected abstract Configuration getConfiguration(); + protected abstract Config getConfiguration(); /** * Get the corresponding property name. @@ -155,7 +152,7 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { * Get the target type. * @return the target type, not null. */ - public TypeLiteral<T> getTargetType(){ + public Type getTargetType(){ return targetType; } @@ -207,7 +204,7 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { @Override public boolean updateValue() { - Configuration config = getConfiguration(); + Config config = getConfiguration(); T val = evaluateValue(); if(value == null){ value = val; @@ -262,48 +259,21 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { * Allows to customize type conversion if needed, e.g. based on some annotations defined. * @return the custom converter, which replaces the default converters, ot null. */ - protected PropertyConverter<T> getCustomConverter(){ + protected Converter<T> getCustomConverter(){ return null; } @Override public T evaluateValue() { T value = null; - List<PropertyConverter<T>> converters = new ArrayList<>(); - if (this.getCustomConverter() != null) { - converters.add(this.getCustomConverter()); - } - converters.addAll(getConfiguration().getContext().getPropertyConverters(targetType)); - + Converter<T> customConverter = getCustomConverter(); for (String key : keys) { - ConversionContext ctx = new ConversionContext.Builder(key, targetType).build(); - String stringVal = getConfiguration().getOrDefault(key, String.class, null); - if(stringVal!=null) { - if(String.class.equals(targetType.getType())){ - value = (T)stringVal; - } - for(PropertyConverter<T> conv:converters){ - try{ - value = conv.convert(stringVal, ctx); - if(value!=null){ - break; - } - }catch(Exception e){ - LOG.warning("failed to convert: " + ctx); - } - } - } - } - if(value == null && defaultValue!=null){ - ConversionContext ctx = new ConversionContext.Builder("<defaultValue>", targetType).build(); - for(PropertyConverter<T> conv:converters){ - try{ - value = conv.convert(defaultValue, ctx); - if(value!=null){ - break; - } - }catch(Exception e){ - LOG.warning("failed to convert: " + ctx); + Optional<String> stringVal = getConfiguration().getOptionalValue(key, String.class); + if(stringVal.isPresent()) { + if(customConverter!=null){ + return customConverter.convert(stringVal.get()); + }else{ + return (T)getConfiguration().getValue(key, (Class)getTargetType()); } } } @@ -324,7 +294,7 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T> { * Performs a commit, if necessary, and returns the current value. * * @return the non-null value held by this {@code DynamicValue} - * @throws org.apache.tamaya.ConfigException if there is no value present + * @throws IllegalArgumentException if there is no value present * @see DynamicValue#isPresent() */ @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java index 94c0091..30740c6 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredField.java @@ -18,8 +18,7 @@ */ package org.apache.tamaya.inject.spi; -import org.apache.tamaya.Configuration; - +import javax.config.Config; import java.lang.reflect.Field; import java.util.Collection; @@ -64,5 +63,5 @@ public interface ConfiguredField { * @param instance the instance, not null. * @param config the configuration, not null. */ - void configure(Object instance, Configuration config); + void configure(Object instance, Config config); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java index d8b0d09..00775c5 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredMethod.java @@ -18,8 +18,7 @@ */ package org.apache.tamaya.inject.spi; -import org.apache.tamaya.Configuration; - +import javax.config.Config; import java.lang.reflect.Method; import java.util.Collection; @@ -64,7 +63,7 @@ public interface ConfiguredMethod { * * @param instance the target instance, not null. * @param config the configuration, not null. - * @throws org.apache.tamaya.ConfigException if evaluation or conversion failed. + * @throws IllegalArgumentException if evaluation or conversion failed. */ - void configure(Object instance, Configuration config); + void configure(Object instance, Config config); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java index 0f81dc7..f7a10ad 100644 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java @@ -18,8 +18,7 @@ */ package org.apache.tamaya.inject.spi; -import org.apache.tamaya.Configuration; - +import javax.config.Config; import java.util.Collection; /** @@ -57,7 +56,7 @@ public interface ConfiguredType{ * @param instance The instance to be configured, not null. * @param config the target config, not null. */ - void configure(Object instance, Configuration config); + void configure(Object instance, Config config); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionEvaluator.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionEvaluator.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionEvaluator.java new file mode 100644 index 0000000..4374819 --- /dev/null +++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionEvaluator.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the 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.inject.spi; + +import org.apache.tamaya.inject.api.ConfigDefaultSections; +import org.apache.tamaya.inject.api.ConfigFallbackKeys; + +import javax.config.inject.ConfigProperty; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Utility class with several commonly used functions. + */ +public final class InjectionEvaluator { + + private InjectionEvaluator(){} + + + /** + * Collects all keys to be be accessed as defined by any annotations of type + * {@link ConfigDefaultSections}, {@link javax.config.inject.ConfigProperty}. + * @param member the (optionally) annotated member instance + * @return the regarding key list to be accessed fomr the {@link javax.config.Config}. + */ + public static List<String> getKeys(AccessibleObject member) { + if(member instanceof Field){ + Field f = (Field)member; + return getKeys(f, f.getDeclaringClass().getAnnotation(ConfigDefaultSections.class)); + } else if(member instanceof Method){ + Method m = (Method)member; + return getKeys(m, m.getDeclaringClass().getAnnotation(ConfigDefaultSections.class)); + } + return Collections.emptyList(); + } + + /** + * Evaluates all absolute configuration keys based on the annotations found in a field/class. + * + * @param method method to analyze. + * @return the list current keys in order how they should be processed/looked up. + */ + private static List<String> getKeys(Method method, ConfigDefaultSections sectionAnnot) { + return getKeys(method, + sectionAnnot, + method.getAnnotation(ConfigProperty.class), + method.getAnnotation(ConfigFallbackKeys.class)); + } + + /** + * Evaluates all absolute configuration keys based on the annotations found in a field/class. + * + * @param field field to analyze. + * @return the list current keys in order how they should be processed/looked up. + */ + private static List<String> getKeys(Field field, ConfigDefaultSections sectionAnnot) { + return getKeys(field, + sectionAnnot, + field.getAnnotation(ConfigProperty.class), + field.getAnnotation(ConfigFallbackKeys.class)); + } + + /** + * Evaluates all absolute configuration keys based on the annotations found in a class. + * + * @param member member to analyze. + * @param sectionsAnnot the (optional) annotation definining sections to be looked up. + * @param propertyAnnotation the annotation on field/method level that may defined one or + * several keys to be looked up (in absolute or relative form). + * @return the list current keys in order how they should be processed/looked up. + */ + private static List<String> getKeys(Member member, + ConfigDefaultSections sectionsAnnot, + ConfigProperty propertyAnnotation, + ConfigFallbackKeys configFallbackKeys) { + List<String> result = new ArrayList<>(); + List<String> memberKeys = new ArrayList<>(); + if(propertyAnnotation!=null && !propertyAnnotation.name().isEmpty()){ + memberKeys.add(propertyAnnotation.name()); + } + if(configFallbackKeys !=null){ + memberKeys.addAll(Arrays.asList(configFallbackKeys.value())); + } + if (memberKeys.isEmpty()) { + memberKeys.add(member.getName()); + } + List<String> areaKeys = getSectionKeys(member, sectionsAnnot); + for(String memberKey:memberKeys){ + if (memberKey.startsWith("[") && memberKey.endsWith("]")) { + // absolute key, strip away brackets, take key as is + result.add(memberKey.substring(1, memberKey.length()-1)); + }else{ + for(String areaKey:areaKeys) { + result.add(areaKey + '.' + memberKey); + } + result.add(memberKey); + } + } + return result; + } + + private static List<String> getSectionKeys(Member member, ConfigDefaultSections sectionsAnnot) { + if(member instanceof Field){ + Field f = (Field)member; + return getSectionKeys(f,sectionsAnnot); + } else if(member instanceof Method){ + Method m = (Method)member; + return getSectionKeys(m,sectionsAnnot); + } + return Collections.emptyList(); + } + + private static List<String> getSectionKeys(Method method, ConfigDefaultSections sectionAnnot) { + List<String> areaKeys = new ArrayList<>(); + if (sectionAnnot != null && sectionAnnot.value().length>0) { + // Remove original entry, since it will be replaced with prefixed entries + areaKeys.addAll(Arrays.asList(sectionAnnot.value())); + }else{ + areaKeys.add(method.getDeclaringClass().getName()); + areaKeys.add(method.getDeclaringClass().getSimpleName()); + } + return areaKeys; + } + + private static List<String> getSectionKeys(Field field, ConfigDefaultSections sectionAnnot) { + List<String> areaKeys = new ArrayList<>(); + if (sectionAnnot != null && sectionAnnot.value().length>0) { + // Remove original entry, since it will be replaced with prefixed entries + areaKeys.addAll(Arrays.asList(sectionAnnot.value())); + }else{ + areaKeys.add(field.getDeclaringClass().getName()); + areaKeys.add(field.getDeclaringClass().getSimpleName()); + } + return areaKeys; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java deleted file mode 100644 index d5ab2ef..0000000 --- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/InjectionUtils.java +++ /dev/null @@ -1,130 +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.inject.spi; - -import org.apache.tamaya.inject.api.Config; -import org.apache.tamaya.inject.api.ConfigDefaultSections; - -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Utility class with several commonly used functions. - */ -public final class InjectionUtils { - - private InjectionUtils(){} - - - /** - * Collects all keys to be be accessed as defined by any annotations of type - * {@link ConfigDefaultSections}, {@link Config}. - * @param field the (optionally) annotated field instance - * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}. - */ - public static List<String> getKeys(Field field) { - ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class); - return InjectionUtils.evaluateKeys(field, areasAnnot, field.getAnnotation(Config.class)); - } - - /** - * Collects all keys to be be accessed as defined by any annotations of type - * {@link ConfigDefaultSections}, {@link Config}. - * @param method the (optionally) annotated method instance - * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}. - */ - public static List<String> getKeys(Method method) { - ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class); - return InjectionUtils.evaluateKeys(method, areasAnnot, method.getAnnotation(Config.class)); - } - - /** - * Evaluates all absolute configuration keys based on the member name found. - * - * @param member member to analyze. - * @param sectionAnnot the (optional) annotation defining areas to be looked up. - * @return the list of current keys in order how they should be processed/looked up. - */ - public static List<String> evaluateKeys(Member member, ConfigDefaultSections sectionAnnot) { - List<String> keys = new ArrayList<>(); - List<String> areaKeys = evaluateSectionKeys(member, sectionAnnot); - String key = null; - String name = member.getName(); - if (name.startsWith("get") || name.startsWith("set")) { - key = Character.toLowerCase(name.charAt(3)) + name.substring(4); - } else { - key = Character.toLowerCase(name.charAt(0)) + name.substring(1); - } - for(String areaKey:areaKeys) { - keys.add(areaKey + '.' + key); - } - keys.add(key); - return keys; - } - - /** - * Evaluates all absolute configuration keys based on the annotations found in a class. - * - * @param member member to analyze. - * @param areasAnnot the (optional) annotation definining areas to be looked up. - * @param propertyAnnotation the annotation on field/method level that may defined one or - * several keys to be looked up (in absolute or relative form). - * @return the list current keys in order how they should be processed/looked up. - */ - public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot, Config propertyAnnotation) { - if(propertyAnnotation==null){ - return evaluateKeys(member, areasAnnot); - } - List<String> result = new ArrayList<>(); - List<String> memberKeys = new ArrayList<>(Arrays.asList(propertyAnnotation.value())); - if (memberKeys.isEmpty()) { - memberKeys.add(member.getName()); - } - List<String> areaKeys = evaluateSectionKeys(member, areasAnnot); - for(String memberKey:memberKeys){ - if (memberKey.startsWith("[") && memberKey.endsWith("]")) { - // absolute key, strip away brackets, take key as is - result.add(memberKey.substring(1, memberKey.length()-1)); - }else{ - for(String areaKey:areaKeys) { - result.add(areaKey + '.' + memberKey); - } - result.add(memberKey); - } - } - return result; - } - - private static List<String> evaluateSectionKeys(Member member, ConfigDefaultSections sectionAnnot) { - List<String> areaKeys = new ArrayList<>(); - if (sectionAnnot != null && sectionAnnot.value().length>0) { - // Remove original entry, since it will be replaced with prefixed entries - areaKeys.addAll(Arrays.asList(sectionAnnot.value())); - }else{ - areaKeys.add(member.getDeclaringClass().getName()); - areaKeys.add(member.getDeclaringClass().getSimpleName()); - } - return areaKeys; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java b/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java index bb568a5..6f2a88b 100644 --- a/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java +++ b/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/BaseDynamicValueTest.java @@ -18,13 +18,11 @@ */ package org.apache.tamaya.inject.spi; -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.inject.api.UpdatePolicy; import org.junit.Test; +import javax.config.Config; +import javax.config.ConfigProvider; import java.util.Arrays; import static org.junit.Assert.*; @@ -36,7 +34,7 @@ public class BaseDynamicValueTest { new MyDynamicValue("a", "b"); } - @Test(expected = ConfigException.class) + @Test(expected = IllegalArgumentException.class) public void create_nokeys(){ new MyDynamicValue(); } @@ -79,12 +77,12 @@ public class BaseDynamicValueTest { private static final class MyDynamicValue extends BaseDynamicValue{ public MyDynamicValue(String... keys){ - super(null, "test", TypeLiteral.of(String.class), Arrays.asList(keys)); + super(null, "test", String.class, Arrays.asList(keys)); } @Override - protected Configuration getConfiguration() { - return ConfigurationProvider.getConfiguration(); + protected Config getConfiguration() { + return ConfigProvider.getConfig(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/InjectionUtilsTest.java ---------------------------------------------------------------------- diff --git a/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/InjectionUtilsTest.java b/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/InjectionUtilsTest.java index fee1a58..4b76d36 100644 --- a/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/InjectionUtilsTest.java +++ b/modules/injection/injection-api/src/test/java/org/apache/tamaya/inject/spi/InjectionUtilsTest.java @@ -18,10 +18,11 @@ */ package org.apache.tamaya.inject.spi; -import org.apache.tamaya.inject.api.Config; import org.apache.tamaya.inject.api.ConfigDefaultSections; +import org.apache.tamaya.inject.api.ConfigFallbackKeys; import org.junit.Test; +import javax.config.inject.ConfigProperty; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.List; @@ -33,13 +34,14 @@ public class InjectionUtilsTest { @Test public void getKeysMethod() { class Klazz { - @Config({"val", "val2", "[vvv]"}) + @ConfigProperty(name="val") + @ConfigFallbackKeys({"val2", "[vvv]"}) public void setValue(String field){} } Method method = Klazz.class.getMethods()[0]; - List<String> foundKeys = InjectionUtils.getKeys(method); + List<String> foundKeys = InjectionEvaluator.getKeys(method); assertThat(foundKeys).isNotNull() .contains("org.apache.tamaya.inject.spi.InjectionUtilsTest$1Klazz.val", @@ -61,7 +63,7 @@ public class InjectionUtilsTest { Field field = Klazz.class.getFields()[0]; - List<String> foundKeys = InjectionUtils.getKeys(field); + List<String> foundKeys = InjectionEvaluator.getKeys(field); assertThat(foundKeys).isNotNull() .contains("org.apache.tamaya.inject.spi.InjectionUtilsTest$2Klazz.field", @@ -80,7 +82,7 @@ public class InjectionUtilsTest { Field field = Klazz.class.getFields()[0]; - List<String> foundKeys = InjectionUtils.evaluateKeys(field, Klazz.class.getAnnotation(ConfigDefaultSections.class)); + List<String> foundKeys = InjectionEvaluator.getKeys(field); assertThat(foundKeys).isNotNull() .contains("basic.field", "field"); @@ -90,7 +92,8 @@ public class InjectionUtilsTest { public void evaluateKeysWithSectionAndMemberAnnotation() { @ConfigDefaultSections("basic") class Klazz { - @Config({"val", "[absoluteVal]"}) + @ConfigProperty(name="val") + @ConfigFallbackKeys({"absoluteVal"}) public String field; protected String protectedField; private String privateField; @@ -98,8 +101,7 @@ public class InjectionUtilsTest { Field field = Klazz.class.getFields()[0]; - List<String> foundKeys = InjectionUtils.evaluateKeys(field, Klazz.class.getAnnotation(ConfigDefaultSections.class), - field.getAnnotation(Config.class)); + List<String> foundKeys = InjectionEvaluator.getKeys(field); assertThat(foundKeys).isNotNull() .contains("basic.val", "val", "absoluteVal"); @@ -108,7 +110,8 @@ public class InjectionUtilsTest { @Test public void evaluateKeysWithMemberAnnotation() { class Klazz { - @Config({"val", "[absoluteVal]"}) + @ConfigProperty(name="val") + @ConfigFallbackKeys("[absoluteVal]") public String field; protected String protectedField; private String privateField; @@ -116,8 +119,7 @@ public class InjectionUtilsTest { Field field = Klazz.class.getFields()[0]; - List<String> foundKeys = InjectionUtils.evaluateKeys(field, null, - field.getAnnotation(Config.class)); + List<String> foundKeys = InjectionEvaluator.getKeys(field); assertThat(foundKeys).isNotNull() .contains("Klazz.val", "val", "absoluteVal"); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/pom.xml ---------------------------------------------------------------------- diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml index d811715..c7da6e0 100644 --- a/modules/injection/pom.xml +++ b/modules/injection/pom.xml @@ -35,4 +35,13 @@ <module>cdi</module> </modules> + <dependencies> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + </project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/standalone/pom.xml ---------------------------------------------------------------------- diff --git a/modules/injection/standalone/pom.xml b/modules/injection/standalone/pom.xml index e3f646e..f677ca2 100644 --- a/modules/injection/standalone/pom.xml +++ b/modules/injection/standalone/pom.xml @@ -35,7 +35,7 @@ under the License. <dependencies> <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> + <artifactId>tamaya-base</artifactId> <version>${tamaya-apicore.version}</version> <scope>provided</scope> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java ---------------------------------------------------------------------- diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java index 898e937..042efc0 100644 --- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java +++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java @@ -19,8 +19,7 @@ package org.apache.tamaya.inject; -import org.apache.tamaya.Configuration; - +import javax.config.Config; import java.util.function.Supplier; /** @@ -51,7 +50,7 @@ public interface ConfigurationInjector { * @param config the configuration to be used for injection. * @return the configured instance (allows chaining of operations). */ - <T> T configure(T instance, Configuration config); + <T> T configure(T instance, Config config); /** * Creates a template implementing the annotated methods based on current configuration data. @@ -70,7 +69,7 @@ public interface ConfigurationInjector { * @param templateType the type of the template to be created. * @return the configured template. */ - <T> T createTemplate(Class<T> templateType, Configuration config); + <T> T createTemplate(Class<T> templateType, Config config); /** @@ -90,6 +89,13 @@ public interface ConfigurationInjector { * @param <T> the target type. * @return a supplier creating configured instances of {@code T}. */ - <T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier, Configuration config); + <T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier, Config config); + /** + * Method checks if the given instance is annotated for being configured using {@link javax.config.inject.ConfigProperty} + * annotations. + * @param o the instance, not null. + * @return true, if the instance has any fields or setter methods annotated with {@link javax.config.inject.ConfigProperty}. + */ + boolean isConfigured(Object o); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java ---------------------------------------------------------------------- diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java index fd9f7be..bee17a0 100644 --- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java +++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java @@ -18,12 +18,10 @@ */ package org.apache.tamaya.inject.internal; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.inject.api.DynamicValue; import org.apache.tamaya.inject.spi.ConfiguredType; +import javax.config.ConfigProvider; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.util.Objects; @@ -53,7 +51,7 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - Configuration config = ConfigurationProvider.getConfiguration(); + javax.config.Config config = ConfigProvider.getConfig(); if ("toString".equals(method.getName())) { return "Configured Proxy -> " + this.type.getType().getName(); } else if ("hashCode".equals(method.getName())) { @@ -66,8 +64,6 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler if (method.getReturnType() == DynamicValue.class) { return DefaultDynamicValue.of(proxy, method, config); } - String[] retKey = new String[1]; - String configValue = InjectionHelper.getConfigValue(method, retKey, config); - return InjectionHelper.adaptValue(method, TypeLiteral.of(method.getReturnType()), retKey[0], configValue); + return InjectionHelper.getConfigValue(method, method.getReturnType(), config); } }
