tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1491269 - in /tomee/tomee/trunk/container/openejb-core/src: main/java/org/apache/openejb/config/sys/JSonConfigReader.java test/java/org/apache/openejb/config/JSonConfigTest.java test/resources/openejb.json
Date Sun, 09 Jun 2013 19:30:02 GMT
Author: rmannibucau
Date: Sun Jun  9 19:30:02 2013
New Revision: 1491269

URL: http://svn.apache.org/r1491269
Log:
TOMEE-966 adding system-properties and daemons as root in json config

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JSonConfigReader.java
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
    tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JSonConfigReader.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JSonConfigReader.java?rev=1491269&r1=1491268&r2=1491269&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JSonConfigReader.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JSonConfigReader.java
Sun Jun  9 19:30:02 2013
@@ -17,11 +17,10 @@
 package org.apache.openejb.config.sys;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.SimpleJSonParser;
 import org.xml.sax.helpers.AttributesImpl;
 
-import javax.script.ScriptEngine;
-import javax.script.ScriptEngineManager;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -42,7 +41,7 @@ public class JSonConfigReader {
             config.startDocument();
             config.startElement(null, "openejb", null, new AttributesImpl());
 
-            final Map<?, ?> jsConfig = map(SimpleJSonParser.read(is)); // TODO: see
how to do so in java 6
+            final Map<?, ?> jsConfig = map(SimpleJSonParser.read(is));
 
             for (final String root :
                     Arrays.asList("Resource", "Container", "JndiProvider", "TransactionManager",
"ConnectionManager",
@@ -79,6 +78,20 @@ public class JSonConfigReader {
             }
 
             config.endElement(null, "openejb", null);
+
+            // global config
+            if (jsConfig.containsKey("system-properties")) {
+                final Map<?, ?> sysProps = map(jsConfig.get("system-properties"));
+                setProperties("", sysProps);
+            }
+
+            // same as global but more specific, would be more readable
+            if (jsConfig.containsKey("daemons")) {
+                final Map<String, ?> daemons = map(jsConfig.get("daemons"));
+                for (final Map.Entry<String, ?> entry : daemons.entrySet()) {
+                    setProperties(entry.getKey() + '.', map(entry.getValue()));
+                }
+            }
         } catch (final Exception e) {
             throw new OpenEJBException(e.getMessage(), e);
         }
@@ -86,6 +99,22 @@ public class JSonConfigReader {
         return config.getOpenejb();
     }
 
+    private static void setProperties(final String prefix, final Map<?, ?> sysProps)
{
+        for (final Map.Entry<?, ?> entry : sysProps.entrySet()) {
+            final String key = prefix + entry.getKey().toString();
+            final Object value = entry.getValue();
+            if (String.class.isInstance(value)) {
+                final String str = String.class.cast(value);
+
+                // set it for openejb AND the JVM since that's probably too late to let it
be done automatically
+                SystemInstance.get().setProperty(key, str);
+                System.setProperty(key, str);
+            } else {
+                setProperties(key + '.', map(value));
+            }
+        }
+    }
+
     private static String toString(final Map<String, ?> properties) {
         if (properties == null) {
             return "";

Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java?rev=1491269&r1=1491268&r2=1491269&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/JSonConfigTest.java
Sun Jun  9 19:30:02 2013
@@ -64,6 +64,14 @@ public class JSonConfigTest {
     }
 
     @Test
+    public void checkSystProps() {
+        assertEquals("b", System.getProperty("a"));
+        assertEquals("d", System.getProperty("c"));
+        assertEquals("g", System.getProperty("e.f"));
+        assertEquals("j", System.getProperty("e.h.i"));
+    }
+
+    @Test
     public void simpleRead() throws IOException, OpenEJBException {
         final Openejb openejb = JSonConfigReader.read(Thread.currentThread().getContextClassLoader().getResource(config()).openStream());
 

Modified: tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json?rev=1491269&r1=1491268&r2=1491269&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json (original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/resources/openejb.json Sun Jun  9 19:30:02
2013
@@ -20,5 +20,15 @@
                 "AccessTimeout": "10 seconds"
             }
         }
+    },
+    "system-properties": {
+        "a": "b",
+        "c": "d",
+        "e": {
+            "f": "g",
+            "h": {
+                "i": "j"
+            }
+        }
     }
 }



Mime
View raw message