Author: rmannibucau
Date: Mon Jun 10 06:18:58 2013
New Revision: 1491346
URL: http://svn.apache.org/r1491346
Log:
TOMEE-966 support of comments through __ key in tomee.json
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/sys/JSonConfigReader.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.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=1491346&r1=1491345&r2=1491346&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
Mon Jun 10 06:18:58 2013
@@ -29,6 +29,8 @@ import java.util.Map;
import java.util.Properties;
public class JSonConfigReader {
+ private static final String COMMENT_KEY = "__";
+
private static Map map(final Object rawMap) {
return Map.class.cast(rawMap);
}
@@ -42,6 +44,7 @@ public class JSonConfigReader {
config.startElement(null, "openejb", null, new AttributesImpl());
final Map<?, ?> jsConfig = map(SimpleJSonParser.read(is));
+ jsConfig.remove(COMMENT_KEY);
for (final String root :
Arrays.asList("Resource", "Container", "JndiProvider",
"TransactionManager", "ConnectionManager",
@@ -56,6 +59,8 @@ public class JSonConfigReader {
final Map<String, Map<String, Map<String, String>>> resources
= map(jsConfig.get(currentRoot));
if (resources != null) {
+ resources.remove(COMMENT_KEY);
+
for (final Map.Entry<String, Map<String, Map<String,
String>>> resource : resources.entrySet()) {
final AttributesImpl attributes =
toAttributes(map(resource.getValue()), "properties");
if (!"deployments".equals(currentRoot)) {
@@ -82,6 +87,7 @@ public class JSonConfigReader {
// global config
if (jsConfig.containsKey("system-properties")) {
final Map<?, ?> sysProps =
map(jsConfig.get("system-properties"));
+
setProperties("", sysProps);
}
@@ -100,6 +106,8 @@ public class JSonConfigReader {
}
private static void setProperties(final String prefix, final Map<?, ?>
sysProps) {
+ sysProps.remove(COMMENT_KEY);
+
for (final Map.Entry<?, ?> entry : sysProps.entrySet()) {
final String key = prefix + entry.getKey().toString();
final Object value = entry.getValue();
@@ -119,6 +127,9 @@ public class JSonConfigReader {
if (properties == null) {
return "";
}
+
+ properties.remove(COMMENT_KEY);
+
final Properties builder = new Properties();
for (final Map.Entry<String, ?> entry : properties.entrySet()) {
builder.put(entry.getKey(), entry.getValue().toString());
@@ -133,6 +144,8 @@ public class JSonConfigReader {
}
private static AttributesImpl toAttributes(final Map<String, String> map,
final String... ignored) {
+ map.remove(COMMENT_KEY);
+
final AttributesImpl attributes = new AttributesImpl();
for (final Map.Entry<String, String> entry : map.entrySet()) {
final String key = entry.getKey();
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java?rev=1491346&r1=1491345&r2=1491346&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/SimpleJSonParser.java
Mon Jun 10 06:18:58 2013
@@ -18,6 +18,8 @@ package org.apache.openejb.util;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -25,6 +27,7 @@ import java.util.Map;
public class SimpleJSonParser {
public static Object read(final InputStream is) throws IOException {
Map<String, Object> json = null;
+ Collection<Object> array = null;
int read;
char current;
@@ -35,6 +38,10 @@ public class SimpleJSonParser {
json = new HashMap<String, Object>();
} else if (current == '}') {
return json;
+ } else if (current == '[') {
+ array = new ArrayList<Object>();
+ } else if (current == ']') {
+ return array;
} else if (current == '"') {
final StringBuilder b = new StringBuilder();
do {
@@ -49,7 +56,7 @@ public class SimpleJSonParser {
}
final String value = b.substring(0, b.length() - 1); // remove
last "
- if (valueRead(is, json, value)) {
+ if (valueRead(is, json, array, value)) {
return value;
}
} else if (current != ':' && current != ',' &&
!isWhiteSpace(current)) {
@@ -62,7 +69,7 @@ public class SimpleJSonParser {
} while (current != -1 && !isWhiteSpace(current) && current !=
',');
final String value = b.substring(0, b.length() - 1); // remove
last character
- if (valueRead(is, json, value)) {
+ if (valueRead(is, json, array, value)) {
return value;
}
}
@@ -72,7 +79,7 @@ public class SimpleJSonParser {
throw new IllegalArgumentException("Please check input, a } is
probably missing");
}
- private static boolean valueRead(final InputStream is, final Map<String,
Object> json, final String value) throws IOException {
+ private static boolean valueRead(final InputStream is, final Map<String,
Object> json, final Collection<Object> array, final String value) throws
IOException {
int read;
do {
read = is.read();
@@ -80,6 +87,8 @@ public class SimpleJSonParser {
if (json != null) {
json.put(value, read(is));
+ } else if (array != null) {
+ array.add(value);
} else {
return true;
}
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=1491346&r1=1491345&r2=1491346&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
Mon Jun 10 06:18:58 2013
@@ -1,6 +1,18 @@
{
+ "__": [
+ "comments are supported through __ key",
+ "so don't hesitate to explain what you are configuring"
+ ],
"resources": {
+ "__": [
+ "here is",
+ "the resources configuration"
+ ],
"json-datasource": {
+ "__": [
+ "properties is the magic attribute",
+ "to configure the resource"
+ ],
"properties": {
"JdbcUrl": "jdbc:hsqldb:mem:json",
"MaxActive": 123,