Return-Path: X-Original-To: apmail-tamaya-commits-archive@minotaur.apache.org Delivered-To: apmail-tamaya-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 983C817D0F for ; Fri, 25 Sep 2015 18:33:12 +0000 (UTC) Received: (qmail 41525 invoked by uid 500); 25 Sep 2015 18:33:12 -0000 Delivered-To: apmail-tamaya-commits-archive@tamaya.apache.org Received: (qmail 41497 invoked by uid 500); 25 Sep 2015 18:33:12 -0000 Mailing-List: contact commits-help@tamaya.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tamaya.incubator.apache.org Delivered-To: mailing list commits@tamaya.incubator.apache.org Received: (qmail 41488 invoked by uid 99); 25 Sep 2015 18:33:12 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Sep 2015 18:33:12 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id BFACFC0C0C for ; Fri, 25 Sep 2015 18:33:11 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.775 X-Spam-Level: * X-Spam-Status: No, score=1.775 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.006, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 0lR1X6Ev9Edk for ; Fri, 25 Sep 2015 18:33:00 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 86866439D4 for ; Fri, 25 Sep 2015 18:32:59 +0000 (UTC) Received: (qmail 40157 invoked by uid 99); 25 Sep 2015 18:32:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Sep 2015 18:32:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EA57AE0A9B; Fri, 25 Sep 2015 18:32:58 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anatole@apache.org To: commits@tamaya.incubator.apache.org Date: Fri, 25 Sep 2015 18:33:05 -0000 Message-Id: In-Reply-To: <14b7600ec1cb4825aa765a7eb94408d4@git.apache.org> References: <14b7600ec1cb4825aa765a7eb94408d4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [8/8] incubator-tamaya git commit: TAMAYA-110: Add Support for integrating with Spring Environment and Configuration. Feature added. TAMAYA-111: Add Classloader aware ServiceContext. TAMAYA-110: Add Support for integrating with Spring Environment and Configuration. Feature added. TAMAYA-111: Add Classloader aware ServiceContext. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/0f3bae97 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/0f3bae97 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/0f3bae97 Branch: refs/heads/master Commit: 0f3bae97ccab9dc18052d2819ead3e9ce8816bc7 Parents: 0f8d598 Author: anatole Authored: Fri Sep 25 20:30:49 2015 +0200 Committer: anatole Committed: Fri Sep 25 20:30:49 2015 +0200 ---------------------------------------------------------------------- modules/integration/pom.xml | 39 ++ modules/integration/spring/pom.xml | 109 +++++ .../SpringConfigInjectionPostProcessor.java | 40 ++ .../integration/spring/TamayaSpringConfig.java | 49 +++ .../spring/TamayaSpringPropertySource.java | 39 ++ .../spring/src/main/resources/spring-config.xml | 32 ++ .../spring/ConfiguredSpringBean.java | 56 +++ .../integration/spring/SpringConfigTest.java | 61 +++ .../META-INF/javaconfiguration.properties | 19 + .../spring/src/test/resources/spring-config.xml | 33 ++ modules/pom.xml | 2 + sandbox/integration/cdi/pom.xml | 195 --------- .../cdi/config/ConfiguredVetoExtension.java | 42 -- .../cdi/internal/CDIAwareServiceContext.java | 173 -------- .../cdi/internal/DefaultConfiguration.java | 268 ------------ .../internal/DefaultConfigurationContext.java | 279 ------------- .../DefaultConfigurationContextBuilder.java | 152 ------- .../integration/cdi/internal/EnumConverter.java | 68 --- .../cdi/internal/PropertyConverterManager.java | 409 ------------------- .../cdi/internal/SEInjectorCDIExtension.java | 86 ---- .../cdi/internal/TamayaCDIIntegration.java | 57 --- .../cdi/internal/TamayaConfigProvider.java | 53 --- .../cdi/src/main/resources/META-INF/beans.xml | 24 -- .../javax.enterprise.inject.spi.Extension | 20 - .../org.apache.tamaya.spi.ServiceContext | 19 - .../tamaya/integration/cdi/ConfiguredClass.java | 124 ------ .../tamaya/integration/cdi/ConfiguredTest.java | 85 ---- .../tamaya/integration/cdi/InjectedClass.java | 62 --- .../cdi/cfg/ProvidedPropertySource.java | 66 --- .../integration/cdi/cfg/TestConfigProvider.java | 45 -- .../integration/cdi/cfg/TestPropertySource.java | 78 ---- .../cdi/src/test/resources/META-INF/beans.xml | 24 -- 32 files changed, 479 insertions(+), 2329 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/pom.xml ---------------------------------------------------------------------- diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml new file mode 100644 index 0000000..2f69450 --- /dev/null +++ b/modules/integration/pom.xml @@ -0,0 +1,39 @@ + + + + + + org.apache.tamaya.ext + tamaya-extensions + 0.2-incubating-SNAPSHOT + + + pom + 4.0.0 + tamaya-integration + + + cdi + spring + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/pom.xml ---------------------------------------------------------------------- diff --git a/modules/integration/spring/pom.xml b/modules/integration/spring/pom.xml new file mode 100644 index 0000000..6916936 --- /dev/null +++ b/modules/integration/spring/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + + org.apache.tamaya.ext + tamaya-integration + 0.2-incubating-SNAPSHOT + + + tamaya-spring + Apache Tamaya Modules Integration - Spring + + + 4.2.1.RELEASE + 1.2.6.RELEASE + + + + + + org.jacoco + jacoco-maven-plugin + + + prepare-agent + + prepare-agent + + + + + + + + + junit + junit + test + + + org.hamcrest + hamcrest-library + test + + + org.hamcrest + hamcrest-core + test + + + + org.apache.tamaya + tamaya-java7-core + ${project.version} + test + + + org.apache.tamaya + tamaya-java7-api + ${project.version} + provided + + + org.apache.tamaya.ext + tamaya-injection + 0.2-incubating-SNAPSHOT + true + + + org.springframework + spring-core + ${spring.version} + provided + + + org.springframework + spring-context + ${spring.version} + provided + + + + org.springframework + spring-test + ${spring.version} + test + + + + http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java b/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java new file mode 100644 index 0000000..1193b8d --- /dev/null +++ b/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the 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.integration.spring; + +import org.apache.tamaya.inject.ConfigurationInjection; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; + +/** + * PostProcessor that performs injection of configured values using Tamaya {@link ConfigurationInjection}. + */ +public class SpringConfigInjectionPostProcessor implements BeanPostProcessor{ + + @Override + public Object postProcessBeforeInitialization(Object o, String s) throws BeansException { + ConfigurationInjection.getConfigurationInjector().configure(o); + return o; + } + + @Override + public Object postProcessAfterInitialization(Object o, String s) throws BeansException { + return o; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java b/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java new file mode 100644 index 0000000..e3adf3f --- /dev/null +++ b/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.integration.spring; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.env.ConfigurableEnvironment; + +import javax.annotation.PostConstruct; + +/** + * Spring Configuration Bean adding {@link TamayaSpringPropertySource} to the current + * {@link org.springframework.core.env.Environment}. + */ +@Configuration +public class TamayaSpringConfig { + + @Autowired + private ConfigurableEnvironment env; + + @PostConstruct + public void init() { + env.getPropertySources().addFirst(new TamayaSpringPropertySource()); + } + + @Bean + public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java b/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java new file mode 100644 index 0000000..2e8ac1c --- /dev/null +++ b/modules/integration/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the 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.integration.spring; + + +import org.apache.tamaya.ConfigurationProvider; +import org.springframework.core.env.PropertySource; + +/** + * Spring PropertySource bridging to Tamaya {@link org.apache.tamaya.Configuration}. + */ +public class TamayaSpringPropertySource extends PropertySource { + + public TamayaSpringPropertySource() { + super("ApacheTamayaConfig"); + } + + @Override + public String getProperty(String name) { + return ConfigurationProvider.getConfiguration().get(name); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/main/resources/spring-config.xml ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/main/resources/spring-config.xml b/modules/integration/spring/src/main/resources/spring-config.xml new file mode 100644 index 0000000..c1d6eda --- /dev/null +++ b/modules/integration/spring/src/main/resources/spring-config.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java b/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java new file mode 100644 index 0000000..9a2526b --- /dev/null +++ b/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.integration.spring; + +import org.apache.tamaya.inject.ConfiguredProperty; +import org.apache.tamaya.inject.ConfiguredType; +import org.apache.tamaya.inject.DefaultValue; +import org.apache.tamaya.inject.NoConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; + +/** + * Created by Anatole on 25.09.2015. + */ +@ConfiguredType +public class ConfiguredSpringBean { + + @Autowired + private Environment env; + + @ConfiguredProperty(keys = "java.version") + private String javaVersion; + + @ConfiguredProperty + @DefaultValue("23") + private int testNumber; + + public String getJavaVersion(){ + return javaVersion; + } + + public int getTestNumber(){ + return testNumber; + } + + public Environment getEnv(){ + return env; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest.java ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest.java b/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest.java new file mode 100644 index 0000000..1f28816 --- /dev/null +++ b/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.integration.spring; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Created by Anatole on 25.09.2015. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("classpath:spring-config.xml") +public class SpringConfigTest { + + @Autowired + private ConfiguredSpringBean configuredBean; + + @Test + public void assertBeanNotNull(){ + assertNotNull(configuredBean); + } + + @Test + public void assert_JavaVersion_Injected(){ + assertNotNull(configuredBean.getJavaVersion()); + assertEquals(System.getProperty("java.version"), configuredBean.getJavaVersion()); + } + + @Test + public void assert_Number_Injected(){ + assertEquals(configuredBean.getTestNumber(), 23); + } + + @Test + public void assert_Number_From_Environment(){ + assertEquals("value11", configuredBean.getEnv().getProperty("myConfiguredValue")); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/test/resources/META-INF/javaconfiguration.properties b/modules/integration/spring/src/test/resources/META-INF/javaconfiguration.properties new file mode 100644 index 0000000..3a7cba7 --- /dev/null +++ b/modules/integration/spring/src/test/resources/META-INF/javaconfiguration.properties @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy 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. +# +myConfiguredValue=value11 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/integration/spring/src/test/resources/spring-config.xml ---------------------------------------------------------------------- diff --git a/modules/integration/spring/src/test/resources/spring-config.xml b/modules/integration/spring/src/test/resources/spring-config.xml new file mode 100644 index 0000000..1978ab9 --- /dev/null +++ b/modules/integration/spring/src/test/resources/spring-config.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/modules/pom.xml ---------------------------------------------------------------------- diff --git a/modules/pom.xml b/modules/pom.xml index 6ab6602..0ea1ca9 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -46,6 +46,8 @@ under the License. server remote optional + classloader-support + integration http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/pom.xml ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/pom.xml b/sandbox/integration/cdi/pom.xml deleted file mode 100644 index 5bbdb6e..0000000 --- a/sandbox/integration/cdi/pom.xml +++ /dev/null @@ -1,195 +0,0 @@ - - - 4.0.0 - - - org.apache.tamaya.ext - tamaya-integrations - 0.2-incubating-SNAPSHOT - - - tamaya-cdi - Apache Tamaya Modules Integration - CDI - - - 1.6.2 - 2.2.7.Final - 1.0 - 1.0 - 1.0 - 0.5 - 1.1.0 - - - - - - org.jacoco - jacoco-maven-plugin - - - prepare-agent - - prepare-agent - - - - - - - - - junit - junit - test - - - org.hamcrest - hamcrest-library - test - - - org.hamcrest - hamcrest-core - test - - - - org.apache.tamaya.ext - tamaya-classloader-support - 0.2-incubating-SNAPSHOT - - - org.apache.tamaya - tamaya-java7-core - ${project.version} - test - - - org.apache.tamaya - tamaya-java7-api - ${project.version} - provided - - - org.apache.tamaya.ext - tamaya-injection - 0.2-incubating-SNAPSHOT - true - - - org.apache.geronimo.specs - geronimo-jcdi_1.1_spec - ${geronimo-jcdi-1.1-spec.version} - provided - - - org.apache.deltaspike.modules - deltaspike-test-control-module-api - ${ds.version} - test - - - org.apache.deltaspike.modules - deltaspike-test-control-module-impl - ${ds.version} - test - - - - - OWB - - true - - - - - org.apache.geronimo.specs - geronimo-atinject_1.0_spec - ${geronimo-atinject-1.0-spec.version} - - - org.apache.geronimo.specs - geronimo-interceptor_1.2_spec - ${geronimo-interceptor-1.2-spec.version} - provided - - - org.apache.geronimo.specs - geronimo-annotation_1.2_spec - 1.0.MR2-SNAPSHOT - provided - - - org.apache.geronimo.specs - geronimo-el_2.2_spec - 1.0.2 - - - - org.apache.openwebbeans - openwebbeans-impl - ${owb.version} - - - org.apache.openwebbeans - openwebbeans-spi - ${owb.version} - - - org.apache.openwebbeans - openwebbeans-resource - ${owb.version} - - - - org.apache.bval - bval-jsr303 - ${bval.version} - test - - - org.apache.deltaspike.cdictrl - deltaspike-cdictrl-owb - ${ds.version} - test - - - - - Weld - - - org.jboss.weld.se - weld-se - ${weld.version} - - - org.apache.deltaspike.cdictrl - deltaspike-cdictrl-weld - ${ds.version} - test - - - - - http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java b/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java deleted file mode 100644 index f90998d..0000000 --- a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.integration.cdi.config; - -import org.apache.tamaya.ConfigurationProvider; - -import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.ProcessAnnotatedType; - -/** - * CDI Extension that can be used to veto on beans by configuring the fully qualified class names (as regex expression) - * under {@code javax.enterprise.inject.vetoed}. Multiple expression can be added as comma separated values. - */ -public class ConfiguredVetoExtension { - - public void observesBean(@Observes ProcessAnnotatedType type){ - String vetoedTypesVal = ConfigurationProvider.getConfiguration().get("javax.enterprise.inject.vetoed"); - String[] vetoedTypes = vetoedTypesVal.split(","); - for(String typeExpr:vetoedTypes){ - if(type.getAnnotatedType().getJavaClass().getName().matches(typeExpr)){ - type.veto(); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java b/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java deleted file mode 100644 index 04d92c7..0000000 --- a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java +++ /dev/null @@ -1,173 +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.integration.cdi.internal; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.clsupport.internal.CLAwareServiceContext; -import org.apache.tamaya.spi.ServiceContext; - -import javax.annotation.Priority; -import javax.enterprise.inject.Instance; -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.ServiceLoader; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * This class implements a {@link ServiceContext}, which basically provides a similar loading mechanism as used - * by the {@link java.util.ServiceLoader}. Whereas the {@link java.util.ServiceLoader} only loads configurations - * and instances from one classloader, this loader manages configs found and the related instances for each - * classloader along the classloader hierarchies individually. It ensures instances are loaded on the classloader - * level, where they first are visible. Additionally it ensures the same configuration resource (and its - * declared services) are loaded multiple times, when going up the classloader hierarchy.

- * Finally classloaders are not stored by reference by this class, to ensure they still can be garbage collected. - * Refer also the inherited parent class for further details.

- * This class uses an ordinal of {@code 10}, so it overrides any default {@link ServiceContext} implementations - * provided with the Tamaya core modules. - */ -public class CDIAwareServiceContext implements ServiceContext { - /** - * List current services loaded, per classloader. - */ - private final CLAwareServiceContext clAwareServiceContext = new CLAwareServiceContext(); - - /** - * Singletons. - */ - private final Map, Object> singletons = new ConcurrentHashMap<>(); - - - @Override - public T getService(Class serviceType) { - Object cached = singletons.get(serviceType); - if (cached == null) { - Collection services = getServices(serviceType); - if (services.isEmpty()) { - cached = null; - } else { - cached = getServiceWithHighestPriority(services, serviceType); - } - if(cached!=null) { - singletons.put(serviceType, cached); - } - } - return serviceType.cast(cached); - } - - /** - * Loads and registers services. - * - * @param the concrete type. - * @param serviceType The service type. - * @return the items found, never {@code null}. - */ - @Override - public List getServices(final Class serviceType) { - List found = (List) clAwareServiceContext.getServices(serviceType); - BeanManager beanManager = TamayaCDIIntegration.getBeanManager(); - Instance cdiInstances = null; - if(beanManager!=null){ - Set> instanceBeans = beanManager.getBeans(Instance.class); - cdiInstances = (Instance)beanManager.getReference(instanceBeans.iterator().next(), Instance.class, null); - } - if(cdiInstances!=null){ - for(T t:cdiInstances.select(serviceType)){ - found.add(t); - } - } - return found; - } - - /** - * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such - * annotation is present, a default priority is returned (1); - * @param o the instance, not null. - * @return a priority, by default 1. - */ - public static int getPriority(Object o){ - int prio = 1; //X TODO discuss default priority - Priority priority = o.getClass().getAnnotation(Priority.class); - if (priority != null) { - prio = priority.value(); - } - return prio; - } - - /** - * @param services to scan - * @param type of the service - * - * @return the service with the highest {@link javax.annotation.Priority#value()} - * - * @throws ConfigException if there are multiple service implementations with the maximum priority - */ - private T getServiceWithHighestPriority(Collection services, Class serviceType) { - - // we do not need the priority stuff if the list contains only one element - if (services.size() == 1) { - return services.iterator().next(); - } - - Integer highestPriority = null; - int highestPriorityServiceCount = 0; - T highestService = null; - - for (T service : services) { - int prio = getPriority(service); - if (highestPriority == null || highestPriority < prio) { - highestService = service; - highestPriorityServiceCount = 1; - highestPriority = prio; - } else if (highestPriority == prio) { - highestPriorityServiceCount++; - } - } - - if (highestPriorityServiceCount > 1) { - throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}", - highestPriorityServiceCount, - serviceType.getName(), - highestPriority, - services)); - } - - return highestService; - } - - /** - * Returns ordinal of 20, overriding defaults as well as the inherited (internally used) CLAwareServiceContext - * instance. - * @return ordinal of 20. - */ - @Override - public int ordinal() { - return 20; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfiguration.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfiguration.java b/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfiguration.java deleted file mode 100644 index 630ba62..0000000 --- a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfiguration.java +++ /dev/null @@ -1,268 +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.integration.cdi.internal; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.ConfigOperator; -import org.apache.tamaya.ConfigQuery; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValueCombinationPolicy; - -import javax.enterprise.inject.Vetoed; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the - * chain of {@link PropertySource} and {@link PropertyFilter} - * instance to evaluate the current Configuration. - */ -@Vetoed -public class DefaultConfiguration implements Configuration { - /** - * The logger. - */ - private static final Logger LOG = Logger.getLogger(DefaultConfiguration.class.getName()); - /** - * The maximal number of filter cycles performed before aborting. - */ - private static final int MAX_FILTER_LOOPS = 10; - - /** - * The current {@link ConfigurationContext} of the current instance. - */ - private final ConfigurationContext configurationContext; - - /** - * Constructor. - * @param configurationContext The configuration Context to be used. - */ - public DefaultConfiguration(ConfigurationContext configurationContext){ - this.configurationContext = Objects.requireNonNull(configurationContext); - } - - /** - * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances - * provided by the current {@link ConfigurationContext}. The first non-null-value returned - * is taken as an intermediate value. Finally the value is filtered through the - * {@link PropertyFilter} instances installed, before it is returned as the final result of - * this method. - * - * @param key the property's key, not null. - * @return the optional configuration value, never null. - */ - @Override - public String get(String key) { - List propertySources = configurationContext.getPropertySources(); - String unfilteredValue = null; - PropertyValueCombinationPolicy combinationPolicy = this.configurationContext - .getPropertyValueCombinationPolicy(); - for (PropertySource propertySource : propertySources) { - unfilteredValue = combinationPolicy.collect(unfilteredValue, key, propertySource); - } - return applyFilter(key, unfilteredValue); - } - - /** - * Apply filters to a single property value. - * - * @param key the key, used for logging, not null. - * @param unfilteredValue the unfiltered property value. - * @return the filtered value, or null. - */ - private String applyFilter(String key, String unfilteredValue) { - // Apply filters to values, prevent values filtered to null! - for (int i = 0; i < MAX_FILTER_LOOPS; i++) { - boolean changed = false; - // Apply filters to values, prevent values filtered to null! - for (PropertyFilter filter : configurationContext.getPropertyFilters()) { - String newValue = filter.filterProperty(key, unfilteredValue); - if (newValue != null && !newValue.equals(unfilteredValue)) { - changed = true; - if (LOG.isLoggable(Level.FINEST)) { - LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter); - } - } else if (unfilteredValue != null && !unfilteredValue.equals(newValue)) { - changed = true; - if (LOG.isLoggable(Level.FINEST)) { - LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter); - } - } - unfilteredValue = newValue; - } - if (!changed) { - LOG.finest("Finishing filter loop, no changes detected."); - break; - } else { - if (i == (MAX_FILTER_LOOPS - 1)) { - if (LOG.isLoggable(Level.WARNING)) { - LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i); - } - } else { - LOG.finest("Repeating filter loop, changes detected."); - } - } - } - return unfilteredValue; - } - - /** - * Get the current properties, composed by the loaded {@link PropertySource} and filtered - * by registered {@link PropertyFilter}. - * - * @return the final properties. - */ - @Override - public Map getProperties() { - List propertySources = new ArrayList<>(configurationContext.getPropertySources()); - Collections.reverse(propertySources); - Map result = new HashMap<>(); - for (PropertySource propertySource : propertySources) { - try { - int origSize = result.size(); - Map otherMap = propertySource.getProperties(); - LOG.log(Level.FINEST, null, "Overriding with properties from " + propertySource.getName()); - result.putAll(otherMap); - LOG.log(Level.FINEST, null, "Handled properties from " + propertySource.getName() + "(new: " + - (result.size() - origSize) + ", overrides: " + origSize + ", total: " + result.size()); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Error adding properties from PropertySource: " + propertySource + ", ignoring PropertySource.", e); - } - } - return applyFilters(result); - } - - /** - * Filter a full configuration property map. - * - * @param inputMap the unfiltered map - * @return the filtered map. - */ - private Map applyFilters(Map inputMap) { - Map resultMap = new HashMap<>(inputMap); - // Apply filters to values, prevent values filtered to null! - for (int i = 0; i < MAX_FILTER_LOOPS; i++) { - AtomicInteger changes = new AtomicInteger(); - for (PropertyFilter filter : configurationContext.getPropertyFilters()) { - for (Map.Entry entry : inputMap.entrySet()) { - final String k = entry.getKey(); - final String v = entry.getValue(); - - String newValue = filter.filterProperty(k, v); - if (newValue != null && !newValue.equals(v)) { - changes.incrementAndGet(); - LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter); - } else if (v != null && !v.equals(newValue)) { - changes.incrementAndGet(); - LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter); - } - // Remove null values - if (null != newValue) { - resultMap.put(k, newValue); - } - else{ - resultMap.remove(k); - } - } - } - if (changes.get() == 0) { - LOG.finest("Finishing filter loop, no changes detected."); - break; - } else { - if (i == (MAX_FILTER_LOOPS - 1)) { - if (LOG.isLoggable(Level.WARNING)) { - LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i); - } - } else { - LOG.finest("Repeating filter loop, changes detected: " + changes.get()); - } - changes.set(0); - } - } - return resultMap; - } - - /** - * Accesses the current String value for the given key and tries to convert it - * using the {@link PropertyConverter} instances provided by the current - * {@link ConfigurationContext}. - * - * @param key the property's absolute, or relative path, e.g. @code - * a/b/c/d.myProperty}. - * @param type The target type required, not null. - * @param the value type - * @return the converted value, never null. - */ - @Override - public T get(String key, Class type) { - return get(key, (TypeLiteral)TypeLiteral.of(type)); - } - - /** - * Accesses the current String value for the given key and tries to convert it - * using the {@link PropertyConverter} instances provided by the current - * {@link ConfigurationContext}. - * - * @param key the property's absolute, or relative path, e.g. @code - * a/b/c/d.myProperty}. - * @param type The target type required, not null. - * @param the value type - * @return the converted value, never null. - */ - @Override - public T get(String key, TypeLiteral type) { - String value = get(key); - if (value != null) { - List> converters = configurationContext.getPropertyConverters(type); - for (PropertyConverter converter : converters) { - try { - T t = converter.convert(value); - if (t != null) { - return t; - } - } catch (Exception e) { - LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e); - } - } - throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key); - } - - return null; - } - - public Configuration with(ConfigOperator operator) { - return operator.operate(this); - } - - public T query(ConfigQuery query) { - return query.query(this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java b/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java deleted file mode 100644 index 1f39c8d..0000000 --- a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java +++ /dev/null @@ -1,279 +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.integration.cdi.internal; - -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.ConfigurationContextBuilder; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertySourceProvider; -import org.apache.tamaya.spi.PropertyValueCombinationPolicy; -import org.apache.tamaya.spi.ServiceContextManager; - -import javax.annotation.Priority; -import javax.enterprise.inject.Vetoed; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.logging.Logger; - -/** - * Default Implementation of a simple ConfigurationContext. - */ -@Vetoed -public class DefaultConfigurationContext implements ConfigurationContext { - /** The logger used. */ - private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName()); - /** - * Cubcomponent handling {@link PropertyConverter} instances. - */ - private PropertyConverterManager propertyConverterManager = new PropertyConverterManager(); - - /** - * The current unmodifiable list of loaded {@link PropertySource} instances. - */ - private List immutablePropertySources; - - /** - * The current unmodifiable list of loaded {@link PropertyFilter} instances. - */ - private List immutablePropertyFilters; - - /** - * The overriding policy used when combining PropertySources registered to evalute the final configuration - * values. - */ - private PropertyValueCombinationPolicy propertyValueCombinationPolicy; - - /** - * Lock for internal synchronization. - */ - private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock(); - - /** Comparator used for ordering property sources. */ - private final PropertySourceComparator propertySourceComparator = new PropertySourceComparator(); - - /** Comparator used for ordering property filters. */ - private final PropertyFilterComparator propertyFilterComparator = new PropertyFilterComparator(); - - - /** - * The first time the Configuration system gets invoked we do initialize - * all our {@link PropertySource}s and - * {@link PropertyFilter}s which are known at startup. - */ - public DefaultConfigurationContext() { - List propertySources = new ArrayList<>(); - - // first we load all PropertySources which got registered via java.util.ServiceLoader - propertySources.addAll(ServiceContextManager.getServiceContext().getServices(PropertySource.class)); - - // after that we add all PropertySources which get dynamically registered via their PropertySourceProviders - propertySources.addAll(evaluatePropertySourcesFromProviders()); - - // now sort them according to their ordinal values - Collections.sort(propertySources, new PropertySourceComparator()); - - immutablePropertySources = Collections.unmodifiableList(propertySources); - LOG.info("Registered " + immutablePropertySources.size() + " property sources: " + - immutablePropertySources); - - // as next step we pick up the PropertyFilters pretty much the same way - List propertyFilters = new ArrayList<>(); - propertyFilters.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)); - Collections.sort(propertyFilters, new PropertyFilterComparator()); - immutablePropertyFilters = Collections.unmodifiableList(propertyFilters); - LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " + - immutablePropertyFilters); - - immutablePropertyFilters = Collections.unmodifiableList(propertyFilters); - LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " + - immutablePropertyFilters); - propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class); - if(propertyValueCombinationPolicy==null) { - propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR; - } - LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy); - } - - DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) { - List propertySources = new ArrayList<>(); - // first we load all PropertySources which got registered via java.util.ServiceLoader - propertySources.addAll(builder.propertySources.values()); - // now sort them according to their ordinal values - Collections.sort(propertySources, propertySourceComparator); - immutablePropertySources = Collections.unmodifiableList(propertySources); - LOG.info("Registered " + immutablePropertySources.size() + " property sources: " + - immutablePropertySources); - - // as next step we pick up the PropertyFilters pretty much the same way - List propertyFilters = new ArrayList<>(); - propertyFilters.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)); - Collections.sort(propertyFilters, propertyFilterComparator); - immutablePropertyFilters = Collections.unmodifiableList(propertyFilters); - LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " + - immutablePropertyFilters); - - propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class); - if(propertyValueCombinationPolicy==null){ - propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR; - } - LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy); - } - - - - /** - * Pick up all {@link PropertySourceProvider}s and return all the - * {@link PropertySource}s they like to register. - */ - private Collection evaluatePropertySourcesFromProviders() { - List propertySources = new ArrayList<>(); - Collection propertySourceProviders = ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class); - for (PropertySourceProvider propertySourceProvider : propertySourceProviders) { - Collection sources = propertySourceProvider.getPropertySources(); - LOG.finer("PropertySourceProvider " + propertySourceProvider.getClass().getName() + - " provided the following property sources: " + sources); - propertySources.addAll(sources); - } - - return propertySources; - } - - @Override - public void addPropertySources(PropertySource... propertySourcesToAdd) { - Lock writeLock = propertySourceLock.writeLock(); - try { - writeLock.lock(); - List newPropertySources = new ArrayList<>(this.immutablePropertySources); - newPropertySources.addAll(Arrays.asList(propertySourcesToAdd)); - Collections.sort(newPropertySources, new PropertySourceComparator()); - - this.immutablePropertySources = Collections.unmodifiableList(newPropertySources); - } finally { - writeLock.unlock(); - } - } - - private static class PropertySourceComparator implements Comparator, Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Order property source reversely, the most important come first. - * - * @param source1 the first PropertySource - * @param source2 the second PropertySource - * @return the comparison result. - */ - private int comparePropertySources(PropertySource source1, PropertySource source2) { - if (source1.getOrdinal() < source2.getOrdinal()) { - return -1; - } else if (source1.getOrdinal() > source2.getOrdinal()) { - return 1; - } else { - return source1.getClass().getName().compareTo(source2.getClass().getName()); - } - } - - @Override - public int compare(PropertySource source1, PropertySource source2) { - return comparePropertySources(source1, source2); - } - } - - private static class PropertyFilterComparator implements Comparator, Serializable{ - - private static final long serialVersionUID = 1L; - - /** - * Compare 2 filters for ordering the filter chain. - * - * @param filter1 the first filter - * @param filter2 the second filter - * @return the comparison result - */ - private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) { - Priority prio1 = filter1.getClass().getAnnotation(Priority.class); - Priority prio2 = filter2.getClass().getAnnotation(Priority.class); - int ord1 = prio1 != null ? prio1.value() : 0; - int ord2 = prio2 != null ? prio2.value() : 0; - - if (ord1 < ord2) { - return -1; - } else if (ord1 > ord2) { - return 1; - } else { - return filter1.getClass().getName().compareTo(filter2.getClass().getName()); - } - } - - @Override - public int compare(PropertyFilter filter1, PropertyFilter filter2) { - return comparePropertyFilters(filter1, filter2); - } - } - - @Override - public List getPropertySources() { - return immutablePropertySources; - } - - @Override - public void addPropertyConverter(TypeLiteral typeToConvert, PropertyConverter propertyConverter) { - propertyConverterManager.register(typeToConvert, propertyConverter); - LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName()); - } - - @Override - public Map, List>> getPropertyConverters() { - return propertyConverterManager.getPropertyConverters(); - } - - @Override - public List> getPropertyConverters(TypeLiteral targetType) { - return propertyConverterManager.getPropertyConverters(targetType); - } - - @Override - public List getPropertyFilters() { - return immutablePropertyFilters; - } - - @Override - public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){ - return propertyValueCombinationPolicy; - } - - @Override - public ConfigurationContextBuilder toBuilder() { - return ConfigurationProvider.getConfigurationContextBuilder().setContext(this); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java b/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java deleted file mode 100644 index 407c881..0000000 --- a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java +++ /dev/null @@ -1,152 +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.integration.cdi.internal; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.ConfigurationContextBuilder; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValueCombinationPolicy; - -import javax.enterprise.inject.Vetoed; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * Default implementation of {@link ConfigurationContextBuilder}. - */ -@Vetoed -public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder { - - Map propertySources = new HashMap<>(); - List propertyFilters = new ArrayList<>(); - Map, List>> propertyConverters = new HashMap<>(); - PropertyValueCombinationPolicy combinationPolicy; - - @Override - public ConfigurationContextBuilder setContext(ConfigurationContext context) { - this.propertySources.clear(); - for(PropertySource ps:context.getPropertySources()) { - this.propertySources.put(ps.getName(), ps); - } - this.propertyFilters.clear(); - this.propertyFilters.addAll(context.getPropertyFilters()); - this.propertyConverters.clear(); - this.propertyConverters.putAll(context.getPropertyConverters()); - this.combinationPolicy = context.getPropertyValueCombinationPolicy(); - return this; - } - - @Override - public ConfigurationContextBuilder addPropertySources(Collection propertySourcesToAdd) { - for(PropertySource ps:propertySourcesToAdd){ - if(this.propertySources.containsKey(ps.getName())){ - throw new ConfigException("Duplicate PropertySource: " + ps.getName()); - } - } - for(PropertySource ps:propertySourcesToAdd) { - this.propertySources.put(ps.getName(), ps); - } - return this; - } - - @Override - public ConfigurationContextBuilder addPropertySources(PropertySource... propertySourcesToAdd) { - return addPropertySources(Arrays.asList(propertySourcesToAdd)); - } - - @Override - public ConfigurationContextBuilder removePropertySources(Collection propertySourcesToRemove) { - for(String key: propertySourcesToRemove){ - this.propertySources.remove(key); - } - return this; - } - - @Override - public ConfigurationContextBuilder removePropertySources(String... propertySourcesToRemove) { - return removePropertySources(Arrays.asList(propertySourcesToRemove)); - } - - @Override - public ConfigurationContextBuilder addPropertyFilters(Collection filters) { - this.propertyFilters.addAll(filters); - return this; - } - - @Override - public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters) { - return addPropertyFilters(Arrays.asList(filters)); - } - - @Override - public ConfigurationContextBuilder removePropertyFilters(Collection filters) { - this.propertyFilters.removeAll(filters); - return this; - } - - @Override - public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) { - return removePropertyFilters(Arrays.asList(filters)); - } - - @Override - public ConfigurationContextBuilder addPropertyConverter(TypeLiteral typeToConvert, PropertyConverter propertyConverter) { - List> converters = this.propertyConverters.get(typeToConvert); - if(converters==null){ - converters = new ArrayList<>(); - this.propertyConverters.put(typeToConvert, converters); - } - return this; - } - - @Override - public ConfigurationContextBuilder removePropertyConverters(TypeLiteral typeToConvert, PropertyConverter... converters) { - return removePropertyConverters(typeToConvert, Arrays.asList(converters)); - } - - @Override - public ConfigurationContextBuilder removePropertyConverters(TypeLiteral typeToConvert, Collection> converters) { - List> existing = this.propertyConverters.get(typeToConvert); - if(existing!=null) { - existing.removeAll(converters); - } - return this; - } - - @Override - public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) { - this.combinationPolicy = Objects.requireNonNull(policy); - return this; - } - - @Override - public ConfigurationContext build() { - return new DefaultConfigurationContext(this); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0f3bae97/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java b/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java deleted file mode 100644 index 4587b18..0000000 --- a/sandbox/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.integration.cdi.internal; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.spi.PropertyConverter; - -import javax.enterprise.inject.Vetoed; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Locale; -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Converter, converting from String to tge given enum type. - */ -@Vetoed -public class EnumConverter implements PropertyConverter { - private Logger LOG = Logger.getLogger(EnumConverter.class.getName()); - private Class enumType; - private Method factory; - - public EnumConverter(Class enumType) { - if (!Enum.class.isAssignableFrom(enumType)) { - throw new IllegalArgumentException("Not an Enum: " + enumType.getName()); - } - this.enumType = Objects.requireNonNull(enumType); - try { - this.factory = enumType.getMethod("valueOf", String.class); - } catch (NoSuchMethodException e) { - throw new ConfigException("Uncovertible enum type without valueOf method found, please provide a custom " + - "PropertyConverter for: " + enumType.getName()); - } - } - - @Override - public T convert(String value) { - try { - return (T) factory.invoke(null, value); - } catch (InvocationTargetException | IllegalAccessException e) { - LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e); - } - try { - return (T) factory.invoke(null, value.toUpperCase(Locale.ENGLISH)); - } catch (InvocationTargetException | IllegalAccessException e) { - LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e); - } - return null; - } -}