diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 5db9ecd..fe86c0c 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -349,7 +349,7 @@ } composer = new Term(DataConstraintModel.insert); composer.addChild(composerSub); - composer.addChild(new Constant(langSpec.getStringDelimiter() + fieldName + langSpec.getStringDelimiter(), DataConstraintModel.typeString)); // key + composer.addChild(new Constant(fieldName, DataConstraintModel.typeString)); // key composer.addChild(childGetter); // value composer.setType(DataConstraintModel.typeMap); composerSub = composer; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index 4ab9dd3..8c2337a 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -607,8 +607,8 @@ } composer = new Term(DataConstraintModel.insert); composer.addChild(composerSub); - composer.addChild(new Constant("\"" + fieldName + "\"", DataConstraintModel.typeString)); // key - composer.addChild(childGetter); // value + composer.addChild(new Constant(fieldName, DataConstraintModel.typeString)); // key + composer.addChild(childGetter); // value composer.setType(DataConstraintModel.typeMap); composerSub = composer; } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index d695463..b50a570 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -730,8 +730,8 @@ } composer = new Term(DataConstraintModel.insert); composer.addChild(composerSub); - composer.addChild(new Constant("\"" + fieldName + "\"", DataConstraintModel.typeString)); // key - composer.addChild(childGetter); // value + composer.addChild(new Constant(fieldName, DataConstraintModel.typeString)); // key + composer.addChild(childGetter); // value composer.setType(DataConstraintModel.typeMap); composerSub = composer; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Constant.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Constant.java index 5f533a7..50207b6 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Constant.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Constant.java @@ -9,7 +9,7 @@ } public Constant(String value, Type type) { - super(new Symbol(value, 0), new ArrayList()); + super(new Symbol((type == null ? value: type.valueToRepresentation(value)), 0), new ArrayList()); symbol.setSignature(new Type[] {type}); } @@ -34,6 +34,13 @@ return symbol.getName(); } + public Object getValue() { + if (getType() != null) { + return getType().representationToValue(symbol.getName()); + } + return symbol.getName(); + } + public String toImplementation(String[] sideEffects) { if (symbol.isImplGenerative()) { String exp = symbol.generate(getType(), new Type[] {}, new String[] {}, new String[] {}, sideEffects); diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java index 3b573d2..9e3eecb 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java @@ -80,6 +80,15 @@ return false; } + public String valueToRepresentation(Object value) { + if (value instanceof String) return (String) value; + return value.toString(); + } + + public Object representationToValue(String representation) { + return representation; + } + @Override public boolean equals(Object another) { if (this == another) return true; diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java index 9cf0280..370c3f7 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java @@ -41,11 +41,11 @@ @Override public String toString() { if (stateTransition.getNextStateExpression() == null) { - return resourcePath.getLeafResourceName() + "(" + return resourcePath.toString() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")"; } - return resourcePath.getLeafResourceName() + "(" + return resourcePath.toString() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")" + " = " + stateTransition.getNextStateExpression(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 4482a27..1507ea3 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -26,7 +26,20 @@ public static final Type typeFloat = new Type("Float", "float", typeInt); public static final Type typeDouble = new Type("Double", "double", typeFloat); public static final Type typeBoolean = new Type("Bool", "boolean"); - public static final Type typeString = new Type("Str", "String"); + public static final Type typeString = new Type("Str", "String") { + public String valueToRepresentation(Object value) { + if (value instanceof String) { + return Parser.DOUBLE_QUOT + (String) value + Parser.DOUBLE_QUOT; + } + return value.toString(); + } + public Object representationToValue(String representation) { + if (representation.startsWith(Parser.DOUBLE_QUOT) && representation.endsWith(Parser.DOUBLE_QUOT)) { + return representation.substring(1, representation.length() - 1); + } + return representation; + } + }; public static final Type typeList = new Type("List", "ArrayList", "List"); public static final Type typeListInt = new Type("List", "ArrayList<>", "List", typeList); public static final Type typeListStr = new Type("List", "ArrayList<>", "List", typeList); @@ -510,7 +523,13 @@ term = (Term) term.getChild(0); } if (term instanceof MapTerm) { - if (((MapTerm) term).keySet().contains(args.get(1).toString())) { + String key; + if (args.get(1) instanceof Constant) { + key = (String) ((Constant) args.get(1)).getValue(); + } else { + key = args.get(1).toString(); + } + if (((MapTerm) term).keySet().contains(key)) { return new Constant(true_); } return new Constant(false_); @@ -526,7 +545,13 @@ term = (Term) term.getChild(0); } if (term instanceof JsonTerm) { - if (((JsonTerm) term).keySet().contains(args.get(1).toString())) { + String key; + if (args.get(1) instanceof Constant) { + key = (String) ((Constant) args.get(1)).getValue(); + } else { + key = args.get(1).toString(); + } + if (((JsonTerm) term).keySet().contains(key)) { return new Constant(true_); } return new Constant(false_); @@ -986,7 +1011,7 @@ for (ResourceHierarchy resource: resourceHierarchies.values()) { String initializer = resource.getInitText(); if (initializer != null) { - init += initializer; + init += resource.toString() + " := " + initializer + "\n"; } } if (init.length() > 0) { diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonAccessor.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonAccessor.java index 85994f2..e7cadb5 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonAccessor.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonAccessor.java @@ -81,7 +81,7 @@ } String keyName = null; if (expKey instanceof Constant) { - keyName = ((Constant) expKey).getSymbol().getName(); + keyName = (String) ((Constant) expKey).getValue(); Term jsonTerm = new Constant(DataConstraintModel.nil); jsonTerm.setType(DataConstraintModel.typeJson); int v = 1; @@ -95,7 +95,7 @@ for (String key: keySet) { Term addMemberTerm = new Term(DataConstraintModel.addMember); // addMember(jsonTerm, key, v) addMemberTerm.addChild(jsonTerm); - addMemberTerm.addChild(new Constant(key)); + addMemberTerm.addChild(new Constant(key, DataConstraintModel.typeString)); Variable var = new Variable("v" + v); addMemberTerm.addChild(var); vars.put(key, var); @@ -156,14 +156,17 @@ public String toString() { if (symbol.equals(DataConstraintModel.dotParam)) { - return children.get(0).toString() + symbol.toString() + "{" + children.get(1).toString() + "}"; + if (children.get(1) instanceof Constant) { + return children.get(0).toString() + symbol.toString() + (String) ((Constant) children.get(1)).getValue(); + } + return children.get(0).toString() + symbol.toString() + children.get(1).toString(); } return super.toString(); } public String toImplementation(String[] sideEffects) { if (symbol.equals(DataConstraintModel.dotParam)) { - return children.get(0).toImplementation(sideEffects) + symbol.toImplementation() + "{" + children.get(1).toImplementation(sideEffects) + "}"; + return children.get(0).toImplementation(sideEffects) + "." + symbol.toImplementation() + "(" + children.get(1).toImplementation(sideEffects) + ")"; } return super.toImplementation(sideEffects); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonTerm.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonTerm.java index dd213a8..5762940 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonTerm.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/JsonTerm.java @@ -8,6 +8,7 @@ import models.algebra.Expression; import models.algebra.Symbol; import models.algebra.Term; +import parser.Parser; public class JsonTerm extends Term { private Map keyToIndex = new HashMap<>(); @@ -36,8 +37,8 @@ } public Expression get(Constant key) { - if (keyToIndex.get(key.toString()) == null) return null; - return getChild(keyToIndex.get(key.toString())); + if (keyToIndex.get(key.getValue()) == null) return null; + return getChild(keyToIndex.get(key.getValue())); } @Override @@ -54,7 +55,7 @@ String jsonStr = "{"; String delim = ""; for (String key: keyToIndex.keySet()) { - jsonStr += delim + key + ": " + getChild(keyToIndex.get(key)).toString(); + jsonStr += delim + Parser.DOUBLE_QUOT + key + Parser.DOUBLE_QUOT + ": " + getChild(keyToIndex.get(key)).toString(); delim = ", "; } return jsonStr + "}"; diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/MapTerm.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/MapTerm.java index 3646146..0badbd1 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/MapTerm.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/MapTerm.java @@ -8,6 +8,7 @@ import models.algebra.Expression; import models.algebra.Symbol; import models.algebra.Term; +import parser.Parser; public class MapTerm extends Term { private Map keyToIndex = new HashMap<>(); @@ -35,7 +36,8 @@ } public Expression get(Constant key) { - return getChild(keyToIndex.get(key.toString())); + if (keyToIndex.get(key.getValue()) == null) return null; + return getChild(keyToIndex.get(key.getValue())); } @Override @@ -52,7 +54,7 @@ String mapStr = "{"; String delim = ""; for (String key: keyToIndex.keySet()) { - mapStr += delim + key + ": " + getChild(keyToIndex.get(key)).toString(); + mapStr += delim + Parser.DOUBLE_QUOT + key + Parser.DOUBLE_QUOT + ": " + getChild(keyToIndex.get(key)).toString(); delim = ", "; } return mapStr + "}"; diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java index e93c937..46bf393 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java @@ -21,6 +21,7 @@ import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.ResourcePath; +import models.dataConstraintModel.Selector; public class DataTransferChannel extends Channel { protected Set inputChannelMembers = null; @@ -612,7 +613,21 @@ @Override public String toString() { - String channelSource = "channel " + getChannelName() + " {\n"; + String channelSource = ""; + if (isNative()) { + channelSource += "native "; + } + channelSource += "channel " + getChannelName(); + if (getSelectors().size() > 0) { + channelSource += "("; + String delimitor = ""; + for (Selector selector: getSelectors()) { + channelSource += delimitor + selector.getExpression().toString(); + delimitor = ", "; + } + channelSource += ")"; + } + channelSource += " {\n"; for (ChannelMember inputMember: inputChannelMembers) { channelSource += "\t in " + inputMember + "\n"; } diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index 2350843..60f5a55 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -13,7 +13,6 @@ import models.algebra.Type; import models.algebra.Variable; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.DataConstraintModel; import models.dataConstraintModel.JsonAccessor; import models.dataConstraintModel.JsonTerm; import models.dataConstraintModel.ResourceHierarchy; @@ -374,7 +373,7 @@ } } else if (symbolName.startsWith(DOUBLE_QUOT) && symbolName.endsWith(DOUBLE_QUOT)) { // a string value - exp = new Constant(symbolName, DataTransferModel.typeString); + exp = new Constant(symbolName.substring(1, symbolName.length() - 1), DataTransferModel.typeString); } else { // a variable exp = parseVariable(stream, model, symbolName); @@ -455,10 +454,10 @@ paramType = ((Term) paramTerm).getType(); } Term term = null; - if (paramType != null && DataConstraintModel.typeInt.isAncestorOf(paramType)) { - term = new JsonAccessor(DataConstraintModel.dotParam); + if (paramType != null && DataTransferModel.typeInt.isAncestorOf(paramType)) { + term = new JsonAccessor(DataTransferModel.dotParam); } else { - term = new JsonAccessor(DataConstraintModel.dot); + term = new JsonAccessor(DataTransferModel.dot); } term.addChild(exp); term.addChild(paramTerm); @@ -616,7 +615,7 @@ if (stream.checkNext() == null || !stream.checkNext().equals(COLON)) throw new ExpectedColon(stream.getLine()); String colon = stream.next(); Expression value = parseTerm(stream, model); - jsonTerm.addMember(DOUBLE_QUOT + key + DOUBLE_QUOT, value); + jsonTerm.addMember(key, value); if (stream.checkNext() == null || !stream.checkNext().equals(COMMA)) break; String comma = stream.next(); } @@ -624,11 +623,11 @@ } private Expression parseListTerm(TokenStream stream2, DataTransferModel model) throws ExpectedRightBracket, WrongJsonExpression, ExpectedColon, ExpectedDoubleQuotation { - Term listTerm = new Constant(DataConstraintModel.nil); - listTerm.setType(DataConstraintModel.typeList); + Term listTerm = new Constant(DataTransferModel.nil); + listTerm.setType(DataTransferModel.typeList); while (stream.checkNext() != null && !stream.checkNext().equals(RIGHT_SQUARE_BRACKET)) { Expression element = parseTerm(stream, model); - Term nextTerm = new Term(DataConstraintModel.cons); + Term nextTerm = new Term(DataTransferModel.cons); nextTerm.addChild(element); nextTerm.addChild(listTerm); listTerm = nextTerm; diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/ResourceIdentifier.java b/AlgebraicDataflowArchitectureModel/src/simulator/ResourceIdentifier.java index 9de3594..8987ee0 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/ResourceIdentifier.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/ResourceIdentifier.java @@ -75,7 +75,11 @@ if (!this.endsWithParam()) { resId += getLeafResourceName(); } else { - resId += getLastParam().toString().replace("\"", ""); + if (getLastParam() instanceof Constant) { + resId += (String) ((Constant) getLastParam()).getValue(); + } else { + resId += getLastParam().toString(); + } } return resId; } diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java index 869aaec..154a8a5 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java @@ -356,7 +356,13 @@ Expression constraint = resPath.getPathParamsAndConstraints().get(i).getValue(); if (constraint != null) { String valStr = val.toString(); - String constStr = constraint.toString().replace("\"", ""); + if (val instanceof Constant) { + valStr = (String) ((Constant) val).getValue(); + } + String constStr = constraint.toString(); + if (constraint instanceof Constant) { + constStr = (String) ((Constant) constraint).getValue(); + } if (!constStr.equals(valStr)) { // The value of the path parameter does not satisfy the constraint defined for the parameter. return false; // Not to fire this event. diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java index a1a0806..8ebe150 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java @@ -309,7 +309,7 @@ childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childKeyExp, childResourceHierarchy); - String childId = ((Constant) childKeyExp).toString(); + String childId = (String) ((Constant) childKeyExp).getValue(); Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, mapValue.getChild(2)); ((MapResourceState) state).addChildState(childId, childInfo.getKey()); createdResources.addAll(childInfo.getValue()); @@ -326,10 +326,9 @@ if (state instanceof JsonResourceState) { List createdResources = new ArrayList<>(); for (String key: jsonValue.keySet()) { - String memberName = key.replace("\"", ""); ResourceHierarchy childResourceHierarchy = null; for (ResourceHierarchy childRes: resourceIdentifier.getResourceHierarchy().getChildren()) { - if (childRes.getResourceName().equals(memberName)) { + if (childRes.getResourceName().equals(key)) { childResourceHierarchy = childRes; break; } @@ -341,15 +340,15 @@ } 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(), key, childResType); } - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, key, childResourceHierarchy); Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, jsonValue.get(key)); ResourceState childState = childInfo.getKey(); - if (res.getChildrenMap() != null && res.getChildrenMap().get(memberName) != null) { - res.getChildrenMap().get(memberName).changeState(childState); + if (res.getChildrenMap() != null && res.getChildrenMap().get(key) != null) { + res.getChildrenMap().get(key).changeState(childState); } - ((JsonResourceState) state).addChildState(memberName, childState); + ((JsonResourceState) state).addChildState(key, childState); createdResources.addAll(childInfo.getValue()); } return createdResources; @@ -363,7 +362,7 @@ while (jsonValue.getSymbol().equals(DataConstraintModel.addMember)) { Expression childKeyExp = jsonValue.getChild(1); if (childKeyExp instanceof Constant) { - String memberName = ((Constant) childKeyExp).getSymbol().getName().replace("\"", ""); + String memberName = (String) ((Constant) childKeyExp).getValue(); ResourceHierarchy childResourceHierarchy = null; for (ResourceHierarchy childRes: resourceIdentifier.getResourceHierarchy().getChildren()) { if (childRes.getResourceName().equals(memberName)) { @@ -381,9 +380,8 @@ childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); - String childId = ((Constant) childKeyExp).toString(); Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, jsonValue.getChild(2)); - ((JsonResourceState) state).addChildState(childId, childInfo.getKey()); + ((JsonResourceState) state).addChildState(memberName, childInfo.getKey()); createdResources.addAll(childInfo.getValue()); } if (!(jsonValue.getChild(0) instanceof Term)) break; @@ -410,10 +408,10 @@ if (parentResType != null && DataConstraintModel.typeList.isAncestorOf(parentResType)) { } else if (parentResType != null && DataConstraintModel.typeMap.isAncestorOf(parentResType)) { JsonResourceState parentState = (JsonResourceState) getResource(parentResId).getState(); - parentState.addChildState(((Constant) resourceIdentifier.getLastParam()).toString(), new PrimitiveResourceState((Constant) resNextStateVal)); + parentState.addChildState((String) ((Constant) resourceIdentifier.getLastParam()).getValue(), new PrimitiveResourceState((Constant) resNextStateVal)); } else if (parentResType != null && DataConstraintModel.typeJson.isAncestorOf(parentResType)) { JsonResourceState parentState = (JsonResourceState) getResource(parentResId).getState(); - parentState.addChildState("\"" + resourceIdentifier.getLeafResourceName() + "\"", new PrimitiveResourceState((Constant) resNextStateVal)); + parentState.addChildState(resourceIdentifier.getLeafResourceName(), new PrimitiveResourceState((Constant) resNextStateVal)); } } List updatedResources = new ArrayList<>(); @@ -595,7 +593,7 @@ childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); - String childId = ((Constant) childExp).toString(); + String childId = (String) ((Constant) childExp).getValue(); Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, mapValue.getChild(2)); state.addChildState(childId, childInfo.getKey()); createdResources.addAll(childInfo.getValue()); @@ -610,10 +608,9 @@ JsonResourceState state = new JsonResourceState(); Map.Entry> createInfo = new AbstractMap.SimpleEntry<>(null, new ArrayList<>()); for (String key: jsonValue.keySet()) { - String memberName = key.replace("\"", ""); ResourceHierarchy childResourceHierarchy = null; for (ResourceHierarchy childRes: resourceIdentifier.getResourceHierarchy().getChildren()) { - if (childRes.getResourceName().equals(memberName)) { + if (childRes.getResourceName().equals(key)) { childResourceHierarchy = childRes; break; } @@ -625,16 +622,16 @@ } 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(), key, childResType); } - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, key, childResourceHierarchy); Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, jsonValue.get(key)); ResourceState childState = childInfo.getKey(); Resource res = getResource(resourceIdentifier); - if (res != null && res.getChildrenMap() != null && res.getChildrenMap().get(memberName) != null) { - res.getChildrenMap().get(memberName).changeState(childState); + if (res != null && res.getChildrenMap() != null && res.getChildrenMap().get(key) != null) { + res.getChildrenMap().get(key).changeState(childState); } - state.addChildState(memberName, childState); + state.addChildState(key, childState); createInfo.getValue().addAll(childInfo.getValue()); createInfo = new AbstractMap.SimpleEntry<>(state, createInfo.getValue()); } @@ -646,7 +643,7 @@ while (jsonValue.getSymbol().equals(DataConstraintModel.addMember)) { Expression childExp = jsonValue.getChild(1); if (childExp instanceof Constant) { - String memberName = ((Constant) childExp).getSymbol().getName().replace("\"", ""); + String memberName = (String) ((Constant) childExp).getValue(); ResourceHierarchy childResourceHierarchy = null; for (ResourceHierarchy childRes: resourceIdentifier.getResourceHierarchy().getChildren()) { if (childRes.getResourceName().equals(memberName)) { @@ -664,9 +661,8 @@ childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); - String childId = ((Constant) childExp).toString(); Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, jsonValue.getChild(2)); - state.addChildState(childId, childInfo.getKey()); + state.addChildState(memberName, childInfo.getKey()); createInfo.getValue().addAll(childInfo.getValue()); createInfo = new AbstractMap.SimpleEntry<>(state, createInfo.getValue()); } diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/ComponentTextReceiver.java b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/ComponentTextReceiver.java index 69badc8..5ab8b63 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/ComponentTextReceiver.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/ComponentTextReceiver.java @@ -27,11 +27,11 @@ Expression text = ((Term) message).getChild(0); if (text instanceof Constant) { if (component instanceof JTextComponent) { - ((JTextComponent) component).setText(((Constant) text).getSymbol().getName()); + ((JTextComponent) component).setText((String) ((Constant) text).getValue()); } else if (component instanceof JLabel) { - ((JLabel) component).setText(((Constant) text).getSymbol().getName()); + ((JLabel) component).setText((String) ((Constant) text).getValue()); } else if (component instanceof JButton) { - ((JButton) component).setText(((Constant) text).getSymbol().getName()); + ((JButton) component).setText((String) ((Constant) text).getValue()); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/SwingPresenter.java b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/SwingPresenter.java index 11ac366..ba514e9 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/SwingPresenter.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/interfaces/swing/SwingPresenter.java @@ -126,14 +126,14 @@ JsonTerm widget = (JsonTerm) value; Resource widgetResource = widgetsResource.getChildrenMap().get(newWid); Expression type = widget.get("type"); - if (type.toString().equals("\"button\"")) { + if (type instanceof Constant && ((String)((Constant) type).getValue()).equals("button")) { // Add a button component. Expression text = widget.get("text"); Expression x = widget.get("x"); Expression y = widget.get("y"); Expression width = widget.get("width"); Expression height = widget.get("height"); - JButton button = new JButton(text.toString().replace("\"", "")); + JButton button = new JButton(((String)((Constant) text).getValue())); if (x != null && y != null) { button.setLocation(Integer.parseInt(x.toString()), Integer.parseInt(y.toString())); } @@ -211,14 +211,14 @@ } resources.put(newWid, widgetHeightResource); } - } else if (type.toString().equals("\"label\"")) { + } else if (type instanceof Constant && ((String)((Constant) type).getValue()).equals("label")) { // Add a label component. Expression text = widget.get("text"); Expression x = widget.get("x"); Expression y = widget.get("y"); Expression width = widget.get("width"); Expression height = widget.get("height"); - JLabel label = new JLabel(text.toString().replace("\"", "")); + JLabel label = new JLabel(((String) ((Constant) text).getValue())); if (x != null && y != null) { label.setLocation(Integer.parseInt(x.toString()), Integer.parseInt(y.toString())); } @@ -294,7 +294,7 @@ } resources.put(newWid, widgetHeightResource); } - } else if (type.toString().equals("\"textInput\"")) { + } else if (type instanceof Constant && ((String)((Constant) type).getValue()).equals("textInput")) { // Add a text input component. Expression x = widget.get("x"); Expression y = widget.get("y"); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/SimulatorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/SimulatorTest.java index 6221b58..a6c2817 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/SimulatorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/SimulatorTest.java @@ -54,7 +54,7 @@ new Variable("cid2", DataConstraintModel.typeString)); // "companies.{cid2}" ResourcePath company2_add = new ResourcePath(company2, "add"); // "companies.{cid2}.add" ResourcePath companyA = new ResourcePath(companies, - new Constant("\"A\"", DataConstraintModel.typeString)); // "companies.A" + new Constant("A", DataConstraintModel.typeString)); // "companies.A" ResourcePath companyA_add = new ResourcePath(companyA, "add"); // "companies.{cid2}.add" model.addResourcePath(customer_off); model.addResourcePath(customer_add);