diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index d947583..3ea8a48 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -381,12 +381,12 @@ for (ResourceNode resNode: dataFlowGraph.getRootResourceNodes()) { int w = 80; int h = 30; - ResourcePath res = resNode.getOutSideResources().iterator().next(); + ResourcePath res = resNode.getPrimaryResourcePath(); Object resource = graph.insertVertex(parent, null, res.getResourceName(), 20, 20, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex resources.put(resNode, resource); - getChildResource(resource, resNode, resources, w, h); + createChildResourceVerticies(resource, resNode, resources, w, h); } // create channel vertices @@ -426,7 +426,7 @@ } else { // I/O channel if (channelsOut.get(channel) == null) { - if(channel.getSelectors().toString() == "[]") { + if (channel.getSelectors().toString() == "[]") { Object chCell = graph.insertVertex(parent, null, channel.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); port_in.setVertex(true); @@ -436,8 +436,7 @@ graph.addCell(port_out, chCell); // insert the output port of a channel channelsIn.put(channel, port_in); channelsOut.put(channel, port_out); - }else { - + } else { for (Selector s: channel.getSelectors()) { Expression exp = s.getExpression(); String selName = exp.toString(); @@ -464,7 +463,7 @@ if (dfEdge.isChannelToResource()) { // output edge DataTransferChannel channel = ((ChannelNode) dfEdge.getSource()).getChannel(); - ResourcePath dstRes = ((ResourceNode) dfEdge.getDestination()).getOutSideResource(channel); + ResourcePath dstRes = ((ResourceNode) dfEdge.getDestination()).getInSideResource(channel); graph.insertEdge(parent, null, new SrcDstAttribute(channel, dstRes), channelsOut.get(channel), resources.get((ResourceNode) dfEdge.getDestination()), "movable=false"); } else { // input edge @@ -497,15 +496,15 @@ return graph; } - public void getChildResource(Object resource, ResourceNode resNode, Map resources, int w, int h) { + public void createChildResourceVerticies(Object resource, ResourceNode resNode, Map resources, int w, int h) { - for (ResourceNode c: resNode.getChildren()) { - ResourcePath chRes = c.getOutSideResources().iterator().next(); - Object chResource = graph.insertVertex(resource, null, - chRes.getName(), 0, 0, w, h, + for (ResourceNode childNode: resNode.getChildren()) { + ResourcePath childRes = childNode.getPrimaryResourcePath(); + Object childResource = graph.insertVertex(resource, null, + childRes.getName(), 0, 0, w, h, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex - resources.put(c, chResource); - getChildResource(chResource, c, resources, w, h); + resources.put(childNode, childResource); + createChildResourceVerticies(childResource, childNode, resources, w, h); } } @@ -536,7 +535,7 @@ mxCell edgeCell = (mxCell) edge; if (edgeCell.getValue() instanceof SrcDstAttribute) { SrcDstAttribute edgeAttr = (SrcDstAttribute) edgeCell.getValue(); - if (srcRes.getOutSideResources().iterator().next().equals(edgeAttr.getSource()) && channel.equals(edgeAttr.getDestination())) { + if (srcRes.getPrimaryResourcePath().equals(edgeAttr.getSource()) && channel.equals(edgeAttr.getDestination())) { edgeCell.setValue(dataFlow.getAttribute()); break; } @@ -794,6 +793,9 @@ if (srcNode != null) { for (ChannelMember dstMem: dependency.get(srcMem).getValue()) { ResourceNode dstNode = dataFlowGraph.getResourceNode(dstMem.getResource()); + while (srcNode.getResourceHierarchy().getNumParameters() == 0 && srcNode.getParent() != null) { + srcNode = srcNode.getParent(); + } resourceDpendency.add(new AbstractMap.SimpleEntry<>(srcNode, dstNode)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 38d2d79..cd3f385 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -392,7 +392,7 @@ protected void declareAccessorInMainComponent(TypeDeclaration mainComponent, ResourceNode accessRes, MethodDeclaration stateGetter, ILanguageSpecific langSpec) { List mainGetterParams = new ArrayList<>(); int v = 1; - for (Expression param: accessRes.getOutSideResources().iterator().next().getPathParams()) { + for (Expression param: accessRes.getPrimaryResourcePath().getPathParams()) { if (param instanceof Variable) { Variable var = (Variable) param; mainGetterParams.add(langSpec.newVariableDeclaration(var.getType(), var.getName())); @@ -409,7 +409,7 @@ accessor = langSpec.newMethodDeclaration(getterPrefix + getComponentName(accessRes.getResourceHierarchy(), langSpec), false, getImplStateType(accessRes.getResourceHierarchy(), langSpec), mainGetterParams); } Block block = new Block(); - Expression getState = getPullAccessor().getDirectStateAccessorFor(accessRes.getOutSideResources().iterator().next(), null); + Expression getState = getPullAccessor().getDirectStateAccessorFor(accessRes.getPrimaryResourcePath(), null); block.addStatement(langSpec.getReturnStatement(getState.toImplementation(new String[] {null})) + langSpec.getStatementDelimiter()); // if (stateGetter.getParameters() == null || stateGetter.getParameters().size() == 0) { // block.addStatement(langSpec.getReturnStatement(langSpec.getMethodInvocation(accessRes.getResourceName(), stateGetter.getName())) + langSpec.getStatementDelimiter()); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java index f573160..9c48e28 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java @@ -984,7 +984,7 @@ MethodDeclaration getterAccessor = null; List mainGetterParams = new ArrayList<>(); int v = 1; - for (Expression param: resourceNode.getOutSideResources().iterator().next().getPathParams()) { + for (Expression param: resourceNode.getPrimaryResourcePath().getPathParams()) { if (param instanceof Variable) { Variable var = (Variable) param; mainGetterParams.add(new VariableDeclaration(var.getType(), var.getName())); @@ -1004,7 +1004,7 @@ getImplStateType(resourceNode.getResourceHierarchy())); } getterAccessor.setBody(new Block()); - Expression getState = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(resourceNode.getOutSideResources().iterator().next(), null); + Expression getState = JavaCodeGenerator.pullAccessor.getDirectStateAccessorFor(resourceNode.getPrimaryResourcePath(), null); getterAccessor.getBody().addStatement("return " + getState.toImplementation(new String[] {null}) + ";"); mainComponent.addMethod(getterAccessor); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index 82dcfb1..14c631a 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -228,7 +228,7 @@ children.add(child.getResourceHierarchy()); List pathParams = new ArrayList<>(); int v = 1; - for (Expression pathParam: child.getOutSideResources().iterator().next().getPathParams()) { + for (Expression pathParam: child.getPrimaryResourcePath().getPathParams()) { if (pathParam instanceof Variable) { Variable var = (Variable) pathParam; pathParams.add(new VariableDeclaration(var.getType(), var.getName())); @@ -413,7 +413,7 @@ // For a non-root resource MethodDeclaration getterAccessor = null; List mainGetterParams = new ArrayList<>(); - String resourcePath = getGetterResourcePathAndPathParams(resourceNode.getOutSideResources().iterator().next(), mainGetterParams); + String resourcePath = getGetterResourcePathAndPathParams(resourceNode.getPrimaryResourcePath(), mainGetterParams); if (resourcePath.indexOf('/') > 0) { resourcePath = resourcePath.substring(resourcePath.indexOf('/')); } else { @@ -429,7 +429,7 @@ getImplStateType(resourceNode.getResourceHierarchy())); } getterAccessor.setBody(new Block()); - ResourcePath resPath = resourceNode.getOutSideResources().iterator().next(); + ResourcePath resPath = resourceNode.getPrimaryResourcePath(); Expression getState = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(resPath, resPath.getRoot()); getterAccessor.getBody().addStatement("return " + getState.toImplementation(new String[] {null}) + ";"); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java index 623657f..a86dc97 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java @@ -15,7 +15,7 @@ protected Set rootResourceNodes = null; protected Set rootChannelNodes = null; protected Map channelNodeMap = null; - protected Map resourceNodeMap = null; + protected Map resourceNodeMap = null; public DataFlowGraph() { super(); @@ -41,7 +41,7 @@ } } else { // a channel local resource node - node = resourceNodeMap.get(outSideResource); + node = resourceNodeMap.get(System.identityHashCode(outSideResource)); } if (node != null) return node; node = new ResourceNode(parent, outSideResource, outSideChannel); @@ -51,7 +51,7 @@ } else { parent.addChild(node); } - resourceNodeMap.put(outSideResource, node); + resourceNodeMap.put(System.identityHashCode(outSideResource), node); return node; } @@ -67,17 +67,17 @@ } } else { // a channel local terminal resource node - node = resourceNodeMap.get(inSideResource); + node = resourceNodeMap.get(System.identityHashCode(inSideResource)); } if (node != null) return node; - node = new ResourceNode(parent, inSideChannel, inSideResource); + node = new ResourceNode(parent, inSideResource, inSideChannel, true); addNode(node); if (parent == null) { rootResourceNodes.add(node); } else { parent.addChild(node); } - resourceNodeMap.put(inSideResource, node); + resourceNodeMap.put(System.identityHashCode(inSideResource), node); return node; } @@ -86,11 +86,11 @@ Map outSide) { ResourceNode node = null; for (ResourcePath outRes: outSide.values()) { - node = resourceNodeMap.get(outRes); + node = resourceNodeMap.get(System.identityHashCode(outRes)); if (node != null) return node; } for (ResourcePath inRes: inSide.values()) { - node = resourceNodeMap.get(inRes); + node = resourceNodeMap.get(System.identityHashCode(inRes)); if (node != null) return node; } node = new ResourceNode(parent, inSide, outSide); @@ -101,10 +101,10 @@ parent.addChild(node); } for (ResourcePath outRes: outSide.values()) { - resourceNodeMap.put(outRes, node); + resourceNodeMap.put(System.identityHashCode(outRes), node); } for (ResourcePath inRes: inSide.values()) { - resourceNodeMap.put(inRes, node); + resourceNodeMap.put(System.identityHashCode(inRes), node); } return node; } @@ -124,7 +124,7 @@ } public ResourceNode getResourceNode(ResourcePath resPath) { - return resourceNodeMap.get(resPath); + return resourceNodeMap.get(System.identityHashCode(resPath)); } public ChannelNode getChannelNode(DataTransferChannel channel) { @@ -138,9 +138,9 @@ public Collection getResourceNodes(ResourceHierarchy resourceHierarchy) { Collection resourceNodes = new ArrayList<>(); - for (ResourcePath rp: resourceNodeMap.keySet()) { - if (rp.getResourceHierarchy() == resourceHierarchy) { - resourceNodes.add(resourceNodeMap.get(rp)); + for (ResourceNode rn: resourceNodeMap.values()) { + if (rn.getResourceHierarchy() == resourceHierarchy) { + resourceNodes.add(rn); } } return resourceNodes; diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java index 6ed6e56..e851d06 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java @@ -120,15 +120,6 @@ if (chToLocalDstNodes != null) { for (Channel dstCh: chToLocalDstNodes.keySet()) { for (ResourceNode localParentNode: chToLocalDstNodes.get(dstCh)) { -// for (ResourcePath localParentPath: localParentNode.getOutSideResources()) { -// if (localParentPath.toString().equals(dstParent.toString())) { -// // There already has been a common channel-local ancestor. -// ResourceNode dstResNode = addResourceNodes(dataFlowGraph, dstRes, (DataTransferChannel)dstCh, channelLocalResMap); -// dstResSet.add(dstResNode); -// break; -// } -// } -// if (dstResSet.size() > 0) break; for (ResourcePath localParentPath: localParentNode.getInSideResources()) { if (localParentPath.toString().equals(dstParent.toString())) { // There already has been a common channel-local ancestor. @@ -182,33 +173,33 @@ } else { // Search an identical parent ResourceNode. ResourceNode parent = null; + DataTransferChannel parentDfChannel = dfChannel; + if (resPath.getResourceHierarchy().getParent().getNumParameters() == 0) { + parentDfChannel = null; + } if (channelLocalResMap.get(resPath.getResourceHierarchy().getParent()) != null) { - Map> chLocalParentResMap = channelLocalResMap.get(resPath.getResourceHierarchy().getParent()); - for (Channel parentDfChannel: chLocalParentResMap.keySet()) { - Set chLocalNodes = chLocalParentResMap.get(parentDfChannel); - if (chLocalNodes != null) { - for (ResourceNode node: chLocalNodes) { - for (ResourcePath r: node.getOutSideResources()) { - if (r.toString().equals(resPath.getParent().toString())) { - parent = node; - break; - } + Set chLocalNodes = channelLocalResMap.get(resPath.getResourceHierarchy().getParent()).get(parentDfChannel); + if (chLocalNodes != null) { + for (ResourceNode node: chLocalNodes) { + for (ResourcePath r: node.getOutSideResources()) { + if (r.toString().equals(resPath.getParent().toString())) { + parent = node; + break; } - if (parent != null) break; - for (ResourcePath r: node.getInSideResources()) { - if (r.toString().equals(resPath.getParent().toString())) { - parent = node; - break; - } - } - if (parent != null) break; } + if (parent != null) break; + for (ResourcePath r: node.getInSideResources()) { + if (r.toString().equals(resPath.getParent().toString())) { + parent = node; + break; + } + } + if (parent != null) break; } - if (parent != null) break; } } if (parent == null) { - parent = addResourceNodes(dataFlowGraph, resPath.getParent(), null, channelLocalResMap, false); + parent = addResourceNodes(dataFlowGraph, resPath.getParent(), parentDfChannel, channelLocalResMap, false); } if (!isTerminal) { resNode = dataFlowGraph.addResourceNode(parent, resPath, dfChannel); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java index 7cb936c..6c2073c 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java @@ -46,28 +46,32 @@ } public ResourceNode(ResourceNode parent, - DataTransferChannel inSideChannel, - ResourcePath inSideResource) { + ResourcePath resource, + DataTransferChannel channel, boolean isInside) { this.parent = parent; this.children = new HashSet<>(); this.inSide = new HashMap<>(); - this.inSide.put(inSideChannel, inSideResource); this.outSide = new HashMap<>(); - this.resourceHierarchy = inSideResource.getResourceHierarchy(); + if (isInside) { + this.inSide.put(channel, resource); + } else { + this.outSide.put(channel, resource); + } + this.resourceHierarchy = resource.getResourceHierarchy(); this.selectors = new ArrayList<>(); if (resourceHierarchy.getNumParameters() > 0) { - if (inSideChannel != null) { - selectors.addAll(inSideChannel.getSelectors()); + if (channel != null) { + selectors.addAll(channel.getSelectors()); } else { - List pathParams = inSideResource.getPathParams(); + List pathParams = resource.getPathParams(); selectors.add(new Selector(pathParams.get(pathParams.size() - 1))); } } } public ResourceNode(ResourceNode parent, - Map inSide, - Map outSide) { + Map outSide, + Map inSide) { this.parent = parent; this.children = new HashSet<>(); this.inSide = inSide; @@ -118,6 +122,11 @@ children.add(child); child.parent = this; } + + public ResourcePath getPrimaryResourcePath() { + if (outSide.size() > 0) return outSide.values().iterator().next(); + return inSide.values().iterator().next(); + } public Collection getInSideResources() { return inSide.values();