diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java index 98f752e..c101792 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java @@ -86,27 +86,32 @@ ListTerm listValue = (ListTerm) resStateValue; Resource res = getResource(resourceIdentifier); ResourceState state = res.getState(); - ResourceIdentifier createdResource = null; - for (int i = 0; i < listValue.size(); i++) { - Expression childExp = new Constant(Integer.toString(i), DataConstraintModel.typeInt); - ResourceHierarchy childResourceHierarchy = null; - if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { - childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); - } else { - Type childResType = null; - if (listValue.get(i) instanceof Variable) { - childResType = ((Variable) listValue.get(i)).getType(); - } else if (listValue.get(i) instanceof Term) { - childResType = ((Term) listValue.get(i)).getType(); + if (state instanceof ListResourceState) { + ResourceIdentifier createdResource = null; + ((ListResourceState) state).clearChildStates(); + for (int i = 0; i < listValue.size(); i++) { + Expression childExp = new Constant(Integer.toString(i), DataConstraintModel.typeInt); + ResourceHierarchy childResourceHierarchy = null; + if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { + childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); + } else { + Type childResType = null; + if (listValue.get(i) instanceof Variable) { + childResType = ((Variable) listValue.get(i)).getType(); + } else if (listValue.get(i) instanceof Term) { + childResType = ((Term) listValue.get(i)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); + Map.Entry childInfo = createResourceState(childResourceIdentifier, listValue.get(i)); + ((ListResourceState) state).addChildState(childInfo.getKey()); + createdResource = childInfo.getValue(); } - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); - Map.Entry childInfo = createResourceState(childResourceIdentifier, listValue.get(i)); - ((ListResourceState) state).addChildState(childInfo.getKey()); - createdResource = childInfo.getValue(); + return createdResource; + } else { + return resourceIdentifier; } - return createdResource; } else if (resStateValue instanceof Term) { Term listValue = (Term) resStateValue; if (listValue.getSymbol().equals(DataConstraintModel.append)) { @@ -150,27 +155,32 @@ JsonTerm mapValue = (JsonTerm) resStateValue; Resource res = getResource(resourceIdentifier); ResourceState state = res.getState(); - ResourceIdentifier createdResource = null; - for (String key: mapValue.keySet()) { - Expression childExp = new Constant(key, DataConstraintModel.typeString); - ResourceHierarchy childResourceHierarchy = null; - if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { - childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); - } else { - Type childResType = null; - if (mapValue.get(key) instanceof Variable) { - childResType = ((Variable) mapValue.get(key)).getType(); - } else if (mapValue.get(key) instanceof Term) { - childResType = ((Term) mapValue.get(key)).getType(); + if (state instanceof MapResourceState) { + ResourceIdentifier createdResource = null; + ((MapResourceState) state).clearChildStates(); + for (String key: mapValue.keySet()) { + Expression childExp = new Constant(key, DataConstraintModel.typeString); + ResourceHierarchy childResourceHierarchy = null; + if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { + childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); + } else { + Type childResType = null; + if (mapValue.get(key) instanceof Variable) { + childResType = ((Variable) mapValue.get(key)).getType(); + } else if (mapValue.get(key) instanceof Term) { + childResType = ((Term) mapValue.get(key)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); + Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.get(key)); + ((MapResourceState) state).addChildState(key, childInfo.getKey()); + createdResource = childInfo.getValue(); } - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); - Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.get(key)); - ((MapResourceState) state).addChildState(key, childInfo.getKey()); - createdResource = childInfo.getValue(); + return createdResource; + } else { + return resourceIdentifier; } - return createdResource; } else if (resStateValue instanceof MapTerm) { MapTerm mapValue = (MapTerm) resStateValue; Resource res = getResource(resourceIdentifier); @@ -239,35 +249,39 @@ JsonTerm jsonValue = (JsonTerm) resStateValue; Resource res = getResource(resourceIdentifier); ResourceState state = res.getState(); - ResourceIdentifier createdResource = null; - for (String key: jsonValue.keySet()) { - String memberName = key.replace("\"", ""); - ResourceHierarchy childResourceHierarchy = null; - for (ResourceHierarchy childRes: resourceIdentifier.getResourceHierarchy().getChildren()) { - if (childRes.getResourceName().equals(memberName)) { - childResourceHierarchy = childRes; - break; + if (state instanceof JsonResourceState) { + ResourceIdentifier createdResource = null; + for (String key: jsonValue.keySet()) { + String memberName = key.replace("\"", ""); + ResourceHierarchy childResourceHierarchy = null; + for (ResourceHierarchy childRes: resourceIdentifier.getResourceHierarchy().getChildren()) { + if (childRes.getResourceName().equals(memberName)) { + childResourceHierarchy = childRes; + break; + } } - } - if (childResourceHierarchy == null) { - Type childResType = null; - if (jsonValue.get(key) instanceof Variable) { - childResType = ((Variable) jsonValue.get(key)).getType(); - } else if (jsonValue.get(key) instanceof Term) { - childResType = ((Term) jsonValue.get(key)).getType(); + if (childResourceHierarchy == null) { + Type childResType = null; + if (jsonValue.get(key) instanceof Variable) { + childResType = ((Variable) jsonValue.get(key)).getType(); + } else if (jsonValue.get(key) instanceof Term) { + childResType = ((Term) jsonValue.get(key)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName, childResType); } - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName, childResType); + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); + Map.Entry childInfo = createResourceState(childResourceIdentifier, jsonValue.get(key)); + ResourceState childState = childInfo.getKey(); + if (res.getChildrenMap() != null && res.getChildrenMap().get(memberName) != null) { + res.getChildrenMap().get(memberName).changeState(childState); + } + ((JsonResourceState) state).addChildState(memberName, childState); + createdResource = childInfo.getValue(); } - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); - Map.Entry childInfo = createResourceState(childResourceIdentifier, jsonValue.get(key)); - ResourceState childState = childInfo.getKey(); - if (res.getChildrenMap() != null && res.getChildrenMap().get(memberName) != null) { - res.getChildrenMap().get(memberName).changeState(childState); - } - ((JsonResourceState) state).addChildState(memberName, childState); - createdResource = childInfo.getValue(); + return createdResource; + } else { + return resourceIdentifier; } - return createdResource; } else if (resStateValue instanceof Term) { Term jsonValue = (Term) resStateValue; Resource res = getResource(resourceIdentifier);