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/16 20:59:43 UTC
[01/11] incubator-tamaya git commit: TAMAYA-123: Adding OSGI Support.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master a038b9c33 -> d03782a58
TAMAYA-123: Adding OSGI Support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/624fb484
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/624fb484
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/624fb484
Branch: refs/heads/master
Commit: 624fb484ea98150ce560225c3d2de321d7c7622b
Parents: a038b9c
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:15:21 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:15:21 2015 +0200
----------------------------------------------------------------------
api/pom.xml | 19 +++++
core/pom.xml | 25 +++++++
modules/builder/pom.xml | 17 +++++
modules/classloader-support/pom.xml | 24 +++++-
modules/events/pom.xml | 24 ++++++
modules/formats/pom.xml | 19 +++++
modules/functions/pom.xml | 20 ++++-
modules/injection-api/pom.xml | 77 ++++++++++++++++++++
modules/injection/pom.xml | 33 ++++++++-
modules/integration/cdi-se/pom.xml | 18 +++++
modules/integration/cdi/pom.xml | 19 ++++-
.../org/tamaya/integration/osgi/Activator.java | 3 +-
.../integration/osgi/TamayaConfigAdminImpl.java | 3 +-
modules/integration/spring/pom.xml | 13 ++++
modules/json/pom.xml | 17 ++++-
modules/management/pom.xml | 19 ++++-
modules/model/pom.xml | 23 +++++-
modules/optional/pom.xml | 19 ++++-
modules/remote/pom.xml | 19 ++++-
modules/resolver/pom.xml | 26 ++++++-
modules/resources/pom.xml | 22 +++++-
modules/server/pom.xml | 23 +++++-
modules/spi-support/pom.xml | 19 ++++-
sandbox/collections/pom.xml | 25 ++++++-
sandbox/integration/commons/pom.xml | 27 ++++++-
sandbox/integration/store/pom.xml | 28 ++++++-
sandbox/jodatime/pom.xml | 25 +++++++
sandbox/metamodels/simple/pom.xml | 28 ++++++-
sandbox/metamodels/staged/pom.xml | 28 ++++++-
sandbox/sysprops/pom.xml | 23 +++++-
30 files changed, 657 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/api/pom.xml
----------------------------------------------------------------------
diff --git a/api/pom.xml b/api/pom.xml
index 369cdb6..0cca428 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-api</artifactId>
<name>Apache Tamaya API</name>
+ <packaging>bundle</packaging>
<description>
The API for accessing configuration data.
@@ -41,4 +42,22 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index fe39e94..1b35dab 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-core</artifactId>
<name>Apache Tamaya Core Implementation</name>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -49,4 +50,28 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.tamaya.core.internal,
+ org.apache.tamaya.core.internal.converters
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/builder/pom.xml
----------------------------------------------------------------------
diff --git a/modules/builder/pom.xml b/modules/builder/pom.xml
index a078f79..710e5e7 100644
--- a/modules/builder/pom.xml
+++ b/modules/builder/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-builder</artifactId>
<name>Apache Tamaya Builder</name>
+ <packaging>jar</packaging> <!-- bundle -->
<inceptionYear>2015</inceptionYear>
@@ -86,5 +87,21 @@ under the License.
</dependencies>
+ <!--build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.builder
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build -->
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/classloader-support/pom.xml
----------------------------------------------------------------------
diff --git a/modules/classloader-support/pom.xml b/modules/classloader-support/pom.xml
index 251bf64..953875d 100644
--- a/modules/classloader-support/pom.xml
+++ b/modules/classloader-support/pom.xml
@@ -32,7 +32,7 @@ under the License.
<description>Apache Tamaya Classloader Support registers a ConfigurationContext that leverages
classloader hierarchies. Also visibility of features and components is aligned with the
corresponding hierarchy of classloaders.</description>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -45,9 +45,31 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.clsupport
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index a9f7e92..0c846c9 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-events</artifactId>
<name>Apache Tamaya Event and dynamic Update Extensions</name>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -62,5 +63,28 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.events,
+ org.apache.tamaya.events.delta,
+ org.apache.tamaya.events.folderobserver,
+ org.apache.tamaya.events..spi
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.events.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/formats/pom.xml
----------------------------------------------------------------------
diff --git a/modules/formats/pom.xml b/modules/formats/pom.xml
index c364a35..c8bfce4 100644
--- a/modules/formats/pom.xml
+++ b/modules/formats/pom.xml
@@ -27,6 +27,7 @@ under the License.
</parent>
<artifactId>tamaya-formats</artifactId>
<name>Apache Tamaya Format Services</name>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -62,4 +63,22 @@ under the License.
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.format,
+ org.apache.tamaya.format.formats
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/functions/pom.xml
----------------------------------------------------------------------
diff --git a/modules/functions/pom.xml b/modules/functions/pom.xml
index c56ca5c..7bc7b66 100644
--- a/modules/functions/pom.xml
+++ b/modules/functions/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-functions</artifactId>
<name>Apache Tamaya Common Functional Extensions</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -54,4 +54,22 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.functions
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/injection-api/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection-api/pom.xml b/modules/injection-api/pom.xml
new file mode 100644
index 0000000..89b1c67
--- /dev/null
+++ b/modules/injection-api/pom.xml
@@ -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 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-extensions</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-injection-api</artifactId>
+ <name>Apache Tamaya Injection Support API</name>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ <geronimo-atinject-1.0-spec.version>1.0</geronimo-atinject-1.0-spec.version>
+ <geronimo-jcdi-1.1-spec.version>1.0</geronimo-jcdi-1.1-spec.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>${geronimo-atinject-1.0-spec.version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </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>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.inject.api
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/injection/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml
index 03a0b60..b5c87b3 100644
--- a/modules/injection/pom.xml
+++ b/modules/injection/pom.xml
@@ -27,7 +27,7 @@ under the License.
</parent>
<artifactId>tamaya-injection</artifactId>
<name>Apache Tamaya Injection Support</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -41,6 +41,11 @@ under the License.
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection-api</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${project.version}</version>
@@ -48,6 +53,11 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-events</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-resolver</artifactId>
<version>${project.version}</version>
<optional>true</optional>
@@ -69,4 +79,25 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.inject
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.inject.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/integration/cdi-se/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/pom.xml b/modules/integration/cdi-se/pom.xml
index 88e9690..b3d573b 100644
--- a/modules/integration/cdi-se/pom.xml
+++ b/modules/integration/cdi-se/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-cdi-se</artifactId>
<name>Apache Tamaya Modules Integration - CDI (Using SE Injection)</name>
+ <packaging>bundle</packaging>
<properties>
<owb.version>1.6.2</owb.version>
@@ -53,6 +54,22 @@ under the License.
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.integration.cdi,
+ org.apache.tamaya.integration.cdi.config,
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.integration.cdi.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
@@ -118,6 +135,7 @@ under the License.
<scope>test</scope>
</dependency>
</dependencies>
+
<profiles>
<profile>
<id>OWB</id>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/integration/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/pom.xml b/modules/integration/cdi/pom.xml
index 2ebcc6b..eabf30e 100644
--- a/modules/integration/cdi/pom.xml
+++ b/modules/integration/cdi/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-cdi</artifactId>
<name>Apache Tamaya Modules Integration - CDI (Java EE)</name>
+ <packaging>bundle</packaging>
<properties>
<owb.version>1.6.2</owb.version>
@@ -56,10 +57,27 @@ under the License.
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.integration.cdi
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection-api</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -75,7 +93,6 @@ under the License.
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Activator.java b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Activator.java
index 6ab5ace..7da7e77 100644
--- a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Activator.java
+++ b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Activator.java
@@ -45,8 +45,7 @@ public class Activator implements BundleActivator {
String ranking = context.getProperty(SERVICE_RANKING_PROP);
if (ranking == null) {
props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING);
- }
- else{
+ } else{
props.put(Constants.SERVICE_RANKING, Integer.valueOf(ranking));
}
TamayaConfigAdminImpl cm = new TamayaConfigAdminImpl(context);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
index c9c7f00..649661c 100644
--- a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
+++ b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
@@ -55,8 +55,7 @@ public class TamayaConfigAdminImpl implements ConfigurationAdmin {
Configuration config = getConfiguration(pid);
if(config==null){
service.updated(null);
- }
- else{
+ } else{
service.updated(config.getProperties());
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/integration/spring/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/spring/pom.xml b/modules/integration/spring/pom.xml
index f98d44b..bfad9a6 100644
--- a/modules/integration/spring/pom.xml
+++ b/modules/integration/spring/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-spring</artifactId>
<name>Apache Tamaya Modules Integration - Spring</name>
+ <packaging>bundle</packaging>
<properties>
<spring.version>4.2.1.RELEASE</spring.version>
@@ -48,6 +49,18 @@ under the License.
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.integration.spring
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/json/pom.xml
----------------------------------------------------------------------
diff --git a/modules/json/pom.xml b/modules/json/pom.xml
index 73c0102..78a88e6 100644
--- a/modules/json/pom.xml
+++ b/modules/json/pom.xml
@@ -28,6 +28,7 @@ under the License.
<artifactId>tamaya-json</artifactId>
<name>Apache Tamaya JSON Support</name>
+ <packaging>bundle</packaging>
<inceptionYear>2015</inceptionYear>
<properties>
@@ -54,22 +55,18 @@ under the License.
<artifactId>tamaya-formats</artifactId>
<version>${project.version}</version>
</dependency>
-
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.0_spec</artifactId>
</dependency>
-
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
</dependency>
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
-
<dependency>
<groupId>org.jboss.arquillian.daemon</groupId>
<artifactId>arquillian-daemon-container-managed</artifactId>
@@ -135,6 +132,18 @@ under the License.
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.json
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/management/pom.xml
----------------------------------------------------------------------
diff --git a/modules/management/pom.xml b/modules/management/pom.xml
index c8b3129..9442452 100644
--- a/modules/management/pom.xml
+++ b/modules/management/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-management</artifactId>
<name>Apache Tamaya Modules - Java Management Extensions</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -58,4 +58,21 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.management
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/model/pom.xml
----------------------------------------------------------------------
diff --git a/modules/model/pom.xml b/modules/model/pom.xml
index d36782b..b92aa6b 100644
--- a/modules/model/pom.xml
+++ b/modules/model/pom.xml
@@ -33,7 +33,7 @@ under the License.
<description>This extension module provides functionality to describe, document and
validate configuration during runtime.
</description>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -82,4 +82,25 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.model,
+ org.apache.tamaya.model.spi
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.model.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/optional/pom.xml
----------------------------------------------------------------------
diff --git a/modules/optional/pom.xml b/modules/optional/pom.xml
index 72a7e63..4204a12 100644
--- a/modules/optional/pom.xml
+++ b/modules/optional/pom.xml
@@ -32,7 +32,7 @@ under the License.
<description>This module provides a simple class that can be used as a single dependency for evaluating
configuration. It runs basically without Tamaya being on the classpath, but if available it
considers/uses Tamaya functionality.</description>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -58,4 +58,21 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.optional
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/remote/pom.xml
----------------------------------------------------------------------
diff --git a/modules/remote/pom.xml b/modules/remote/pom.xml
index 8b97441..68ae946 100644
--- a/modules/remote/pom.xml
+++ b/modules/remote/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-remote</artifactId>
<name>Apache Tamaya Remote PropertySource</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -56,4 +56,21 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.remote
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/resolver/pom.xml
----------------------------------------------------------------------
diff --git a/modules/resolver/pom.xml b/modules/resolver/pom.xml
index 0eef3d7..770dc9f 100644
--- a/modules/resolver/pom.xml
+++ b/modules/resolver/pom.xml
@@ -16,7 +16,8 @@ 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">
+<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>
@@ -27,7 +28,7 @@ under the License.
</parent>
<artifactId>tamaya-resolver</artifactId>
<name>Apache Tamaya Resolver Services</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -56,4 +57,25 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.resolver,
+ org.apache.tamaya.resolver.spi
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.resolver.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/resources/pom.xml
----------------------------------------------------------------------
diff --git a/modules/resources/pom.xml b/modules/resources/pom.xml
index 14f2677..25b11eb 100644
--- a/modules/resources/pom.xml
+++ b/modules/resources/pom.xml
@@ -27,7 +27,7 @@ under the License.
</parent>
<artifactId>tamaya-resources</artifactId>
<name>Apache Tamaya Resource Services</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -44,4 +44,24 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.resource
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.resource.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/server/pom.xml
----------------------------------------------------------------------
diff --git a/modules/server/pom.xml b/modules/server/pom.xml
index b7c7f86..7d1d360 100644
--- a/modules/server/pom.xml
+++ b/modules/server/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-server</artifactId>
<name>Apache Tamaya Modules: Server Extension</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -69,4 +69,25 @@ under the License.
<version>3.1.2</version>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.server,
+ org.apache.tamaya.server.spi
+ </Export-Package>
+ <Private-Package>
+ org.apache.tamaya.server.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/modules/spi-support/pom.xml
----------------------------------------------------------------------
diff --git a/modules/spi-support/pom.xml b/modules/spi-support/pom.xml
index 2b2d6b6..8c8e8ae 100644
--- a/modules/spi-support/pom.xml
+++ b/modules/spi-support/pom.xml
@@ -31,7 +31,7 @@ under the License.
<name> Apache Tamaya SPI Support Classes</name>
<description>Apache Tamaya Support Classes useful when implementing the Tamaya SPI or code independent of the core RI
implementation.</description>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<properties>
<jdkVersion>1.7</jdkVersion>
@@ -56,4 +56,21 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.tamaya.spisupport
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/collections/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/collections/pom.xml b/sandbox/collections/pom.xml
index 0ec3dda..d5ed30b 100644
--- a/sandbox/collections/pom.xml
+++ b/sandbox/collections/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-collections</artifactId>
<name>Apache Tamaya Modules - Collections Support</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -49,4 +49,27 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.tamaya.collections.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/integration/commons/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/integration/commons/pom.xml b/sandbox/integration/commons/pom.xml
index d3d1b85..8c04a41 100644
--- a/sandbox/integration/commons/pom.xml
+++ b/sandbox/integration/commons/pom.xml
@@ -28,7 +28,7 @@ under the License.
</parent>
<artifactId>commons</artifactId>
<name>Apache Tamaya Commons Configuration Integration</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -47,4 +47,29 @@ under the License.
<version>1.10</version>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ org.apache.tamaya.format,
+ org.apache.commons,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.tamaya.integration.commons
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/integration/store/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/integration/store/pom.xml b/sandbox/integration/store/pom.xml
index d755551..0e8a546 100644
--- a/sandbox/integration/store/pom.xml
+++ b/sandbox/integration/store/pom.xml
@@ -28,7 +28,7 @@ under the License.
<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>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -51,4 +51,30 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ org.apache.tamaya.events,
+ org.apache.tamaya.spisupport
+ javax.annotation,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.tamaya.integration.store,
+ org.apache.tamaya.integration.store.spi,
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/jodatime/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/jodatime/pom.xml b/sandbox/jodatime/pom.xml
index 268939f..98b13a6 100644
--- a/sandbox/jodatime/pom.xml
+++ b/sandbox/jodatime/pom.xml
@@ -31,6 +31,7 @@ under the License.
<artifactId>tamaya-jodatime</artifactId>
<name>Apache Tamaya Joda-Time Support</name>
+ <packaging>bundle</packaging>
<inceptionYear>2015</inceptionYear>
@@ -77,6 +78,30 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ org.jodatime,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.tamaya.jodatime
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/metamodels/simple/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/simple/pom.xml b/sandbox/metamodels/simple/pom.xml
index a806459..1d1b26b 100644
--- a/sandbox/metamodels/simple/pom.xml
+++ b/sandbox/metamodels/simple/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-metamodels-simple</artifactId>
<name>Apache Tamaya Modules Metamodels - Simple</name>
<description>Simple Tamaya Metamodel, e.g. feasible for SE commandline tools and simple use cases.</description>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -49,7 +49,7 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-items</artifactId>
+ <artifactId>tamaya-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -59,4 +59,28 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ org.apache.tamaya.format,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.tamaya.metamodel.simple
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/metamodels/staged/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/metamodels/staged/pom.xml b/sandbox/metamodels/staged/pom.xml
index 325e4ec..324ea5e 100644
--- a/sandbox/metamodels/staged/pom.xml
+++ b/sandbox/metamodels/staged/pom.xml
@@ -29,7 +29,7 @@ under the License.
<artifactId>tamaya-metamodel-staged</artifactId>
<name>Apache Tamaya Modules - Staged Configuration</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -65,4 +65,30 @@ under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ org.apache.tamaya.resources,
+ org.apache.tamaya.spisupport,
+ org.apache.tamaya.functions,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.tamaya.metamodel.simple
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/624fb484/sandbox/sysprops/pom.xml
----------------------------------------------------------------------
diff --git a/sandbox/sysprops/pom.xml b/sandbox/sysprops/pom.xml
index fba1d69..2fe0dd2 100644
--- a/sandbox/sysprops/pom.xml
+++ b/sandbox/sysprops/pom.xml
@@ -28,7 +28,7 @@ under the License.
</parent>
<artifactId>tamaya-sysprops</artifactId>
<name>Apache Tamaya - Configured Java SE System Properties</name>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<build>
<plugins>
@@ -44,6 +44,27 @@ under the License.
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.apache.tamaya,
+ org.apache.tamaya.spi,
+ org.apache.tamaya.resources,
+ org.apache.tamaya.spisupport,
+ org.apache.tamaya.functions,
+ javax.annotation,
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.tamaya.integration.se
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
</plugins>
</build>
[02/11] incubator-tamaya git commit: TAMAYA-123: Adding OSGI Support.
Posted by an...@apache.org.
TAMAYA-123: Adding OSGI Support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/bb9e0f99
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/bb9e0f99
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/bb9e0f99
Branch: refs/heads/master
Commit: bb9e0f99e5e201e3c91eaae97433e10f3a35478c
Parents: 624fb48
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:29:05 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:29:05 2015 +0200
----------------------------------------------------------------------
modules/integration/osgi/pom.xml | 32 +-------------------------------
pom.xml | 26 +++++++++++++++++++++++++-
2 files changed, 26 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb9e0f99/modules/integration/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/pom.xml b/modules/integration/osgi/pom.xml
index a8766dc..6bff679 100644
--- a/modules/integration/osgi/pom.xml
+++ b/modules/integration/osgi/pom.xml
@@ -33,7 +33,6 @@
<description>Tamaya Based ConfigAdmin Service</description>
<properties>
- <osgi.version>6.0.0</osgi.version>
<osgi.compendium.version>5.0.0</osgi.compendium.version>
<felix.plugin.version>2.5.4</felix.plugin.version>
</properties>
@@ -48,47 +47,18 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-SymbolicName>
- ${project.artifactId}
- </Bundle-SymbolicName>
<Bundle-Activator>
org.apache.tamaya.integration.karaf.Activator
</Bundle-Activator>
- <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
- <DynamicImport-Package>
- org.osgi.service.log;version="[1.3,2)"
- </DynamicImport-Package>
- <Import-Package>
- org.osgi.service.cm,
- org.osgi.framework,
- *
- </Import-Package>
<Export-Package>org.osgi.service.cm</Export-Package>
<Private-Package>
- org.tamaya.integration.osgi,
- org.apache.felix.utils.properties
+ org.tamaya.integration.osgi
</Private-Package>
- <Import-Service>
- </Import-Service>
<Export-Service>
org.osgi.service.cm.ConfigurationAdmin
</Export-Service>
</instructions>
</configuration>
- <executions>
- <execution>
- <id>cleanVersions</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>cleanVersions</goal>
- </goals>
- <configuration>
- <versions>
- <karaf.osgi.version>${osgi.version}</karaf.osgi.version>
- </versions>
- </configuration>
- </execution>
- </executions>
</plugin>
</plugins>
</build>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bb9e0f99/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3241efa..d479ffa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,6 +47,7 @@ under the License.
<commons-io.version>2.4</commons-io.version>
<findbugs.skip>false</findbugs.skip>
<jdkVersion>1.7</jdkVersion>
+ <osgi.version>6.0.0</osgi.version>
<maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel>
<maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel>
<maven.compile.optimize>false</maven.compile.optimize>
@@ -82,7 +83,6 @@ under the License.
<!-- Dependencies for site generation -->
<reflow-skin.version>1.1.1</reflow-skin.version>
-
</properties>
<licenses>
@@ -494,6 +494,30 @@ under the License.
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<inherited>true</inherited>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-DocURL>http://tamaya.incubator.apache.org</Bundle-DocURL>
+ <Bundle-SymbolicName>
+ ${project.groupId}.${project.artifactId}
+ </Bundle-SymbolicName>
+ <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
+ </instructions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>cleanVersions</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>cleanVersions</goal>
+ </goals>
+ <configuration>
+ <versions>
+ <karaf.osgi.version>${osgi.version}</karaf.osgi.version>
+ </versions>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
[03/11] incubator-tamaya git commit: TAMAYA-124: Unifying annotations
for SE and EE based injection.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/DefaultDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/DefaultDynamicValue.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/DefaultDynamicValue.java
new file mode 100644
index 0000000..2a74f5f
--- /dev/null
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/DefaultDynamicValue.java
@@ -0,0 +1,424 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.inject.api.BaseDynamicValue;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.InjectionUtils;
+import org.apache.tamaya.inject.api.WithPropertyConverter;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
+ * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the value.
+ * <h3>Implementation Details</h3>
+ * This class is
+ * <ul>
+ * <li>Serializable, when also the item stored is serializable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ *
+ * @param <T> The type of the value.
+ */
+final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
+
+ private static final long serialVersionUID = -2071172847144537443L;
+
+ /**
+ * The property name of the entry.
+ */
+ private String propertyName;
+ /**
+ * The keys to be resolved.
+ */
+ private String[] keys;
+ /**
+ * Back reference to the base configuration instance. This reference is used reevalaute the given property and
+ * compare the result with the previous value after a configuration change was triggered.
+ */
+ private Configuration configuration;
+ /**
+ * The target type of the property used to lookup a matching {@link PropertyConverter}.
+ * If null, {@code propertyConverter} is set and used instead.
+ */
+ private TypeLiteral<T> targetType;
+ /**
+ * The property converter to be applied, may be null. In the ladder case targetType is not null.
+ */
+ private PropertyConverter<T> propertyConverter;
+ /**
+ * Policy that defines how new values are applied, be default it is applied initially once, but never updated
+ * anymore.
+ */
+ private UpdatePolicy updatePolicy = UpdatePolicy.NEVER;
+ /**
+ * The current value, never null.
+ */
+ private transient T value;
+ /**
+ * The new value, or null.
+ */
+ private transient T newValue;
+ /**
+ * List of listeners that listen for changes.
+ */
+ private transient WeakList<PropertyChangeListener> listeners;
+
+ /**
+ * Constructor.
+ *
+ * @param propertyName the name of the fields' property/method.
+ * @param keys the keys of the property, not null.
+ * @param configuration the configuration, not null.
+ * @param targetType the target type, not null.
+ * @param propertyConverter the optional converter to be used.
+ */
+ private DefaultDynamicValue(String propertyName, Configuration configuration, TypeLiteral<T> targetType,
+ PropertyConverter<T> propertyConverter, List<String> keys) {
+ this.propertyName = Objects.requireNonNull(propertyName);
+ this.keys = keys.toArray(new String[keys.size()]);
+ this.configuration = Objects.requireNonNull(configuration);
+ this.propertyConverter = propertyConverter;
+ this.targetType = targetType;
+ this.value = evaluateValue();
+ }
+
+ public static DynamicValue of(Field annotatedField, Configuration configuration){
+ // Check for adapter/filter
+ Type targetType = annotatedField.getGenericType();
+ if (targetType == null) {
+ throw new ConfigException("Failed to evaluate target type for " + annotatedField.getAnnotatedType().getType().getTypeName()
+ + '.' + annotatedField.getName());
+ }
+ if (targetType instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) targetType;
+ Type[] types = pt.getActualTypeArguments();
+ if (types.length != 1) {
+ throw new ConfigException("Failed to evaluate target type for " + annotatedField.getAnnotatedType().getType().getTypeName()
+ + '.' + annotatedField.getName());
+ }
+ targetType = (Type) types[0];
+ }
+ PropertyConverter<?> propertyConverter = null;
+ WithPropertyConverter annot = annotatedField.getAnnotation(WithPropertyConverter.class);
+ if (annot != null) {
+ try {
+ propertyConverter = annot.value().newInstance();
+ } catch (Exception e) {
+ throw new ConfigException("Failed to instantiate annotated PropertyConverter on " +
+ annotatedField.getAnnotatedType().getType().getTypeName()
+ + '.' + annotatedField.getName(), e);
+ }
+ }
+ List<String> keys = InjectionUtils.getKeys(annotatedField);
+ return new DefaultDynamicValue(annotatedField.getName(), configuration,
+ TypeLiteral.of(targetType), propertyConverter, keys);
+ }
+
+ public static DynamicValue of(Method method, Configuration configuration){
+ // Check for adapter/filter
+ Type targetType = method.getGenericReturnType();
+ if (targetType == null) {
+ throw new ConfigException("Failed to evaluate target type for " + method.getDeclaringClass()
+ .getTypeName() + '.' + method.getName());
+ }
+ if (targetType instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) targetType;
+ Type[] types = pt.getActualTypeArguments();
+ if (types.length != 1) {
+ throw new ConfigException("Failed to evaluate target type for " + method.getDeclaringClass()
+ .getTypeName() + '.' + method.getName());
+ }
+ targetType = (Class) types[0];
+ }
+ PropertyConverter<Object> propertyConverter = null;
+ WithPropertyConverter annot = method.getAnnotation(WithPropertyConverter.class);
+ if (annot != null) {
+ try {
+ propertyConverter = (PropertyConverter<Object>) annot.value().newInstance();
+ } catch (Exception e) {
+ throw new ConfigException("Failed to instantiate annotated PropertyConverter on " +
+ method.getDeclaringClass().getTypeName()
+ + '.' + method.getName(), e);
+ }
+ }
+ return new DefaultDynamicValue<Object>(method.getName(),
+ configuration, TypeLiteral.of(targetType), propertyConverter, InjectionUtils.getKeys(method));
+ }
+
+
+ /**
+ * Commits a new value that has not been committed yet, make it the new value of the instance. On change any
+ * registered listeners will be triggered.
+ */
+ public void commit() {
+ synchronized (this) {
+ PropertyChangeEvent evt = new PropertyChangeEvent(this, propertyName, value,
+ newValue);
+ value = newValue;
+ newValue = null;
+ if (listeners != null) {
+ for (PropertyChangeListener consumer : listeners.get()) {
+ consumer.propertyChange(evt);
+ }
+ }
+ }
+ }
+
+ /**
+ * Discards a new value that was published. No listeners will be informed.
+ */
+ public void discard() {
+ newValue = null;
+ }
+
+
+ /**
+ * Access the {@link UpdatePolicy} used for updating this value.
+ *
+ * @return the update policy, never null.
+ */
+ public UpdatePolicy getUpdatePolicy() {
+ return updatePolicy;
+ }
+
+ /**
+ * Sets a new {@link UpdatePolicy}.
+ *
+ * @param updatePolicy the new policy, not null.
+ */
+ public void setUpdatePolicy(UpdatePolicy updatePolicy) {
+ this.updatePolicy = Objects.requireNonNull(updatePolicy);
+ }
+
+ /**
+ * Add a listener to be called as weak reference, when this value has been changed.
+ *
+ * @param l the listener, not null
+ */
+ public void addListener(PropertyChangeListener l) {
+ if (listeners == null) {
+ listeners = new WeakList<>();
+ }
+ listeners.add(l);
+ }
+
+ /**
+ * Removes a listener to be called, when this value has been changed.
+ *
+ * @param l the listner to be removed, not null
+ */
+ public void removeListener(PropertyChangeListener l) {
+ if (listeners != null) {
+ listeners.remove(l);
+ }
+ }
+
+ /**
+ * If a value is present in this {@code DynamicValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws ConfigException if there is no value present
+ * @see DefaultDynamicValue#isPresent()
+ */
+ public T get() {
+ return value;
+ }
+
+ /**
+ * Method to check for and apply a new value. Depending on the {@link UpdatePolicy}
+ * the value is immediately or deferred visible (or it may even be ignored completely).
+ *
+ * @return true, if a new value has been detected. The value may not be visible depending on the current
+ * {@link UpdatePolicy} in place.
+ */
+ public boolean updateValue() {
+ T newValue = evaluateValue();
+ if (Objects.equals(newValue, this.value)) {
+ return false;
+ }
+ switch (this.updatePolicy) {
+ case IMMEDIATE:
+ this.newValue = newValue;
+ commit();
+ break;
+ case LOG_AND_DISCARD:
+ Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue=" + newValue);
+ this.newValue = null;
+ break;
+ case NEVER:
+ this.newValue = null;
+ break;
+ case EXPLCIT:
+ default:
+ this.newValue = newValue;
+ break;
+ }
+ return true;
+ }
+
+ /**
+ * Evaluates the current value dynamically from the underlying configuration.
+ *
+ * @return the current actual value, or null.
+ */
+ public T evaluateValue() {
+ T value = null;
+
+ for (String key : keys) {
+ if (propertyConverter == null) {
+ value = configuration.get(key, targetType);
+ } else {
+ String source = configuration.get(key);
+ value = propertyConverter.convert(source);
+ }
+
+ if (value != null) {
+ break;
+ }
+ }
+
+ return value;
+ }
+
+ /**
+ * Access a new value that has not yet been committed.
+ *
+ * @return the uncommitted new value, or null.
+ */
+ public T getNewValue() {
+ T nv = newValue;
+ if (nv != null) {
+ return nv;
+ }
+ return null;
+ }
+
+
+ /**
+ * Serialization implementation that strips away the non serializable Optional part.
+ *
+ * @param oos the output stream
+ * @throws IOException if serialization fails.
+ */
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ oos.writeObject(getUpdatePolicy());
+ oos.writeObject(get());
+ }
+
+ /**
+ * Reads an instance from the input stream.
+ *
+ * @param ois the object input stream
+ * @throws IOException if deserialization fails.
+ * @throws ClassNotFoundException
+ */
+ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+ this.updatePolicy = (UpdatePolicy) ois.readObject();
+ if (isPresent()) {
+ this.value = (T) ois.readObject();
+ }
+ newValue = null;
+ }
+
+
+ /**
+ * Simple helper that allows keeping the listeners registered as weak references, hereby avoiding any
+ * memory leaks.
+ *
+ * @param <I> the type
+ */
+ private class WeakList<I> {
+ final List<WeakReference<I>> refs = new LinkedList<>();
+
+ /**
+ * Adds a new instance.
+ *
+ * @param t the new instance, not null.
+ */
+ void add(I t) {
+ refs.add(new WeakReference<>(t));
+ }
+
+ /**
+ * Removes a instance.
+ *
+ * @param t the instance to be removed.
+ */
+ void remove(I t) {
+ synchronized (refs) {
+ for (Iterator<WeakReference<I>> iterator = refs.iterator(); iterator.hasNext(); ) {
+ WeakReference<I> ref = iterator.next();
+ I instance = ref.get();
+ if (instance == null || instance == t) {
+ iterator.remove();
+ break;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Access a list (copy) of the current instances that were not discarded by the GC.
+ *
+ * @return the list of accessible items.
+ */
+ public List<I> get() {
+ synchronized (refs) {
+ List<I> res = new ArrayList<>();
+ for (Iterator<WeakReference<I>> iterator = refs.iterator(); iterator.hasNext(); ) {
+ WeakReference<I> ref = iterator.next();
+ I instance = ref.get();
+ if (instance == null) {
+ iterator.remove();
+ } else {
+ res.add(instance);
+ }
+ }
+ return res;
+ }
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/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
deleted file mode 100644
index f97524a..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/WithConfigOperator.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.integration.cdi;
-
-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/3beb5a44/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
deleted file mode 100644
index dbc9d33..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/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.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/3beb5a44/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
index 0853ec2..f0c117b 100644
--- 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
@@ -20,6 +20,8 @@ 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.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tomitribe.util.Duration;
@@ -47,6 +49,7 @@ public class ConfigurationProducerTest {
@Test
public void defaultValues() {
+ assertNotNull(allTypes);
assertEquals("defaultString", allTypes.getDefaultString());
assertEquals(new File("./"), allTypes.getDefaultFile());
assertEquals(new Duration("2 hours and 54 minutes"), allTypes.getDefaultDuration());
@@ -56,6 +59,7 @@ public class ConfigurationProducerTest {
@Test
public void actualPropertyValues() {
+ assertNotNull(allTypes);
assertEquals("hello", allTypes.getString());
assertEquals(new File("./conf"), allTypes.getFile());
assertEquals(new Duration("10 minutes and 57 seconds"), allTypes.getDuration());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/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
index 4be519b..afeeb84 100644
--- 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
@@ -16,6 +16,7 @@
*/
package org.apache.tamaya.integration.cdi;
+import org.apache.tamaya.inject.api.Config;
import org.tomitribe.util.Duration;
import javax.inject.Inject;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index 0d89231..d43d1c0 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -37,6 +37,7 @@ under the License.
<module>spi-support</module>
<module>events</module>
<module>formats</module>
+ <module>injection-api</module>
<module>injection</module>
<module>json</module>
<module>resolver</module>
[06/11] incubator-tamaya git commit: TAMAYA-114: Added additional
implementations shared by modules.
Posted by an...@apache.org.
TAMAYA-114: Added additional implementations shared by modules.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/051d75f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/051d75f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/051d75f3
Branch: refs/heads/master
Commit: 051d75f3f4f1bc60444be903b45b7cbf72798858
Parents: 3beb5a4
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:32:46 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:32:46 2015 +0200
----------------------------------------------------------------------
.../ctx/DefaultConfigurationContext.java | 256 -----------
.../clsupport/internal/ctx/EnumConverter.java | 67 ---
.../internal/ctx/PropertyConverterManager.java | 434 -------------------
.../spisupport/DefaultConfigurationContext.java | 256 +++++++++++
.../apache/tamaya/spisupport/EnumConverter.java | 67 +++
.../spisupport/PropertyConverterManager.java | 434 +++++++++++++++++++
6 files changed, 757 insertions(+), 757 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/051d75f3/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/DefaultConfigurationContext.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/DefaultConfigurationContext.java
deleted file mode 100644
index 978dbb7..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/DefaultConfigurationContext.java
+++ /dev/null
@@ -1,256 +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.clsupport.internal.ctx;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import javax.annotation.Priority;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Logger;
-
-/**
- * Default Implementation of a simple ConfigurationContext.
- */
-public class DefaultConfigurationContext implements ConfigurationContext {
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
- /**
- * Cubcomponent handling {@link 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);
- }
-
- /**
- * 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 comparing 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 comparing 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/051d75f3/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/EnumConverter.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/EnumConverter.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/EnumConverter.java
deleted file mode 100644
index a75de75..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/EnumConverter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.clsupport.internal.ctx;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to tge given enum type.
- * @param <T> the enum type.
- */
-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/051d75f3/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/PropertyConverterManager.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/PropertyConverterManager.java
deleted file mode 100644
index 848fe78..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ctx/PropertyConverterManager.java
+++ /dev/null
@@ -1,434 +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.clsupport.internal.ctx;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import javax.annotation.Priority;
-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.
- */
-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 = getPriority(o1) - getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
- };
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
- * annotation is present, a default priority is returned (1);
- * @param o the instance, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o){
- int prio = 1;
- Priority priority = o.getClass().getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-
- /**
- * Constructor.
- */
- public PropertyConverterManager() {
- this(true);
- }
-
- public PropertyConverterManager(boolean init) {
- if (init) {
- initConverters();
- }
- }
-
- /**
- * Registers the default converters provided out of the box.
- */
- protected void initConverters() {
- for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
- register(TypeLiteral.of(type), conv);
- }
- }
-
- /**
- * Registers a ew converter instance.
- *
- * @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
- */
- public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
- Objects.requireNonNull(converter);
- Lock writeLock = lock.writeLock();
- try {
- writeLock.lock();
- List converters = List.class.cast(this.converters.get(targetType));
- List<PropertyConverter<?>> newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- // evaluate transitive closure for all inherited supertypes and implemented interfaces
- // direct implemented interfaces
- for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- Class<?> superClass = targetType.getRawType().getSuperclass();
- while (superClass != null && !superClass.equals(Object.class)) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
- for (Class<?> ifaceType : superClass.getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- superClass = superClass.getSuperclass();
- }
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Allows to evaluate if a given target type is supported.
- *
- * @param targetType the target type, not null.
- * @return true, if a converter for the given type is registered, or a default one can be created.
- */
- public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
- if (converters.containsKey(targetType) || transitiveConverters.containsKey(targetType)) {
- return true;
- }
- return createDefaultPropertyConverter(targetType) != null;
- }
-
- /**
- * Get a map of all property converters currently registered. This will not contain the converters that
- * may be created, when an instance is adapted, which provides a String constructor or compatible
- * factory methods taking a single String instance.
- *
- * @return the current map of instantiated and registered converters.
- * @see #createDefaultPropertyConverter(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>() {
- 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 {
- constr.setAccessible(true);
- 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/051d75f3/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
new file mode 100644
index 0000000..8e9970c
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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 org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.annotation.Priority;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.logging.Logger;
+
+/**
+ * Default Implementation of a simple ConfigurationContext.
+ */
+public class DefaultConfigurationContext implements ConfigurationContext {
+ /** The logger used. */
+ private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
+ /**
+ * Cubcomponent handling {@link 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);
+ }
+
+ /**
+ * 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 comparing 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 comparing 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/051d75f3/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java
new file mode 100644
index 0000000..ffab266
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Converter, converting from String to tge given enum type.
+ * @param <T> the enum type.
+ */
+public class EnumConverter<T> implements PropertyConverter<T> {
+ private Logger LOG = Logger.getLogger(EnumConverter.class.getName());
+ private Class<T> enumType;
+ private Method factory;
+
+ public EnumConverter(Class<T> enumType) {
+ if (!Enum.class.isAssignableFrom(enumType)) {
+ throw new IllegalArgumentException("Not an Enum: " + enumType.getName());
+ }
+ this.enumType = Objects.requireNonNull(enumType);
+ try {
+ this.factory = enumType.getMethod("valueOf", String.class);
+ } catch (NoSuchMethodException e) {
+ throw new ConfigException("Uncovertible enum type without valueOf method found, please provide a custom " +
+ "PropertyConverter for: " + enumType.getName());
+ }
+ }
+
+ @Override
+ public T convert(String value) {
+ 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/051d75f3/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
new file mode 100644
index 0000000..28ea65f
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
@@ -0,0 +1,434 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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 org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.annotation.Priority;
+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.
+ */
+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 = getPriority(o1) - getPriority(o2);
+ if (prio < 0) {
+ return 1;
+ } else if (prio > 0) {
+ return -1;
+ } else {
+ return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
+ }
+ }
+ };
+
+ /**
+ * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
+ * annotation is present, a default priority is returned (1);
+ * @param o the instance, not null.
+ * @return a priority, by default 1.
+ */
+ public static int getPriority(Object o){
+ int prio = 1;
+ Priority priority = o.getClass().getAnnotation(Priority.class);
+ if (priority != null) {
+ prio = priority.value();
+ }
+ return prio;
+ }
+
+ /**
+ * Constructor.
+ */
+ public PropertyConverterManager() {
+ this(true);
+ }
+
+ public PropertyConverterManager(boolean init) {
+ if (init) {
+ initConverters();
+ }
+ }
+
+ /**
+ * Registers the default converters provided out of the box.
+ */
+ protected void initConverters() {
+ for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
+ Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
+ register(TypeLiteral.of(type), conv);
+ }
+ }
+
+ /**
+ * Registers a ew converter instance.
+ *
+ * @param targetType the target type, not null.
+ * @param converter the converter, not null.
+ * @param <T> the type.
+ */
+ public <T> void register(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
+ Objects.requireNonNull(converter);
+ Lock writeLock = lock.writeLock();
+ try {
+ writeLock.lock();
+ List converters = List.class.cast(this.converters.get(targetType));
+ List<PropertyConverter<?>> newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.converters.put(targetType, Collections.unmodifiableList(newConverters));
+ // evaluate transitive closure for all inherited supertypes and implemented interfaces
+ // direct implemented interfaces
+ for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
+ }
+ Class<?> superClass = targetType.getRawType().getSuperclass();
+ while (superClass != null && !superClass.equals(Object.class)) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
+ for (Class<?> ifaceType : superClass.getInterfaces()) {
+ converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
+ newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ Collections.sort(newConverters, PRIORITY_COMPARATOR);
+ this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
+ }
+ superClass = superClass.getSuperclass();
+ }
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Allows to evaluate if a given target type is supported.
+ *
+ * @param targetType the target type, not null.
+ * @return true, if a converter for the given type is registered, or a default one can be created.
+ */
+ public boolean isTargetTypeSupported(TypeLiteral<?> targetType) {
+ if (converters.containsKey(targetType) || transitiveConverters.containsKey(targetType)) {
+ return true;
+ }
+ return createDefaultPropertyConverter(targetType) != null;
+ }
+
+ /**
+ * Get a map of all property converters currently registered. This will not contain the converters that
+ * may be created, when an instance is adapted, which provides a String constructor or compatible
+ * factory methods taking a single String instance.
+ *
+ * @return the current map of instantiated and registered converters.
+ * @see #createDefaultPropertyConverter(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>() {
+ 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 {
+ constr.setAccessible(true);
+ 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;
+ }
+
+}
[07/11] incubator-tamaya git commit: TAMAYA-123: Adding OSGI Support:
had to move some aspects out of (non-accessible) internal packages.
Posted by an...@apache.org.
TAMAYA-123: Adding OSGI Support: had to move some aspects out of (non-accessible) internal packages.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7f0abb7c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7f0abb7c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7f0abb7c
Branch: refs/heads/master
Commit: 7f0abb7cac0f3d476c9e8822ee9fd4cccd49844b
Parents: 051d75f
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:33:48 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:33:48 2015 +0200
----------------------------------------------------------------------
.../clsupport/CLAwareConfigurationContext.java | 105 +++++++
.../tamaya/clsupport/CLAwareServiceContext.java | 246 +++++++++++++++
.../tamaya/clsupport/ServiceContainer.java | 311 +++++++++++++++++++
.../internal/CLAwareConfigurationContext.java | 106 -------
.../internal/CLAwareServiceContext.java | 247 ---------------
.../clsupport/internal/ServiceContainer.java | 311 -------------------
.../tamaya/clsupport/internal/package-info.java | 22 --
.../org.apache.tamaya.spi.ServiceContext | 2 +-
8 files changed, 663 insertions(+), 687 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java
new file mode 100644
index 0000000..47b78b2
--- /dev/null
+++ b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.clsupport;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spisupport.DefaultConfigurationContext;
+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.annotation.Priority;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * Default Implementation of a simple ConfigurationContext.
+ */
+@Priority(100)
+public class CLAwareConfigurationContext implements ConfigurationContext {
+
+ /** The logger used. */
+ private final static Logger LOG = Logger.getLogger(CLAwareConfigurationContext.class.getName());
+
+ private ContextManager contextManager = new ContextManager();
+
+
+ @Override
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ contextManager.getItemNoParent(true).addPropertySources(propertySourcesToAdd);
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return contextManager.getItemNoParent(true).getPropertySources();
+ }
+
+ @Override
+ public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ contextManager.getItemNoParent(true).addPropertyConverter(typeToConvert, propertyConverter);
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return contextManager.getItemNoParent(true).getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
+ return contextManager.getItemNoParent(true).getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return contextManager.getItemNoParent(true).getPropertyFilters();
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
+ return contextManager.getItemNoParent(true).getPropertyValueCombinationPolicy();
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ return contextManager.getItemNoParent(true).toBuilder();
+ }
+
+
+ /**
+ * Subcomponent managing {@link ConfigurationContext} instances, one per classloader.
+ */
+ private static final class ContextManager extends AbstractClassloaderAwareItemLoader<ConfigurationContext>{
+
+ @Override
+ protected ConfigurationContext createItem(ClassLoader classLoader) {
+ // Simply create a complete configuration manager for every classloader. Maybe we will optimize this at a
+ // later stage in the project but as for now it is the most simple working solution.
+ return new DefaultConfigurationContext();
+ }
+
+ @Override
+ protected void updateItem(ConfigurationContext currentItemSet, ClassLoader classLoader) {
+ // ignore, currently not supported.
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java
new file mode 100644
index 0000000..392d8b1
--- /dev/null
+++ b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.clsupport;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ServiceContext;
+
+import javax.annotation.Priority;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * This class implements a {@link ServiceContext}, which basically provides a similar loading mechanism as used
+ * by the {@link java.util.ServiceLoader}. Whereas the {@link java.util.ServiceLoader} only loads configurations
+ * and instances from one classloader, this loader manages configs found and the related instances for each
+ * classloader along the classloader hierarchies individually. It ensures instances are loaded on the classloader
+ * level, where they first are visible. Additionally it ensures the same configuration resource (and its
+ * declared services) are loaded multiple times, when going up the classloader hierarchy.<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.
+ */
+@Priority(10)
+public class CLAwareServiceContext extends AbstractClassloaderAwareItemLoader<ServiceContainer>
+ implements ServiceContext{
+
+ private static final Logger LOG = Logger.getLogger(CLAwareServiceContext.class.getName());
+
+ /**
+ * Default location for service loader files.
+ */
+ private static final String PREFIX = "META-INF/services/";
+
+ /**
+ * Constructor, using the current default classloader as defined by
+ * {@link AbstractClassloaderAwareItemLoader#getDefaultClassLoader()}.
+ */
+ public CLAwareServiceContext(){
+ super();
+ }
+
+ /**
+ * Constructor, using the given classloader.
+ * @param classLoader the target classloader for initializing of services, not null.
+ */
+ public CLAwareServiceContext(ClassLoader classLoader) {
+ super(classLoader);
+ }
+
+
+ /**
+ * Implementation that creates a {@link ServiceContainer}, which manages all configs and instances loaded
+ * for a given classloader.
+ * @param classLoader the classloader, not null.
+ * @return a new empty, {@link ServiceContainer} instance.
+ */
+ @Override
+ protected ServiceContainer createItem(ClassLoader classLoader) {
+ if(LOG.isLoggable(Level.INFO)) {
+ LOG.info("Loading services for classloader: " + classLoader);
+ }
+ return new ServiceContainer(classLoader);
+ }
+
+ @Override
+ protected void updateItem(ServiceContainer currentContainer, ClassLoader classLoader) {
+ // nothing to be done here, since we dont have a specific target type.
+ }
+
+ @Override
+ public int ordinal() {
+ return 10;
+ }
+
+ /**
+ * This method tries to evaluate the current singleton from the {@link ServiceContainer} attached to the
+ * current classloader. If not found the singleton instance is evaluated based on the priorities
+ * assigned for all known providers. The resulting instance is then cached and always returned as
+ * singleton instance fomr this loader, when the same current classloader instance is active.
+ * @param serviceType the service type.
+ * @param <T> the type
+ * @return the item found, or null.
+ */
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ return getService(serviceType, getDefaultClassLoader());
+ }
+
+ /**
+ * Evaluates the current singleton instance using the given classloader context.
+ * @param serviceType the service type.
+ * @param classLoader the classloader, not null.
+ * @param <T> the type
+ * @return the item found, or null.
+ */
+ public <T> T getService(Class<T> serviceType, ClassLoader classLoader) {
+ if(LOG.isLoggable(Level.INFO)) {
+ LOG.info("Evaluating services for classloader: " + classLoader);
+ }
+ ServiceContainer container = getItemNoParent(classLoader, true);
+ T singleton = container.getSingleton(serviceType);
+ if(singleton!=null){
+ if(LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Evaluated singleton of type " + serviceType.getName() + " to " + singleton);
+ }
+ return singleton;
+ }
+ Collection<? extends T> services = getServices(serviceType, classLoader);
+ if (services.isEmpty()) {
+ singleton = null;
+ } else {
+ singleton = getServiceWithHighestPriority(services, serviceType);
+ }
+ if(singleton!=null) {
+ container.setSingleton(serviceType, singleton);
+ }
+ if(LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Evaluated singleton of type " + serviceType.getName() + " to " + singleton);
+ }
+ return singleton;
+ }
+
+ /**
+ * Gets the services visible.
+ * @param serviceType
+ * the service type.
+ * @param <T> the type param
+ * @return the services visible for the current classloader.
+ */
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ return getServices(serviceType, AbstractClassloaderAwareItemLoader.getDefaultClassLoader());
+ }
+
+ /**
+ * Gets the services visible.
+ * @param serviceType the service type.
+ * @param classLoader the classloader
+ * @param <T> the type param
+ * @return the services visible for the current classloader.
+ */
+ public <T> List<T> getServices(Class<T> serviceType, ClassLoader classLoader) {
+ List<T> services = new ArrayList<>();
+ ClassLoader cl = classLoader;
+ List<ServiceContainer> containers = new ArrayList<>();
+ while(cl!=null) {
+ ServiceContainer container = getItemNoParent(cl, true);
+ containers.add(container);
+ cl = cl.getParent();
+ }
+ List<ServiceContainer> prevContainers = new ArrayList<>();
+ Collections.reverse(containers);
+ for(ServiceContainer container: containers) {
+ if (!container.isTypeLoaded(serviceType)) {
+ container.loadServices(serviceType, prevContainers);
+ }
+ services.addAll(container.getServices(serviceType));
+ prevContainers.add(container);
+ }
+ if(LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Evaluated services of type " + serviceType.getName() + " to " + services);
+ }
+ return services;
+ }
+
+ /**
+ * @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<? extends 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;
+ }
+
+ /**
+ * 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 = 0;
+ Priority priority = o.getClass().getAnnotation(Priority.class);
+ if (priority != null) {
+ prio = priority.value();
+ }
+ if(LOG.isLoggable(Level.FINEST)) {
+ LOG.finest("Evaluated priority for " + o.getClass().getName() + " to " + prio);
+ }
+ return prio;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/ServiceContainer.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/ServiceContainer.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/ServiceContainer.java
new file mode 100644
index 0000000..1eea749
--- /dev/null
+++ b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/ServiceContainer.java
@@ -0,0 +1,311 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the 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.clsupport;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.ref.WeakReference;
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceConfigurationError;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Created by Anatole on 08.09.2015.
+ */
+class ServiceContainer {
+
+ private static final Logger LOG = Logger.getLogger(ServiceContainer.class.getName());
+
+ private static final String PREFIX = "META-INF/services/";
+
+ // The access control context taken when the ServiceLoader is created
+ private final AccessControlContext acc;
+
+ private WeakReference<ClassLoader> classLoaderRef;
+
+ /**
+ * List current services loaded using this classloader, per class.
+ */
+ private final Map<Class<?>, Map<String, Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /**
+ * The cached singletons for the given classloader.
+ */
+ private final Map<Class, Object> singletons = new ConcurrentHashMap<>();
+
+ /**
+ * List current services loaded using this classloader, per class.
+ */
+ private final Map<Class, List<URL>> configsLoaded = new ConcurrentHashMap<>();
+
+ ServiceContainer(ClassLoader classLoader) {
+ acc = (System.getSecurityManager() != null) ? AccessController.getContext() : null;
+ this.classLoaderRef = new WeakReference<>(classLoader);
+ }
+
+ public ClassLoader getClassLoader() {
+ ClassLoader cl = classLoaderRef.get();
+ if (cl == null) {
+ throw new IllegalStateException("Classloader reference removed, not active anynire.");
+ }
+ return cl;
+ }
+
+
+ public <T> void loadServices(Class<?> type,
+ Collection<ServiceContainer> preceedingContainers) {
+ Map<String, Object> services = (Map<String, Object>) this.servicesLoaded.get(type);
+ if (services == null) {
+ services = new LinkedHashMap<>();
+ this.servicesLoaded.put(type, services);
+ }
+ loop:
+ for (URL config : getConfigs(type)) {
+ for (ServiceContainer cont : preceedingContainers) {
+ if (cont.getConfigs(type).contains(config)) {
+ LOG.finer("Ignoring already loaded config: " + config);
+ continue loop;
+ }
+ }
+ Collection<String> serviceNames = parse(type, config);
+ for (String s : serviceNames) {
+ for (ServiceContainer cont : preceedingContainers) {
+ if (cont.containsService(type, s)) {
+ LOG.finest("Ignoring duplicate service: " + s);
+ continue;
+ }
+ }
+ LOG.info("Loading component: " + s);
+ services.put(s, create(type, s));
+ }
+ }
+ }
+
+ private Collection<URL> getConfigs(Class<?> type) {
+ List<URL> result = this.configsLoaded.get(type);
+ if (result == null) {
+ ClassLoader cl = this.classLoaderRef.get();
+ if (cl == null) {
+ throw new IllegalStateException("CLassLoader dereferenced already.");
+ }
+ result = new ArrayList<>();
+ try {
+ Enumeration<URL> resources = cl.getResources(PREFIX + type.getName());
+ while (resources.hasMoreElements()) {
+ result.add(resources.nextElement());
+ }
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Failed to read service config for " + type.getName() + " from " + cl, e);
+ }
+ this.configsLoaded.put(type, result);
+ LOG.log(Level.FINE, "Found service config for " + type.getName() + ": " + result);
+ }
+ return result;
+ }
+
+ private boolean containsService(Class<?> type, String serviceClassName) {
+ Map<String, Object> services = servicesLoaded.get(type);
+ if (services == null) {
+ return false;
+ }
+ return services.containsKey(serviceClassName);
+ }
+
+
+ private <S> S create(Class<S> serviceType, String className) {
+ Class<?> c = null;
+ ClassLoader classLoader = getClassLoader();
+ try {
+ c = Class.forName(className, false, classLoader);
+ } catch (ClassNotFoundException x) {
+ fail(serviceType,
+ "Provider " + className + " not found");
+ }
+ if (!serviceType.isAssignableFrom(c)) {
+ fail(serviceType,
+ "Provider " + className + " not a subtype");
+ }
+ try {
+ S p = serviceType.cast(c.newInstance());
+ return p;
+ } catch (Throwable x) {
+ fail(serviceType,
+ "Provider " + className + " could not be instantiated",
+ x);
+ }
+ throw new Error(); // This cannot happen
+ }
+
+ public <T> Collection<T> getServices(Class<T> serviceType) {
+ Map<String, Object> services = this.servicesLoaded.get(serviceType);
+ if (services != null) {
+ return (Collection<T>) services.values();
+ }
+ return Collections.emptySet();
+ }
+
+ public boolean isTypeLoaded(Class<?> serviceType) {
+ return this.servicesLoaded.containsKey(serviceType);
+ }
+
+ public Collection<URL> load(Class<?> serviceType) {
+ return load(serviceType, Collection.class.cast(Collections.emptySet()));
+ }
+
+ public Collection<URL> load(Class<?> serviceType, Collection<URL> configsLoaded) {
+ List<URL> result = new ArrayList<>();
+ try {
+ Enumeration<URL> resources = getClassLoader().getResources(PREFIX + serviceType.getName());
+ while (resources.hasMoreElements()) {
+ URL res = resources.nextElement();
+ if (!configsLoaded.contains(res)) {
+ result.add(res);
+ }
+ }
+ return result;
+ } catch (Exception e) {
+ fail(serviceType, "Failed to load service config: " + PREFIX + serviceType.getName(), e);
+ }
+ return result;
+ }
+
+
+ // Parse a single line from the given configuration file, adding the name
+ // on the line to the names list.
+ //
+ private int parseLine(Class<?> serviceType, URL u, BufferedReader r, int lc,
+ List<String> names)
+ throws IOException, ServiceConfigurationError {
+ String ln = r.readLine();
+ if (ln == null) {
+ return -1;
+ }
+ int ci = ln.indexOf('#');
+ if (ci >= 0) {
+ ln = ln.substring(0, ci);
+ }
+ ln = ln.trim();
+ int n = ln.length();
+ if (n != 0) {
+ if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0)) {
+ fail(serviceType, u, lc, "Illegal configuration-file syntax");
+ }
+ int cp = ln.codePointAt(0);
+ if (!Character.isJavaIdentifierStart(cp)) {
+ fail(serviceType, u, lc, "Illegal provider-class name: " + ln);
+ }
+ for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
+ cp = ln.codePointAt(i);
+ if (!Character.isJavaIdentifierPart(cp) && (cp != '.')) {
+ fail(serviceType, u, lc, "Illegal provider-class name: " + ln);
+ }
+ }
+ Map<String, Object> services = this.servicesLoaded.get(serviceType);
+ if (services == null || !services.containsKey(ln) && !names.contains(ln)) {
+ names.add(ln);
+ }
+ }
+ return lc + 1;
+ }
+
+
+ // Parse the content of the given URL as a provider-configuration file.
+ //
+ // @param service
+ // The service type for which providers are being sought;
+ // used to construct error detail strings
+ //
+ // @param u
+ // The URL naming the configuration file to be parsed
+ //
+ // @return A (possibly empty) iterator that will yield the provider-class
+ // names in the given configuration file that are not yet members
+ // of the returned set
+ //
+ // @throws ServiceConfigurationError
+ // If an I/O error occurs while reading from the given URL, or
+ // if a configuration-file format error is detected
+ //
+ private Collection<String> parse(Class<?> service, URL u)
+ throws ServiceConfigurationError {
+ InputStream in = null;
+ BufferedReader r = null;
+ ArrayList<String> names = new ArrayList<>();
+ try {
+ in = u.openStream();
+ r = new BufferedReader(new InputStreamReader(in, "utf-8"));
+ int lc = 1;
+ while ((lc = parseLine(service, u, r, lc, names)) >= 0) {
+ // go ahead
+ }
+ } catch (IOException x) {
+ fail(service, "Error reading configuration file", x);
+ } finally {
+ try {
+ if (r != null) {
+ r.close();
+ }
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException y) {
+ fail(service, "Error closing configuration file", y);
+ }
+ }
+ return names;
+ }
+
+
+ private static void fail(Class<?> service, String msg, Throwable cause)
+ throws ServiceConfigurationError {
+ LOG.log(Level.SEVERE, "Failed to load: " + service.getName() + ": " + msg, cause);
+ }
+
+ private static void fail(Class<?> service, String msg)
+ throws ServiceConfigurationError {
+ LOG.log(Level.SEVERE, "Failed to load: " + service.getName() + ": " + msg);
+ }
+
+ private static void fail(Class<?> service, URL u, int line, String msg)
+ throws ServiceConfigurationError {
+ fail(service, u + ":" + line + ": " + msg);
+ }
+
+ public <T> T getSingleton(Class<T> serviceType) {
+ return (T) this.singletons.get(serviceType);
+ }
+
+ <T> void setSingleton(Class<T> type, T instance) {
+ LOG.info("Caching singleton for " + type.getName() + " and classloader: " +
+ getClassLoader().toString() + ": " + instance);
+ this.singletons.put(type, instance);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareConfigurationContext.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareConfigurationContext.java
deleted file mode 100644
index 8575393..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareConfigurationContext.java
+++ /dev/null
@@ -1,106 +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.clsupport.internal;
-
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.clsupport.AbstractClassloaderAwareItemLoader;
-import org.apache.tamaya.clsupport.internal.ctx.DefaultConfigurationContext;
-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.annotation.Priority;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * Default Implementation of a simple ConfigurationContext.
- */
-@Priority(100)
-public class CLAwareConfigurationContext implements ConfigurationContext {
-
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(CLAwareConfigurationContext.class.getName());
-
- private ContextManager contextManager = new ContextManager();
-
-
- @Override
- public void addPropertySources(PropertySource... propertySourcesToAdd) {
- contextManager.getItemNoParent(true).addPropertySources(propertySourcesToAdd);
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return contextManager.getItemNoParent(true).getPropertySources();
- }
-
- @Override
- public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- contextManager.getItemNoParent(true).addPropertyConverter(typeToConvert, propertyConverter);
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return contextManager.getItemNoParent(true).getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return contextManager.getItemNoParent(true).getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return contextManager.getItemNoParent(true).getPropertyFilters();
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
- return contextManager.getItemNoParent(true).getPropertyValueCombinationPolicy();
- }
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- return contextManager.getItemNoParent(true).toBuilder();
- }
-
-
- /**
- * Subcomponent managing {@link ConfigurationContext} instances, one per classloader.
- */
- private static final class ContextManager extends AbstractClassloaderAwareItemLoader<ConfigurationContext>{
-
- @Override
- protected ConfigurationContext createItem(ClassLoader classLoader) {
- // Simply create a complete configuration manager for every classloader. Maybe we will optimize this at a
- // later stage in the project but as for now it is the most simple working solution.
- return new DefaultConfigurationContext();
- }
-
- @Override
- protected void updateItem(ConfigurationContext currentItemSet, ClassLoader classLoader) {
- // ignore, currently not supported.
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareServiceContext.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareServiceContext.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareServiceContext.java
deleted file mode 100644
index 02caed0..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/CLAwareServiceContext.java
+++ /dev/null
@@ -1,247 +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.clsupport.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.clsupport.AbstractClassloaderAwareItemLoader;
-import org.apache.tamaya.spi.ServiceContext;
-
-import javax.annotation.Priority;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-
-/**
- * This class implements a {@link ServiceContext}, which basically provides a similar loading mechanism as used
- * by the {@link java.util.ServiceLoader}. Whereas the {@link java.util.ServiceLoader} only loads configurations
- * and instances from one classloader, this loader manages configs found and the related instances for each
- * classloader along the classloader hierarchies individually. It ensures instances are loaded on the classloader
- * level, where they first are visible. Additionally it ensures the same configuration resource (and its
- * declared services) are loaded multiple times, when going up the classloader hierarchy.<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.
- */
-@Priority(10)
-public class CLAwareServiceContext extends AbstractClassloaderAwareItemLoader<ServiceContainer>
- implements ServiceContext{
-
- private static final Logger LOG = Logger.getLogger(CLAwareServiceContext.class.getName());
-
- /**
- * Default location for service loader files.
- */
- private static final String PREFIX = "META-INF/services/";
-
- /**
- * Constructor, using the current default classloader as defined by
- * {@link AbstractClassloaderAwareItemLoader#getDefaultClassLoader()}.
- */
- public CLAwareServiceContext(){
- super();
- }
-
- /**
- * Constructor, using the given classloader.
- * @param classLoader the target classloader for initializing of services, not null.
- */
- public CLAwareServiceContext(ClassLoader classLoader) {
- super(classLoader);
- }
-
-
- /**
- * Implementation that creates a {@link ServiceContainer}, which manages all configs and instances loaded
- * for a given classloader.
- * @param classLoader the classloader, not null.
- * @return a new empty, {@link ServiceContainer} instance.
- */
- @Override
- protected ServiceContainer createItem(ClassLoader classLoader) {
- if(LOG.isLoggable(Level.INFO)) {
- LOG.info("Loading services for classloader: " + classLoader);
- }
- return new ServiceContainer(classLoader);
- }
-
- @Override
- protected void updateItem(ServiceContainer currentContainer, ClassLoader classLoader) {
- // nothing to be done here, since we dont have a specific target type.
- }
-
- @Override
- public int ordinal() {
- return 10;
- }
-
- /**
- * This method tries to evaluate the current singleton from the {@link ServiceContainer} attached to the
- * current classloader. If not found the singleton instance is evaluated based on the priorities
- * assigned for all known providers. The resulting instance is then cached and always returned as
- * singleton instance fomr this loader, when the same current classloader instance is active.
- * @param serviceType the service type.
- * @param <T> the type
- * @return the item found, or null.
- */
- @Override
- public <T> T getService(Class<T> serviceType) {
- return getService(serviceType, getDefaultClassLoader());
- }
-
- /**
- * Evaluates the current singleton instance using the given classloader context.
- * @param serviceType the service type.
- * @param classLoader the classloader, not null.
- * @param <T> the type
- * @return the item found, or null.
- */
- public <T> T getService(Class<T> serviceType, ClassLoader classLoader) {
- if(LOG.isLoggable(Level.INFO)) {
- LOG.info("Evaluating services for classloader: " + classLoader);
- }
- ServiceContainer container = getItemNoParent(classLoader, true);
- T singleton = container.getSingleton(serviceType);
- if(singleton!=null){
- if(LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Evaluated singleton of type " + serviceType.getName() + " to " + singleton);
- }
- return singleton;
- }
- Collection<? extends T> services = getServices(serviceType, classLoader);
- if (services.isEmpty()) {
- singleton = null;
- } else {
- singleton = getServiceWithHighestPriority(services, serviceType);
- }
- if(singleton!=null) {
- container.setSingleton(serviceType, singleton);
- }
- if(LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Evaluated singleton of type " + serviceType.getName() + " to " + singleton);
- }
- return singleton;
- }
-
- /**
- * Gets the services visible.
- * @param serviceType
- * the service type.
- * @param <T> the type param
- * @return the services visible for the current classloader.
- */
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- return getServices(serviceType, AbstractClassloaderAwareItemLoader.getDefaultClassLoader());
- }
-
- /**
- * Gets the services visible.
- * @param serviceType the service type.
- * @param classLoader the classloader
- * @param <T> the type param
- * @return the services visible for the current classloader.
- */
- public <T> List<T> getServices(Class<T> serviceType, ClassLoader classLoader) {
- List<T> services = new ArrayList<>();
- ClassLoader cl = classLoader;
- List<ServiceContainer> containers = new ArrayList<>();
- while(cl!=null) {
- ServiceContainer container = getItemNoParent(cl, true);
- containers.add(container);
- cl = cl.getParent();
- }
- List<ServiceContainer> prevContainers = new ArrayList<>();
- Collections.reverse(containers);
- for(ServiceContainer container: containers) {
- if (!container.isTypeLoaded(serviceType)) {
- container.loadServices(serviceType, prevContainers);
- }
- services.addAll(container.getServices(serviceType));
- prevContainers.add(container);
- }
- if(LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Evaluated services of type " + serviceType.getName() + " to " + services);
- }
- return services;
- }
-
- /**
- * @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<? extends 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;
- }
-
- /**
- * 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 = 0;
- Priority priority = o.getClass().getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- if(LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Evaluated priority for " + o.getClass().getName() + " to " + prio);
- }
- return prio;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ServiceContainer.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ServiceContainer.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ServiceContainer.java
deleted file mode 100644
index 713b292..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/ServiceContainer.java
+++ /dev/null
@@ -1,311 +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.clsupport.internal;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.ref.WeakReference;
-import java.net.URL;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceConfigurationError;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Created by Anatole on 08.09.2015.
- */
-class ServiceContainer {
-
- private static final Logger LOG = Logger.getLogger(ServiceContainer.class.getName());
-
- private static final String PREFIX = "META-INF/services/";
-
- // The access control context taken when the ServiceLoader is created
- private final AccessControlContext acc;
-
- private WeakReference<ClassLoader> classLoaderRef;
-
- /**
- * List current services loaded using this classloader, per class.
- */
- private final Map<Class<?>, Map<String, Object>> servicesLoaded = new ConcurrentHashMap<>();
- /**
- * The cached singletons for the given classloader.
- */
- private final Map<Class, Object> singletons = new ConcurrentHashMap<>();
-
- /**
- * List current services loaded using this classloader, per class.
- */
- private final Map<Class, List<URL>> configsLoaded = new ConcurrentHashMap<>();
-
- ServiceContainer(ClassLoader classLoader) {
- acc = (System.getSecurityManager() != null) ? AccessController.getContext() : null;
- this.classLoaderRef = new WeakReference<>(classLoader);
- }
-
- public ClassLoader getClassLoader() {
- ClassLoader cl = classLoaderRef.get();
- if (cl == null) {
- throw new IllegalStateException("Classloader reference removed, not active anynire.");
- }
- return cl;
- }
-
-
- public <T> void loadServices(Class<?> type,
- Collection<ServiceContainer> preceedingContainers) {
- Map<String, Object> services = (Map<String, Object>) this.servicesLoaded.get(type);
- if (services == null) {
- services = new LinkedHashMap<>();
- this.servicesLoaded.put(type, services);
- }
- loop:
- for (URL config : getConfigs(type)) {
- for (ServiceContainer cont : preceedingContainers) {
- if (cont.getConfigs(type).contains(config)) {
- LOG.finer("Ignoring already loaded config: " + config);
- continue loop;
- }
- }
- Collection<String> serviceNames = parse(type, config);
- for (String s : serviceNames) {
- for (ServiceContainer cont : preceedingContainers) {
- if (cont.containsService(type, s)) {
- LOG.finest("Ignoring duplicate service: " + s);
- continue;
- }
- }
- LOG.info("Loading component: " + s);
- services.put(s, create(type, s));
- }
- }
- }
-
- private Collection<URL> getConfigs(Class<?> type) {
- List<URL> result = this.configsLoaded.get(type);
- if (result == null) {
- ClassLoader cl = this.classLoaderRef.get();
- if (cl == null) {
- throw new IllegalStateException("CLassLoader dereferenced already.");
- }
- result = new ArrayList<>();
- try {
- Enumeration<URL> resources = cl.getResources(PREFIX + type.getName());
- while (resources.hasMoreElements()) {
- result.add(resources.nextElement());
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to read service config for " + type.getName() + " from " + cl, e);
- }
- this.configsLoaded.put(type, result);
- LOG.log(Level.FINE, "Found service config for " + type.getName() + ": " + result);
- }
- return result;
- }
-
- private boolean containsService(Class<?> type, String serviceClassName) {
- Map<String, Object> services = servicesLoaded.get(type);
- if (services == null) {
- return false;
- }
- return services.containsKey(serviceClassName);
- }
-
-
- private <S> S create(Class<S> serviceType, String className) {
- Class<?> c = null;
- ClassLoader classLoader = getClassLoader();
- try {
- c = Class.forName(className, false, classLoader);
- } catch (ClassNotFoundException x) {
- fail(serviceType,
- "Provider " + className + " not found");
- }
- if (!serviceType.isAssignableFrom(c)) {
- fail(serviceType,
- "Provider " + className + " not a subtype");
- }
- try {
- S p = serviceType.cast(c.newInstance());
- return p;
- } catch (Throwable x) {
- fail(serviceType,
- "Provider " + className + " could not be instantiated",
- x);
- }
- throw new Error(); // This cannot happen
- }
-
- public <T> Collection<T> getServices(Class<T> serviceType) {
- Map<String, Object> services = this.servicesLoaded.get(serviceType);
- if (services != null) {
- return (Collection<T>) services.values();
- }
- return Collections.emptySet();
- }
-
- public boolean isTypeLoaded(Class<?> serviceType) {
- return this.servicesLoaded.containsKey(serviceType);
- }
-
- public Collection<URL> load(Class<?> serviceType) {
- return load(serviceType, Collection.class.cast(Collections.emptySet()));
- }
-
- public Collection<URL> load(Class<?> serviceType, Collection<URL> configsLoaded) {
- List<URL> result = new ArrayList<>();
- try {
- Enumeration<URL> resources = getClassLoader().getResources(PREFIX + serviceType.getName());
- while (resources.hasMoreElements()) {
- URL res = resources.nextElement();
- if (!configsLoaded.contains(res)) {
- result.add(res);
- }
- }
- return result;
- } catch (Exception e) {
- fail(serviceType, "Failed to load service config: " + PREFIX + serviceType.getName(), e);
- }
- return result;
- }
-
-
- // Parse a single line from the given configuration file, adding the name
- // on the line to the names list.
- //
- private int parseLine(Class<?> serviceType, URL u, BufferedReader r, int lc,
- List<String> names)
- throws IOException, ServiceConfigurationError {
- String ln = r.readLine();
- if (ln == null) {
- return -1;
- }
- int ci = ln.indexOf('#');
- if (ci >= 0) {
- ln = ln.substring(0, ci);
- }
- ln = ln.trim();
- int n = ln.length();
- if (n != 0) {
- if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0)) {
- fail(serviceType, u, lc, "Illegal configuration-file syntax");
- }
- int cp = ln.codePointAt(0);
- if (!Character.isJavaIdentifierStart(cp)) {
- fail(serviceType, u, lc, "Illegal provider-class name: " + ln);
- }
- for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) {
- cp = ln.codePointAt(i);
- if (!Character.isJavaIdentifierPart(cp) && (cp != '.')) {
- fail(serviceType, u, lc, "Illegal provider-class name: " + ln);
- }
- }
- Map<String, Object> services = this.servicesLoaded.get(serviceType);
- if (services == null || !services.containsKey(ln) && !names.contains(ln)) {
- names.add(ln);
- }
- }
- return lc + 1;
- }
-
-
- // Parse the content of the given URL as a provider-configuration file.
- //
- // @param service
- // The service type for which providers are being sought;
- // used to construct error detail strings
- //
- // @param u
- // The URL naming the configuration file to be parsed
- //
- // @return A (possibly empty) iterator that will yield the provider-class
- // names in the given configuration file that are not yet members
- // of the returned set
- //
- // @throws ServiceConfigurationError
- // If an I/O error occurs while reading from the given URL, or
- // if a configuration-file format error is detected
- //
- private Collection<String> parse(Class<?> service, URL u)
- throws ServiceConfigurationError {
- InputStream in = null;
- BufferedReader r = null;
- ArrayList<String> names = new ArrayList<>();
- try {
- in = u.openStream();
- r = new BufferedReader(new InputStreamReader(in, "utf-8"));
- int lc = 1;
- while ((lc = parseLine(service, u, r, lc, names)) >= 0) {
- // go ahead
- }
- } catch (IOException x) {
- fail(service, "Error reading configuration file", x);
- } finally {
- try {
- if (r != null) {
- r.close();
- }
- if (in != null) {
- in.close();
- }
- } catch (IOException y) {
- fail(service, "Error closing configuration file", y);
- }
- }
- return names;
- }
-
-
- private static void fail(Class<?> service, String msg, Throwable cause)
- throws ServiceConfigurationError {
- LOG.log(Level.SEVERE, "Failed to load: " + service.getName() + ": " + msg, cause);
- }
-
- private static void fail(Class<?> service, String msg)
- throws ServiceConfigurationError {
- LOG.log(Level.SEVERE, "Failed to load: " + service.getName() + ": " + msg);
- }
-
- private static void fail(Class<?> service, URL u, int line, String msg)
- throws ServiceConfigurationError {
- fail(service, u + ":" + line + ": " + msg);
- }
-
- public <T> T getSingleton(Class<T> serviceType) {
- return (T) this.singletons.get(serviceType);
- }
-
- <T> void setSingleton(Class<T> type, T instance) {
- LOG.info("Caching singleton for " + type.getName() + " and classloader: " +
- getClassLoader().toString() + ": " + instance);
- this.singletons.put(type, instance);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/package-info.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/package-info.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/internal/package-info.java
deleted file mode 100644
index 3949b74..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/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 classloader support module.
- */
-package org.apache.tamaya.clsupport.internal;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7f0abb7c/modules/classloader-support/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/modules/classloader-support/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
index c3b6acd..7016afb 100644
--- a/modules/classloader-support/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
+++ b/modules/classloader-support/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.clsupport.internal.CLAwareServiceContext
+org.apache.tamaya.clsupport.CLAwareServiceContext
[09/11] incubator-tamaya git commit: TAMAYA-123: Adding OSGI Support:
fixed invalid export.
Posted by an...@apache.org.
TAMAYA-123: Adding OSGI Support: fixed invalid export.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/29d7ca71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/29d7ca71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/29d7ca71
Branch: refs/heads/master
Commit: 29d7ca710875d45348f0ff223d7d20f1e6d5c72d
Parents: 4cd97f9
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:35:53 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:35:53 2015 +0200
----------------------------------------------------------------------
modules/events/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/29d7ca71/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index 0c846c9..cf56fa3 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -75,7 +75,7 @@ under the License.
org.apache.tamaya.events,
org.apache.tamaya.events.delta,
org.apache.tamaya.events.folderobserver,
- org.apache.tamaya.events..spi
+ org.apache.tamaya.events.spi
</Export-Package>
<Private-Package>
org.apache.tamaya.events.internal
[04/11] incubator-tamaya git commit: TAMAYA-124: Unifying annotations
for SE and EE based injection.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java
deleted file mode 100644
index 19f9d74..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/WithLoadPolicy.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define how config changes are handled for a type or per property/template method.
- * @see LoadPolicy
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
-public @interface WithLoadPolicy {
-
- /**
- * The load policy to be used. If this annotation is present a load policy must be defined.
- * @return The load policy to be used, not null.
- */
- LoadPolicy value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithPropertyConverter.java
deleted file mode 100644
index f0c3796..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/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.inject;
-
-
-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})
-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/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
deleted file mode 100644
index a2b0f2a..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigChangeCallbackMethod.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject.internal;
-
-import org.apache.tamaya.event.PropertyChangeSet;
-
-import java.lang.reflect.Method;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class holds a method object that is annotated to be a callback method to be called on configuration
- * changes.
- */
-public final class ConfigChangeCallbackMethod {
-
- private static final Logger LOG = Logger.getLogger(ConfigChangeCallbackMethod.class.getName());
-
- private Method callbackMethod;
-
- public ConfigChangeCallbackMethod(Method methodCandidate) {
- if (void.class.equals(methodCandidate.getReturnType()) &&
- methodCandidate.getParameterCount() == 1 &&
- methodCandidate.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
- this.callbackMethod = methodCandidate;
- }
- }
-
- public PropertyChangeSetListener createConsumer(final Object instance) {
- return new PropertyChangeSetListener() {
- @Override
- public void propertyChange(PropertyChangeSet propertyChangeSet) {
- call(instance, propertyChangeSet);
- }
- };
- }
-
- public void call(Object instance, PropertyChangeSet configChangeEvent) {
- try {
- callbackMethod.setAccessible(true);
- callbackMethod.invoke(instance, configChangeEvent);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error calling ConfigChange callback method " +
- callbackMethod.getDeclaringClass().getName() + '.' + callbackMethod.getName() + " on " + instance,
- e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
index b2fec95..061eaad 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfigTemplateInvocationHandler.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.inject.DynamicValue;
+import org.apache.tamaya.inject.api.DynamicValue;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -72,8 +72,8 @@ public final class ConfigTemplateInvocationHandler implements InvocationHandler
if (method.getReturnType() == DynamicValue.class) {
return DefaultDynamicValue.of(method, configuration);
}
- String configValue = InjectionUtils.getConfigValue(method);
- Object result = InjectionUtils.adaptValue(method, TypeLiteral.of(method.getReturnType()), configValue);
+ String configValue = InjectionHelper.getConfigValue(method);
+ Object result = InjectionHelper.adaptValue(method, TypeLiteral.of(method.getReturnType()), configValue);
if (result == null && method.isDefault()) {
result = method.getDefaultValue();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
index e824589..21122ff 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -21,7 +21,8 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.inject.DynamicValue;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.InjectionUtils;
import java.lang.reflect.Field;
import java.security.AccessController;
@@ -100,14 +101,14 @@ public class ConfiguredField {
private void applyValue(Object target,boolean resolve) throws ConfigException {
Objects.requireNonNull(target);
try {
- String configValue = InjectionUtils.getConfigValue(this.annotatedField);
+ String configValue = InjectionHelper.getConfigValue(this.annotatedField);
// Next step perform expression resolution, if any
String evaluatedValue = resolve && configValue != null
- ? InjectionUtils.evaluateValue(configValue)
+ ? InjectionHelper.evaluateValue(configValue)
: configValue;
// Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.annotatedField, TypeLiteral.of(this.annotatedField.getType()), evaluatedValue);
+ Object value = InjectionHelper.adaptValue(this.annotatedField, TypeLiteral.of(this.annotatedField.getType()), evaluatedValue);
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 6eb6e74..ca4e21c 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.inject.api.InjectionUtils;
import java.lang.reflect.Method;
import java.security.AccessController;
@@ -59,15 +60,15 @@ public class ConfiguredSetterMethod {
* @throws ConfigException if evaluation or conversion failed.
*/
public void applyValue(Object target, boolean resolve) throws ConfigException {
- String configValue = InjectionUtils.getConfigValue(this.setterMethod);
+ String configValue = InjectionHelper.getConfigValue(this.setterMethod);
Objects.requireNonNull(target);
try {
String evaluatedString = resolve && configValue != null
- ? InjectionUtils.evaluateValue(configValue)
+ ? InjectionHelper.evaluateValue(configValue)
: configValue;
// Check for adapter/filter
- Object value = InjectionUtils.adaptValue(this.setterMethod, TypeLiteral.of(this.setterMethod.getParameterTypes()[0]), evaluatedString);
+ Object value = InjectionHelper.adaptValue(this.setterMethod, TypeLiteral.of(this.setterMethod.getParameterTypes()[0]), evaluatedString);
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
index 10856d2..85a432c 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredType.java
@@ -26,11 +26,9 @@ import java.util.logging.Logger;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.inject.ConfigAutoInject;
-import org.apache.tamaya.inject.ConfigDefaultSections;
-import org.apache.tamaya.inject.Config;
import org.apache.tamaya.inject.NoConfig;
-import org.apache.tamaya.event.ObservesConfigChange;
-import org.apache.tamaya.event.PropertyChangeSet;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
/**
* Structure that contains and manages configuration related things for a configured type registered.
@@ -49,10 +47,6 @@ public class ConfiguredType {
*/
private List<ConfiguredSetterMethod> configuredSetterMethods = new ArrayList<>();
/**
- * A list with all callback methods listening to config changes.
- */
- private List<ConfigChangeCallbackMethod> callbackMethods = new ArrayList<>();
- /**
* The basic type.
*/
private Class type;
@@ -123,28 +117,10 @@ public class ConfiguredType {
continue;
}
if(isConfiguredMethod(m) || autoConfigure) {
- ObservesConfigChange observesAnnot = m.getAnnotation(ObservesConfigChange.class);
Config propAnnot = m.getAnnotation(Config.class);
- if (type.isInterface()) {
- // it is a template
- if (observesAnnot != null && m.isDefault()) {
- if (addObserverMethod(m)) {
- LOG.finer("Added configured observer for template: " + m.getClass().getName() + "#" +
- m.toGenericString());
- }
- }
- } else {
- if (observesAnnot != null) {
- if (addObserverMethod(m)) {
- LOG.finer("Added configured observer: " + m.getClass().getName() + "#" +
- m.toGenericString());
- }
- } else {
- if (addPropertySetter(m, propAnnot)) {
- LOG.finer("Added configured setter: " + m.getClass().getName() + "#" +
- m.toGenericString());
- }
- }
+ if (addPropertySetter(m, propAnnot)) {
+ LOG.finer("Added configured setter: " + m.getClass().getName() + "#" +
+ m.toGenericString());
}
}
}
@@ -170,27 +146,6 @@ public class ConfiguredType {
}
-
- private boolean addObserverMethod(Method m) {
- if (m.getParameterTypes().length != 1) {
- return false;
- }
- if (!m.getParameterTypes()[0].equals(PropertyChangeSet.class)) {
- return false;
- }
- if (!void.class.equals(m.getReturnType())) {
- return false;
- }
- try {
- this.callbackMethods.add(new ConfigChangeCallbackMethod(m));
- return true;
- } catch (Exception e) {
- throw new ConfigException("Failed to initialized configured callback method: " +
- m.getDeclaringClass().getName() + '.' + m.getName(), e);
- }
- }
-
-
/**
* Method called to configure an instance.
*
@@ -203,11 +158,6 @@ public class ConfiguredType {
for (ConfiguredSetterMethod method : configuredSetterMethods) {
method.applyValue(instance, true);
// // TODO, if method should be recalled on changes, corresponding callbacks could be registered here
-// WeakConfigListenerManager.of().registerConsumer(instance, method.createConsumer(instance));
- }
- // Register callbacks for this instance (weakly)
- for (ConfigChangeCallbackMethod callback : callbackMethods) {
- WeakConfigListenerManager.of().registerConsumer(instance, callback.createConsumer(instance));
}
}
@@ -259,14 +209,6 @@ public class ConfiguredType {
return configuredSetterMethods;
}
- /**
- * Get the registered annotated callback methods.
- * @return the registered annotated callback methods, never null.
- */
- public Collection<ConfigChangeCallbackMethod> getObserverMethods(){
- return callbackMethods;
- }
-
@Override
public String toString() {
return "ConfigDefaultSections{"+ this.getType().getName() + '}';
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
index 2e50217..e6ed12b 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -19,9 +19,6 @@
package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.event.ObservesConfigChange;
-import org.apache.tamaya.inject.ConfigDefaultSections;
-import org.apache.tamaya.inject.Config;
import org.apache.tamaya.inject.ConfigurationInjector;
import javax.annotation.Priority;
@@ -33,8 +30,10 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
-import org.apache.tamaya.inject.ConfiguredItemSupplier;
+import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
import org.apache.tamaya.inject.NoConfig;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
/**
* Simple injector singleton that also registers instances configured using weak references.
@@ -73,18 +72,12 @@ public final class DefaultConfigurationInjector implements ConfigurationInjector
return true;
}
for (Field f : type.getDeclaredFields()) {
- if (f.isAnnotationPresent(NoConfig.class)) {
- return true;
- }
- if (f.isAnnotationPresent(ObservesConfigChange.class) || f.isAnnotationPresent(Config.class)) {
+ if (f.isAnnotationPresent(NoConfig.class) || f.isAnnotationPresent(Config.class)) {
return true;
}
}
for (Method m : type.getDeclaredMethods()) {
- if (m.isAnnotationPresent(NoConfig.class)) {
- return true;
- }
- if (m.isAnnotationPresent(ObservesConfigChange.class) || m.isAnnotationPresent(Config.class)) {
+ if (m.isAnnotationPresent(NoConfig.class) || m.isAnnotationPresent(Config.class)) {
return true;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
index 9da9c6d..46a4bb1 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
@@ -20,18 +20,18 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.ConfiguredItemSupplier;
-import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.inject.DynamicValue;
-import org.apache.tamaya.inject.WithPropertyConverter;
+import org.apache.tamaya.inject.api.BaseDynamicValue;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.InjectionUtils;
+import org.apache.tamaya.inject.api.WithPropertyConverter;
+import org.apache.tamaya.spi.PropertyConverter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -58,7 +58,7 @@ import java.util.logging.Logger;
*
* @param <T> The type of the value.
*/
-public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializable {
+public final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
private static final long serialVersionUID = -2071172847144537443L;
@@ -112,7 +112,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @param propertyConverter the optional converter to be used.
*/
private DefaultDynamicValue(String propertyName, Configuration configuration, TypeLiteral<T> targetType,
- PropertyConverter<T> propertyConverter, List<String> keys) {
+ PropertyConverter<T> propertyConverter, List<String> keys) {
this.propertyName = Objects.requireNonNull(propertyName);
this.keys = keys.toArray(new String[keys.size()]);
this.configuration = Objects.requireNonNull(configuration);
@@ -121,7 +121,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
this.value = evaluateValue();
}
- public static DynamicValue of(Field annotatedField, Configuration configuration){
+ public static DynamicValue of(Field annotatedField, Configuration configuration) {
// Check for adapter/filter
Type targetType = annotatedField.getGenericType();
if (targetType == null) {
@@ -153,7 +153,7 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
TypeLiteral.of(targetType), propertyConverter, keys);
}
- public static DynamicValue of(Method method, Configuration configuration){
+ public static DynamicValue of(Method method, Configuration configuration) {
// Check for adapter/filter
Type targetType = method.getGenericReturnType();
if (targetType == null) {
@@ -184,17 +184,6 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
configuration, TypeLiteral.of(targetType), propertyConverter, InjectionUtils.getKeys(method));
}
- /**
- * Performs a commit, if necessary, and returns the current value.
- *
- * @return the non-null value held by this {@code DynamicValue}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- * @see DefaultDynamicValue#isPresent()
- */
- public T commitAndGet() {
- commit();
- return get();
- }
/**
* Commits a new value that has not been committed yet, make it the new value of the instance. On change any
@@ -284,25 +273,27 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
*/
public boolean updateValue() {
T newValue = evaluateValue();
- if (Objects.equals(newValue, this.value)) {
- return false;
- }
- switch (this.updatePolicy) {
- case IMMEDIATE:
- this.newValue = newValue;
- commit();
- break;
- case LOG_AND_DISCARD:
- Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue=" + newValue);
- this.newValue = null;
- break;
- case NEVER:
- this.newValue = null;
- break;
- case EXPLCIT:
- default:
- this.newValue = newValue;
- break;
+ synchronized (this) {
+ if (Objects.equals(newValue, this.value)) {
+ return false;
+ }
+ switch (this.updatePolicy) {
+ case IMMEDIATE:
+ this.newValue = newValue;
+ commit();
+ break;
+ case LOG_AND_DISCARD:
+ Logger.getLogger(getClass().getName()).info("Discard change on " + this + ", newValue=" + newValue);
+ this.newValue = null;
+ break;
+ case NEVER:
+ this.newValue = null;
+ break;
+ case EXPLCIT:
+ default:
+ this.newValue = newValue;
+ break;
+ }
}
return true;
}
@@ -344,69 +335,6 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
return null;
}
- /**
- * Return {@code true} if there is a value present, otherwise {@code false}.
- *
- * @return {@code true} if there is a value present, otherwise {@code false}
- */
- public boolean isPresent() {
- return value != null;
- }
-
-
- /**
- * Return the value if present, otherwise return {@code other}.
- *
- * @param other the value to be returned if there is no value present, may
- * be null
- * @return the value, if present, otherwise {@code other}
- */
- public T orElse(T other) {
- if (value == null) {
- return other;
- }
- return value;
- }
-
- /**
- * Return the value if present, otherwise invoke {@code other} and return
- * the result of that invocation.
- *
- * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
- * is present
- * @return the value if present otherwise the result of {@code other.get()}
- * @throws NullPointerException if value is not present and {@code other} is
- * null
- */
- public T orElseGet(ConfiguredItemSupplier<? extends T> other) {
- if (value == null) {
- return other.get();
- }
- return value;
- }
-
- /**
- * Return the contained value, if present, otherwise throw an exception
- * to be created by the provided supplier.
- * <p>
- * NOTE A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
- * {@code IllegalStateException::new}
- *
- * @param <X> Type of the exception to be thrown
- * @param exceptionSupplier The supplier which will return the exception to
- * be thrown
- * @return the present value
- * @throws X if there is no value present
- * @throws NullPointerException if no value is present and
- * {@code exceptionSupplier} is null
- */
- public <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X {
- if (value == null) {
- throw exceptionSupplier.get();
- }
- return value;
- }
/**
* Serialization implementation that strips away the non serializable Optional part.
@@ -415,11 +343,9 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @throws java.io.IOException if serialization fails.
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
- oos.writeObject(updatePolicy);
- if (isPresent()) {
- oos.writeObject(this.value);
- } else {
- oos.writeObject(null);
+ synchronized (this) {
+ oos.writeObject(getUpdatePolicy());
+ oos.writeObject(get());
}
}
@@ -431,11 +357,13 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>, Serializab
* @throws ClassNotFoundException
*/
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
- this.updatePolicy = (UpdatePolicy) ois.readObject();
- if (isPresent()) {
- this.value = (T) ois.readObject();
+ synchronized (this) {
+ this.updatePolicy = (UpdatePolicy) ois.readObject();
+ if (isPresent()) {
+ this.value = (T) ois.readObject();
+ }
+ newValue = null;
}
- newValue = null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
new file mode 100644
index 0000000..9550a71
--- /dev/null
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject.internal;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+import org.apache.tamaya.inject.api.InjectionUtils;
+import org.apache.tamaya.inject.api.WithPropertyConverter;
+import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+
+/**
+ * Utility class containing several aspects used in this module.
+ */
+@SuppressWarnings("unchecked")
+final class InjectionHelper {
+
+ private static final Logger LOG = Logger.getLogger(InjectionHelper.class.getName());
+
+ private static final boolean RESOLUTION_MODULE_LOADED = checkResolutionModuleLoaded();
+
+ private static boolean checkResolutionModuleLoaded() {
+ try {
+ Class.forName("org.apache.tamaya.resolver.internal.DefaultExpressionEvaluator");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
+ private InjectionHelper() {
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ public static String getConfigValue(Method method) {
+ ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
+ return getConfigValueInternal(method, areasAnnot);
+ }
+
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ public static String getConfigValue(Field field) {
+ ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
+ return getConfigValueInternal(field, areasAnnot);
+ }
+
+ /**
+ * Internally evaluated the current valid configuration keys based on the given annotations present.
+ *
+ * @return the keys to be returned, or null.
+ */
+ private static String getConfigValueInternal(AnnotatedElement element, ConfigDefaultSections areasAnnot) {
+ Config prop = element.getAnnotation(Config.class);
+ ConfigDefault defaultAnnot = element.getAnnotation(ConfigDefault.class);
+ List<String> keys;
+ if (prop == null) {
+ keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot);
+ } else {
+ keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
+ }
+ String configValue = evaluteConfigValue(keys);
+ if (configValue == null && defaultAnnot != null) {
+ return defaultAnnot.value();
+ }
+ return configValue;
+ }
+
+
+ private static String evaluteConfigValue(List<String> keys) {
+ String configValue = null;
+ for (String key : keys) {
+ configValue = ConfigurationProvider.getConfiguration().get(key);
+ if (configValue != null) {
+ break;
+ }
+ }
+ return configValue;
+ }
+
+
+ @SuppressWarnings("rawtypes")
+ public static <T> T adaptValue(AnnotatedElement element, TypeLiteral<T> targetType, String configValue) {
+ // Check for adapter/filter
+ T adaptedValue = null;
+ WithPropertyConverter converterAnnot = element.getAnnotation(WithPropertyConverter.class);
+ Class<? extends PropertyConverter<T>> converterType;
+ if (converterAnnot != null) {
+ converterType = (Class<? extends PropertyConverter<T>>) converterAnnot.value();
+ if (!converterType.getName().equals(WithPropertyConverter.class.getName())) {
+ try {
+ // TODO cache here...
+ PropertyConverter<T> converter = PropertyConverter.class.cast(converterType.newInstance());
+ adaptedValue = converter.convert(configValue);
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Failed to convert using explicit PropertyConverter on " + element +
+ ", trying default conversion.", e);
+ }
+ }
+ }
+ if (adaptedValue != null) {
+ return adaptedValue;
+ }
+ if (String.class == targetType.getType()) {
+ return (T) configValue;
+ } else {
+ List<PropertyConverter<T>> converters = ConfigurationProvider.getConfigurationContext()
+ .getPropertyConverters(targetType);
+ for (PropertyConverter<T> converter : converters) {
+ adaptedValue = converter.convert(configValue);
+ if (adaptedValue != null) {
+ return adaptedValue;
+ }
+ }
+ throw new ConfigException("Non convertible property type: " + element);
+ }
+ }
+
+ /**
+ * Method that allows to statically check, if the resolver module is loaded. If the module is loaded
+ * value expressions are automatically forwarded to the resolver module for resolution.
+ *
+ * @return true, if the resolver module is on the classpath.
+ */
+ public static boolean isResolutionModuleLoaded() {
+ return RESOLUTION_MODULE_LOADED;
+ }
+
+ /**
+ * Evaluates the given expression.
+ *
+ * @param expression the expression, not null.
+ * @return
+ */
+ public static String evaluateValue(String expression) {
+ if (!RESOLUTION_MODULE_LOADED) {
+ return expression;
+ }
+ ExpressionEvaluator evaluator = ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class);
+ if (evaluator != null) {
+ return evaluator.evaluateExpression("<injection>", expression);
+ }
+ return expression;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
deleted file mode 100644
index af3fe19..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject.internal;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.inject.ConfigDefaultSections;
-import org.apache.tamaya.inject.Config;
-import org.apache.tamaya.inject.ConfigDefault;
-import org.apache.tamaya.inject.WithPropertyConverter;
-import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-
-/**
- * Utility class containing several aspects used in this module.
- */
-@SuppressWarnings("unchecked")
-final class InjectionUtils {
-
- private static final Logger LOG = Logger.getLogger(InjectionUtils.class.getName());
-
- private static final boolean RESOLUTION_MODULE_LOADED = checkResolutionModuleLoaded();
-
- private static boolean checkResolutionModuleLoaded() {
- try {
- Class.forName("org.apache.tamaya.resolver.internal.DefaultExpressionEvaluator");
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
- }
-
- private InjectionUtils() {
- }
-
- /**
- * Evaluates all absolute configuration key based on the annotations found on a class.
- *
- * @param areasAnnot the (optional) annotation definining areas to be looked up.
- * @param propertyAnnotation the annotation on field/method level that may defined one or
- * several keys to be looked up (in absolute or relative form).
- * @return the list current keys in order how they should be processed/looked up.
- */
- public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot, Config propertyAnnotation) {
- if(propertyAnnotation==null){
- return evaluateKeys(member, areasAnnot);
- }
- List<String> keys = new ArrayList<>(Arrays.asList(propertyAnnotation.keys()));
- if (keys.isEmpty()) {
- keys.add(member.getName());
- }
- ListIterator<String> iterator = keys.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 (areasAnnot != null && areasAnnot.value().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 : areasAnnot.value()) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return keys;
- }
-
- /**
- * Evaluates all absolute configuration key based on the member name found.
- *
- * @param areasAnnot the (optional) annotation definining areas to be looked up.
- * @return the list current keys in order how they should be processed/looked up.
- */
- public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot) {
- List<String> keys = new ArrayList<>();
- String name = member.getName();
- String mainKey;
- if (name.startsWith("get") || name.startsWith("set")) {
- mainKey = Character.toLowerCase(name.charAt(3)) + name.substring(4);
- } else {
- mainKey = Character.toLowerCase(name.charAt(0)) + name.substring(1);
- }
- keys.add(mainKey);
- if (areasAnnot != null) {
- // Add prefixed entries, including absolute (root) entry for "" area keys.
- for (String area : areasAnnot.value()) {
- if (!area.isEmpty()) {
- keys.add(area + '.' + mainKey);
- }
- }
- } else { // add package name
- keys.add(member.getDeclaringClass().getName() + '.' + mainKey);
- }
- return keys;
- }
-
- /**
- * Internally evaluated the current valid configuration keys based on the given annotations present.
- *
- * @return the keys to be returned, or null.
- */
- public static String getConfigValue(Method method) {
- ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
- return getConfigValueInternal(method, areasAnnot);
- }
-
-
- /**
- * Internally evaluated the current valid configuration keys based on the given annotations present.
- *
- * @return the keys to be returned, or null.
- */
- public static String getConfigValue(Field field) {
- ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
- return getConfigValueInternal(field, areasAnnot);
- }
-
- /**
- * Internally evaluated the current valid configuration keys based on the given annotations present.
- *
- * @return the keys to be returned, or null.
- */
- private static String getConfigValueInternal(AnnotatedElement element, ConfigDefaultSections areasAnnot) {
- Config prop = element.getAnnotation(Config.class);
- ConfigDefault defaultAnnot = element.getAnnotation(ConfigDefault.class);
- List<String> keys;
- if (prop == null) {
- keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot);
- } else {
- keys = InjectionUtils.evaluateKeys((Member) element, areasAnnot, prop);
- }
- String configValue = evaluteConfigValue(keys);
- if (configValue == null && defaultAnnot != null) {
- return defaultAnnot.value();
- }
- return configValue;
- }
-
- /**
- * Collects all keys to be be accessed as defined by any annotations of type
- * {@link ConfigDefaultSections}, {@link Config}.
- * @param field the (optionally) annotated field instance
- * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}.
- */
- public static List<String> getKeys(Field field) {
- ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
- return InjectionUtils.evaluateKeys(field, areasAnnot, field.getAnnotation(Config.class));
- }
-
- /**
- * Collects all keys to be be accessed as defined by any annotations of type
- * {@link ConfigDefaultSections}, {@link Config}.
- * @param method the (optionally) annotated method instance
- * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}.
- */
- public static List<String> getKeys(Method method) {
- ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
- return InjectionUtils.evaluateKeys(method, areasAnnot, method.getAnnotation(Config.class));
- }
-
- private static String evaluteConfigValue(List<String> keys) {
- String configValue = null;
- for (String key : keys) {
- configValue = ConfigurationProvider.getConfiguration().get(key);
- if (configValue != null) {
- break;
- }
- }
- return configValue;
- }
-
-
- @SuppressWarnings("rawtypes")
- public static <T> T adaptValue(AnnotatedElement element, TypeLiteral<T> targetType, String configValue) {
- // Check for adapter/filter
- T adaptedValue = null;
- WithPropertyConverter converterAnnot = element.getAnnotation(WithPropertyConverter.class);
- Class<? extends PropertyConverter<T>> converterType;
- if (converterAnnot != null) {
- converterType = (Class<? extends PropertyConverter<T>>) converterAnnot.value();
- if (!converterType.getName().equals(WithPropertyConverter.class.getName())) {
- try {
- // TODO cache here...
- PropertyConverter<T> converter = PropertyConverter.class.cast(converterType.newInstance());
- adaptedValue = converter.convert(configValue);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to convert using explicit PropertyConverter on " + element +
- ", trying default conversion.", e);
- }
- }
- }
- if (adaptedValue != null) {
- return adaptedValue;
- }
- if (String.class == targetType.getType()) {
- return (T) configValue;
- } else {
- List<PropertyConverter<T>> converters = ConfigurationProvider.getConfigurationContext()
- .getPropertyConverters(targetType);
- for (PropertyConverter<T> converter : converters) {
- adaptedValue = converter.convert(configValue);
- if (adaptedValue != null) {
- return adaptedValue;
- }
- }
- throw new ConfigException("Non convertible property type: " + element);
- }
- }
-
- /**
- * Method that allows to statically check, if the resolver module is loaded. If the module is loaded
- * value expressions are automatically forwarded to the resolver module for resolution.
- *
- * @return true, if the resolver module is on the classpath.
- */
- public static boolean isResolutionModuleLoaded() {
- return RESOLUTION_MODULE_LOADED;
- }
-
- /**
- * Evaluates the given expression.
- *
- * @param expression the expression, not null.
- * @return
- */
- public static String evaluateValue(String expression) {
- if (!RESOLUTION_MODULE_LOADED) {
- return expression;
- }
- ExpressionEvaluator evaluator = ServiceContextManager.getServiceContext().getService(ExpressionEvaluator.class);
- if (evaluator != null) {
- return evaluator.evaluateExpression("<injection>", expression);
- }
- return expression;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
index f0218b4..3fbc243 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ModelPopulator.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.inject.internal;
+import org.apache.tamaya.inject.api.InjectionUtils;
import org.apache.tamaya.model.ConfigValidator;
import org.apache.tamaya.model.spi.ParameterValidation;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java
deleted file mode 100644
index d2abe73..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/PropertyChangeSetListener.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject.internal;
-
-import org.apache.tamaya.event.PropertyChangeSet;
-
-/**
- * Listner interface for {@link org.apache.tamaya.event.PropertyChangeSet} events.
- */
-public interface PropertyChangeSetListener {
-
- /**
- * This method gets called when a bound property is changed.
- *
- * @param evt A PropertyChangeEvent object describing the event source
- * and the property that has changed.
- */
-
- void propertyChange(PropertyChangeSet evt);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
deleted file mode 100644
index 412d074..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/WeakConfigListenerManager.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject.internal;
-
-import org.apache.tamaya.event.PropertyChangeSet;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple listener container that only holds weak references on the listeners.
- */
-public final class WeakConfigListenerManager {
-
- private static final WeakConfigListenerManager INSTANCE = new WeakConfigListenerManager();
-
- private static final Logger LOG = Logger.getLogger(WeakConfigListenerManager.class.getName());
- private StampedLock lock = new StampedLock();
- private Map<Object, PropertyChangeSetListener> listenerReferences = new WeakHashMap<>();
-
- /**
- * Private singleton constructor.
- */
- private WeakConfigListenerManager() {
- }
-
- public static WeakConfigListenerManager of() {
- return INSTANCE;
- }
-
- /**
- * Registers the given consumer for the instance. If a consumer already exists for this instance the given
- * consumer is appended.
- *
- * @param instance the instance, not null.
- * @param listener the consumer.
- */
- public void registerConsumer(Object instance, final PropertyChangeSetListener listener) {
- Lock writeLock = lock.asWriteLock();
- try {
- writeLock.lock();
- final PropertyChangeSetListener l = listenerReferences.get(instance);
- if (l == null) {
- listenerReferences.put(instance, listener);
- } else {
- listenerReferences.put(instance, new PropertyChangeSetListener() {
- @Override
- public void propertyChange(PropertyChangeSet evt) {
- l.propertyChange(evt);
- listener.propertyChange(evt);
- }
- });
- }
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Unregisters all consumers for the given instance.
- *
- * @param instance the instance, not null.
- */
- public void unregisterConsumer(Object instance) {
- Lock writeLock = lock.asWriteLock();
- try {
- writeLock.lock();
- listenerReferences.remove(instance);
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Publishes a change event to all consumers registered.
- *
- * @param change the change event, not null.
- */
- public void publishChangeEvent(PropertyChangeSet change) {
- Lock readLock = lock.asReadLock();
- try {
- readLock.lock();
- for (PropertyChangeSetListener l : listenerReferences.values()) {
- try {
- l.propertyChange(change);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "ConfigChangeListener failed: " + l.getClass().getName(), e);
- }
- }
- } finally {
- readLock.unlock();
- }
- }
-
-
- @Override
- public String toString() {
- return "WeakConfigListenerManager{" +
- "listenerReferences=" + listenerReferences +
- '}';
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java b/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
index 111aaff..dc65dad 100644
--- a/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
@@ -18,14 +18,11 @@
*/
package annottext;
-import org.apache.tamaya.event.ObservesConfigChange;
-import org.apache.tamaya.event.PropertyChangeSet;
-import org.apache.tamaya.inject.ConfigDefault;
-import org.apache.tamaya.inject.Config;
-import org.apache.tamaya.inject.DynamicValue;
-import org.apache.tamaya.inject.LoadPolicy;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.LoadPolicy;
import org.apache.tamaya.inject.NoConfig;
-import org.apache.tamaya.inject.WithLoadPolicy;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
import java.util.ArrayList;
import java.util.List;
@@ -35,25 +32,23 @@ import java.util.List;
* configuration system, nevertheless extending the overall Configuration interface.
* Created by Anatole on 15.02.14.
*/
-@WithLoadPolicy(LoadPolicy.INITIAL)
public class AnnotatedConfigBean {
- @Config(keys = {"foo.bar.myprop", "mp", "common.testdata.myProperty"})
+ @Config({"foo.bar.myprop", "mp", "common.testdata.myProperty"})
@ConfigDefault("ET")
// @ConfigLoadPolicy(listener = MyListener.class)
public String myParameter;
- @Config(keys = "simple_value")
- @WithLoadPolicy(LoadPolicy.LAZY)
+ @Config("simple_value")
public String simpleValue;
@Config
String anotherValue;
- @Config(keys = "host.name")
+ @Config("host.name")
private String hostName;
- @Config(keys = "host.name")
+ @Config("host.name")
private DynamicValue<String> dynamicHostname;
@NoConfig
@@ -78,14 +73,9 @@ public class AnnotatedConfigBean {
public static final String CONSTANT = "a constant";
- @Config(keys = "java.version")
+ @Config("java.version")
void setJavaVersion(String version){
this.javaVersion = version;
}
- @Config(keys="b")
- @ObservesConfigChange
- public void callBackTest(PropertyChangeSet value){
- this.events.add(value.toString());
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java b/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
index 9b19c14..a9f0933 100644
--- a/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfigTemplate.java
@@ -18,36 +18,32 @@
*/
package annottext;
-import org.apache.tamaya.inject.ConfigDefault;
-import org.apache.tamaya.inject.Config;
-import org.apache.tamaya.inject.DynamicValue;
-import org.apache.tamaya.inject.LoadPolicy;
-import org.apache.tamaya.inject.WithLoadPolicy;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
/**
* An example showing some basic annotations, using an interface to be proxied by the
* configuration system.
* Created by Anatole on 15.02.14.
*/
-@WithLoadPolicy(LoadPolicy.INITIAL)
public interface AnnotatedConfigTemplate {
- @Config(keys = {"foo.bar.myprop", "mp","common.testdata.myProperty"})
+ @Config({"foo.bar.myprop", "mp","common.testdata.myProperty"})
@ConfigDefault("ET")
// @ConfigLoadPolicy(listener = MyListener.class)
String myParameter();
- @Config(keys = "simple_value")
- @WithLoadPolicy(LoadPolicy.LAZY)
+ @Config("simple_value")
String simpleValue();
@Config
String simplestValue();
- @Config(keys = "host.name")
+ @Config("host.name")
String hostName();
- @Config(keys = "host.name")
+ @Config("host.name")
DynamicValue<String> getDynamicValue();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
index 3eb449d..9a55dde 100644
--- a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
+++ b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
@@ -21,9 +21,9 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.builder.ConfigurationBuilder;
-import org.apache.tamaya.inject.Config;
-import org.apache.tamaya.inject.ConfiguredItemSupplier;
-import org.apache.tamaya.inject.DynamicValue;
+import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
@@ -42,13 +42,13 @@ import static org.junit.Assert.*;
*/
public class DefaultDynamicValueTest {
- @Config(keys="a")
+ @Config("a")
String myValue;
- @Config(keys="a")
+ @Config("a")
String myValue2;
- @Config(keys="a")
+ @Config("a")
void setterMethod(String value){
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java b/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
deleted file mode 100644
index 747c23e..0000000
--- a/modules/injection/src/test/java/org/apache/tamaya/inject/internal/WeakConfigListenerManagerTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject.internal;
-
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
-import org.apache.tamaya.event.PropertyChangeSet;
-import org.apache.tamaya.event.PropertyChangeSetBuilder;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class WeakConfigListenerManagerTest {
-
- private PropertyChangeSetListener consumer = new PropertyChangeSetListener() {
- @Override
- public void propertyChange(PropertyChangeSet set) {
- loggedSet = set;
- }
- };
- private PropertyChangeSet loggedSet;
-
- @Test
- public void testOf() throws Exception {
- assertNotNull(WeakConfigListenerManager.of());
- }
-
- @Test
- public void testRegisterConsumer() throws Exception {
- SystemPropertySource sysSrc = new SystemPropertySource();
- WeakConfigListenerManager.of().registerConsumer(this, new PropertyChangeSetListener() {
- @Override
- public void propertyChange(PropertyChangeSet set) {
- loggedSet = set;
- }
- });
- PropertyChangeSet change = PropertyChangeSetBuilder.of(sysSrc).add("aaa", "aaaValue").build();
- WeakConfigListenerManager.of().registerConsumer(this, consumer);
- WeakConfigListenerManager.of().publishChangeEvent(change);
- assertNotNull(loggedSet);
- loggedSet = null;
- WeakConfigListenerManager.of().unregisterConsumer(consumer);
- }
-
- @Test
- public void testUnregisterConsumer() throws Exception {
- SystemPropertySource sysSrc = new SystemPropertySource();
- PropertyChangeSet change = PropertyChangeSetBuilder.of(sysSrc).add("aaa", "aaaValue").build();
- PropertyChangeSetListener tempConsumer = new PropertyChangeSetListener() {
- @Override
- public void propertyChange(PropertyChangeSet set) {
- loggedSet = set;
- }
- };
- WeakConfigListenerManager.of().registerConsumer(this, tempConsumer);
- WeakConfigListenerManager.of().publishChangeEvent(change);
- assertNotNull(loggedSet);
- loggedSet = null;
- WeakConfigListenerManager.of().unregisterConsumer(this);
- assertNull(loggedSet);
- WeakConfigListenerManager.of().publishChangeEvent(change);
- assertNull(loggedSet);
- }
-
- @Test
- public void testPublishChangeEvent() throws Exception {
- SystemPropertySource sysSrc = new SystemPropertySource();
- WeakConfigListenerManager.of().publishChangeEvent(
- PropertyChangeSetBuilder.of(sysSrc).add("aaa", "aaaValue").build());
- }
-
- @Test
- public void testToString() throws Exception {
- assertNotNull(WeakConfigListenerManager.of());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/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
index ee069eb..a847db8 100644
--- 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
@@ -19,7 +19,7 @@
package org.apache.tamaya.integration.cdi.internal;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.clsupport.internal.CLAwareServiceContext;
+import org.apache.tamaya.clsupport.CLAwareServiceContext;
import org.apache.tamaya.spi.ServiceContext;
import javax.annotation.Priority;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/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
index 013a70a..9f4135e 100644
--- 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
@@ -20,15 +20,13 @@
*/
package org.apache.tamaya.integration.cdi;
-import java.beans.PropertyChangeEvent;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+
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.Config;
-
/**
* Class to be loaded from CDI to ensure fields are correctly configured using CDI injection mechanisms.
*/
@@ -38,11 +36,11 @@ public class ConfiguredClass{
@Config
private String testProperty;
- @Config(keys = {"a.b.c.key1","a.b.c.key2","a.b.c.key3"})
+ @Config({"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;
- @Config(keys = {"foo","a.b.c.key2"})
+ @Config({"foo","a.b.c.key2"})
private String value2;
@Config
@@ -63,17 +61,12 @@ public class ConfiguredClass{
@Config
private boolean booleanT;
- @Config(keys = "BD")
+ @Config("BD")
private BigDecimal bigNumber;
- @Config(keys = "double1")
+ @Config("double1")
private double doubleValue;
- @ObservesConfigChange
- public void changeListener1(PropertyChangeEvent configChange){
- // will be called
- }
-
public String getTestProperty() {
return testProperty;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/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
index b0e85be..69e8ef9 100644
--- 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
@@ -46,9 +46,7 @@ public class ConfiguredTest{
System.out.println("********************************************");
System.out.println(item);
System.out.println("********************************************");
-
double actual = 1234.5678;
-
MatcherAssert.assertThat(item.getDoubleValue(), is(actual));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/integration/cdi-se/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/test/resources/META-INF/javaconfiguration.properties b/modules/integration/cdi-se/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..0937669
--- /dev/null
+++ b/modules/integration/cdi-se/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+double1=1234.5678
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/Config.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/Config.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/Config.java
deleted file mode 100644
index f8927b2..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/Config.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.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 Config {
-
- /**
- * 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/3beb5a44/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
deleted file mode 100644
index 2a28b32..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/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.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/3beb5a44/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
deleted file mode 100644
index 6f20130..0000000
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/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.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/3beb5a44/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
index f8f786e..4cf5c53 100644
--- 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
@@ -20,6 +20,11 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+import org.apache.tamaya.inject.api.WithConfigOperator;
+import org.apache.tamaya.inject.api.WithPropertyConverter;
import org.apache.tamaya.spi.PropertyConverter;
import javax.enterprise.context.spi.CreationalContext;
@@ -46,9 +51,9 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* CDI Extension module that adds injection mechanism for configuration.
*
- * @see Config
- * @see ConfigDefault
- * @see org.apache.tamaya.integration.cdi.ConfigDefaultSections
+ * @see org.apache.tamaya.inject.api.Config
+ * @see org.apache.tamaya.inject.api.ConfigDefault
+ * @see org.apache.tamaya.inject.api.ConfigDefaultSections
* @see ConfigException
*/
public class ConfigurationExtension implements Extension {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/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
index 7d25e48..10906a4 100644
--- 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
@@ -21,11 +21,20 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+import org.apache.tamaya.inject.api.DynamicValue;
+import org.apache.tamaya.inject.api.WithConfigOperator;
+import org.apache.tamaya.inject.api.WithPropertyConverter;
import org.apache.tamaya.spi.PropertyConverter;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -38,10 +47,22 @@ public class ConfigurationProducer {
private static final Logger LOGGER = Logger.getLogger(ConfigurationProducer.class.getName());
+ private DynamicValue createynamicValue(final InjectionPoint injectionPoint) {
+ Member member = injectionPoint.getMember();
+ if(member instanceof Field) {
+ return DefaultDynamicValue.of((Field)member, ConfigurationProvider.getConfiguration());
+ } else if(member instanceof Method) {
+ return DefaultDynamicValue.of((Method)member, ConfigurationProvider.getConfiguration());
+ }
+ return null;
+ }
+
@Produces
@Config
public Object resolveAndConvert(final InjectionPoint injectionPoint) {
-
+ if(DynamicValue.class.equals(injectionPoint.getAnnotated().getBaseType())){
+ return createynamicValue(injectionPoint);
+ }
final Config annotation = injectionPoint.getAnnotated().getAnnotation(Config.class);
final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
[11/11] incubator-tamaya git commit: TAMAYA-124: Fixed imports.
Posted by an...@apache.org.
TAMAYA-124: Fixed imports.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d03782a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d03782a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d03782a5
Branch: refs/heads/master
Commit: d03782a58d41dda2b7b04f495e3a6cea32c0de19
Parents: ccfc61e
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 20:58:05 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 20:58:05 2015 +0200
----------------------------------------------------------------------
.../org/apache/tamaya/examples/injection/ExampleTemplate.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d03782a5/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
----------------------------------------------------------------------
diff --git a/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java b/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
index cfff52a..d731484 100644
--- a/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
+++ b/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
@@ -18,6 +18,10 @@
*/
package org.apache.tamaya.examples.injection;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
+
/**
* Simple example bean, mapped by default names mostly.
*/
@@ -31,7 +35,7 @@ public interface ExampleTemplate {
String getDescription();
int getVersion();
- @Config(keys = "author")
+ @Config("author")
String getExampleAuthor();
}
[08/11] incubator-tamaya git commit: TAMAYA-124: Unifying annotations
for SE and EE based injection.
Posted by an...@apache.org.
TAMAYA-124: Unifying annotations for SE and EE based injection.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4cd97f9c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4cd97f9c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4cd97f9c
Branch: refs/heads/master
Commit: 4cd97f9c791e3e022ab1e90a92b18e2c87732a8e
Parents: 7f0abb7
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:34:24 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:34:24 2015 +0200
----------------------------------------------------------------------
.../tamaya/integration/spring/ConfiguredSpringBean.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4cd97f9c/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java
----------------------------------------------------------------------
diff --git a/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java b/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java
index 7941d03..95b10ef 100644
--- a/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java
+++ b/modules/integration/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.integration.spring;
-import org.apache.tamaya.inject.ConfigDefaultSections;
-import org.apache.tamaya.inject.Config;
-import org.apache.tamaya.inject.ConfigDefault;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
@@ -33,7 +33,7 @@ public class ConfiguredSpringBean {
@Autowired
private Environment env;
- @Config(keys = "java.version")
+ @Config("java.version")
private String javaVersion;
@Config
[10/11] incubator-tamaya git commit: TAMAYA-124: Unifying annotations
for SE and EE based injection - adapted/unified docs as well.
Posted by an...@apache.org.
TAMAYA-124: Unifying annotations for SE and EE based injection - adapted/unified docs as well.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ccfc61ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ccfc61ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ccfc61ee
Branch: refs/heads/master
Commit: ccfc61eebd3532488e1c89969697e9ad5f2ab45e
Parents: 29d7ca7
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 20:10:21 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 20:10:21 2015 +0200
----------------------------------------------------------------------
src/site/asciidoc/extensions/mod_cdi-ee.adoc | 216 -------------------
src/site/asciidoc/extensions/mod_cdi-se.adoc | 210 ------------------
src/site/asciidoc/extensions/mod_cdi.adoc | 249 ++++++++++++++++++++++
src/site/asciidoc/extensions/modules.adoc | 2 +-
4 files changed, 250 insertions(+), 427 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ccfc61ee/src/site/asciidoc/extensions/mod_cdi-ee.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_cdi-ee.adoc b/src/site/asciidoc/extensions/mod_cdi-ee.adoc
deleted file mode 100644
index 77fd63b..0000000
--- a/src/site/asciidoc/extensions/mod_cdi-ee.adoc
+++ /dev/null
@@ -1,216 +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:
-
-* 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 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:
-
-[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{
-
- @Config
- private String testProperty;
-
- @Config({"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;
-
- @Config({"foo","a.b.c.key2"})
- private String value2;
-
- @Config
- @ConfigDefault("N/A")
- private String runtimeVersion;
-
- @Config
- @ConfigDefault("${sys:java.version}")
- private String javaVersion2;
-
- @Config
- @ConfigDefault("5")
- private Integer int1;
-
- ...
-
-}
---------------------------------------------------------
-
-=== 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 +@Config+ annotation.
- E.g. for trying first +a.b+ and then +new.b+ you would configure it as follows:
-
-[source,java]
---------------------------------------------------------------------------------------
-@Config({"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]
---------------------------------------------------------------------------------------
-@Config({"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]
---------------------------------------------------------------------------------------
-@Config({"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{
-
-@Config({"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/ccfc61ee/src/site/asciidoc/extensions/mod_cdi-se.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_cdi-se.adoc b/src/site/asciidoc/extensions/mod_cdi-se.adoc
deleted file mode 100644
index fe28a89..0000000
--- a/src/site/asciidoc/extensions/mod_cdi-se.adoc
+++ /dev/null
@@ -1,210 +0,0 @@
-= 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{
-
- @Config
- private String testProperty;
-
- @Config({"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;
-
- @Config({"foo","a.b.c.key2"})
- private String value2;
-
- @Config
- @ConfigDefault("N/A")
- private String runtimeVersion;
-
- @Config
- @ConfigDefault("${sys:java.version}")
- private String javaVersion2;
-
- @Config
- @ConfigDefault("5")
- private Integer int1;
-
- ...
-
-}
---------------------------------------------------------
-
-=== 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 +@Configy+ annotation.
- E.g. for trying first +a.b+ and then +new.b+ you would configure it as follows:
-
-[source,java]
---------------------------------------------------------------------------------------
-@Config({"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]
---------------------------------------------------------------------------------------
-@Config({"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]
---------------------------------------------------------------------------------------
-@Config({"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{
-
-@Config({"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/ccfc61ee/src/site/asciidoc/extensions/mod_cdi.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_cdi.adoc b/src/site/asciidoc/extensions/mod_cdi.adoc
new file mode 100644
index 0000000..cff0cf2
--- /dev/null
+++ b/src/site/asciidoc/extensions/mod_cdi.adoc
@@ -0,0 +1,249 @@
+= 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 (Extension Modules)
+=== Overview
+
+Apache Tamaya currently provides two implementations for integration with CDI extensions implementing similar
+functionality as described in this document:
+
+* Loading of CDI managed SPI components as configuration extensions such as +PropertySources, PropertySourceProviders,
+ PropertyFilters, etc+. This also includes SPI defined by any Tamaya submodules.
+* Implement and enable Tamaya's configuration injection services with CDI.
+
+Hereby there are two implementations provided:
+
+* +tamaya-cdi-ee+ implements injection by using CDI's injection mechanism to inject configuration values into the
+ beans managed by the CDI systems.
+* +tamaya-cdi-se+ implements injection by integrating the +tamaya-injection+ SE based injection module (also used
+ for Spring and OSGI injection) with CDI. Injection hereby is performed by the Tamaya SE module, whereas
+ beans and injection control overall are still managed by CDI.
+* One difference, of course, is that +tamaya-se+ also provides an SE compatible API (+ConfigurationInjection,
+ ConfigurationInjector+), which is not available, when using the purely Java EE based variant.
+
+The annotations used for all injection functionality in Tamaya is defined as a separate module. This allows you to
+code against the injection API without dependency on the concrete injection implementation. As a consequence your
+components will be compatible regardless if deployed in a pure SE, a Java EE (CDI) or OSGI or Spring environment:
+
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-injection-api</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+
+=== Compatibility
+
+Both modules are based on Java 7, so they will not run on Java 7 and beyond.
+
+
+=== Installation
+
+To benefit from Tamaya CDI integration you only must one of the following dependencies to your module. Ensure that
+you never have installed both CDI extensions at the same time because this may be lead to unforseen side-effects.
+
+.CDI Pure Application Configuration
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-cdi-ee</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+.CDI enhanced with Tamaya SE Application Configuration
+[source, xml]
+-----------------------------------------------
+<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-cdi-se</artifactId>
+ <version>{tamayaVersion}</version>
+</dependency>
+-----------------------------------------------
+
+Both components will auto-register its components and override the default +ServicceContext+ in use. Additionally they
+register CDI extensions that implement Configuration injection as described before.
+
+IMPORTANT: Never install Tamaya's +tamaya-cdi-se+ and +tamaya-cdi-ee+ on the same system, since unpredictable side
+ effects could occur.
+
+=== Registering CDI managed components into the Application's ConfigurationContext
+
+As mentioned both modules allow to provide Tamaya SPI extensions modules as ordinary CDI managed beans. By default
+extensions should be registered using +@Singleton+ or +@ApplicationScoped+ scope annotations. So you can define/deploy
+additional application specific +PropertySources+ and other artifacts simply by defining a CDI managed bean implementing
+the required SPI interface:
+
+[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;
+ }
+}
+--------------------------------------------------------
+
+Note that for many SPI's there is a priority mechanism using +@Priority+ annotations in place.
+The +ServiceContext+ implementation combines the components registered with the ones loaded from the +ServiceLoader+
+mechanism hereby considering classloaser hierarchies.
+
+
+=== Annotating your Classes
+
+Basically annotating your classes is stright forward. +@Config+ defines an additional CDI qualifier that is, depending
+on the module deployed, handled by a CDI producer (+tamaya-cdi-ee+) or the Tamaya SE injection mechanism $
+(+tamaya-cdi-se+). All types injected by this module are injected using _dependent scope_.
+
+
+[source, java]
+--------------------------------------------------------
+@RequestScoped
+public class ConfiguredClass{
+
+ @Config
+ private String testProperty;
+
+ @Config({"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;
+
+ @Config({"foo","a.b.c.key2"})
+ private String value2;
+
+ @Config
+ @ConfigDefault("N/A")
+ private String runtimeVersion;
+
+ @Config
+ @ConfigDefault("${sys:java.version}")
+ private String javaVersion2;
+
+ @Config
+ @ConfigDefault("5")
+ private Integer int1;
+
+ ...
+
+}
+--------------------------------------------------------
+
+=== 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 +@Configy+ annotation.
+ E.g. for trying first +a.b+ and then +new.b+ you would configure it as follows:
+
+[source,java]
+--------------------------------------------------------------------------------------
+@Config({"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]
+--------------------------------------------------------------------------------------
+@Config({"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]
+--------------------------------------------------------------------------------------
+@Config({"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{
+
+@Config({"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/ccfc61ee/src/site/asciidoc/extensions/modules.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/modules.adoc b/src/site/asciidoc/extensions/modules.adoc
index 52fcecc..c77d906 100644
--- a/src/site/asciidoc/extensions/modules.adoc
+++ b/src/site/asciidoc/extensions/modules.adoc
@@ -69,7 +69,7 @@ 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-se+ |Tamaya integration module for CDI. |link:mod_cdi-se.html[Documentation]
+|+org.apache.tamaya.ext:tamaya-cdi+ |Tamaya integration modules for CDI. |link:mod_cdi.html[Documentation]
|+org.apache.tamaya.ext:tamaya-spi-support+ |Tamaya support module for SPI implementation. |link:mod_spi-support.html[Documentation]
|=======
[05/11] incubator-tamaya git commit: TAMAYA-124: Unifying annotations
for SE and EE based injection.
Posted by an...@apache.org.
TAMAYA-124: Unifying annotations for SE and EE based injection.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3beb5a44
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3beb5a44
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3beb5a44
Branch: refs/heads/master
Commit: 3beb5a44e0db97676a8535f9429ff19174b94a78
Parents: bb9e0f9
Author: anatole <an...@apache.org>
Authored: Fri Oct 16 19:31:25 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Oct 16 19:31:25 2015 +0200
----------------------------------------------------------------------
.../resources/findbugs/findbugs-exclude.xml | 7 +
.../tamaya/examples/injection/Example.java | 8 +-
.../examples/injection/ExampleTemplate.java | 4 -
.../tamaya/clsupport/spi/package-info.java | 22 -
.../tamaya/inject/api/BaseDynamicValue.java | 123 ++++++
.../org/apache/tamaya/inject/api/Config.java | 80 ++++
.../apache/tamaya/inject/api/ConfigDefault.java | 41 ++
.../inject/api/ConfigDefaultSections.java | 43 ++
.../inject/api/ConfiguredItemSupplier.java | 41 ++
.../apache/tamaya/inject/api/DynamicValue.java | 183 ++++++++
.../tamaya/inject/api/InjectionUtils.java | 124 ++++++
.../apache/tamaya/inject/api/LoadPolicy.java | 48 +++
.../tamaya/inject/api/WithConfigOperator.java | 44 ++
.../inject/api/WithPropertyConverter.java | 45 ++
.../apache/tamaya/inject/api/package-info.java | 22 +
.../tamaya/event/ObservesConfigChange.java | 38 --
.../apache/tamaya/event/PropertyChangeSet.java | 125 ------
.../tamaya/event/PropertyChangeSetBuilder.java | 164 -------
.../org/apache/tamaya/event/package-info.java | 22 -
.../apache/tamaya/inject/BaseDynamicValue.java | 41 --
.../java/org/apache/tamaya/inject/Config.java | 79 ----
.../org/apache/tamaya/inject/ConfigDefault.java | 41 --
.../tamaya/inject/ConfigDefaultSections.java | 43 --
.../tamaya/inject/ConfigurationInjector.java | 2 +
.../tamaya/inject/ConfiguredItemSupplier.java | 41 --
.../org/apache/tamaya/inject/DynamicValue.java | 183 --------
.../org/apache/tamaya/inject/LoadPolicy.java | 48 ---
.../tamaya/inject/WithConfigOperator.java | 45 --
.../apache/tamaya/inject/WithLoadPolicy.java | 40 --
.../tamaya/inject/WithPropertyConverter.java | 45 --
.../internal/ConfigChangeCallbackMethod.java | 64 ---
.../ConfigTemplateInvocationHandler.java | 6 +-
.../tamaya/inject/internal/ConfiguredField.java | 9 +-
.../inject/internal/ConfiguredSetterMethod.java | 7 +-
.../tamaya/inject/internal/ConfiguredType.java | 68 +--
.../internal/DefaultConfigurationInjector.java | 17 +-
.../inject/internal/DefaultDynamicValue.java | 150 ++-----
.../tamaya/inject/internal/InjectionHelper.java | 183 ++++++++
.../tamaya/inject/internal/InjectionUtils.java | 271 ------------
.../tamaya/inject/internal/ModelPopulator.java | 1 +
.../internal/PropertyChangeSetListener.java | 37 --
.../internal/WeakConfigListenerManager.java | 124 ------
.../java/annottext/AnnotatedConfigBean.java | 28 +-
.../java/annottext/AnnotatedConfigTemplate.java | 18 +-
.../internal/DefaultDynamicValueTest.java | 12 +-
.../internal/WeakConfigListenerManagerTest.java | 91 ----
.../cdi/internal/CDIAwareServiceContext.java | 2 +-
.../tamaya/integration/cdi/ConfiguredClass.java | 21 +-
.../tamaya/integration/cdi/ConfiguredTest.java | 2 -
.../META-INF/javaconfiguration.properties | 18 +
.../apache/tamaya/integration/cdi/Config.java | 80 ----
.../tamaya/integration/cdi/ConfigDefault.java | 41 --
.../integration/cdi/ConfigDefaultSections.java | 43 --
.../integration/cdi/ConfigurationExtension.java | 11 +-
.../integration/cdi/ConfigurationProducer.java | 23 +-
.../integration/cdi/DefaultDynamicValue.java | 424 +++++++++++++++++++
.../integration/cdi/WithConfigOperator.java | 44 --
.../integration/cdi/WithPropertyConverter.java | 45 --
.../cdi/ConfigurationProducerTest.java | 4 +
.../integration/cdi/NotFoundNoDefault.java | 1 +
modules/pom.xml | 1 +
61 files changed, 1560 insertions(+), 2078 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
index be0102f..0741f0e 100644
--- a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
+++ b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
@@ -111,4 +111,11 @@ under the License.
<Method name="checkConfigurationUpdate" />
</Match>
+ <Match>
+ <Class name="org.apache.tamaya.inject.internal.DefaultDynamicValue"/>
+ </Match>
+ <Match>
+ <Class name="org.apache.tamaya.integration.cdi.DefaultDynamicValue"/>
+ </Match>
+
</FindBugsFilter>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/Example.java
----------------------------------------------------------------------
diff --git a/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/Example.java b/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/Example.java
index 25db2a1..c4eec9b 100644
--- a/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/Example.java
+++ b/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/Example.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.examples.injection;
-import org.apache.tamaya.inject.ConfigDefaultSections;
-import org.apache.tamaya.inject.Config;
-import org.apache.tamaya.inject.ConfigDefault;
+import org.apache.tamaya.inject.api.Config;
+import org.apache.tamaya.inject.api.ConfigDefault;
+import org.apache.tamaya.inject.api.ConfigDefaultSections;
/**
* Simple example bean, mapped by default names mostly.
@@ -34,7 +34,7 @@ public class Example {
@ConfigDefault("No description available.")
private String description;
private int version;
- @Config(keys = "author")
+ @Config("author")
private String exampleAuthor;
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
----------------------------------------------------------------------
diff --git a/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java b/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
index 9592b1e..cfff52a 100644
--- a/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
+++ b/examples/5-injection-example/src/main/java/org/apache/tamaya/examples/injection/ExampleTemplate.java
@@ -18,10 +18,6 @@
*/
package org.apache.tamaya.examples.injection;
-import org.apache.tamaya.inject.ConfigDefault;
-import org.apache.tamaya.inject.ConfigDefaultSections;
-import org.apache.tamaya.inject.Config;
-
/**
* Simple example bean, mapped by default names mostly.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/spi/package-info.java
----------------------------------------------------------------------
diff --git a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/spi/package-info.java b/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/spi/package-info.java
deleted file mode 100644
index 6eb85d3..0000000
--- a/modules/classloader-support/src/main/java/org/apache/tamaya/clsupport/spi/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.
- */
-/**
- * Defines the SPI of the classloader support module.
- */
-package org.apache.tamaya.clsupport.spi;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java
new file mode 100644
index 0000000..4c05da1
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/BaseDynamicValue.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject.api;
+
+
+import java.io.Serializable;
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
+ * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the value.<br/>
+ * Types of this interface can be used as injection targets in injected beans or as template resiult on configuration
+ * templates.
+ * <h3>Implementation Specification</h3>
+ * Implementation of this interface must be
+ * <ul>
+ * <li>Serializable, when also the item stored is serializable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ *
+ * @param <T> The type of the value.
+ */
+public abstract class BaseDynamicValue<T> implements DynamicValue<T>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Performs a commit, if necessary, and returns the current value.
+ *
+ * @return the non-null value held by this {@code DynamicValue}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ * @see DynamicValue#isPresent()
+ */
+ public T commitAndGet() {
+ commit();
+ return get();
+ }
+
+ /**
+ * Return {@code true} if there is a value present, otherwise {@code false}.
+ *
+ * @return {@code true} if there is a value present, otherwise {@code false}
+ */
+ public boolean isPresent() {
+ return get() != null;
+ }
+
+
+ /**
+ * Return the value if present, otherwise return {@code other}.
+ *
+ * @param other the value to be returned if there is no value present, may
+ * be null
+ * @return the value, if present, otherwise {@code other}
+ */
+ public T orElse(T other) {
+ T value = get();
+ if (value == null) {
+ return other;
+ }
+ return value;
+ }
+
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ public T orElseGet(ConfiguredItemSupplier<? extends T> other) {
+ T value = get();
+ if (value == null) {
+ return other.get();
+ }
+ return value;
+ }
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ * <p>
+ * NOTE A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ public <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X {
+ T value = get();
+ if (value == null) {
+ throw exceptionSupplier.get();
+ }
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.java
new file mode 100644
index 0000000..c63e5ad
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/Config.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.inject.api;
+
+
+import javax.enterprise.util.Nonbinding;
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to 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 Config {
+
+ /**
+ * 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/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefault.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefault.java
new file mode 100644
index 0000000..5b43a20
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/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.inject.api;
+
+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/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigDefaultSections.java
new file mode 100644
index 0000000..c6cec50
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/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.inject.api;
+
+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/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java
new file mode 100644
index 0000000..4775ef6
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.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.inject.api;
+
+/**
+ * Represents a supplier of results.
+ * <p>
+ * <p>There is no requirement that a new or distinct result be returned each
+ * time the supplier is invoked.
+ * <p>
+ * <p>This is a functional interface,
+ * whose functional method is {@link #get()}.
+ *
+ * @param <T> the type of results supplied by this supplier
+ */
+//@FunctionalInterface
+public interface ConfiguredItemSupplier<T> {
+
+ /**
+ * Gets a result.
+ *
+ * @return a result
+ */
+ T get();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
new file mode 100644
index 0000000..72c3ee9
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject.api;
+
+import java.beans.PropertyChangeListener;
+
+
+/**
+ * A accessor for a single configured value. This can be used to support values that may change during runtime,
+ * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
+ * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
+ * by client code. Similarly an instance also can ignore all later changes to the value.<br/>
+ * Types of this interface can be used as injection targets in injected beans or as template resiult on configuration
+ * templates.
+ * <h3>Implementation Specification</h3>
+ * Implementation of this interface must be
+ * <ul>
+ * <li>Serializable, when also the item stored is serializable</li>
+ * <li>Thread safe</li>
+ * </ul>
+ * @param <T> The type of the value.
+ */
+public interface DynamicValue<T> {
+
+ /**
+ * Policy to control how new values are applied to this instance.
+ */
+ enum UpdatePolicy{
+ /** New values are applied immedately and registered listeners are informed about the change. */
+ IMMEDIATE,
+ /** New values or not applied, but stored in the newValue property. Explcit call to #commit
+ of #commitAndGet are required to accept the change and inform the listeners about the change.
+ */
+ EXPLCIT,
+ /**
+ * New values are always immedately discarded.
+ */
+ NEVER,
+ /**
+ * Changes are logged before the are discarded.
+ */
+ LOG_AND_DISCARD
+ }
+
+ /**
+ * Performs a commit, if necessary, and returns the current value.
+ *
+ * @return the non-null value held by this {@code DynamicValue}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see DynamicValue#isPresent()
+ */
+ T commitAndGet();
+
+ /**
+ * Commits a new value that has not been committed yet, make it the new value of the instance. On change any
+ * registered listeners will be triggered.
+ */
+ void commit();
+
+ /**
+ * Discards a new value that was published. No listeners will be informed.
+ */
+ void discard();
+
+ /**
+ * Access the {@link UpdatePolicy} used for updating this value.
+ * @return the update policy, never null.
+ */
+ UpdatePolicy getUpdatePolicy();
+
+ /**
+ * Add a listener to be called as weak reference, when this value has been changed.
+ * @param l the listener, not null
+ */
+ void addListener(PropertyChangeListener l);
+
+ /**
+ * Removes a listener to be called, when this value has been changed.
+ * @param l the listner to be removed, not null
+ */
+ void removeListener(PropertyChangeListener l);
+
+ /**
+ * If a value is present in this {@code DynamicValue}, returns the value,
+ * otherwise throws {@code ConfigException}.
+ *
+ * @return the non-null value held by this {@code Optional}
+ * @throws org.apache.tamaya.ConfigException if there is no value present
+ *
+ * @see DynamicValue#isPresent()
+ */
+ T get();
+
+ /**
+ * Method to check for and apply a new value. Depending on the {@link UpdatePolicy}
+ * the value is immediately or deferred visible (or it may even be ignored completely).
+ * @return true, if a new value has been detected. The value may not be visible depending on the current
+ * {@link DynamicValue.UpdatePolicy} in place.
+ */
+ boolean updateValue();
+
+ /**
+ * Evaluates the current value dynamically from the underlying configuration.
+ * @return the current actual value, or null.
+ */
+ T evaluateValue();
+
+ /**
+ * Sets a new {@link UpdatePolicy}.
+ * @param updatePolicy the new policy, not null.
+ */
+ void setUpdatePolicy(UpdatePolicy updatePolicy);
+
+ /**
+ * Access a new value that has not yet been committed.
+ * @return the uncommitted new value, or null.
+ */
+ T getNewValue();
+
+ /**
+ * Return {@code true} if there is a value present, otherwise {@code false}.
+ *
+ * @return {@code true} if there is a value present, otherwise {@code false}
+ */
+ boolean isPresent();
+
+ /**
+ * Return the value if present, otherwise return {@code other}.
+ *
+ * @param other the value to be returned if there is no value present, may
+ * be null
+ * @return the value, if present, otherwise {@code other}
+ */
+ T orElse(T other);
+
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ T orElseGet(ConfiguredItemSupplier<? extends T> other);
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ *
+ * NOTE A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.java
new file mode 100644
index 0000000..43fe757
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/InjectionUtils.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 of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject.api;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Created by Anatole on 16.10.2015.
+ */
+public final class InjectionUtils {
+
+ private InjectionUtils(){}
+
+
+ /**
+ * Collects all keys to be be accessed as defined by any annotations of type
+ * {@link ConfigDefaultSections}, {@link Config}.
+ * @param field the (optionally) annotated field instance
+ * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}.
+ */
+ public static List<String> getKeys(Field field) {
+ ConfigDefaultSections areasAnnot = field.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
+ return InjectionUtils.evaluateKeys(field, areasAnnot, field.getAnnotation(Config.class));
+ }
+
+ /**
+ * Collects all keys to be be accessed as defined by any annotations of type
+ * {@link ConfigDefaultSections}, {@link Config}.
+ * @param method the (optionally) annotated method instance
+ * @return the regarding key list to be accessed fomr the {@link org.apache.tamaya.Configuration}.
+ */
+ public static List<String> getKeys(Method method) {
+ ConfigDefaultSections areasAnnot = method.getDeclaringClass().getAnnotation(ConfigDefaultSections.class);
+ return InjectionUtils.evaluateKeys(method, areasAnnot, method.getAnnotation(Config.class));
+ }
+
+ /**
+ * Evaluates all absolute configuration key based on the member name found.
+ *
+ * @param areasAnnot the (optional) annotation definining areas to be looked up.
+ * @return the list current keys in order how they should be processed/looked up.
+ */
+ public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot) {
+ List<String> keys = new ArrayList<>();
+ String name = member.getName();
+ String mainKey;
+ if (name.startsWith("get") || name.startsWith("set")) {
+ mainKey = Character.toLowerCase(name.charAt(3)) + name.substring(4);
+ } else {
+ mainKey = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+ keys.add(mainKey);
+ if (areasAnnot != null) {
+ // Add prefixed entries, including absolute (root) entry for "" area keys.
+ for (String area : areasAnnot.value()) {
+ if (!area.isEmpty()) {
+ keys.add(area + '.' + mainKey);
+ }
+ }
+ } else { // add package name
+ keys.add(member.getDeclaringClass().getName() + '.' + mainKey);
+ }
+ return keys;
+ }
+
+ /**
+ * Evaluates all absolute configuration key based on the annotations found on a class.
+ *
+ * @param areasAnnot the (optional) annotation definining areas to be looked up.
+ * @param propertyAnnotation the annotation on field/method level that may defined one or
+ * several keys to be looked up (in absolute or relative form).
+ * @return the list current keys in order how they should be processed/looked up.
+ */
+ public static List<String> evaluateKeys(Member member, ConfigDefaultSections areasAnnot, Config propertyAnnotation) {
+ if(propertyAnnotation==null){
+ return evaluateKeys(member, areasAnnot);
+ }
+ List<String> keys = new ArrayList<>(Arrays.asList(propertyAnnotation.value()));
+ if (keys.isEmpty()) {
+ keys.add(member.getName());
+ }
+ ListIterator<String> iterator = keys.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 (areasAnnot != null && areasAnnot.value().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 : areasAnnot.value()) {
+ iterator.add(area.isEmpty() ? next : area + '.' + next);
+ }
+ }
+ }
+ }
+ return keys;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
new file mode 100644
index 0000000..7924222
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/LoadPolicy.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.inject.api;
+
+/**
+ * Available policies that describe how changes affecting configured values are published/reinjected.
+ * The policy also affects the cases were any configured listeners/listener methods are called for
+ * propagation current configuration changes.
+ */
+public enum LoadPolicy {
+ /**
+ * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later.
+ */
+ INITIAL,
+ /**
+ * The configuration keys is evaluated exactly once on its first use lazily, but never updated later.
+ * This feature is not applicable on field injection, but only on configuration template methods.
+ */
+ LAZY,
+ /**
+ * The configuration keys is evaluated once, when the owning component is loaded/configured.
+ * Later changes on this configuration entry will be reinjected/updated and additionally triggered
+ * as {@link java.beans.PropertyChangeEvent}.
+ */
+ MANAGED,
+ /**
+ * The configuration keys is evaluated once, when the owning component is loaded/configured.
+ * Later changes on this configuration entry will be reinjected/updated, but no {@link java.beans.PropertyChangeEvent}
+ * will be triggered.
+ */
+ SILENT
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithConfigOperator.java
new file mode 100644
index 0000000..0574de8
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/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.inject.api;
+
+import org.apache.tamaya.ConfigOperator;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define an configuration operator to be used before accessing a configured 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/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/WithPropertyConverter.java
new file mode 100644
index 0000000..7abd8df
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/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.inject.api;
+
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to define a type adapter to be used before injecting a configured 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/3beb5a44/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java
new file mode 100644
index 0000000..b5d8bc3
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Common njection API.
+ */
+package org.apache.tamaya.inject.api;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/event/ObservesConfigChange.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/event/ObservesConfigChange.java b/modules/injection/src/main/java/org/apache/tamaya/event/ObservesConfigChange.java
deleted file mode 100644
index 3c251ef..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/event/ObservesConfigChange.java
+++ /dev/null
@@ -1,38 +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.event;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to annotate a method on a class to be informed on config changes.
- * The exact behaviour, when configuration change events are sent can be configured
- * on each configured property/method by adding the {@link org.apache.tamaya.inject.WithLoadPolicy}
- * annotation. By default listeners are informed on all changes of configurations that were used as
- * input configurations for configuring a class/instance. Additionally {@link org.apache.tamaya.inject.Config}
- * annotations can be added that allows to constrain changes to some limited properties.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.METHOD })
-public @interface ObservesConfigChange {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSet.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSet.java b/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSet.java
deleted file mode 100644
index 079f333..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSet.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.event;
-
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * Event that contains a set of changed keys of a {@link org.apache.tamaya.spi.PropertySource}. Any values must
- * be obtained by calling the {@link org.apache.tamaya.Configuration} due to security reasons. This event can be used
- * by the {@link org.apache.tamaya.spi.PropertySource} implementation to cleanup caches as needed.
- * This class is immutable and thread-safe. To create instances use
- * {@link PropertyChangeSetBuilder}.
- */
-public final class PropertyChangeSet implements Serializable{
- /** The serialVersionUID. */
- private static final long serialVersionUID = 1L;
- /** The base property source name. */
- private String propertySourceName;
- /** The timestamp of the change. */
- private long timestamp = System.currentTimeMillis();
- /**
- * The recorded keys added.
- */
- final SortedSet<String> addedKeys = new TreeSet<>();
-
- /**
- * The recorded keys updated.
- */
- final SortedSet<String> updatedKeys = new TreeSet<>();
-
- /**
- * The recorded keys removed.
- */
- final SortedSet<String> removedKeys = new TreeSet<>();
-
-
- /**
- * Constructor used by {@link PropertyChangeSetBuilder}.
- * @param builder The builder instance, not null.
- */
- PropertyChangeSet(PropertyChangeSetBuilder builder) {
- this.propertySourceName = Objects.requireNonNull(builder.propertySourceName);
- this.addedKeys.addAll(builder.addedKeys);
- this.removedKeys.addAll(builder.removedKeys);
- this.updatedKeys.addAll(builder.updatedKeys);
- }
-
- /**
- * Get the underlying property provider/configuration.
- * @return the underlying property provider/configuration, never null.
- */
- public String getPropertySourceName(){
- return this.propertySourceName;
- }
-
- /**
- * Get the timestamp of this changeset. This allows to track, if a ChangeSet was already applied.
- * @return the timestamp
- */
- public long getTimestamp(){
- return timestamp;
- }
-
- /**
- * Get the keys added.
- * @return the added keys, never null.
- */
- public Collection<String> getKeysAdded(){
- return Collections.unmodifiableCollection(this.addedKeys);
- }
-
- /**
- * Get the keys removed.
- * @return the removed keys, never null.
- */
- public Collection<String> getKeysRemoved(){
- return Collections.unmodifiableCollection(this.removedKeys);
- }
-
- /**
- * Get the updated keys.
- * @return the updated keys, never null.
- */
- public Collection<String> getKeysUpdated(){
- return Collections.unmodifiableCollection(this.addedKeys);
- }
-
-
- /**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
- */
- public boolean isEmpty(){
- return this.addedKeys.isEmpty() && this.updatedKeys.isEmpty() && this.removedKeys.isEmpty();
- }
-
-
- @Override
- public String toString() {
- return "ConfigChangeSet{" +
- "propertySourceName=" + propertySourceName +
- ", timestamp=" + timestamp +
- ", addedKeys=" + addedKeys +
- ", updatedKeys=" + updatedKeys +
- ", removedKeys=" + removedKeys +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSetBuilder.java b/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSetBuilder.java
deleted file mode 100644
index 73fb53f..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/event/PropertyChangeSetBuilder.java
+++ /dev/null
@@ -1,164 +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.event;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-/**
- * Models a set current changes to be applied to a configuration/property provider. Such a set can be applied
- * to any {@link PropertySource} instance. If the provider is mutable it may check the
- * version given and applyChanges the changes to the provider/configuration, including triggering current regarding
- * change events.
- * <p>
- * For appropriate conversion a {@code Function<String, Codec>} can be applied, which performs correct conversion,
- * when changed values are set. This function enables connecting e.g. setters on a configuration template with
- * the corresponding conversion logic, so the template calls are correctly converted back.
- */
-public final class PropertyChangeSetBuilder {
- /**
- * The recorded changes.
- */
- final SortedSet<String> addedKeys = new TreeSet<>();
-
- /**
- * The recorded changes.
- */
- final SortedSet<String> updatedKeys = new TreeSet<>();
-
- /**
- * The recorded changes.
- */
- final SortedSet<String> removedKeys = new TreeSet<>();
-
- /**
- * The underlying configuration/provider.
- */
- String propertySourceName;
-
- /**
- * Constructor.
- *
- * @param source the underlying configuration/provider, not null.
- */
- private PropertyChangeSetBuilder(PropertySource source) {
- this.propertySourceName = Objects.requireNonNull(source).getName();
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @return the builder for chaining.
- */
- public static PropertyChangeSetBuilder of(PropertySource source) {
- return new PropertyChangeSetBuilder(source);
- }
-
-
- /**
- * Marks the given key(s) as removed.
- *
- * @param keys the keys removed
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder remove(String... keys) {
- for (String removeKey : keys) {
- this.removedKeys.add(removeKey);
- }
- return this;
- }
-
- /**
- * Marks the given key(s) as added.
- *
- * @param keys the keys added
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder add(String... keys) {
- for (String addKey : keys) {
- this.addedKeys.add(addKey);
- }
- return this;
- }
-
- /**
- * Marks the given key(s) as updaed.
- *
- * @param keys the keys updated
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder update(String... keys) {
- for (String uptKey : keys) {
- this.updatedKeys.add(uptKey);
- }
- return this;
- }
-
-
- /**
- * Compares the two property maps and adds the corresponding updated/aded/removed keys to the builder.
- *
- * @param map1 the source map, not null.
- * @param map2 the target map, not null.
- * @return the builder for chaining.
- */
- public PropertyChangeSetBuilder addChanges(Map<String, String> map1, Map<String, String> map2) {
- for (Map.Entry<String, String> en : map1.entrySet()) {
- String val = map2.get(en.getKey());
- if (val == null) {
- remove(en.getKey());
- } else if (!val.equals(en.getValue())) {
- update(en.getKey());
- }
- }
- for (Map.Entry<String, String> en : map2.entrySet()) {
- String val = map1.get(en.getKey());
- if (val == null) {
- add(en.getKey());
- }
- // update case already handled before!
- }
- return this;
- }
-
- /**
- * Builds s new change set.
- *
- * @return a new change set, never null.
- */
- public PropertyChangeSet build() {
- return new PropertyChangeSet(this);
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "PropertyChangeEventBuilder [propertySourceName=" + propertySourceName + ", " +
- ", added=" + addedKeys + ", updated=" + updatedKeys + ", removed=" + removedKeys + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/event/package-info.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/event/package-info.java b/modules/injection/src/main/java/org/apache/tamaya/event/package-info.java
deleted file mode 100644
index e1e5a33..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/event/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.
- */
-/**
- * This package provides artifacts to distribute property changes, so instances can observe the changes.
- */
-package org.apache.tamaya.event;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.java
deleted file mode 100644
index c905ad2..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/BaseDynamicValue.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.inject;
-
-
-/**
- * A accessor for a single configured value. This can be used to support values that may change during runtime,
- * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
- * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
- * by client code. Similarly an instance also can ignore all later changes to the value.<br/>
- * Types of this interface can be used as injection targets in injected beans or as template resiult on configuration
- * templates.
- * <h3>Implementation Specification</h3>
- * Implementation of this interface must be
- * <ul>
- * <li>Serializable, when also the item stored is serializable</li>
- * <li>Thread safe</li>
- * </ul>
- *
- * @param <T> The type of the value.
- */
-public abstract class BaseDynamicValue<T> implements DynamicValue<T> {
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/Config.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/Config.java b/modules/injection/src/main/java/org/apache/tamaya/inject/Config.java
deleted file mode 100644
index 0b1abb6..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/Config.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject;
-
-
-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 WithLoadPolicy}, {@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 = Configuration.current();}</li>
- * <li>The current property String keys is evaluated by calling {@code cfg.get("aValue");}</li>
- * <li>if not successful, an error is thrown ({@link org.apache.tamaya.ConfigException}.</li>
- * <li>On success, since no type conversion is involved, the keys is injected.</li>
- * <li>The configured bean is registered as a weak change listener in the config system's underlying
- * configuration, so future config changes can be propagated (controlled by {@link WithLoadPolicy}
- * annotations).</li>
- * </ul>
- *
- * In the next example we explicitly define the property keys:
- * {@code
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty
- * @ConfiguredProperty(keys={"a.b.value", "a.b.deprecated.keys"})
- * @ConfiguredProperty(keys="a")
- * private String aValue;
- * }
- *
- * Within this example we evaluate multiple possible keys. 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 "aValue", "a.b.keys", "a.b.deprecated.keys"}. If no keys could be read
- * fromMap the configuration, it uses the keys fromMap the {@code ConfigDefault} annotation. Interesting here
- * is that this keys is not static, it is evaluated.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface Config {
-
- /**
- * 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.
- */
- String[] keys() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigDefault.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigDefault.java
deleted file mode 100644
index 7a0b923..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/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.inject;
-
-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 })
-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/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigDefaultSections.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigDefaultSections.java
deleted file mode 100644
index 023fb72..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/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.inject;
-
-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 Config}
- * 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/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
index 16a2a90..9432ba2 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
@@ -19,6 +19,8 @@
package org.apache.tamaya.inject;
+import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
+
/**
* Accessor interface for injection of configuration and configuration templates.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredItemSupplier.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredItemSupplier.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredItemSupplier.java
deleted file mode 100644
index 2cb9af1..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfiguredItemSupplier.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.inject;
-
-/**
- * Represents a supplier of results.
- * <p>
- * <p>There is no requirement that a new or distinct result be returned each
- * time the supplier is invoked.
- * <p>
- * <p>This is a functional interface,
- * whose functional method is {@link #get()}.
- *
- * @param <T> the type of results supplied by this supplier
- */
-//@FunctionalInterface
-public interface ConfiguredItemSupplier<T> {
-
- /**
- * Gets a result.
- *
- * @return a result
- */
- T get();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java b/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
deleted file mode 100644
index b420c71..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/DynamicValue.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject;
-
-import java.beans.PropertyChangeListener;
-
-
-/**
- * A accessor for a single configured value. This can be used to support values that may change during runtime,
- * reconfigured or final. Hereby external code (could be Tamaya configuration listners or client code), can set a
- * new value. Depending on the {@link UpdatePolicy} the new value is immedeately active or it requires an active commit
- * by client code. Similarly an instance also can ignore all later changes to the value.<br/>
- * Types of this interface can be used as injection targets in injected beans or as template resiult on configuration
- * templates.
- * <h3>Implementation Specification</h3>
- * Implementation of this interface must be
- * <ul>
- * <li>Serializable, when also the item stored is serializable</li>
- * <li>Thread safe</li>
- * </ul>
- * @param <T> The type of the value.
- */
-public interface DynamicValue<T> {
-
- /**
- * Policy to control how new values are applied to this instance.
- */
- enum UpdatePolicy{
- /** New values are applied immedately and registered listeners are informed about the change. */
- IMMEDIATE,
- /** New values or not applied, but stored in the newValue property. Explcit call to #commit
- of #commitAndGet are required to accept the change and inform the listeners about the change.
- */
- EXPLCIT,
- /**
- * New values are always immedately discarded.
- */
- NEVER,
- /**
- * Changes are logged before the are discarded.
- */
- LOG_AND_DISCARD
- }
-
- /**
- * Performs a commit, if necessary, and returns the current value.
- *
- * @return the non-null value held by this {@code DynamicValue}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- *
- * @see DynamicValue#isPresent()
- */
- T commitAndGet();
-
- /**
- * Commits a new value that has not been committed yet, make it the new value of the instance. On change any
- * registered listeners will be triggered.
- */
- void commit();
-
- /**
- * Discards a new value that was published. No listeners will be informed.
- */
- void discard();
-
- /**
- * Access the {@link UpdatePolicy} used for updating this value.
- * @return the update policy, never null.
- */
- UpdatePolicy getUpdatePolicy();
-
- /**
- * Add a listener to be called as weak reference, when this value has been changed.
- * @param l the listener, not null
- */
- void addListener(PropertyChangeListener l);
-
- /**
- * Removes a listener to be called, when this value has been changed.
- * @param l the listner to be removed, not null
- */
- void removeListener(PropertyChangeListener l);
-
- /**
- * If a value is present in this {@code DynamicValue}, returns the value,
- * otherwise throws {@code ConfigException}.
- *
- * @return the non-null value held by this {@code Optional}
- * @throws org.apache.tamaya.ConfigException if there is no value present
- *
- * @see DynamicValue#isPresent()
- */
- T get();
-
- /**
- * Method to check for and apply a new value. Depending on the {@link UpdatePolicy}
- * the value is immediately or deferred visible (or it may even be ignored completely).
- * @return true, if a new value has been detected. The value may not be visible depending on the current
- * {@link org.apache.tamaya.inject.DynamicValue.UpdatePolicy} in place.
- */
- boolean updateValue();
-
- /**
- * Evaluates the current value dynamically from the underlying configuration.
- * @return the current actual value, or null.
- */
- T evaluateValue();
-
- /**
- * Sets a new {@link UpdatePolicy}.
- * @param updatePolicy the new policy, not null.
- */
- void setUpdatePolicy(UpdatePolicy updatePolicy);
-
- /**
- * Access a new value that has not yet been committed.
- * @return the uncommitted new value, or null.
- */
- T getNewValue();
-
- /**
- * Return {@code true} if there is a value present, otherwise {@code false}.
- *
- * @return {@code true} if there is a value present, otherwise {@code false}
- */
- boolean isPresent();
-
- /**
- * Return the value if present, otherwise return {@code other}.
- *
- * @param other the value to be returned if there is no value present, may
- * be null
- * @return the value, if present, otherwise {@code other}
- */
- T orElse(T other);
-
- /**
- * Return the value if present, otherwise invoke {@code other} and return
- * the result of that invocation.
- *
- * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
- * is present
- * @return the value if present otherwise the result of {@code other.get()}
- * @throws NullPointerException if value is not present and {@code other} is
- * null
- */
- T orElseGet(ConfiguredItemSupplier<? extends T> other);
-
- /**
- * Return the contained value, if present, otherwise throw an exception
- * to be created by the provided supplier.
- *
- * NOTE A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
- * {@code IllegalStateException::new}
- *
- * @param <X> Type of the exception to be thrown
- * @param exceptionSupplier The supplier which will return the exception to
- * be thrown
- * @return the present value
- * @throws X if there is no value present
- * @throws NullPointerException if no value is present and
- * {@code exceptionSupplier} is null
- */
- <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java b/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java
deleted file mode 100644
index 90c1e8f..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/LoadPolicy.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject;
-
-/**
- * Available policies that describe how changes affecting configured values are published/reinjected.
- * The policy also affects the cases were any configured listeners/listener methods are called for
- * propagation current configuration changes.
- */
-public enum LoadPolicy {
- /**
- * The configuration keys is evaluated once, when the owning component is loaded/configured, but never updated later.
- */
- INITIAL,
- /**
- * The configuration keys is evaluated exactly once on its first use lazily, but never updated later.
- * This feature is not applicable on field injection, but only on configuration template methods.
- */
- LAZY,
- /**
- * The configuration keys is evaluated once, when the owning component is loaded/configured.
- * Later changes on this configuration entry will be reinjected/updated and additionally triggered
- * as {@link java.beans.PropertyChangeEvent}.
- */
- MANAGED,
- /**
- * The configuration keys is evaluated once, when the owning component is loaded/configured.
- * Later changes on this configuration entry will be reinjected/updated, but no {@link java.beans.PropertyChangeEvent}
- * will be triggered.
- */
- SILENT
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3beb5a44/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java b/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java
deleted file mode 100644
index e43ebc3..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/WithConfigOperator.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject;
-
-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;
-import java.util.function.UnaryOperator;
-
-/**
- * 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})
-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 UnaryOperator<Configuration>> value();
-
-}