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 2018/02/03 20:02:39 UTC
[5/6] incubator-tamaya-sandbox git commit: Adapted to comply with JSR
API.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
index 7882512..4ca96d1 100644
--- a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
+++ b/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedReadOnlyTests.java
@@ -18,9 +18,11 @@
*/
package org.apache.tamaya.collections;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
+import javax.config.Config;
+import javax.config.ConfigProvider;
+
+import org.apache.tamaya.base.convert.ConversionContext;
+import org.apache.tamaya.spi.TypeLiteral;
import org.junit.Test;
import java.util.*;
@@ -38,8 +40,12 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testArrayListList_1(){
- Configuration config = ConfigurationProvider.getConfiguration();
- List<String> items = config.get("typed.arraylist", new TypeLiteral<List<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.arraylist", new TypeLiteral<List<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ List<String> items = config.getValue("typed.arraylist", List.class);
+ assertTrue(items instanceof ArrayList);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -48,8 +54,11 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testArrayListList_2(){
- Configuration config = ConfigurationProvider.getConfiguration();
- List<String> items = (List<String>) config.get("typed.arraylist", List.class);
+ Config config = ConfigProvider.getConfig();ConversionContext ctx = new ConversionContext.Builder(
+ "typed.arraylist", new TypeLiteral<ArrayList<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ List<String> items = config.getValue("typed.arraylist", List.class);
+ assertTrue(items instanceof ArrayList);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -58,8 +67,12 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testLinkedListList_1(){
- Configuration config = ConfigurationProvider.getConfiguration();
- List<String> items = config.get("typed.linkedlist", new TypeLiteral<List<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.linkedlist", new TypeLiteral<LinkedList<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ List<String> items = config.getValue("typed.linkedlist", List.class);
+ assertTrue(items instanceof LinkedList);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -68,8 +81,12 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testLinkedListList_2(){
- Configuration config = ConfigurationProvider.getConfiguration();
- List<String> items = (List<String>) config.get("typed.linkedlist", List.class);
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.linkedlist", new TypeLiteral<LinkedList<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ List<String> items = config.getValue("typed.linkedlist", LinkedList.class);
+ assertTrue(items instanceof LinkedList);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -79,8 +96,12 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testHashSet_1(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Set<String> items = config.get("typed.hashset", new TypeLiteral<Set<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.hashset", new TypeLiteral<Set<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Set<String> items = config.getValue("typed.hashset", Set.class);
+ assertTrue(items instanceof HashSet);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -88,8 +109,12 @@ public class CollectionsTypedReadOnlyTests {
}
@Test(expected=UnsupportedOperationException.class)
public void testHashSet_2(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Set<String> items = (Set<String>) config.get("typed.hashset", Set.class);
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.hashset", new TypeLiteral<HashSet<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Set<String> items = config.getValue("typed.hashset", Set.class);
+ assertTrue(items instanceof HashSet);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -98,8 +123,12 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testTreeSet_1(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Set<String> items = config.get("typed.treeset", new TypeLiteral<Set<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.treeset", new TypeLiteral<TreeSet<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Set<String> items = config.getValue("typed.treeset", Set.class);
+ assertTrue(items instanceof TreeSet);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -107,8 +136,9 @@ public class CollectionsTypedReadOnlyTests {
}
@Test(expected=UnsupportedOperationException.class)
public void testTreeSet_2(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Set<String> items = items = (Set<String>) config.get("typed.treeset", Set.class);
+ Config config = ConfigProvider.getConfig();
+ Set<String> items = items = config.getValue("typed.treeset", TreeSet.class);
+ assertTrue(items instanceof TreeSet);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -117,9 +147,13 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testHashMap_1(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> items = config.get("typed.hashmap", new TypeLiteral<Map<String,String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.hashmap", new TypeLiteral<Map<String,String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Map<String,String> items = config.getValue("typed.hashmap", Map.class);
assertNotNull(items);
+ assertTrue(items instanceof HashMap);
assertFalse(items.isEmpty());
assertEquals(4, items.size());
assertEquals("a", items.get("1"));
@@ -130,9 +164,13 @@ public class CollectionsTypedReadOnlyTests {
}
@Test(expected=UnsupportedOperationException.class)
public void testHashMap_2(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> items = (Map<String,String>) config.get("typed.hashmap", Map.class);
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.hashmap", new TypeLiteral<HashMap<String,String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Map<String,String> items = config.getValue("typed.hashmap", Map.class);
assertNotNull(items);
+ assertTrue(items instanceof HashMap);
assertFalse(items.isEmpty());
assertEquals(4, items.size());
assertEquals("a", items.get("1"));
@@ -145,9 +183,13 @@ public class CollectionsTypedReadOnlyTests {
@Test(expected=UnsupportedOperationException.class)
public void testTreeMap_1(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> items = config.get("typed.treemap", new TypeLiteral<Map<String,String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.treemap", new TypeLiteral<HashMap<String,String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Map<String,String> items = config.getValue("typed.treemap", Map.class);
assertNotNull(items);
+ assertTrue(items instanceof TreeMap);
assertFalse(items.isEmpty());
assertEquals(4, items.size());
assertEquals("a", items.get("1"));
@@ -158,9 +200,13 @@ public class CollectionsTypedReadOnlyTests {
}
@Test(expected=UnsupportedOperationException.class)
public void testTreeMap_2(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> items = (Map<String,String>) config.get("typed.treemap", Map.class);
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed.treemap", new TypeLiteral<HashMap<String,String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Map<String,String> items = config.getValue("typed.treemap", TreeMap.class);
assertNotNull(items);
+ assertTrue(items instanceof TreeMap);
assertFalse(items.isEmpty());
assertEquals(4, items.size());
assertEquals("a", items.get("1"));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java b/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
index b4e4d52..8b2860d 100644
--- a/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
+++ b/collections/src/test/java/org/apache/tamaya/collections/CollectionsTypedTests.java
@@ -18,9 +18,11 @@
*/
package org.apache.tamaya.collections;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
+import javax.config.Config;
+import javax.config.ConfigProvider;
+
+import org.apache.tamaya.base.convert.ConversionContext;
+import org.apache.tamaya.spi.TypeLiteral;
import org.junit.Test;
import java.util.*;
@@ -40,13 +42,17 @@ public class CollectionsTypedTests {
@Test
public void testArrayListList_String(){
- Configuration config = ConfigurationProvider.getConfiguration();
- List<String> items = config.get("typed2.arraylist", new TypeLiteral<List<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.arraylist", new TypeLiteral<List<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ List<String> items = config.getValue("typed2.arraylist", List.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof ArrayList);
- items = (List<String>) config.get("typed2.arraylist", List.class);
+ items = (List<String>) config.getValue("typed2.arraylist", List.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -55,13 +61,17 @@ public class CollectionsTypedTests {
@Test
public void testLinkedListList_String(){
- Configuration config = ConfigurationProvider.getConfiguration();
- List<String> items = config.get("typed2.linkedlist", new TypeLiteral<List<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.linkedlist", new TypeLiteral<List<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ List<String> items = config.getValue("typed2.linkedlist", List.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof LinkedList);
- items = (List<String>) config.get("typed2.linkedlist", List.class);
+ items = (List<String>) config.getValue("typed2.linkedlist", List.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -71,13 +81,17 @@ public class CollectionsTypedTests {
@Test
public void testHashSet_String(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Set<String> items = config.get("typed2.hashset", new TypeLiteral<Set<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.hashset", new TypeLiteral<Set<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Set<String> items = config.getValue("typed2.hashset", Set.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof HashSet);
- items = (Set<String>) config.get("typed2.hashset", Set.class);
+ items = (Set<String>) config.getValue("typed2.hashset", Set.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -86,13 +100,17 @@ public class CollectionsTypedTests {
@Test
public void testTreeSet_String(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Set<String> items = config.get("typed2.treeset", new TypeLiteral<Set<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.treeset", new TypeLiteral<Set<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Set<String> items = config.getValue("typed2.treeset", Set.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof TreeSet);
- items = (Set<String>) config.get("typed2.treeset", Set.class);
+ items = (Set<String>) config.getValue("typed2.treeset", Set.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -101,9 +119,13 @@ public class CollectionsTypedTests {
@Test
public void testHashMap_String(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> items = config.get("typed2.hashmap", new TypeLiteral<Map<String,String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.treeset", new TypeLiteral<Map<String,String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Map<String, String> items = config.getValue("typed2.hashmap", Map.class);
assertNotNull(items);
+ ConversionContext.reset();
assertFalse(items.isEmpty());
assertEquals(4, items.size());
assertEquals("a", items.get("1"));
@@ -111,7 +133,7 @@ public class CollectionsTypedTests {
assertEquals("c", items.get("3"));
assertEquals(" ", items.get("4"));
assertTrue(items instanceof HashMap);
- items = (Map<String,String>) config.get("typed2.hashmap", Map.class);
+ items = (Map<String,String>) config.getValue("typed2.hashmap", Map.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(4, items.size());
@@ -124,9 +146,13 @@ public class CollectionsTypedTests {
@Test
public void testTreeMap_String(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> items = config.get("typed2.treemap", new TypeLiteral<Map<String,String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.treeset", new TypeLiteral<Map<String,String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Map<String, String> items = config.getValue("typed2.treemap", Map.class);
assertNotNull(items);
+ ConversionContext.reset();
assertFalse(items.isEmpty());
assertEquals(4, items.size());
assertEquals("a", items.get("1"));
@@ -134,7 +160,7 @@ public class CollectionsTypedTests {
assertEquals("c", items.get("3"));
assertEquals(" ", items.get("4"));
assertTrue(items instanceof TreeMap);
- items = (Map<String,String>) config.get("typed2.treemap", Map.class);
+ items = (Map<String,String>) config.getValue("typed2.treemap", Map.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(4, items.size());
@@ -147,13 +173,17 @@ public class CollectionsTypedTests {
@Test
public void testCollection_HashSet(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Collection<String> items = config.get("typed2.hashset", new TypeLiteral<Collection<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.treeset", new TypeLiteral<Collection<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Collection<String> items = config.getValue("typed2.hashset", Collection.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof HashSet);
- items = (Collection<String>) config.get("typed2.hashset", Collection.class);
+ items = (Collection<String>) config.getValue("typed2.hashset", Collection.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -162,13 +192,17 @@ public class CollectionsTypedTests {
@Test
public void testCollection_TreeSet(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Collection<String> items = config.get("typed2.treeset", new TypeLiteral<Collection<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.treeset", new TypeLiteral<Collection<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Collection<String> items = config.getValue("typed2.treeset", Collection.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof TreeSet);
- items = (Collection<String>) config.get("typed2.treeset", Collection.class);
+ items = (Collection<String>) config.getValue("typed2.treeset", Collection.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -177,13 +211,17 @@ public class CollectionsTypedTests {
@Test
public void testCollection_ArrayList(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Collection<String> items = config.get("typed2.arraylist", new TypeLiteral<Collection<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.arraylist", new TypeLiteral<Collection<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Collection<String> items = config.getValue("typed2.arraylist", Collection.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof ArrayList);
- items = (Collection<String>) config.get("typed2.arraylist", Collection.class);
+ items = (Collection<String>) config.getValue("typed2.arraylist", Collection.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
@@ -192,13 +230,17 @@ public class CollectionsTypedTests {
@Test
public void testCollection_LinkedList(){
- Configuration config = ConfigurationProvider.getConfiguration();
- Collection<String> items = config.get("typed2.linkedlist", new TypeLiteral<Collection<String>>(){});
+ Config config = ConfigProvider.getConfig();
+ ConversionContext ctx = new ConversionContext.Builder(
+ "typed2.linkedlist", new TypeLiteral<Collection<String>>(){}.getType()).build();
+ ConversionContext.setContext(ctx);
+ Collection<String> items = config.getValue("typed2.linkedlist", Collection.class);
+ ConversionContext.reset();
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
assertTrue(items instanceof LinkedList);
- items = (Collection<String>) config.get("typed2.linkedlist", Collection.class);
+ items = (Collection<String>) config.getValue("typed2.linkedlist", Collection.class);
assertNotNull(items);
assertFalse(items.isEmpty());
assertEquals(10, items.size());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java b/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
index 1c95261..988ace8 100644
--- a/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
+++ b/collections/src/test/java/org/apache/tamaya/collections/MyUpperCaseConverter.java
@@ -18,16 +18,15 @@
*/
package org.apache.tamaya.collections;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
+import javax.config.spi.Converter;
/**
* Example converter that is used for testing the custom parsing functionality. It sorrounds values with () and
* converts them to uppercase.
*/
-public class MyUpperCaseConverter implements PropertyConverter<String>{
+public class MyUpperCaseConverter implements Converter<String> {
@Override
- public String convert(String value, ConversionContext context) {
+ public String convert(String value) {
return "("+value.toUpperCase()+")";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configsources/bnd.bnd
----------------------------------------------------------------------
diff --git a/configsources/bnd.bnd b/configsources/bnd.bnd
new file mode 100644
index 0000000..dae0996
--- /dev/null
+++ b/configsources/bnd.bnd
@@ -0,0 +1,27 @@
+-buildpath: \
+ osgi.annotation; version=6.0.0,\
+ osgi.core; version=6.0,\
+ osgi.cmpn; version=6.0
+
+-testpath: \
+ ${junit}
+
+javac.source: 1.8
+javac.target: 1.8
+
+Bundle-Version: ${version}.${tstamp}
+Bundle-Name: Apache Tamaya - More PropertySources
+Bundle-SymbolicName: org.apache.tamaya.propertysources
+Bundle-Description: Apacha Tamaya Configuration - Reusable PropertySources
+Bundle-Category: Implementation
+Bundle-Copyright: (C) Apache Foundation
+Bundle-License: Apache Licence version 2
+Bundle-Vendor: Apache Software Foundation
+Bundle-ContactAddress: dev-tamaya@incubator.apache.org
+Bundle-DocURL: http://tamaya.apache.org
+Export-Package: \
+ org.apache.tamaya.propertysources
+Import-Package: \
+ org.apache.tamaya,\
+ org.apache.tamaya.spi,\
+ org.apache.tamaya.spisupport
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configsources/pom.xml
----------------------------------------------------------------------
diff --git a/configsources/pom.xml b/configsources/pom.xml
new file mode 100644
index 0000000..d97deb0
--- /dev/null
+++ b/configsources/pom.xml
@@ -0,0 +1,61 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.4-incubating-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>tamaya-configsources_alpha</artifactId>
+ <name>Apache Tamaya Modules - ConfigSources</name>
+ <description>A collection of simple config sources and config source providers.</description>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-core</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-resources</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigDirConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigDirConfigSourceProvider.java b/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigDirConfigSourceProvider.java
new file mode 100644
index 0000000..2f94c2c
--- /dev/null
+++ b/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigDirConfigSourceProvider.java
@@ -0,0 +1,75 @@
+/*
+ * 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.propertysources;
+
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.MappedConfigurationDataConfigSource;
+import org.apache.tamaya.resource.AbstractPathConfigSourceProvider;
+
+import javax.config.spi.ConfigSource;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A property provider implementation that tries to read all files in a directory as
+ * configuration.
+ */
+public class ConfigDirConfigSourceProvider extends AbstractPathConfigSourceProvider {
+
+ public ConfigDirConfigSourceProvider() {
+ super(getConfigLocation());
+ }
+
+ private static String getConfigLocation() {
+ String location = System.getProperty("configdir");
+ if (location == null) {
+ location = "./config";
+ }
+ if (!location.endsWith("/")) {
+ location += "/";
+ }
+ if (!location.startsWith("file:")) {
+ location = "file:" + location;
+ }
+ return location + "**/*.*";
+ }
+
+ @Override
+ protected Collection<ConfigSource> getConfigSources(URL url) {
+ try {
+ ConfigurationData config = ConfigurationFormats.readConfigurationData(url);
+ if (config == null) {
+ Logger.getLogger(getClass().getName()).log(Level.INFO,
+ "Failed to read configuration from " + url);
+ return Collections.emptySet();
+ }
+ return Collections.singleton(new MappedConfigurationDataConfigSource(config));
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Failed to read configuration from " + url, e);
+ return Collections.emptySet();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigSourceBuilder.java
----------------------------------------------------------------------
diff --git a/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigSourceBuilder.java b/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigSourceBuilder.java
new file mode 100644
index 0000000..36df14d
--- /dev/null
+++ b/configsources/src/main/java/org/apache/tamaya/propertysources/ConfigSourceBuilder.java
@@ -0,0 +1,119 @@
+/*
+ * 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.propertysources;
+
+import org.apache.tamaya.base.configsource.SimpleConfigSource;
+
+import javax.config.spi.ConfigSource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Simple builder for building a {@link ConfigSource}.
+ */
+public final class ConfigSourceBuilder {
+ /** The ordinal to be used. */
+ private int ordinal;
+ /** The name to be used. */
+ private final String name;
+ /** The properties. */
+ private final Map<String,String> properties = new HashMap<>();
+
+ /** private constructor. */
+ private ConfigSourceBuilder(String name){
+ this.name = Objects.requireNonNull(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static ConfigSourceBuilder of(String name){
+ return new ConfigSourceBuilder(name);
+ }
+
+ /**
+ * Gets a new instance of a builder.
+ * @param name The name of the property source, not null.
+ * @return a new instance.
+ */
+ public static ConfigSourceBuilder from(String name){
+ return new ConfigSourceBuilder(name);
+ }
+
+ /**
+ * Sets a new property key/value.
+ * @param key the property key, not null.
+ * @param value the property value, not null.
+ * @return the bulder for chaining.
+ */
+ public ConfigSourceBuilder put(String key, String value){
+ this.properties.put(key, value);
+ return this;
+ }
+
+ /**
+ * Put all the given key, values.
+ * @param values the new key/values, not null.
+ * @return the bulder for chaining.
+ */
+ public ConfigSourceBuilder putAll(Map<String, String> values){
+ this.properties.putAll(values);
+ return this;
+ }
+
+ /**
+ * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}.
+ * @param ordinal the explicit ordinal to be used.
+ * @return the bulder for chaining.
+ */
+ public ConfigSourceBuilder withOrdinal(int ordinal){
+ this.ordinal = ordinal;
+ return this;
+ }
+
+ /**
+ * Puts all values from the given property source.
+ * @param propertySource the property source, not null.
+ * @return the bulder for chaining.
+ */
+ public ConfigSourceBuilder putAll(ConfigSource propertySource){
+ this.properties.putAll(propertySource.getProperties());
+ return this;
+ }
+
+ /**
+ * Creates a new immutable {@link ConfigSource} instance.
+ * @return a new immutable {@link ConfigSource} instance, never null.
+ */
+ public ConfigSource build(){
+ return new SimpleConfigSource(name, properties);
+ }
+
+ @Override
+ public String toString() {
+ return "PropertySourceBuilder{" +
+ "ordinal=" + ordinal +
+ ", name='" + name + '\'' +
+ ", properties=" + properties +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configsources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/configsources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigConfigSourceProvider.java b/configsources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigConfigSourceProvider.java
new file mode 100644
index 0000000..dc64567
--- /dev/null
+++ b/configsources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigConfigSourceProvider.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.propertysources;
+
+
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.format.MappedConfigurationDataConfigSource;
+import org.apache.tamaya.resource.AbstractPathConfigSourceProvider;
+
+import javax.config.spi.ConfigSource;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Property source provider that reads all resources from {@code META-INF/config/**}
+ * into configuration sources..
+ */
+public class MetainfConfigConfigSourceProvider extends AbstractPathConfigSourceProvider {
+
+ public MetainfConfigConfigSourceProvider() {
+ super("classpath:META-INF/config/**/*.*");
+ }
+
+ @Override
+ protected Collection<ConfigSource> getConfigSources(URL url) {
+ try {
+ ConfigurationData config = ConfigurationFormats.readConfigurationData(url);
+ return Collections.singleton(new MappedConfigurationDataConfigSource(config));
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName()).log(Level.SEVERE,
+ "Failed to read configuration from " + url, e);
+ return Collections.emptySet();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configsources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java
----------------------------------------------------------------------
diff --git a/configsources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java b/configsources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java
new file mode 100644
index 0000000..42067e0
--- /dev/null
+++ b/configsources/src/test/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProviderTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.propertysources;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 30.10.16.
+ */
+public class MetainfConfigPropertySourceProviderTest {
+
+ @Test
+ public void getPropertySources_Default() throws Exception {
+ MetainfConfigConfigSourceProvider provider = new MetainfConfigConfigSourceProvider();
+ assertNotNull(provider.getConfigSources(getClass().getClassLoader()));
+ // TODO add test for containing property sources.
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/configured-sysprops/src/main/java/org/apache/tamaya/sysprops/ConfiguredSystemProperties.java
----------------------------------------------------------------------
diff --git a/configured-sysprops/src/main/java/org/apache/tamaya/sysprops/ConfiguredSystemProperties.java b/configured-sysprops/src/main/java/org/apache/tamaya/sysprops/ConfiguredSystemProperties.java
index 18f0349..c130500 100644
--- a/configured-sysprops/src/main/java/org/apache/tamaya/sysprops/ConfiguredSystemProperties.java
+++ b/configured-sysprops/src/main/java/org/apache/tamaya/sysprops/ConfiguredSystemProperties.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya.sysprops;
+import javax.config.Config;
+import javax.config.ConfigProvider;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -32,9 +34,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.logging.Logger;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-
/**
* Properties implementation class that can be applied as current System properties by calling
* {@link ConfiguredSystemProperties#install()}. The system properties will
@@ -330,10 +329,9 @@ public class ConfiguredSystemProperties extends Properties {
protected Properties createNewProperties() {
Properties props = new Properties(initialProperties);
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String, String> configMap = config.getProperties();
- for (Map.Entry<String, String> en : configMap.entrySet()) {
- props.put(en.getKey(), en.getValue());
+ Config config = ConfigProvider.getConfig();
+ for (String key : config.getPropertyNames()) {
+ props.put(key, config.getValue(key, String.class));
}
return props;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/etcd/bnd.bnd
----------------------------------------------------------------------
diff --git a/etcd/bnd.bnd b/etcd/bnd.bnd
index 027e033..f80b1df 100644
--- a/etcd/bnd.bnd
+++ b/etcd/bnd.bnd
@@ -22,9 +22,11 @@ Bundle-DocURL: http://tamaya.apache.org
Export-Package: \
org.apache.tamaya.etcd
Import-Package: \
- org.apache.tamaya,\
- org.apache.tamaya.spi,\
- org.apache.tamaya.mutableconfig\
+ javax.config,\
+ javax.config.spi,\
+ org.osgi.framework,\
+ javax.annotation,\
+ org.apache.tamaya.mutableconfig,\
org.apache.tamaya.mutableconfig.spi
Export-Service: \
org.apache.tamaya.spi.PropertySource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
----------------------------------------------------------------------
diff --git a/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java b/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
index dab3457..647bca3 100644
--- a/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
+++ b/management/src/main/java/org/apache/tamaya/management/ManagedConfig.java
@@ -19,12 +19,13 @@
package org.apache.tamaya.management;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.functions.ConfigurationFunctions;
+import javax.config.Config;
+import javax.config.ConfigProvider;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
/**
* Default implementation of the {@link ManagedConfigMBean} interface. Each bean binds to the
@@ -50,38 +51,52 @@ public class ManagedConfig implements ManagedConfigMBean {
@Override
public String getJsonConfigurationInfo() {
- return getConfigurationInternal().query(ConfigurationFunctions.jsonInfo());
+ return ConfigurationFunctions.jsonInfo().apply(getConfigurationInternal());
}
@Override
public String getXmlConfigurationInfo() {
- return getConfigurationInternal().query(ConfigurationFunctions.xmlInfo());
+ return ConfigurationFunctions.xmlInfo().apply(getConfigurationInternal());
}
@Override
public Map<String, String> getConfiguration() {
- return getConfigurationInternal().getProperties();
+ Map<String,String> map = new TreeMap<>();
+ for(String key:getConfigurationInternal().getPropertyNames()){
+ map.put(key, getConfigurationInternal().getValue(key, String.class));
+ }
+ return map;
}
@Override
public Map<String, String> getSection(String area, boolean recursive) {
- return getConfigurationInternal().with(ConfigurationFunctions.section(area, recursive)).getProperties();
+ Map<String,String> map = new TreeMap<>();
+
+ Config config = null;
+ if(recursive){
+ config = ConfigurationFunctions.sectionsRecursive(area).apply(getConfigurationInternal());
+ }else{
+ config = ConfigurationFunctions.section(area).apply(getConfigurationInternal());
+ }
+ for(String key:config.getPropertyNames()) {
+ map.put(key, config.getValue(key, String.class));
+ }
+ return map;
}
@Override
public Set<String> getSections() {
- return getConfigurationInternal().query(ConfigurationFunctions.sections());
+ return ConfigurationFunctions.sections().apply(getConfigurationInternal());
}
@Override
public Set<String> getTransitiveSections() {
- return getConfigurationInternal().query(ConfigurationFunctions.transitiveSections());
+ return ConfigurationFunctions.transitiveSections().apply(getConfigurationInternal());
}
@Override
public boolean isAreaExisting(String area) {
- return !getConfigurationInternal().with(
- ConfigurationFunctions.section(area)).getProperties().isEmpty();
+ return ConfigurationFunctions.section(area).apply(getConfigurationInternal()).getPropertyNames().iterator().hasNext();
}
@Override
@@ -92,15 +107,15 @@ public class ManagedConfig implements ManagedConfigMBean {
/**
* Evaluate the current configuration. By default this class is temporarely setting the
- * TCCL to the instance active on bean creation and then calls {@link ConfigurationProvider#getConfiguration()}.
+ * TCCL to the instance active on bean creation and then calls {@link ConfigProvider#getConfig()}.
*
* @return the configuration instance to be used.
*/
- protected Configuration getConfigurationInternal() {
+ protected Config getConfigurationInternal() {
ClassLoader currentCL = Thread.currentThread().getContextClassLoader();
try{
Thread.currentThread().setContextClassLoader(this.classLoader);
- return ConfigurationProvider.getConfiguration();
+ return ConfigProvider.getConfig();
} finally{
Thread.currentThread().setContextClassLoader(currentCL);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/management/src/main/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/management/src/main/resources/META-INF/javaconfiguration.properties b/management/src/main/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index 333ba9c..0000000
--- a/management/src/main/resources/META-INF/javaconfiguration.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z=alphabet
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
----------------------------------------------------------------------
diff --git a/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java b/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
index 90ad0bf..cb86117 100644
--- a/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
+++ b/management/src/test/java/org/apache/tamaya/management/internal/ManagedConfigTest.java
@@ -66,6 +66,7 @@ public class ManagedConfigTest {
@org.junit.Test
public void testGetConfigurationArea() throws Exception {
Map<String,String> cfg = bean.getSection("java", false);
+ System.out.println(cfg.keySet());
for(Map.Entry<String,String> en:cfg.entrySet()){
assertEquals(System.getProperty(en.getKey()), en.getValue());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/management/src/test/resources/META-INF/javaconfig.properties
----------------------------------------------------------------------
diff --git a/management/src/test/resources/META-INF/javaconfig.properties b/management/src/test/resources/META-INF/javaconfig.properties
new file mode 100644
index 0000000..333ba9c
--- /dev/null
+++ b/management/src/test/resources/META-INF/javaconfig.properties
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z=alphabet
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/meta/bnd.bnd
----------------------------------------------------------------------
diff --git a/meta/bnd.bnd b/meta/bnd.bnd
new file mode 100644
index 0000000..4e80876
--- /dev/null
+++ b/meta/bnd.bnd
@@ -0,0 +1,30 @@
+-buildpath: \
+ osgi.annotation; version=6.0.0,\
+ osgi.core; version=6.0,\
+ osgi.cmpn; version=6.0
+
+-testpath: \
+ ${junit}
+
+javac.source: 1.8
+javac.target: 1.8
+
+Bundle-Version: ${version}.${tstamp}
+Bundle-Name: Apache Tamaya - JMX
+Bundle-SymbolicName: org.apache.tamaya.management
+Bundle-Description: Apacha Tamaya Config - Meta Config Properties
+Bundle-Category: Implementation
+Bundle-Copyright: (C) Apache Foundation
+Bundle-License: Apache Licence version 2
+Bundle-Vendor: Apache Software Foundation
+Bundle-ContactAddress: dev-tamaya@incubator.apache.org
+Bundle-DocURL: http://tamaya.apache.org
+Export-Package: \
+ org.apache.tamaya.meta
+Import-Package: \
+ javax.config,\
+ javax.config.spi,\
+ org.osgi.framework,\
+ javax.annotation
+Export-Service: \
+ org.apache.tamaya.meta.spi.MetaPropertyMapping
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/meta/pom.xml
----------------------------------------------------------------------
diff --git a/meta/pom.xml b/meta/pom.xml
new file mode 100644
index 0000000..b2807e6
--- /dev/null
+++ b/meta/pom.xml
@@ -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 current the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-sandbox</artifactId>
+ <version>0.4-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>tamaya-meta</artifactId>
+ <name>Apache Tamaya Meta Parameter Extension</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>java-hamcrest</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/meta/src/main/java/org/apache/tamaya/meta/MetaProperties.java
----------------------------------------------------------------------
diff --git a/meta/src/main/java/org/apache/tamaya/meta/MetaProperties.java b/meta/src/main/java/org/apache/tamaya/meta/MetaProperties.java
new file mode 100644
index 0000000..b2a703e
--- /dev/null
+++ b/meta/src/main/java/org/apache/tamaya/meta/MetaProperties.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.meta;
+
+
+import org.apache.tamaya.meta.spi.MetaPropertyMapping;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import javax.config.Config;
+import javax.config.spi.ConfigSource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.logging.Logger;
+
+
+/**
+ * Accessor singleton for Meta-entries.
+ */
+public final class MetaProperties {
+
+ /** The logger used. */
+ private final static Logger LOG = Logger.getLogger(MetaProperties.class.getName());
+
+
+ /**
+ * Private singleton constructor.
+ */
+ private MetaProperties(){}
+
+ /**
+ * Checks if the given key is a meta-entry.
+ * @param key the config key, not null.
+ * @return true, if the entry is a meta-entry.
+ */
+ public static boolean isMetaEntry(String key){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ return mapping.getMetaEntryFilter(null).test(key);
+ }
+
+ /**
+ * Get all meta-entries of the given config instance.
+ * @param config the config, not null.
+ * @return the meta entries found.
+ */
+ public static Map<String,String> getMetaEntries(Config config){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ Map<String,String> result = new HashMap<>();
+ Predicate<String> filter = mapping.getMetaEntryFilter(null);
+ config.getPropertyNames().forEach(k -> {
+ if(filter.test(k)){
+ result.put(k, config.getValue(k, String.class));
+ }
+ });
+ return result;
+ }
+
+ /**
+ * Get all meta-entries of the given config source and entry of the given configuration.
+ * @param config the config, not null
+ * @param configSource the configSource name, not null.
+ * @return the meta entries found.
+ */
+ public static Map<String,String> getMetaEntriesForConfigSource(Config config, String configSource){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ Map<String,String> result = new HashMap<>();
+ Predicate<String> filter = mapping.getMetaEntryFilter(null);
+ for(ConfigSource cs:config.getConfigSources()){
+ if(cs.getName().equals(configSource)){
+ cs.getProperties().entrySet().forEach(k -> {
+ if(filter.test(k.getKey())){
+ result.put(k.getKey(), k.getValue());
+ }
+ });
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get all meta-entries of the given config instance and entry.
+ * @param config the config, not null
+ * @param key the target key, not null.
+ * @return the meta entries found.
+ */
+ public static Map<String,String> getMetaEntries(Config config, String key){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ Map<String,String> result = new HashMap<>();
+ Predicate<String> filter = mapping.getMetaEntryFilter(key);
+ config.getPropertyNames().forEach(k -> {
+ if(filter.test(k)){
+ result.put(k, config.getValue(k, String.class));
+ }
+ });
+ return result;
+ }
+
+ /**
+ * Get the given metaentry.
+ * @param config the config, not null
+ * @param key the target key, not null.
+ * @param metaEntry the meta entry key, not null.
+ * @return the meta entry value.
+ */
+ public static String getMetaEntry(Config config, String key, String metaEntry){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ return config.getValue(mapping.getKey(key, metaEntry), String.class);
+ }
+
+ /**
+ * Get the given metaentry.
+ * @param config the config, not null
+ * @param key the target key, not null.
+ * @param metaEntry the meta entry key, not null.
+ * @param targetType the target type, not null.
+ * @return the meta entry value.
+ */
+ public static <T> T getMetaEntry(Config config, String key, String metaEntry, Class<T> targetType){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ return config.getValue(mapping.getKey(key, metaEntry), targetType);
+ }
+
+ /**
+ * Get the given (optional) metaentry.
+ * @param config the config, not null
+ * @param key the target key, not null.
+ * @param metaEntry the meta entry key, not null.
+ * @return the meta entry value.
+ */
+ public static Optional<String> getOptionalMetaEntry(Config config, String key, String metaEntry){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ return config.getOptionalValue(mapping.getKey(key, metaEntry), String.class);
+ }
+
+ /**
+ * Get the given (optional) metaentry.
+ * @param config the config, not null
+ * @param key the target key, not null.
+ * @param metaEntry the meta entry key, not null.
+ * @param targetType the target type, not null.
+ * @return the meta entry value.
+ */
+ public static <T> Optional<T> getOptionalMetaEntry(Config config, String key, String metaEntry, Class<T> targetType) {
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ return config.getOptionalValue(mapping.getKey(key, metaEntry), targetType);
+ }
+
+ /**
+ * Get the corresponding meta key for a given key. This method can be used by property sources to add
+ * the correct meta keys, hereby using the correct metadata representation key layout.
+ * @param entryKey the key of the config entry, not null.
+ * @param metaKey the metadata key, not null.
+ * @return the key to be used to store/reference the given metadata.
+ */
+ public static String getMetaKey(String entryKey, String metaKey){
+ MetaPropertyMapping mapping = ServiceContextManager.getServiceContext().getService(MetaPropertyMapping.class);
+ return mapping.getKey(entryKey, metaKey);
+ }
+
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/meta/src/main/java/org/apache/tamaya/meta/internal/DefaultMetaPropertyMapping.java
----------------------------------------------------------------------
diff --git a/meta/src/main/java/org/apache/tamaya/meta/internal/DefaultMetaPropertyMapping.java b/meta/src/main/java/org/apache/tamaya/meta/internal/DefaultMetaPropertyMapping.java
new file mode 100644
index 0000000..495af8a
--- /dev/null
+++ b/meta/src/main/java/org/apache/tamaya/meta/internal/DefaultMetaPropertyMapping.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy 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.meta.internal;
+
+import org.apache.tamaya.meta.spi.MetaPropertyMapping;
+
+import javax.annotation.Priority;
+import java.util.function.Predicate;
+
+
+/**
+ * Default metadata property mapping, which defines the following mapping:
+ * <pre>
+ * foo.bar.Property=foo
+ *
+ * // JSON
+ * "foo.bar.Property": {
+ * "[meta]": {
+ * "propertysource": " MyPropertySource"
+ * }
+ * }
+ *
+ * // YAML
+ * foo.bar.Property:
+ * [meta]:
+ * propertysource: "MyPropertySource"
+ *
+ * // properties
+ * foor.bar.Property.[meta].propertySource=MyPropertySource
+ * </pre>
+ */
+@Priority(1)
+public final class DefaultMetaPropertyMapping implements MetaPropertyMapping{
+
+ @Override
+ public String getKey(String entryKey, String metaKey) {
+ return entryKey + ".[meta]."+metaKey;
+ }
+
+ @Override
+ public Predicate<String> getMetaEntryFilter(String key) {
+ return s -> s.contains(".[meta].");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/meta/src/main/java/org/apache/tamaya/meta/internal/EtcdMetaPropertyMapping.java
----------------------------------------------------------------------
diff --git a/meta/src/main/java/org/apache/tamaya/meta/internal/EtcdMetaPropertyMapping.java b/meta/src/main/java/org/apache/tamaya/meta/internal/EtcdMetaPropertyMapping.java
new file mode 100644
index 0000000..14e9009
--- /dev/null
+++ b/meta/src/main/java/org/apache/tamaya/meta/internal/EtcdMetaPropertyMapping.java
@@ -0,0 +1,55 @@
+/*
+ * 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.meta.internal;
+
+import org.apache.tamaya.meta.spi.MetaPropertyMapping;
+
+import java.util.function.Predicate;
+
+
+/**
+ * Default metadata property mapping, which defines the following mapping:
+ * <pre>
+ * foo.bar.Property=foo
+ *
+ * // JSON
+ * "_foo.bar.Property": {
+ * "propertysource": " MyPropertySource"
+ * }
+ *
+ * // YAML
+ * _foo.bar.Property:
+ * propertysource: "MyPropertySource"
+ *
+ * // properties
+ * _foo.bar.Property.propertySource=MyPropertySource
+ * </pre>
+ */
+public final class EtcdMetaPropertyMapping implements MetaPropertyMapping{
+
+ @Override
+ public String getKey(String entryKey, String metaKey) {
+ return "_" + entryKey + "."+metaKey;
+ }
+
+ @Override
+ public Predicate<String> getMetaEntryFilter(String key) {
+ return s -> s.startsWith("_");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/meta/src/main/java/org/apache/tamaya/meta/spi/MetaPropertyMapping.java
----------------------------------------------------------------------
diff --git a/meta/src/main/java/org/apache/tamaya/meta/spi/MetaPropertyMapping.java b/meta/src/main/java/org/apache/tamaya/meta/spi/MetaPropertyMapping.java
new file mode 100644
index 0000000..05cfa9b
--- /dev/null
+++ b/meta/src/main/java/org/apache/tamaya/meta/spi/MetaPropertyMapping.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.meta.spi;
+
+import java.util.function.Predicate;
+
+/**
+ * Interface for defining the mapping strategy for meta properties.
+ */
+public interface MetaPropertyMapping {
+
+ /**
+ * Get the corresponding full metadata key, for the given entry key and metadata key.
+ * @param entryKey the entry key, not null.
+ * @param metaKey the metadata key, not null.
+ * @return the corresponding metadata key, not null.
+ */
+ String getKey(String entryKey, String metaKey);
+
+ /**
+ * Get a predicate for the given key (optional) to extract all metaentries.
+ * @param key the key, or null, for all metaentries in a configuration.
+ * @return the predicate to test if the given key is a metadata key.
+ */
+ Predicate<String> getMetaEntryFilter(String key);
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/pom.xml
----------------------------------------------------------------------
diff --git a/metamodel/pom.xml b/metamodel/pom.xml
index 9d75493..a3bff90 100644
--- a/metamodel/pom.xml
+++ b/metamodel/pom.xml
@@ -36,9 +36,15 @@
<dependencies>
<dependency>
<groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-base</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${project.parent.version}</version>
- <scope>test</scope>
+ <scope>compile</scope>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
@@ -74,24 +80,6 @@
<artifactId>bsh</artifactId>
<version>2.0b6</version>
</dependency>
- <!--<dependency>-->
- <!--<groupId>org.apache.tamaya.ext</groupId>-->
- <!--<artifactId>tamaya-json</artifactId>-->
- <!--<version>${project.version}</version>-->
- <!--<scope>provided</scope>-->
- <!--<optional>true</optional>-->
- <!--</dependency>-->
- <!--<dependency>-->
- <!--<groupId>org.apache.johnzon</groupId>-->
- <!--<artifactId>johnzon-core</artifactId>-->
- <!--<version>${johnzon.version}</version>-->
- <!--</dependency>-->
- <!--<dependency>-->
- <!--<groupId>org.apache.geronimo.specs</groupId>-->
- <!--<artifactId>geronimo-json_1.0_spec</artifactId>-->
- <!--<version>1.0-alpha-1</version>-->
- <!--<scope>compile</scope>-->
- <!--</dependency>-->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
index d2a343c..98d2ebe 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/CachedFilter.java
@@ -19,9 +19,7 @@
package org.apache.tamaya.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.Filter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,7 +30,7 @@ import java.util.concurrent.TimeUnit;
* is changing underneath, hereby different values for single and multi-property access
* are considered.
*/
-public class CachedFilter implements PropertyFilter{
+public class CachedFilter implements Filter{
private String matches;
private Map<String, CachedEntry> cachedEntries = new ConcurrentHashMap<>();
@@ -42,20 +40,20 @@ public class CachedFilter implements PropertyFilter{
/**
* Factory for configuring immutable property filter.
*/
- public static final class CachedFilterFactory implements ItemFactory<PropertyFilter> {
+ public static final class CachedFilterFactory implements ItemFactory<Filter> {
@Override
public String getName() {
return "Cached";
}
@Override
- public PropertyFilter create(Map<String,String> parameters) {
+ public Filter create(Map<String,String> parameters) {
return new CachedFilter();
}
@Override
- public Class<? extends PropertyFilter> getType() {
- return PropertyFilter.class;
+ public Class<? extends Filter> getType() {
+ return Filter.class;
}
}
@@ -69,11 +67,9 @@ public class CachedFilter implements PropertyFilter{
}
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ public String filterProperty(String key, String value) {
if(matches !=null){
- if(value.getKey().matches(matches)){
- return resolveCachedEntry(value);
- }
+ return resolveCachedEntry(key, value);
}
return value;
}
@@ -84,15 +80,15 @@ public class CachedFilter implements PropertyFilter{
* @param value
* @return
*/
- private PropertyValue resolveCachedEntry(PropertyValue value) {
+ private String resolveCachedEntry(String key, String value) {
if(maxSize>0 && maxSize<=this.cachedEntries.size()){
return value;
}
- CachedEntry ce = cachedEntries.get(value.getKey());
+ CachedEntry ce = cachedEntries.get(key);
if(ce==null || !ce.isValid()){
if(value!=null) {
- ce = new CachedEntry(value, System.currentTimeMillis() + timeout);
- this.cachedEntries.put(value.getKey(), ce);
+ ce = new CachedEntry(key, value, System.currentTimeMillis() + timeout);
+ this.cachedEntries.put(key, ce);
}
}
return value;
@@ -110,11 +106,13 @@ public class CachedFilter implements PropertyFilter{
private static final class CachedEntry{
long ttl;
- PropertyValue value;
+ String key;
+ String value;
- public CachedEntry (PropertyValue value, long ttl){
+ public CachedEntry (String key, String value, long ttl){
this.ttl = ttl;
this.value = value;
+ this.key = key;
}
public boolean isValid(){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledConfigSource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledConfigSource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledConfigSource.java
new file mode 100644
index 0000000..14834e2
--- /dev/null
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledConfigSource.java
@@ -0,0 +1,113 @@
+/*
+ * 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.metamodel;
+
+import org.apache.tamaya.base.configsource.ConfigSourceComparator;
+import org.apache.tamaya.metamodel.internal.resolver.JavaResolver;
+
+import javax.config.spi.ConfigSource;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.logging.Logger;
+
+
+/**
+ * Wrapped property source that allows enabling a property source using an
+ * {@code enabled} expression.
+ */
+public final class EnabledConfigSource
+ implements ConfigSource, Enabled {
+
+ private static final Logger LOG = Logger.getLogger(EnabledConfigSource.class.getName());
+ private String enabledExpression;
+ private ConfigSource wrapped;
+ private boolean enabled;
+ private static final JavaResolver resolver = new JavaResolver();
+
+ public EnabledConfigSource(ConfigSource wrapped, Map<String,String> context, String expression) {
+ this.enabledExpression = Objects.requireNonNull(expression);
+ this.wrapped = Objects.requireNonNull(wrapped);
+ this.enabled = calculateEnabled(context);
+ }
+
+ protected boolean calculateEnabled(Map<String, String> context) {
+ try {
+ return Boolean.TRUE.equals(resolver.evaluate(enabledExpression, context));
+ } catch (Exception e) {
+ LOG.severe("Invalid Boolean expression: '"
+ +enabledExpression+"': " + e + ", property source will be disabled: " +
+ wrapped.getName());
+ }
+ return false;
+ }
+
+ /**
+ * Returns the enabled property.
+ * @return the enabled value.
+ */
+ @Override
+ public boolean isEnabled(){
+ return enabled;
+ }
+
+ /**
+ * Enables/disables this property source.
+ * @param enabled the enabled value.
+ */
+ @Override
+ public void setEnabled(boolean enabled){
+ this.enabled = enabled;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return ConfigSourceComparator.getOrdinal(this.wrapped);
+ }
+
+
+ @Override
+ public String getName() {
+ return this.wrapped.getName();
+ }
+
+ @Override
+ public String getValue(String key) {
+ if(!isEnabled()){
+ return null;
+ }
+ return this.wrapped.getValue(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ if(!isEnabled()){
+ return Collections.emptyMap();
+ }
+ return this.wrapped.getProperties();
+ }
+
+ @Override
+ public String toString() {
+ return "DynamicPropertySource{" +
+ "\n enabled=" + enabledExpression +
+ "\n wrapped=" + wrapped +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
deleted file mode 100644
index 2dcf101..0000000
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/EnabledPropertySource.java
+++ /dev/null
@@ -1,121 +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.metamodel;
-
-import org.apache.tamaya.metamodel.internal.resolver.JavaResolver;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.PropertySourceComparator;
-
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
-import javax.script.ScriptException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-
-/**
- * Wrapped property source that allows enabling a property source using an
- * {@code enabled} expression.
- */
-public final class EnabledPropertySource
- implements PropertySource, Enabled {
-
- private static final Logger LOG = Logger.getLogger(EnabledPropertySource.class.getName());
- private String enabledExpression;
- private PropertySource wrapped;
- private boolean enabled;
- private static final JavaResolver resolver = new JavaResolver();
-
- public EnabledPropertySource(PropertySource wrapped, Map<String,String> context, String expression) {
- this.enabledExpression = Objects.requireNonNull(expression);
- this.wrapped = Objects.requireNonNull(wrapped);
- this.enabled = calculateEnabled(context);
- }
-
- protected boolean calculateEnabled(Map<String, String> context) {
- try {
- return Boolean.TRUE.equals(resolver.evaluate(enabledExpression, context));
- } catch (Exception e) {
- LOG.severe("Invalid Boolean expression: '"
- +enabledExpression+"': " + e + ", property source will be disabled: " +
- wrapped.getName());
- }
- return false;
- }
-
- /**
- * Returns the enabled property.
- * @return the enabled value.
- */
- @Override
- public boolean isEnabled(){
- return enabled;
- }
-
- /**
- * Enables/disables this property source.
- * @param enabled the enabled value.
- */
- @Override
- public void setEnabled(boolean enabled){
- this.enabled = enabled;
- }
-
- @Override
- public int getOrdinal() {
- return PropertySourceComparator.getOrdinal(this.wrapped);
- }
-
- @Override
- public String getName() {
- return this.wrapped.getName();
- }
-
- @Override
- public PropertyValue get(String key) {
- if(!isEnabled()){
- return null;
- }
- return this.wrapped.get(key);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- if(!isEnabled()){
- return Collections.emptyMap();
- }
- return this.wrapped.getProperties();
- }
-
- @Override
- public boolean isScannable() {
- return this.wrapped.isScannable();
- }
-
- @Override
- public String toString() {
- return "DynamicPropertySource{" +
- "\n enabled=" + enabledExpression +
- "\n wrapped=" + wrapped +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
index 6a1e116..820bb18 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/HideFilter.java
@@ -19,10 +19,7 @@
package org.apache.tamaya.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
+import org.apache.tamaya.spi.*;
import java.util.Map;
@@ -31,27 +28,27 @@ import java.util.Map;
* is changing underneath, hereby different values for single and multi-property access
* are considered.
*/
-public class HideFilter implements PropertyFilter{
+public class HideFilter implements Filter{
private String matches;
/**
* Factory for configuring immutable property filter.
*/
- public static final class HideFilterFactory implements ItemFactory<PropertyFilter> {
+ public static final class HideFilterFactory implements ItemFactory<Filter> {
@Override
public String getName() {
return "Hide";
}
@Override
- public PropertyFilter create(Map<String,String> parameters) {
+ public Filter create(Map<String,String> parameters) {
return new HideFilter();
}
@Override
- public Class<? extends PropertyFilter> getType() {
- return PropertyFilter.class;
+ public Class<? extends Filter> getType() {
+ return Filter.class;
}
}
@@ -65,9 +62,9 @@ public class HideFilter implements PropertyFilter{
}
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ public String filterProperty(String key, String value) {
if(matches !=null){
- if(value.getKey().matches(matches)){
+ if(key.matches(matches)){
return null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/db6b909a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
----------------------------------------------------------------------
diff --git a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
index 13f3d0c..3a0446b 100644
--- a/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
+++ b/metamodel/src/main/java/org/apache/tamaya/metamodel/ImmutableFilter.java
@@ -19,9 +19,7 @@
package org.apache.tamaya.metamodel;
import org.apache.tamaya.metamodel.spi.ItemFactory;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.Filter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -31,37 +29,36 @@ import java.util.concurrent.ConcurrentHashMap;
* is changing underneath, hereby different values for single and multi-property access
* are considered.
*/
-public class ImmutableFilter implements PropertyFilter{
+public class ImmutableFilter implements Filter{
/**
* Factory for configuring immutable property filter.
*/
- public static final class ImmutableFilterFactory implements ItemFactory<PropertyFilter> {
+ public static final class ImmutableFilterFactory implements ItemFactory<Filter> {
@Override
public String getName() {
return "Immutable";
}
@Override
- public PropertyFilter create(Map<String,String> parameters) {
+ public Filter create(Map<String,String> parameters) {
return new ImmutableFilter();
}
@Override
- public Class<? extends PropertyFilter> getType() {
- return PropertyFilter.class;
+ public Class<? extends Filter> getType() {
+ return Filter.class;
}
}
- private Map<String,PropertyValue> map = new ConcurrentHashMap<>();
+ private Map<String,String> map = new ConcurrentHashMap<>();
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- String key = value.getKey();
- if(!context.isSinglePropertyScoped()) {
- key = value.getKey() + "_all";
- }
- PropertyValue val = map.get(key);
+ public String filterProperty(String key, String value) {
+// if(!context.isSinglePropertyScoped()) {
+// key = key + "_all";
+// }
+ String val = map.get(key);
if(val==null){
map.put(key, value);
val = value;