You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/10/12 08:02:56 UTC
[01/13] incubator-tamaya git commit: TAMAYA-114: Fixed potential NPE
for getOrdinal().
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 8c7444784 -> 04b3fc5ec
TAMAYA-114: Fixed potential NPE for getOrdinal().
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bb062685
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bb062685
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bb062685
Branch: refs/heads/master
Commit: bb06268543432ad73a9b9bb99402a7ebfa890848
Parents: 4383a45
Author: anatole <an...@apache.org>
Authored: Wed Oct 7 22:16:35 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:46 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/spisupport/MapPropertySource.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb062685/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
index f447aea..ada292a 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
@@ -129,7 +129,10 @@ public class MapPropertySource extends BasePropertySource {
@Override
public int getOrdinal() {
- return priority;
+ if(priority!=null) {
+ return priority;
+ }
+ return super.getOrdinal();
}
@Override
[13/13] incubator-tamaya git commit: TAMAYA-116: CHeckstyle fixes for
cdi module (new).
Posted by an...@apache.org.
TAMAYA-116: CHeckstyle fixes for cdi module (new).
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/04b3fc5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/04b3fc5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/04b3fc5e
Branch: refs/heads/master
Commit: 04b3fc5ece0efe465e78b84ac09cab279b32141a
Parents: 7a32a1a
Author: anatole <an...@apache.org>
Authored: Mon Oct 12 08:01:23 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:02:10 2015 +0200
----------------------------------------------------------------------
modules/integration/cdi-se/pom.xml | 199 +++++++++
.../cdi/config/ConfiguredVetoExtension.java | 42 ++
.../cdi/internal/CDIAwareServiceContext.java | 168 ++++++++
.../internal/DefaultConfigurationContext.java | 285 +++++++++++++
.../DefaultConfigurationContextBuilder.java | 152 +++++++
.../integration/cdi/internal/EnumConverter.java | 69 +++
.../cdi/internal/PropertyConverterManager.java | 421 +++++++++++++++++++
.../cdi/internal/SEInjectorCDIExtension.java | 90 ++++
.../cdi/internal/TamayaCDIIntegration.java | 52 +++
.../cdi/internal/TamayaConfigProvider.java | 54 +++
.../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 ++++
.../src/test/resources/META-INF/beans.xml | 24 ++
modules/integration/cdi/pom.xml | 207 +++++++++
.../tamaya/integration/cdi/ConfigDefault.java | 41 ++
.../integration/cdi/ConfigDefaultSections.java | 43 ++
.../tamaya/integration/cdi/ConfigProperty.java | 80 ++++
.../integration/cdi/ConfigurationExtension.java | 258 ++++++++++++
.../integration/cdi/ConfigurationProducer.java | 117 ++++++
.../integration/cdi/WithConfigOperator.java | 44 ++
.../integration/cdi/WithPropertyConverter.java | 45 ++
.../tamaya/integration/cdi2/ConfigDefault.java | 41 --
.../integration/cdi2/ConfigDefaultSections.java | 43 --
.../tamaya/integration/cdi2/ConfigProperty.java | 80 ----
.../cdi2/ConfigurationExtension.java | 257 -----------
.../integration/cdi2/ConfigurationProducer.java | 115 -----
.../integration/cdi2/WithConfigOperator.java | 45 --
.../integration/cdi2/WithPropertyConverter.java | 45 --
.../cdi/src/main/resources/META-INF/beans.xml | 18 +
.../javax.enterprise.inject.spi.Extension | 20 +-
...onfigurationProducerFailedInjectionTest.java | 33 ++
.../cdi/ConfigurationProducerTest.java | 175 ++++++++
.../cdi/ConfigurationResolverTest.java | 112 +++++
.../integration/cdi/EnvironmentsTest.java | 83 ++++
.../integration/cdi/InterpolationTest.java | 62 +++
.../integration/cdi/NotFoundNoDefault.java | 77 ++++
.../cdi/src/test/resources/META-INF/beans.xml | 19 +
.../META-INF/javaconfiguration.properties | 18 +
.../cdi/src/test/resources/base.properties | 32 ++
.../cdi/src/test/resources/cert.properties | 20 +
.../cdi/src/test/resources/dev.properties | 19 +
.../cdi/src/test/resources/prod.properties | 20 +
.../cdi/src/test/resources/qa.properties | 20 +
.../cdi/src/test/resources/test.properties | 20 +
.../org.apache.tamaya.store.PropertyStore | 19 +
52 files changed, 3680 insertions(+), 627 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/pom.xml b/modules/integration/cdi-se/pom.xml
new file mode 100644
index 0000000..88e9690
--- /dev/null
+++ b/modules/integration/cdi-se/pom.xml
@@ -0,0 +1,199 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-integration</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tamaya-cdi-se</artifactId>
+ <name>Apache Tamaya Modules Integration - CDI (Using SE Injection)</name>
+
+ <properties>
+ <owb.version>1.6.2</owb.version>
+ <weld.version>2.2.7.Final</weld.version>
+ <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version>
+ <geronimo-interceptor-1.2-spec.version>1.0</geronimo-interceptor-1.2-spec.version>
+ <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version>
+ <bval.version>0.5</bval.version>
+ <ds.version>1.1.0</ds.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-classloader-support</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+ <version>${geronimo-jcdi-1.1-spec.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.modules</groupId>
+ <artifactId>deltaspike-test-control-module-api</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.modules</groupId>
+ <artifactId>deltaspike-test-control-module-impl</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>OWB</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <!-- OWB specific dependencies-->
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>${geronimo-atinject-1.0-spec.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+ <version>${geronimo-interceptor-1.2-spec.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <version>1.0.MR2-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-el_2.2_spec</artifactId>
+ <version>1.0.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-impl</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-spi</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-resource</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.bval</groupId>
+ <artifactId>bval-jsr303</artifactId>
+ <version>${bval.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-owb</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>Weld</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.se</groupId>
+ <artifactId>weld-se</artifactId>
+ <version>${weld.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-weld</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java
new file mode 100644
index 0000000..f90998d
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/config/ConfiguredVetoExtension.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.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/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java
new file mode 100644
index 0000000..ee069eb
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/CDIAwareServiceContext.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * 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.<p/>
+ * 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.<p/>
+ * 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<Class<?>, Object> singletons = new ConcurrentHashMap<>();
+
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ Object cached = singletons.get(serviceType);
+ if (cached == null) {
+ Collection<T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = null;
+ } else {
+ cached = getServiceWithHighestPriority(services, serviceType);
+ }
+ if(cached!=null) {
+ singletons.put(serviceType, cached);
+ }
+ }
+ return serviceType.cast(cached);
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param <T> the concrete type.
+ * @param serviceType The service type.
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<T> getServices(final Class<T> serviceType) {
+ List<T> found = (List<T>) clAwareServiceContext.getServices(serviceType);
+ BeanManager beanManager = TamayaCDIIntegration.getBeanManager();
+ Instance<T> cdiInstances = null;
+ if(beanManager!=null){
+ Set<Bean<?>> instanceBeans = beanManager.getBeans(Instance.class);
+ cdiInstances = (Instance<T>)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 <T> type of the service
+ *
+ * @return the service with the highest {@link javax.annotation.Priority#value()}
+ *
+ * @throws ConfigException if there are multiple service implementations with the maximum priority
+ */
+ private <T> T getServiceWithHighestPriority(Collection<T> services, Class<T> serviceType) {
+
+ // we do not need the priority stuff if the list contains only one element
+ if (services.size() == 1) {
+ return services.iterator().next();
+ }
+
+ Integer highestPriority = null;
+ int highestPriorityServiceCount = 0;
+ T highestService = null;
+
+ for (T service : services) {
+ int prio = getPriority(service);
+ if (highestPriority == null || highestPriority < prio) {
+ highestService = service;
+ highestPriorityServiceCount = 1;
+ highestPriority = prio;
+ } else if (highestPriority == prio) {
+ highestPriorityServiceCount++;
+ }
+ }
+
+ if (highestPriorityServiceCount > 1) {
+ throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}",
+ highestPriorityServiceCount,
+ serviceType.getName(),
+ highestPriority,
+ services));
+ }
+
+ return highestService;
+ }
+
+ /**
+ * 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/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java
new file mode 100644
index 0000000..c7bf107
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContext.java
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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<PropertySource> immutablePropertySources;
+
+ /**
+ * The current unmodifiable list of loaded {@link PropertyFilter} instances.
+ */
+ private List<PropertyFilter> immutablePropertyFilters;
+
+ /**
+ * The overriding policy used when combining PropertySources registered to evalute the final configuration
+ * values.
+ */
+ private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+
+ /** Comparator used for ordering property sources. */
+ private final PropertySourceComparator propertySourceComparator = new PropertySourceComparator();
+
+ /** Comparator used for ordering property filters. */
+ private final PropertyFilterComparator propertyFilterComparator = new PropertyFilterComparator();
+
+
+ /**
+ * The first time the Configuration system gets invoked we do initialize
+ * all our {@link PropertySource}s and
+ * {@link PropertyFilter}s which are known at startup.
+ */
+ public DefaultConfigurationContext() {
+ List<PropertySource> propertySources = new ArrayList<>();
+
+ // first we load all PropertySources which got registered via java.util.ServiceLoader
+ propertySources.addAll(ServiceContextManager.getServiceContext().getServices(PropertySource.class));
+
+ // after that we add all PropertySources which get dynamically registered via their PropertySourceProviders
+ propertySources.addAll(evaluatePropertySourcesFromProviders());
+
+ // now sort them according to their ordinal values
+ Collections.sort(propertySources, new PropertySourceComparator());
+
+ immutablePropertySources = Collections.unmodifiableList(propertySources);
+ LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
+ immutablePropertySources);
+
+ // as next step we pick up the PropertyFilters pretty much the same way
+ List<PropertyFilter> propertyFilters = new ArrayList<>();
+ propertyFilters.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class));
+ Collections.sort(propertyFilters, new PropertyFilterComparator());
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
+ immutablePropertyFilters);
+
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
+ immutablePropertyFilters);
+ propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
+ if(propertyValueCombinationPolicy==null) {
+ propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+ }
+ LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
+ }
+
+ DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
+ List<PropertySource> propertySources = new ArrayList<>();
+ // first we load all PropertySources which got registered via java.util.ServiceLoader
+ propertySources.addAll(builder.propertySources.values());
+ // now sort them according to their ordinal values
+ Collections.sort(propertySources, propertySourceComparator);
+ immutablePropertySources = Collections.unmodifiableList(propertySources);
+ LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
+ immutablePropertySources);
+
+ // as next step we pick up the PropertyFilters pretty much the same way
+ List<PropertyFilter> propertyFilters = new ArrayList<>();
+ propertyFilters.addAll(ServiceContextManager.getServiceContext().getServices(PropertyFilter.class));
+ Collections.sort(propertyFilters, propertyFilterComparator);
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
+ immutablePropertyFilters);
+
+ propertyValueCombinationPolicy = 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<? extends PropertySource> evaluatePropertySourcesFromProviders() {
+ List<PropertySource> propertySources = new ArrayList<>();
+ Collection<PropertySourceProvider> propertySourceProviders = ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class);
+ for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
+ Collection<PropertySource> sources = propertySourceProvider.getPropertySources();
+ LOG.finer("PropertySourceProvider " + propertySourceProvider.getClass().getName() +
+ " provided the following property sources: " + sources);
+ propertySources.addAll(sources);
+ }
+
+ return propertySources;
+ }
+
+ @Override
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ Lock writeLock = propertySourceLock.writeLock();
+ try {
+ writeLock.lock();
+ List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
+ newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
+ Collections.sort(newPropertySources, new PropertySourceComparator());
+
+ this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Comparator used for ordering PropertySources.
+ */
+ private static class PropertySourceComparator implements Comparator<PropertySource>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Order property source reversely, the most important come first.
+ *
+ * @param source1 the first PropertySource
+ * @param source2 the second PropertySource
+ * @return the comparison result.
+ */
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+ if (source1.getOrdinal() < source2.getOrdinal()) {
+ return -1;
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
+ return 1;
+ } else {
+ return source1.getClass().getName().compareTo(source2.getClass().getName());
+ }
+ }
+
+ @Override
+ public int compare(PropertySource source1, PropertySource source2) {
+ return comparePropertySources(source1, source2);
+ }
+ }
+
+ /**
+ * Comparator used for ordering PropertyFilters.
+ */
+ private static class PropertyFilterComparator implements Comparator<PropertyFilter>, Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Compare 2 filters for ordering the filter chain.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return the comparison result
+ */
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
+ Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
+ Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+
+ if (ord1 < ord2) {
+ return -1;
+ } else if (ord1 > ord2) {
+ return 1;
+ } else {
+ return filter1.getClass().getName().compareTo(filter2.getClass().getName());
+ }
+ }
+
+ @Override
+ public int compare(PropertyFilter filter1, PropertyFilter filter2) {
+ return comparePropertyFilters(filter1, filter2);
+ }
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return immutablePropertySources;
+ }
+
+ @Override
+ public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return immutablePropertyFilters;
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
+ return propertyValueCombinationPolicy;
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ return ConfigurationProvider.getConfigurationContextBuilder().setContext(this);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java
new file mode 100644
index 0000000..407c881
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/DefaultConfigurationContextBuilder.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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<String, PropertySource> propertySources = new HashMap<>();
+ List<PropertyFilter> propertyFilters = new ArrayList<>();
+ Map<TypeLiteral<?>, List<PropertyConverter<?>>> 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<PropertySource> propertySourcesToAdd) {
+ for(PropertySource ps:propertySourcesToAdd){
+ if(this.propertySources.containsKey(ps.getName())){
+ throw new ConfigException("Duplicate PropertySource: " + ps.getName());
+ }
+ }
+ for(PropertySource ps:propertySourcesToAdd) {
+ this.propertySources.put(ps.getName(), ps);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertySources(PropertySource... propertySourcesToAdd) {
+ return addPropertySources(Arrays.asList(propertySourcesToAdd));
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertySources(Collection<String> propertySourcesToRemove) {
+ for(String key: propertySourcesToRemove){
+ this.propertySources.remove(key);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertySources(String... propertySourcesToRemove) {
+ return removePropertySources(Arrays.asList(propertySourcesToRemove));
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters) {
+ this.propertyFilters.addAll(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters) {
+ return addPropertyFilters(Arrays.asList(filters));
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
+ this.propertyFilters.removeAll(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) {
+ return removePropertyFilters(Arrays.asList(filters));
+ }
+
+ @Override
+ public <T> ConfigurationContextBuilder addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ List<PropertyConverter<?>> converters = this.propertyConverters.get(typeToConvert);
+ if(converters==null){
+ converters = new ArrayList<>();
+ this.propertyConverters.put(typeToConvert, converters);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, PropertyConverter<?>... converters) {
+ return removePropertyConverters(typeToConvert, Arrays.asList(converters));
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert, Collection<PropertyConverter<?>> converters) {
+ List<PropertyConverter<?>> existing = this.propertyConverters.get(typeToConvert);
+ if(existing!=null) {
+ existing.removeAll(converters);
+ }
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
+ this.combinationPolicy = Objects.requireNonNull(policy);
+ return this;
+ }
+
+ @Override
+ public ConfigurationContext build() {
+ return new DefaultConfigurationContext(this);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java
new file mode 100644
index 0000000..5b96044
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/EnumConverter.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.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.
+ * @param <T> the enum type.
+ */
+@Vetoed
+public class EnumConverter<T> implements PropertyConverter<T> {
+ private Logger LOG = Logger.getLogger(EnumConverter.class.getName());
+ private Class<T> enumType;
+ private Method factory;
+
+ public EnumConverter(Class<T> enumType) {
+ if (!Enum.class.isAssignableFrom(enumType)) {
+ throw new IllegalArgumentException("Not an Enum: " + enumType.getName());
+ }
+ this.enumType = Objects.requireNonNull(enumType);
+ try {
+ this.factory = enumType.getMethod("valueOf", String.class);
+ } catch (NoSuchMethodException e) {
+ throw new ConfigException("Uncovertible enum type without valueOf method found, please provide a custom " +
+ "PropertyConverter for: " + enumType.getName());
+ }
+ }
+
+ @Override
+ public T convert(String value) {
+ try {
+ return (T) factory.invoke(null, value);
+ } catch (InvocationTargetException | IllegalAccessException e) {
+ LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
+ }
+ try {
+ return (T) factory.invoke(null, value.toUpperCase(Locale.ENGLISH));
+ } catch (InvocationTargetException | IllegalAccessException e) {
+ LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/PropertyConverterManager.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/PropertyConverterManager.java
new file mode 100644
index 0000000..8a78548
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/PropertyConverterManager.java
@@ -0,0 +1,421 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.PropertyConverter;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.enterprise.inject.Vetoed;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.logging.Logger;
+
+/**
+ * Manager that deals with {@link PropertyConverter} instances.
+ * This class is thread-safe.
+ */
+@Vetoed
+public class PropertyConverterManager {
+ /**
+ * The logger used.
+ */
+ private static final Logger LOG = Logger.getLogger(PropertyConverterManager.class.getName());
+ /**
+ * The registered converters.
+ */
+ private Map<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ /**
+ * The transitive converters.
+ */
+ private Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>();
+ /**
+ * The lock used.
+ */
+ private ReadWriteLock lock = new ReentrantReadWriteLock();
+
+ private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() {
+
+ @Override
+ public int compare(Object o1, Object o2) {
+ int prio = CDIAwareServiceContext.getPriority(o1) - CDIAwareServiceContext.getPriority(o2);
+ if (prio < 0) {
+ return 1;
+ } else if (prio > 0) {
+ return -1;
+ } else {
+ return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
+ }
+ }
+ };
+
+ /**
+ * Constructor.
+ */
+ public PropertyConverterManager() {
+ initConverters();
+ }
+
+ /**
+ * Registers the default converters provided out of the box.
+ */
+ protected void initConverters() {
+ for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
+ register(TypeLiteral.of(type), conv);
+ }
+ }
+
+ /**
+ * Registers a ew converter instance.
+ *
+ * @param targetType the target type, not null.
+ * @param converter the converter, not null.
+ * @param <T> the type.
+ */
+ public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
+ Objects.requireNonNull(converter);
+ Lock writeLock = lock.writeLock();
+ try {
+ writeLock.lock();
+ List converters = List.class.cast(this.converters.get(targetType));
+ List<PropertyConverter<?>> newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.converters.put(targetType, Collections.unmodifiableList(newConverters));
+ // evaluate transitive closure for all inherited supertypes and implemented interfaces
+ // direct implemented interfaces
+ for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
+ }
+ Class<?> superClass = targetType.getRawType().getSuperclass();
+ while (superClass != null && !superClass.equals(Object.class)) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
+ for (Class<?> ifaceType : superClass.getInterfaces()) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
+ }
+ superClass = superClass.getSuperclass();
+ }
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Allows to evaluate if a given target type is supported.
+ *
+ * @param targetType the target type, not null.
+ * @return true, if a converter for the given type is registered, or a default one can be created.
+ */
+ public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
+ if (converters.containsKey(targetType) || transitiveConverters.containsKey(targetType)) {
+ return true;
+ }
+ return createDefaultPropertyConverter(targetType) != null;
+ }
+
+ /**
+ * Get a map of all property converters currently registered. This will not contain the converters that
+ * may be created, when an instance is adapted, which provides a String constructor or compatible
+ * factory methods taking a single String instance.
+ *
+ * @return the current map of instantiated and registered converters.
+ * @see #createDefaultPropertyConverter(TypeLiteral)
+ */
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ Lock readLock = lock.readLock();
+ try {
+ readLock.lock();
+ return new HashMap<>(this.converters);
+ } finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * Get the list of all current registered converters for the given target type.
+ * If not converters are registered, they component tries to create and register a dynamic
+ * converter based on String costructor or static factory methods available.<br/>
+ * The converters provided are of the following type and returned in the following order:
+ * <ul>
+ * <li>Converters mapped explicitly to the required target type are returned first, ordered
+ * by decreasing priority. This means, if explicit converters are registered these are used
+ * primarly for converting a value.</li>
+ * <li>The target type of each explicitly registered converter also can be transitively mapped to
+ * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces
+ * implemented by its superclasses. These groups of transitive converters is returned similarly in the
+ * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li>
+ * <li>java.lang wrapper classes and native types are automatically mapped.</li>
+ * <li>If no explicit converters are registered, for Enum types a default implementation is provided that
+ * compares the configuration values with the different enum members defined (cases sensitive mapping).</li>
+ * </ul>
+ *
+ * So given that list above directly registered mappings always are tried first, before any transitive mapping
+ * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place.
+ * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and
+ * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored.
+ *
+ *
+ * @param targetType the target type, not null.
+ * @param <T> the type class
+ * @return the ordered list of converters (may be empty for not convertible types).
+ * @see #createDefaultPropertyConverter(TypeLiteral)
+ */
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ Lock readLock = lock.readLock();
+ List<PropertyConverter<T>> converterList = new ArrayList<>();
+ List<PropertyConverter<T>> converters;
+ // direct mapped converters
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ // transitive converter
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.transitiveConverters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ // handling of java.lang wrapper classes
+ TypeLiteral<T> boxedType = mapBoxedType(targetType);
+ if (boxedType != null) {
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(boxedType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ }
+ if (converterList.isEmpty()) {
+ // adding any converters created on the fly, e.g. for enum types.
+ PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
+ if (defaultConverter != null) {
+ register(targetType, defaultConverter);
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ }
+ if (converters != null) {
+ converterList.addAll(converters);
+ }
+ }
+ return converterList;
+ }
+
+ /**
+ * Maps native types to the corresponding boxed types.
+ *
+ * @param targetType the native type.
+ * @param <T> the type
+ * @return the boxed type, or null.
+ */
+ private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
+ Type parameterType = targetType.getType();
+ if (parameterType == int.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Integer.class));
+ }
+ if (parameterType == short.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Short.class));
+ }
+ if (parameterType == byte.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Byte.class));
+ }
+ if (parameterType == long.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Long.class));
+ }
+ if (parameterType == boolean.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
+ }
+ if (parameterType == char.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Character.class));
+ }
+ if (parameterType == float.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Float.class));
+ }
+ if (parameterType == double.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Double.class));
+ }
+ if (parameterType == int[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class));
+ }
+ if (parameterType == short[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Short[].class));
+ }
+ if (parameterType == byte[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class));
+ }
+ if (parameterType == long[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
+ }
+ if (parameterType == boolean.class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
+ }
+ if (parameterType == char[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));
+ }
+ if (parameterType == float[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Float[].class));
+ }
+ if (parameterType == double[].class) {
+ return TypeLiteral.class.cast(TypeLiteral.of(Double[].class));
+ }
+ return null;
+ }
+
+ /**
+ * Creates a dynamic PropertyConverter for the given target type.
+ *
+ * @param targetType the target type
+ * @param <T> the type class
+ * @return a new converter, or null.
+ */
+ protected <T> PropertyConverter<T> createDefaultPropertyConverter(final TypeLiteral<T> targetType) {
+ if (Enum.class.isAssignableFrom(targetType.getRawType())) {
+ return new EnumConverter<T>(targetType.getRawType());
+ }
+ PropertyConverter<T> converter = null;
+ final Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
+ if (factoryMethod != null) {
+ converter = new PropertyConverter<T>() {
+ @Override
+ public T convert(String value) {
+ try {
+ if (!Modifier.isStatic(factoryMethod.getModifiers())) {
+ throw new ConfigException(factoryMethod.toGenericString() +
+ " is not a static method. Only static " +
+ "methods can be used as factory methods.");
+ }
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ factoryMethod.setAccessible(true);
+ return null;
+ }
+ });
+ Object invoke = factoryMethod.invoke(null, value);
+ return targetType.getRawType().cast(invoke);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + value + "'", e);
+ }
+ }
+ };
+ }
+ if (converter == null) {
+ try {
+ final Constructor<T> constr = targetType.getRawType().getDeclaredConstructor(String.class);
+ converter = new PropertyConverter<T>() {
+ @Override
+ public T convert(String value) {
+ try {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
+ public Object run() {
+ constr.setAccessible(true);
+ return null;
+ }
+ });
+ return constr.newInstance(value);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + value + "'", e);
+ }
+ }
+ };
+ } catch (Exception e) {
+ LOG.finest("Failed to construct instance of type: " + targetType.getRawType().getName() + ": " + e);
+ }
+ }
+ return converter;
+ }
+
+ /**
+ * Tries to evaluate a factory method that can be used to create an instance based on a String.
+ *
+ * @param type the target type
+ * @param methodNames the possible static method names
+ * @return the first method found, or null.
+ */
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for (String name : methodNames) {
+ try {
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ } catch (NoSuchMethodException | RuntimeException e) {
+ LOG.finest("No such factory method found on type: " + type.getName() + ", methodName: " + name);
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/SEInjectorCDIExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/SEInjectorCDIExtension.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/SEInjectorCDIExtension.java
new file mode 100644
index 0000000..cc253d9
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/SEInjectorCDIExtension.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.inject.ConfigurationInjection;
+import org.apache.tamaya.inject.internal.ConfiguredType;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Vetoed;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+import java.util.Set;
+
+/**
+ * CDI portable extension that integrates {@link org.apache.tamaya.inject.ConfigurationInjector}
+ * with CDI by adding configuration features to CDI (config enable CDI beans).
+ */
+@Vetoed
+public final class SEInjectorCDIExtension implements Extension {
+
+ /**
+ * Method that injects the values into any configured fields, by wrapping the given
+ * InjectionTarget.
+ * @param pit the injection target
+ * @param <T> the target type
+ */
+ public <T> void initializeConfiguredFields(final @Observes ProcessInjectionTarget<T> pit) {
+ final AnnotatedType<T> at = pit.getAnnotatedType();
+ if (!ConfiguredType.isConfigured(at.getJavaClass())) {
+ return;
+ }
+ final InjectionTarget<T> it = pit.getInjectionTarget();
+ InjectionTarget<T> wrapped = new InjectionTarget<T>() {
+ @Override
+ public void inject(T instance, CreationalContext<T> ctx) {
+ it.inject(instance, ctx);
+ ConfigurationInjection.getConfigurationInjector().configure(instance);
+ }
+
+ @Override
+ public void postConstruct(T instance) {
+ it.postConstruct(instance);
+ }
+
+ @Override
+ public void preDestroy(T instance) {
+ it.dispose(instance);
+ }
+
+ @Override
+ public void dispose(T instance) {
+ it.dispose(instance);
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return it.getInjectionPoints();
+ }
+
+ @Override
+ public T produce(CreationalContext<T> ctx) {
+ return it.produce(ctx);
+ }
+ };
+ pit.setInjectionTarget(wrapped);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
new file mode 100644
index 0000000..4357242
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.integration.cdi.internal;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * Tamaya main integreation with CDI, storing the BeanManager reference for implementation, where no
+ * JNDI is available or {@code java:comp/env/BeanManager} is not set correctly.
+ */
+public class TamayaCDIIntegration implements Extension{
+ /** The BeanManager references stored. */
+ private static BeanManager beanManager;
+
+ /**
+ * Initializes the current BeanMaanager with the instance passed.
+ * @param validation the event
+ * @param beanManager the BeanManager instance
+ */
+ @SuppressWarnings("all")
+ public void initBeanManager(@Observes AfterDeploymentValidation validation, BeanManager beanManager){
+ TamayaCDIIntegration.beanManager = beanManager;
+ }
+
+ /**
+ * Get the current {@link BeanManager} instance.
+ * @return
+ */
+ public static BeanManager getBeanManager(){
+ return beanManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaConfigProvider.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaConfigProvider.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaConfigProvider.java
new file mode 100644
index 0000000..33251d7
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaConfigProvider.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.integration.cdi.internal;
+
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.DefaultConfiguration;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Singleton;
+
+/**
+ * Tamaya main integreation with CDI (singleton) serving producers for Configuration, ConfigurationContext and
+ * ConfigurationContextBuilder.
+ */
+@Singleton
+public class TamayaConfigProvider{
+
+ @Produces
+ @ApplicationScoped
+ public Configuration getConfiguration(ConfigurationContext context){
+ return new DefaultConfiguration(context);
+ }
+
+ @Produces @ApplicationScoped
+ public ConfigurationContext getConfigurationContext(){
+ return new DefaultConfigurationContext();
+ }
+
+ @Produces
+ public ConfigurationContextBuilder getConfigurationContextBuilder(){
+ return new DefaultConfigurationContextBuilder();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/resources/META-INF/beans.xml b/modules/integration/cdi-se/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..adee378
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy 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.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
+
+</beans>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/modules/integration/cdi-se/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..db6641d
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.integration.cdi.internal.TamayaCDIIntegration
+org.apache.tamaya.integration.cdi.internal.SEInjectorCDIExtension
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/modules/integration/cdi-se/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..5c501ee
--- /dev/null
+++ b/modules/integration/cdi-se/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.integration.cdi.internal.CDIAwareServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
new file mode 100644
index 0000000..29a55a1
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredClass.java
@@ -0,0 +1,124 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.integration.cdi;
+
+import java.beans.PropertyChangeEvent;
+import java.math.BigDecimal;
+
+import javax.inject.Singleton;
+
+import org.apache.tamaya.event.ObservesConfigChange;
+import org.apache.tamaya.inject.ConfigDefault;
+import org.apache.tamaya.inject.ConfigProperty;
+
+/**
+ * Class to be loaded from CDI to ensure fields are correctly configured using CDI injection mechanisms.
+ */
+@Singleton
+public class ConfiguredClass{
+
+ @ConfigProperty
+ private String testProperty;
+
+ @ConfigProperty(keys = {"a.b.c.key1","a.b.c.key2","a.b.c.key3"})
+ @ConfigDefault("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
+ String value1;
+
+ @ConfigProperty(keys = {"foo","a.b.c.key2"})
+ private String value2;
+
+ @ConfigProperty
+ @ConfigDefault("N/A")
+ private String runtimeVersion;
+
+ @ConfigProperty
+ @ConfigDefault("${sys:java.version}")
+ private String javaVersion2;
+
+ @ConfigProperty
+ @ConfigDefault("5")
+ private Integer int1;
+
+ @ConfigProperty
+ private int int2;
+
+ @ConfigProperty
+ private boolean booleanT;
+
+ @ConfigProperty(keys = "BD")
+ private BigDecimal bigNumber;
+
+ @ConfigProperty(keys = "double1")
+ private double doubleValue;
+
+ @ObservesConfigChange
+ public void changeListener1(PropertyChangeEvent configChange){
+ // will be called
+ }
+
+ public String getTestProperty() {
+ return testProperty;
+ }
+
+ public String getValue1() {
+ return value1;
+ }
+
+ public String getValue2() {
+ return value2;
+ }
+
+ public String getRuntimeVersion() {
+ return runtimeVersion;
+ }
+
+ public String getJavaVersion2() {
+ return javaVersion2;
+ }
+
+ public Integer getInt1() {
+ return int1;
+ }
+
+ public int getInt2() {
+ return int2;
+ }
+
+ public boolean isBooleanT() {
+ return booleanT;
+ }
+
+ public BigDecimal getBigNumber() {
+ return bigNumber;
+ }
+
+ public double getDoubleValue() {
+ return doubleValue;
+ }
+
+ @Override
+ public String toString(){
+ return super.toString() + ": testProperty="+testProperty+", value1="+value1+", value2="+value2
+ +", int1="+int1+", int2="+int2+", booleanT="+booleanT+", bigNumber="+bigNumber
+ +", runtimeVersion="+runtimeVersion+", javaVersion2="+javaVersion2;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredTest.java b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredTest.java
new file mode 100644
index 0000000..b0e85be
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/ConfiguredTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy 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.integration.cdi;
+
+import org.apache.deltaspike.testcontrol.api.TestControl;
+import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
+import org.hamcrest.MatcherAssert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.CDI;
+import javax.inject.Singleton;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for CDI integration.
+ */
+@RunWith(CdiTestRunner.class)
+@TestControl(startScopes = {ApplicationScoped.class, Singleton.class})
+public class ConfiguredTest{
+
+ @Test
+ public void test_Configuration_is_injected_correctly(){
+ ConfiguredClass item = CDI.current().select(ConfiguredClass.class).get();
+ System.out.println("********************************************");
+ System.out.println(item);
+ System.out.println("********************************************");
+
+ double actual = 1234.5678;
+
+ MatcherAssert.assertThat(item.getDoubleValue(), is(actual));
+ }
+
+ @Test
+ public void test_Default_injections_are_accessible(){
+ InjectedClass injectedClass = CDI.current().select(InjectedClass.class).get();
+ System.out.println("********************************************");
+ System.out.println(injectedClass);
+ System.out.println("********************************************");
+ assertNotNull(injectedClass.builder1);
+ assertNotNull(injectedClass.builder2);
+ assertNotNull(injectedClass.config);
+ assertNotNull(injectedClass.configContext);
+ }
+
+ @Test
+ public void test_Injected_builders_are_notSame(){
+ InjectedClass injectedClass = CDI.current().select(InjectedClass.class).get();
+ assertTrue(injectedClass.builder1 != injectedClass.builder2);
+ }
+
+ @Test
+ public void test_Injected_configs_are_same(){
+ InjectedClass injectedClass = CDI.current().select(InjectedClass.class).get();
+ assertTrue(injectedClass.config == injectedClass.config2);
+ }
+
+ @Test
+ public void test_Injected_configContexts_are_same(){
+ InjectedClass injectedClass = CDI.current().select(InjectedClass.class).get();
+ assertTrue(injectedClass.configContext == injectedClass.configContext2);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/InjectedClass.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/InjectedClass.java b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/InjectedClass.java
new file mode 100644
index 0000000..9b7bd23
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/InjectedClass.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy 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.integration.cdi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * Class loaded by CDI to test correct injection of Configuration API artifacts.
+ */
+@Singleton
+public class InjectedClass {
+
+ @Inject
+ Configuration config;
+
+ @Inject
+ Configuration config2;
+
+ @Inject
+ ConfigurationContext configContext;
+
+ @Inject
+ ConfigurationContext configContext2;
+
+ @Inject
+ ConfigurationContextBuilder builder1;
+
+ @Inject
+ ConfigurationContextBuilder builder2;
+
+ @Override
+ public String toString() {
+ return "InjectedClass{" +
+ "config=" + config +
+ ", configContext=" + configContext +
+ ", builder1=" + builder1 +
+ ", builder2=" + builder2 +
+ '}';
+ }
+}
[03/13] incubator-tamaya git commit: Added lots of docs,
some of them still WIP.
Posted by an...@apache.org.
Added lots of docs, some of them still WIP.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/2df75a8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/2df75a8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/2df75a8f
Branch: refs/heads/master
Commit: 2df75a8fa800ce380044c422e4b5114ae5b335f3
Parents: 1520152
Author: anatole <an...@apache.org>
Authored: Wed Oct 7 23:03:17 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:47 2015 +0200
----------------------------------------------------------------------
docs/src/main/asciidoc/mod_cdi-ee.adoc | 162 +++++++++++++++++++
docs/src/main/asciidoc/mod_cdi-se.adoc | 162 +++++++++++++++++++
docs/src/main/asciidoc/mod_cdi.adoc | 159 ------------------
docs/src/main/asciidoc/mod_environment.adoc | 75 +++++++++
.../src/main/asciidoc/mod_metamodel-staged.adoc | 94 +++++++++++
docs/src/main/asciidoc/mod_spi-support.adoc | 75 +++++++++
docs/src/main/asciidoc/modules.adoc | 5 +-
7 files changed, 572 insertions(+), 160 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/mod_cdi-ee.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_cdi-ee.adoc b/docs/src/main/asciidoc/mod_cdi-ee.adoc
new file mode 100644
index 0000000..6f2f7ad
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_cdi-ee.adoc
@@ -0,0 +1,162 @@
+= Apache Tamaya -- Extension: Classloader Isolation Support
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.integration.cdi
+:title: Apache Tamaya Extension: CDI Integration
+:revdate: September 2015
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Remote]]
+== Tamaya CDI Integration (Extension Module)
+=== Overview
+
+The Tamaya CDI Integration provides CDI extensions implementing the following functionality:
+
+* Loading of CDI managed components as configuration extensions such as +PropertySources, PropertySourceProvieders,
+ PropertyFilters, etc+.
+* Enable Configuration Injection similar to Tamaya's Java SE based configuration injection services, but implemented
+ as a portable, Java EE compliant CDI extension.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from Tamaya CDI integration you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-cdi</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+The component will auto-register its components and override the default +ServicceContext+ in use. Additionally it
+registers CDI extensions that implement Configuration injection based on Tamaya's +Configuration+ present in the
+system/runtime context.
+
+IMPORTANT: Dont install Tamaya's +cdi-se+ module at the same time.
+
+=== How it Works
+
+This module registers as +ServiceContext+ and integrates CDI for component loading as well as configuration injection.
+All types injected by this module are injected using _dependent scope_. So with this module you can define/deploy
+your +PropertySources+ and other artifacts simply by adding corresponding CDI managed beans:
+
+[source, java]
+--------------------------------------------------------
+@Singleton
+public class TestPropertySource implements PropertySource{
+
+ final Map<String,String> config = new HashMap<>();
+
+ public TestPropertySource(){
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("{"+getName()+"}source", getClass().getName());
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 10;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ return config.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return config;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
+--------------------------------------------------------
+
+The +ServiceContext+ implementation hereby combines the components registered using the +ServiceLoader+ mechanism
+hereby considering classloaser hierarchies.
+
+
+=== Injecting Configuration
+
+This component also allows to inject configuration using Tamaya's type-safe injection mechanism:
+
+[source, java]
+--------------------------------------------------------
+@RequestScoped
+public class ConfiguredClass{
+
+ @ConfigProperty
+ private String testProperty;
+
+ @ConfigProperty({"a.b.c.key1","a.b.c.key2","a.b.c.key3"})
+ @DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
+ String value1;
+
+ @ConfigProperty({"foo","a.b.c.key2"})
+ private String value2;
+
+ @ConfigProperty
+ @DefaultValue("N/A")
+ private String runtimeVersion;
+
+ @ConfigProperty
+ @DefaultValue("${sys:java.version}")
+ private String javaVersion2;
+
+ @ConfigProperty
+ @DefaultValue("5")
+ private Integer int1;
+
+ ...
+
+}
+--------------------------------------------------------
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/mod_cdi-se.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_cdi-se.adoc b/docs/src/main/asciidoc/mod_cdi-se.adoc
new file mode 100644
index 0000000..ed77848
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_cdi-se.adoc
@@ -0,0 +1,162 @@
+= Apache Tamaya -- Extension: Classloader Isolation Support
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.integration.cdi
+:title: Apache Tamaya Extension: CDI Integration of tamaya-injection (SE)
+:revdate: September 2015
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Remote]]
+== Tamaya CDI Integration of tamaya-injection (Extension Module)
+=== Overview
+
+The Tamaya CDI injection Integration provides CDI extensions implementing the following functionality:
+
+* Loading of CDI managed components as configuration extensions such as +PropertySources, PropertySourceProvieders,
+ PropertyFilters, etc+.
+* Enable Tamaya's Java SE based configuration injection services with CDI. As a consequence injection and config lifecycle is managed
+ by thos module and not the CDI context.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from Tamaya CDI integration you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-cdi-se</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+The component will auto-register its components and override the default +ServicceContext+ in use. Additionally it
+registers CDI extensions that implement Configuration injection based on Tamaya's +tamaya-injection+ and
++tamaya-classloader-support+ modules.
+
+IMPORTANT: Dont install Tamaya's +cdi+ at the same time.
+
+=== How it Works
+
+This module registers as +ServiceContext+ and integrates CDI for component loading as well as configuration injection.
+All types injected by this module are injected using _dependent scope_. So with this module you can define/deploy
+your +PropertySources+ and other artifacts simply by adding corresponding CDI managed beans:
+
+[source, java]
+--------------------------------------------------------
+@Singleton
+public class TestPropertySource implements PropertySource{
+
+ final Map<String,String> config = new HashMap<>();
+
+ public TestPropertySource(){
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("{"+getName()+"}source", getClass().getName());
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 10;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ return config.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return config;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
+--------------------------------------------------------
+
+The +ServiceContext+ implementation hereby combines the components registered using the +ServiceLoader+ mechanism
+hereby considering classloaser hierarchies.
+
+
+=== Injecting Configuration
+
+This component also allows to inject configuration using Tamaya's type-safe injection mechanism:
+
+[source, java]
+--------------------------------------------------------
+@RequestScoped
+public class ConfiguredClass{
+
+ @ConfigProperty
+ private String testProperty;
+
+ @ConfigProperty({"a.b.c.key1","a.b.c.key2","a.b.c.key3"})
+ @DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
+ String value1;
+
+ @ConfigProperty({"foo","a.b.c.key2"})
+ private String value2;
+
+ @ConfigProperty
+ @DefaultValue("N/A")
+ private String runtimeVersion;
+
+ @ConfigProperty
+ @DefaultValue("${sys:java.version}")
+ private String javaVersion2;
+
+ @ConfigProperty
+ @DefaultValue("5")
+ private Integer int1;
+
+ ...
+
+}
+--------------------------------------------------------
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/mod_cdi.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_cdi.adoc b/docs/src/main/asciidoc/mod_cdi.adoc
deleted file mode 100644
index b0c5074..0000000
--- a/docs/src/main/asciidoc/mod_cdi.adoc
+++ /dev/null
@@ -1,159 +0,0 @@
-= Apache Tamaya -- Extension: Classloader Isolation Support
-
-:name: Tamaya
-:rootpackage: org.apache.tamaya.integration.cdi
-:title: Apache Tamaya Extension: CDI Integration
-:revdate: September 2015
-:authorinitials: ATR
-:author: Anatole Tresch
-:email: <an...@apache.org>
-:source-highlighter: coderay
-:website: http://tamaya.incubator.apache.org/
-:toc:
-:toc-placement: manual
-:encoding: UTF-8
-:numbered:
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the 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.
-'''
-
-<<<
-
-toc::[]
-
-<<<
-:numbered!:
-<<<
-[[Remote]]
-== Tamaya CDI Integration (Extension Module)
-=== Overview
-
-The Tamaya CDI Integration provides CDI extensions implementing the following functionality:
-
-* Configuration of classes to be vetoed based on regular expressions of the fully qualified classnames.
-* Loading of CDI managed components as configuration extensions such as +PropertySources, PropertySourceProvieders,
- PropertyFilters, etc+.
-
-
-=== Compatibility
-
-The module is based on Java 7, so it will not run on Java 7 and beyond.
-
-
-=== Installation
-
-To benefit from Tamaya CDI integration you only must add the corresponding dependency to your module:
-
-[source, xml]
------------------------------------------------
-<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-cdi</artifactId>
- <version>{tamayaVersion}</version>
-</dependency>
------------------------------------------------
-
-The component will auto-register its components and override the default +ServicceContext+ in use. Additionally it
-registers CDI extensions that implement Configuration injection based on Tamaya's +tamaya-injection+ and
-+tamaya-classloader-support+ modules.
-
-=== How it Works
-
-This module registers as +ServiceContext+ and integrates CDI for component loading as well as configuration injection.
-All types injected by this module are injected using _dependent scope_. So with this module you can define/deploy
-your +PropertySources+ and other artifacts simply by adding corresponding CDI managed beans:
-
-[source, java]
---------------------------------------------------------
-@Singleton
-public class TestPropertySource implements PropertySource{
-
- final Map<String,String> config = new HashMap<>();
-
- public TestPropertySource(){
- config.put("a.b.c.key1", "keys current a.b.c.key1");
- config.put("a.b.c.key2", "keys current a.b.c.key2");
- config.put("{"+getName()+"}source", getClass().getName());
- }
-
- @Override
- public int getOrdinal() {
- return 10;
- }
-
- @Override
- public String getName() {
- return getClass().getName();
- }
-
- @Override
- public String get(String key) {
- return config.get(key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return config;
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-}
---------------------------------------------------------
-
-The +ServiceContext+ implementation hereby combines the components registered using the +ServiceLoader+ mechanism
-hereby considering classloaser hierarchies.
-
-
-=== Injecting Configuration
-
-This component also allows to inject configuration using Tamaya's type-safe injection mechanism:
-
-[source, java]
---------------------------------------------------------
-@RequestScoped
-public class ConfiguredClass{
-
- @ConfiguredProperty
- private String testProperty;
-
- @ConfiguredProperty(keys = {"a.b.c.key1","a.b.c.key2","a.b.c.key3"})
- @DefaultValue("The current \\${JAVA_HOME} env property is ${env:JAVA_HOME}.")
- String value1;
-
- @ConfiguredProperty(keys = {"foo","a.b.c.key2"})
- private String value2;
-
- @ConfiguredProperty
- @DefaultValue("N/A")
- private String runtimeVersion;
-
- @ConfiguredProperty
- @DefaultValue("${sys:java.version}")
- private String javaVersion2;
-
- @ConfiguredProperty
- @DefaultValue("5")
- private Integer int1;
-
- ...
-
-}
---------------------------------------------------------
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/mod_environment.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_environment.adoc b/docs/src/main/asciidoc/mod_environment.adoc
new file mode 100644
index 0000000..fd0393b
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_environment.adoc
@@ -0,0 +1,75 @@
+= Apache Tamaya -- Extension: Classloader Isolation Support
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.environment
+:title: Apache Tamaya Extension: Environment
+:revdate: September 2015
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Remote]]
+== Tamaya Environment Model (Extension Module)
+=== Overview
+
+The Tamaya Environment extension adds a simple PropertySourceProvider that evaluates a List of environment context and
+combines them in the given order into an (optional) root context within the system's configuration.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from Tamaya Environment Model you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-envionment</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== How it Works
+
+tbd
+
+=== Reusable Base Classes
+
+tbd
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/mod_metamodel-staged.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_metamodel-staged.adoc b/docs/src/main/asciidoc/mod_metamodel-staged.adoc
new file mode 100644
index 0000000..4da9f6a
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_metamodel-staged.adoc
@@ -0,0 +1,94 @@
+= Apache Tamaya -- Extension: Staged PropertySources
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.integration.cdi
+:title: Apache Tamaya Extension: Staged PropertySources
+:revdate: October 2015
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[Remote]]
+== Tamaya Metamodel: Staged PropertySources (Extension Module)
+=== Overview
+
+The Tamaya Staged PropertySources extension provides a base class and default implementation for loading
+multistaged configuration easily from a common configuration location.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from Tamaya CDI integration you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext.metamodels</groupId>
+ <artifactId>tamaya-metamodel.staged</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+The component will not register any components. The component basically provides the following options:
+
+* Use it as default configuration extension. Hereby you should define your stages in use by setting the
+ +env.STAGE+ system property with the stages to be loaded in order of precedence (most significant last),
+ e.g. +sys-env,DEFAULTS,TEST,DEVELOPMENT. _Additionally_ you must register
+ +org.apache.tamaya.staged.StagedConfigPropertiesProvider+ as in
+
+--------------------------------------------------------------
+META-INF
+|_service
+ |_org.apache.tamaya.spi.PropertySourceProvider
+--------------------------------------------------------------
+
+Tamaya will then load .properties files from +System.getenv(),
+classpath:DEFAULTS.properties, classpath:TEST.properties+ and
++classpath:DEVELOPMENT.properties+
+
+* For more advanced requirements, such as alternate locations, patterns or formats, you can also extend one of the
+ provided classes (+org.apache.tamaya.staged.StagedConfigPropertiesProvider+,
+ ** +BaseStagedPropertySourceProvider+). Extending provides features such as:
+
+ ** Defining a prefix for all entries provided/loaded.
+ ** Using alternate locations or formats.
+ ** Defining the ordinals used.
+
+
+
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/mod_spi-support.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_spi-support.adoc b/docs/src/main/asciidoc/mod_spi-support.adoc
new file mode 100644
index 0000000..0f80fba
--- /dev/null
+++ b/docs/src/main/asciidoc/mod_spi-support.adoc
@@ -0,0 +1,75 @@
+= Apache Tamaya -- Extension: Classloader Isolation Support
+
+:name: Tamaya
+:rootpackage: org.apache.tamaya.integration.cdi
+:title: Apache Tamaya Extension: SPI Implementation Support Classes
+:revdate: October 2015
+:authorinitials: ATR
+:author: Anatole Tresch
+:email: <an...@apache.org>
+:source-highlighter: coderay
+:website: http://tamaya.incubator.apache.org/
+:toc:
+:toc-placement: manual
+:encoding: UTF-8
+:numbered:
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the 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.
+'''
+
+<<<
+
+toc::[]
+
+<<<
+:numbered!:
+<<<
+[[SPISupport]]
+== Tamaya SPI Support (Extension Module)
+=== Overview
+
+The Tamaya SPI support module provides a few helpful base classes that can be used to implement some of the often
+used SPI parts in Tamaya:
+
+* +BasePropertySource+ provides an abstract base class for implementation of your own PropertySources.
+* +DefaultConfiguration+ provides you with a simple implementation of the +Configuration+ interface based on a
+ +ConfigurationContext+ provided. This is also very useful for mocking configuration during test execution, but
+ not only constraint to that use case.
+
+
+=== Compatibility
+
+The module is based on Java 7, so it will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from Tamaya CDI integration you only must add the corresponding dependency to your module:
+
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+The component will not register any components but only providing portable base classes for some common SPI
+implementation tasks. It only depends on the API, so it should be safely reusable also with other implementations
+of the Tamaya API similarly.
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2df75a8f/docs/src/main/asciidoc/modules.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/modules.adoc b/docs/src/main/asciidoc/modules.adoc
index 7d9486c..52fcecc 100644
--- a/docs/src/main/asciidoc/modules.adoc
+++ b/docs/src/main/asciidoc/modules.adoc
@@ -69,7 +69,8 @@ NOTE All extensions, despite the _tamaya-builder_ module, currently run on Java
|+org.apache.tamaya.ext:tamaya-server+ |Lets a Tamaya configuration instance provide scoped configuration as a http service. |link:mod_server.html[Documentation]
|+org.apache.tamaya.ext:tamaya-optional+ |Lets a Tamaya configuration to be used as an optional project extension only. |link:mod_optional.html[Documentation]
|+org.apache.tamaya.ext:tamaya-classloader-support+ |Manages Tamaya configuration and services considering classloading hierarchies. |link:mod_classloader_support.html[Documentation]
-|+org.apache.tamaya.ext:tamaya-cdi+ |Tamaya integration module for CDI. |link:mod_cdi.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-cdi-se+ |Tamaya integration module for CDI. |link:mod_cdi-se.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-spi-support+ |Tamaya support module for SPI implementation. |link:mod_spi-support.html[Documentation]
|=======
@@ -82,4 +83,6 @@ very carefully and especially give us feedback, so we can improve them before pr
|=======
|_Artifact_ |_Description_ |_Links_
|+org.apache.tamaya.ext:tamaya-jodatime+ |Provides support for JodaTime. | link:mod_jodatime.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-cdi+ |Java EE compliant CDI extension for Tamaya. |link:mod_cdi.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-staged+ |Simple configuration extension to add staged config. |link:mod_metamodel-staged.html[Documentation]
|=======
[02/13] incubator-tamaya git commit: TAMAYA-114: Added common
Map/properties based PropertySource impls.
Posted by an...@apache.org.
TAMAYA-114: Added common Map/properties based PropertySource impls.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4383a451
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4383a451
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4383a451
Branch: refs/heads/master
Commit: 4383a45112e7f66dc2709a2c35e3ed429dccb677
Parents: 8c74447
Author: anatole <an...@apache.org>
Authored: Wed Oct 7 22:15:14 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:46 2015 +0200
----------------------------------------------------------------------
.../tamaya/spisupport/MapPropertySource.java | 143 +++++++++++++++++++
.../PropertiesResourcePropertySource.java | 78 ++++++++++
.../spisupport/PropertyFilterComparator.java | 1 +
.../spisupport/PropertySourceComparator.java | 2 +-
.../SimplePropertiesPropertySource.java | 82 -----------
5 files changed, 223 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4383a451/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
new file mode 100644
index 0000000..f447aea
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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.spisupport;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+
+/**
+ * Simple PropertySource implementation that just takes a Map and an (optional) priority.
+ * Optionally the entries passed can be mapped to a different rootContext.
+ */
+public class MapPropertySource extends BasePropertySource {
+
+ /** The unique name of the PropertySource. */
+ private final String name;
+
+ /**
+ * The Property Sources priority, if a fixed priority should be used.
+ */
+ private final Integer priority;
+
+ /**
+ * The current properties.
+ */
+ private Map<String, String> props = new HashMap<>();
+
+ /**
+ * Creates a new instance, hereby using the default mechanism for evaluting the property source's
+ * priority.
+ *
+ * @param props the properties
+ */
+ public MapPropertySource(String name, Map<String, String> props) {
+ this(name, props, null, null);
+ }
+
+ /**
+ * Creates a new instance, hereby using the default mechanism for evaluting the property source's
+ * priority, but applying a custom mapping {@code rootContext} to the entries provided.
+ *
+ * @param props the properties
+ * @param rootContext the root context mapping, or null (for no mapping).
+ */
+ public MapPropertySource(String name, Map<String, String> props, String rootContext) {
+ this(name, props, rootContext, null);
+ }
+
+ /**
+ * Creates a new instance, hereby using the default mechanism for evaluting the property source's
+ * priority, but applying a custom mapping {@code rootContext} to the entries provided.
+ *
+ * @param props the properties
+ * @param rootContext the root context mapping, or null (for no mapping).
+ * @param priority the (optional) fixed priority. If null, the default priority
+ * evaluation is used.
+ */
+ public MapPropertySource(String name, Map<String, String> props, String rootContext, Integer priority) {
+ this.priority = priority;
+ this.name = Objects.requireNonNull(name);
+ if (rootContext == null) {
+ this.props.putAll(props);
+ } else {
+ for (Map.Entry<String, String> en : props.entrySet()) {
+ String prefix = rootContext;
+ if (prefix == null) {
+ prefix = "";
+ }
+ if (!prefix.endsWith(".") && prefix.length() > 0) {
+ prefix += ".";
+ }
+ this.props.put(prefix + en.getKey(), en.getValue());
+ }
+ }
+ }
+
+ /**
+ * Creates a new instance, hereby using the default mechanism for evaluting the property source's
+ * priority, but applying a custom mapping {@code rootContext} to the entries provided.
+ *
+ * @param props the properties
+ * @param rootContext the root context mapping, or null (for no mapping).
+ * @param priority the (optional) fixed priority. If null, the default priority
+ * evaluation is used.
+ */
+ public MapPropertySource(String name, Properties props, String rootContext, Integer priority) {
+ this(name, getMap(props), rootContext, priority);
+ }
+
+ /**
+ * Simple method to convert a Properties to a Map instance.
+ * @param props the properties, not null.
+ * @return the corresponding Map instance.
+ */
+ private static Map<String, String> getMap(Properties props) {
+ Map<String, String> result = new HashMap<>();
+ for (Map.Entry en : props.entrySet()) {
+ result.put(en.getKey().toString(), en.getValue().toString());
+ }
+ return result;
+ }
+
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(this.props);
+ }
+
+ @Override
+ public int getOrdinal() {
+ return priority;
+ }
+
+ @Override
+ public String toString() {
+ return "SimplePropertiesPropertySource{" +
+ "name=" + name + ", " +
+ "priority=" + priority +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4383a451/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java
new file mode 100644
index 0000000..67055bc
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple PropertySource, with a fixed ordinal that reads a .properties file from a given URL.
+ */
+public class PropertiesResourcePropertySource extends MapPropertySource {
+ /** The logger used. */
+ private static final Logger LOGGER = Logger.getLogger(PropertiesResourcePropertySource.class.getName());
+ /** The resource loaded. */
+ private URL url;
+
+ /**
+ * Creates a new instance.
+ * @param url the resource URL, not null.
+ * @param priority the optional (fixed) priority ordinal.
+ */
+ public PropertiesResourcePropertySource(URL url, Integer priority){
+ this(null, url, priority);
+ }
+
+ /**
+ * Creates a new instance.
+ * @param rootContext the (optional) root context for mapping (prefixing) the properties loaded.
+ * @param url the resource URL, not null.
+ * @param priority the optional (fixed) priority ordinal.
+ */
+ public PropertiesResourcePropertySource(String rootContext, URL url, Integer priority){
+ super(url.toExternalForm(), loadProps(url), rootContext, priority);
+ this.url = url;
+ }
+
+ /**
+ * Loads the properties using the JDK's Property loading mechanism.
+ * @param url the resource URL, not null.
+ * @return the loaded properties.
+ */
+ private static Map<String, String> loadProps(URL url) {
+ Map<String,String> result = new HashMap<>();
+ try(InputStream is = url.openStream();){
+ Properties props = new Properties();
+ props.load(is);
+ for(Map.Entry en: props.entrySet()){
+ result.put(en.getKey().toString(), en.getValue().toString());
+ }
+ }
+ catch(Exception e){
+ LOGGER.log(Level.WARNING, "Failed to read properties from " + url, e);
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4383a451/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
index 8eedd8f..14f1d66 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
@@ -29,6 +29,7 @@ import java.util.Comparator;
*/
public class PropertyFilterComparator implements Comparator<PropertyFilter>, Serializable {
+ /** serial version UID. */
private static final long serialVersionUID = 1L;
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4383a451/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
index 68473e1..6554167 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
@@ -27,7 +27,7 @@ import java.util.Comparator;
* Comparator for ordering of PropertySources based on their ordinal method and class name.
*/
public class PropertySourceComparator implements Comparator<PropertySource>, Serializable {
-
+ /** serial version UID. */
private static final long serialVersionUID = 1L;
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4383a451/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertiesPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertiesPropertySource.java
deleted file mode 100644
index 69c12f8..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertiesPropertySource.java
+++ /dev/null
@@ -1,82 +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.spisupport;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple PropertySource, with a fixed ordinal that reads a .properties file.
- */
-public final class SimplePropertiesPropertySource extends BasePropertySource {
-
- private static final Logger LOGGER = Logger.getLogger(SimplePropertiesPropertySource.class.getName());
- private URL url;
- private Map<String, String> properties = new HashMap<>();
- private final int priority;
-
- public SimplePropertiesPropertySource(URL url, int priority){
- this(null, url, priority);
- }
-
- public SimplePropertiesPropertySource(String rootContext, URL url, int priority){
- this.priority = priority;
- this.url = Objects.requireNonNull(url);
- try(InputStream is = url.openStream();){
- Properties props = new Properties();
- props.load(is);
- for(Map.Entry en: props.entrySet()){
- if(rootContext!=null){
- String prefix = rootContext;
- if(!prefix.endsWith(".")){
- prefix += ".";
- }
- this.properties.put(prefix + en.getKey().toString(), en.getValue().toString());
- } else{
- this.properties.put(en.getKey().toString(), en.getValue().toString());
- }
- }
- }
- catch(Exception e){
- LOGGER.log(Level.WARNING, "Failed to read properties from " + url, e);
- }
- }
-
- @Override
- public int getOrdinal(){
- return priority;
- }
-
- @Override
- public String getName() {
- return url.toExternalForm();
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-
-}
[08/13] incubator-tamaya git commit: TAMAYA-116: Moved Sabot CDI
module to extension section. Added docs.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java b/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java
new file mode 100644
index 0000000..db567ac
--- /dev/null
+++ b/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.store.internal;
+
+import com.hazelcast.config.Config;
+import com.hazelcast.config.GroupConfig;
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.store.PropertyStore;
+import org.apache.tamaya.store.spi.PropertyStoreProviderSpi;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * SPI implmentation for a providing Hazelcast based PropertyStores.
+ */
+public class HazelcastProprtyStoreProviderSpi implements PropertyStoreProviderSpi {
+ private static final String CONFIG_CLASS_SYS_PROP = "tamaya.store.hazelcast.configClass";
+ private static final String CONFIG_GROUP_SYS_PROP = "tamaya.store.hazelcast.groupName";
+
+
+
+ private static final Logger LOG = Logger.getLogger(HazelcastProprtyStoreProviderSpi.class.getName());
+
+ private HazelcastInstance store;
+ private Map<String,HazelcastProprtyStore> stores = new ConcurrentHashMap<>();
+
+ public HazelcastProprtyStoreProviderSpi() {
+ String customConfig = System.getProperty(CONFIG_CLASS_SYS_PROP);
+ Config config = null;
+ if(customConfig!=null){
+ try {
+ config = (Config)Class.forName(customConfig).newInstance();
+ LOG.info("Successfully created custom store config for HazelCast store: " + customConfig);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to instantiate custom store config for HazelCast store: " + customConfig, e);
+ }
+ }
+ if(config==null){
+ config = ServiceContextManager.getServiceContext().getService(Config.class);
+ }
+ if(config==null) {
+ config = new Config();
+ GroupConfig gc = new GroupConfig();
+ String groupName = System.getProperty(CONFIG_GROUP_SYS_PROP, "Tamaya");
+ gc.setName(groupName);
+ config.setGroupConfig(gc);
+ }
+ LOG.info("Starting HazelCast storage with config: " + config);
+ store = Hazelcast.getOrCreateHazelcastInstance(config);
+ }
+
+ @Override
+ public PropertyStore getPropertyStore(String storeId) {
+ HazelcastProprtyStore propertyStore = stores.get(storeId);
+ if(propertyStore==null){
+ LOG.info("Creating new distributed configuration map in HazelCast store for " + storeId + "...");
+ propertyStore = new HazelcastProprtyStore(store, storeId);
+ this.stores.put(storeId, propertyStore);
+ }
+ return propertyStore;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/pom.xml b/sandbox/integration/store/pom.xml
new file mode 100644
index 0000000..d755551
--- /dev/null
+++ b/sandbox/integration/store/pom.xml
@@ -0,0 +1,54 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-integration-sandbox</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>tamaya-store</artifactId>
+ <name>Apache Tamaya Storage/Cache/Datagrid Integration</name>
+ <description>Integration with a Datagrid backend for distributed configuration.</description>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-events</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java
new file mode 100644
index 0000000..d1d6adf
--- /dev/null
+++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.store;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Map;
+
+/**
+ * Simple abstraction of a property synchronization backend. Most methods are similar
+ * to a {@link org.apache.tamaya.spi.PropertySource}, enhanced with methods for
+ * updating the property storage.
+ */
+public interface PropertyStore {
+
+ /**
+ * Get the store's name.
+ * @return the name, never null.
+ */
+ String getName();
+
+ /**
+ * Stores the given PropertySource into the store.
+ * @param propertySource
+ */
+ void store(PropertySource propertySource);
+
+ /**
+ * Read all properties.
+ * @return the properties from the remote store, never null.
+ */
+ Map<String,String> read();
+
+ /**
+ * Reads a single key fromt hthe store.
+ * @param key the key, not null.
+ * @return the value, or null.
+ */
+ String read(String key);
+
+ /**
+ * Determines if {@link #read()} returns all contained properties, or optionally only
+ * a subset of the accessible and defined properties are returned.
+ * @return true, if this store is scannable.
+ */
+ boolean isScannable();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java
new file mode 100644
index 0000000..dceb29a
--- /dev/null
+++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.store;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.store.spi.PropertyStoreProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Simple provider accessor singleton for accessing {@link PropertyStore}
+ * instances.
+ */
+public final class PropertyStoreProvider {
+ /**
+ * The logger used.
+ */
+ private static final Logger LOG = Logger.getLogger(PropertyStoreProvider.class.getName());
+
+
+ /**
+ * Singleton constructor.
+ */
+ private PropertyStoreProvider() {
+ }
+
+
+ /**
+ * Access a {@link PropertyStore} using it's id.
+ *
+ * @param storeId the unique id of the store to use.
+ * @return
+ */
+ public static PropertyStore getPropertyStore(String storeId) {
+ for (PropertyStoreProviderSpi propertyStoreProviderSpi : ServiceContextManager.getServiceContext()
+ .getServices(PropertyStoreProviderSpi.class)) {
+ PropertyStore store = propertyStoreProviderSpi.getPropertyStore(storeId);
+ if (store != null) {
+ LOG.finest("DataGrid '" + storeId + "' used: " + store);
+ return store;
+ }
+ }
+ throw new ConfigException("No such Store: " + storeId);
+ }
+
+ /**
+ * Access a {@link PropertyStore} using it's id, hereby returning the most significant of the configured
+ * {@link PropertyStore} instances.
+ *
+ * @return the default PropertyStore instance.
+ */
+ public static PropertyStore getDefaultPropertyStore() {
+ return getPropertyStore("default");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java
new file mode 100644
index 0000000..c19fa45
--- /dev/null
+++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.store;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Map;
+
+/**
+ * Simple abstraction of a property synchronization backend. Most methods are similar
+ * to a {@link org.apache.tamaya.spi.PropertySource}, enhanced with methods for
+ * updating the property storage.
+ */
+public interface WritablePropertySource extends PropertySource{
+
+ /**
+ * Loads the property source from its store..
+ */
+ void load();
+
+ /**
+ * Sets the store to the given properties, replacing all previous state.
+ * @param props the new properties.
+ */
+ void setAll(Map<String, String> props);
+
+ /**
+ * Updates/adds all the given entries.
+ * @param props the entries to be added/updated.
+ */
+ void putAll(Map<String, String> props);
+
+ /**
+ * Writes a single entry.
+ * @param key the key, not null.
+ * @param value the new value, not null.
+ */
+ void put(String key, String value);
+
+ /**
+ * Removes all entries.
+ */
+ void clear();
+
+ /**
+ * Synchronize the current state with the remote version.
+ */
+ void synch();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java
new file mode 100644
index 0000000..b3fe1ee
--- /dev/null
+++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.store.spi;
+
+import org.apache.tamaya.events.ConfigEventManager;
+import org.apache.tamaya.events.FrozenPropertySource;
+import org.apache.tamaya.events.delta.ChangeType;
+import org.apache.tamaya.events.delta.PropertySourceChange;
+import org.apache.tamaya.events.delta.PropertySourceChangeBuilder;
+import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.store.PropertyStore;
+import org.apache.tamaya.store.WritablePropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * PropertySource that is connected to a {@link PropertyStore}.
+ */
+public class DefaultStoredPropertySource extends BasePropertySource
+ implements WritablePropertySource {
+
+ /**
+ * The store to be used, not null.
+ */
+ private PropertyStore propertyStore;
+
+ /**
+ * The last version of stoarge data accessed.
+ */
+ private String lastVersion;
+
+ private Map<String, String> properties = new HashMap<>();
+
+
+ private FrozenPropertySource currentConfig;
+
+ /**
+ * Creates a new property source.
+ *
+ * @param propertyStore the backend store.
+ * @param defaultOrdinal the default ordinal to be used.
+ */
+ public DefaultStoredPropertySource(PropertyStore propertyStore, int defaultOrdinal) {
+ super(defaultOrdinal);
+ this.propertyStore = Objects.requireNonNull(propertyStore);
+ this.properties.putAll(this.propertyStore.read());
+ }
+
+ @Override
+ public void load() {
+ this.properties.clear();
+ this.properties.putAll(this.propertyStore.read());
+ synch();
+ }
+
+ @Override
+ public String getName() {
+ return this.propertyStore.getName();
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public String get(String key) {
+ if (!propertyStore.isScannable()) {
+ return propertyStore.read(key);
+ }
+ return properties.get(key);
+ }
+
+ @Override
+ public boolean isScannable() {
+ return propertyStore.isScannable();
+ }
+
+ @Override
+ public String toString() {
+ return "StoredPropertySource{" +
+ "propertyStore=" + propertyStore.getName() +
+ '}';
+ }
+
+ @Override
+ public void setAll(Map<String, String> props) {
+ this.properties.clear();
+ this.properties.putAll(props);
+ synch();
+ }
+
+ @Override
+ public void putAll(Map<String, String> props) {
+ this.properties.putAll(props);
+ synch();
+ }
+
+ @Override
+ public void put(String key, String value) {
+ this.properties.put(key, value);
+ synch();
+ }
+
+ @Override
+ public void clear() {
+ this.properties.clear();
+ synch();
+ }
+
+ @Override
+ public void synch() {
+ FrozenPropertySource newConfig = FrozenPropertySource.of(this);
+ PropertySourceChange change = PropertySourceChangeBuilder.of(currentConfig, ChangeType.UPDATED)
+ .addChanges(newConfig).build();
+ currentConfig = newConfig;
+ ConfigEventManager.fireEvent(change);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java
new file mode 100644
index 0000000..1b20fc1
--- /dev/null
+++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.store.spi;
+
+import org.apache.tamaya.store.PropertyStore;
+
+/**
+ * Class, that provides access to PropertyStores to be used.
+ */
+public interface PropertyStoreProviderSpi {
+
+ /**
+ * Access a {@link PropertyStore} using it's id.
+ * @param storeId the unique id of the store to use.
+ * @return
+ */
+ PropertyStore getPropertyStore(String storeId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java b/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java
deleted file mode 100644
index e260732..0000000
--- a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java
+++ /dev/null
@@ -1,138 +0,0 @@
-import kafka.server.KafkaConfig;
-import kafka.server.KafkaServer;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-public class EmbeddedKafkaCluster {
- private final List<Integer> ports;
- private final String zkConnection;
- private final Properties baseProperties;
-
- private final String brokerList;
-
- private final List<KafkaServer> brokers;
- private final List<File> logDirs;
-
- public EmbeddedKafkaCluster(String zkConnection) {
- this(zkConnection, new Properties());
- }
-
- public EmbeddedKafkaCluster(String zkConnection, Properties baseProperties) {
- this(zkConnection, baseProperties, Collections.singletonList(-1));
- }
-
- public EmbeddedKafkaCluster(String zkConnection, Properties baseProperties, List<Integer> ports) {
- this.zkConnection = zkConnection;
- this.ports = resolvePorts(ports);
- this.baseProperties = baseProperties;
-
- this.brokers = new ArrayList<KafkaServer>();
- this.logDirs = new ArrayList<File>();
-
- this.brokerList = constructBrokerList(this.ports);
- }
-
- private List<Integer> resolvePorts(List<Integer> ports) {
- List<Integer> resolvedPorts = new ArrayList<Integer>();
- for (Integer port : ports) {
- resolvedPorts.add(resolvePort(port));
- }
- return resolvedPorts;
- }
-
- private int resolvePort(int port) {
- if (port == -1) {
- return TestUtils.getAvailablePort();
- }
- return port;
- }
-
- private String constructBrokerList(List<Integer> ports) {
- StringBuilder sb = new StringBuilder();
- for (Integer port : ports) {
- if (sb.length() > 0) {
- sb.append(",");
- }
- sb.append("localhost:").append(port);
- }
- return sb.toString();
- }
-
- public void startup() {
- for (int i = 0; i < ports.size(); i++) {
- Integer port = ports.get(i);
- File logDir = TestUtils.constructTempDir("kafka-local");
-
- Properties properties = new Properties();
- properties.putAll(baseProperties);
- properties.setProperty("zookeeper.connect", zkConnection);
- properties.setProperty("broker.id", String.valueOf(i + 1));
- properties.setProperty("host.name", "localhost");
- properties.setProperty("port", Integer.toString(port));
- properties.setProperty("log.dir", logDir.getAbsolutePath());
- properties.setProperty("log.flush.interval.messages", String.valueOf(1));
-
- KafkaServer broker = startBroker(properties);
-
- brokers.add(broker);
- logDirs.add(logDir);
- }
- }
-
-
- private KafkaServer startBroker(Properties props) {
- KafkaServer server = new KafkaServer(new KafkaConfig(props), new SystemTime());
- server.startup();
- return server;
- }
-
- public Properties getProps() {
- Properties props = new Properties();
- props.putAll(baseProperties);
- props.put("metadata.broker.list", brokerList);
- props.put("zookeeper.connect", zkConnection);
- return props;
- }
-
- public String getBrokerList() {
- return brokerList;
- }
-
- public List<Integer> getPorts() {
- return ports;
- }
-
- public String getZkConnection() {
- return zkConnection;
- }
-
- public void shutdown() {
- for (KafkaServer broker : brokers) {
- try {
- broker.shutdown();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- for (File logDir : logDirs) {
- try {
- TestUtils.deleteFile(logDir);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("EmbeddedKafkaCluster{");
- sb.append("brokerList='").append(brokerList).append('\'');
- sb.append('}');
- return sb.toString();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java b/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java
deleted file mode 100644
index 54068fc..0000000
--- a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java
+++ /dev/null
@@ -1,95 +0,0 @@
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-public class EmbeddedZookeeper {
- private int port = -1;
- private int tickTime = 500;
-
- private ServerCnxnFactory factory;
- private File snapshotDir;
- private File logDir;
-
- public EmbeddedZookeeper() {
- this(-1);
- }
-
- public EmbeddedZookeeper(int port) {
- this(port, 500);
- }
-
- public EmbeddedZookeeper(int port, int tickTime) {
- this.port = resolvePort(port);
- this.tickTime = tickTime;
- }
-
- private int resolvePort(int port) {
- if (port == -1) {
- return TestUtils.getAvailablePort();
- }
- return port;
- }
-
- public void startup() throws IOException{
- if (this.port == -1) {
- this.port = TestUtils.getAvailablePort();
- }
- this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
- this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot");
- this.logDir = TestUtils.constructTempDir("embeeded-zk/log");
-
- try {
- factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
- } catch (InterruptedException e) {
- throw new IOException(e);
- }
- }
-
-
- public void shutdown() {
- factory.shutdown();
- try {
- TestUtils.deleteFile(snapshotDir);
- } catch (FileNotFoundException e) {
- // ignore
- }
- try {
- TestUtils.deleteFile(logDir);
- } catch (FileNotFoundException e) {
- // ignore
- }
- }
-
- public String getConnection() {
- return "localhost:" + port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public void setTickTime(int tickTime) {
- this.tickTime = tickTime;
- }
-
- public int getPort() {
- return port;
- }
-
- public int getTickTime() {
- return tickTime;
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("EmbeddedZookeeper{");
- sb.append("connection=").append(getConnection());
- sb.append('}');
- return sb.toString();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/metamodels/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/pom.xml b/sandbox/metamodels/pom.xml
index fcc37ae..4a05846 100644
--- a/sandbox/metamodels/pom.xml
+++ b/sandbox/metamodels/pom.xml
@@ -34,6 +34,7 @@ under the License.
<modules>
<module>simple</module>
+ <module>staged</module>
</modules>
</project>
[07/13] incubator-tamaya git commit: Added functionality for
evaluating specific PropertySources for names matching.
Posted by an...@apache.org.
Added functionality for evaluating specific PropertySources for names matching.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/0e8ab2a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/0e8ab2a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/0e8ab2a2
Branch: refs/heads/master
Commit: 0e8ab2a2827a1fa09b9cb38ae8e5ce9e8b6134de
Parents: d9a8424
Author: anatole <an...@apache.org>
Authored: Fri Oct 9 00:40:28 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:49 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/functions/PropertySourceFunctions.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0e8ab2a2/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
index 32cea21..11aa58c 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
@@ -357,7 +357,6 @@ public final class PropertySourceFunctions {
* @return the list of all {@link PropertySource} instances matching, never null.
*/
public static <T> T getPropertySource(Class<T> type) {
- List<T> result = new ArrayList<>();
for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources()) {
if (type.isAssignableFrom(src.getClass())) {
return (T) src;
[04/13] incubator-tamaya git commit: TAMAYA-115: Implemented multi
classpath environment PropertySourceProvider, with relocation capability.
Posted by an...@apache.org.
TAMAYA-115: Implemented multi classpath environment PropertySourceProvider, with relocation capability.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/15201521
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/15201521
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/15201521
Branch: refs/heads/master
Commit: 15201521bce0e0119af6b1cfd3248d0db3ae16c7
Parents: bb06268
Author: anatole <an...@apache.org>
Authored: Wed Oct 7 23:00:18 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:47 2015 +0200
----------------------------------------------------------------------
sandbox/environment/pom.xml | 68 ---------
.../BaseEnvironmentPropertySourceProvider.java | 119 ----------------
.../tamaya/environment/spi/package-info.java | 23 ----
...org.apache.tamaya.spi.PropertySourceProvider | 19 ---
.../src/test/resources/GLOBAL.properties | 19 ---
.../src/test/resources/TEST.properties | 19 ---
sandbox/metamodels/staged/pom.xml | 68 +++++++++
.../spi/BaseStagedPropertySourceProvider.java | 121 ++++++++++++++++
.../spi/StagedConfigPropertiesProvider.java | 137 +++++++++++++++++++
.../apache/tamaya/staged/spi/package-info.java | 23 ++++
...org.apache.tamaya.spi.PropertySourceProvider | 19 +++
.../staged/src/test/resources/GLOBAL.properties | 19 +++
.../staged/src/test/resources/TEST.properties | 19 +++
13 files changed, 406 insertions(+), 267 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/environment/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/environment/pom.xml b/sandbox/environment/pom.xml
deleted file mode 100644
index c2e1745..0000000
--- a/sandbox/environment/pom.xml
+++ /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 current the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-sandbox</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>tamaya-environment</artifactId>
- <name>Apache Tamaya Modules - Environment Manager</name>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-core</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-functions</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-spisupport</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-resources</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java
deleted file mode 100644
index 5924640..0000000
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/BaseEnvironmentPropertySourceProvider.java
+++ /dev/null
@@ -1,119 +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.environment.spi;
-
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Logger;
-
-/**
- * Implements a base property source that defines a multilayered environment setup.
- */
-public abstract class BaseEnvironmentPropertySourceProvider implements PropertySourceProvider {
-
- private static final Logger LOGGER = Logger.getLogger(BaseEnvironmentPropertySourceProvider.class.getName());
-
- private int basePriority;
-
- private int priorityIncrease;
-
- private List<String> environmentIds = new ArrayList<>();
-
- private String environmentRootContext;
-
- private List<PropertySource> propertySources = new ArrayList<>();
-
-
- /**
- * Creates a new Environment provider, hereby using 10 for basePriority and priorityIncrease.
- * @param environmentRootContext the environment target root context, e.g. ENV. or null
- * for not remapping the environment properties.
- * @param environmentIds the context ids, that build up the environment.
- */
- public BaseEnvironmentPropertySourceProvider(String environmentRootContext,
- String... environmentIds) {
- this(environmentRootContext, 10,10,environmentIds);
- }
- /**
- * Creates a new Environment provider.
- * @param environmentRootContext the environment target root context, e.g. ENV. or null
- * for not remapping the environment properties.
- * @param basePriority the base priority used for the weakest environment properties set.
- * @param priorityIncrease the value the property source's priority should be increased with each
- * environment context level added.
- * @param environmentIds the context ids, that build up the environment.
- */
- public BaseEnvironmentPropertySourceProvider(String environmentRootContext, int basePriority, int priorityIncrease,
- String... environmentIds) {
- this.basePriority = basePriority;
- this.priorityIncrease = priorityIncrease;
- if (environmentIds.length == 0) {
- throw new ConfigException("At least one environment context id must be defined.");
- }
- if (environmentRootContext == null) {
- LOGGER.finest("No environment mapping is applied.");
- }
- this.environmentRootContext = environmentRootContext;
- this.environmentIds.addAll(Arrays.asList(environmentIds));
- int priority = basePriority;
- for (String contextId : environmentIds) {
- propertySources.addAll(loadEnvProperties(environmentRootContext, contextId, priority));
- priority += priorityIncrease;
- }
- }
-
- /**
- * Method that loads the environment properties for the given contextId.
- * @param environmentRootContext the root context, where entries should be mapped to.
- * @param contextId the contextId.
- * @param priority the target priority the created PropertySource should have. This priority is important, since it reflects the
- * environment context overriding rules for the environment part created.
- * @return the corresponding PrioritySources to be added, never null.
- */
- protected abstract Collection<PropertySource> loadEnvProperties(
- String environmentRootContext, String contextId, int priority);
-
- /**
- * Get the environment context ids that define how this environment configuration
- * is setup, in order of priority increasing.
- * @return the ordered list of context ids.
- */
- public List<String> getEnvironmentIds() {
- return environmentIds;
- }
-
- @Override
- public String toString() {
- return "EnvironmentPropertySourceProvider{" +
- "environmentIds=" + environmentIds +
- ", environmentRootContext='" + environmentRootContext + '\'' +
- '}';
- }
-
- @Override
- public Collection<PropertySource> getPropertySources() {
- return propertySources;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
deleted file mode 100644
index 9037c2b..0000000
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/spi/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-/**
- * Main API of the environment module, containing the base class for implementing adapted
- * environment parts in your configuration.
- */
-package org.apache.tamaya.environment.spi;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/sandbox/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index 233448a..0000000
--- a/sandbox/environment/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.environment.internal.ClasspathPropertiesEnvironmentProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/environment/src/test/resources/GLOBAL.properties
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/test/resources/GLOBAL.properties b/sandbox/environment/src/test/resources/GLOBAL.properties
deleted file mode 100644
index 9f39f75..0000000
--- a/sandbox/environment/src/test/resources/GLOBAL.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy 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.
-#
-aKey=aValue.GLOBAL
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/environment/src/test/resources/TEST.properties
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/test/resources/TEST.properties b/sandbox/environment/src/test/resources/TEST.properties
deleted file mode 100644
index 2b31cb3..0000000
--- a/sandbox/environment/src/test/resources/TEST.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy 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.
-#
-aKey=aValue.TEST
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/pom.xml b/sandbox/metamodels/staged/pom.xml
new file mode 100644
index 0000000..325e4ec
--- /dev/null
+++ b/sandbox/metamodels/staged/pom.xml
@@ -0,0 +1,68 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext.metamodels</groupId>
+ <artifactId>tamaya-metamodels</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>tamaya-metamodel-staged</artifactId>
+ <name>Apache Tamaya Modules - Staged Configuration</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-functions</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-resources</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java b/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java
new file mode 100644
index 0000000..36fcd11
--- /dev/null
+++ b/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/BaseStagedPropertySourceProvider.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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.staged.spi;
+
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Implements a base property source provider that defines a multilayered
+ * stage setup.
+ */
+public abstract class BaseStagedPropertySourceProvider implements PropertySourceProvider {
+
+ /** The logger used. */
+ private static final Logger LOGGER = Logger.getLogger(BaseStagedPropertySourceProvider.class.getName());
+
+ /** the current environment stages in order of precedence (weakest first). */
+ private List<String> contextIds = new ArrayList<>();
+
+ /** Optional root context of the environment in the config tree. All entries loaded will be mapped into
+ * this root conztext.
+ */
+ private String rootContext;
+
+ /** List of PropertySources evaluated and returned to the current ConfigurationContext on load. */
+ private List<PropertySource> propertySources = new ArrayList<>();
+
+
+ /**
+ * Creates a new Environment provider, hereby using 10 for basePriority and priorityIncrease.
+ * @param rootContext the environment target root context, e.g. ENV. or null
+ * for not remapping the environment properties.
+ * @param contextIds the context ids, that build up the environment.
+ */
+ public BaseStagedPropertySourceProvider(String rootContext,
+ String... contextIds) {
+ this(rootContext, 10,10, contextIds);
+ }
+ /**
+ * Creates a new Environment provider.
+ * @param rootContext the environment target root context, e.g. ENV. or null
+ * for not remapping the environment properties.
+ * @param basePriority the base priority used for the weakest environment properties set.
+ * @param priorityIncrease the value the property source's priority should be increased with each
+ * environment context level added.
+ * @param contextIds the context ids, that build up the environment.
+ */
+ public BaseStagedPropertySourceProvider(String rootContext, int basePriority, int priorityIncrease,
+ String... contextIds) {
+ if (contextIds.length == 0) {
+ throw new ConfigException("At least one environment context id must be defined.");
+ }
+ if (rootContext == null) {
+ LOGGER.finest("No environment mapping is applied.");
+ }
+ this.rootContext = rootContext;
+ this.contextIds.addAll(Arrays.asList(contextIds));
+ int priority = basePriority;
+ for (String contextId : contextIds) {
+ propertySources.addAll(loadStageProperties(rootContext, contextId, priority));
+ priority += priorityIncrease;
+ }
+ }
+
+ /**
+ * Method that loads the environment properties for the given contextId.
+ * @param rootContext the root context, where entries read should be mapped to.
+ * @param contextId the contextId.
+ * @param priority the target priority the created PropertySource should have. This priority is
+ * important, since it reflects the order as defined
+ * when configuring this class. Therefore it should not be overridden normally.
+ * @return the corresponding PrioritySources to be added, never null.
+ */
+ protected abstract Collection<PropertySource> loadStageProperties(
+ String rootContext, String contextId, int priority);
+
+ /**
+ * Get the environment context ids that define how this environment configuration
+ * is setup, in order of their increasing priority.
+ * @return the ordered list of context ids.
+ */
+ public List<String> getContextIds() {
+ return contextIds;
+ }
+
+ @Override
+ public String toString() {
+ return "EnvironmentPropertySourceProvider{" +
+ "contextIds=" + contextIds +
+ ", rootContext='" + rootContext + '\'' +
+ '}';
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return propertySources;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/StagedConfigPropertiesProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/StagedConfigPropertiesProvider.java b/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/StagedConfigPropertiesProvider.java
new file mode 100644
index 0000000..e224d52
--- /dev/null
+++ b/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/StagedConfigPropertiesProvider.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.staged.spi;
+
+
+import org.apache.tamaya.spisupport.MapPropertySource;
+import org.apache.tamaya.spisupport.PropertiesResourcePropertySource;
+import org.apache.tamaya.resource.ConfigResources;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Configuration provider that resolves to a location in the classpath.
+ * Hereby the following system properties can be set to configure the provider
+ * (all entries are optional):
+ * <pre>
+ * env.STAGE : ordered list of configs to be loaded, e.g. sys-env,GLOBAL,TEST,DEV
+ * </pre>
+ * Adding {@code sys-env} as stage maps the current environment properties using
+ * the priority to be aliged with the context ordering, defined by {@code env.STAGE}.
+ * Similarly the same thing can be done by passing {@code sys-props} as context id for
+ * adding the current System properties to the configuration tree.
+ *
+ * The rootContext can be used to remap the whole property space to an alternate subtree in
+ * the configuration tree overall. This is very handy, if multiple instances of this class
+ * are registered into the same configuration, but with different location setups. Remapping
+ * configuration allows to separate these entries clearly.<br/>
+ * Finally the resource location can be adapted by overriding {@link #getBaseResourcePath()}.
+ * Different formats and loading mechanisms can be implemented by overriding
+ * {@link #loadProperties(String, String, int, List)}.
+ */
+public class StagedConfigPropertiesProvider extends BaseStagedPropertySourceProvider {
+
+ /** The system property to define the stages used. */
+ private static final String STAGE_PROP = "env.STAGE";
+ /** The logger used. */
+
+ private static final Logger LOGGER = Logger.getLogger(StagedConfigPropertiesProvider.class.getName());
+
+ /** The context id for adding the system's environment properties. */
+ private static final String DEFAULT_ENV = "sys-env";
+
+ /** The context id for adding the system's properties. */
+ private static final String DEFAULT_SYSPROPS = "sys-props";
+
+ /**
+ * Creates a new instance.
+ * @param rootContext the (optional) root context, can be null.
+ * @param stages the comma separated list of stages.
+ */
+ public StagedConfigPropertiesProvider(String rootContext, String... stages){
+ super(rootContext, evaluateStages(stages));
+ }
+
+ /**
+ * Creates a default instance. the stages are read from the {@code env.STAGE} system¨propertx
+ * or a default is applied.
+ */
+ public StagedConfigPropertiesProvider(){
+ super(null, evaluateStages(null));
+ }
+
+ /**
+ * Evaluates the stages or returns the default STAGE entry.
+ * @return the stages to be used, never null.
+ */
+ private static String[] evaluateStages(String[] stages) {
+ if(stages!=null && stages.length>0){
+ return stages.clone();
+ }
+ String value = System.getProperty(STAGE_PROP);
+ if(value==null) {
+ value = System.getenv(STAGE_PROP);
+ }
+ if(value==null){
+ value = "sys-env,GLOBAL,DEVELOPMENT,sys-props";
+ }
+ return value.split(",");
+ }
+
+ @Override
+ protected Collection<PropertySource> loadStageProperties(
+ String rootContext, String contextId, int priority) {
+ List<PropertySource> result = new ArrayList<>();
+ if (DEFAULT_ENV.equals(contextId)){
+ result.add(new MapPropertySource(DEFAULT_ENV, System.getenv(),
+ rootContext, priority));
+ }else if (DEFAULT_SYSPROPS.equals(contextId)){
+ result.add(new MapPropertySource(DEFAULT_SYSPROPS, System.getProperties(),
+ rootContext, priority));
+ }
+ else{
+ loadProperties(rootContext, contextId, priority, result);
+ }
+ return result;
+ }
+
+ private void loadProperties(String rootContext, String contextId, int priority,
+ List<PropertySource> result) {
+ String cpExp = getBaseResourcePath()+'/' +contextId+".properties";
+ if(cpExp.startsWith("/")){
+ cpExp = cpExp.substring(1);
+ }
+ for(URL url: ConfigResources.getResourceResolver().getResources(cpExp)){
+ result.add(new PropertiesResourcePropertySource(rootContext, url, priority));
+ }
+ }
+
+ /**
+ * Get the basic resource path used for lookup of properties files.
+ * @return the basic resource path, never null.
+ */
+ protected String getBaseResourcePath() {
+ return "";
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/package-info.java
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/package-info.java b/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/package-info.java
new file mode 100644
index 0000000..9037c2b
--- /dev/null
+++ b/sandbox/metamodels/staged/src/main/java/org/apache/tamaya/staged/spi/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.
+ */
+/**
+ * Main API of the environment module, containing the base class for implementing adapted
+ * environment parts in your configuration.
+ */
+package org.apache.tamaya.environment.spi;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/sandbox/metamodels/staged/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..2bdf843
--- /dev/null
+++ b/sandbox/metamodels/staged/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.staged.spi.StagedConfigPropertiesProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/src/test/resources/GLOBAL.properties
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/src/test/resources/GLOBAL.properties b/sandbox/metamodels/staged/src/test/resources/GLOBAL.properties
new file mode 100644
index 0000000..9f39f75
--- /dev/null
+++ b/sandbox/metamodels/staged/src/test/resources/GLOBAL.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.
+#
+aKey=aValue.GLOBAL
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15201521/sandbox/metamodels/staged/src/test/resources/TEST.properties
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/src/test/resources/TEST.properties b/sandbox/metamodels/staged/src/test/resources/TEST.properties
new file mode 100644
index 0000000..2b31cb3
--- /dev/null
+++ b/sandbox/metamodels/staged/src/test/resources/TEST.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.
+#
+aKey=aValue.TEST
[09/13] incubator-tamaya git commit: TAMAYA-116: Moved Sabot CDI
module to extension section. Added docs.
Posted by an...@apache.org.
TAMAYA-116: Moved Sabot CDI module to extension section. Added docs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/5e332cbc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/5e332cbc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/5e332cbc
Branch: refs/heads/master
Commit: 5e332cbce87e2de331df53ae21084849e622ff68
Parents: 0e8ab2a
Author: anatole <an...@apache.org>
Authored: Mon Oct 12 07:14:59 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:02:09 2015 +0200
----------------------------------------------------------------------
docs/src/main/asciidoc/mod_cdi-ee.adoc | 54 ++++
docs/src/main/asciidoc/mod_cdi-se.adoc | 48 ++++
.../tamaya/integration/cdi2/ConfigDefault.java | 41 +++
.../integration/cdi2/ConfigDefaultSections.java | 43 ++++
.../tamaya/integration/cdi2/ConfigProperty.java | 80 ++++++
.../cdi2/ConfigurationExtension.java | 257 +++++++++++++++++++
.../integration/cdi2/ConfigurationProducer.java | 115 +++++++++
.../integration/cdi2/WithConfigOperator.java | 45 ++++
.../integration/cdi2/WithPropertyConverter.java | 45 ++++
.../cdi/src/main/resources/META-INF/beans.xml | 1 +
.../javax.enterprise.inject.spi.Extension | 1 +
.../META-INF/javaconfiguration.properties | 14 +
modules/integration/pom.xml | 2 +
.../ClasspathPropertiesEnvironmentProvider.java | 167 ------------
.../environment/internal/package-info.java | 22 --
.../tamaya/integration/cdi2/ConfigDefault.java | 41 ---
.../integration/cdi2/ConfigDefaultSections.java | 43 ----
.../tamaya/integration/cdi2/ConfigProperty.java | 80 ------
.../cdi2/ConfigurationExtension.java | 257 -------------------
.../integration/cdi2/ConfigurationProducer.java | 115 ---------
.../integration/cdi2/WithConfigOperator.java | 45 ----
.../integration/cdi2/WithPropertyConverter.java | 45 ----
.../cdi2/src/main/resources/META-INF/beans.xml | 1 -
.../javax.enterprise.inject.spi.Extension | 1 -
.../META-INF/javaconfiguration.properties | 14 -
sandbox/integration/pom.xml | 4 +-
...he.tamaya.store.spi.PropertyStoreProviderSpi | 18 ++
.../HazelcastProprtyStoreProviderSpi.java | 87 +++++++
sandbox/integration/store/pom.xml | 54 ++++
.../org/apache/tamaya/store/PropertyStore.java | 64 +++++
.../tamaya/store/PropertyStoreProvider.java | 78 ++++++
.../tamaya/store/WritablePropertySource.java | 66 +++++
.../store/spi/DefaultStoredPropertySource.java | 137 ++++++++++
.../store/spi/PropertyStoreProviderSpi.java | 34 +++
.../tamaya/zookeeper/EmbeddedKafkaCluster.java | 138 ----------
.../tamaya/zookeeper/EmbeddedZookeeper.java | 95 -------
sandbox/metamodels/pom.xml | 1 +
37 files changed, 1287 insertions(+), 1066 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/docs/src/main/asciidoc/mod_cdi-ee.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_cdi-ee.adoc b/docs/src/main/asciidoc/mod_cdi-ee.adoc
index 6f2f7ad..24cc57a 100644
--- a/docs/src/main/asciidoc/mod_cdi-ee.adoc
+++ b/docs/src/main/asciidoc/mod_cdi-ee.adoc
@@ -76,6 +76,12 @@ IMPORTANT: Dont install Tamaya's +cdi-se+ module at the same time.
=== How it Works
+This module registers a portable CDI extension to add the Configuration injection feature to CDI. Additionally
+this module overrides the +ServiceContext+ used, os it is aware of the CDI environment ans also considering the
+current CDI +BeaManager+ when looking up components (such as SPI classes).
+
+=== Adding SPI implementations managed as CDI beans
+
This module registers as +ServiceContext+ and integrates CDI for component loading as well as configuration injection.
All types injected by this module are injected using _dependent scope_. So with this module you can define/deploy
your +PropertySources+ and other artifacts simply by adding corresponding CDI managed beans:
@@ -160,3 +166,51 @@ public class ConfiguredClass{
}
--------------------------------------------------------
+=== Advanced Use Cases
+
+Beside basic configuration Tamaya also covers additional requirements:
+
+* _Reading multiple keys, where the first successful one is determining the value of the configuration, is
+ simply possible, by adding multiple keys to the +@ConfigProperty+ annotation.
+ E.g. for trying first +a.b+ and then +new.b+ you would configure it as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigPriority({"a.b", "new.b"}
+private String value;
+--------------------------------------------------------------------------------------
+
+* When you must apply a +ConfigOperator+ to your config, before reading the configuration, you can
+ configure one as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigPriority({"a.b", "new.b"}
+@WithConfigOperator(MyOperator.class)
+private String value;
+--------------------------------------------------------------------------------------
+
+* When you must apply a some special conversion, or you use a type that is not registered
+ for conversion, you can configure a custom converter to be applied as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigPriority({"a.b", "new.b"}
+@WithPropertyConverter(MyConverter.class)
+private MySpecialFooType value;
+--------------------------------------------------------------------------------------
+
+* Often multiple keys in a class belong to the same root section. So instead of copying this to
+ every entry you can define the most common root sections in the type's header:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigDefaultSections({"aaaa", "new"});
+public class MyType{
+
+@ConfigPriority({"b", "[legacy.bKey]"} // lookups: "aaaa.b", "new.b", legacy.bKey
+private String value;
+--------------------------------------------------------------------------------------
+
+In the example above +legacy.bKey+ defines an absolute key, which is not combined with any defined
+default section parts.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/docs/src/main/asciidoc/mod_cdi-se.adoc
----------------------------------------------------------------------
diff --git a/docs/src/main/asciidoc/mod_cdi-se.adoc b/docs/src/main/asciidoc/mod_cdi-se.adoc
index ed77848..f5fb1af 100644
--- a/docs/src/main/asciidoc/mod_cdi-se.adoc
+++ b/docs/src/main/asciidoc/mod_cdi-se.adoc
@@ -160,3 +160,51 @@ public class ConfiguredClass{
}
--------------------------------------------------------
+=== Advanced Use Cases
+
+Beside basic configuration Tamaya also covers additional requirements:
+
+* _Reading multiple keys, where the first successful one is determining the value of the configuration, is
+ simply possible, by adding multiple keys to the +@ConfigProperty+ annotation.
+ E.g. for trying first +a.b+ and then +new.b+ you would configure it as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigPriority({"a.b", "new.b"}
+private String value;
+--------------------------------------------------------------------------------------
+
+* When you must apply a +ConfigOperator+ to your config, before reading the configuration, you can
+ configure one as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigPriority({"a.b", "new.b"}
+@WithConfigOperator(MyOperator.class)
+private String value;
+--------------------------------------------------------------------------------------
+
+* When you must apply a some special conversion, or you use a type that is not registered
+ for conversion, you can configure a custom converter to be applied as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigPriority({"a.b", "new.b"}
+@WithPropertyConverter(MyConverter.class)
+private MySpecialFooType value;
+--------------------------------------------------------------------------------------
+
+* Often multiple keys in a class belong to the same root section. So instead of copying this to
+ every entry you can define the most common root sections in the type's header:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@ConfigDefaultSections({"aaaa", "new"});
+public class MyType{
+
+@ConfigPriority({"b", "[legacy.bKey]"} // lookups: "aaaa.b", "new.b", legacy.bKey
+private String value;
+--------------------------------------------------------------------------------------
+
+In the example above +legacy.bKey+ defines an absolute key, which is not combined with any defined
+default section parts.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
new file mode 100644
index 0000000..420f1fd
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.integration.cdi2;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define a default keys to be returned, when no configured keys could be
+ * determined for a property/template accessor. The keys hereby can also contain a
+ * dynamic expression that is evaluated by the configuration system.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
+public @interface ConfigDefault {
+
+ /**
+ * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
+ * is defined, it is handled as a deployment error.
+ */
+ String value() default "";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
new file mode 100644
index 0000000..e6b5ba2
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.cdi2;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to control injection and resolution current a configured bean. The configuration keys
+ * to be resolved are basically determined by the {@link org.apache.tamaya.inject.ConfigProperty}
+ * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
+ * to define a configuration area that is prefixed to all relative configuration keys within the
+ * corresponding class/template interface.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.TYPE })
+public @interface ConfigDefaultSections {
+
+ /**
+ * Allows to declare an section names that are prepended to resolve relative configuration keys.
+ * @return the section names to used for key resolution.
+ */
+ String[] value() default {};
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
new file mode 100644
index 0000000..4077fce
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.cdi2;
+
+
+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 enable injection current a configured property or define the returned data for
+ * a configuration template method. Hereby this annotation can be used in multiple ways and combined
+ * with other annotations such as {@link ConfigDefault}, {@link WithConfigOperator}, {@link WithPropertyConverter}.
+ *
+ * Below the most simple variant current a configured class is given:
+ * {@code
+ * pubic class ConfiguredItem{
+ *
+ * @ConfiguredProperty
+ * private String aValue;
+ * }
+ * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
+ * the following is happening:
+ * <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("aValue");}</li>
+ * <li>if not successful, and a @ConfigDefault annotation is present, the 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>
+ *
+ * In the next example we explicitly define the property keys:
+ * {@code
+ * @ConfigDefaultSections("section1")
+ * pubic class ConfiguredItem{
+ *
+ * @ConfiguredProperty({"b", "[a.b.deprecated.keys]", "a"})
+ * @ConfigDefault("myDefaultValue")
+ * private String aValue;
+ * }
+ *
+ * Within this example we evaluate multiple possible keys (section1.b, a.b.deprecated.keys, section1.a). Evaluation is
+ * aborted if a key could be successfully resolved. Hereby the ordering current the annotations define the ordering
+ * current resolution, so in the example above
+ * resolution equals to {@code "section1.b", "a.b.deprecated.keys", "section1.a"}. If no value has bee found,
+ * the configured default {@code myDefaultValue} is returned.
+ */
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
+public @interface ConfigProperty {
+
+ /**
+ * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
+ *
+ * @return the property names, not null. If missing the field or method name being injected is used by default.
+ */
+ @Nonbinding
+ String[] value() default {};
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
new file mode 100644
index 0000000..ffec5d1
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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.cdi2;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.ProcessBean;
+import javax.enterprise.inject.spi.ProcessProducerMethod;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * CDI Extension module that adds injection mechanism for configuration.
+ *
+ * @see ConfigProperty
+ * @see ConfigDefault
+ * @see org.apache.tamaya.integration.cdi2.ConfigDefaultSections
+ * @see ConfigException
+ */
+public class ConfigurationExtension implements Extension {
+
+ static final Map<Class, ConfigOperator> CUSTOM_OPERATORS = new ConcurrentHashMap<>();
+ static final Map<Class, PropertyConverter> CUSTOM_CONVERTERS = new ConcurrentHashMap<>();
+
+ private static class ConverterBean implements Bean<Object> {
+
+ private final Bean<Object> delegate;
+ private final Set<Type> types;
+
+ public ConverterBean(final Bean convBean, final Set<Type> types) {
+ this.types = types;
+ this.delegate = convBean;
+ }
+
+ @Override
+ public Set<Type> getTypes() {
+ return types;
+ }
+
+ @Override
+ public Class<?> getBeanClass() {
+ return delegate.getBeanClass();
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return delegate.getInjectionPoints();
+ }
+
+ @Override
+ public String getName() {
+ return delegate.getName();
+ }
+
+ @Override
+ public Set<Annotation> getQualifiers() {
+ return delegate.getQualifiers();
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope() {
+ return delegate.getScope();
+ }
+
+ @Override
+ public Set<Class<? extends Annotation>> getStereotypes() {
+ return delegate.getStereotypes();
+ }
+
+ @Override
+ public boolean isAlternative() {
+ return delegate.isAlternative();
+ }
+
+ @Override
+ public boolean isNullable() {
+ return delegate.isNullable();
+ }
+
+ @Override
+ public Object create(CreationalContext<Object> creationalContext) {
+ return delegate.create(creationalContext);
+ }
+
+ @Override
+ public void destroy(Object instance, CreationalContext<Object> creationalContext) {
+ delegate.destroy(instance, creationalContext);
+ }
+ }
+
+ private Set<Type> types = new HashSet<>();
+ private Bean<?> convBean;
+
+ /**
+ * Method that checks the configuration injection points during deployment for available configuration.
+ * @param pb the bean to process.
+ */
+ public void retrieveTypes(@Observes final ProcessBean<?> pb) {
+
+ final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
+
+ for (InjectionPoint injectionPoint : ips) {
+ if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
+ final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
+ final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
+ final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
+ final List<String> keys = evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
+
+ final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
+ if(withOperatorAnnot!=null){
+ tryLoadOpererator(withOperatorAnnot.value());
+ }
+ final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
+ if(withConverterAnnot!=null){
+ tryLoadConverter(withConverterAnnot.value());
+ }
+
+ // We don't want to wait until the injection really fails at runtime.
+ // If there is a non resolvable configuration, we want to know at startup.
+ Configuration config = ConfigurationProvider.getConfiguration();
+ String keyFound = null;
+ String value = null;
+ for(String key:keys) {
+ value = config.get(key);
+ if(value!=null){
+ keyFound = key;
+ break;
+ }
+ }
+ if(value==null && defaultAnnot!=null){
+ value = defaultAnnot.value();
+ }
+ if(value==null){
+ throw new ConfigException(String.format(
+ "Can't resolve any of the possible config keys: %s. Please provide one of the given keys" +
+ "with a value in your configuration sources.",
+ keys.toString()));
+ }
+ types.add(injectionPoint.getType());
+ }
+ }
+ }
+
+ private void tryLoadOpererator(Class<? extends ConfigOperator> operatorClass) {
+ Objects.requireNonNull(operatorClass);
+ if(ConfigOperator.class == operatorClass){
+ return;
+ }
+ try{
+ if(!CUSTOM_OPERATORS.containsKey(operatorClass)) {
+ CUSTOM_OPERATORS.put(operatorClass, operatorClass.newInstance());
+ }
+ }
+ catch(Exception e){
+ throw new ConfigException("Custom ConfigOperator could not be loaded: " + operatorClass.getName(), e);
+ }
+ }
+
+ private void tryLoadConverter(Class<? extends PropertyConverter> converterClass) {
+ Objects.requireNonNull(converterClass);
+ if(PropertyConverter.class == converterClass){
+ return;
+ }
+ try{
+ if(!CUSTOM_CONVERTERS.containsKey(converterClass)) {
+ CUSTOM_CONVERTERS.put(converterClass, converterClass.newInstance());
+ }
+ }
+ catch(Exception e){
+ throw new ConfigException("Custom PropertyConverter could not be loaded: " + converterClass.getName(), e);
+ }
+ }
+
+ /**
+ * Evaluates the effective keys to be used. if no {@code keys} are defined, {@code memberName} is used.
+ * The effective keys are then combined with the sections given (if any) and only, if the given keys are not
+ * absolute keys (surrounded by brackets).
+ * @param memberName the default member name, not null.
+ * @param keys the keys, may be empty, but not null.
+ * @param sections the default sections, may be empty. May also be null.
+ * @return the list of keys to be finally used for configuration resolution in order of
+ * precedence. The first keys in the list that could be successfully resolved define the final
+ * configuration value.
+ */
+ public static List<String> evaluateKeys(String memberName, String[] keys, String[] sections) {
+ List<String> effKeys = new ArrayList<>(Arrays.asList(keys));
+ if (effKeys.isEmpty()) {
+ effKeys.add(memberName);
+ }
+ ListIterator<String> iterator = effKeys.listIterator();
+ while (iterator.hasNext()) {
+ String next = iterator.next();
+ if (next.startsWith("[") && next.endsWith("]")) {
+ // absolute key, strip away brackets, take key as is
+ iterator.set(next.substring(1, next.length() - 1));
+ } else {
+ if (sections != null && sections.length>0) {
+ // Remove original entry, since it will be replaced with prefixed entries
+ iterator.remove();
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : sections) {
+ iterator.add(area.isEmpty() ? next : area + '.' + next);
+ }
+ }
+ }
+ }
+ return effKeys;
+ }
+
+
+ public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
+ if (ppm.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
+ convBean = ppm.getBean();
+ }
+
+ }
+
+ public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
+ abd.addBean(new ConverterBean(convBean, types));
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
new file mode 100644
index 0000000..8b4ae9f
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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.cdi2;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@ApplicationScoped
+public class ConfigurationProducer {
+
+ private static final Logger LOGGER = Logger.getLogger(ConfigurationProducer.class.getName());
+
+ @Produces
+ @ConfigProperty
+ public Object resolveAndConvert(final InjectionPoint injectionPoint) {
+
+ final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
+ final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
+ final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
+ final List<String> keys = ConfigurationExtension.evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
+
+ final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
+ ConfigOperator operator = null;
+ if(withOperatorAnnot!=null){
+ operator = ConfigurationExtension.CUSTOM_OPERATORS.get(withOperatorAnnot.value());
+ }
+ PropertyConverter customCnverter = null;
+ final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
+ if(withConverterAnnot!=null){
+ customCnverter = ConfigurationExtension.CUSTOM_CONVERTERS.get(withConverterAnnot.value());
+ }
+
+ // unless the extension is not installed, this should never happen because the extension
+ // enforces the resolvability of the config
+ Configuration config = ConfigurationProvider.getConfiguration();
+ if(operator!=null){
+ config = operator.operate(config);
+ }
+ final Class<?> toType = (Class<?>) injectionPoint.getAnnotated().getBaseType();
+ String textValue = null;
+ String defaultTextValue = defaultAnnot!=null?defaultAnnot.value():null;
+ String keyFound = null;
+ for(String key:keys) {
+ textValue = config.get(key);
+ if(textValue!=null){
+ keyFound = key;
+ break;
+ }
+ }
+ Object value = null;
+ if(keyFound!=null){
+ if(customCnverter!=null) {
+ value = customCnverter.convert(textValue);
+ }
+ if(value==null){
+ value = config.get(keyFound, toType);
+ }
+ }
+ else if(defaultTextValue!=null){
+ if(customCnverter!=null) {
+ value = customCnverter.convert(defaultTextValue);
+ }
+ if(value==null) {
+ List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfigurationContext()
+ .getPropertyConverters(TypeLiteral.of(toType));
+ for (PropertyConverter<Object> converter : converters) {
+ try {
+ value = converter.convert(defaultTextValue);
+ if (value != null) {
+ LOGGER.log(Level.FINEST, "Parsed default value from '" + defaultTextValue + "' into " +
+ injectionPoint);
+ break;
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.FINEST, "Failed to convert default value '" + defaultTextValue + "' for " +
+ injectionPoint, e);
+ }
+ }
+ }
+ }
+ if(value==null){
+ throw new ConfigException(String.format(
+ "Can't resolve any of the possible config keys: %s to the required target type: %s",
+ keys.toString(), toType.getName()));
+ }
+ LOGGER.finest(String.format("Injecting %s for key %s in class %s", keyFound, value.toString(), injectionPoint.toString()));
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
new file mode 100644
index 0000000..7d6ac66
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.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.integration.cdi2;
+
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+
+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 keys.
+ * This allows filtering current configuration, e.g. for realizing views or ensuring 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.
+ */
+ Class<? extends ConfigOperator> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
new file mode 100644
index 0000000..f50edcb
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.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.integration.cdi2;
+
+
+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 keys, 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.
+ */
+ Class<? extends PropertyConverter<?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/resources/META-INF/beans.xml b/modules/integration/cdi/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..e71e480
--- /dev/null
+++ b/modules/integration/cdi/src/main/resources/META-INF/beans.xml
@@ -0,0 +1 @@
+<beans></beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
new file mode 100644
index 0000000..78139d5
--- /dev/null
+++ b/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -0,0 +1 @@
+org.tomitribe.sabot.ConfigurationExtension
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties b/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..6c8b06c
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,14 @@
+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/blob/5e332cbc/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
index db10c11..85bd5c4 100644
--- a/modules/integration/pom.xml
+++ b/modules/integration/pom.xml
@@ -33,6 +33,8 @@ under the License.
<modules>
<module>spring</module>
+ <module>cdi-se</module>
+ <module>cdi</module>
</modules>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
deleted file mode 100644
index d9767e5..0000000
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
+++ /dev/null
@@ -1,167 +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.environment.internal;
-
-
-import org.apache.tamaya.environment.spi.BaseEnvironmentPropertySourceProvider;
-import org.apache.tamaya.spisupport.SimplePropertiesPropertySource;
-import org.apache.tamaya.resource.ConfigResources;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.BasePropertySource;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * Configuration provider that resolves to a location in the classpath.
- * Hereby the following system properties can be set to configure the provider
- * (all entries are optional):
- * <pre>
- * env.STAGE : ordered list of configs to be loaded, e.g. GLOBAL,TEST,DEV
- * env.ROOT : root context of the environment, by default ENV
- * </pre>
- * Adding {@code System.getenv()} as stage maps the current environment properties using
- * the priority to be aliged with the context ordering, defined by {@code env.STAGE}.
- */
-public class ClasspathPropertiesEnvironmentProvider extends BaseEnvironmentPropertySourceProvider {
-
- private static final String STAGE_PROP = "env.STAGE";
-
- private static final String ROOT_PROP = "env.ROOT";
-
- private static final Logger LOGGER = Logger.getLogger(ClasspathPropertiesEnvironmentProvider.class.getName());
-
- private String rootLocation;
-
- private static final String DEFAULT_ENV = "System.getenv()";
-
-
- public ClasspathPropertiesEnvironmentProvider(){
- super(evaluateRoot(), evaluateStages());
- }
-
- private static String evaluateRoot() {
- String value = System.getProperty(ROOT_PROP);
- if(value==null) {
- value = System.getenv(ROOT_PROP);
- }
- if(value==null){
- value = "ENV";
- }
- return value;
- }
-
- private static String[] evaluateStages() {
- String value = System.getProperty(STAGE_PROP);
- if(value==null) {
- value = System.getenv(STAGE_PROP);
- }
- if(value==null){
- value = "System.getenv(),GLOBAL,DEVELOPMENT";
- }
- return value.split(",");
- }
-
- @Override
- protected Collection<PropertySource> loadEnvProperties(
- String environmentRootContext, String contextId, int priority) {
- List<PropertySource> result = new ArrayList<>();
- if (DEFAULT_ENV.equals(contextId)){
- result.add(new EnvPropertiesPropertySource(environmentRootContext, priority));
- }
- else{
- loadProperties(environmentRootContext, contextId, priority, result);
- }
- return result;
- }
-
- private void loadProperties(String environmentRootContext, String contextId, int priority, List<PropertySource> result) {
- String cpExp = getBaseResourcePath()+'/' +contextId+".properties";
- if(cpExp.startsWith("/")){
- cpExp = cpExp.substring(1);
- }
- for(URL url: ConfigResources.getResourceResolver().getResources(cpExp)){
- result.add(new SimplePropertiesPropertySource(environmentRootContext, url, priority));
- }
- }
-
- /**
- * Get the basic resource path used for lookup of properties files.
- * @return the basic resource path, never null.
- */
- protected String getBaseResourcePath() {
- return "";
- }
-
- private static final class EnvPropertiesPropertySource extends BasePropertySource{
-
- private final int priority;
-
- private Map<String, String> envProps = new HashMap<>();
-
- public EnvPropertiesPropertySource(int priority) {
- this(null, priority);
- }
-
- public EnvPropertiesPropertySource(String environmentRootContext, int priority){
- this.priority = priority;
- if(environmentRootContext==null){
- envProps.putAll(System.getenv());
- }
- else{
- for(Map.Entry<String,String> en: System.getenv().entrySet()){
- String prefix = environmentRootContext;
- if(!prefix.endsWith(".")){
- prefix += ".";
- }
- envProps.put(prefix+en.getKey(), en.getValue());
- }
- }
- this.envProps = Collections.unmodifiableMap(envProps);
- }
-
- @Override
- public String getName() {
- return "System.getenv()";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.envProps;
- }
-
- @Override
- public int getOrdinal(){
- return priority;
- }
-
- @Override
- public String toString() {
- return "EnvPropertiesPropertySource{" +
- "priority=" + priority +
- '}';
- }
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
----------------------------------------------------------------------
diff --git a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java b/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
deleted file mode 100644
index 3f5b53f..0000000
--- a/sandbox/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/**
- * Contains the provided implementation classes for the environment module.
- */
-package org.apache.tamaya.environment.internal;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
deleted file mode 100644
index 420f1fd..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.cdi2;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a default keys to be returned, when no configured keys could be
- * determined for a property/template accessor. The keys hereby can also contain a
- * dynamic expression that is evaluated by the configuration system.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ConfigDefault {
-
- /**
- * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
- * is defined, it is handled as a deployment error.
- */
- String value() default "";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
deleted file mode 100644
index e6b5ba2..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
+++ /dev/null
@@ -1,43 +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.cdi2;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to control injection and resolution current a configured bean. The configuration keys
- * to be resolved are basically determined by the {@link org.apache.tamaya.inject.ConfigProperty}
- * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
- * to define a configuration area that is prefixed to all relative configuration keys within the
- * corresponding class/template interface.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.TYPE })
-public @interface ConfigDefaultSections {
-
- /**
- * Allows to declare an section names that are prepended to resolve relative configuration keys.
- * @return the section names to used for key resolution.
- */
- String[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
deleted file mode 100644
index 4077fce..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
+++ /dev/null
@@ -1,80 +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.cdi2;
-
-
-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 enable injection current a configured property or define the returned data for
- * a configuration template method. Hereby this annotation can be used in multiple ways and combined
- * with other annotations such as {@link ConfigDefault}, {@link WithConfigOperator}, {@link WithPropertyConverter}.
- *
- * Below the most simple variant current a configured class is given:
- * {@code
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty
- * private String aValue;
- * }
- * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
- * the following is happening:
- * <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("aValue");}</li>
- * <li>if not successful, and a @ConfigDefault annotation is present, the 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>
- *
- * In the next example we explicitly define the property keys:
- * {@code
- * @ConfigDefaultSections("section1")
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty({"b", "[a.b.deprecated.keys]", "a"})
- * @ConfigDefault("myDefaultValue")
- * private String aValue;
- * }
- *
- * Within this example we evaluate multiple possible keys (section1.b, a.b.deprecated.keys, section1.a). Evaluation is
- * aborted if a key could be successfully resolved. Hereby the ordering current the annotations define the ordering
- * current resolution, so in the example above
- * resolution equals to {@code "section1.b", "a.b.deprecated.keys", "section1.a"}. If no value has bee found,
- * the configured default {@code myDefaultValue} is returned.
- */
-@Qualifier
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ConfigProperty {
-
- /**
- * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
- *
- * @return the property names, not null. If missing the field or method name being injected is used by default.
- */
- @Nonbinding
- String[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
deleted file mode 100644
index ffec5d1..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
+++ /dev/null
@@ -1,257 +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.cdi2;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.ProcessBean;
-import javax.enterprise.inject.spi.ProcessProducerMethod;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * CDI Extension module that adds injection mechanism for configuration.
- *
- * @see ConfigProperty
- * @see ConfigDefault
- * @see org.apache.tamaya.integration.cdi2.ConfigDefaultSections
- * @see ConfigException
- */
-public class ConfigurationExtension implements Extension {
-
- static final Map<Class, ConfigOperator> CUSTOM_OPERATORS = new ConcurrentHashMap<>();
- static final Map<Class, PropertyConverter> CUSTOM_CONVERTERS = new ConcurrentHashMap<>();
-
- private static class ConverterBean implements Bean<Object> {
-
- private final Bean<Object> delegate;
- private final Set<Type> types;
-
- public ConverterBean(final Bean convBean, final Set<Type> types) {
- this.types = types;
- this.delegate = convBean;
- }
-
- @Override
- public Set<Type> getTypes() {
- return types;
- }
-
- @Override
- public Class<?> getBeanClass() {
- return delegate.getBeanClass();
- }
-
- @Override
- public Set<InjectionPoint> getInjectionPoints() {
- return delegate.getInjectionPoints();
- }
-
- @Override
- public String getName() {
- return delegate.getName();
- }
-
- @Override
- public Set<Annotation> getQualifiers() {
- return delegate.getQualifiers();
- }
-
- @Override
- public Class<? extends Annotation> getScope() {
- return delegate.getScope();
- }
-
- @Override
- public Set<Class<? extends Annotation>> getStereotypes() {
- return delegate.getStereotypes();
- }
-
- @Override
- public boolean isAlternative() {
- return delegate.isAlternative();
- }
-
- @Override
- public boolean isNullable() {
- return delegate.isNullable();
- }
-
- @Override
- public Object create(CreationalContext<Object> creationalContext) {
- return delegate.create(creationalContext);
- }
-
- @Override
- public void destroy(Object instance, CreationalContext<Object> creationalContext) {
- delegate.destroy(instance, creationalContext);
- }
- }
-
- private Set<Type> types = new HashSet<>();
- private Bean<?> convBean;
-
- /**
- * Method that checks the configuration injection points during deployment for available configuration.
- * @param pb the bean to process.
- */
- public void retrieveTypes(@Observes final ProcessBean<?> pb) {
-
- final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
-
- for (InjectionPoint injectionPoint : ips) {
- if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
- final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
- final List<String> keys = evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
-
- final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
- if(withOperatorAnnot!=null){
- tryLoadOpererator(withOperatorAnnot.value());
- }
- final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
- tryLoadConverter(withConverterAnnot.value());
- }
-
- // We don't want to wait until the injection really fails at runtime.
- // If there is a non resolvable configuration, we want to know at startup.
- Configuration config = ConfigurationProvider.getConfiguration();
- String keyFound = null;
- String value = null;
- for(String key:keys) {
- value = config.get(key);
- if(value!=null){
- keyFound = key;
- break;
- }
- }
- if(value==null && defaultAnnot!=null){
- value = defaultAnnot.value();
- }
- if(value==null){
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s. Please provide one of the given keys" +
- "with a value in your configuration sources.",
- keys.toString()));
- }
- types.add(injectionPoint.getType());
- }
- }
- }
-
- private void tryLoadOpererator(Class<? extends ConfigOperator> operatorClass) {
- Objects.requireNonNull(operatorClass);
- if(ConfigOperator.class == operatorClass){
- return;
- }
- try{
- if(!CUSTOM_OPERATORS.containsKey(operatorClass)) {
- CUSTOM_OPERATORS.put(operatorClass, operatorClass.newInstance());
- }
- }
- catch(Exception e){
- throw new ConfigException("Custom ConfigOperator could not be loaded: " + operatorClass.getName(), e);
- }
- }
-
- private void tryLoadConverter(Class<? extends PropertyConverter> converterClass) {
- Objects.requireNonNull(converterClass);
- if(PropertyConverter.class == converterClass){
- return;
- }
- try{
- if(!CUSTOM_CONVERTERS.containsKey(converterClass)) {
- CUSTOM_CONVERTERS.put(converterClass, converterClass.newInstance());
- }
- }
- catch(Exception e){
- throw new ConfigException("Custom PropertyConverter could not be loaded: " + converterClass.getName(), e);
- }
- }
-
- /**
- * Evaluates the effective keys to be used. if no {@code keys} are defined, {@code memberName} is used.
- * The effective keys are then combined with the sections given (if any) and only, if the given keys are not
- * absolute keys (surrounded by brackets).
- * @param memberName the default member name, not null.
- * @param keys the keys, may be empty, but not null.
- * @param sections the default sections, may be empty. May also be null.
- * @return the list of keys to be finally used for configuration resolution in order of
- * precedence. The first keys in the list that could be successfully resolved define the final
- * configuration value.
- */
- public static List<String> evaluateKeys(String memberName, String[] keys, String[] sections) {
- List<String> effKeys = new ArrayList<>(Arrays.asList(keys));
- if (effKeys.isEmpty()) {
- effKeys.add(memberName);
- }
- ListIterator<String> iterator = effKeys.listIterator();
- while (iterator.hasNext()) {
- String next = iterator.next();
- if (next.startsWith("[") && next.endsWith("]")) {
- // absolute key, strip away brackets, take key as is
- iterator.set(next.substring(1, next.length() - 1));
- } else {
- if (sections != null && sections.length>0) {
- // Remove original entry, since it will be replaced with prefixed entries
- iterator.remove();
- // Add prefixed entries, including absolute (root) entry for "" area keys.
- for (String area : sections) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return effKeys;
- }
-
-
- public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
- if (ppm.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- convBean = ppm.getBean();
- }
-
- }
-
- public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
- abd.addBean(new ConverterBean(convBean, types));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
deleted file mode 100644
index 8b4ae9f..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
+++ /dev/null
@@ -1,115 +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.cdi2;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-@ApplicationScoped
-public class ConfigurationProducer {
-
- private static final Logger LOGGER = Logger.getLogger(ConfigurationProducer.class.getName());
-
- @Produces
- @ConfigProperty
- public Object resolveAndConvert(final InjectionPoint injectionPoint) {
-
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
- final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
- final List<String> keys = ConfigurationExtension.evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
-
- final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
- ConfigOperator operator = null;
- if(withOperatorAnnot!=null){
- operator = ConfigurationExtension.CUSTOM_OPERATORS.get(withOperatorAnnot.value());
- }
- PropertyConverter customCnverter = null;
- final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
- customCnverter = ConfigurationExtension.CUSTOM_CONVERTERS.get(withConverterAnnot.value());
- }
-
- // unless the extension is not installed, this should never happen because the extension
- // enforces the resolvability of the config
- Configuration config = ConfigurationProvider.getConfiguration();
- if(operator!=null){
- config = operator.operate(config);
- }
- final Class<?> toType = (Class<?>) injectionPoint.getAnnotated().getBaseType();
- String textValue = null;
- String defaultTextValue = defaultAnnot!=null?defaultAnnot.value():null;
- String keyFound = null;
- for(String key:keys) {
- textValue = config.get(key);
- if(textValue!=null){
- keyFound = key;
- break;
- }
- }
- Object value = null;
- if(keyFound!=null){
- if(customCnverter!=null) {
- value = customCnverter.convert(textValue);
- }
- if(value==null){
- value = config.get(keyFound, toType);
- }
- }
- else if(defaultTextValue!=null){
- if(customCnverter!=null) {
- value = customCnverter.convert(defaultTextValue);
- }
- if(value==null) {
- List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfigurationContext()
- .getPropertyConverters(TypeLiteral.of(toType));
- for (PropertyConverter<Object> converter : converters) {
- try {
- value = converter.convert(defaultTextValue);
- if (value != null) {
- LOGGER.log(Level.FINEST, "Parsed default value from '" + defaultTextValue + "' into " +
- injectionPoint);
- break;
- }
- } catch (Exception e) {
- LOGGER.log(Level.FINEST, "Failed to convert default value '" + defaultTextValue + "' for " +
- injectionPoint, e);
- }
- }
- }
- }
- if(value==null){
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s to the required target type: %s",
- keys.toString(), toType.getName()));
- }
- LOGGER.finest(String.format("Injecting %s for key %s in class %s", keyFound, value.toString(), injectionPoint.toString()));
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
deleted file mode 100644
index 7d6ac66..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/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.integration.cdi2;
-
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-
-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 keys.
- * This allows filtering current configuration, e.g. for realizing views or ensuring 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.
- */
- Class<? extends ConfigOperator> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java b/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
deleted file mode 100644
index f50edcb..0000000
--- a/sandbox/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.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.integration.cdi2;
-
-
-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 keys, 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.
- */
- Class<? extends PropertyConverter<?>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/resources/META-INF/beans.xml b/sandbox/integration/cdi2/src/main/resources/META-INF/beans.xml
deleted file mode 100644
index e71e480..0000000
--- a/sandbox/integration/cdi2/src/main/resources/META-INF/beans.xml
+++ /dev/null
@@ -1 +0,0 @@
-<beans></beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/sandbox/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
deleted file mode 100644
index 78139d5..0000000
--- a/sandbox/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
+++ /dev/null
@@ -1 +0,0 @@
-org.tomitribe.sabot.ConfigurationExtension
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/sandbox/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties b/sandbox/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index 6c8b06c..0000000
--- a/sandbox/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-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/blob/5e332cbc/sandbox/integration/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/integration/pom.xml b/sandbox/integration/pom.xml
index dd3dfaa..efecb5e 100644
--- a/sandbox/integration/pom.xml
+++ b/sandbox/integration/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-sandbox</artifactId>
+ <artifactId>tamaya-extensions</artifactId>
<version>0.2-incubating-SNAPSHOT</version>
</parent>
@@ -32,7 +32,7 @@ under the License.
<artifactId>tamaya-integration-sandbox</artifactId>
<modules>
- <module>cdi2</module>
+ <module>store</module>
<module>commons</module>
</modules>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi
----------------------------------------------------------------------
diff --git a/sandbox/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi b/sandbox/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi
new file mode 100644
index 0000000..f3199f2
--- /dev/null
+++ b/sandbox/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy 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.
+#
[12/13] incubator-tamaya git commit: TAMAYA-116: CHeckstyle fixes for
cdi module (new).
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
new file mode 100644
index 0000000..1c383b4
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.integration.cdi.cfg;
+
+import org.apache.tamaya.spi.PropertySource;
+
+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,String> config = new HashMap<>();
+
+ public ProvidedPropertySource(){
+ config.put("a.b.c.key3", "keys current a.b.c.key3");
+ config.put("a.b.c.key4", "keys current a.b.c.key4");
+ config.put("{meta}source.type:"+getClass().getName(), "PropertySourceProvider");
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 10;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ return config.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return config;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestConfigProvider.java b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestConfigProvider.java
new file mode 100644
index 0000000..7b89fba
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestConfigProvider.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 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.integration.cdi.cfg;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import javax.enterprise.context.ApplicationScoped;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Created by Anatole on 29.09.2014.
+ */
+@ApplicationScoped
+public class TestConfigProvider implements PropertySourceProvider {
+
+ private List<PropertySource> configs = new ArrayList<>();
+
+ public TestConfigProvider(){
+ configs.add(new ProvidedPropertySource());
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return configs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
new file mode 100644
index 0000000..1db3d2c
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy 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.integration.cdi.cfg;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import javax.inject.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by Anatole on 17.09.2015.
+ */
+@Singleton
+public class TestPropertySource implements PropertySource{
+
+ final Map<String,String> config = new HashMap<>();
+
+ public TestPropertySource(){
+ config.put("a.b.c.key1", "keys current a.b.c.key1");
+ config.put("a.b.c.key2", "keys current a.b.c.key2");
+ config.put("a.b.key3", "keys current a.b.key3");
+ config.put("a.b.key4", "keys current a.b.key4");
+ config.put("a.key5", "keys current a.key5");
+ config.put("a.key6", "keys current a.key6");
+ config.put("int1", "123456");
+ config.put("int2", "111222");
+ config.put("testProperty", "testPropertyValue!");
+ config.put("booleanT", "true");
+ config.put("double1", "1234.5678");
+ config.put("BD", "123456789123456789123456789123456789.123456789123456789123456789123456789");
+ config.put("testProperty", "keys current testProperty");
+ config.put("runtimeVersion", "${java.version}");
+ config.put("{meta}source.type:"+getClass().getName(), "PropertySource");
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 10;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ return config.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return config;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi-se/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/resources/META-INF/beans.xml b/modules/integration/cdi-se/src/test/resources/META-INF/beans.xml
new file mode 100644
index 0000000..adee378
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/resources/META-INF/beans.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy 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.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
+
+</beans>
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/pom.xml b/modules/integration/cdi/pom.xml
new file mode 100644
index 0000000..a5206d0
--- /dev/null
+++ b/modules/integration/cdi/pom.xml
@@ -0,0 +1,207 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-integration</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tamaya-cdi</artifactId>
+ <name>Apache Tamaya Modules Integration - CDI (Java EE)</name>
+
+ <properties>
+ <owb.version>1.6.2</owb.version>
+ <weld.version>2.2.7.Final</weld.version>
+ <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version>
+ <geronimo-interceptor-1.2-spec.version>1.0</geronimo-interceptor-1.2-spec.version>
+ <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version>
+ <bval.version>0.5</bval.version>
+ <ds.version>1.1.0</ds.version>
+ <javaee-api.version>6.0-6</javaee-api.version>
+ <openejb.version>4.7.1</openejb.version>
+ <tomee.version>1.7.1</tomee.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>${javaee-api.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.tomitribe</groupId>
+ <artifactId>tomitribe-util</artifactId>
+ <version>1.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>${openejb.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+ <version>${geronimo-jcdi-1.1-spec.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.modules</groupId>
+ <artifactId>deltaspike-test-control-module-api</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.modules</groupId>
+ <artifactId>deltaspike-test-control-module-impl</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>OWB</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <dependencies>
+ <!-- OWB specific dependencies-->
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>${geronimo-atinject-1.0-spec.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+ <version>${geronimo-interceptor-1.2-spec.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <version>1.0.MR2-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-el_2.2_spec</artifactId>
+ <version>1.0.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-impl</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-spi</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-resource</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.bval</groupId>
+ <artifactId>bval-jsr303</artifactId>
+ <version>${bval.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-owb</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ <profile>
+ <id>Weld</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.se</groupId>
+ <artifactId>weld-se</artifactId>
+ <version>${weld.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-weld</artifactId>
+ <version>${ds.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefault.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefault.java
new file mode 100644
index 0000000..2a28b32
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefault.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.integration.cdi;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define a default keys to be returned, when no configured keys could be
+ * determined for a property/template accessor. The keys hereby can also contain a
+ * dynamic expression that is evaluated by the configuration system.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
+public @interface ConfigDefault {
+
+ /**
+ * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
+ * is defined, it is handled as a deployment error.
+ */
+ String value() default "";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefaultSections.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefaultSections.java
new file mode 100644
index 0000000..6f20130
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigDefaultSections.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to control injection and resolution current a configured bean. The configuration keys
+ * to be resolved are basically determined by the {@link org.apache.tamaya.inject.ConfigProperty}
+ * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
+ * to define a configuration area that is prefixed to all relative configuration keys within the
+ * corresponding class/template interface.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.TYPE })
+public @interface ConfigDefaultSections {
+
+ /**
+ * Allows to declare an section names that are prepended to resolve relative configuration keys.
+ * @return the section names to used for key resolution.
+ */
+ String[] value() default {};
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigProperty.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigProperty.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigProperty.java
new file mode 100644
index 0000000..686e63f
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigProperty.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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;
+
+
+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 enable injection current a configured property or define the returned data for
+ * a configuration template method. Hereby this annotation can be used in multiple ways and combined
+ * with other annotations such as {@link ConfigDefault}, {@link WithConfigOperator}, {@link WithPropertyConverter}.
+ *
+ * Below the most simple variant current a configured class is given:
+ * {@code
+ * pubic class ConfiguredItem{
+ *
+ * @ConfiguredProperty
+ * private String aValue;
+ * }
+ * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
+ * the following is happening:
+ * <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("aValue");}</li>
+ * <li>if not successful, and a @ConfigDefault annotation is present, the 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>
+ *
+ * In the next example we explicitly define the property keys:
+ * {@code
+ * @ConfigDefaultSections("section1")
+ * pubic class ConfiguredItem{
+ *
+ * @ConfiguredProperty({"b", "[a.b.deprecated.keys]", "a"})
+ * @ConfigDefault("myDefaultValue")
+ * private String aValue;
+ * }
+ *
+ * Within this example we evaluate multiple possible keys (section1.b, a.b.deprecated.keys, section1.a). Evaluation is
+ * aborted if a key could be successfully resolved. Hereby the ordering current the annotations define the ordering
+ * current resolution, so in the example above
+ * resolution equals to {@code "section1.b", "a.b.deprecated.keys", "section1.a"}. If no value has bee found,
+ * the configured default {@code myDefaultValue} is returned.
+ */
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
+public @interface ConfigProperty {
+
+ /**
+ * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
+ *
+ * @return the property names, not null. If missing the field or method name being injected is used by default.
+ */
+ @Nonbinding
+ String[] value() default {};
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
new file mode 100644
index 0000000..65e0433
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.ProcessBean;
+import javax.enterprise.inject.spi.ProcessProducerMethod;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * CDI Extension module that adds injection mechanism for configuration.
+ *
+ * @see ConfigProperty
+ * @see ConfigDefault
+ * @see org.apache.tamaya.integration.cdi.ConfigDefaultSections
+ * @see ConfigException
+ */
+public class ConfigurationExtension implements Extension {
+
+ static final Map<Class, ConfigOperator> CUSTOM_OPERATORS = new ConcurrentHashMap<>();
+ static final Map<Class, PropertyConverter> CUSTOM_CONVERTERS = new ConcurrentHashMap<>();
+
+ /**
+ * Internally used conversion bean.
+ */
+ private static class ConverterBean implements Bean<Object> {
+
+ private final Bean<Object> delegate;
+ private final Set<Type> types;
+
+ public ConverterBean(final Bean convBean, final Set<Type> types) {
+ this.types = types;
+ this.delegate = convBean;
+ }
+
+ @Override
+ public Set<Type> getTypes() {
+ return types;
+ }
+
+ @Override
+ public Class<?> getBeanClass() {
+ return delegate.getBeanClass();
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return delegate.getInjectionPoints();
+ }
+
+ @Override
+ public String getName() {
+ return delegate.getName();
+ }
+
+ @Override
+ public Set<Annotation> getQualifiers() {
+ return delegate.getQualifiers();
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope() {
+ return delegate.getScope();
+ }
+
+ @Override
+ public Set<Class<? extends Annotation>> getStereotypes() {
+ return delegate.getStereotypes();
+ }
+
+ @Override
+ public boolean isAlternative() {
+ return delegate.isAlternative();
+ }
+
+ @Override
+ public boolean isNullable() {
+ return delegate.isNullable();
+ }
+
+ @Override
+ public Object create(CreationalContext<Object> creationalContext) {
+ return delegate.create(creationalContext);
+ }
+
+ @Override
+ public void destroy(Object instance, CreationalContext<Object> creationalContext) {
+ delegate.destroy(instance, creationalContext);
+ }
+ }
+
+ private Set<Type> types = new HashSet<>();
+ private Bean<?> convBean;
+
+ /**
+ * Method that checks the configuration injection points during deployment for available configuration.
+ * @param pb the bean to process.
+ */
+ public void retrieveTypes(@Observes final ProcessBean<?> pb) {
+
+ final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
+
+ for (InjectionPoint injectionPoint : ips) {
+ if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
+ final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
+ final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
+ final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
+ final List<String> keys = evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
+
+ final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
+ if(withOperatorAnnot!=null){
+ tryLoadOpererator(withOperatorAnnot.value());
+ }
+ final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
+ if(withConverterAnnot!=null){
+ tryLoadConverter(withConverterAnnot.value());
+ }
+
+ // We don't want to wait until the injection really fails at runtime.
+ // If there is a non resolvable configuration, we want to know at startup.
+ Configuration config = ConfigurationProvider.getConfiguration();
+ String keyFound = null;
+ String value = null;
+ for(String key:keys) {
+ value = config.get(key);
+ if(value!=null){
+ keyFound = key;
+ break;
+ }
+ }
+ if(value==null && defaultAnnot!=null){
+ value = defaultAnnot.value();
+ }
+ if(value==null){
+ throw new ConfigException(String.format(
+ "Can't resolve any of the possible config keys: %s. Please provide one of the given keys" +
+ "with a value in your configuration sources.",
+ keys.toString()));
+ }
+ types.add(injectionPoint.getType());
+ }
+ }
+ }
+
+ private void tryLoadOpererator(Class<? extends ConfigOperator> operatorClass) {
+ Objects.requireNonNull(operatorClass);
+ if(ConfigOperator.class == operatorClass){
+ return;
+ }
+ try{
+ if(!CUSTOM_OPERATORS.containsKey(operatorClass)) {
+ CUSTOM_OPERATORS.put(operatorClass, operatorClass.newInstance());
+ }
+ } catch(Exception e){
+ throw new ConfigException("Custom ConfigOperator could not be loaded: " + operatorClass.getName(), e);
+ }
+ }
+
+ private void tryLoadConverter(Class<? extends PropertyConverter> converterClass) {
+ Objects.requireNonNull(converterClass);
+ if(PropertyConverter.class == converterClass){
+ return;
+ }
+ try{
+ if(!CUSTOM_CONVERTERS.containsKey(converterClass)) {
+ CUSTOM_CONVERTERS.put(converterClass, converterClass.newInstance());
+ }
+ } catch(Exception e){
+ throw new ConfigException("Custom PropertyConverter could not be loaded: " + converterClass.getName(), e);
+ }
+ }
+
+ /**
+ * Evaluates the effective keys to be used. if no {@code keys} are defined, {@code memberName} is used.
+ * The effective keys are then combined with the sections given (if any) and only, if the given keys are not
+ * absolute keys (surrounded by brackets).
+ * @param memberName the default member name, not null.
+ * @param keys the keys, may be empty, but not null.
+ * @param sections the default sections, may be empty. May also be null.
+ * @return the list of keys to be finally used for configuration resolution in order of
+ * precedence. The first keys in the list that could be successfully resolved define the final
+ * configuration value.
+ */
+ public static List<String> evaluateKeys(String memberName, String[] keys, String[] sections) {
+ List<String> effKeys = new ArrayList<>(Arrays.asList(keys));
+ if (effKeys.isEmpty()) {
+ effKeys.add(memberName);
+ }
+ ListIterator<String> iterator = effKeys.listIterator();
+ while (iterator.hasNext()) {
+ String next = iterator.next();
+ if (next.startsWith("[") && next.endsWith("]")) {
+ // absolute key, strip away brackets, take key as is
+ iterator.set(next.substring(1, next.length() - 1));
+ } else {
+ if (sections != null && sections.length>0) {
+ // Remove original entry, since it will be replaced with prefixed entries
+ iterator.remove();
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : sections) {
+ iterator.add(area.isEmpty() ? next : area + '.' + next);
+ }
+ }
+ }
+ }
+ return effKeys;
+ }
+
+
+ public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
+ if (ppm.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
+ convBean = ppm.getBean();
+ }
+
+ }
+
+ public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
+ abd.addBean(new ConverterBean(convBean, types));
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
new file mode 100644
index 0000000..c537df3
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.integration.cdi;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Producer bean for configuration properties.
+ */
+@ApplicationScoped
+public class ConfigurationProducer {
+
+ private static final Logger LOGGER = Logger.getLogger(ConfigurationProducer.class.getName());
+
+ @Produces
+ @ConfigProperty
+ public Object resolveAndConvert(final InjectionPoint injectionPoint) {
+
+ final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
+ final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
+ final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
+ final List<String> keys = ConfigurationExtension.evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
+
+ final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
+ ConfigOperator operator = null;
+ if(withOperatorAnnot!=null){
+ operator = ConfigurationExtension.CUSTOM_OPERATORS.get(withOperatorAnnot.value());
+ }
+ PropertyConverter customCnverter = null;
+ final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
+ if(withConverterAnnot!=null){
+ customCnverter = ConfigurationExtension.CUSTOM_CONVERTERS.get(withConverterAnnot.value());
+ }
+
+ // unless the extension is not installed, this should never happen because the extension
+ // enforces the resolvability of the config
+ Configuration config = ConfigurationProvider.getConfiguration();
+ if(operator!=null){
+ config = operator.operate(config);
+ }
+ final Class<?> toType = (Class<?>) injectionPoint.getAnnotated().getBaseType();
+ String textValue = null;
+ String defaultTextValue = defaultAnnot!=null?defaultAnnot.value():null;
+ String keyFound = null;
+ for(String key:keys) {
+ textValue = config.get(key);
+ if(textValue!=null){
+ keyFound = key;
+ break;
+ }
+ }
+ Object value = null;
+ if(keyFound!=null){
+ if(customCnverter!=null) {
+ value = customCnverter.convert(textValue);
+ }
+ if(value==null){
+ value = config.get(keyFound, toType);
+ }
+ } else if(defaultTextValue!=null){
+ if(customCnverter!=null) {
+ value = customCnverter.convert(defaultTextValue);
+ }
+ if(value==null) {
+ List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfigurationContext()
+ .getPropertyConverters(TypeLiteral.of(toType));
+ for (PropertyConverter<Object> converter : converters) {
+ try {
+ value = converter.convert(defaultTextValue);
+ if (value != null) {
+ LOGGER.log(Level.FINEST, "Parsed default value from '" + defaultTextValue + "' into " +
+ injectionPoint);
+ break;
+ }
+ } catch (Exception e) {
+ LOGGER.log(Level.FINEST, "Failed to convert default value '" + defaultTextValue + "' for " +
+ injectionPoint, e);
+ }
+ }
+ }
+ }
+ if(value==null){
+ throw new ConfigException(String.format(
+ "Can't resolve any of the possible config keys: %s to the required target type: %s",
+ keys.toString(), toType.getName()));
+ }
+ LOGGER.finest(String.format("Injecting %s for key %s in class %s", keyFound, value.toString(), injectionPoint.toString()));
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithConfigOperator.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithConfigOperator.java
new file mode 100644
index 0000000..f97524a
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithConfigOperator.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.integration.cdi;
+
+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 keys.
+ * This allows filtering current configuration, e.g. for realizing views or ensuring 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.
+ */
+ Class<? extends ConfigOperator> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithPropertyConverter.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithPropertyConverter.java
new file mode 100644
index 0000000..dbc9d33
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithPropertyConverter.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.integration.cdi;
+
+
+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 keys, 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.
+ */
+ Class<? extends PropertyConverter<?>> value();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
deleted file mode 100644
index 420f1fd..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.cdi2;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a default keys to be returned, when no configured keys could be
- * determined for a property/template accessor. The keys hereby can also contain a
- * dynamic expression that is evaluated by the configuration system.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ConfigDefault {
-
- /**
- * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
- * is defined, it is handled as a deployment error.
- */
- String value() default "";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
deleted file mode 100644
index e6b5ba2..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
+++ /dev/null
@@ -1,43 +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.cdi2;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to control injection and resolution current a configured bean. The configuration keys
- * to be resolved are basically determined by the {@link org.apache.tamaya.inject.ConfigProperty}
- * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
- * to define a configuration area that is prefixed to all relative configuration keys within the
- * corresponding class/template interface.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.TYPE })
-public @interface ConfigDefaultSections {
-
- /**
- * Allows to declare an section names that are prepended to resolve relative configuration keys.
- * @return the section names to used for key resolution.
- */
- String[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
deleted file mode 100644
index 4077fce..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
+++ /dev/null
@@ -1,80 +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.cdi2;
-
-
-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 enable injection current a configured property or define the returned data for
- * a configuration template method. Hereby this annotation can be used in multiple ways and combined
- * with other annotations such as {@link ConfigDefault}, {@link WithConfigOperator}, {@link WithPropertyConverter}.
- *
- * Below the most simple variant current a configured class is given:
- * {@code
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty
- * private String aValue;
- * }
- * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
- * the following is happening:
- * <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("aValue");}</li>
- * <li>if not successful, and a @ConfigDefault annotation is present, the 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>
- *
- * In the next example we explicitly define the property keys:
- * {@code
- * @ConfigDefaultSections("section1")
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty({"b", "[a.b.deprecated.keys]", "a"})
- * @ConfigDefault("myDefaultValue")
- * private String aValue;
- * }
- *
- * Within this example we evaluate multiple possible keys (section1.b, a.b.deprecated.keys, section1.a). Evaluation is
- * aborted if a key could be successfully resolved. Hereby the ordering current the annotations define the ordering
- * current resolution, so in the example above
- * resolution equals to {@code "section1.b", "a.b.deprecated.keys", "section1.a"}. If no value has bee found,
- * the configured default {@code myDefaultValue} is returned.
- */
-@Qualifier
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ConfigProperty {
-
- /**
- * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
- *
- * @return the property names, not null. If missing the field or method name being injected is used by default.
- */
- @Nonbinding
- String[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
deleted file mode 100644
index ffec5d1..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
+++ /dev/null
@@ -1,257 +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.cdi2;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.ProcessBean;
-import javax.enterprise.inject.spi.ProcessProducerMethod;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * CDI Extension module that adds injection mechanism for configuration.
- *
- * @see ConfigProperty
- * @see ConfigDefault
- * @see org.apache.tamaya.integration.cdi2.ConfigDefaultSections
- * @see ConfigException
- */
-public class ConfigurationExtension implements Extension {
-
- static final Map<Class, ConfigOperator> CUSTOM_OPERATORS = new ConcurrentHashMap<>();
- static final Map<Class, PropertyConverter> CUSTOM_CONVERTERS = new ConcurrentHashMap<>();
-
- private static class ConverterBean implements Bean<Object> {
-
- private final Bean<Object> delegate;
- private final Set<Type> types;
-
- public ConverterBean(final Bean convBean, final Set<Type> types) {
- this.types = types;
- this.delegate = convBean;
- }
-
- @Override
- public Set<Type> getTypes() {
- return types;
- }
-
- @Override
- public Class<?> getBeanClass() {
- return delegate.getBeanClass();
- }
-
- @Override
- public Set<InjectionPoint> getInjectionPoints() {
- return delegate.getInjectionPoints();
- }
-
- @Override
- public String getName() {
- return delegate.getName();
- }
-
- @Override
- public Set<Annotation> getQualifiers() {
- return delegate.getQualifiers();
- }
-
- @Override
- public Class<? extends Annotation> getScope() {
- return delegate.getScope();
- }
-
- @Override
- public Set<Class<? extends Annotation>> getStereotypes() {
- return delegate.getStereotypes();
- }
-
- @Override
- public boolean isAlternative() {
- return delegate.isAlternative();
- }
-
- @Override
- public boolean isNullable() {
- return delegate.isNullable();
- }
-
- @Override
- public Object create(CreationalContext<Object> creationalContext) {
- return delegate.create(creationalContext);
- }
-
- @Override
- public void destroy(Object instance, CreationalContext<Object> creationalContext) {
- delegate.destroy(instance, creationalContext);
- }
- }
-
- private Set<Type> types = new HashSet<>();
- private Bean<?> convBean;
-
- /**
- * Method that checks the configuration injection points during deployment for available configuration.
- * @param pb the bean to process.
- */
- public void retrieveTypes(@Observes final ProcessBean<?> pb) {
-
- final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
-
- for (InjectionPoint injectionPoint : ips) {
- if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
- final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
- final List<String> keys = evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
-
- final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
- if(withOperatorAnnot!=null){
- tryLoadOpererator(withOperatorAnnot.value());
- }
- final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
- tryLoadConverter(withConverterAnnot.value());
- }
-
- // We don't want to wait until the injection really fails at runtime.
- // If there is a non resolvable configuration, we want to know at startup.
- Configuration config = ConfigurationProvider.getConfiguration();
- String keyFound = null;
- String value = null;
- for(String key:keys) {
- value = config.get(key);
- if(value!=null){
- keyFound = key;
- break;
- }
- }
- if(value==null && defaultAnnot!=null){
- value = defaultAnnot.value();
- }
- if(value==null){
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s. Please provide one of the given keys" +
- "with a value in your configuration sources.",
- keys.toString()));
- }
- types.add(injectionPoint.getType());
- }
- }
- }
-
- private void tryLoadOpererator(Class<? extends ConfigOperator> operatorClass) {
- Objects.requireNonNull(operatorClass);
- if(ConfigOperator.class == operatorClass){
- return;
- }
- try{
- if(!CUSTOM_OPERATORS.containsKey(operatorClass)) {
- CUSTOM_OPERATORS.put(operatorClass, operatorClass.newInstance());
- }
- }
- catch(Exception e){
- throw new ConfigException("Custom ConfigOperator could not be loaded: " + operatorClass.getName(), e);
- }
- }
-
- private void tryLoadConverter(Class<? extends PropertyConverter> converterClass) {
- Objects.requireNonNull(converterClass);
- if(PropertyConverter.class == converterClass){
- return;
- }
- try{
- if(!CUSTOM_CONVERTERS.containsKey(converterClass)) {
- CUSTOM_CONVERTERS.put(converterClass, converterClass.newInstance());
- }
- }
- catch(Exception e){
- throw new ConfigException("Custom PropertyConverter could not be loaded: " + converterClass.getName(), e);
- }
- }
-
- /**
- * Evaluates the effective keys to be used. if no {@code keys} are defined, {@code memberName} is used.
- * The effective keys are then combined with the sections given (if any) and only, if the given keys are not
- * absolute keys (surrounded by brackets).
- * @param memberName the default member name, not null.
- * @param keys the keys, may be empty, but not null.
- * @param sections the default sections, may be empty. May also be null.
- * @return the list of keys to be finally used for configuration resolution in order of
- * precedence. The first keys in the list that could be successfully resolved define the final
- * configuration value.
- */
- public static List<String> evaluateKeys(String memberName, String[] keys, String[] sections) {
- List<String> effKeys = new ArrayList<>(Arrays.asList(keys));
- if (effKeys.isEmpty()) {
- effKeys.add(memberName);
- }
- ListIterator<String> iterator = effKeys.listIterator();
- while (iterator.hasNext()) {
- String next = iterator.next();
- if (next.startsWith("[") && next.endsWith("]")) {
- // absolute key, strip away brackets, take key as is
- iterator.set(next.substring(1, next.length() - 1));
- } else {
- if (sections != null && sections.length>0) {
- // Remove original entry, since it will be replaced with prefixed entries
- iterator.remove();
- // Add prefixed entries, including absolute (root) entry for "" area keys.
- for (String area : sections) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return effKeys;
- }
-
-
- public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
- if (ppm.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- convBean = ppm.getBean();
- }
-
- }
-
- public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
- abd.addBean(new ConverterBean(convBean, types));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
deleted file mode 100644
index 8b4ae9f..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
+++ /dev/null
@@ -1,115 +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.cdi2;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-@ApplicationScoped
-public class ConfigurationProducer {
-
- private static final Logger LOGGER = Logger.getLogger(ConfigurationProducer.class.getName());
-
- @Produces
- @ConfigProperty
- public Object resolveAndConvert(final InjectionPoint injectionPoint) {
-
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
- final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
- final List<String> keys = ConfigurationExtension.evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
-
- final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
- ConfigOperator operator = null;
- if(withOperatorAnnot!=null){
- operator = ConfigurationExtension.CUSTOM_OPERATORS.get(withOperatorAnnot.value());
- }
- PropertyConverter customCnverter = null;
- final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
- customCnverter = ConfigurationExtension.CUSTOM_CONVERTERS.get(withConverterAnnot.value());
- }
-
- // unless the extension is not installed, this should never happen because the extension
- // enforces the resolvability of the config
- Configuration config = ConfigurationProvider.getConfiguration();
- if(operator!=null){
- config = operator.operate(config);
- }
- final Class<?> toType = (Class<?>) injectionPoint.getAnnotated().getBaseType();
- String textValue = null;
- String defaultTextValue = defaultAnnot!=null?defaultAnnot.value():null;
- String keyFound = null;
- for(String key:keys) {
- textValue = config.get(key);
- if(textValue!=null){
- keyFound = key;
- break;
- }
- }
- Object value = null;
- if(keyFound!=null){
- if(customCnverter!=null) {
- value = customCnverter.convert(textValue);
- }
- if(value==null){
- value = config.get(keyFound, toType);
- }
- }
- else if(defaultTextValue!=null){
- if(customCnverter!=null) {
- value = customCnverter.convert(defaultTextValue);
- }
- if(value==null) {
- List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfigurationContext()
- .getPropertyConverters(TypeLiteral.of(toType));
- for (PropertyConverter<Object> converter : converters) {
- try {
- value = converter.convert(defaultTextValue);
- if (value != null) {
- LOGGER.log(Level.FINEST, "Parsed default value from '" + defaultTextValue + "' into " +
- injectionPoint);
- break;
- }
- } catch (Exception e) {
- LOGGER.log(Level.FINEST, "Failed to convert default value '" + defaultTextValue + "' for " +
- injectionPoint, e);
- }
- }
- }
- }
- if(value==null){
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s to the required target type: %s",
- keys.toString(), toType.getName()));
- }
- LOGGER.finest(String.format("Injecting %s for key %s in class %s", keyFound, value.toString(), injectionPoint.toString()));
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
deleted file mode 100644
index 7d6ac66..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/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.integration.cdi2;
-
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-
-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 keys.
- * This allows filtering current configuration, e.g. for realizing views or ensuring 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.
- */
- Class<? extends ConfigOperator> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
deleted file mode 100644
index f50edcb..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.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.integration.cdi2;
-
-
-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 keys, 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.
- */
- Class<? extends PropertyConverter<?>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/resources/META-INF/beans.xml b/modules/integration/cdi/src/main/resources/META-INF/beans.xml
index e71e480..562647f 100644
--- a/modules/integration/cdi/src/main/resources/META-INF/beans.xml
+++ b/modules/integration/cdi/src/main/resources/META-INF/beans.xml
@@ -1 +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.
+-->
<beans></beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
index 78139d5..e82118a 100644
--- a/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
+++ b/modules/integration/cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -1 +1,19 @@
-org.tomitribe.sabot.ConfigurationExtension
\ No newline at end of file
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.integration.cdi.ConfigurationExtension
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerFailedInjectionTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerFailedInjectionTest.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerFailedInjectionTest.java
new file mode 100644
index 0000000..6bfda3a
--- /dev/null
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerFailedInjectionTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy 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;
+
+import org.apache.openejb.OpenEjbContainer;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+
+public class ConfigurationProducerFailedInjectionTest {
+
+ @Test(expected = OpenEjbContainer.AssembleApplicationException.class)
+ public void notFoundShouldNotDeploy() {
+ // this explicitly tests that a non resolvable config makes
+ // the deployment fail and we won't have any failure at runtime
+ EJBContainer.createEJBContainer();
+ }
+
+}
[06/13] incubator-tamaya git commit: Added functionality for
evaluating specific PropertySources for types implemented.
Posted by an...@apache.org.
Added functionality for evaluating specific PropertySources for types implemented.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/9a4bd775
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/9a4bd775
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/9a4bd775
Branch: refs/heads/master
Commit: 9a4bd7754cce2db516e7d53aed397aca56cd21c0
Parents: 2df75a8
Author: anatole <an...@apache.org>
Authored: Fri Oct 9 00:09:10 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:48 2015 +0200
----------------------------------------------------------------------
.../functions/PropertySourceFunctions.java | 39 +++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9a4bd775/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
index 0eed11b..c0392d9 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
@@ -18,14 +18,21 @@
*/
package org.apache.tamaya.functions;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContextManager;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.logging.Logger;
/**
* Accessor that provides useful functions along with configuration.
@@ -265,7 +272,7 @@ public final class PropertySourceFunctions {
*/
static String stripSectionKeys(String key, String... areaKeys) {
for(String areaKey:areaKeys) {
- if(key.startsWith(areaKey+'.')) {
+ if(key.startsWith(areaKey + '.')) {
return key.substring(areaKey.length() + 1);
}
}
@@ -308,4 +315,34 @@ public final class PropertySourceFunctions {
return EMPTY_PROPERTYSOURCE;
}
+ /**
+ * Get a list of all {@link PropertySource} instances managed by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
+ * @return the list of all {@link PropertySource} instances matching, never null.
+ */
+ public static <T> Collection<T> getPropertySources(Class<T> type) {
+ List<T> result = new ArrayList<>();
+ for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources()) {
+ if (type.isAssignableFrom(src.getClass())) {
+ result.add((T) src);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get a list of all {@link PropertySource} instances managed by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
+ * @return the list of all {@link PropertySource} instances matching, never null.
+ */
+ public static <T> T getPropertySource(Class<T> type) {
+ List<T> result = new ArrayList<>();
+ for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources()) {
+ if (type.isAssignableFrom(src.getClass())) {
+ return (T)src;
+ }
+ }
+ return null;
+ }
+
}
[11/13] incubator-tamaya git commit: TAMAYA-116: CHeckstyle fixes for
cdi module (new).
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerTest.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerTest.java
new file mode 100644
index 0000000..88f425b
--- /dev/null
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationProducerTest.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.integration.cdi;
+
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.tomitribe.util.Duration;
+
+import javax.inject.Inject;
+import java.io.File;
+
+import static org.junit.Assert.*;
+
+@RunWith(ApplicationComposer.class)
+public class ConfigurationProducerTest {
+
+ @Module
+ @Classes(cdi = true, value = {
+ AllTypes.class,
+ ConfigurationExtension.class,
+ ConfigurationProducer.class
+ })
+ public EjbJar jar() {
+ return new EjbJar("config");
+ }
+
+ @Inject
+ private AllTypes allTypes;
+
+ @Test
+ public void defaultValues() {
+ assertEquals("defaultString", allTypes.getDefaultString());
+ assertEquals(new File("./"), allTypes.getDefaultFile());
+ assertEquals(new Duration("2 hours and 54 minutes"), allTypes.getDefaultDuration());
+ assertEquals(true, allTypes.getDefaultBoolean());
+ assertEquals(45, (int) allTypes.getDefaultInteger());
+ }
+
+ @Test
+ public void actualPropertyValues() {
+ assertEquals("hello", allTypes.getString());
+ assertEquals(new File("./conf"), allTypes.getFile());
+ assertEquals(new Duration("10 minutes and 57 seconds"), allTypes.getDuration());
+ assertEquals(true, allTypes.getaBoolean());
+ assertEquals(123, (int) allTypes.getInteger());
+ }
+
+ static class AllTypes {
+
+ @Inject
+ @ConfigProperty("string.value")
+ @ConfigDefault("defaultString")
+ private String string;
+
+ @Inject
+ @ConfigProperty("defaultString.value")
+ @ConfigDefault("defaultString")
+ private String defaultString;
+
+ @Inject
+ @ConfigProperty("file.value")
+ @ConfigDefault("./")
+ private File file;
+
+ @Inject
+ @ConfigProperty("defaultFile.value")
+ @ConfigDefault("./")
+ private File defaultFile;
+
+ @Inject
+ @ConfigProperty("duration.value")
+ @ConfigDefault("2 hours and 54 minutes")
+ private Duration duration;
+
+ @Inject
+ @ConfigProperty("defaultDuration.value")
+ @ConfigDefault("2 hours and 54 minutes")
+ private Duration defaultDuration;
+
+ @Inject
+ @ConfigProperty("boolean.value")
+ @ConfigDefault("true")
+ private Boolean aBoolean;
+
+ @Inject
+ @ConfigProperty("defaultBoolean.value")
+ @ConfigDefault("true")
+ private Boolean defaultBoolean;
+
+ @Inject
+ @ConfigProperty("integer.value")
+ @ConfigDefault("45")
+ private Integer integer;
+
+ @Inject
+ @ConfigProperty("defaultInteger.value")
+ @ConfigDefault("45")
+ private Integer defaultInteger;
+
+ public String getString() {
+ return string;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public Duration getDuration() {
+ return duration;
+ }
+
+ public Boolean getaBoolean() {
+ return aBoolean;
+ }
+
+ public Integer getInteger() {
+ return integer;
+ }
+
+ public String getDefaultString() {
+ return defaultString;
+ }
+
+ public File getDefaultFile() {
+ return defaultFile;
+ }
+
+ public Duration getDefaultDuration() {
+ return defaultDuration;
+ }
+
+ public Boolean getDefaultBoolean() {
+ return defaultBoolean;
+ }
+
+ public Integer getDefaultInteger() {
+ return defaultInteger;
+ }
+
+ @Override
+ public String toString() {
+ return "AllTypes{" +
+ "string='" + string + '\'' +
+ ", defaultString='" + defaultString + '\'' +
+ ", file=" + file +
+ ", defaultFile=" + defaultFile +
+ ", duration=" + duration +
+ ", defaultDuration=" + defaultDuration +
+ ", aBoolean=" + aBoolean +
+ ", defaultBoolean=" + defaultBoolean +
+ ", integer=" + integer +
+ ", defaultInteger=" + defaultInteger +
+ '}';
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationResolverTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationResolverTest.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationResolverTest.java
new file mode 100644
index 0000000..697580a
--- /dev/null
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/ConfigurationResolverTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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;
+//
+//import org.apache.openejb.loader.SystemInstance;
+//import org.junit.Before;
+//import org.junit.Test;
+//
+//import static org.junit.Assert.*;
+//
+//public class ConfigurationResolverTest {
+//
+// private ConfigurationResolver resolver;
+//
+// @Before
+// public void cleanEnv() {
+// SystemInstance.reset();
+// System.clearProperty("environment");
+//
+// resolver = new ConfigurationResolver();
+// }
+//
+// @Test
+// public void defaultEnvironment() {
+// assertEquals("test", resolver.getEnvironment());
+// }
+//
+// @Test
+// public void overrideDefaultEnvironment() {
+// System.setProperty("environment", "dev");
+//
+// // don't use the field cause before is invoked before we have a chance to set the environment
+// assertEquals("dev", new ConfigurationResolver().getEnvironment());
+// }
+//
+// @Test
+// public void isResolvable() {
+//
+// { // precondition
+// try {
+// resolver.isResolvableConfig(null, "value");
+// fail("a null key is not resolvable");
+//
+// } catch (final NullPointerException e) {
+// // expected
+// }
+// }
+// { // precondition
+// try {
+// resolver.isResolvableConfig("key", null);
+// fail("a null default value is not resolvable");
+//
+// } catch (final NullPointerException e) {
+// // expected
+// }
+// }
+//
+// // loaded from test.properties
+// assertTrue(resolver.isResolvableConfig("remote.wsdl.location", ""));
+// assertFalse(resolver.isResolvableConfig("something", ""));
+//
+// // loaded from base.properties
+// assertTrue(resolver.isResolvableConfig("remote.username", ""));
+// assertFalse(resolver.isResolvableConfig("bla", ""));
+// }
+//
+// @Test
+// public void found() {
+//
+// { // precondition
+// try {
+// resolver.isResolvableConfig(null, "value");
+// fail("a null key is not resolvable");
+//
+// } catch (final NullPointerException e) {
+// // expected
+// }
+// }
+// { // precondition
+// try {
+// resolver.isResolvableConfig("key", null);
+// fail("a null default value is not resolvable");
+//
+// } catch (final NullPointerException e) {
+// // expected
+// }
+// }
+//
+// // loaded from test.properties
+// assertEquals("classpath:/service-wsdl.xml", resolver.resolve("remote.wsdl.location", ""));
+// assertEquals("something-else", resolver.resolve("something", "something-else"));
+//
+// // loaded from base.properties
+// assertEquals("joecool", resolver.resolve("remote.username", ""));
+// assertEquals("blabla", resolver.resolve("bla", "blabla"));
+// }
+//
+//}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
new file mode 100644
index 0000000..cb60307
--- /dev/null
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.integration.cdi;
+//
+//import org.junit.Test;
+//
+//import java.util.Map;
+//import java.util.Properties;
+//
+//import static org.junit.Assert.assertEquals;
+//
+///**
+// * Tests the related environment properties exist
+// */
+//public class EnvironmentsTest {
+//
+// @Test
+// public void testGetProperties() throws Exception {
+//
+// final Properties test = Environments.getProperties("test");
+//
+// // loaded from test.properties
+// assertEquals("classpath:/test-service-wsdl.xml", test.getProperty("remote.wsdl.location"));
+//
+// // loaded from base.properties
+// assertEquals("joecool", test.getProperty("remote.username"));
+// }
+//
+// @Test(expected = IllegalArgumentException.class)
+// public void noEnvFound() {
+// Environments.getProperties("does not exists");
+// }
+//
+// @Test
+// public void dev() throws Exception {
+//
+// final Properties test = Environments.getProperties("dev");
+//
+// assertEquals("org.apache.openejb.cipher.StaticDESPasswordCipher", test.getProperty("cipher"));
+// assertEquals("NjAq6q2agYVnvSMz+eYUZg==", test.getProperty("remote.password"));
+// assertEquals("1443", test.getProperty("remote.port"));
+// assertEquals("https://srv1114.supertribe.org:1443/remote/service/url", test.getProperty("remote.target.url"));
+// assertEquals("srv1114.supertribe.org:1443", test.getProperty("remote.address"));
+// assertEquals("srv1114.supertribe.org", test.getProperty("remote.host"));
+// assertEquals("classpath:/service-wsdl.xml", test.getProperty("remote.wsdl.location"));
+// assertEquals("joecool", test.getProperty("remote.username"));
+// }
+//
+// @Test
+// public void cert() throws Exception {
+// final Properties test = Environments.getProperties("cert");
+// assertEquals("srv1016.supertribe.org", test.getProperty("remote.host"));
+// assertEquals("joecool", test.getProperty("remote.username"));
+// }
+//
+// @Test
+// public void prod() throws Exception {
+// final Properties test = Environments.getProperties("prod");
+// assertEquals("remotedb001.supertribe.org", test.getProperty("remote.host"));
+// assertEquals("joecool", test.getProperty("remote.username"));
+// }
+//
+//
+// private static void generateAsserts(Properties test) {
+// for (Map.Entry<Object, Object> entry : test.entrySet()) {
+// System.out.printf("assertEquals(\"%s\", test.getProperty(\"%s\"));%n", entry.getValue(), entry.getKey());
+// }
+// }
+//}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/InterpolationTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/InterpolationTest.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/InterpolationTest.java
new file mode 100644
index 0000000..56cc8c9
--- /dev/null
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/InterpolationTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tamaya.integration.cdi;
+//
+//import org.junit.Test;
+//import org.tomitribe.util.IO;
+//
+//import java.net.URL;
+//import java.util.Properties;
+//
+//import static org.junit.Assert.assertEquals;
+//
+//public class InterpolationTest {
+//
+// @Test
+// public void testInterpolate() throws Exception {
+// final Properties interpolated;
+// {
+// final Properties properties = new Properties();
+// properties.setProperty("foo.host", "localhost");
+// properties.setProperty("foo.port", "1234");
+// properties.setProperty("address", "http://${foo.host}:${foo.port}");
+// properties.setProperty("url", "${address}/webapp");
+// properties.setProperty("urlUnchanged", "${not an address}/webapp");
+//
+// interpolated = Interpolation.interpolate(properties);
+// }
+//
+// assertEquals("localhost", interpolated.getProperty("foo.host"));
+// assertEquals("1234", interpolated.getProperty("foo.port"));
+// assertEquals("http://localhost:1234", interpolated.getProperty("address"));
+// assertEquals("http://localhost:1234/webapp", interpolated.getProperty("url"));
+// assertEquals("${not an address}/webapp", interpolated.getProperty("urlUnchanged"));
+// }
+//
+// @Test
+// public void test() throws Exception {
+//
+// final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+//
+// final URL resource = loader.getResource("test.properties");
+// final Properties properties = Interpolation.interpolate(IO.readProperties(resource));
+//
+// //remote.wsdl.location = classpath:/lx01116-zhr-active-partner-service-wsdl.xml
+// assertEquals("classpath:/test-service-wsdl.xml", properties.getProperty("remote.wsdl.location"));
+// }
+//
+//}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/NotFoundNoDefault.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/NotFoundNoDefault.java b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/NotFoundNoDefault.java
new file mode 100644
index 0000000..d4355ab
--- /dev/null
+++ b/modules/integration/cdi/src/test/java/org/apache/tamaya/integration/cdi/NotFoundNoDefault.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the 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;
+
+import org.tomitribe.util.Duration;
+
+import javax.inject.Inject;
+import java.io.File;
+
+public class NotFoundNoDefault {
+
+ @Inject
+ @ConfigProperty("string.bla")
+ private String string;
+
+ @Inject
+ @ConfigProperty("file.bla")
+ private File file;
+
+ @Inject
+ @ConfigProperty("duration.bla")
+ private Duration duration;
+
+ @Inject
+ @ConfigProperty("boolean.bla")
+ private Boolean aBoolean;
+
+ @Inject
+ @ConfigProperty("integer.bla")
+ private Integer integer;
+
+ public String getString() {
+ return string;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public Duration getDuration() {
+ return duration;
+ }
+
+ public Boolean getaBoolean() {
+ return aBoolean;
+ }
+
+ public Integer getInteger() {
+ return integer;
+ }
+
+ @Override
+ public String toString() {
+ return "NotFoundNoDefault{" +
+ "string='" + string + '\'' +
+ ", file=" + file +
+ ", duration=" + duration +
+ ", aBoolean=" + aBoolean +
+ ", integer=" + integer +
+ '}';
+ }
+
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/META-INF/beans.xml b/modules/integration/cdi/src/test/resources/META-INF/beans.xml
new file mode 100644
index 0000000..562647f
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/META-INF/beans.xml
@@ -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.
+-->
+<beans></beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties b/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
index 6c8b06c..8d3c5c8 100644
--- a/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
+++ b/modules/integration/cdi/src/test/resources/META-INF/javaconfiguration.properties
@@ -1,3 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the 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.
+#
remote.wsdl.location = classpath:/service-wsdl.xml
remote.port=1443
remote.address=${remote.host}:${remote.port}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/base.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/base.properties b/modules/integration/cdi/src/test/resources/base.properties
new file mode 100644
index 0000000..a4d9896
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/base.properties
@@ -0,0 +1,32 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy 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.
+#
+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
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/cert.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/cert.properties b/modules/integration/cdi/src/test/resources/cert.properties
new file mode 100644
index 0000000..c2c3712
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/cert.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+remote.host=srv1016.supertribe.org
+remote.password=vm9oNWJpN8Y=
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/dev.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/dev.properties b/modules/integration/cdi/src/test/resources/dev.properties
new file mode 100644
index 0000000..abd3e03
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/dev.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.
+#
+remote.host=srv1114.supertribe.org
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/prod.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/prod.properties b/modules/integration/cdi/src/test/resources/prod.properties
new file mode 100644
index 0000000..9f1ad67
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/prod.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+remote.host=remotedb001.supertribe.org
+remote.password=vm9oNWJpN8Y=
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/qa.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/qa.properties b/modules/integration/cdi/src/test/resources/qa.properties
new file mode 100644
index 0000000..3f43795
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/qa.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+remote.host=srv1115.supertribe.org
+remote.password=vm9oNWJpN8Y=
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/modules/integration/cdi/src/test/resources/test.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/test/resources/test.properties b/modules/integration/cdi/src/test/resources/test.properties
new file mode 100644
index 0000000..8e08405
--- /dev/null
+++ b/modules/integration/cdi/src/test/resources/test.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+remote.wsdl.location = classpath:/test-service-wsdl.xml
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/04b3fc5e/sandbox/integration/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore
----------------------------------------------------------------------
diff --git a/sandbox/integration/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore b/sandbox/integration/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore
new file mode 100644
index 0000000..0833eac
--- /dev/null
+++ b/sandbox/integration/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.store.internal.IgniteProprtyStore
\ No newline at end of file
[05/13] incubator-tamaya git commit: Added functionality for
evaluating specific PropertySources for types implemented.
Posted by an...@apache.org.
Added functionality for evaluating specific PropertySources for types implemented.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d9a84246
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d9a84246
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d9a84246
Branch: refs/heads/master
Commit: d9a842469adcb38995b1fce9629bb48e5091a12b
Parents: 9a4bd77
Author: anatole <an...@apache.org>
Authored: Fri Oct 9 00:14:49 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:01:48 2015 +0200
----------------------------------------------------------------------
.../functions/PropertySourceFunctions.java | 131 +++++++++++--------
1 file changed, 76 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d9a84246/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
index c0392d9..32cea21 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
@@ -18,10 +18,8 @@
*/
package org.apache.tamaya.functions;
-import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.ServiceContextManager;
import java.util.ArrayList;
import java.util.Collection;
@@ -32,7 +30,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import java.util.logging.Logger;
/**
* Accessor that provides useful functions along with configuration.
@@ -68,7 +65,7 @@ public final class PropertySourceFunctions {
}
@Override
- public String toString(){
+ public String toString() {
return "PropertySource<empty>";
}
};
@@ -100,23 +97,23 @@ public final class PropertySourceFunctions {
* [meta:metaKey1]entry2=metaValue1
* [meta:metaKey2]entry2=metaValue2
* </pre>
- *
+ * <p>
* This mechanism allows to add meta information such as origin, sensitivity, to all keys of a current
* PropertySource or Configuration. If done on multiple PropertySources that are combined the corresponding
* values are visible in synch with the values visible.
*
* @param propertySource the base propertySource, not null.
- * @param metaData the metaData to be added, not null
+ * @param metaData the metaData to be added, not null
* @return the metadata enriched configuration, not null.
*/
- public static PropertySource addMetaData(PropertySource propertySource, Map<String,String> metaData) {
+ public static PropertySource addMetaData(PropertySource propertySource, Map<String, String> metaData) {
return new MetaEnrichedPropertySource(propertySource, metaData);
}
/**
* Calculates the current section key and compares it with the given key.
*
- * @param key the fully qualified entry key, not null
+ * @param key the fully qualified entry key, not null
* @param sectionKey the section key, not null
* @return true, if the entry is exact in this section
*/
@@ -129,13 +126,13 @@ public final class PropertySourceFunctions {
/**
* Calculates the current section key and compares it with the given section keys.
*
- * @param key the fully qualified entry key, not null
+ * @param key the fully qualified entry key, not null
* @param sectionKeys the section keys, not null
* @return true, if the entry is exact in this section
*/
public static boolean isKeyInSections(String key, String... sectionKeys) {
- for(String areaKey:sectionKeys){
- if(isKeyInSection(key, areaKey)){
+ for (String areaKey : sectionKeys) {
+ if (isKeyInSection(key, areaKey)) {
return true;
}
}
@@ -150,16 +147,16 @@ public final class PropertySourceFunctions {
* @return s set with all sections, never {@code null}.
*/
public static Set<String> sections(Map<String, String> properties) {
- final Set<String> areas = new HashSet<>();
- for(String s: properties.keySet()) {
- int index = s.lastIndexOf('.');
- if (index > 0) {
- areas.add(s.substring(0, index));
- } else {
- areas.add("<root>");
- }
+ final Set<String> areas = new HashSet<>();
+ for (String s : properties.keySet()) {
+ int index = s.lastIndexOf('.');
+ if (index > 0) {
+ areas.add(s.substring(0, index));
+ } else {
+ areas.add("<root>");
}
- return areas;
+ }
+ return areas;
}
/**
@@ -171,20 +168,20 @@ public final class PropertySourceFunctions {
* @return s set with all transitive sections, never {@code null}.
*/
public static Set<String> transitiveSections(Map<String, String> properties) {
- final Set<String> transitiveAreas = new HashSet<>();
- for(String s: sections(properties)) {
- int index = s.lastIndexOf('.');
- if (index < 0) {
- transitiveAreas.add("<root>");
- } else {
- while (index > 0) {
- s = s.substring(0, index);
- transitiveAreas.add(s);
- index = s.lastIndexOf('.');
- }
+ final Set<String> transitiveAreas = new HashSet<>();
+ for (String s : sections(properties)) {
+ int index = s.lastIndexOf('.');
+ if (index < 0) {
+ transitiveAreas.add("<root>");
+ } else {
+ while (index > 0) {
+ s = s.substring(0, index);
+ transitiveAreas.add(s);
+ index = s.lastIndexOf('.');
}
}
- return transitiveAreas;
+ }
+ return transitiveAreas;
}
/**
@@ -198,8 +195,8 @@ public final class PropertySourceFunctions {
*/
public static Set<String> sections(Map<String, String> properties, final Predicate<String> predicate) {
Set<String> treeSet = new TreeSet<>();
- for(String area: sections(properties)){
- if(predicate.test(area)){
+ for (String area : sections(properties)) {
+ if (predicate.test(area)) {
treeSet.add(area);
}
}
@@ -217,8 +214,8 @@ public final class PropertySourceFunctions {
*/
public static Set<String> transitiveSections(Map<String, String> properties, Predicate<String> predicate) {
Set<String> treeSet = new TreeSet<>();
- for(String area: transitiveSections(properties)){
- if(predicate.test(area)){
+ for (String area : transitiveSections(properties)) {
+ if (predicate.test(area)) {
treeSet.add(area);
}
}
@@ -234,7 +231,7 @@ public final class PropertySourceFunctions {
* @param sectionKeys the section keys, not null
* @return the section configuration, with the areaKey stripped away.
*/
- public static Map<String,String> sectionsRecursive(Map<String, String> properties, String... sectionKeys) {
+ public static Map<String, String> sectionsRecursive(Map<String, String> properties, String... sectionKeys) {
return sectionRecursive(properties, true, sectionKeys);
}
@@ -242,21 +239,21 @@ public final class PropertySourceFunctions {
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given section (recursive).
*
- * @param sectionKeys the section keys, not null
- * @param stripKeys if set to true, the section key is stripped away fromMap the resulting key.
+ * @param sectionKeys the section keys, not null
+ * @param stripKeys if set to true, the section key is stripped away fromMap the resulting key.
* @return the section configuration, with the areaKey stripped away.
*/
- public static Map<String,String> sectionRecursive(Map<String, String> properties, boolean stripKeys, String... sectionKeys) {
- Map<String,String> result = new HashMap<>(properties.size());
- if(stripKeys) {
- for(Map.Entry<String,String> en: properties.entrySet()){
- if(isKeyInSections(en.getKey(), sectionKeys)){
+ public static Map<String, String> sectionRecursive(Map<String, String> properties, boolean stripKeys, String... sectionKeys) {
+ Map<String, String> result = new HashMap<>(properties.size());
+ if (stripKeys) {
+ for (Map.Entry<String, String> en : properties.entrySet()) {
+ if (isKeyInSections(en.getKey(), sectionKeys)) {
result.put(en.getKey(), en.getValue());
}
}
} else {
- for(Map.Entry<String,String> en: properties.entrySet()){
- if(isKeyInSections(en.getKey(), sectionKeys)){
+ for (Map.Entry<String, String> en : properties.entrySet()) {
+ if (isKeyInSections(en.getKey(), sectionKeys)) {
result.put(stripSectionKeys(en.getKey(), sectionKeys), en.getValue());
}
}
@@ -266,13 +263,14 @@ public final class PropertySourceFunctions {
/**
* Strips the section key of the given absolute key, if it is one of the areaKeys passed.
- * @param key the current key, not null.
+ *
+ * @param key the current key, not null.
* @param areaKeys the areaKeys, not null.
* @return the stripped key, or the original key (if no section was matching).
*/
static String stripSectionKeys(String key, String... areaKeys) {
- for(String areaKey:areaKeys) {
- if(key.startsWith(areaKey + '.')) {
+ for (String areaKey : areaKeys) {
+ if (key.startsWith(areaKey + '.')) {
return key.substring(areaKey.length() + 1);
}
}
@@ -281,43 +279,65 @@ public final class PropertySourceFunctions {
/**
* Creates a ConfigOperator that adds the given items.
- * @param items the items to be added/replaced.
+ *
+ * @param items the items to be added/replaced.
* @param override if true, all items existing are overridden by the new ones passed.
* @return the ConfigOperator, never null.
*/
- public static PropertySource addItems(PropertySource propertySource, final Map<String,String> items, final boolean override){
+ public static PropertySource addItems(PropertySource propertySource, final Map<String, String> items, final boolean override) {
return new EnrichedPropertySource(propertySource, items, override);
}
/**
* Creates an operator that adds items to the instance.
+ *
* @param items the items, not null.
* @return the operator, never null.
*/
- public static PropertySource addItems(PropertySource propertySource, Map<String,String> items){
+ public static PropertySource addItems(PropertySource propertySource, Map<String, String> items) {
return addItems(propertySource, items, false);
}
/**
* Creates an operator that replaces the given items.
+ *
* @param items the items.
* @return the operator for replacing the items.
*/
- public static PropertySource replaceItems(PropertySource propertySource, Map<String,String> items){
+ public static PropertySource replaceItems(PropertySource propertySource, Map<String, String> items) {
return addItems(propertySource, items, true);
}
/**
* Accesses an empty PropertySource.
+ *
* @return an empty PropertySource, never null.
*/
- public static PropertySource emptyPropertySource(){
+ public static PropertySource emptyPropertySource() {
return EMPTY_PROPERTYSOURCE;
}
/**
+ * Find all {@link PropertySource} instances managed by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
+ *
+ * @param expression the regular expression to match the source's name.
+ * @return the list of all {@link PropertySource} instances matching, never null.
+ */
+ public static Collection<? extends PropertySource> findPropertySourcesByName(String expression) {
+ List result = new ArrayList<>();
+ for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources()) {
+ if (src.getName().matches(expression)) {
+ result.add(src);
+ }
+ }
+ return result;
+ }
+
+ /**
* Get a list of all {@link PropertySource} instances managed by the current
* {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
+ *
* @return the list of all {@link PropertySource} instances matching, never null.
*/
public static <T> Collection<T> getPropertySources(Class<T> type) {
@@ -333,13 +353,14 @@ public final class PropertySourceFunctions {
/**
* Get a list of all {@link PropertySource} instances managed by the current
* {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
+ *
* @return the list of all {@link PropertySource} instances matching, never null.
*/
public static <T> T getPropertySource(Class<T> type) {
List<T> result = new ArrayList<>();
for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources()) {
if (type.isAssignableFrom(src.getClass())) {
- return (T)src;
+ return (T) src;
}
}
return null;
[10/13] incubator-tamaya git commit: TAMAYA-114: Added common
Map/properties based PropertySource impls.
Posted by an...@apache.org.
TAMAYA-114: Added common Map/properties based PropertySource impls.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7a32a1a8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7a32a1a8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7a32a1a8
Branch: refs/heads/master
Commit: 7a32a1a8b8b220ae187df532cc1758549af22de8
Parents: 5e332cb
Author: anatole <an...@apache.org>
Authored: Mon Oct 12 07:15:21 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:02:10 2015 +0200
----------------------------------------------------------------------
.../main/java/org/apache/tamaya/spisupport/MapPropertySource.java | 3 ---
1 file changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7a32a1a8/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
index ada292a..324b80a 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
@@ -79,9 +79,6 @@ public class MapPropertySource extends BasePropertySource {
} else {
for (Map.Entry<String, String> en : props.entrySet()) {
String prefix = rootContext;
- if (prefix == null) {
- prefix = "";
- }
if (!prefix.endsWith(".") && prefix.length() > 0) {
prefix += ".";
}