diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java b/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java index 07afdf1..836227a 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java @@ -24,22 +24,22 @@ */ static public DataFlowGraph createDataFlowGraphWithStateStoringAttribute(DataTransferModel model) { DataFlowGraph graph = model.getDataFlowGraph(); - Collection channels = new HashSet<>(model.getIOChannelGenerators()); - channels.addAll(model.getChannelGenerators()); - for (ChannelGenerator generator: channels) { - for (ChannelMember member: ((DataTransferChannelGenerator) generator).getOutputChannelMembers()) { + Collection channels = new HashSet<>(model.getIOChannels()); + channels.addAll(model.getChannels()); + for (Channel channel: channels) { + for (ChannelMember member: ((DataTransferChannel) channel).getOutputChannelMembers()) { boolean flag = !member.getStateTransition().isRightUnary(); // The state does not need to be stored if the state transition function is right unary. for (Node node : graph.getNodes()) { - if (((ResourceNode) node).getIdentifierTemplate().equals(member.getIdentifierTemplate())) { + if (((ResourceNode) node).getResource().equals(member.getResource())) { setStoreAttribute(flag, (ResourceNode) node); } } } } for (Node node : graph.getNodes()) { - HashSet inChannels = new HashSet<>(); + HashSet inChannels = new HashSet<>(); for(Edge pre : ((ResourceNode) node).getInEdges()) { - inChannels.add(((DataFlowEdge) pre).getChannelGenerator()); + inChannels.add(((DataFlowEdge) pre).getChannel()); } if ((inChannels.size() > 1)) { setStoreAttribute(true, (ResourceNode) node); diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java index fb48b10..d29070d 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java @@ -19,10 +19,10 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataConstraintModel.StateTransition; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ResourceNode; @@ -84,9 +84,9 @@ } static public void infer(DataTransferModel model) { - Map> resources = new HashMap<>(); + Map> resources = new HashMap<>(); Map variables = new HashMap<>(); - Map, Type>>> messages = new HashMap<>(); + Map, Type>>> messages = new HashMap<>(); Map consOrSet = new HashMap<>(); Map tuple = new HashMap<>(); Map pair = new HashMap<>(); @@ -123,12 +123,12 @@ mapComponentTypes.put(DataConstraintModel.typeMap, Arrays.asList(new Type[] { null, null })); // 1. Collect type information from the architecture model. - Collection channels = new HashSet<>(model.getIOChannelGenerators()); - channels.addAll(model.getChannelGenerators()); - for (ChannelGenerator c : channels) { + Collection channels = new HashSet<>(model.getIOChannels()); + channels.addAll(model.getChannels()); + for (Channel c : channels) { for (ChannelMember cm : c.getChannelMembers()) { StateTransition st = cm.getStateTransition(); - IdentifierTemplate id = cm.getIdentifierTemplate(); + ResourcePath id = cm.getResource(); // 1.1 Group expressions by resources. List sameResource = resources.get(id); @@ -1056,11 +1056,11 @@ } } - private static void updateResourceTypes(Expression exp, Map> resources, + private static void updateResourceTypes(Expression exp, Map> resources, Map> expToResource, Map> updateFromResource) { List sameResource = expToResource.get(System.identityHashCode(exp)); if (sameResource == null) return; - for (IdentifierTemplate id : resources.keySet()) { + for (ResourcePath id : resources.keySet()) { if (resources.get(id) == sameResource) { Type resType = id.getResourceStateType(); Type newResType = getExpTypeIfUpdatable(resType, exp); @@ -1124,13 +1124,13 @@ } private static void updateMessageTypes(Expression exp, - Map, Type>>> messages, + Map, Type>>> messages, Map> expToMessage, Map> updateFromMessage) { List messageExps = expToMessage.get(System.identityHashCode(exp)); if (messageExps == null) return; Type msgType = null; Map.Entry, Type> expsAndType = null; - for (ChannelGenerator c : messages.keySet()) { + for (Channel c : messages.keySet()) { for (int i : messages.get(c).keySet()) { expsAndType = messages.get(c).get(i); if (expsAndType.getKey() == messageExps) { diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java index 28070d2..83acc69 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java @@ -16,7 +16,7 @@ import generators.DataTransferMethodAnalyzer; import generators.JavaCodeGenerator; import generators.JavaMethodBodyGenerator; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ModelExtension; import models.dataFlowModel.DataFlowGraph; @@ -45,7 +45,7 @@ if (fileName == null) fileName = "Main"; String mainTypeName = fileName.split("\\.")[0]; boolean exist = false; - for (IdentifierTemplate id: model.getIdentifierTemplates()) { + for (ResourcePath id: model.getResourcePaths()) { String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); if (mainTypeName.equals(resourceName)) { exist = true; diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java index b74075c..766c384 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java @@ -17,7 +17,7 @@ import generators.JerseyCodeGenerator; import generators.JerseyMethodBodyGenerator; import models.algebra.Type; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ModelExtension; import models.dataFlowModel.DataFlowGraph; @@ -46,7 +46,7 @@ if (fileName == null) fileName = "Main"; String mainTypeName = fileName.split("\\.")[0]; boolean exist = false; - for (IdentifierTemplate id: model.getIdentifierTemplates()) { + for (ResourcePath id: model.getResourcePaths()) { String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); if (mainTypeName.equals(resourceName)) { exist = true; diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java index e8148f5..6ee664c 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java @@ -5,7 +5,7 @@ import javax.swing.JOptionPane; import application.editor.Editor; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; public class NewChannelAction extends AbstractEditorAction { @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) { String channelName = JOptionPane.showInputDialog("Channel Name:"); if (channelName == null) return; - editor.addChannelGenerator(new DataTransferChannelGenerator(channelName)); + editor.addChannel(new DataTransferChannel(channelName)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java index 4eb4afe..068c758 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java @@ -19,7 +19,7 @@ import application.ApplicationWindow; import application.editor.Editor; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; public class NewFormulaChannelAction extends AbstractEditorAction implements ActionListener { @@ -47,16 +47,16 @@ panel.add(symbolText); int r = JOptionPane.showConfirmDialog( - null, // �I�[�i�[�E�B���h�E - panel, // ���b�Z�[�W - "New Formula Channel", // �E�B���h�E�^�C�g�� - JOptionPane.OK_CANCEL_OPTION, // �I�v�V�����i�{�^���̎�ށj - JOptionPane.QUESTION_MESSAGE); // ���b�Z�[�W�^�C�v�i�A�C�R���̎�ށj + null, + panel, + "New Formula Channel", + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); String channelName = channelText.getText(); String symbol = symbolText.getText(); if(r == JOptionPane.OK_OPTION) { - editor.addFormulaChannelGenerator(new FormulaChannelGenerator(channelName, editor.getModel().getSymbol(symbol))); + editor.addFormulaChannel(new FormulaChannel(channelName, editor.getModel().getSymbol(symbol))); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java index 8d819d8..85e48de 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java @@ -5,7 +5,7 @@ import javax.swing.JOptionPane; import application.editor.Editor; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; public class NewIOChannelAction extends AbstractEditorAction { @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) { String channelName = JOptionPane.showInputDialog("I/O Channel Name:"); if (channelName == null) return; - editor.addIOChannelGenerator(new DataTransferChannelGenerator(channelName)); + editor.addIOChannel(new DataTransferChannel(channelName)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java index 5c230f7..50b1512 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java @@ -5,7 +5,7 @@ import javax.swing.JOptionPane; import application.editor.Editor; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class NewResourceAction extends AbstractEditorAction { @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) { String resName = JOptionPane.showInputDialog("Resourece Name:"); if (resName == null) return; - editor.addIdentifierTemplate(new IdentifierTemplate(resName, 0)); + editor.addResourcePath(new ResourcePath(resName, 0)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java index d89a024..b4d81a6 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/DataTransferModelingCellEditor.java @@ -24,10 +24,10 @@ import models.algebra.Expression; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; import parser.Parser; import parser.Parser.TokenStream; import parser.exceptions.ExpectedRightBracket; @@ -65,16 +65,16 @@ if (!graphComponent.getGraph().getModel().isEdge(cell)) { DataTransferModel model = editor.getModel(); - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) model.getChannelGenerator((String) ((mxCell) cell).getValue()); + DataTransferChannel ch = (DataTransferChannel) model.getChannel((String) ((mxCell) cell).getValue()); if (ch == null) { - ch = (DataTransferChannelGenerator) model.getIOChannelGenerator((String) ((mxCell) cell).getValue()); + ch = (DataTransferChannel) model.getIOChannel((String) ((mxCell) cell).getValue()); if(ch == null) { //resource return; } } - if(ch instanceof FormulaChannelGenerator) { + if(ch instanceof FormulaChannel) { JPanel panel = new JPanel(); JLabel label1 = new JLabel("Formula: "); @@ -90,7 +90,7 @@ gbc.gridx = 1; gbc.gridy = 0; - JTextField formulaText = new JTextField(((FormulaChannelGenerator) ch).getFormula(),15); + JTextField formulaText = new JTextField(((FormulaChannel) ch).getFormula(),15); layout.setConstraints(formulaText, gbc); panel.add(formulaText); @@ -121,8 +121,8 @@ try { Expression exp = parser.parseTerm(stream, editor.getModel()); - ((FormulaChannelGenerator) ch).setFormula(formula); - ((FormulaChannelGenerator) ch).setFormulaTerm(exp); + ((FormulaChannel) ch).setFormula(formula); + ((FormulaChannel) ch).setFormulaTerm(exp); } catch (ExpectedRightBracket e) { e.printStackTrace(); } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index bf9467a..b285ce0 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -35,16 +35,16 @@ import models.Edge; import models.EdgeAttribute; import models.Node; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.ResourceNode; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; import parser.Parser; import parser.Parser.TokenStream; import parser.exceptions.ExpectedAssignment; @@ -294,21 +294,21 @@ int w = (int) state.getWidth(); int h = (int) state.getHeight(); - for(ChannelGenerator ch: model.getChannelGenerators()) { - if(ch instanceof FormulaChannelGenerator && state.getLabel().equals(ch.getChannelName())) { + for(Channel ch: model.getChannels()) { + if(ch instanceof FormulaChannel && state.getLabel().equals(ch.getChannelName())) { fileString += "\tnode fc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; - } else if(ch instanceof ChannelGenerator && state.getLabel().equals(ch.getChannelName())) { + } else if(ch instanceof Channel && state.getLabel().equals(ch.getChannelName())) { fileString +="\tnode c " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; } } - for (IdentifierTemplate res: model.getIdentifierTemplates()){ - if(res instanceof IdentifierTemplate && state.getLabel().equals(res.getResourceName())) + for (ResourcePath res: model.getResourcePaths()){ + if(res instanceof ResourcePath && state.getLabel().equals(res.getResourceName())) fileString += "\tnode r " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; } - for (ChannelGenerator ioC: model.getIOChannelGenerators()) { - if(ioC instanceof ChannelGenerator && state.getLabel().equals(ioC.getChannelName())) { + for (Channel ioC: model.getIOChannels()) { + if(ioC instanceof Channel && state.getLabel().equals(ioC.getChannelName())) { fileString += "\tnode ioc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; } } @@ -338,13 +338,13 @@ geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); geo2.setRelative(true); - Map channelsIn = new HashMap<>(); - Map channelsOut = new HashMap<>(); - Map resources = new HashMap<>(); + Map channelsIn = new HashMap<>(); + Map channelsOut = new HashMap<>(); + Map resources = new HashMap<>(); // create channel vertices - for (ChannelGenerator c: model.getChannelGenerators()) { - DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) c; + for (Channel c: model.getChannels()) { + DataTransferChannel channelGen = (DataTransferChannel) c; if (channelsIn.get(channelGen) == null || channelsOut.get(channelGen) == null) { Object channel = graph.insertVertex(parent, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); @@ -359,7 +359,7 @@ } // create resource vertices - for (IdentifierTemplate res: model.getIdentifierTemplates()) { + for (ResourcePath res: model.getResourcePaths()) { Object resource = graph.insertVertex(parent, null, res.getResourceName(), 20, 20, 80, 30, "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex @@ -367,30 +367,30 @@ } // add input, output and reference edges - for (ChannelGenerator ch: model.getChannelGenerators()) { - DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) ch; + for (Channel ch: model.getChannels()) { + DataTransferChannel channelGen = (DataTransferChannel) ch; // input edge - for (IdentifierTemplate srcRes: channelGen.getInputIdentifierTemplates()) { + for (ResourcePath srcRes: channelGen.getInputResources()) { graph.insertEdge(parent, null, new SrcDstAttribute(srcRes, channelGen), resources.get(srcRes), channelsIn.get(channelGen), "movable=false"); } // output edge - for (IdentifierTemplate dstRes: channelGen.getOutputIdentifierTemplates()) { + for (ResourcePath dstRes: channelGen.getOutputResources()) { graph.insertEdge(parent, null, new SrcDstAttribute(channelGen, dstRes), channelsOut.get(channelGen), resources.get(dstRes), "movable=false"); } // reference edges - for (IdentifierTemplate refRes: channelGen.getReferenceIdentifierTemplates()) { + for (ResourcePath refRes: channelGen.getReferenceResources()) { graph.insertEdge(parent, null, null, resources.get(refRes), channelsIn.get(channelGen), "dashed=true;movable=false"); } } - for (ChannelGenerator ioChannelGen: model.getIOChannelGenerators()) { + for (Channel ioChannelGen: model.getIOChannels()) { if (channelsOut.get(ioChannelGen) == null) { Object channel = graph.insertVertex(parent, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); graph.addCell(port_out, channel); // insert the output port of a channel - channelsOut.put((DataTransferChannelGenerator) ioChannelGen, port_out); - for (IdentifierTemplate outRes: ((DataTransferChannelGenerator) ioChannelGen).getOutputIdentifierTemplates()) { + channelsOut.put((DataTransferChannel) ioChannelGen, port_out); + for (ResourcePath outRes: ((DataTransferChannel) ioChannelGen).getOutputResources()) { graph.insertEdge(parent, null, null, port_out, resources.get(outRes), "movable=false"); } } @@ -422,14 +422,14 @@ for (Edge e : dataFlowGraph.getEdges()) { if (e instanceof DataFlowEdge) { DataFlowEdge dataFlow = (DataFlowEdge) e; - DataTransferChannelGenerator channelGen = dataFlow.getChannelGenerator(); + DataTransferChannel channelGen = dataFlow.getChannel(); ResourceNode srcRes = (ResourceNode) dataFlow.getSource(); // input edge for (Object edge: graph.getChildEdges(parent)) { mxCell edgeCell = (mxCell) edge; if (edgeCell.getValue() instanceof SrcDstAttribute) { SrcDstAttribute edgeAttr = (SrcDstAttribute) edgeCell.getValue(); - if (edgeAttr.getSrouce() == srcRes.getIdentifierTemplate() && edgeAttr.getDestination() == channelGen) { + if (edgeAttr.getSrouce() == srcRes.getResource() && edgeAttr.getDestination() == channelGen) { edgeCell.setValue(dataFlow.getAttribute()); break; } @@ -468,8 +468,8 @@ } } - public void addIdentifierTemplate(IdentifierTemplate res) { - getModel().addIdentifierTemplate(res); + public void addResourcePath(ResourcePath res) { + getModel().addResourcePath(res); resetDataFlowGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); @@ -481,8 +481,8 @@ } } - public void addChannelGenerator(DataTransferChannelGenerator channelGen) { - getModel().addChannelGenerator(channelGen); + public void addChannel(DataTransferChannel channelGen) { + getModel().addChannel(channelGen); resetDataFlowGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); @@ -507,8 +507,8 @@ } } - public void addIOChannelGenerator(DataTransferChannelGenerator ioChannelGen) { - getModel().addIOChannelGenerator(ioChannelGen); + public void addIOChannel(DataTransferChannel ioChannelGen) { + getModel().addIOChannel(ioChannelGen); resetDataFlowGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); @@ -526,8 +526,8 @@ } } - public void addFormulaChannelGenerator(FormulaChannelGenerator formulaChannelGen) { - getModel().addChannelGenerator(formulaChannelGen); + public void addFormulaChannel(FormulaChannel formulaChannelGen) { + getModel().addChannel(formulaChannelGen); resetDataFlowGraph(); graph.getModel().beginUpdate(); Object parent = graph.getDefaultParent(); @@ -554,26 +554,26 @@ public boolean connectEdge(mxCell edge, mxCell src, mxCell dst) { DataTransferModel model = getModel(); - ChannelGenerator srcCh = model.getChannelGenerator((String) src.getValue()); + Channel srcCh = model.getChannel((String) src.getValue()); if (srcCh == null) { - srcCh = model.getIOChannelGenerator((String) src.getValue()); + srcCh = model.getIOChannel((String) src.getValue()); if (srcCh == null) { - IdentifierTemplate srcRes = model.getIdentifierTemplate((String) src.getValue()); - ChannelGenerator dstCh = model.getChannelGenerator((String) dst.getValue()); + ResourcePath srcRes = model.getResourcePath((String) src.getValue()); + Channel dstCh = model.getChannel((String) dst.getValue()); if (srcRes == null || dstCh == null) return false; // resource to channel edge ChannelMember srcCm = new ChannelMember(srcRes); - ((DataTransferChannelGenerator ) dstCh).addChannelMemberAsInput(srcCm); + ((DataTransferChannel ) dstCh).addChannelMemberAsInput(srcCm); edge.setValue(new SrcDstAttribute(srcRes, dstCh)); resetDataFlowGraph(); return true; } } - IdentifierTemplate dstRes = model.getIdentifierTemplate((String) dst.getValue()); + ResourcePath dstRes = model.getResourcePath((String) dst.getValue()); if (dstRes == null) return false; // channel to resource edge ChannelMember dstCm = new ChannelMember(dstRes); - ((DataTransferChannelGenerator) srcCh).addChannelMemberAsOutput(dstCm); + ((DataTransferChannel) srcCh).addChannelMemberAsOutput(dstCm); edge.setValue(new SrcDstAttribute(srcCh, dstRes)); resetDataFlowGraph(); return true; @@ -585,26 +585,26 @@ if (cell.isEdge()) { String srcName = (String) cell.getSource().getValue(); String dstName = (String) cell.getTarget().getValue(); - if (model.getIdentifierTemplate(srcName) != null) { + if (model.getResourcePath(srcName) != null) { // resource to channel edge - ChannelGenerator ch = model.getChannelGenerator(dstName); - ch.removeChannelMember(model.getIdentifierTemplate(srcName)); - } else if (model.getIdentifierTemplate(dstName) != null) { + Channel ch = model.getChannel(dstName); + ch.removeChannelMember(model.getResourcePath(srcName)); + } else if (model.getResourcePath(dstName) != null) { // channel to resource edge - ChannelGenerator ch = model.getChannelGenerator(srcName); + Channel ch = model.getChannel(srcName); if (ch == null) { - ch = model.getIOChannelGenerator(srcName); + ch = model.getIOChannel(srcName); } - ch.removeChannelMember(model.getIdentifierTemplate(dstName)); + ch.removeChannelMember(model.getResourcePath(dstName)); } } else if (cell.isVertex()) { String name = (String) cell.getValue(); - if (model.getChannelGenerator(name) != null) { - model.removeChannelGenerator(name); - } else if (model.getIOChannelGenerator(name) != null) { - model.removeIOChannelGenerator(name); - } else if (model.getIdentifierTemplate(name) != null) { - model.removeIdentifierTemplate(name); + if (model.getChannel(name) != null) { + model.removeChannel(name); + } else if (model.getIOChannel(name) != null) { + model.removeIOChannel(name); + } else if (model.getResourcePath(name) != null) { + model.removeResourcePath(name); } } } @@ -612,7 +612,7 @@ resetDataFlowGraph(); } - public void setChannelCode(DataTransferChannelGenerator ch, String code) { + public void setChannelCode(DataTransferChannel ch, String code) { ch.setSourceText(code); TokenStream stream = new Parser.TokenStream(); Parser parser = new Parser(stream); @@ -621,10 +621,10 @@ stream.addLine(line); } try { - DataTransferChannelGenerator ch2 = parser.parseChannel(getModel()); + DataTransferChannel ch2 = parser.parseChannel(getModel()); for (ChannelMember chm2: ch2.getInputChannelMembers()) { for (ChannelMember chm: ch.getInputChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + if (chm2.getResource() == chm.getResource()) { chm.setStateTransition(chm2.getStateTransition()); break; } @@ -632,7 +632,7 @@ } for (ChannelMember chm2: ch2.getOutputChannelMembers()) { for (ChannelMember chm: ch.getOutputChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + if (chm2.getResource() == chm.getResource()) { chm.setStateTransition(chm2.getStateTransition()); break; } @@ -640,7 +640,7 @@ } for (ChannelMember chm2: ch2.getReferenceChannelMembers()) { for (ChannelMember chm: ch.getReferenceChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + if (chm2.getResource() == chm.getResource()) { chm.setStateTransition(chm2.getStateTransition()); break; } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java index 74ed6a8..314e81a 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java @@ -23,13 +23,13 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.DataFlowEdge; @@ -76,16 +76,16 @@ // For each resource. for (ResourceNode rn: resources) { boolean f = false; - String resourceName = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() - + rn.getIdentifierTemplate().getResourceName().substring(1); + String resourceName = rn.getResource().getResourceName().substring(0, 1).toUpperCase() + + rn.getResource().getResourceName().substring(1); TypeDeclaration type = new TypeDeclaration(resourceName); // Declare the field to refer to each resource in the main type. String fieldInitializer = "new " + resourceName + "("; - Set depends = new HashSet<>(); + Set depends = new HashSet<>(); for (Edge e : rn.getOutEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate dstRes = ((ResourceNode) re.getDestination()).getIdentifierTemplate(); + ResourcePath dstRes = ((ResourceNode) re.getDestination()).getResource(); String resName = dstRes.getResourceName().substring(0, 1).toUpperCase() + dstRes.getResourceName().substring(1); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { depends.add(dstRes); @@ -95,7 +95,7 @@ } for (Edge e : rn.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String resName = srcRes.getResourceName().substring(0, 1).toUpperCase() + srcRes.getResourceName().substring(1); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { depends.add(srcRes); @@ -104,17 +104,17 @@ } else { if (rn.getIndegree() > 1) { // Declare a field to cash the state of the source resource in the type of the destination resource. - IdentifierTemplate cashResId = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath cashResId = ((ResourceNode) re.getSource()).getResource(); type.addField(new FieldDeclaration( - cashResId.getResourceStateType(), ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName(), getInitializer(cashResId))); + cashResId.getResourceStateType(), ((ResourceNode) re.getSource()).getResource().getResourceName(), getInitializer(cashResId))); } } } - Set refs = new HashSet<>(); - for (ChannelGenerator cg : model.getChannelGenerators()) { - DataTransferChannelGenerator c = (DataTransferChannelGenerator) cg; - if (c.getInputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { - for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + Set refs = new HashSet<>(); + for (Channel cg : model.getChannels()) { + DataTransferChannel c = (DataTransferChannel) cg; + if (c.getInputResources().contains(rn.getResource())) { + for (ResourcePath id: c.getReferenceResources()) { if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); @@ -126,14 +126,14 @@ } if (f) fieldInitializer = fieldInitializer.substring(0, fieldInitializer.length() - 1); fieldInitializer += ")"; - FieldDeclaration field = new FieldDeclaration(new Type(resourceName, resourceName), rn.getIdentifierTemplate().getResourceName()); + FieldDeclaration field = new FieldDeclaration(new Type(resourceName, resourceName), rn.getResource().getResourceName()); mainType.addField(field); Block manConstructorBody = mainConstructor.getBody(); if (manConstructorBody == null) { manConstructorBody = new Block(); mainConstructor.setBody(manConstructorBody); } - manConstructorBody.addStatement(rn.getIdentifierTemplate().getResourceName() + " = " + fieldInitializer + ";"); + manConstructorBody.addStatement(rn.getResource().getResourceName() + " = " + fieldInitializer + ";"); // Declare a constructor, fields and update methods in the type of each resource. MethodDeclaration constructor = new MethodDeclaration(resourceName, true); @@ -141,7 +141,7 @@ depends = new HashSet<>(); for (Edge e : rn.getOutEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate dstRes = ((ResourceNode) re.getDestination()).getIdentifierTemplate(); + ResourcePath dstRes = ((ResourceNode) re.getDestination()).getResource(); String dstResName = dstRes.getResourceName().substring(0, 1).toUpperCase() + dstRes.getResourceName().substring(1); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // Declare a field to refer to the destination resource of push transfer. @@ -153,7 +153,7 @@ } for (Edge e : rn.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String srcResName = srcRes.getResourceName().substring(0, 1).toUpperCase() + srcRes.getResourceName().substring(1); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { // Declare a field to refer to the source resource of pull transfer. @@ -165,9 +165,9 @@ // Declare an update method in the type of the destination resource. ArrayList vars = new ArrayList<>(); vars.add(new VariableDeclaration(srcRes.getResourceStateType(), srcRes.getResourceName())); - DataTransferChannelGenerator c = (DataTransferChannelGenerator) re.getChannelGenerator(); - for (IdentifierTemplate ref: c.getReferenceIdentifierTemplates()) { - if (ref != rn.getIdentifierTemplate()) { + DataTransferChannel c = (DataTransferChannel) re.getChannel(); + for (ResourcePath ref: c.getReferenceResources()) { + if (ref != rn.getResource()) { vars.add(new VariableDeclaration(ref.getResourceStateType(), ref.getResourceName())); } } @@ -176,10 +176,10 @@ } // Declare a field to refer to the reference resource. refs = new HashSet<>(); - for (ChannelGenerator cg : model.getChannelGenerators()) { - DataTransferChannelGenerator c = (DataTransferChannelGenerator) cg; - if (c.getInputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { - for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + for (Channel cg : model.getChannels()) { + DataTransferChannel c = (DataTransferChannel) cg; + if (c.getInputResources().contains(rn.getResource())) { + for (ResourcePath id: c.getReferenceResources()) { if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); @@ -196,9 +196,9 @@ type.addMethod(constructor); // Declare input methods in resources and the main type. - for (ChannelGenerator cg : model.getIOChannelGenerators()) { - for (ChannelMember cm : ((DataTransferChannelGenerator) cg).getOutputChannelMembers()) { - if (cm.getIdentifierTemplate().equals(rn.getIdentifierTemplate())) { + for (Channel cg : model.getIOChannels()) { + for (ChannelMember cm : ((DataTransferChannel) cg).getOutputChannelMembers()) { + if (cm.getResource().equals(rn.getResource())) { Expression message = cm.getStateTransition().getMessageExpression(); if (message.getClass() == Term.class) { ArrayList params = new ArrayList<>(); @@ -244,13 +244,13 @@ // Declare the field to store the state in the type of each resource. if (((StoreAttribute) rn.getAttribute()).isStored()) { - IdentifierTemplate resId = rn.getIdentifierTemplate(); + ResourcePath resId = rn.getResource(); type.addField(new FieldDeclaration(resId.getResourceStateType(), "value", getInitializer(resId))); } // Declare the getter method to obtain the state in the type of each resource. type.addMethod(new MethodDeclaration("getValue", - rn.getIdentifierTemplate().getResourceStateType())); + rn.getResource().getResourceStateType())); // Add compilation unit for each resource. CompilationUnit cu = new CompilationUnit(type); @@ -262,7 +262,7 @@ boolean isCreatedPair = false; for(ResourceNode rn : resources) { if(isCreatedPair) continue; - if(model.getType("Pair").isAncestorOf(rn.getIdentifierTemplate().getResourceStateType())) { + if(model.getType("Pair").isAncestorOf(rn.getResource().getResourceStateType())) { TypeDeclaration type = new TypeDeclaration("Pair"); type.addField(new FieldDeclaration(new Type("Double", "T"), "left")); type.addField(new FieldDeclaration(new Type("Double", "T"), "right")); @@ -297,12 +297,12 @@ for (Node n : graph.getNodes()) { ResourceNode rn = (ResourceNode) n; MethodDeclaration getter = new MethodDeclaration( - "get" + rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() - + rn.getIdentifierTemplate().getResourceName().substring(1), - rn.getIdentifierTemplate().getResourceStateType()); + "get" + rn.getResource().getResourceName().substring(0, 1).toUpperCase() + + rn.getResource().getResourceName().substring(1), + rn.getResource().getResourceStateType()); getter.setBody(new Block()); getter.getBody().addStatement( - "return " + rn.getIdentifierTemplate().getResourceName() + ".getValue();"); + "return " + rn.getResource().getResourceName() + ".getValue();"); mainType.addMethod(getter); } @@ -324,7 +324,7 @@ return codes; } - private static String getInitializer(IdentifierTemplate resId) { + private static String getInitializer(ResourcePath resId) { Type stateType = resId.getResourceStateType(); String initializer = null; if (resId.getInitialValue() != null) { @@ -413,8 +413,8 @@ ResourceNode rn = (ResourceNode) n; for (Edge e : rn.getOutEdges()) { DataFlowEdge re = (DataFlowEdge) e; - for (ChannelMember m: re.getChannelGenerator().getReferenceChannelMembers()) { - if (m.getIdentifierTemplate() == curNode.getIdentifierTemplate()) { + for (ChannelMember m: re.getChannel().getReferenceChannelMembers()) { + if (m.getResource() == curNode.getResource()) { topologicalSort(graph, rn, visited, orderedList); } } @@ -432,7 +432,7 @@ static public IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -445,7 +445,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); @@ -453,7 +453,7 @@ }; static public IResourceStateAccessor pullAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -466,7 +466,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { Term getter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); getter.addChild(new Field(target.getResourceName(), target.getResourceStateType())); return getter; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index ec17706..86cd28a 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -21,13 +21,13 @@ import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; @@ -48,24 +48,24 @@ // Generate the body of each update or getter method. try { - Map> referredResources = new HashMap<>(); + Map> referredResources = new HashMap<>(); for (Edge e: graph.getEdges()) { DataFlowEdge d = (DataFlowEdge) e; PushPullAttribute pushPull = (PushPullAttribute) d.getAttribute(); ResourceNode src = (ResourceNode) d.getSource(); ResourceNode dst = (ResourceNode) d.getDestination(); - String srcResourceName = src.getIdentifierTemplate().getResourceName(); - String dstResourceName = dst.getIdentifierTemplate().getResourceName(); + String srcResourceName = src.getResource().getResourceName(); + String dstResourceName = dst.getResource().getResourceName(); TypeDeclaration srcType = typeMap.get(srcResourceName); TypeDeclaration dstType = typeMap.get(dstResourceName); - for (ChannelMember out: d.getChannelGenerator().getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == dst.getIdentifierTemplate()) { + for (ChannelMember out: d.getChannel().getOutputChannelMembers()) { + if (out.getResource() == dst.getResource()) { if (pushPull.getOptions().get(0) == PushPullValue.PUSH && srcType != null) { // for push data transfer MethodDeclaration update = getUpdateMethod(dstType, srcType); if (((StoreAttribute) dst.getAttribute()).isStored()) { // update stored state of dst side resource (when every incoming edge is in push style) - Expression updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, JavaCodeGenerator.pushAccessor); + Expression updateExp = d.getChannel().deriveUpdateExpressionOf(out, JavaCodeGenerator.pushAccessor); String[] sideEffects = new String[] {""}; String curState = updateExp.toImplementation(sideEffects); String updateStatement; @@ -89,7 +89,7 @@ if (((StoreAttribute) dst.getAttribute()).isStored()) { // returns the current state stored in a field. if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { - Type resourceType = dst.getIdentifierTemplate().getResourceStateType(); + Type resourceType = dst.getResource().getResourceStateType(); if (model.isPrimitiveType(resourceType)) { getter.addStatement("return value;"); } else { @@ -111,19 +111,19 @@ // src side (for a chain of update method invocations) for (MethodDeclaration srcUpdate: getUpdateMethods(srcType)) { String refParams = ""; - Set referredSet = referredResources.get(srcUpdate); - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcUpdate); + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // to get the value of reference member. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcUpdate, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refVarName = ref.getResourceName(); if (!referredSet.contains(ref)) { referredSet.add(ref); - Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getIdentifierTemplate()); + Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getResource()); String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); @@ -136,19 +136,19 @@ } for (MethodDeclaration srcInput: getInputMethods(srcType, src, model)) { String refParams = ""; - Set referredSet = referredResources.get(srcInput); - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcInput); + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // to get the value of reference member. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcInput, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refVarName = ref.getResourceName(); if (!referredSet.contains(ref)) { referredSet.add(ref); - Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getIdentifierTemplate()); + Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getResource()); String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); @@ -164,29 +164,29 @@ MethodDeclaration getter = getGetterMethod(dstType); if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { boolean isContainedPush = false; - HashMap inputIdentifierToStateAccessor = new HashMap<>(); + HashMap inputResourceToStateAccessor = new HashMap<>(); for (Edge eIn: dst.getInEdges()) { DataFlowEdge dIn = (DataFlowEdge) eIn; if (((PushPullAttribute) dIn.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { isContainedPush = true; - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), JavaCodeGenerator.pushAccessor); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), JavaCodeGenerator.pushAccessor); } else { - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), JavaCodeGenerator.pullAccessor); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), JavaCodeGenerator.pullAccessor); } } // for reference channel members - for (ChannelMember c: d.getChannelGenerator().getReferenceChannelMembers()) { - inputIdentifierToStateAccessor.put(c.getIdentifierTemplate(), JavaCodeGenerator.pullAccessor); // by pull data transfer + for (ChannelMember c: d.getChannel().getReferenceChannelMembers()) { + inputResourceToStateAccessor.put(c.getResource(), JavaCodeGenerator.pullAccessor); // by pull data transfer } String[] sideEffects = new String[] {""}; // generate a return statement. if (!isContainedPush) { // All incoming edges are in PULL style. - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor).toImplementation(sideEffects); + String curState = d.getChannel().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor).toImplementation(sideEffects); getter.addStatement(sideEffects[0] + "return " + curState + ";"); } else { // At least one incoming edge is in PUSH style. - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor, inputIdentifierToStateAccessor).toImplementation(sideEffects); + String curState = d.getChannel().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor, inputResourceToStateAccessor).toImplementation(sideEffects); getter.addStatement(sideEffects[0] + "return " + curState + ";"); } } @@ -199,13 +199,13 @@ TypeDeclaration mainType = typeMap.get(mainTypeName); for (Node n: graph.getNodes()) { ResourceNode resource = (ResourceNode) n; - String resourceName = resource.getIdentifierTemplate().getResourceName(); + String resourceName = resource.getResource().getResourceName(); TypeDeclaration type = typeMap.get(resourceName); if (type != null) { // getter method MethodDeclaration getter = getGetterMethod(type); if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { - Type resourceType = resource.getIdentifierTemplate().getResourceStateType(); + Type resourceType = resource.getResource().getResourceStateType(); if (model.isPrimitiveType(resourceType)) { getter.addStatement("return value;"); } else { @@ -224,8 +224,8 @@ } } // methods for input events - Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); - for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { + Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); + for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { Set outs = entry.getValue(); for (ChannelMember out: outs) { MethodDeclaration input = getInputMethod(type, out); @@ -293,13 +293,13 @@ return null; } - private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { - Map> ioChannelsAndMembers = new HashMap<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) c; + private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { + Map> ioChannelsAndMembers = new HashMap<>(); + for (Channel c: model.getIOChannels()) { + DataTransferChannel ch = (DataTransferChannel) c; // I/O channel for (ChannelMember out: ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { if (out.getStateTransition().getMessageExpression() instanceof Term || out.getStateTransition().getMessageExpression() instanceof Variable) { Set channelMembers = ioChannelsAndMembers.get(ch); if (channelMembers == null) { @@ -316,11 +316,11 @@ private static List getInputMethods(TypeDeclaration type, ResourceNode resource, DataTransferModel model) { List inputs = new ArrayList<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator channel = (DataTransferChannelGenerator) c; + for (Channel c: model.getIOChannels()) { + DataTransferChannel channel = (DataTransferChannel) c; // I/O channel for (ChannelMember out: channel.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { MethodDeclaration input = getInputMethod(type, out); inputs.add(input); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index dcbd48f..dbd0b45 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -21,13 +21,13 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.DataFlowEdge; @@ -66,13 +66,13 @@ for (Node n : resources) { ResourceNode rn = (ResourceNode) n; - String resourceName = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() - + rn.getIdentifierTemplate().getResourceName().substring(1); + String resourceName = rn.getResource().getResourceName().substring(0, 1).toUpperCase() + + rn.getResource().getResourceName().substring(1); // Declare the field to refer each resource in the main type. TypeDeclaration type = new TypeDeclaration(resourceName); type.addAnnotation(new Annotation("Component")); - type.addAnnotation(new Annotation("Path", "\"/" + rn.getIdentifierTemplate().getResourceName() + "\"")); + type.addAnnotation(new Annotation("Path", "\"/" + rn.getResource().getResourceName() + "\"")); // Declare a client field and update methods from other resources. boolean bDeclareClientField = false; @@ -86,7 +86,7 @@ } for (Edge e : rn.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String srcResName = srcRes.getResourceName().substring(0, 1).toUpperCase() + srcRes.getResourceName().substring(1); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { if (!bDeclareClientField) { @@ -102,16 +102,16 @@ VariableDeclaration param = new VariableDeclaration(srcType, srcName); param.addAnnotation(new Annotation("FormParam", "\"" + srcName + "\"")); vars.add(param); - for (IdentifierTemplate refRes: re.getChannelGenerator().getReferenceIdentifierTemplates()) { - if (refRes != rn.getIdentifierTemplate()) { + for (ResourcePath refRes: re.getChannel().getReferenceResources()) { + if (refRes != rn.getResource()) { param = new VariableDeclaration(refRes.getResourceStateType(), refRes.getResourceName()); param.addAnnotation(new Annotation("FormParam", "\"" + refRes.getResourceName() + "\"")); vars.add(param); } } MethodDeclaration update = new MethodDeclaration("update" + srcResName, false, typeVoid, vars); - for (ChannelMember cm: re.getChannelGenerator().getOutputChannelMembers()) { - if (cm.getIdentifierTemplate() == rn.getIdentifierTemplate()) { + for (ChannelMember cm: re.getChannel().getOutputChannelMembers()) { + if (cm.getResource() == rn.getResource()) { if (cm.getStateTransition().isRightUnary()) { update.addAnnotation(new Annotation("PUT")); } else { @@ -123,7 +123,7 @@ // For each source resource, a child resource is defined in the destination resource so that its state can be updated separately. update.addAnnotation(new Annotation("Path", "\"/" + srcName + "\"")); // Declare a field to cash the state of the source resource in the type of the destination resource. - IdentifierTemplate cashResId = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath cashResId = ((ResourceNode) re.getSource()).getResource(); type.addField(new FieldDeclaration(cashResId.getResourceStateType(), srcName, getInitializer(cashResId))); } type.addMethod(update); @@ -149,9 +149,9 @@ // } // Declare input methods in resources. - for (ChannelGenerator cg : model.getIOChannelGenerators()) { - for (ChannelMember cm : ((DataTransferChannelGenerator) cg).getOutputChannelMembers()) { - if (cm.getIdentifierTemplate().equals(rn.getIdentifierTemplate())) { + for (Channel cg : model.getIOChannels()) { + for (ChannelMember cm : ((DataTransferChannel) cg).getOutputChannelMembers()) { + if (cm.getResource().equals(rn.getResource())) { Expression message = cm.getStateTransition().getMessageExpression(); if (message.getClass() == Term.class) { ArrayList params = new ArrayList<>(); @@ -187,12 +187,12 @@ // Declare the field to store the state in the type of each resource. if (((StoreAttribute) rn.getAttribute()).isStored()) { - IdentifierTemplate resId = rn.getIdentifierTemplate(); + ResourcePath resId = rn.getResource(); type.addField(new FieldDeclaration(resId.getResourceStateType(), "value", getInitializer(resId))); } // Declare the getter method to obtain the state in the type of each resource. - MethodDeclaration getter = new MethodDeclaration("getValue", rn.getIdentifierTemplate().getResourceStateType()); + MethodDeclaration getter = new MethodDeclaration("getValue", rn.getResource().getResourceStateType()); getter.addAnnotation(new Annotation("Produces", "MediaType.APPLICATION_JSON")); getter.addAnnotation(new Annotation("GET")); type.addMethod(getter); @@ -214,7 +214,7 @@ for(Node n : resources) { ResourceNode rn = (ResourceNode) n; if(isCreatedPair) continue; - if(model.getType("Pair").isAncestorOf(rn.getIdentifierTemplate().getResourceStateType())) { + if(model.getType("Pair").isAncestorOf(rn.getResource().getResourceStateType())) { TypeDeclaration type = new TypeDeclaration("Pair"); type.addField(new FieldDeclaration(new Type("Double", "T"), "left")); type.addField(new FieldDeclaration(new Type("Double", "T"), "right")); @@ -254,7 +254,7 @@ return codes; } - private static String getInitializer(IdentifierTemplate resId) { + private static String getInitializer(ResourcePath resId) { Type stateType = resId.getResourceStateType(); String initializer = null; if (resId.getInitialValue() != null) { @@ -316,7 +316,7 @@ static public IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -326,7 +326,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); @@ -334,7 +334,7 @@ }; static public IResourceStateAccessor pullAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -347,7 +347,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index 6fe0efd..cdaf898 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -24,12 +24,12 @@ import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; @@ -37,7 +37,7 @@ import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.ResourceNode; import models.dataFlowModel.StoreAttribute; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; public class JerseyMethodBodyGenerator { private static String baseURL = "http://localhost:8080"; @@ -54,37 +54,37 @@ // Generate the body of each update or getter method. try { Set chainedCalls = new HashSet<>(); - Map> referredResources = new HashMap<>(); + Map> referredResources = new HashMap<>(); for (Edge e: graph.getEdges()) { DataFlowEdge d = (DataFlowEdge) e; PushPullAttribute pushPull = (PushPullAttribute) d.getAttribute(); ResourceNode src = (ResourceNode) d.getSource(); ResourceNode dst = (ResourceNode) d.getDestination(); - String srcResourceName = src.getIdentifierTemplate().getResourceName(); - String dstResourceName = dst.getIdentifierTemplate().getResourceName(); + String srcResourceName = src.getResource().getResourceName(); + String dstResourceName = dst.getResource().getResourceName(); TypeDeclaration srcType = typeMap.get(srcResourceName); TypeDeclaration dstType = typeMap.get(dstResourceName); - for (ChannelMember out: d.getChannelGenerator().getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == dst.getIdentifierTemplate()) { + for (ChannelMember out: d.getChannel().getOutputChannelMembers()) { + if (out.getResource() == dst.getResource()) { if (pushPull.getOptions().get(0) == PushPullValue.PUSH && srcType != null) { // for push data transfer MethodDeclaration update = getUpdateMethod(dstType, srcType); if (((StoreAttribute) dst.getAttribute()).isStored()) { // update stored state of dst side resource (when every incoming edge is in push style) Expression updateExp = null; - if (d.getChannelGenerator().getReferenceChannelMembers().size() == 0) { - updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor); + if (d.getChannel().getReferenceChannelMembers().size() == 0) { + updateExp = d.getChannel().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor); } else { // if there exists one or more reference channel member. - HashMap inputIdentifierToStateAccessor = new HashMap<>(); + HashMap inputResourceToStateAccessor = new HashMap<>(); for (Edge eIn: dst.getInEdges()) { DataFlowEdge dIn = (DataFlowEdge) eIn; - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), JerseyCodeGenerator.pushAccessor); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), JerseyCodeGenerator.pushAccessor); } - for (ChannelMember c: d.getChannelGenerator().getReferenceChannelMembers()) { - inputIdentifierToStateAccessor.put(c.getIdentifierTemplate(), JerseyCodeGenerator.pullAccessor); + for (ChannelMember c: d.getChannel().getReferenceChannelMembers()) { + inputResourceToStateAccessor.put(c.getResource(), JerseyCodeGenerator.pullAccessor); } - updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor, inputIdentifierToStateAccessor); + updateExp = d.getChannel().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor, inputResourceToStateAccessor); } String[] sideEffects = new String[] {""}; String curState = updateExp.toImplementation(sideEffects); @@ -187,16 +187,16 @@ for (MethodDeclaration srcUpdate: getUpdateMethods(srcType)) { if (srcUpdate != null) { List>> params = new ArrayList<>(); - Set referredSet = referredResources.get(srcUpdate); - if (d.getChannelGenerator().getReferenceChannelMembers().size() > 0) { - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcUpdate); + if (d.getChannel().getReferenceChannelMembers().size() > 0) { + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // For each reference channel member, get the current state of the reference side resource by pull data transfer. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcUpdate, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refResourceName = ref.getResourceName(); Type refResourceType = ref.getResourceStateType(); if (!referredSet.contains(ref)) { @@ -215,14 +215,14 @@ if (!chainedCalls.contains(srcUpdate)) { // The first call to an update method in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcUpdate.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, true)); srcUpdate.addStatement("String result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); chainedCalls.add(srcUpdate); } else { // After the second time of call to update methods in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcUpdate.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, false)); srcUpdate.addStatement("result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); } @@ -231,15 +231,15 @@ } for (MethodDeclaration srcInput: getInputMethods(srcType, src, model)) { List>> params = new ArrayList<>(); - Set referredSet = referredResources.get(srcInput); - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcInput); + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // For each reference channel member, get the current state of the reference side resource by pull data transfer. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcInput, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refResourceName = ref.getResourceName(); Type refResourceType = ref.getResourceStateType(); if (!referredSet.contains(ref)) { @@ -257,14 +257,14 @@ if (!chainedCalls.contains(srcInput)) { // First call to an update method in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcInput.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, true)); srcInput.addStatement("String result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); chainedCalls.add(srcInput); } else { // After the second time of call to update methods in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcInput.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, false)); srcInput.addStatement("result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); } @@ -276,17 +276,17 @@ if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { // generate a return statement. String[] sideEffects = new String[] {""}; - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pullAccessor).toImplementation(sideEffects); // no pull data transfer is included. + String curState = d.getChannel().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pullAccessor).toImplementation(sideEffects); // no pull data transfer is included. getter.addStatement(sideEffects[0] + "return " + curState + ";"); // For each reference channel member, get the current state of the reference side resource by pull data transfer. - for (ChannelMember c: d.getChannelGenerator().getReferenceChannelMembers()) { - String refResourceName = c.getIdentifierTemplate().getResourceName(); - Type refResourceType = c.getIdentifierTemplate().getResourceStateType(); + for (ChannelMember c: d.getChannel().getReferenceChannelMembers()) { + String refResourceName = c.getResource().getResourceName(); + Type refResourceType = c.getResource().getResourceStateType(); generatePullDataTransfer(getter, refResourceName, refResourceType); } } // get src side resource state by pull data transfer. - Type srcResourceType = src.getIdentifierTemplate().getResourceStateType(); + Type srcResourceType = src.getResource().getResourceStateType(); generatePullDataTransfer(getter, srcResourceName, srcResourceType); } } @@ -295,7 +295,7 @@ // for source nodes for (Node n: graph.getNodes()) { ResourceNode resource = (ResourceNode) n; - String resourceName = resource.getIdentifierTemplate().getResourceName(); + String resourceName = resource.getResource().getResourceName(); TypeDeclaration type = typeMap.get(resourceName); if (type != null) { // getter method @@ -304,8 +304,8 @@ getter.addStatement("return value;"); } // methods for input events - Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); - for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { + Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); + for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { Set outs = entry.getValue(); for (ChannelMember out: outs) { MethodDeclaration input = getInputMethod(type, out); @@ -540,13 +540,13 @@ return null; } - private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { - Map> ioChannelsAndMembers = new HashMap<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) c; + private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { + Map> ioChannelsAndMembers = new HashMap<>(); + for (Channel c: model.getIOChannels()) { + DataTransferChannel ch = (DataTransferChannel) c; // I/O channel for (ChannelMember out: ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { if (out.getStateTransition().getMessageExpression() instanceof Term || out.getStateTransition().getMessageExpression() instanceof Variable) { Set channelMembers = ioChannelsAndMembers.get(ch); if (channelMembers == null) { @@ -563,11 +563,11 @@ private static List getInputMethods(TypeDeclaration type, ResourceNode resource, DataTransferModel model) { List inputs = new ArrayList<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator channel = (DataTransferChannelGenerator) c; + for (Channel c: model.getIOChannels()) { + DataTransferChannel channel = (DataTransferChannel) c; // I/O channel for (ChannelMember out: channel.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { MethodDeclaration input = getInputMethod(type, out); inputs.add(input); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java index a11aa71..0a7c10b 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; -import models.dataConstraintModel.IdentifierTemplate; - public class Position implements Cloneable { private ArrayList orders = new ArrayList(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java new file mode 100644 index 0000000..8bf74da --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java @@ -0,0 +1,96 @@ +package models.dataConstraintModel; + +import java.util.HashSet; +import java.util.Set; + +import models.algebra.Variable; + +public class Channel { + protected String channelName; + protected Set selectors = null; + protected Set channelMembers = null; + protected String sourceText = null; + + public Channel(String channelName) { + this.channelName = channelName; + selectors = new HashSet<>(); + channelMembers = new HashSet<>(); + } + + public Channel(String channelName, Set variables) { + this.channelName = channelName; + selectors = new HashSet<>(); + for (Variable var: variables) { + selectors.add(new Selector(var)); + } + channelMembers = new HashSet<>(); + } + + public String getChannelName() { + return channelName; + } + + public Set getChannelSelectors() { + return selectors; + } + + public void setChannelSelectors(Set selectors) { + this.selectors = selectors; + } + + public void addSelector(Selector selector) { + selectors.add(selector); + } + + public Set getChannelMembers() { + return channelMembers; + } + + public void setChannelMembers(Set channelMembers) { + this.channelMembers = channelMembers; + for (ChannelMember channelMember: channelMembers) { + for (Selector selector: channelMember.getSelectors()) { + addSelector(selector); + } + } + } + + public void addChannelMember(ChannelMember channelMember) { + channelMembers.add(channelMember); + for (Selector selector: channelMember.getSelectors()) { + addSelector(selector); + } + } + + public void removeChannelMember(ResourcePath id) { + for (ChannelMember cm: channelMembers) { + if (cm.getResource() == id) { + channelMembers.remove(cm); + break; + } + } + } + + public Set getResources() { + Set resources = new HashSet<>(); + for (ChannelMember member: channelMembers) { + resources.add(member.getResource()); + } + return resources; + } + + public String toString() { + return channelName; + } + + public void setSourceText(String sourceText) { + this.sourceText = sourceText; + } + + public String getSourceText() { + if (sourceText == null) { + return toString(); + } + return sourceText; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java deleted file mode 100644 index 8a9bd1f..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java +++ /dev/null @@ -1,107 +0,0 @@ -package models.dataConstraintModel; - -import java.util.HashSet; -import java.util.Set; - -public class ChannelGenerator { - protected String channelName; - protected Set groupSelectors = null; - protected Set channelSelectors = null; - protected Set channelMembers = null; - protected String sourceText = null; - - public ChannelGenerator(String channelName) { - this.channelName = channelName; - groupSelectors = new HashSet<>(); - channelSelectors = new HashSet<>(); - channelMembers = new HashSet<>(); - } - - public String getChannelName() { - return channelName; - } - - public Set getGroupSelectors() { - return groupSelectors; - } - - public void setGroupSelectors(Set groupSelectors) { - this.groupSelectors = groupSelectors; - } - - public void addGroupSelector(GroupSelector groupSelector) { - groupSelectors.add(groupSelector); - } - - public Set getChannelSelectors() { - return channelSelectors; - } - - public void setChannelSelectors(Set channelSelectors) { - this.channelSelectors = channelSelectors; - } - - public void addChannelSelector(ChannelSelector channelSelector) { - channelSelectors.add(channelSelector); - } - - public void addSelector(Selector selector) { - if (selector instanceof GroupSelector) { - groupSelectors.add((GroupSelector)selector); - } else if (selector instanceof ChannelSelector) { - channelSelectors.add((ChannelSelector)selector); - } - } - - public Set getChannelMembers() { - return channelMembers; - } - - public void setChannelMembers(Set channelMembers) { - this.channelMembers = channelMembers; - for (ChannelMember channelMember: channelMembers) { - for (Selector selector: channelMember.getSelectors()) { - addSelector(selector); - } - } - } - - public void addChannelMember(ChannelMember channelMember) { - channelMembers.add(channelMember); - for (Selector selector: channelMember.getSelectors()) { - addSelector(selector); - } - } - - public void removeChannelMember(IdentifierTemplate id) { - for (ChannelMember cm: channelMembers) { - if (cm.getIdentifierTemplate() == id) { - channelMembers.remove(cm); - break; - } - } - } - - public Set getIdentifierTemplates() { - Set identifierTemplates = new HashSet<>(); - for (ChannelMember member: channelMembers) { - identifierTemplates.add(member.getIdentifierTemplate()); - } - return identifierTemplates; - } - - public String toString() { - return channelName; - } - - public void setSourceText(String sourceText) { - this.sourceText = sourceText; - } - - public String getSourceText() { - if (sourceText == null) { - return toString(); - } - return sourceText; - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java index 8c2f210..190a49f 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java @@ -4,22 +4,22 @@ import java.util.List; public class ChannelMember { - private IdentifierTemplate identifierTemplate = null; + private ResourcePath resourcePath = null; private List selectors = null; private StateTransition stateTransition = null; - public ChannelMember(IdentifierTemplate identifierTemplate) { - this.identifierTemplate = identifierTemplate; + public ChannelMember(ResourcePath resourcePath) { + this.resourcePath = resourcePath; selectors = new ArrayList<>(); stateTransition = new StateTransition(); } - public IdentifierTemplate getIdentifierTemplate() { - return identifierTemplate; + public ResourcePath getResource() { + return resourcePath; } - public void setIdentifierTemplate(IdentifierTemplate identifierTemplate) { - this.identifierTemplate = identifierTemplate; + public void setResource(ResourcePath resourcePath) { + this.resourcePath = resourcePath; } public List getSelectors() { @@ -46,11 +46,11 @@ @Override public String toString() { if (stateTransition.getNextStateExpression() == null) { - return identifierTemplate.getResourceName() + "(" + return resourcePath.getResourceName() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")"; } - return identifierTemplate.getResourceName() + "(" + return resourcePath.getResourceName() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")" + " == " + stateTransition.getNextStateExpression(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelSelector.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelSelector.java deleted file mode 100644 index daa5ec5..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelSelector.java +++ /dev/null @@ -1,5 +0,0 @@ -package models.dataConstraintModel; - -public class ChannelSelector extends Selector { - -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index c6fb2ea..35b2aa7 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -8,9 +8,9 @@ import parser.Parser; public class DataConstraintModel { - protected HashMap identifierTemplates = null; - protected HashMap channelGenerators = null; - protected HashMap ioChannelGenerators = null; + protected HashMap resourcePaths = null; + protected HashMap channels = null; + protected HashMap ioChannels = null; protected HashMap types = null; protected HashMap symbols = null; public static final Type typeInt = new Type("Int", "int"); @@ -182,9 +182,9 @@ } public DataConstraintModel() { - identifierTemplates = new HashMap<>(); - channelGenerators = new HashMap<>(); - ioChannelGenerators = new HashMap<>(); + resourcePaths = new HashMap<>(); + channels = new HashMap<>(); + ioChannels = new HashMap<>(); types = new HashMap<>(); addType(typeInt); addType(typeLong); @@ -234,87 +234,87 @@ addSymbol(lookup); } - public Collection getIdentifierTemplates() { - return identifierTemplates.values(); + public Collection getResourcePaths() { + return resourcePaths.values(); } - public IdentifierTemplate getIdentifierTemplate(String resourceName) { - return identifierTemplates.get(resourceName); + public ResourcePath getResourcePath(String resourceName) { + return resourcePaths.get(resourceName); } - public void addIdentifierTemplate(IdentifierTemplate identifierTemplate) { - identifierTemplates.put(identifierTemplate.getResourceName(), identifierTemplate); + public void addResourcePath(ResourcePath resourcePath) { + resourcePaths.put(resourcePath.getResourceName(), resourcePath); } - public void setIdentifierTemplates(HashMap identifierTemplates) { - this.identifierTemplates = identifierTemplates; + public void setResourcePaths(HashMap resourcePaths) { + this.resourcePaths = resourcePaths; } - public void removeIdentifierTemplate(String resourceName) { - IdentifierTemplate id = identifierTemplates.get(resourceName); - identifierTemplates.remove(resourceName); - for (ChannelGenerator ch: channelGenerators.values()) { + public void removeResourcePath(String resourceName) { + ResourcePath id = resourcePaths.get(resourceName); + resourcePaths.remove(resourceName); + for (Channel ch: channels.values()) { ch.removeChannelMember(id); } - for (ChannelGenerator ch: ioChannelGenerators.values()) { + for (Channel ch: ioChannels.values()) { ch.removeChannelMember(id); } } - public Collection getChannelGenerators() { - return channelGenerators.values(); + public Collection getChannels() { + return channels.values(); } - public ChannelGenerator getChannelGenerator(String channelName) { - return channelGenerators.get(channelName); + public Channel getChannel(String channelName) { + return channels.get(channelName); } - public void setChannelGenerators(HashMap channelGenerators) { - this.channelGenerators = channelGenerators; - for (ChannelGenerator g: channelGenerators.values()) { - for (IdentifierTemplate id: g.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void setChannels(HashMap channels) { + this.channels = channels; + for (Channel g: channels.values()) { + for (ResourcePath id: g.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } } - public void addChannelGenerator(ChannelGenerator channelGenerator) { - channelGenerators.put(channelGenerator.getChannelName(), channelGenerator); - for (IdentifierTemplate id: channelGenerator.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void addChannel(Channel channel) { + channels.put(channel.getChannelName(), channel); + for (ResourcePath id: channel.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } - public void removeChannelGenerator(String channelName) { - channelGenerators.remove(channelName); + public void removeChannel(String channelName) { + channels.remove(channelName); } - public Collection getIOChannelGenerators() { - return ioChannelGenerators.values(); + public Collection getIOChannels() { + return ioChannels.values(); } - public ChannelGenerator getIOChannelGenerator(String channelName) { - return ioChannelGenerators.get(channelName); + public Channel getIOChannel(String channelName) { + return ioChannels.get(channelName); } - public void setIOChannelGenerators(HashMap ioChannelGenerators) { - this.ioChannelGenerators = ioChannelGenerators; - for (ChannelGenerator g: ioChannelGenerators.values()) { - for (IdentifierTemplate id: g.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void setIOChannels(HashMap ioChannels) { + this.ioChannels = ioChannels; + for (Channel g: ioChannels.values()) { + for (ResourcePath id: g.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } } - public void addIOChannelGenerator(ChannelGenerator ioChannelGenerator) { - ioChannelGenerators.put(ioChannelGenerator.getChannelName(), ioChannelGenerator); - for (IdentifierTemplate id: ioChannelGenerator.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void addIOChannel(Channel ioChannel) { + ioChannels.put(ioChannel.getChannelName(), ioChannel); + for (ResourcePath id: ioChannel.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } - public void removeIOChannelGenerator(String ioChannelName) { - ioChannelGenerators.remove(ioChannelName); + public void removeIOChannel(String ioChannelName) { + ioChannels.remove(ioChannelName); } public void addType(Type type) { @@ -383,11 +383,11 @@ @Override public String toString() { String out = ""; - for (ChannelGenerator channelGenerator: ioChannelGenerators.values()) { - out += channelGenerator.toString(); + for (Channel channel: ioChannels.values()) { + out += channel.toString(); } - for (ChannelGenerator channelGenerator: channelGenerators.values()) { - out += channelGenerator.toString(); + for (Channel channel: channels.values()) { + out += channel.toString(); } return out; } @@ -395,8 +395,8 @@ public String getSourceText() { String out = ""; String init = ""; - for (IdentifierTemplate identifierTemplate: identifierTemplates.values()) { - String initializer = identifierTemplate.getInitText(); + for (ResourcePath resource: resourcePaths.values()) { + String initializer = resource.getInitText(); if (initializer != null) { init += initializer; } @@ -404,11 +404,11 @@ if (init.length() > 0) { out += "init {\n" + init + "}\n"; } - for (ChannelGenerator channelGenerator: ioChannelGenerators.values()) { - out += channelGenerator.getSourceText(); + for (Channel channel: ioChannels.values()) { + out += channel.getSourceText(); } - for (ChannelGenerator channelGenerator: channelGenerators.values()) { - out += channelGenerator.getSourceText(); + for (Channel channel: channels.values()) { + out += channel.getSourceText(); } return out; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/GroupSelector.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/GroupSelector.java deleted file mode 100644 index 66e5731..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/GroupSelector.java +++ /dev/null @@ -1,5 +0,0 @@ -package models.dataConstraintModel; - -public class GroupSelector extends Selector { - -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java deleted file mode 100644 index d91355c..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java +++ /dev/null @@ -1,70 +0,0 @@ -package models.dataConstraintModel; - -import models.algebra.Expression; -import models.algebra.Term; -import models.algebra.Type; - -public class IdentifierTemplate { - private String resourceName = null; - private Type resourceStateType = null; - private int numParameters = 0; - private Expression initialValue = null; - protected String initText = null; - - public IdentifierTemplate(String resourceName, int numParameters) { - this.resourceName = resourceName; - this.numParameters =numParameters; - } - - public IdentifierTemplate(String resourceName, Type resourceStateType, int numParameters) { - this.resourceName = resourceName; - this.resourceStateType = resourceStateType; - this.numParameters = numParameters; - } - - public String getResourceName() { - return resourceName; - } - - public int getNumberOfParameters() { - return numParameters; - } - - public Type getResourceStateType() { - return resourceStateType; - } - - public void setResourceStateType(Type resourceStateType) { - this.resourceStateType = resourceStateType; - if (initialValue != null) { - if (initialValue instanceof Term) { - ((Term) initialValue).setType(resourceStateType); - } - } - } - - public Expression getInitialValue() { - return initialValue; - } - - public void setInitialValue(Expression initialValue) { - this.initialValue = initialValue; - } - - public void setInitText(String initText) { - this.initText = initText; - } - - public String getInitText() { - return initText; - } - - public boolean equals(Object another) { - if (!(another instanceof IdentifierTemplate)) return false; - return resourceName.equals(((IdentifierTemplate) another).resourceName); - } - - public int hashCode() { - return resourceName.hashCode(); - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java new file mode 100644 index 0000000..e530016 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java @@ -0,0 +1,70 @@ +package models.dataConstraintModel; + +import models.algebra.Expression; +import models.algebra.Term; +import models.algebra.Type; + +public class ResourcePath { + private String resourceName = null; + private Type resourceStateType = null; + private int numParameters = 0; + private Expression initialValue = null; + protected String initText = null; + + public ResourcePath(String resourceName, int numParameters) { + this.resourceName = resourceName; + this.numParameters = numParameters; + } + + public ResourcePath(String resourceName, Type resourceStateType, int numParameters) { + this.resourceName = resourceName; + this.resourceStateType = resourceStateType; + this.numParameters = numParameters; + } + + public String getResourceName() { + return resourceName; + } + + public int getNumberOfParameters() { + return numParameters; + } + + public Type getResourceStateType() { + return resourceStateType; + } + + public void setResourceStateType(Type resourceStateType) { + this.resourceStateType = resourceStateType; + if (initialValue != null) { + if (initialValue instanceof Term) { + ((Term) initialValue).setType(resourceStateType); + } + } + } + + public Expression getInitialValue() { + return initialValue; + } + + public void setInitialValue(Expression initialValue) { + this.initialValue = initialValue; + } + + public void setInitText(String initText) { + this.initText = initText; + } + + public String getInitText() { + return initText; + } + + public boolean equals(Object another) { + if (!(another instanceof ResourcePath)) return false; + return resourceName.equals(((ResourcePath) another).resourceName); + } + + public int hashCode() { + return resourceName.hashCode(); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java index 1794428..a29f8e3 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java @@ -1,5 +1,19 @@ package models.dataConstraintModel; -abstract public class Selector { +import models.algebra.Variable; +public class Selector { + private Variable variable = null; + + public Selector(Variable variable) { + this.setVariable(variable); + } + + public Variable getVariable() { + return variable; + } + + public void setVariable(Variable variable) { + this.variable = variable; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java index 3c3b25f..9de9359 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java @@ -3,18 +3,18 @@ import models.*; public class DataFlowEdge extends Edge { - protected DataTransferChannelGenerator channelGenerator = null; + protected DataTransferChannel channel = null; - public DataFlowEdge(ResourceNode src, ResourceNode dst, DataTransferChannelGenerator channelGenerator) { + public DataFlowEdge(ResourceNode src, ResourceNode dst, DataTransferChannel channel) { super(src, dst); - this.channelGenerator = channelGenerator; + this.channel = channel; } - public DataTransferChannelGenerator getChannelGenerator() { - return channelGenerator; + public DataTransferChannel getChannel() { + return channel; } public String toString() { - return channelGenerator.getChannelName(); + return channel.getChannelName(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java index 5df4229..2c540ed 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java @@ -4,17 +4,17 @@ import java.util.Map; import models.DirectedGraph; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class DataFlowGraph extends DirectedGraph { - protected Map nodeMap = null; + protected Map nodeMap = null; public DataFlowGraph() { super(); nodeMap = new HashMap<>(); } - public void addNode(IdentifierTemplate id) { + public void addNode(ResourcePath id) { if (nodeMap.get(id) == null) { ResourceNode node = new ResourceNode(id); addNode(node); @@ -22,7 +22,7 @@ } } - public void addEdge(IdentifierTemplate in, IdentifierTemplate out, DataTransferChannelGenerator dfChannelGen) { + public void addEdge(ResourcePath in, ResourcePath out, DataTransferChannel dfChannelGen) { ResourceNode srcNode = nodeMap.get(in); if (srcNode == null) { srcNode = new ResourceNode(in); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java new file mode 100644 index 0000000..b3f3bf0 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java @@ -0,0 +1,273 @@ +package models.dataFlowModel; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import models.algebra.Expression; +import models.algebra.InvalidMessage; +import models.algebra.Parameter; +import models.algebra.ParameterizedIdentifierIsFutureWork; +import models.algebra.Position; +import models.algebra.Term; +import models.algebra.UnificationFailed; +import models.algebra.ValueUndefined; +import models.algebra.Variable; +import models.dataConstraintModel.*; + +public class DataTransferChannel extends Channel { + protected Set inputChannelMembers = null; + protected Set outputChannelMembers = null; + protected Set referenceChannelMembers = null; + + public DataTransferChannel(String channelName) { + super(channelName); + inputChannelMembers = new HashSet<>(); + outputChannelMembers = new HashSet<>(); + referenceChannelMembers = new HashSet<>(); + } + + public Set getInputChannelMembers() { + return inputChannelMembers; + } + + public void setInputChannelMembers(Set inputChannelMembers) { + this.inputChannelMembers = inputChannelMembers; + } + + public void addInputChannelMember(ChannelMember inputChannelMember) { + inputChannelMembers.add(inputChannelMember); + } + + public Set getOutputChannelMembers() { + return outputChannelMembers; + } + + public void setOutputChannelMembers(Set outputChannelMembers) { + this.outputChannelMembers = outputChannelMembers; + } + + public void addOutputChannelMember(ChannelMember outputChannelMember) { + outputChannelMembers.add(outputChannelMember); + } + + public Set getReferenceChannelMembers() { + return referenceChannelMembers; + } + + public void setReferenceChannelMembers(Set referenceChannelMembers) { + this.referenceChannelMembers = referenceChannelMembers; + } + + public void addReferenceChannelMember(ChannelMember referenceChannelMember) { + referenceChannelMembers.add(referenceChannelMember); + } + + public void addChannelMemberAsInput(ChannelMember groupDependentResource) { + addChannelMember(groupDependentResource); + addInputChannelMember(groupDependentResource); + } + + public void addChannelMemberAsOutput(ChannelMember groupDependentResource) { + addChannelMember(groupDependentResource); + addOutputChannelMember(groupDependentResource); + } + + public void addChannelMemberAsReference(ChannelMember groupDependentResource) { + addChannelMember(groupDependentResource); + addReferenceChannelMember(groupDependentResource); + } + + public void removeChannelMember(ResourcePath id) { + for (ChannelMember cm: inputChannelMembers) { + if (cm.getResource() == id) { + inputChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + for (ChannelMember cm: outputChannelMembers) { + if (cm.getResource() == id) { + outputChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + for (ChannelMember cm: referenceChannelMembers) { + if (cm.getResource() == id) { + referenceChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + } + + public Set getInputResources() { + Set inputResources = new HashSet<>(); + for (ChannelMember member: inputChannelMembers) { + inputResources.add(member.getResource()); + } + return inputResources; + } + + public Set getOutputResources() { + Set outputResources = new HashSet<>(); + for (ChannelMember member: outputChannelMembers) { + outputResources.add(member.getResource()); + } + return outputResources; + } + + public Set getReferenceResources() { + Set referenceResources = new HashSet<>(); + for (ChannelMember member: referenceChannelMembers) { + referenceResources.add(member.getResource()); + } + return referenceResources; + } + + /** + * Derive the update expression of the state of the target channel member. + * @param targetMember a channel member whose state is to be updated + * @return the derived update expression + * @throws ParameterizedIdentifierIsFutureWork + * @throws ResolvingMultipleDefinitionIsFutureWork + * @throws InvalidMessage + * @throws UnificationFailed + * @throws ValueUndefined + */ + public Expression deriveUpdateExpressionOf(ChannelMember targetMember) throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { + IResourceStateAccessor defaultStateAccessor = new IResourceStateAccessor() { + HashMap curStateParams = new HashMap<>(); + HashMap nextStateParams = new HashMap<>(); + + @Override + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { + String resource = target.getResourceName(); + Parameter curStateParam = curStateParams.get(resource); + if (curStateParam == null) { + curStateParam = new Parameter("cur" + resource); + curStateParams.put(resource, curStateParam); + } + return curStateParam; + } + + @Override + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { + String resource = target.getResourceName(); + Parameter nextStateParam = nextStateParams.get(resource); + if (nextStateParam == null) { + nextStateParam = new Parameter("next" + resource); + nextStateParams.put(resource, nextStateParam); + } + return nextStateParam; + } + }; + return deriveUpdateExpressionOf(targetMember, defaultStateAccessor); + } + + /** + * Derive the update expression of the state of the target channel member with a given resource state accessor. + * @param targetMember a channel member whose state is to be updated + * @param stateAccessor a resource state accessor + * @return the derived update expression + * @throws ParameterizedIdentifierIsFutureWork + * @throws ResolvingMultipleDefinitionIsFutureWork + * @throws InvalidMessage + * @throws UnificationFailed + * @throws ValueUndefined + */ + public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor) + throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { + return deriveUpdateExpressionOf(targetMember, stateAccessor, null); + } + + public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor, HashMap inputResourceToStateAccessor) + throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { + if (!getOutputChannelMembers().contains(targetMember)) return null; + HashSet messageConstraints = new HashSet<>(); + + // 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) { + curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(inputResource, targetMember.getResource()); + nextInputStateAccessor = stateAccessor.getNextStateAccessorFor(inputResource, targetMember.getResource()); + } else { + curInputStateAccessor = inputResourceToStateAccessor.get(inputResource).getCurrentStateAccessorFor(inputResource, targetMember.getResource()); + nextInputStateAccessor = inputResourceToStateAccessor.get(inputResource).getNextStateAccessorFor(inputResource, targetMember.getResource()); + } + Expression messageConstraintByInput = inputMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor, nextInputStateAccessor); + messageConstraints.add((Term) messageConstraintByInput); + } + + // 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()); + } else { + curInputStateAccessor = inputResourceToStateAccessor.get(referenceResource).getCurrentStateAccessorFor(referenceResource, targetMember.getResource()); + } + Expression messageConstraintByReference = referenceMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor); + messageConstraints.add((Term) messageConstraintByReference); + } + + // Unify message constraints + Term unifiedMessage = null; + for (Term messageContraint: messageConstraints) { + if (unifiedMessage == null) { + unifiedMessage = messageContraint; + } else { + unifiedMessage = (Term) unifiedMessage.unify(messageContraint); + if (unifiedMessage == null) { + throw new UnificationFailed(); + } + } + } + + // 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 + if (targetMember.getStateTransition().getMessageExpression() instanceof Term) { + unifiedMessage = (Term) targetMember.getStateTransition().getMessageExpression(); + } + } + return targetMember.getStateTransition().deriveNextStateExpressionFor(curOutputStateAccessor, unifiedMessage); + } + + @Override + public String toString() { + String channelSource = "channel " + getChannelName() + " {\n"; + for (ChannelMember inputMember: inputChannelMembers) { + channelSource += "\t in " + inputMember + "\n"; + } + for (ChannelMember refMember: referenceChannelMembers) { + channelSource += "\t ref " + refMember + "\n"; + } + for (ChannelMember outputMember: outputChannelMembers) { + channelSource += "\t out " + outputMember + "\n"; + } + channelSource += "}\n"; + return channelSource; + } + + public interface IResourceStateAccessor { + Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from); + Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannelGenerator.java deleted file mode 100644 index 1426ac7..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannelGenerator.java +++ /dev/null @@ -1,273 +0,0 @@ -package models.dataFlowModel; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import models.algebra.Expression; -import models.algebra.InvalidMessage; -import models.algebra.Parameter; -import models.algebra.ParameterizedIdentifierIsFutureWork; -import models.algebra.Position; -import models.algebra.Term; -import models.algebra.UnificationFailed; -import models.algebra.ValueUndefined; -import models.algebra.Variable; -import models.dataConstraintModel.*; - -public class DataTransferChannelGenerator extends ChannelGenerator { - protected Set inputChannelMembers = null; - protected Set outputChannelMembers = null; - protected Set referenceChannelMembers = null; - - public DataTransferChannelGenerator(String channelName) { - super(channelName); - inputChannelMembers = new HashSet<>(); - outputChannelMembers = new HashSet<>(); - referenceChannelMembers = new HashSet<>(); - } - - public Set getInputChannelMembers() { - return inputChannelMembers; - } - - public void setInputChannelMembers(Set inputChannelMembers) { - this.inputChannelMembers = inputChannelMembers; - } - - public void addInputChannelMember(ChannelMember inputChannelMember) { - inputChannelMembers.add(inputChannelMember); - } - - public Set getOutputChannelMembers() { - return outputChannelMembers; - } - - public void setOutputChannelMembers(Set outputChannelMembers) { - this.outputChannelMembers = outputChannelMembers; - } - - public void addOutputChannelMember(ChannelMember outputChannelMember) { - outputChannelMembers.add(outputChannelMember); - } - - public Set getReferenceChannelMembers() { - return referenceChannelMembers; - } - - public void setReferenceChannelMembers(Set referenceChannelMembers) { - this.referenceChannelMembers = referenceChannelMembers; - } - - public void addReferenceChannelMember(ChannelMember referenceChannelMember) { - referenceChannelMembers.add(referenceChannelMember); - } - - public void addChannelMemberAsInput(ChannelMember groupDependentResource) { - addChannelMember(groupDependentResource); - addInputChannelMember(groupDependentResource); - } - - public void addChannelMemberAsOutput(ChannelMember groupDependentResource) { - addChannelMember(groupDependentResource); - addOutputChannelMember(groupDependentResource); - } - - public void addChannelMemberAsReference(ChannelMember groupDependentResource) { - addChannelMember(groupDependentResource); - addReferenceChannelMember(groupDependentResource); - } - - public void removeChannelMember(IdentifierTemplate id) { - for (ChannelMember cm: inputChannelMembers) { - if (cm.getIdentifierTemplate() == id) { - inputChannelMembers.remove(cm); - super.removeChannelMember(id); - return; - } - } - for (ChannelMember cm: outputChannelMembers) { - if (cm.getIdentifierTemplate() == id) { - outputChannelMembers.remove(cm); - super.removeChannelMember(id); - return; - } - } - for (ChannelMember cm: referenceChannelMembers) { - if (cm.getIdentifierTemplate() == id) { - referenceChannelMembers.remove(cm); - super.removeChannelMember(id); - return; - } - } - } - - public Set getInputIdentifierTemplates() { - Set inputIdentifierTemplates = new HashSet<>(); - for (ChannelMember member: inputChannelMembers) { - inputIdentifierTemplates.add(member.getIdentifierTemplate()); - } - return inputIdentifierTemplates; - } - - public Set getOutputIdentifierTemplates() { - Set outputIdentifierTemplates = new HashSet<>(); - for (ChannelMember member: outputChannelMembers) { - outputIdentifierTemplates.add(member.getIdentifierTemplate()); - } - return outputIdentifierTemplates; - } - - public Set getReferenceIdentifierTemplates() { - Set referenceIdentifierTemplates = new HashSet<>(); - for (ChannelMember member: referenceChannelMembers) { - referenceIdentifierTemplates.add(member.getIdentifierTemplate()); - } - return referenceIdentifierTemplates; - } - - /** - * Derive the update expression of the state of the target channel member. - * @param targetMember a channel member whose state is to be updated - * @return the derived update expression - * @throws ParameterizedIdentifierIsFutureWork - * @throws ResolvingMultipleDefinitionIsFutureWork - * @throws InvalidMessage - * @throws UnificationFailed - * @throws ValueUndefined - */ - public Expression deriveUpdateExpressionOf(ChannelMember targetMember) throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { - IResourceStateAccessor defaultStateAccessor = new IResourceStateAccessor() { - HashMap curStateParams = new HashMap<>(); - HashMap nextStateParams = new HashMap<>(); - - @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { - String resource = target.getResourceName(); - Parameter curStateParam = curStateParams.get(resource); - if (curStateParam == null) { - curStateParam = new Parameter("cur" + resource); - curStateParams.put(resource, curStateParam); - } - return curStateParam; - } - - @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { - String resource = target.getResourceName(); - Parameter nextStateParam = nextStateParams.get(resource); - if (nextStateParam == null) { - nextStateParam = new Parameter("next" + resource); - nextStateParams.put(resource, nextStateParam); - } - return nextStateParam; - } - }; - return deriveUpdateExpressionOf(targetMember, defaultStateAccessor); - } - - /** - * Derive the update expression of the state of the target channel member with a given resource state accessor. - * @param targetMember a channel member whose state is to be updated - * @param stateAccessor a resource state accessor - * @return the derived update expression - * @throws ParameterizedIdentifierIsFutureWork - * @throws ResolvingMultipleDefinitionIsFutureWork - * @throws InvalidMessage - * @throws UnificationFailed - * @throws ValueUndefined - */ - public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor) - throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { - return deriveUpdateExpressionOf(targetMember, stateAccessor, null); - } - - public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor, HashMap inputIdentifierToStateAccessor) - throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { - if (!getOutputChannelMembers().contains(targetMember)) return null; - HashSet messageConstraints = new HashSet<>(); - - // Calculate message constraints from input state transitions - for (ChannelMember inputMember: getInputChannelMembers()) { - IdentifierTemplate inputIdentifier = inputMember.getIdentifierTemplate(); - if (inputIdentifier.getNumberOfParameters() > 0) { - throw new ParameterizedIdentifierIsFutureWork(); - } - Expression curInputStateAccessor = null; - Expression nextInputStateAccessor = null; - if (inputIdentifierToStateAccessor == null) { - curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - nextInputStateAccessor = stateAccessor.getNextStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - } else { - curInputStateAccessor = inputIdentifierToStateAccessor.get(inputIdentifier).getCurrentStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - nextInputStateAccessor = inputIdentifierToStateAccessor.get(inputIdentifier).getNextStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - } - Expression messageConstraintByInput = inputMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor, nextInputStateAccessor); - messageConstraints.add((Term) messageConstraintByInput); - } - - // Calculate message constraints from reference state transitions - for (ChannelMember referenceMember: getReferenceChannelMembers()) { - IdentifierTemplate referenceIdentifier = referenceMember.getIdentifierTemplate(); - if (referenceIdentifier.getNumberOfParameters() > 0) { - throw new ParameterizedIdentifierIsFutureWork(); - } - Expression curInputStateAccessor = null; - if (inputIdentifierToStateAccessor == null) { - curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(referenceIdentifier, targetMember.getIdentifierTemplate()); - } else { - curInputStateAccessor = inputIdentifierToStateAccessor.get(referenceIdentifier).getCurrentStateAccessorFor(referenceIdentifier, targetMember.getIdentifierTemplate()); - } - Expression messageConstraintByReference = referenceMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor); - messageConstraints.add((Term) messageConstraintByReference); - } - - // Unify message constraints - Term unifiedMessage = null; - for (Term messageContraint: messageConstraints) { - if (unifiedMessage == null) { - unifiedMessage = messageContraint; - } else { - unifiedMessage = (Term) unifiedMessage.unify(messageContraint); - if (unifiedMessage == null) { - throw new UnificationFailed(); - } - } - } - - // Calculate the next state of target resource from the unified message and the current resource state - IdentifierTemplate targetIdentifier = targetMember.getIdentifierTemplate(); - if (targetIdentifier.getNumberOfParameters() > 0) { - throw new ParameterizedIdentifierIsFutureWork(); - } - Expression curOutputStateAccessor = stateAccessor.getCurrentStateAccessorFor(targetIdentifier, targetIdentifier); - if (unifiedMessage == null) { - // for IOChannel - if (targetMember.getStateTransition().getMessageExpression() instanceof Term) { - unifiedMessage = (Term) targetMember.getStateTransition().getMessageExpression(); - } - } - return targetMember.getStateTransition().deriveNextStateExpressionFor(curOutputStateAccessor, unifiedMessage); - } - - @Override - public String toString() { - String channelSource = "channel " + getChannelName() + " {\n"; - for (ChannelMember inputMember: inputChannelMembers) { - channelSource += "\t in " + inputMember + "\n"; - } - for (ChannelMember refMember: referenceChannelMembers) { - channelSource += "\t ref " + refMember + "\n"; - } - for (ChannelMember outputMember: outputChannelMembers) { - channelSource += "\t out " + outputMember + "\n"; - } - channelSource += "}\n"; - return channelSource; - } - - public interface IResourceStateAccessor { - Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from); - Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from); - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java index 364a646..db43b80 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java @@ -2,27 +2,27 @@ import java.util.Set; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class DataTransferModel extends DataConstraintModel { public DataFlowGraph getDataFlowGraph() { DataFlowGraph dataFlowGraph = new DataFlowGraph(); - for (ChannelGenerator channelGen: getChannelGenerators()) { - DataTransferChannelGenerator dfChannelGen = (DataTransferChannelGenerator)channelGen; - Set inputResources = dfChannelGen.getInputIdentifierTemplates(); - Set outputResources = dfChannelGen.getOutputIdentifierTemplates(); - for (IdentifierTemplate in: inputResources) { - for (IdentifierTemplate out: outputResources) { - dataFlowGraph.addEdge(in ,out, dfChannelGen); + for (Channel channel: getChannels()) { + DataTransferChannel dfChannel = (DataTransferChannel)channel; + Set inputResources = dfChannel.getInputResources(); + Set outputResources = dfChannel.getOutputResources(); + for (ResourcePath in: inputResources) { + for (ResourcePath out: outputResources) { + dataFlowGraph.addEdge(in ,out, dfChannel); } } } - for (ChannelGenerator channelGen: getIOChannelGenerators()) { - DataTransferChannelGenerator dfChannelGen = (DataTransferChannelGenerator)channelGen; - Set outputResources = dfChannelGen.getOutputIdentifierTemplates(); - for (IdentifierTemplate out: outputResources) { + for (Channel channel: getIOChannels()) { + DataTransferChannel dfChannel = (DataTransferChannel)channel; + Set outputResources = dfChannel.getOutputResources(); + for (ResourcePath out: outputResources) { dataFlowGraph.addNode(out); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java index 698eac3..ef286af 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java @@ -1,30 +1,30 @@ package models.dataFlowModel; import models.Node; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class ResourceNode extends Node { - protected IdentifierTemplate identifierTemplate = null; + protected ResourcePath resourcePath = null; - public ResourceNode(IdentifierTemplate identifierTemplate) { - this.identifierTemplate = identifierTemplate; + public ResourceNode(ResourcePath resourcePath) { + this.resourcePath = resourcePath; } - public IdentifierTemplate getIdentifierTemplate() { - return identifierTemplate; + public ResourcePath getResource() { + return resourcePath; } public boolean equals(Object another) { if (this == another) return true; if (!(another instanceof ResourceNode)) return false; - return identifierTemplate.equals(((ResourceNode)another).identifierTemplate); + return resourcePath.equals(((ResourceNode)another).resourcePath); } public int hashCode() { - return identifierTemplate.hashCode(); + return resourcePath.hashCode(); } public String toString() { - return identifierTemplate.getResourceName(); + return resourcePath.getResourceName(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java new file mode 100644 index 0000000..581d31e --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java @@ -0,0 +1,161 @@ +package models.visualModel; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import models.algebra.Expression; +import models.algebra.Symbol; +import models.algebra.Term; +import models.algebra.Variable; +import models.dataConstraintModel.ChannelMember; +import models.dataConstraintModel.DataConstraintModel; +import models.dataConstraintModel.ResourcePath; +import models.dataConstraintModel.StateTransition; +import models.dataFlowModel.DataTransferChannel; + +public class FormulaChannel extends DataTransferChannel { + private Symbol defaultOperator = null; + private String formula = null; + private Expression formulaRhs = null; + + public FormulaChannel(String channelName, Symbol defaultOperator) { + super(channelName); + this.defaultOperator = defaultOperator; + } + + public void addChannelMemberAsInput(ChannelMember channelMember) { +// StateTransition st = new StateTransition(); +// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); +// st.setNextStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "2")); +// channelMember.setStateTransition(st); + super.addChannelMemberAsInput(channelMember); + if (formula != null && getInputChannelMembers().size() > 1) { + formula += " " + defaultOperator + " " + channelMember.getResource().getResourceName(); + if (formulaRhs != null) { + if (formulaRhs instanceof Variable) { + Term newTerm = new Term(defaultOperator); + newTerm.addChild(formulaRhs); + newTerm.addChild(new Variable(channelMember.getResource().getResourceName()), true); + formulaRhs = newTerm; + } else if (formulaRhs instanceof Term) { + Term newTerm = new Term(defaultOperator); + newTerm.addChild(formulaRhs); + newTerm.addChild(new Variable(channelMember.getResource().getResourceName())); + formulaRhs = newTerm; + } + } + } else { + if (formula == null) formula = ""; + formula += channelMember.getResource().getResourceName(); + formulaRhs = new Variable(channelMember.getResource().getResourceName()); + } + if (formulaRhs != null) { + setFormulaTerm(formulaRhs); + } + } + + public void addChannelMemberAsOutput(ChannelMember channelMember) { +// StateTransition st = new StateTransition(); +// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); +// channelMember.setStateTransition(st); + super.addChannelMemberAsOutput(channelMember); + if (getOutputChannelMembers().size() == 1) { + if (formula == null) formula = ""; + if (!formula.contains("==")) { + formula = channelMember.getResource().getResourceName() + " == " + formula; + } + } + if (formulaRhs != null) { + setFormulaTerm(formulaRhs); + } + } + + public Symbol getDefaultOperator() { + return defaultOperator; + } + + public void setDefaultOperator(Symbol defaultOperator) { + this.defaultOperator = defaultOperator; + } + + public void setFormulaTerm(Expression rhs) { + formulaRhs = rhs; + Collection variables; + if (rhs instanceof Variable) { + variables = new ArrayList<>(); + variables.add((Variable) rhs); + } else if (rhs instanceof Term) { + variables = ((Term) rhs).getVariables().values(); + } else { + return; + } + Map curStates = new HashMap<>(); + Map nextStates = new HashMap<>(); + Map resToNextVar = new HashMap<>(); + for (ChannelMember cm: this.getInputChannelMembers()) { + ResourcePath id = cm.getResource(); + String resName = id.getResourceName(); + Variable curVar = new Variable(resName + "1"); + Variable nextVar = new Variable(resName + "2"); + curStates.put(id, curVar); + nextStates.put(id, nextVar); + for (Variable var: variables) { + if (var.getName().equals(resName)) { + resToNextVar.put(var, nextVar); + break; + } + } + } + Symbol update = new Symbol("update"); + update.setArity(resToNextVar.keySet().size()); + for (ChannelMember cm: getInputChannelMembers()) { + ResourcePath id = cm.getResource(); + StateTransition st = new StateTransition(); + st.setCurStateExpression(curStates.get(id)); + st.setNextStateExpression(nextStates.get(id)); + Term message = new Term(update); + for (Variable var: resToNextVar.values()) { + message.addChild(var); + } + st.setMessageExpression(message); + cm.setStateTransition(st); + } + + if (rhs instanceof Variable) { + rhs = resToNextVar.get((Variable) rhs); + } else if (rhs instanceof Term) { + formulaRhs = rhs; + for (Variable var: resToNextVar.keySet()) { + rhs = ((Term) rhs).substitute(var, resToNextVar.get(var)); + } + } + for (ChannelMember cm: getOutputChannelMembers()) { + ResourcePath id = cm.getResource(); + StateTransition st = new StateTransition(); + String resName = id.getResourceName(); + Variable curVar = new Variable(resName + "1"); + st.setCurStateExpression(curVar); + st.setNextStateExpression(rhs); + Term message = new Term(update); + for (Variable var: resToNextVar.values()) { + message.addChild(var); + } + st.setMessageExpression(message); + cm.setStateTransition(st); + } + } + + public Expression getFormulaTerm() { + return formulaRhs; + } + + public void setFormula(String formula) { + this.formula = formula; + } + + public String getFormula() { + return formula; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannelGenerator.java deleted file mode 100644 index 4bbfe7e..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannelGenerator.java +++ /dev/null @@ -1,161 +0,0 @@ -package models.visualModel; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import models.algebra.Expression; -import models.algebra.Symbol; -import models.algebra.Term; -import models.algebra.Variable; -import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataConstraintModel.StateTransition; -import models.dataFlowModel.DataTransferChannelGenerator; - -public class FormulaChannelGenerator extends DataTransferChannelGenerator { - private Symbol defaultOperator = null; - private String formula = null; - private Expression formulaRhs = null; - - public FormulaChannelGenerator(String channelName, Symbol defaultOperator) { - super(channelName); - this.defaultOperator = defaultOperator; - } - - public void addChannelMemberAsInput(ChannelMember channelMember) { -// StateTransition st = new StateTransition(); -// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); -// st.setNextStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "2")); -// channelMember.setStateTransition(st); - super.addChannelMemberAsInput(channelMember); - if (formula != null && getInputChannelMembers().size() > 1) { - formula += " " + defaultOperator + " " + channelMember.getIdentifierTemplate().getResourceName(); - if (formulaRhs != null) { - if (formulaRhs instanceof Variable) { - Term newTerm = new Term(defaultOperator); - newTerm.addChild(formulaRhs); - newTerm.addChild(new Variable(channelMember.getIdentifierTemplate().getResourceName()), true); - formulaRhs = newTerm; - } else if (formulaRhs instanceof Term) { - Term newTerm = new Term(defaultOperator); - newTerm.addChild(formulaRhs); - newTerm.addChild(new Variable(channelMember.getIdentifierTemplate().getResourceName())); - formulaRhs = newTerm; - } - } - } else { - if (formula == null) formula = ""; - formula += channelMember.getIdentifierTemplate().getResourceName(); - formulaRhs = new Variable(channelMember.getIdentifierTemplate().getResourceName()); - } - if (formulaRhs != null) { - setFormulaTerm(formulaRhs); - } - } - - public void addChannelMemberAsOutput(ChannelMember channelMember) { -// StateTransition st = new StateTransition(); -// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); -// channelMember.setStateTransition(st); - super.addChannelMemberAsOutput(channelMember); - if (getOutputChannelMembers().size() == 1) { - if (formula == null) formula = ""; - if (!formula.contains("==")) { - formula = channelMember.getIdentifierTemplate().getResourceName() + " == " + formula; - } - } - if (formulaRhs != null) { - setFormulaTerm(formulaRhs); - } - } - - public Symbol getDefaultOperator() { - return defaultOperator; - } - - public void setDefaultOperator(Symbol defaultOperator) { - this.defaultOperator = defaultOperator; - } - - public void setFormulaTerm(Expression rhs) { - formulaRhs = rhs; - Collection variables; - if (rhs instanceof Variable) { - variables = new ArrayList<>(); - variables.add((Variable) rhs); - } else if (rhs instanceof Term) { - variables = ((Term) rhs).getVariables().values(); - } else { - return; - } - Map curStates = new HashMap<>(); - Map nextStates = new HashMap<>(); - Map resToNextVar = new HashMap<>(); - for (ChannelMember cm: this.getInputChannelMembers()) { - IdentifierTemplate id = cm.getIdentifierTemplate(); - String resName = id.getResourceName(); - Variable curVar = new Variable(resName + "1"); - Variable nextVar = new Variable(resName + "2"); - curStates.put(id, curVar); - nextStates.put(id, nextVar); - for (Variable var: variables) { - if (var.getName().equals(resName)) { - resToNextVar.put(var, nextVar); - break; - } - } - } - Symbol update = new Symbol("update"); - update.setArity(resToNextVar.keySet().size()); - for (ChannelMember cm: getInputChannelMembers()) { - IdentifierTemplate id = cm.getIdentifierTemplate(); - StateTransition st = new StateTransition(); - st.setCurStateExpression(curStates.get(id)); - st.setNextStateExpression(nextStates.get(id)); - Term message = new Term(update); - for (Variable var: resToNextVar.values()) { - message.addChild(var); - } - st.setMessageExpression(message); - cm.setStateTransition(st); - } - - if (rhs instanceof Variable) { - rhs = resToNextVar.get((Variable) rhs); - } else if (rhs instanceof Term) { - formulaRhs = rhs; - for (Variable var: resToNextVar.keySet()) { - rhs = ((Term) rhs).substitute(var, resToNextVar.get(var)); - } - } - for (ChannelMember cm: getOutputChannelMembers()) { - IdentifierTemplate id = cm.getIdentifierTemplate(); - StateTransition st = new StateTransition(); - String resName = id.getResourceName(); - Variable curVar = new Variable(resName + "1"); - st.setCurStateExpression(curVar); - st.setNextStateExpression(rhs); - Term message = new Term(update); - for (Variable var: resToNextVar.values()) { - message.addChild(var); - } - st.setMessageExpression(message); - cm.setStateTransition(st); - } - } - - public Expression getFormulaTerm() { - return formulaRhs; - } - - public void setFormula(String formula) { - this.formula = formula; - } - - public String getFormula() { - return formula; - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index ed9aaf9..876ee6f 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -14,10 +14,10 @@ import models.algebra.Type; import models.algebra.Variable; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataConstraintModel.StateTransition; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import parser.exceptions.ExpectedAssignment; import parser.exceptions.ExpectedChannel; import parser.exceptions.ExpectedChannelName; @@ -86,18 +86,18 @@ public DataTransferModel parseDataFlowModel() throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment { DataTransferModel model = new DataTransferModel(); - DataTransferChannelGenerator channel; + DataTransferChannel channel; while ((channel = parseChannel(model)) != null) { if (channel.getInputChannelMembers().size() == 0) { - model.addIOChannelGenerator(channel); + model.addIOChannel(channel); } else { - model.addChannelGenerator(channel); + model.addChannel(channel); } } return model; } - public DataTransferChannelGenerator parseChannel(DataTransferModel model) + public DataTransferChannel parseChannel(DataTransferModel model) throws ExpectedLeftCurlyBracket, ExpectedRightBracket, ExpectedAssignment, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, @@ -119,7 +119,7 @@ if (channelName.equals(LEFT_CURLY_BRACKET)) throw new ExpectedChannelName(stream.getLine()); int fromLine = stream.getLine(); - DataTransferChannelGenerator channel = new DataTransferChannelGenerator(channelName); + DataTransferChannel channel = new DataTransferChannel(channelName); String leftBracket = stream.next(); if (!leftBracket.equals(LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); @@ -159,10 +159,10 @@ String resourceName = null; while (stream.hasNext() && !(resourceName = stream.next()).equals(RIGHT_CURLY_BRACKET)) { int fromLine = stream.getLine(); - IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); - if (identifier == null) { - identifier = new IdentifierTemplate(resourceName, 0); - model.addIdentifierTemplate(identifier); + ResourcePath resourcePath = model.getResourcePath(resourceName); + if (resourcePath == null) { + resourcePath = new ResourcePath(resourceName, 0); + model.addResourcePath(resourcePath); } if (!stream.hasNext()) throw new ExpectedAssignment(stream.getLine()); @@ -178,8 +178,8 @@ rightTerm = parseTerm(stream, model); if (rightTerm == null) throw new WrongRHSExpression(stream.getLine()); - identifier.setInitialValue(rightTerm); - identifier.setInitText(stream.getSourceText(fromLine, toLine)); + resourcePath.setInitialValue(rightTerm); + resourcePath.setInitText(stream.getSourceText(fromLine, toLine)); } } @@ -204,22 +204,22 @@ } String resourceName = ((Term) leftTerm).getSymbol().getName(); - IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); - if (identifier == null) { - identifier = new IdentifierTemplate(resourceName, 0); - model.addIdentifierTemplate(identifier); + ResourcePath resourcePath = model.getResourcePath(resourceName); + if (resourcePath == null) { + resourcePath = new ResourcePath(resourceName, 0); + model.addResourcePath(resourcePath); } - ChannelMember channelMember = new ChannelMember(identifier); + ChannelMember channelMember = new ChannelMember(resourcePath); StateTransition stateTransition = new StateTransition(); stateTransition.setCurStateExpression(((Term) leftTerm).getChild(0)); stateTransition.setMessageExpression(((Term) leftTerm).getChild(1)); if (!inOrOutOrRef.equals(REF)) stateTransition.setNextStateExpression(rightTerm); channelMember.setStateTransition(stateTransition); // for type definition - if (identifier.getResourceStateType() == null && ((Term) leftTerm).getChild(0) instanceof Variable) { + if (resourcePath.getResourceStateType() == null && ((Term) leftTerm).getChild(0) instanceof Variable) { Variable stateVar = (Variable) ((Term) leftTerm).getChild(0); if (stateVar.getType() != null) { - identifier.setResourceStateType(stateVar.getType()); + resourcePath.setResourceStateType(stateVar.getType()); } } if (((Term) leftTerm).getChild(1) instanceof Term) { diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java index 5719cac..afe405a 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java @@ -12,25 +12,25 @@ public void test() { // Construct a data constraint architecture model. DataConstraintModel model = new DataConstraintModel(); - IdentifierTemplate customer_off = new IdentifierTemplate("customers.{customer_id}.off", 1); - IdentifierTemplate customer_add = new IdentifierTemplate("customers.{customer_id}.add", 1); - IdentifierTemplate company_add = new IdentifierTemplate("companies.{company_id}.add", 1); + ResourcePath customer_off = new ResourcePath("customers.{customer_id}.off", 1); + ResourcePath customer_add = new ResourcePath("customers.{customer_id}.add", 1); + ResourcePath company_add = new ResourcePath("companies.{company_id}.add", 1); - ChannelGenerator gin_1 = new ChannelGenerator("gin_1"); // set customer's office + Channel gin_1 = new Channel("gin_1"); // set customer's office GroupSelector x1 = new GroupSelector(); ChannelMember customer_off_1 = new ChannelMember(customer_off); customer_off_1.addSelector(x1); gin_1.addChannelMember(customer_off_1); assertEquals(customer_off.getNumberOfParameters(), customer_off_1.getSelectors().size()); - ChannelGenerator gin_2 = new ChannelGenerator("gin_2"); // set companie's address + Channel gin_2 = new Channel("gin_2"); // set companie's address GroupSelector x2 = new GroupSelector(); ChannelMember company_add_1 = new ChannelMember(company_add); company_add_1.addSelector(x2); gin_2.addChannelMember(company_add_1); assertEquals(company_add.getNumberOfParameters(), company_add_1.getSelectors().size()); - ChannelGenerator g = new ChannelGenerator("g"); // update customer's address + Channel g = new Channel("g"); // update customer's address GroupSelector x3 = new GroupSelector(); ChannelSelector y = new ChannelSelector(); ChannelMember customer_off_2 = new ChannelMember(customer_off); @@ -46,14 +46,14 @@ assertEquals(customer_add.getNumberOfParameters(), customer_add_2.getSelectors().size()); assertEquals(company_add.getNumberOfParameters(), company_add_2.getSelectors().size()); - model.addIOChannelGenerator(gin_1); - model.addIOChannelGenerator(gin_2); - model.addChannelGenerator(g); + model.addIOChannel(gin_1); + model.addIOChannel(gin_2); + model.addChannel(g); // Check the model. - assertEquals(3, model.getIdentifierTemplates().size()); - assertEquals(2, model.getIOChannelGenerators().size()); - assertEquals(1, model.getChannelGenerators().size()); + assertEquals(3, model.getResourcePaths().size()); + assertEquals(2, model.getIOChannels().size()); + assertEquals(1, model.getChannels().size()); } } diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java index 6065992..605b006 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java @@ -14,16 +14,16 @@ public void test() { // Construct a data-flow architecture model. DataTransferModel model = new DataTransferModel(); - IdentifierTemplate customer_off = new IdentifierTemplate("customers.{x1}.off", 1); // an identifier template to specify a customer's office resource - IdentifierTemplate company_add = new IdentifierTemplate("companies.{x2}.add", 1); // an identifier template to specify a companie's address resource - IdentifierTemplate customer_add = new IdentifierTemplate("customers.{x1}.add", 1); // an identifier template to specify a customer's address resource + ResourcePath customer_off = new ResourcePath("customers.{x1}.off", 1); // an identifier template to specify a customer's office resource + ResourcePath company_add = new ResourcePath("companies.{x2}.add", 1); // an identifier template to specify a companie's address resource + ResourcePath customer_add = new ResourcePath("customers.{x1}.add", 1); // an identifier template to specify a customer's address resource // === gin_1 === // // customers.{x1}.off(c, set(x)) == x // customers.{x1}.off(c, e) == c // - DataTransferChannelGenerator gin_1 = new DataTransferChannelGenerator("gin_1"); // set customer's office (an input channel) + DataTransferChannel gin_1 = new DataTransferChannel("gin_1"); // set customer's office (an input channel) GroupSelector x1 = new GroupSelector(); ChannelMember customer_off_1 = new ChannelMember(customer_off); customer_off_1.addSelector(x1); // x1 is determined by the path parameter in customer's office template, and serves as a group selector in this channel @@ -35,7 +35,7 @@ // companies.{x2}.add(a, set(y)) == y // companies.{x2}.add(a, e) == a // - DataTransferChannelGenerator gin_2 = new DataTransferChannelGenerator("gin_2"); // set companie's address (an input channel) + DataTransferChannel gin_2 = new DataTransferChannel("gin_2"); // set companie's address (an input channel) GroupSelector x2 = new GroupSelector(); ChannelMember company_add_1 = new ChannelMember(company_add); company_add_1.addSelector(x2); // x2 is determined by the path parameter in companie's address template, and serves as a group selector in this channel @@ -48,7 +48,7 @@ // companies.{y}.add( a1, update(y, z)) == z // customers.{x3}.add(a2, update(y, z)) == z // - DataTransferChannelGenerator g = new DataTransferChannelGenerator("g"); // update customer's address + DataTransferChannel g = new DataTransferChannel("g"); // update customer's address GroupSelector x3 = new GroupSelector(); ChannelSelector y = new ChannelSelector(); ChannelMember customer_off_2 = new ChannelMember(customer_off); @@ -65,14 +65,14 @@ assertEquals(company_add.getNumberOfParameters(), company_add_2.getSelectors().size()); // Construct a data-flow architecture model. - model.addIOChannelGenerator(gin_1); - model.addIOChannelGenerator(gin_2); - model.addChannelGenerator(g); + model.addIOChannel(gin_1); + model.addIOChannel(gin_2); + model.addChannel(g); // Check the model. - assertEquals(3, model.getIdentifierTemplates().size()); - assertEquals(2, model.getIOChannelGenerators().size()); - assertEquals(1, model.getChannelGenerators().size()); + assertEquals(3, model.getResourcePaths().size()); + assertEquals(2, model.getIOChannels().size()); + assertEquals(1, model.getChannels().size()); // Extract the resource dependency graph. DataFlowGraph resourceDependencyGraph = model.getDataFlowGraph(); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java index 67a1a2a..9d28936 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java @@ -35,7 +35,7 @@ DataTransferModelAnalyzer.annotateWithSelectableDataTransferAttiribute(graph); DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); for(Node n:graph.getNodes()) { - System.out.println(((ResourceNode) n).getIdentifierTemplate().getResourceName() + ":" + ((StoreAttribute) ((ResourceNode) n).getAttribute()).isStored()); + System.out.println(((ResourceNode) n).getResource().getResourceName() + ":" + ((StoreAttribute) ((ResourceNode) n).getAttribute()).isStored()); } } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression diff --git a/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java index 2cf2b37..a8f3503 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java @@ -5,18 +5,18 @@ import models.algebra.Symbol; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; -import models.visualModel.FormulaChannelGenerator; +import models.dataConstraintModel.ResourcePath; +import models.visualModel.FormulaChannel; public class FormulaChannelTest { @Test public void test() { - IdentifierTemplate id1 = new IdentifierTemplate("r1", 0); - IdentifierTemplate id2 = new IdentifierTemplate("r2", 0); - IdentifierTemplate id3 = new IdentifierTemplate("r3", 0); + ResourcePath id1 = new ResourcePath("r1", 0); + ResourcePath id2 = new ResourcePath("r2", 0); + ResourcePath id3 = new ResourcePath("r3", 0); - FormulaChannelGenerator ch1 = new FormulaChannelGenerator("ch1", DataConstraintModel.add); + FormulaChannel ch1 = new FormulaChannel("ch1", DataConstraintModel.add); System.out.println(ch1.getFormula()); System.out.println(ch1.getFormulaTerm()); System.out.println(ch1.getSourceText()); @@ -33,7 +33,7 @@ System.out.println(ch1.getFormulaTerm()); System.out.println(ch1.getSourceText()); - FormulaChannelGenerator ch2 = new FormulaChannelGenerator("ch2", DataConstraintModel.mul); + FormulaChannel ch2 = new FormulaChannel("ch2", DataConstraintModel.mul); System.out.println(ch2.getFormula()); System.out.println(ch2.getFormulaTerm()); System.out.println(ch2.getSourceText()); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java index ff262b2..acb5333 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java @@ -14,16 +14,16 @@ public void test() { // Construct a data-flow architecture model. DataTransferModel model = new DataTransferModel(); - IdentifierTemplate payment = new IdentifierTemplate("payment", 0); // an identifier template to specify the payment resource - IdentifierTemplate loyalty = new IdentifierTemplate("loyalty", 0); // an identifier template to specify the loyalty resource - IdentifierTemplate history = new IdentifierTemplate("history", 0); // an identifier template to specify the payment history resource - IdentifierTemplate total = new IdentifierTemplate("total", 0); // an identifier template to specify the total payment resource + ResourcePath payment = new ResourcePath("payment", 0); // a resource to specify the payment resource + ResourcePath loyalty = new ResourcePath("loyalty", 0); // a resource to specify the loyalty resource + ResourcePath history = new ResourcePath("history", 0); // a resource to specify the payment history resource + ResourcePath total = new ResourcePath("total", 0); // a resource to specify the total payment resource // === cin === // // payment(p1, purchase(x)) == x // - DataTransferChannelGenerator cin = new DataTransferChannelGenerator("cin"); + DataTransferChannel cin = new DataTransferChannel("cin"); ChannelMember cin_payment = new ChannelMember(payment); cin.addChannelMember(cin_payment); assertEquals(cin.getChannelMembers().size(), 1); @@ -33,7 +33,7 @@ // payment(p1, update1(y)) == y // loyalty(l, update1(y)) == floor(y * 0.05) // - DataTransferChannelGenerator c1 = new DataTransferChannelGenerator("c1"); + DataTransferChannel c1 = new DataTransferChannel("c1"); ChannelMember c1_payment = new ChannelMember(payment); ChannelMember c1_loyalty = new ChannelMember(loyalty); c1.addChannelMemberAsInput(c1_payment); @@ -47,7 +47,7 @@ // payment(p1, update2(z)) == z // history(h, update2(z)) == cons(z, h) // - DataTransferChannelGenerator c2 = new DataTransferChannelGenerator("c2"); + DataTransferChannel c2 = new DataTransferChannel("c2"); ChannelMember c2_payment = new ChannelMember(payment); ChannelMember c2_history = new ChannelMember(history); c2.addChannelMemberAsInput(c2_payment); @@ -61,7 +61,7 @@ // history(h, update3(u)) == u // total(t, update3(u)) == sum(u) // - DataTransferChannelGenerator c3 = new DataTransferChannelGenerator("c3"); + DataTransferChannel c3 = new DataTransferChannel("c3"); ChannelMember c3_history = new ChannelMember(history); ChannelMember c3_total = new ChannelMember(total); c3.addChannelMemberAsInput(c3_history); @@ -71,15 +71,15 @@ assertEquals(c3.getOutputChannelMembers().size(), 1); // Construct a data-flow architecture model. - model.addIOChannelGenerator(cin); - model.addChannelGenerator(c1); - model.addChannelGenerator(c2); - model.addChannelGenerator(c3); + model.addIOChannel(cin); + model.addChannel(c1); + model.addChannel(c2); + model.addChannel(c3); // Check the model. - assertEquals(4, model.getIdentifierTemplates().size()); - assertEquals(1, model.getIOChannelGenerators().size()); - assertEquals(3, model.getChannelGenerators().size()); + assertEquals(4, model.getResourcePaths().size()); + assertEquals(1, model.getIOChannels().size()); + assertEquals(3, model.getChannels().size()); // Extract the resource dependency graph. DataFlowGraph resourceDependencyGraph = model.getDataFlowGraph(); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java index cfd510c..69a5b1f 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java @@ -13,8 +13,8 @@ import models.algebra.Variable; import models.dataConstraintModel.*; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; public class UpdateCodeGenerationTest { @@ -25,10 +25,10 @@ Symbol sum = new Symbol("sum", 1, Symbol.Type.PREFIX, "stream().mapToInt(x->x).sum", Symbol.Type.METHOD); // resources - IdentifierTemplate payment = new IdentifierTemplate("payment", DataConstraintModel.typeInt, 0); // an identifier template to specify the payment resource - IdentifierTemplate loyalty = new IdentifierTemplate("loyalty", DataConstraintModel.typeInt, 0); // an identifier template to specify the loyalty resource - IdentifierTemplate history = new IdentifierTemplate("history", DataConstraintModel.typeList, 0);// an identifier template to specify the payment history resource - IdentifierTemplate total = new IdentifierTemplate("total", DataConstraintModel.typeInt, 0); // an identifier template to specify the total payment resource + ResourcePath payment = new ResourcePath("payment", DataConstraintModel.typeInt, 0); // a resource to specify the payment resource + ResourcePath loyalty = new ResourcePath("loyalty", DataConstraintModel.typeInt, 0); // a resource to specify the loyalty resource + ResourcePath history = new ResourcePath("history", DataConstraintModel.typeList, 0);// a resource to specify the payment history resource + ResourcePath total = new ResourcePath("total", DataConstraintModel.typeInt, 0); // a resource to specify the total payment resource // fields in the Java program final Field fPayment = new Field("payment", DataConstraintModel.typeInt); @@ -42,7 +42,7 @@ final Parameter pTotal = new Parameter("total", DataConstraintModel.typeInt); IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { if (target.equals(payment)) return fPayment; if (target.equals(loyalty)) return fLoyalty; @@ -52,7 +52,7 @@ return null; } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(payment)) return pPayment; if (target.equals(loyalty)) return pLoyalty; if (target.equals(history)) return pHistory; @@ -68,7 +68,7 @@ final Symbol totalGetter = new Symbol("getTotal", 1, Symbol.Type.METHOD); IResourceStateAccessor pullAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { if (target.equals(payment)) return fPayment; if (target.equals(loyalty)) return fLoyalty; @@ -78,7 +78,7 @@ return null; } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(payment)) { Term getter = new Term(paymentGetter); getter.addChild(fPayment); @@ -108,7 +108,7 @@ // payment(p1, update1(y)) == y // loyalty(l, update1(y)) == floor(y * 0.05) // - DataTransferChannelGenerator c1 = new DataTransferChannelGenerator("c1"); + DataTransferChannel c1 = new DataTransferChannel("c1"); ChannelMember c1_payment = new ChannelMember(payment); ChannelMember c1_loyalty = new ChannelMember(loyalty); c1.addChannelMemberAsInput(c1_payment); @@ -175,7 +175,7 @@ // payment(p1, update2(z)) == z // history(h, update2(z)) == cons(z, h) // - DataTransferChannelGenerator c2 = new DataTransferChannelGenerator("c2"); + DataTransferChannel c2 = new DataTransferChannel("c2"); ChannelMember c2_payment = new ChannelMember(payment); ChannelMember c2_history = new ChannelMember(history); c2.addChannelMemberAsInput(c2_payment); @@ -238,7 +238,7 @@ // history(h, update3(u)) = u // total(t, update3(u)) = sum(u) // - DataTransferChannelGenerator c3 = new DataTransferChannelGenerator("c3"); + DataTransferChannel c3 = new DataTransferChannel("c3"); ChannelMember c3_history = new ChannelMember(history); ChannelMember c3_total = new ChannelMember(total); c3.addChannelMemberAsInput(c3_history); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java b/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java index 008d004..a1ea0a3 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java @@ -10,7 +10,7 @@ import models.algebra.ParameterizedIdentifierIsFutureWork; import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataFlowModel.*; import parser.Parser; @@ -37,10 +37,10 @@ model = parser.doParse(); System.out.println(model); - for (ChannelGenerator c: model.getChannelGenerators()) { - for (ChannelMember out: ((DataTransferChannelGenerator) c).getOutputChannelMembers()) { + for (Channel c: model.getChannels()) { + for (ChannelMember out: ((DataTransferChannel) c).getOutputChannelMembers()) { String[] sideEffects = new String[] {""}; - System.out.println("next" + out.getIdentifierTemplate().getResourceName() + " = " + ((DataTransferChannelGenerator) c).deriveUpdateExpressionOf(out).toImplementation(sideEffects)); + System.out.println("next" + out.getResource().getResourceName() + " = " + ((DataTransferChannel) c).deriveUpdateExpressionOf(out).toImplementation(sideEffects)); } }