+
+ public void mergeConfig(Config newValues, boolean merge) {
+
+ for (Map.Entry<String, Object> entry : newValues.getData().entrySet()) {
+
+ String key = entry.getKey();
+ Object nvalue = entry.getValue();
+
+ if (!merge || key.equals("appbase")) {
+ _data.put(key, nvalue);
+ } else {
+
+ // merge
+
+ Object value = _data.get(key);
+
+ if (value == null) {
+ _data.put(key, nvalue);
+ } else if (value instanceof String) {
+ if (nvalue instanceof String) {
+
+ // value is String, nvalue is String
+ _data.put(key, new String[] { (String)value, (String)nvalue });
+
+ } else if (nvalue instanceof String[]) {
+
+ // value is String, nvalue is String[]
+ String[] nvalues = (String[])nvalue;
+ String[] newvalues = new String[nvalues.length+1];
+ newvalues[0] = (String)value;
+ System.arraycopy(nvalues, 0, newvalues, 1, nvalues.length);
+ _data.put(key, newvalues);
+
+ }
+ } else if (value instanceof String[]) {
+ if (nvalue instanceof String) {
+
+ // value is String[], nvalue is String
+ String[] values = (String[])value;
+ String[] newvalues = new String[values.length+1];
+ System.arraycopy(values, 0, newvalues, 0, values.length);
+ newvalues[values.length] = (String)nvalue;
+ _data.put(key, newvalues);
+
+ } else if (nvalue instanceof String[]) {
+
+ // value is String[], nvalue is String[]
+ String[] values = (String[])value;
+ String[] nvalues = (String[])nvalue;
+ String[] newvalues = new String[values.length + nvalues.length];
+ System.arraycopy(values, 0, newvalues, 0, values.length);
+ System.arraycopy(nvalues, 0, newvalues, values.length, newvalues.length);
+ _data.put(key, newvalues);
+
+ }
+ }
+
+ }
+
+ }
+
+ }
+
+ public Map<String, Object> getData() {
+ return _data;
+ }