|
@@ -75,7 +75,6 @@ public class SaveController {
|
|
|
}
|
|
|
|
|
|
private Model model;
|
|
|
- private Gson gson;
|
|
|
private int nCat, nObj, nEle, nEdge, nConn, nNodeEdge, nOldEdge, nUnitGraph, nStatsGraph;
|
|
|
|
|
|
/**
|
|
@@ -86,7 +85,6 @@ public class SaveController {
|
|
|
*/
|
|
|
public SaveController(Model model) {
|
|
|
this.model = model;
|
|
|
- initGson();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -119,7 +117,7 @@ public class SaveController {
|
|
|
storeData(stream);
|
|
|
|
|
|
FileWriter writer = new FileWriter(holonFile);
|
|
|
- writer.write(gson.toJson(file));
|
|
|
+ writer.write(model.getGson().toJson(file));
|
|
|
writer.flush();
|
|
|
writer.close();
|
|
|
|
|
@@ -146,7 +144,7 @@ public class SaveController {
|
|
|
storeCanvas(file);
|
|
|
|
|
|
FileWriter writer = new FileWriter(path);
|
|
|
- writer.write(gson.toJson(file));
|
|
|
+ writer.write(model.getGson().toJson(file));
|
|
|
|
|
|
writer.flush();
|
|
|
writer.close();
|
|
@@ -166,7 +164,7 @@ public class SaveController {
|
|
|
storeCategory(file);
|
|
|
|
|
|
FileWriter writer = new FileWriter(path);
|
|
|
- writer.write(gson.toJson(file));
|
|
|
+ writer.write(model.getGson().toJson(file));
|
|
|
|
|
|
writer.flush();
|
|
|
writer.close();
|
|
@@ -219,7 +217,7 @@ public class SaveController {
|
|
|
file.add(key, new JsonPrimitive(cat.getName()));
|
|
|
// forall object in the category store them into the jsontree
|
|
|
for (AbstractCpsObject obj : cat.getObjects()) {
|
|
|
- file.add("CGOBJECT" + getNumerator(NUMTYPE.OBJECT), gson.toJsonTree(obj, AbstractCpsObject.class));
|
|
|
+ file.add("CGOBJECT" + getNumerator(NUMTYPE.OBJECT), model.getGson().toJsonTree(obj, AbstractCpsObject.class));
|
|
|
// if its a holonobject add elements too
|
|
|
if (obj instanceof HolonObject)
|
|
|
elementsToJson(TYPE.CATEGORY, file, obj);
|
|
@@ -247,7 +245,7 @@ public class SaveController {
|
|
|
u = queue.pop();
|
|
|
// add currentnode into jsontree
|
|
|
String key = "CVSOBJECT" + getNumerator(NUMTYPE.OBJECT);
|
|
|
- file.add(key, gson.toJsonTree(u, AbstractCpsObject.class));
|
|
|
+ file.add(key, model.getGson().toJsonTree(u, AbstractCpsObject.class));
|
|
|
// and its connections too
|
|
|
edgeToJson(EDGETYPE.CONNECTION, file, u.getId(), u.getConnections());
|
|
|
// if holonobject elements too
|
|
@@ -306,7 +304,7 @@ public class SaveController {
|
|
|
String key = null;
|
|
|
// forall elements store them into json and include the id of the object
|
|
|
for (HolonElement ele : ((HolonObject) obj).getElements()) {
|
|
|
- temp.add("properties", gson.toJsonTree(ele));
|
|
|
+ temp.add("properties", model.getGson().toJsonTree(ele));
|
|
|
temp.add("ID", new JsonPrimitive(obj.getId()));
|
|
|
// switch for deciding the key
|
|
|
switch (type) {
|
|
@@ -319,7 +317,7 @@ public class SaveController {
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- file.add(key, gson.toJsonTree(temp));
|
|
|
+ file.add(key, model.getGson().toJsonTree(temp));
|
|
|
// if there are gps add them into
|
|
|
if (ele.getGraphPoints().size() != 0)
|
|
|
unitgraphToJson(GRAPHTYPE.ELEMENT, file, ele.getId(), ele.getGraphPoints());
|
|
@@ -355,7 +353,7 @@ public class SaveController {
|
|
|
// add id of element so it can be found again
|
|
|
temp.add("ID", new JsonPrimitive(id));
|
|
|
|
|
|
- file.add(key, gson.toJsonTree(temp));
|
|
|
+ file.add(key, model.getGson().toJsonTree(temp));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -374,7 +372,7 @@ public class SaveController {
|
|
|
|
|
|
for (CpsEdge edge : arr) {
|
|
|
// add properties and only the ids from a and b
|
|
|
- temp.add("properties", gson.toJsonTree(edge));
|
|
|
+ temp.add("properties", model.getGson().toJsonTree(edge));
|
|
|
temp.add("A", new JsonPrimitive(edge.getA().getId()));
|
|
|
temp.add("B", new JsonPrimitive(edge.getB().getId()));
|
|
|
|
|
@@ -402,7 +400,7 @@ public class SaveController {
|
|
|
&& !type.equals(EDGETYPE.CONNECTION))
|
|
|
b = true;
|
|
|
temp.add("connection", new JsonPrimitive(b));
|
|
|
- file.add(k, gson.toJsonTree(temp));
|
|
|
+ file.add(k, model.getGson().toJsonTree(temp));
|
|
|
temp = new JsonObject();
|
|
|
}
|
|
|
|
|
@@ -417,7 +415,7 @@ public class SaveController {
|
|
|
temp.add("" + i, new JsonPrimitive(model.getTrackingObj().get(i).getId()));
|
|
|
}
|
|
|
|
|
|
- file.add(key, gson.toJsonTree(temp));
|
|
|
+ file.add(key, model.getGson().toJsonTree(temp));
|
|
|
}
|
|
|
|
|
|
private void statisticgraphToJson(JsonObject file) {
|
|
@@ -432,14 +430,14 @@ public class SaveController {
|
|
|
for (int i = 0; i < model.getGraphTable().get(k).getStatGraph().getDataSets().size(); i++) {
|
|
|
TrackedDataSet set = model.getGraphTable().get(k).getStatGraph().getDataSets().get(i);
|
|
|
dataSet.add("ID", new JsonPrimitive(set.getCpsObject().getId()));
|
|
|
- dataSet.add("COLOR", gson.toJsonTree(set.getColor(), Color.class));
|
|
|
+ dataSet.add("COLOR", model.getGson().toJsonTree(set.getColor(), Color.class));
|
|
|
dataSet.add("PROPERTY", new JsonPrimitive(set.getProperty()));
|
|
|
- temp.add("" + i, gson.toJsonTree(dataSet));
|
|
|
+ temp.add("" + i, model.getGson().toJsonTree(dataSet));
|
|
|
dataSet = new JsonObject();
|
|
|
}
|
|
|
temp.add("KEY", new JsonPrimitive(k));
|
|
|
|
|
|
- file.add("STATSGRAPH" + getNumerator(NUMTYPE.STATSGRAPH), gson.toJsonTree(temp));
|
|
|
+ file.add("STATSGRAPH" + getNumerator(NUMTYPE.STATSGRAPH), model.getGson().toJsonTree(temp));
|
|
|
temp = new JsonObject();
|
|
|
}
|
|
|
|
|
@@ -515,20 +513,6 @@ public class SaveController {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Initialize the Gson with wanted parameters
|
|
|
- */
|
|
|
- private void initGson() {
|
|
|
- // TODO Auto-generated method stub
|
|
|
- GsonBuilder builder = new GsonBuilder();
|
|
|
- builder.excludeFieldsWithoutExposeAnnotation().serializeNulls().setPrettyPrinting();
|
|
|
- builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter());
|
|
|
- builder.registerTypeAdapter(Position.class, new PositionAdapter());
|
|
|
- builder.registerTypeAdapter(Color.class, new ColorAdapter());
|
|
|
- // use the builder and make a instance of the Gson
|
|
|
- this.gson = builder.create();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Just initialize the Numerators for the Json Keys. Maybe bad Style..
|
|
|
*/
|