1 package com.exsoinn.util.epf;
2
3 import com.google.gson.JsonArray;
4 import com.google.gson.JsonElement;
5 import com.google.gson.JsonObject;
6
7
8
9
10 public class MutableJsonContext extends JsonContext implements MutableContext {
11 MutableJsonContext(JsonElement pJsonElement) {
12 super(pJsonElement);
13 }
14
15 @Override
16 public void addMember(String pName, Context pContext) {
17 if (!isRecursible()) {
18 throw new IllegalStateException("This operation not supported for elements that are not complex.");
19 }
20
21
22
23 JsonElement srcJson = ((JsonContext) pContext).unwrap();
24 JsonObject targetJson = (JsonObject) unwrap();
25 targetJson.add(pName, srcJson);
26 }
27
28 @Override
29 public void addEntryToArray(Context pEntry) {
30 if (!isArray()) {
31 throw new IllegalStateException("This operation not supported for elements that are not array.");
32 }
33
34 JsonElement srcJson = ((JsonContext) pEntry).unwrap();
35 JsonArray targetJson = (JsonArray) unwrap();
36 targetJson.add(srcJson);
37 }
38 }