diff --git a/AlgebraicDataflowArchitectureModel/models/SimpleUI.model b/AlgebraicDataflowArchitectureModel/models/SimpleUI.model index ac3c51d..3e03bbd 100644 --- a/AlgebraicDataflowArchitectureModel/models/SimpleUI.model +++ b/AlgebraicDataflowArchitectureModel/models/SimpleUI.model @@ -1,3 +1,14 @@ +init { + screenTemplates := { + "000": {"widgets": {"001": {"type": "textInput", "text": "", "state": 0}, + "002": {"type": "button", "text": "Next", "state": 0}}, + "layout": true}, + "001": {"widgets": {"003": {"type": "label", "text": "label", "state": 0}, + "004": {"type": "button", "text": "Back", "state": 0}}, + "layout": true} + } +} + native channel ScreenUpdate { in screen(curSc: Json, update(curSc, nextSc)) = nextSc } @@ -38,6 +49,16 @@ out screen.widgets.{wid}.text(curText: Str, textEvent(nextText)) = nextText } +channel ChangeCurScreen { + out curScreen(curScId: Str, changeCurScreen(nextScId)) = nextScId +} + +channel ScreenTransition { + in curScreen(curScId: Str, transScreen(nextScId, nextSc)) = nextScId + in screenTemplates.{nextScId}(curSc, transScreen(nextScId, nextSc)) = nextSc + out screen(curS, transScreen(nextScId, nextSc)) = nextSc +} + channel ChangeLayout { out screen.layout(curLayout: Bool, changeLayout(layout)) = layout } @@ -72,4 +93,4 @@ channel AddMovableTextInput { out screen.widgets(widgets: Map, addMovableTextInput(wid: Str, x: Int, y: Int, width: Int, height: Int)) = insert(widgets, wid, {"type": "textInput", "text": "", "x": x, "y": y, "width": width, "height": height, "state": 0}) -} +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java index 41ec4d5..82f6fe3 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java @@ -194,7 +194,7 @@ if (((DataTransferChannel)ch).getInputResources().size() == 0) {//ioch Or normalch for (ChannelMember out: ((DataTransferChannel)ch).getOutputChannelMembers()) { ResourcePath resPath = out.getResource(); - if (resId.isInstanceOf(resPath)) {//account.uid == acounts.123 + if (!out.isOutside() && resId.isInstanceOf(resPath)) {//account.uid == acounts.123 eventResPath = resPath; eventChs.add(((DataTransferChannel)ch)); String message = null; diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java index 20c3cf2..980fc53 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java @@ -51,6 +51,7 @@ public Symbol(String name, int arity, Type operatorType, IImplGenerator generator) { this.name = name; + this.implName = name; this.arity = arity; this.operatorType = operatorType; this.generator = generator; @@ -59,6 +60,7 @@ public Symbol(String name, int arity, Type operatorType, IImplGenerator generator, boolean bSideEffect) { this.name = name; + this.implName = name; this.arity = arity; this.operatorType = operatorType; this.generator = generator; @@ -71,19 +73,23 @@ public Symbol(String name, int arity, ICalculator calculator) { this.name = name; + this.implName = name; this.arity = arity; this.calculator = calculator; } public Symbol(String name, int arity, Type operatorType, ICalculator calculator) { this.name = name; + this.implName = name; this.arity = arity; this.operatorType = operatorType; + this.implOperatorType = operatorType; this.calculator = calculator; } public Symbol(String name, int arity, Type operatorType, IImplGenerator generator, ICalculator calculator) { this.name = name; + this.implName = name; this.arity = arity; this.operatorType = operatorType; this.generator = generator; diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java index e408a54..3b573d2 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java @@ -73,7 +73,7 @@ public boolean isAncestorOf(Type another) { if (this.equals(another)) return true; - if (another.getParentTypes() == null) return false; + if (another == null || another.getParentTypes() == null) return false; for (Type anothersParentType: another.getParentTypes()) { if (isAncestorOf(anothersParentType)) return true; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index a76879f..4482a27 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -40,10 +40,10 @@ public static final Symbol add = new Symbol(Parser.ADD, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -65,10 +65,10 @@ public static final Symbol mul = new Symbol(Parser.MUL, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -90,10 +90,10 @@ public static final Symbol sub = new Symbol(Parser.SUB, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -115,10 +115,10 @@ public static final Symbol div = new Symbol(Parser.DIV, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -140,10 +140,10 @@ public static final Symbol mod = new Symbol(Parser.MOD, 2, Symbol.Type.INFIX, "%", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -161,7 +161,7 @@ public static final Symbol minus = new Symbol(Parser.MINUS, 1, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } Constant arg = (Constant) args.get(0); @@ -193,10 +193,10 @@ }, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -237,10 +237,10 @@ }, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -269,10 +269,10 @@ public static final Symbol gt = new Symbol(Parser.GT, 2, Symbol.Type.INFIX, ">", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -299,10 +299,10 @@ public static final Symbol lt = new Symbol(Parser.LT, 2, Symbol.Type.INFIX, "<", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -329,10 +329,10 @@ public static final Symbol ge = new Symbol(Parser.GE, 2, Symbol.Type.INFIX, ">=", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -359,10 +359,10 @@ public static final Symbol le = new Symbol(Parser.LE, 2, Symbol.Type.INFIX, "<=", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -389,10 +389,10 @@ public static final Symbol and = new Symbol(Parser.AND, 2, Symbol.Type.INFIX, "&&", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -413,10 +413,10 @@ public static final Symbol or = new Symbol(Parser.OR, 2, Symbol.Type.INFIX, "||", Symbol.Type.INFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } - if (!(args.get(1) instanceof Constant)) { + if (!(args.get(1).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -437,7 +437,7 @@ public static final Symbol neg = new Symbol(Parser.NEG, 1, Symbol.Type.PREFIX, "!", Symbol.Type.PREFIX, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) { + if (!(args.get(0).getClass() == Constant.class)) { return null; } Constant arg0 = (Constant) args.get(0); @@ -475,7 +475,7 @@ }, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (args.get(0) instanceof Constant && ((Constant) args.get(0)).getSymbol().equals(nil)) { + if (args.get(0).getClass() == Constant.class && ((Constant) args.get(0)).getSymbol().equals(nil)) { return new Constant(false_); } if (args.get(0) instanceof Term) { @@ -588,7 +588,7 @@ }, new Symbol.ICalculator() { @Override public Expression calculate(List args) { - if (!(args.get(0) instanceof Constant)) return null; + if (!(args.get(0).getClass() == Constant.class)) return null; if (((Constant) args.get(0)).getSymbol().equals(true_)) { return args.get(1); } else if (((Constant) args.get(0)).getSymbol().equals(false_)) { diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java index 7412266..be99827 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourceHierarchy.java @@ -97,6 +97,7 @@ public ResourceHierarchy(ResourceHierarchy parent, Expression parameterExp, Type resourceStateType) { this.parent = parent; + if (this.children == null) this.children = new HashSet<>(); this.resourceName = null; this.numParameters = 1; this.resourceStateType = resourceStateType; @@ -120,6 +121,7 @@ public ResourceHierarchy(ResourceHierarchy parent, int numParameters, Type resourceStateType) { this.parent = parent; + if (this.children == null) this.children = new HashSet<>(); this.resourceName = null; this.numParameters = numParameters; this.resourceStateType = resourceStateType; diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/Event.java b/AlgebraicDataflowArchitectureModel/src/simulator/Event.java index 58a9df8..b0feb2b 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/Event.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/Event.java @@ -235,8 +235,11 @@ for (ChannelMember depending: dependency.keySet()) { toResolve.remove(depending); } + Expression messageConstraint = null; + if ((messageConstraint = getMessage()) instanceof Term) { + unifiedMessage = (Term) messageConstraint; + } for (ChannelMember leafMember: toResolve) { - Expression messageConstraint = null; if (channel.getInputChannelMembers().contains(leafMember)) { // Calculate message constraint from an input state transition messageConstraint = channel.calcMessageConstraintForInputMember(leafMember, null, resouceStateAccessor, null, substitutedPositionsInMessageFromChannels); @@ -287,7 +290,6 @@ } // Calculate message constraint - Expression messageConstraint = null; if (channel.getInputChannelMembers().contains(dependingMem)) { // Calculate message constraint from an input state transition messageConstraint = channel.calcMessageConstraintForInputMember(dependingMem, null, resouceStateAccessor, null, substitutedPositionsInMessageFromChannels); diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java index 6197b03..57f5a35 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/Simulator.java @@ -84,6 +84,7 @@ public SystemState transition(Event inputEvent) throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { SystemState nextSystemState = new SystemState(curState); + inputEvent.updateDependingParameters(new ResourceStateValueProvider(curState, nextSystemState)); nextSystemState.addEvent(inputEvent); fireEvent(inputEvent, curState, nextSystemState); @@ -174,16 +175,25 @@ if (channel.getOutputResources().size() > 0) { // For each output resource, calculate the next state. for (ChannelMember out: channel.getOutputChannelMembers()) { + // Calculate the next state expression. Expression nextResState = null; if (!event.isInput()) { nextResState = channel.deriveUpdateExpressionOf(out, resouceStateAccessor).getKey(); } else { nextResState = channel.deriveUpdateExpressionOf(out, (Term) event.getMessage(), resouceStateAccessor); } - ResourceIdentifier outResId = event.getOutputResourceIdentifier(out.getResource()); + // Substitute each channel selector in the expression to a value. + for (Map.Entry selestorAndVal: event.getChannelSelectorAndValues()) { + Expression selExp = selestorAndVal.getKey().getExpression(); + if (nextResState instanceof Term && selExp instanceof Variable) { + nextResState = ((Term) nextResState).substitute((Variable) selExp, selestorAndVal.getValue()); + } + } if (nextResState instanceof Term) { nextResState = ((Term) nextResState).reduce(); } + // Update the resource state. + ResourceIdentifier outResId = event.getOutputResourceIdentifier(out.getResource()); ResourceIdentifier updatedOutResId = nextSystemState.updateResourceState(outResId, nextResState); while (updatedOutResId != null) { // In addition to the target state, its descendants' states are also changed. for (Event nextEvent: getNextEvents(updatedOutResId, curSystemState, nextSystemState)) { @@ -203,22 +213,10 @@ } } - private Set getNextEvents(ResourceIdentifier inResId, final SystemState curSystemState, final SystemState nextSystemState) + private Set getNextEvents(ResourceIdentifier inResId, SystemState curSystemState, SystemState nextSystemState) throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { Set nextEvents = new HashSet<>(); - IResourceStateValueProvider resourceStateValueProvider = new IResourceStateValueProvider() { - @Override - public Expression getCurrentStateValueOf(ResourceIdentifier resId) { - if (curSystemState.getResource(resId) == null) return null; - return curSystemState.getResource(resId).getState().getValue(); - } - - @Override - public Expression getNextStateValueOf(ResourceIdentifier resId) { - if (nextSystemState.getResource(resId) == null) return null; - return nextSystemState.getResource(resId).getState().getValue(); - } - }; + IResourceStateValueProvider resourceStateValueProvider = new ResourceStateValueProvider(curSystemState, nextSystemState); for (Map.Entry chEntry: nextSystemState.getChannelStates().entrySet()) { DataTransferChannel channel = chEntry.getKey(); ChannelState nextChState = chEntry.getValue(); @@ -316,4 +314,26 @@ } return nextEvents; } + + private static class ResourceStateValueProvider implements IResourceStateValueProvider { + SystemState curSystemState; + SystemState nextSystemState; + + public ResourceStateValueProvider(SystemState curSystemState, SystemState nextSystemState) { + this.curSystemState = curSystemState; + this.nextSystemState = nextSystemState; + } + + @Override + public Expression getCurrentStateValueOf(ResourceIdentifier resId) { + if (curSystemState.getResource(resId) == null) return null; + return curSystemState.getResource(resId).getState().getValue(); + } + + @Override + public Expression getNextStateValueOf(ResourceIdentifier resId) { + if (nextSystemState.getResource(resId) == null) return null; + return nextSystemState.getResource(resId).getState().getValue(); + } + }; } diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java index cac52a4..98f752e 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java @@ -12,6 +12,7 @@ import models.algebra.Expression; import models.algebra.Term; import models.algebra.Type; +import models.algebra.Variable; import models.dataConstraintModel.DataConstraintModel; import models.dataConstraintModel.JsonTerm; import models.dataConstraintModel.ListTerm; @@ -88,9 +89,19 @@ ResourceIdentifier createdResource = null; for (int i = 0; i < listValue.size(); i++) { Expression childExp = new Constant(Integer.toString(i), DataConstraintModel.typeInt); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, listValue.get(i)); ((ListResourceState) state).addChildState(childInfo.getKey()); createdResource = childInfo.getValue(); @@ -119,7 +130,13 @@ if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); } else { - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1); + Type childResType = null; + if (listValue.getChild(1) instanceof Variable) { + childResType = ((Variable) listValue.getChild(1)).getType(); + } else if (listValue.getChild(1) instanceof Term) { + childResType = ((Term) listValue.getChild(1)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, listValue.getChild(1)); @@ -136,9 +153,19 @@ ResourceIdentifier createdResource = null; for (String key: mapValue.keySet()) { Expression childExp = new Constant(key, DataConstraintModel.typeString); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.get(key)); ((MapResourceState) state).addChildState(key, childInfo.getKey()); createdResource = childInfo.getValue(); @@ -151,9 +178,19 @@ ResourceIdentifier createdResource = null; for (String key: mapValue.keySet()) { Expression childExp = new Constant(key, DataConstraintModel.typeString); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.get(key)); ((MapResourceState) state).addChildState(key, childInfo.getKey()); createdResource = childInfo.getValue(); @@ -180,7 +217,13 @@ if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); } else { - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1); + Type childResType = null; + if (mapValue.getChild(2) instanceof Variable) { + childResType = ((Variable) mapValue.getChild(2)).getType(); + } else if (mapValue.getChild(2) instanceof Term) { + childResType = ((Term) mapValue.getChild(2)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); String childId = ((Constant) childExp).toString(); @@ -207,7 +250,13 @@ } } if (childResourceHierarchy == null) { - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName); + 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); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, jsonValue.get(key)); @@ -236,7 +285,13 @@ } } if (childResourceHierarchy == null) { - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName); + Type childResType = null; + if (jsonValue.getChild(2) instanceof Variable) { + childResType = ((Variable) jsonValue.getChild(2)).getType(); + } else if (jsonValue.getChild(2) instanceof Term) { + childResType = ((Term) jsonValue.getChild(2)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); String childId = ((Constant) childExp).toString(); @@ -289,9 +344,19 @@ Map.Entry createInfo = null; for (int i = 0; i < listValue.size(); i++) { Expression childExp = new Constant(Integer.toString(i), DataConstraintModel.typeInt); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, listValue.get(i)); state.addChildState(childInfo.getKey()); createInfo = new AbstractMap.SimpleEntry<>(state, childInfo.getValue()); @@ -302,9 +367,19 @@ if (listValue.getSymbol().equals(DataConstraintModel.append)) { ListResourceState state = new ListResourceState(); Expression childExp = new Constant(Integer.toString(((ListResourceState) state).getChildStates().size()), DataConstraintModel.typeInt); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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.getChild(1) instanceof Variable) { + childResType = ((Variable) listValue.getChild(1)).getType(); + } else if (listValue.getChild(1) instanceof Term) { + childResType = ((Term) listValue.getChild(1)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, listValue.getChild(1)); state.addChildState(childInfo.getKey()); return new AbstractMap.SimpleEntry<>(state, childInfo.getValue()); @@ -318,9 +393,19 @@ Map.Entry createInfo = null; for (String key: mapValue.keySet()) { Expression childExp = new Constant(key, DataConstraintModel.typeString); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.get(key)); state.addChildState(key, childInfo.getKey()); createInfo = new AbstractMap.SimpleEntry<>(state, childInfo.getValue()); @@ -332,9 +417,19 @@ Map.Entry createInfo = null; for (String key: mapValue.keySet()) { Expression childExp = new Constant(key, DataConstraintModel.typeString); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.get(key)); state.addChildState(key, childInfo.getKey()); createInfo = new AbstractMap.SimpleEntry<>(state, childInfo.getValue()); @@ -346,9 +441,19 @@ Expression childExp = mapValue.getChild(1); if (childExp instanceof Constant) { MapResourceState state = new MapResourceState(); - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, - childExp, - resourceIdentifier.getResourceHierarchy().getChildren().iterator().next()); + 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.getChild(2) instanceof Variable) { + childResType = ((Variable) mapValue.getChild(2)).getType(); + } else if (mapValue.getChild(2) instanceof Term) { + childResType = ((Term) mapValue.getChild(2)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); + } + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); String childId = ((Constant) childExp).toString(); Map.Entry childInfo = createResourceState(childResourceIdentifier, mapValue.getChild(2)); state.addChildState(childId, childInfo.getKey()); @@ -372,7 +477,13 @@ } } if (childResourceHierarchy == null) { - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName); + 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); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); Map.Entry childInfo = createResourceState(childResourceIdentifier, jsonValue.get(key)); @@ -401,7 +512,13 @@ } } if (childResourceHierarchy == null) { - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName); + Type childResType = null; + if (jsonValue.getChild(2) instanceof Variable) { + childResType = ((Variable) jsonValue.getChild(2)).getType(); + } else if (jsonValue.getChild(2) instanceof Term) { + childResType = ((Term) jsonValue.getChild(2)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), memberName, childResType); } ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, memberName, childResourceHierarchy); String childId = ((Constant) childExp).toString();