You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/09/06 17:17:59 UTC

[03/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-112: Add Module Support for Collections - adding configuration data, adaptive combination policy and PropertyConverter skeletons,

TAMAYA-112: Add Module Support for Collections - adding configuration data, adaptive combination policy and PropertyConverter skeletons,


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/9a34a72a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/9a34a72a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/9a34a72a

Branch: refs/heads/master
Commit: 9a34a72ac30b94c0c9fdc4a5830ab5f28088dfb3
Parents: e901866
Author: anatole <an...@apache.org>
Authored: Sat Sep 26 01:56:09 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Sat Sep 26 01:56:09 2015 +0200

----------------------------------------------------------------------
 collections/pom.xml                             | 52 +++++++++++++++
 .../internal/AdaptiveCombinationPolicy.java     | 66 ++++++++++++++++++++
 .../internal/ArrayListConverter.java            | 34 ++++++++++
 .../collections/internal/HashMapConverter.java  | 34 ++++++++++
 .../collections/internal/HashSetConverter.java  | 33 ++++++++++
 .../internal/LinkedListConverter.java           | 33 ++++++++++
 .../collections/internal/TreeMapConverter.java  | 34 ++++++++++
 .../collections/internal/TreeSetConverter.java  | 34 ++++++++++
 .../META-INF/javaconfiguration.properties       | 50 +++++++++++++++
 ...he.tamaya.spi.PropertyValueCombinationPolicy | 19 ++++++
 10 files changed, 389 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/pom.xml
----------------------------------------------------------------------
diff --git a/collections/pom.xml b/collections/pom.xml
new file mode 100644
index 0000000..7726888
--- /dev/null
+++ b/collections/pom.xml
@@ -0,0 +1,52 @@
+<!-- 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy current the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.tamaya.ext</groupId>
+        <artifactId>tamaya-sandbox</artifactId>
+        <version>0.2-incubating-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+
+    <artifactId>tamaya-collections</artifactId>
+    <name>Apache Tamaya Modules - Collections Support</name>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-java7-core</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-java7-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java b/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
new file mode 100644
index 0000000..113d817
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/AdaptiveCombinationPolicy.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+
+import javax.annotation.Priority;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * PropertyValueCombinationPolicy that allows to configure a PropertyValueCombinationPolicy for each key
+ * individually, by adding a configured entry of the form {@code key{combinationPolicy}=fqPolicyClassName}.
+ */
+@Priority(100)
+public class AdaptiveCombinationPolicy implements PropertyValueCombinationPolicy {
+
+    private static final Logger LOG = Logger.getLogger(AdaptiveCombinationPolicy.class.getName());
+
+    private Map<Class, PropertyValueCombinationPolicy> configuredPolicies = new ConcurrentHashMap<>();
+
+    @Override
+    public String collect(String currentValue, String key, PropertySource propertySource) {
+        String adaptiveCombinationPolicyClass  = ConfigurationProvider.getConfiguration().get(key+"{combinationPolicy}");
+        if(adaptiveCombinationPolicyClass!=null){
+            PropertyValueCombinationPolicy delegatePolicy = null;
+            try{
+                Class clazz = Class.forName(adaptiveCombinationPolicyClass);
+                delegatePolicy = configuredPolicies.get(clazz);
+                if(delegatePolicy==null){
+                    delegatePolicy = PropertyValueCombinationPolicy.class.cast(clazz.newInstance());
+                    configuredPolicies.put(clazz, delegatePolicy);
+                }
+                return delegatePolicy.collect(currentValue, key, propertySource);
+            }
+            catch(Exception e){
+                LOG.log(Level.SEVERE, "Error loading configured PropertyValueCombinationPolicy for key: " + key, e);
+            }
+        }
+        String newValue = propertySource.get(key);
+        if(newValue!=null){
+            return newValue;
+        }
+        return currentValue;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
new file mode 100644
index 0000000..0d7e6f3
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/ArrayListConverter.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+
+/**
+ *  PropertyConverter for gnerating ArrayList representation of a values.
+ */
+public class ArrayListConverter implements PropertyConverter<ArrayList<?>> {
+    @Override
+    public ArrayList<?> convert(String value) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
new file mode 100644
index 0000000..917c31e
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/HashMapConverter.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.HashMap;
+import java.util.TreeSet;
+
+/**
+ *  PropertyConverter for gnerating HashMap representation of a values.
+ */
+public class HashMapConverter implements PropertyConverter<HashMap<?,?>> {
+    @Override
+    public HashMap<?,?> convert(String value) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
new file mode 100644
index 0000000..d41b6a2
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/HashSetConverter.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.HashSet;
+
+/**
+ *  PropertyConverter for gnerating HashSet representation of a values.
+ */
+public class HashSetConverter implements PropertyConverter<HashSet<?>> {
+    @Override
+    public HashSet<?> convert(String value) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
new file mode 100644
index 0000000..aaca08d
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/LinkedListConverter.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.LinkedList;
+
+/**
+ *  PropertyConverter for gnerating LinkedList representation of a values.
+ */
+public class LinkedListConverter implements PropertyConverter<LinkedList<?>> {
+    @Override
+    public LinkedList<?> convert(String value) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
new file mode 100644
index 0000000..6e74d5c
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeMapConverter.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.HashMap;
+import java.util.TreeMap;
+
+/**
+ *  PropertyConverter for gnerating HashMap representation of a values.
+ */
+public class TreeMapConverter implements PropertyConverter<TreeMap<?,?>> {
+    @Override
+    public TreeMap<?,?> convert(String value) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
new file mode 100644
index 0000000..2797c91
--- /dev/null
+++ b/collections/src/main/java/org/apache/tamaya/collections/internal/TreeSetConverter.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.collections.internal;
+
+import org.apache.tamaya.spi.PropertyConverter;
+
+import java.util.HashSet;
+import java.util.TreeSet;
+
+/**
+ *  PropertyConverter for gnerating HashSet representation of a values.
+ */
+public class TreeSetConverter implements PropertyConverter<TreeSet<?>> {
+    @Override
+    public TreeSet<?> convert(String value) {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/collections/src/test/resources/META-INF/javaconfiguration.properties b/collections/src/test/resources/META-INF/javaconfiguration.properties
new file mode 100644
index 0000000..7d8031e
--- /dev/null
+++ b/collections/src/test/resources/META-INF/javaconfiguration.properties
@@ -0,0 +1,50 @@
+#
+# 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.
+#
+
+# Examples for collection syntax
+
+list=a,b,c
+list{collection-type}=List
+#list{collection-combinationPolicy}=MyLeftAppendingCombinationPolicy
+
+arrayList=d;e;f
+arrayList{collection-type}=java.util.ArrayList
+arrayList{collection-separator}=;
+#arrayList{collection-valueParser}=myParserClass
+
+linkedList=g,h,i
+linkedList{collection-type}=java.util.LinkedList
+
+set=a,b,b
+set{collection-type}=java.util.Set
+set{combinationPolicy}=WarnOnDuplicates
+
+sortedSet=a,c,b
+sortedSet{collection:type}=java.util.TreeSet
+
+map=1:a,2:b,3:c
+map{collection-type}=Map
+#map{collection-keyParser}=myParserClass
+#map{collection-valueParser}=myParserClass
+
+sortedMap=|3:c||1:a||2:b|
+sortedMap{collection-type}=java.util.TreeMap
+
+concurrentMap=|3:c||1:a||2:b|
+concurrentMap{collection-type}=java.util.ConcurrentHashMap
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/9a34a72a/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
----------------------------------------------------------------------
diff --git a/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy b/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
new file mode 100644
index 0000000..6b7a67b
--- /dev/null
+++ b/collections/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyValueCombinationPolicy
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy current the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.collections.internal.AdaptiveCombinationPolicy
\ No newline at end of file