1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- include "modelling.alh"
- include "primitives.alh"
- include "object_operations.alh"
- include "model_management.alh"
- String function JSON_print(model : Element):
- String result
- Element keys_m
- String v_m
- String type
- String attr_key
- Element attr_keys
- Boolean first
- Element attr_value
- result = "["
- keys_m = dict_keys(model["model"])
- first = True
- while (read_nr_out(keys_m) > 0):
- v_m = set_pop(keys_m)
- type = read_type(model["metamodel"], read_type(model, v_m))
- if (bool_or(type == "Class", type == "Association")):
- if (bool_not(first)):
- result = result + ","
- else:
- first = False
- result = result + "{"
- result = (((result + "\"id\": \"") + v_m) + "\"")
- result = (((result + ",") + "\"type\": \"") + read_type(model, v_m)) + "\""
- if (type == "Association"):
- result = (((result + ", \"__source\": \"") + reverseKeyLookup(model["model"], read_edge_src(model["model"][v_m]))) + "\"")
- result = (((result + ", \"__target\": \"") + reverseKeyLookup(model["model"], read_edge_dst(model["model"][v_m]))) + "\"")
- // Has attributes
- attr_keys = dict_keys(getAttributeList(model, v_m))
- while (0 < read_nr_out(attr_keys)):
- attr_key = set_pop(attr_keys)
- attr_value = read_attribute(model, v_m, attr_key)
- if (element_eq(attr_value, read_root())):
- result = (((result + ", \"") + attr_key) + "\": null")
- else:
- if (is_physical_boolean(attr_value)):
- if (attr_value):
- result = ((result + ", \"") + attr_key) + "\": true"
- else:
- result = ((result + ", \"") + attr_key) + "\": false"
- else:
- result = ((((result + ", \"") + attr_key) + "\": ") + cast_v2s(attr_value))
- result = result + "}"
- result = result + "]"
- return result!
|