tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [06/13] incubator-tamaya git commit: Added functionality for evaluating specific PropertySources for types implemented.
Date Mon, 12 Oct 2015 06:03:01 GMT
Added functionality for evaluating specific PropertySources for types implemented.


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

Branch: refs/heads/master
Commit: 9a4bd7754cce2db516e7d53aed397aca56cd21c0
Parents: 2df75a8
Author: anatole <anatole@apache.org>
Authored: Fri Oct 9 00:09:10 2015 +0200
Committer: anatole <anatole@apache.org>
Committed: Mon Oct 12 08:01:48 2015 +0200

----------------------------------------------------------------------
 .../functions/PropertySourceFunctions.java      | 39 +++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9a4bd775/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
index 0eed11b..c0392d9 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
@@ -18,14 +18,21 @@
  */
 package org.apache.tamaya.functions;
 
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigurationProvider;
 import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContextManager;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.logging.Logger;
 
 /**
  * Accessor that provides useful functions along with configuration.
@@ -265,7 +272,7 @@ public final class PropertySourceFunctions {
      */
     static String stripSectionKeys(String key, String... areaKeys) {
         for(String areaKey:areaKeys) {
-            if(key.startsWith(areaKey+'.')) {
+            if(key.startsWith(areaKey + '.')) {
                 return key.substring(areaKey.length() + 1);
             }
         }
@@ -308,4 +315,34 @@ public final class PropertySourceFunctions {
         return EMPTY_PROPERTYSOURCE;
     }
 
+    /**
+     * Get a list of all {@link PropertySource} instances managed by the current
+     * {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given
type.
+     * @return the list of all {@link PropertySource} instances matching, never null.
+     */
+    public static <T> Collection<T> getPropertySources(Class<T> type) {
+        List<T> result = new ArrayList<>();
+        for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources())
{
+            if (type.isAssignableFrom(src.getClass())) {
+                result.add((T) src);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Get a list of all {@link PropertySource} instances managed by the current
+     * {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given
type.
+     * @return the list of all {@link PropertySource} instances matching, never null.
+     */
+    public static <T> T getPropertySource(Class<T> type) {
+        List<T> result = new ArrayList<>();
+        for (PropertySource src : ConfigurationProvider.getConfigurationContext().getPropertySources())
{
+            if (type.isAssignableFrom(src.getClass())) {
+                return (T)src;
+            }
+        }
+        return null;
+    }
+
 }


Mime
View raw message