diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 37bdd37..75e5dce 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -28,6 +28,7 @@ import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; import models.dataConstraintModel.ResourcePath; +import models.dataConstraintModel.Selector; import models.dataFlowModel.ChannelNode; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; @@ -234,24 +235,29 @@ } } - protected void declareAccessorInMainComponent(TypeDeclaration mainComponent, ResourcePath accessRes, MethodDeclaration getter, ILanguageSpecific langSpec) { - List params = new ArrayList<>(); - if (getter.getParameters() != null) { - for (VariableDeclaration var: getter.getParameters()) { - params.add(var.getName()); + protected void declareAccessorInMainComponent(TypeDeclaration mainComponent, ResourceNode accessRes, MethodDeclaration getter, ILanguageSpecific langSpec) { + List mainParams = new ArrayList<>(); + for (Selector selector: accessRes.getAllSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + mainParams.add(var.getName()); } } MethodDeclaration accessor = null; - if (params.size() == 0) { + if (mainParams.size() == 0) { accessor = langSpec.newMethodDeclaration("get" + langSpec.toComponentName(accessRes.getResourceName()), accessRes.getResourceStateType()); } else { accessor = langSpec.newMethodDeclaration("get" + langSpec.toComponentName(accessRes.getResourceName()), false, accessRes.getResourceStateType(), getter.getParameters()); } Block block = new Block(); - if (params.size() == 0) { + if (getter.getParameters() == null || getter.getParameters().size() == 0) { block.addStatement(langSpec.getReturnStatement(langSpec.getMethodInvocation(accessRes.getResourceName(), getter.getName())) + langSpec.getStatementDelimiter()); } else { - block.addStatement(langSpec.getReturnStatement(langSpec.getMethodInvocation(accessRes.getResourceName(), getter.getName(), params)) + langSpec.getStatementDelimiter()); + List resParams = new ArrayList<>(); + for (VariableDeclaration var: getter.getParameters()) { + resParams.add(var.getName()); + } + block.addStatement(langSpec.getReturnStatement(langSpec.getMethodInvocation(accessRes.getResourceName(), getter.getName(), resParams)) + langSpec.getStatementDelimiter()); } accessor.setBody(block); mainComponent.addMethod(accessor); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 080d7f7..b3b4340 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -70,12 +70,11 @@ } } - ResourcePath res = resourceNode.getOutSideResource(); - Type resStateType = res.getResourceStateType(); + Type resStateType = resourceNode.getResourceStateType(); // Declare the field in this resource to store the state. if (((StoreAttribute) resourceNode.getAttribute()).isStored() && resourceNode.getNumberOfParameters() == 0) { - FieldDeclaration stateField = langSpec.newFieldDeclaration(resStateType, fieldOfResourceState, langSpec.getFieldInitializer(resStateType, res.getResourceHierarchy().getInitialValue())); + FieldDeclaration stateField = langSpec.newFieldDeclaration(resStateType, fieldOfResourceState, langSpec.getFieldInitializer(resStateType, resourceNode.getResourceHierarchy().getInitialValue())); component.addField(stateField); } @@ -83,7 +82,7 @@ MethodDeclaration getter = declareGetterMethod(resourceNode, component, resStateType, langSpec); // Declare the accessor method in the main component to call the getter method. - declareAccessorInMainComponent(mainComponent, res, getter, langSpec); + declareAccessorInMainComponent(mainComponent, resourceNode, getter, langSpec); // Declare cache fields and update methods in this resource. List updates = declareCacheFieldsAndUpdateMethods(resourceNode, component, langSpec); @@ -140,15 +139,10 @@ private MethodDeclaration declareGetterMethod(ResourceNode resourceNode, TypeDeclaration component, Type resStateType, ILanguageSpecific langSpec) { // Declare the getter method of the resource state. ArrayList params = new ArrayList<>(); - DataTransferChannel inCh = null; - Edge inEdge = resourceNode.getInEdges().iterator().next(); - if (inEdge != null) { - inCh = ((ChannelNode) inEdge.getSource()).getChannel(); - for (Selector selector: inCh.getAllSelectors()) { - if (selector.getExpression() instanceof Variable) { - Variable var = (Variable) selector.getExpression(); - params.add(new VariableDeclaration(var.getType(), var.getName())); - } + for (Selector selector: resourceNode.getSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + params.add(new VariableDeclaration(var.getType(), var.getName())); } } MethodDeclaration getter = null; @@ -341,17 +335,25 @@ MethodDeclaration mainInput = null; if (message instanceof Term) { // Declare an input method in this component. - ArrayList params = new ArrayList<>(); - for (Selector selector: ch.getAllSelectors()) { + ArrayList resParams = new ArrayList<>(); + ArrayList mainParams = new ArrayList<>(); + for (Selector selector: resourceNode.getSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); - params.add(new VariableDeclaration(var.getType(), var.getName())); + resParams.add(new VariableDeclaration(var.getType(), var.getName())); + } + } + for (Selector selector: resourceNode.getAllSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + mainParams.add(new VariableDeclaration(var.getType(), var.getName())); } } for (Variable var: message.getVariables().values()) { - params.add(langSpec.newVariableDeclaration(var.getType(), var.getName())); + resParams.add(langSpec.newVariableDeclaration(var.getType(), var.getName())); + mainParams.add(langSpec.newVariableDeclaration(var.getType(), var.getName())); } - input = langSpec.newMethodDeclaration(((Term) message).getSymbol().getImplName(), false, null, params); + input = langSpec.newMethodDeclaration(((Term) message).getSymbol().getImplName(), false, null, resParams); component.addMethod(input); inputMethods.add(input); @@ -359,14 +361,14 @@ String str = ((Term) message).getSymbol().getImplName(); mainInput = getMethod(mainComponent, str); if (mainInput == null) { - mainInput = langSpec.newMethodDeclaration(str, false, null, params); + mainInput = langSpec.newMethodDeclaration(str, false, null, mainParams); mainComponent.addMethod(mainInput); } else { // Add type to a parameter without type. if (mainInput.getParameters() != null) { for (VariableDeclaration param: mainInput.getParameters()) { if (param.getType() == null) { - for (VariableDeclaration p: params) { + for (VariableDeclaration p: mainParams) { if (param.getName().equals(p.getName()) && p.getType() != null) { param.setType(p.getType()); } @@ -377,17 +379,24 @@ } } else if (message instanceof Variable) { // Declare an input method in this component. - ArrayList params = new ArrayList<>(); - for (Selector selector: ch.getAllSelectors()) { + ArrayList resParams = new ArrayList<>(); + ArrayList mainParams = new ArrayList<>(); + for (Selector selector: resourceNode.getSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); - params.add(new VariableDeclaration(var.getType(), var.getName())); + resParams.add(new VariableDeclaration(var.getType(), var.getName())); } } - if (params.size() == 0) { + for (Selector selector: resourceNode.getAllSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + mainParams.add(new VariableDeclaration(var.getType(), var.getName())); + } + } + if (resParams.size() == 0) { input = langSpec.newMethodDeclaration(((Variable) message).getName(), null); } else { - input = langSpec.newMethodDeclaration(((Variable) message).getName(), false, null, params); + input = langSpec.newMethodDeclaration(((Variable) message).getName(), false, null, resParams); } component.addMethod(input); inputMethods.add(input); @@ -396,10 +405,10 @@ // Declare the accessor in the main component to call the input method. mainInput = getMethod(mainComponent, str); if (mainInput == null) { - if (params.size() == 0) { + if (mainParams.size() == 0) { mainInput = langSpec.newMethodDeclaration(str, null); } else { - mainInput = langSpec.newMethodDeclaration(str, false, null, params); + mainInput = langSpec.newMethodDeclaration(str, false, null, mainParams); } mainComponent.addMethod(mainInput); } @@ -408,7 +417,7 @@ // Add an invocation to the accessor method. if (mainInput != null) { List args = new ArrayList<>(); - for (Selector selector: ch.getAllSelectors()) { + for (Selector selector: resourceNode.getAllSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); args.add(var.getName()); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java index 771e43a..b39db0e 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java @@ -222,40 +222,46 @@ } // Declare input methods in resources and the main type. - Channel inCh = null; for (Channel ch : model.getIOChannels()) { for (ChannelMember cm : ((DataTransferChannel) ch).getOutputChannelMembers()) { if (rn.getInSideResources().contains(cm.getResource())) { - inCh = ch; Expression message = cm.getStateTransition().getMessageExpression(); if (message instanceof Term) { - // In the resource. - ArrayList params = new ArrayList<>(); - for (Selector selector: ch.getAllSelectors()) { + // In each resource. + ArrayList resParams = new ArrayList<>(); + ArrayList mainParams = new ArrayList<>(); + for (Selector selector: rn.getSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); - params.add(new VariableDeclaration(var.getType(), var.getName())); + resParams.add(new VariableDeclaration(var.getType(), var.getName())); + } + } + for (Selector selector: rn.getAllSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + mainParams.add(new VariableDeclaration(var.getType(), var.getName())); } } for (Variable var: message.getVariables().values()) { - params.add(new VariableDeclaration(var.getType(), var.getName())); + resParams.add(new VariableDeclaration(var.getType(), var.getName())); + mainParams.add(new VariableDeclaration(var.getType(), var.getName())); } MethodDeclaration input = new MethodDeclaration( - ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(), - false, typeVoid, params); + ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(), + false, typeVoid, resParams); type.addMethod(input); // In the main type. String str = ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(); - input = getMethod(mainType, str, params); + input = getMethod(mainType, str, mainParams); if (input == null) { - input = new MethodDeclaration(str, false, typeVoid, params); + input = new MethodDeclaration(str, false, typeVoid, mainParams); mainType.addMethod(input); } else { // Add type to a parameter without type. for (VariableDeclaration param: input.getParameters()) { if (param.getType() == null) { - for (VariableDeclaration p: params) { + for (VariableDeclaration p: mainParams) { if (param.getName().equals(p.getName()) && p.getType() != null) { param.setType(p.getType()); } @@ -264,19 +270,26 @@ } } } else if (message instanceof Variable) { - // In the resource. - ArrayList params = new ArrayList<>(); - for (Selector selector: ch.getAllSelectors()) { + // In each resource. + ArrayList resParams = new ArrayList<>(); + ArrayList mainParams = new ArrayList<>(); + for (Selector selector: rn.getSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); - params.add(new VariableDeclaration(var.getType(), var.getName())); + resParams.add(new VariableDeclaration(var.getType(), var.getName())); + } + } + for (Selector selector: rn.getAllSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + mainParams.add(new VariableDeclaration(var.getType(), var.getName())); } } MethodDeclaration input = null; - if (params.size() > 0) { + if (resParams.size() > 0) { input = new MethodDeclaration( ((Variable) cm.getStateTransition().getMessageExpression()).getName(), - false, typeVoid, params); + false, typeVoid, resParams); } else { input = new MethodDeclaration( ((Variable) cm.getStateTransition().getMessageExpression()).getName(), @@ -286,10 +299,10 @@ // In the main type. String str = ((Variable) cm.getStateTransition().getMessageExpression()).getName(); - input = getMethod(mainType, str, params); + input = getMethod(mainType, str, mainParams); if (input == null) { - if (params.size() > 0) { - input = new MethodDeclaration(str, false, typeVoid, params); + if (mainParams.size() > 0) { + input = new MethodDeclaration(str, false, typeVoid, mainParams); } else { input = new MethodDeclaration(str, false, typeVoid, null); } @@ -307,57 +320,53 @@ } // Declare the getter methods to obtain the state in the resource and the main type. - if (inCh == null) { - DataFlowEdge chToRes = (DataFlowEdge) rn.getInEdges().iterator().next(); - if (chToRes != null) { - inCh = ((ChannelNode) chToRes.getSource()).getChannel(); + List resParams = new ArrayList<>(); + List mainParams = new ArrayList<>(); + for (Selector pathParam: rn.getSelectors()) { + if (pathParam.getExpression() instanceof Variable) { + Variable var = (Variable) pathParam.getExpression(); + resParams.add(new VariableDeclaration(var.getType(), var.getName())); } } - if (inCh != null) { - // In the resource. - ArrayList params = new ArrayList<>(); - for (Selector selector: inCh.getAllSelectors()) { - if (selector.getExpression() instanceof Variable) { - Variable var = (Variable) selector.getExpression(); - params.add(new VariableDeclaration(var.getType(), var.getName())); - } + for (Selector pathParam: rn.getAllSelectors()) { + if (pathParam.getExpression() instanceof Variable) { + Variable var = (Variable) pathParam.getExpression(); + mainParams.add(new VariableDeclaration(var.getType(), var.getName())); } - if (params.size() > 0) { - type.addMethod(new MethodDeclaration("getValue", false, rn.getResourceStateType(), params)); - } else { - type.addMethod(new MethodDeclaration("getValue", rn.getResourceStateType())); - } - - // In the main type. - MethodDeclaration getter = null; - if (params.size() > 0) { - getter = new MethodDeclaration("get" + rn.getResourceName().substring(0, 1).toUpperCase() - + rn.getResourceName().substring(1), - false, - rn.getResourceStateType(), - params); - } else { - getter = new MethodDeclaration("get" + rn.getResourceName().substring(0, 1).toUpperCase() + } + if (resParams.size() > 0) { + type.addMethod(new MethodDeclaration("getValue", false, rn.getResourceStateType(), resParams)); + } else { + type.addMethod(new MethodDeclaration("getValue", rn.getResourceStateType())); + } + + // In the main type. + MethodDeclaration getter = null; + if (mainParams.size() > 0) { + getter = new MethodDeclaration("get" + rn.getResourceName().substring(0, 1).toUpperCase() + rn.getResourceName().substring(1), - rn.getResourceStateType()); - } - getter.setBody(new Block()); - if (params.size() > 0) { - String sParams = ""; - String delimiter = ""; - for (VariableDeclaration var: params) { - sParams += delimiter + var.getName(); - delimiter = ", "; - } - getter.getBody().addStatement("return " + rn.getResourceName() + ".getValue(" + sParams + ");"); - } else { - getter.getBody().addStatement("return " + rn.getResourceName() + ".getValue();"); - } - mainType.addMethod(getter); + false, + rn.getResourceStateType(), + mainParams); + } else { + getter = new MethodDeclaration("get" + rn.getResourceName().substring(0, 1).toUpperCase() + + rn.getResourceName().substring(1), + rn.getResourceStateType()); } + getter.setBody(new Block()); + if (mainParams.size() > 0) { + String sParams = ""; + String delimiter = ""; + for (VariableDeclaration var: mainParams) { + sParams += delimiter + var.getName(); + delimiter = ", "; + } + getter.getBody().addStatement("return " + rn.getResourceName() + ".getValue(" + sParams + ");"); + } else { + getter.getBody().addStatement("return " + rn.getResourceName() + ".getValue();"); + } + mainType.addMethod(getter); } - - // Declare the Pair class. boolean isCreatedPair = false; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index 177b87e..d8dbe5d 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -246,7 +246,7 @@ for (ChannelMember out: outs) { MethodDeclaration input = getInputMethod(type, out); if (input != null) { - // In the resource + // In each resource if (resource.getTotalNumParameters() == 0) { String[] sideEffects = new String[] {""}; Expression updateExp = entry.getKey().deriveUpdateExpressionOf(out, JavaCodeGenerator.pushAccessor); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index 7618a14..0cfbbce 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -176,16 +176,14 @@ // } // Declare input methods in resources. - Channel inCh = null; for (Channel ch : model.getIOChannels()) { for (ChannelMember cm : ((DataTransferChannel) ch).getOutputChannelMembers()) { if (rn.getInSideResources().contains(cm.getResource())) { - inCh = ch; Expression message = cm.getStateTransition().getMessageExpression(); if (message instanceof Term) { ArrayList params = new ArrayList<>(); String resourcePath = "\""; - for (Selector selector: ch.getAllSelectors()) { + for (Selector selector: rn.getSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); String paramName = var.getName(); @@ -217,7 +215,7 @@ } else if (message instanceof Variable) { ArrayList params = new ArrayList<>(); String resourcePath = "\""; - for (Selector selector: ch.getAllSelectors()) { + for (Selector selector: rn.getSelectors()) { if (selector.getExpression() instanceof Variable) { Variable var = (Variable) selector.getExpression(); String paramName = var.getName(); @@ -259,39 +257,31 @@ } // Declare the getter method to obtain the state in the type of each resource. - if (inCh == null) { - DataFlowEdge chToRes = (DataFlowEdge) rn.getInEdges().iterator().next(); - if (chToRes != null) { - inCh = ((ChannelNode) chToRes.getSource()).getChannel(); + ArrayList params = new ArrayList<>(); + String resourcePath = "\""; + for (Selector selector: rn.getSelectors()) { + if (selector.getExpression() instanceof Variable) { + Variable var = (Variable) selector.getExpression(); + String paramName = var.getName(); + VariableDeclaration param = new VariableDeclaration(var.getType(), paramName); + param.addAnnotation(new Annotation("PathParam", "\"" + paramName + "\"")); + params.add(param); + resourcePath += "/{" + paramName + "}"; } + } + resourcePath += "\""; + MethodDeclaration getter = null; + if (params.size() > 0) { + getter = new MethodDeclaration("getValue", false, rn.getResourceStateType(), params); + } else { + getter = new MethodDeclaration("getValue", rn.getResourceStateType()); } - if (inCh != null) { - ArrayList params = new ArrayList<>(); - String resourcePath = "\""; - for (Selector selector: inCh.getAllSelectors()) { - if (selector.getExpression() instanceof Variable) { - Variable var = (Variable) selector.getExpression(); - String paramName = var.getName(); - VariableDeclaration param = new VariableDeclaration(var.getType(), paramName); - param.addAnnotation(new Annotation("PathParam", "\"" + paramName + "\"")); - params.add(param); - resourcePath += "/{" + paramName + "}"; - } - } - resourcePath += "\""; - MethodDeclaration getter = null; - if (params.size() > 0) { - getter = new MethodDeclaration("getValue", false, rn.getResourceStateType(), params); - } else { - getter = new MethodDeclaration("getValue", rn.getResourceStateType()); - } - getter.addAnnotation(new Annotation("Produces", "MediaType.APPLICATION_JSON")); - getter.addAnnotation(new Annotation("GET")); - if (inCh.getAllSelectors().size() > 0) { - getter.addAnnotation(new Annotation("Path", resourcePath)); - } - type.addMethod(getter); + getter.addAnnotation(new Annotation("Produces", "MediaType.APPLICATION_JSON")); + getter.addAnnotation(new Annotation("GET")); + if (rn.getSelectors().size() > 0) { + getter.addAnnotation(new Annotation("Path", resourcePath)); } + type.addMethod(getter); } // Declare the Pair class. diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java index 2c906b0..ad09c92 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java @@ -205,9 +205,6 @@ // Calculate message constraints from input state transitions for (ChannelMember inputMember: getInputChannelMembers()) { ResourcePath inputResource = inputMember.getResource(); -// if (inputResource.getNumberOfParameters() > 0) { -// throw new ParameterizedIdentifierIsFutureWork(); -// } Expression curInputStateAccessor = null; Expression nextInputStateAccessor = null; if (inputResourceToStateAccessor == null) { @@ -224,9 +221,6 @@ // Calculate message constraints from reference state transitions for (ChannelMember referenceMember: getReferenceChannelMembers()) { ResourcePath referenceResource = referenceMember.getResource(); -// if (referenceResource.getNumberOfParameters() > 0) { -// throw new ParameterizedIdentifierIsFutureWork(); -// } Expression curInputStateAccessor = null; if (inputResourceToStateAccessor == null) { curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(referenceResource, targetMember.getResource()); @@ -252,9 +246,6 @@ // Calculate the next state of target resource from the unified message and the current resource state ResourcePath targetResource = targetMember.getResource(); -// if (targetResource.getNumberOfParameters() > 0) { -// throw new ParameterizedIdentifierIsFutureWork(); -// } Expression curOutputStateAccessor = stateAccessor.getCurrentStateAccessorFor(targetResource, targetResource); if (unifiedMessage == null) { // for IOChannel diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java index c94b787..b339a66 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java @@ -26,42 +26,42 @@ return dataFlowGraph; } - private void addResourceToChannelEdges(DataFlowGraph dataFlowGraph, Channel channel, ChannelNode parentNode, + private void addResourceToChannelEdges(DataFlowGraph dataFlowGraph, Channel dstChannel, ChannelNode parentChannelNode, Map> resourceMap) { - DataTransferChannel dfChannel = (DataTransferChannel)channel; - ChannelNode channelNode = dataFlowGraph.addChannelNode(parentNode, dfChannel); - Set inputResources = dfChannel.getInputResources(); - for (ResourcePath inRes: inputResources) { - ResourceNode resNode = addResourceNodes(dataFlowGraph, inRes, dfChannel, resourceMap); - dataFlowGraph.addEdge(resNode, channelNode); + DataTransferChannel dstDfChannel = (DataTransferChannel)dstChannel; + ChannelNode dstChannelNode = dataFlowGraph.addChannelNode(parentChannelNode, dstDfChannel); + Set inputResources = dstDfChannel.getInputResources(); + for (ResourcePath srcRes: inputResources) { + ResourceNode srcResNode = addResourceNodes(dataFlowGraph, srcRes, dstDfChannel, resourceMap); + dataFlowGraph.addEdge(srcResNode, dstChannelNode); } - for (Channel childChannel: dfChannel.getChildren()) { - addResourceToChannelEdges(dataFlowGraph, childChannel, channelNode, resourceMap); + for (Channel childChannel: dstDfChannel.getChildren()) { + addResourceToChannelEdges(dataFlowGraph, childChannel, dstChannelNode, resourceMap); } } - private void addChannelToResourceEdges(DataFlowGraph dataFlowGraph, Channel channel, ChannelNode parentNode, + private void addChannelToResourceEdges(DataFlowGraph dataFlowGraph, Channel srcChannel, ChannelNode parentChannelNode, Map> resourceMap) { - DataTransferChannel dfChannel = (DataTransferChannel)channel; - Set outputResources = dfChannel.getOutputResources(); - ChannelNode channelNode = dataFlowGraph.addChannelNode(parentNode, dfChannel); - for (ResourcePath outRes: outputResources) { - Set resSet = resourceMap.get(outRes.getResourceHierarchy()); - if (resSet == null || resSet.size() == 0) { - ResourceNode resNode = addResourceNodes(dataFlowGraph, outRes, dfChannel, resourceMap); - if (resSet == null) { - resSet = new HashSet<>(); - resourceMap.put(outRes.getResourceHierarchy(), resSet); + DataTransferChannel srcDfChannel = (DataTransferChannel)srcChannel; + Set outputResources = srcDfChannel.getOutputResources(); + ChannelNode srcChannelNode = dataFlowGraph.addChannelNode(parentChannelNode, srcDfChannel); + for (ResourcePath dstRes: outputResources) { + Set dstResSet = resourceMap.get(dstRes.getResourceHierarchy()); // ResourceNodes that have the same ResourceHierarchy. + if (dstResSet == null || dstResSet.size() == 0) { + ResourceNode dstResNode = addResourceNodes(dataFlowGraph, dstRes, srcDfChannel, resourceMap); + if (dstResSet == null) { + dstResSet = new HashSet<>(); + resourceMap.put(dstRes.getResourceHierarchy(), dstResSet); } - resSet.add(resNode); + dstResSet.add(dstResNode); } - for (ResourceNode resNode: resSet) { - resNode.addInSideResource(dfChannel, outRes); - dataFlowGraph.addEdge(channelNode, resNode); + for (ResourceNode dstResNode: dstResSet) { + dstResNode.addInSideResource(srcDfChannel, dstRes); + dataFlowGraph.addEdge(srcChannelNode, dstResNode); // Connect to each ResourceNode that has the same ResourceHierarchy. } } - for (Channel childChannel: dfChannel.getChildren()) { - addChannelToResourceEdges(dataFlowGraph, childChannel, channelNode, resourceMap); + for (Channel childChannel: srcDfChannel.getChildren()) { + addChannelToResourceEdges(dataFlowGraph, childChannel, srcChannelNode, resourceMap); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java index 4d33ec8..438a8c1 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java @@ -2,16 +2,20 @@ import java.util.AbstractMap; import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import models.Node; +import models.algebra.Expression; import models.algebra.Type; import models.dataConstraintModel.ResourceHierarchy; import models.dataConstraintModel.ResourcePath; +import models.dataConstraintModel.Selector; public class ResourceNode extends Node { protected ResourceNode parent = null; @@ -19,6 +23,7 @@ protected ResourceHierarchy resourceHierarchy = null; protected Map inSide = null; protected Map.Entry outSide = null; + protected List selectors = null; public ResourceNode(ResourceNode parent, DataTransferChannel outSideChannel, @@ -28,6 +33,15 @@ this.inSide = new HashMap<>(); this.outSide = new AbstractMap.SimpleEntry<>(outSideChannel, outSideResource); this.resourceHierarchy = outSideResource.getResourceHierarchy(); + this.selectors = new ArrayList<>(); + if (resourceHierarchy.getNumParameters() > 0) { + if (outSideChannel != null) { + selectors.addAll(outSideChannel.getSelectors()); + } else { + List pathParams = outSideResource.getPathParams(); + selectors.add(new Selector(pathParams.get(pathParams.size() - 1))); + } + } } public ResourceNode(ResourceNode parent, @@ -38,6 +52,17 @@ this.inSide = inSide; this.outSide = outSide; this.resourceHierarchy = outSide.getValue().getResourceHierarchy(); + this.selectors = new ArrayList<>(); + DataTransferChannel outSideChannel = outSide.getKey(); + ResourcePath outSideResource = outSide.getValue(); + if (resourceHierarchy.getNumParameters() > 0) { + if (outSideChannel != null) { + selectors.addAll(outSideChannel.getSelectors()); + } else { + List pathParams = outSideResource.getPathParams(); + selectors.add(new Selector(pathParams.get(pathParams.size() - 1))); + } + } } public ResourceHierarchy getResourceHierarchy() { @@ -92,6 +117,19 @@ public void setOutSideResource(DataTransferChannel channel, ResourcePath outResource) { outSide = new AbstractMap.SimpleEntry<>(channel, outResource); } + + public List getSelectors() { + return selectors; + } + + public List getAllSelectors() { + List selectors = new ArrayList<>(); + if (parent != null) { + selectors.addAll(parent.getAllSelectors()); + } + selectors.addAll(this.selectors); + return selectors; + } // public boolean equals(Object another) { // if (this == another) return true;