felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1796628 - /felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
Date Mon, 29 May 2017 13:49:09 GMT
Author: cziegeler
Date: Mon May 29 13:49:09 2017
New Revision: 1796628

URL: http://svn.apache.org/viewvc?rev=1796628&view=rev
Log:
Refactor utility methods

Modified:
    felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java

Modified: felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java?rev=1796628&r1=1796627&r2=1796628&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
(original)
+++ felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
Mon May 29 13:49:09 2017
@@ -29,6 +29,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
@@ -186,10 +187,11 @@ public class JSONUtil {
             final Report report) {
         final List<Config> configurations = new ArrayList<>();
         for(final Map.Entry<String, ?> entry : configs.entrySet()) {
-            if ( ! (entry.getValue() instanceof JsonObject) ) {
+            if ( ! (entry.getValue() instanceof Map) ) {
                 report.errors.add("Ignoring configuration in '" + identifier + "' (not a
configuration) : " + entry.getKey());
             } else {
-                final JsonObject mainMap = (JsonObject)entry.getValue();
+                @SuppressWarnings("unchecked")
+                final Map<String, ?> mainMap = (Map<String, ?>)entry.getValue();
                 final int envIndex = entry.getKey().indexOf('[');
                 if ( envIndex != -1 && !entry.getKey().endsWith("]") ) {
                     report.errors.add("Ignoring configuration in '" + identifier + "' (invalid
environments definition) : " + entry.getKey());
@@ -214,7 +216,7 @@ public class JSONUtil {
                 final Dictionary<String, Object> properties = new Hashtable<>();
                 boolean valid = true;
                 for(final String mapKey : mainMap.keySet()) {
-                    final Object value = getValue(mainMap, mapKey);
+                    final Object value = mainMap.get(mapKey);
 
                     final boolean internalKey = mapKey.startsWith(INTERNAL_PREFIX);
                     String key = mapKey;
@@ -339,8 +341,13 @@ public class JSONUtil {
                              array.add(getValue(x));
                          }
                          return array;
-            // type OBJECT -> return object
-            case OBJECT : return value;
+             // type OBJECT -> return map
+             case OBJECT : final Map<String, Object> map = new HashMap<>();
+                           final JsonObject obj = (JsonObject)value;
+                           for(final Map.Entry<String, JsonValue> entry : obj.entrySet())
{
+                               map.put(entry.getKey(), getValue(entry.getValue()));
+                           }
+                           return map;
         }
         return null;
     }



Mime
View raw message