diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java index 35ef30a..c18d220 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Accounts.java @@ -35,13 +35,13 @@ public Map getNotificationsValue(@PathParam("aid") String aid) { return getAccount(aid).getNotifications(); } + @POST + public void signUp(@FormParam("aid") String aid) { + this.value.put(aid,new Account(new HashMap<>())); + } @Path("/{aid}/notifications") @DELETE public void hasRead(@PathParam("aid") String aid, @FormParam("gid") String gid) { getAccount(aid).hasRead(aid, gid); } - @POST - public void signUp(@FormParam("aid") String aid) { - this.value.put(aid,new Account(new HashMap<>())); - } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java index 3579e08..bb06954 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Group.java @@ -7,16 +7,16 @@ private Client client = ClientBuilder.newClient(); public Map getValue() { Map temp_nil2 = new HashMap<>(); - temp_nil2.put("messages",this.getMessages()); temp_nil2.put("members",this.getMembers()); + temp_nil2.put("messages",this.getMessages()); return temp_nil2; } - public String getMember(int mno) { - return this.members.get(mno); - } public List getMembers() { return this.members; } + public String getMember(int mno) { + return this.members.get(mno); + } public List getMessages() { return this.messages; } @@ -31,7 +31,7 @@ } form.param("member", member.toString()); Entity
entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path("/accounts."+member+".notifications").request().post(entity, String.class); + String result = client.target("http://localhost:8080").path("/accounts/"+member+"/notifications").request().post(entity, String.class); } this.messages.add(message); } diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java index e00259d..19b1f42 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/GroupChat/Groups.java @@ -18,18 +18,6 @@ public Group getGroup(String gid) { return this.value.get(gid); } - @Path("/{gid}/members/{mno}") - @Produces(MediaType.APPLICATION_JSON) - @GET - public String getMemberValue(@PathParam("gid") String gid, @PathParam("mno") int mno) { - return getGroup(gid).getMember(mno); - } - @Path("/{gid}/messages") - @Produces(MediaType.APPLICATION_JSON) - @GET - public List getMessagesValue(@PathParam("gid") String gid) { - return getGroup(gid).getMessages(); - } @Path("/{gid}") @Produces(MediaType.APPLICATION_JSON) @GET @@ -43,6 +31,23 @@ return getGroup(gid).getMembers(); } @Path("/{gid}/messages") + @Produces(MediaType.APPLICATION_JSON) + @GET + public List getMessagesValue(@PathParam("gid") String gid) { + return getGroup(gid).getMessages(); + } + @Path("/{gid}/members/{mno}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public String getMemberValue(@PathParam("gid") String gid, @PathParam("mno") int mno) { + return getGroup(gid).getMember(mno); + } + @Path("/{gid}/members") + @POST + public void addGroupMember(@PathParam("gid") String gid, @FormParam("aid") String aid) { + getGroup(gid).addGroupMember(gid, aid); + } + @Path("/{gid}/messages") @POST public void postMessage(@PathParam("gid") String gid, @FormParam("message") String message) throws JsonProcessingException { getGroup(gid).postMessage(gid, message); @@ -51,9 +56,4 @@ public void createGroup(@FormParam("gid") String gid) { this.value.put(gid,new Group(new ArrayList<>(), new ArrayList<>())); } - @Path("/{gid}/members") - @POST - public void addGroupMember(@PathParam("gid") String gid, @FormParam("aid") String aid) { - getGroup(gid).addGroupMember(gid, aid); - } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java index f7594e2..31bc4bd 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Account.java @@ -1,27 +1,27 @@ import java.util.*; public class Account { - private int point; private String name; + private int point; public Map getValue() { - Map temp_nil4 = new HashMap<>(); - temp_nil4.put("name",this.getName()); - temp_nil4.put("point",this.getPoint()); - return temp_nil4; - } - public int getPoint() { - return point; + Map temp_nil5 = new HashMap<>(); + temp_nil5.put("point",this.getPoint()); + temp_nil5.put("name",this.getName()); + return temp_nil5; } public String getName() { return this.name; } + public int getPoint() { + return point; + } public void updatePointFromBattle(String self, String rid, int mno, boolean battle, String id) { - int temp_if1; + int temp_if0; if (battle) { - temp_if1 = (this.point+1); + temp_if0 = (this.point+1); } else { - temp_if1 = this.point; - }this.point = temp_if1; + temp_if0 = this.point; + }this.point = temp_if0; } public void changeName(String aid, String name) { this.name = name; diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java index 9ec4085..fc4d20e 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Accounts.java @@ -23,31 +23,31 @@ public void updatePointFromBattle(@PathParam("mid") String mid, @FormParam("rid") String rid, @FormParam("mno") int mno, @FormParam("battle") boolean battle, @FormParam("id") String id) { getAccount(mid).updatePointFromBattle(mid, rid, mno, battle, id); } - @Path("/{mid}") - @Produces(MediaType.APPLICATION_JSON) - @GET - public Map getAccountValue(@PathParam("mid") String mid) { - return getAccount(mid).getValue(); - } @Path("/{mid}/point") @Produces(MediaType.APPLICATION_JSON) @GET public int getPointValue(@PathParam("mid") String mid) { return getAccount(mid).getPoint(); } + @Path("/{mid}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getAccountValue(@PathParam("mid") String mid) { + return getAccount(mid).getValue(); + } @Path("/{mid}/name") @Produces(MediaType.APPLICATION_JSON) @GET public String getNameValue(@PathParam("mid") String mid) { return getAccount(mid).getName(); } + @POST + public void signUp(@FormParam("name") String name, @FormParam("aid") String aid) { + this.value.put(aid,new Account(name, 0)); + } @Path("/{aid}/name") @PUT public void changeName(@PathParam("aid") String aid, @FormParam("name") String name) { getAccount(aid).changeName(aid, name); } - @POST - public void signUp(@FormParam("name") String name, @FormParam("aid") String aid) { - this.value.put(aid,new Account(name, 0)); - } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java index e566317..d12c2cf 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Member.java @@ -5,16 +5,16 @@ private String id; private Client client = ClientBuilder.newClient(); public Map getValue() { - Map temp_nil5 = new HashMap<>(); - temp_nil5.put("name",this.getName()); - temp_nil5.put("id",this.getId()); - return temp_nil5; + Map temp_nil6 = new HashMap<>(); + temp_nil6.put("id",this.getId()); + temp_nil6.put("name",this.getName()); + return temp_nil6; } public String getId() { return this.id; } public String getName() { - String name = client.target("http://localhost:8080").path("/accounts."+id+".name").request().get(String.class); + String name = client.target("http://localhost:8080").path("/accounts/"+id+"/name").request().get(String.class); return name; } public Member(String id) { diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java index 55dce69..edbdd93 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Room.java @@ -6,10 +6,10 @@ private boolean battle; private Client client = ClientBuilder.newClient(); public Map getValue() { - Map temp_nil3 = new HashMap<>(); - temp_nil3.put("members",this.members.getValue()); - temp_nil3.put("battle",this.getBattle()); - return temp_nil3; + Map temp_nil4 = new HashMap<>(); + temp_nil4.put("battle",this.getBattle()); + temp_nil4.put("members",this.members.getValue()); + return temp_nil4; } public Members getMembers() { return this.members; @@ -26,7 +26,7 @@ form.param("battle", Boolean.toString(battle)); form.param("id", id.toString()); Entity entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED); - String result = client.target("http://localhost:8080").path("/accounts."+id+".point").request().post(entity, String.class); + String result = client.target("http://localhost:8080").path("/accounts/"+id+"/point").request().post(entity, String.class); } this.battle = hasWon; } diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java index c0b7951..818eebd 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/OnlineBattleGame2/Rooms.java @@ -18,54 +18,54 @@ public Room getRoom(String rid) { return this.value.get(rid); } - @Path("/{rid}/members/{mno}/name") - @Produces(MediaType.APPLICATION_JSON) - @GET - public String getNameValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { - return getRoom(rid).getMembers().getMember(mno).getName(); - } - @Path("/{rid}/members/{mno}") - @Produces(MediaType.APPLICATION_JSON) - @GET - public Map getMemberValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { - return getRoom(rid).getMembers().getMember(mno).getValue(); - } @Path("/{rid}") @Produces(MediaType.APPLICATION_JSON) @GET public Map getRoomValue(@PathParam("rid") String rid) { return getRoom(rid).getValue(); } - @Path("/{rid}/members") - @Produces(MediaType.APPLICATION_JSON) - @GET - public List getMembersValue(@PathParam("rid") String rid) { - return getRoom(rid).getMembers().getValue(); - } @Path("/{rid}/members/{mno}/id") @Produces(MediaType.APPLICATION_JSON) @GET public String getIdValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { return getRoom(rid).getMembers().getMember(mno).getId(); } + @Path("/{rid}/members/{mno}") + @Produces(MediaType.APPLICATION_JSON) + @GET + public Map getMemberValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { + return getRoom(rid).getMembers().getMember(mno).getValue(); + } @Path("/{rid}/battle") @Produces(MediaType.APPLICATION_JSON) @GET public boolean getBattleValue(@PathParam("rid") String rid) { return getRoom(rid).getBattle(); } + @Path("/{rid}/members/{mno}/name") + @Produces(MediaType.APPLICATION_JSON) + @GET + public String getNameValue(@PathParam("rid") String rid, @PathParam("mno") int mno) { + return getRoom(rid).getMembers().getMember(mno).getName(); + } + @Path("/{rid}/members") + @Produces(MediaType.APPLICATION_JSON) + @GET + public List getMembersValue(@PathParam("rid") String rid) { + return getRoom(rid).getMembers().getValue(); + } @POST public void createRoom(@FormParam("rid") String rid) { this.value.put(rid,new Room(false)); } - @Path("/{rid}/members") - @POST - public void addRoomMember(@PathParam("rid") String rid, @FormParam("id") String id) { - getRoom(rid).getMembers().addRoomMember(rid, id); - } @Path("/{rid}/battle") @PUT public void battle(@PathParam("rid") String rid, @FormParam("hasWon") boolean hasWon) throws JsonProcessingException { getRoom(rid).battle(rid, hasWon); } + @Path("/{rid}/members") + @POST + public void addRoomMember(@PathParam("rid") String rid, @FormParam("id") String id) { + getRoom(rid).getMembers().addRoomMember(rid, id); + } } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Account.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Account.java index fce3635..5bdc922 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Account.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Account.java @@ -3,9 +3,9 @@ public class Account { private String vote; public Map getValue() { - Map temp_nil0 = new HashMap<>(); - temp_nil0.put("vote",this.getVote()); - return temp_nil0; + Map temp_nil7 = new HashMap<>(); + temp_nil7.put("vote",this.getVote()); + return temp_nil7; } public String getVote() { return this.vote; diff --git a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Counts.java b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Counts.java index 9baed06..06026ed 100644 --- a/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Counts.java +++ b/AlgebraicDataflowArchitectureModel/prototypes/JAX-RS/VotingSystem/Counts.java @@ -19,7 +19,7 @@ Map> accounts = new HashMap<>(); accounts = accounts_json; for (String aid: accounts.keySet()) { - String vote = client.target("http://localhost:8080").path("/accounts."+aid+".vote").request().get(String.class); + String vote = client.target("http://localhost:8080").path("/accounts/"+aid+"/vote").request().get(String.class); v0.put(aid,vote); } return v0; diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Companies.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Companies.java deleted file mode 100644 index 148543f..0000000 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Companies.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.util.*; - -public class Companies { - private Map value = new HashMap<>(); - public Map getValue() { - return new HashMap<>(value); - } - public Company getCompany(String cid) { - return this.value.get(cid); - } - public void addCampany(String address, String cid) { - this.value.put(cid,new Company(address)); - } -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Company.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Company.java deleted file mode 100644 index 518a8f0..0000000 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Company.java +++ /dev/null @@ -1,19 +0,0 @@ -import java.util.*; - -public class Company { - private String address; - public Map getValue() { - Map temp_nil8 = new HashMap<>(); - temp_nil8.put("address",this.getAddress()); - return temp_nil8; - } - public String getAddress() { - return this.address; - } - public void setAddress(String cid, String add) { - this.address = add; - } - public Company(String address) { - this.address = address; - } -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Customer.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Customer.java deleted file mode 100644 index 1279f8c..0000000 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Customer.java +++ /dev/null @@ -1,33 +0,0 @@ -import java.util.*; - -public class Customer { - private Company company; - private Companies companies; - private String organization; - public Map getValue() { - Map temp_nil9 = new HashMap<>(); - temp_nil9.put("organization",this.getOrganization()); - temp_nil9.put("address",this.getAddress()); - return temp_nil9; - } - public String getAddress() { - return address; - } - public String getOrganization() { - return this.organization; - } - public void updateAddressFromOrganization(String self, String uid, String organization) { - this.address = address; - this.organization = organization; - } - public void setOrganization(String uid, String cid) { - this.organization = cid; - this.company = this.companies.getCompany(this.organization); - this.updateAddressFromOrganization(uid, uid, organization); - } - public Customer(Companies companies, String organization) { - this.companies = companies; - this.organization = organization; - this.company = this.companies.getCompany(this.organization); - } -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/CustomerManagement.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/CustomerManagement.java deleted file mode 100644 index 6a2e752..0000000 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/CustomerManagement.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.util.*; - -public class CustomerManagement { - private Companies companies; - private Customers customers; - public CustomerManagement() { - companies = new Companies(); - customers = new Customers(companies); - } - public String getAddress(String uid) { - return this.customers.getCustomer(uid).getAddress(); - } - public Map getCustomer(String uid) { - return this.customers.getCustomer(uid).getValue(); - } - public String getOrganization(String uid) { - return this.customers.getCustomer(uid).getOrganization(); - } - public void setOrganization(String uid, String cid) { - this.customers.getCustomer(uid).setOrganization(uid, cid); - } - public Map getCompany(String cid) { - return this.companies.getCompany(cid).getValue(); - } - public Map getCompanies() { - return this.companies.getValue(); - } - public void addCampany(String address, String cid) { - this.companies.addCampany(address, cid); - } - public Map getCustomers() { - return this.customers.getValue(); - } - public void addCustomer(String org, String uid) { - this.customers.addCustomer(org, uid); - } - public String getAddress(String cid) { - return this.companies.getCompany(cid).getAddress(); - } - public void setAddress(String cid, String add) { - this.companies.getCompany(cid).setAddress(cid, add); - } -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Customers.java b/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Customers.java deleted file mode 100644 index c19487b..0000000 --- a/AlgebraicDataflowArchitectureModel/prototypes/Java/CustomerManagement/PUSH-first/Customers.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.*; - -public class Customers { - private Map value = new HashMap<>(); - private Companies companies; - public Map getValue() { - return new HashMap<>(value); - } - public Customer getCustomer(String uid) { - return this.value.get(uid); - } - public void addCustomer(String org, String uid) { - this.value.put(uid,new Customer(companies, org)); - } - public Customers(Companies companies) { - this.companies = companies; - } -} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index b23a6a3..40caf08 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -27,6 +27,7 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; +import models.controlFlowModel.StatefulObjectNode; import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; @@ -38,6 +39,7 @@ import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.IFlowGraph; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResourceNode; @@ -137,13 +139,13 @@ * @param langSpec specified language * @return source codes */ - public ArrayList generateCode(DataTransferModel model, DataFlowGraph flowGraph, IPlatformSpecific platformSpec, ILanguageSpecific langSpec) { + public ArrayList generateCode(DataTransferModel model, IFlowGraph flowGraph, IPlatformSpecific platformSpec, ILanguageSpecific langSpec) { CodeGenerator.langSpec = langSpec; CodeGenerator.platformSpec = platformSpec; ArrayList codes = new ArrayList<>(); Map> dependedRootComponentGraph = null; - Collection components = null; + Collection> components = null; if (platformSpec.isMonolithic()) { // To build monolithic application, the dependency of the components should be resolved in advance. @@ -154,7 +156,7 @@ components = determineComponentOrder(flowGraph, dependedRootComponentGraph); } else { // Get the all components. - components = flowGraph.getResourceNodes(); + components = flowGraph.getAllComponentNodes().values(); } // Generate the other components. @@ -163,25 +165,25 @@ return codes; } - public abstract void generateCodeFromFlowGraph(DataTransferModel model, DataFlowGraph flowGraph, Collection components, ArrayList codes, + public abstract void generateCodeFromFlowGraph(DataTransferModel model, IFlowGraph flowGraph, Collection> components, ArrayList codes, Map> dependedRootComponentGraph, IPlatformSpecific platformSpec, ILanguageSpecific langSpec); private static Map> getDependedRootComponentGraph(DataTransferModel model) { Map> dependedComponentGraph = new HashMap<>(); for (Channel ch: model.getChannels()) { - Set inRes = new HashSet<>(); - Set outRes = new HashSet<>(); - getDependedRootComponentGraphSub(ch, inRes, outRes, true); - if (outRes.size() > 0 && inRes.size() > 0) { - for (ResourceHierarchy out: outRes) { - for (ResourceHierarchy in: inRes) { - Set dependings = dependedComponentGraph.get(out.getRoot()); + Set insideRes = new HashSet<>(); + Set outsideRes = new HashSet<>(); + getDependedRootComponentGraphSub(ch, insideRes, outsideRes, true); + if (outsideRes.size() > 0 && insideRes.size() > 0) { + for (ResourceHierarchy outside: outsideRes) { + for (ResourceHierarchy inside: insideRes) { + Set dependings = dependedComponentGraph.get(outside.getRoot()); if (dependings == null) { dependings = new HashSet<>(); - dependedComponentGraph.put(out.getRoot(), dependings); + dependedComponentGraph.put(outside.getRoot(), dependings); } - if (!out.getRoot().equals(in.getRoot())) { - dependings.add(in.getRoot()); + if (!outside.getRoot().equals(inside.getRoot())) { + dependings.add(inside.getRoot()); } } } @@ -190,75 +192,85 @@ return dependedComponentGraph; } - private static void getDependedRootComponentGraphSub(Channel ch, Set inRes, Set outRes, boolean isRoot) { + private static void getDependedRootComponentGraphSub(Channel ch, Set insideRes, Set outsideRes, boolean isRoot) { DataTransferChannel dtCh = (DataTransferChannel) ch; for (ChannelMember cm: dtCh.getChannelMembers()) { if (!isRoot && !cm.isOutside()) { - outRes.add(cm.getResource().getResourceHierarchy()); // dependency to a descendant channel resource. + outsideRes.add(cm.getResource().getResourceHierarchy()); // dependency to a descendant channel resource. } if (cm.isOutside()) { - outRes.add(cm.getResource().getResourceHierarchy()); // dependency to an outside resource. + outsideRes.add(cm.getResource().getResourceHierarchy()); // dependency to an outside resource. } else { - inRes.add(cm.getResource().getResourceHierarchy()); // dependency from an inside resource. + insideRes.add(cm.getResource().getResourceHierarchy()); // dependency from an inside resource. } } for (Channel childCh: ch.getChildren()) { - getDependedRootComponentGraphSub(childCh, inRes, outRes, false); + getDependedRootComponentGraphSub(childCh, insideRes, outsideRes, false); } } - private static ArrayList determineComponentOrder(DataFlowGraph graph, Map> dependedRootComponentGraph) { - ArrayList objects = new ArrayList<>(); - Set visited = new HashSet<>(); - Collection allNodes = graph.getResourceNodes(); - for (ResourceNode resNode: allNodes) { - topologicalSort(resNode, allNodes, dependedRootComponentGraph, visited, objects); + private static ArrayList> determineComponentOrder(IFlowGraph graph, Map> dependedRootComponentGraph) { + ArrayList> objectList = new ArrayList<>(); + Set> visited = new HashSet<>(); + Map> allNodes = graph.getAllComponentNodes(); + for (Set nodeSet: allNodes.values()) { + topologicalSort(nodeSet, allNodes, dependedRootComponentGraph, visited, objectList); } - return objects; + return objectList; } - private static void topologicalSort(ResourceNode curResNode, Collection allNodes, Map> dependedRootComponentGraph, Set visited, List orderedList) { - if (visited.contains(curResNode)) return; - visited.add(curResNode); + private static void topologicalSort(Set curNodeSet, Map> allNodeSets, Map> dependedRootComponentGraph, Set> visited, List> orderedList) { + if (visited.contains(curNodeSet)) return; + visited.add(curNodeSet); // A caller is before the callee // For each incoming PUSH transfer. - for (Edge chToRes: curResNode.getInEdges()) { - for (Edge resToCh: chToRes.getSource().getInEdges()) { - if (!(resToCh instanceof DataFlowEdge) || ((PushPullAttribute)((DataFlowEdge) resToCh).getAttribute()).getSelectedOption() == PushPullValue.PUSH) { - topologicalSort((ResourceNode) resToCh.getSource(), allNodes, dependedRootComponentGraph, visited, orderedList); + for (Node curNode: curNodeSet) { + for (Edge chToRes: curNode.getInEdges()) { + for (Edge resToCh: chToRes.getSource().getInEdges()) { + if (!(resToCh instanceof DataFlowEdge) || ((PushPullAttribute)((DataFlowEdge) resToCh).getAttribute()).getSelectedOption() == PushPullValue.PUSH) { + topologicalSort(allNodeSets.get(resToCh.getSource()), allNodeSets, dependedRootComponentGraph, visited, orderedList); + } } } } // For each outgoing PULL transfer. - if (curResNode instanceof ResourceNode) { - for (Edge resToCh: curResNode.getOutEdges()) { - DataFlowEdge de = (DataFlowEdge) resToCh; - if (((PushPullAttribute) de.getAttribute()).getSelectedOption() != PushPullValue.PUSH) { - for (Edge chToRes : resToCh.getDestination().getOutEdges()) { - topologicalSort((ResourceNode) chToRes.getDestination(), allNodes, dependedRootComponentGraph, visited, orderedList); + if (curNodeSet.iterator().next() instanceof ResourceNode) { + for (Node curNode: curNodeSet) { + for (Edge resToCh: curNode.getOutEdges()) { + DataFlowEdge de = (DataFlowEdge) resToCh; + if (((PushPullAttribute) de.getAttribute()).getSelectedOption() != PushPullValue.PUSH) { + for (Edge chToRes : resToCh.getDestination().getOutEdges()) { + topologicalSort(allNodeSets.get(chToRes.getDestination()), allNodeSets, dependedRootComponentGraph, visited, orderedList); + } } } } } // For each depending root node. - if (curResNode instanceof ResourceNode && dependedRootComponentGraph.get(curResNode.getResourceHierarchy()) != null) { - for (ResourceHierarchy dependingRes: dependedRootComponentGraph.get(curResNode.getResourceHierarchy())) { - for (ResourceNode rootNode: allNodes) { - ResourceHierarchy rootRes = rootNode.getResourceHierarchy(); - if (rootRes.getParent() == null && rootRes.equals(dependingRes)) { - topologicalSort(rootNode, allNodes, dependedRootComponentGraph, visited, orderedList); + Node curNode = curNodeSet.iterator().next(); + if (curNode instanceof ResourceNode && dependedRootComponentGraph.get(((ResourceNode) curNode).getResourceHierarchy()) != null) { + for (ResourceHierarchy dependingRes: dependedRootComponentGraph.get(((ResourceNode) curNode).getResourceHierarchy())) { + for (Node node: allNodeSets.keySet()) { + if (node instanceof ResourceNode) { + ResourceNode rootNode = (ResourceNode) node; + ResourceHierarchy rootRes = rootNode.getResourceHierarchy(); + if (rootRes.getParent() == null && rootRes.equals(dependingRes)) { + topologicalSort(allNodeSets.get(rootNode), allNodeSets, dependedRootComponentGraph, visited, orderedList); + } } } } } // For each reference resource. ResourceNode cn = null; - if (curResNode instanceof ResourceNode) { - cn = (ResourceNode) curResNode; + if (curNode instanceof ResourceNode) { + cn = (ResourceNode) curNode; + } else if (curNode instanceof StatefulObjectNode) { + cn = ((StatefulObjectNode) curNode).getResource(); } if (cn != null) { - for (Node n: allNodes) { + for (Node n: allNodeSets.keySet()) { ResourceNode resNode = null; if (n instanceof ResourceNode) { resNode = (ResourceNode) n; @@ -267,15 +279,15 @@ for (Edge resToCh: resNode.getOutEdges()) { ChannelNode chNode = (ChannelNode) resToCh.getDestination(); for (ChannelMember m: chNode.getChannel().getReferenceChannelMembers()) { - if (curResNode.getOutSideResources().contains(m.getResource())) { - topologicalSort(resNode, allNodes, dependedRootComponentGraph, visited, orderedList); + if (cn.getOutSideResources().contains(m.getResource())) { + topologicalSort(allNodeSets.get(resNode), allNodeSets, dependedRootComponentGraph, visited, orderedList); } } } } } } - orderedList.add(0, curResNode); + orderedList.add(0, curNodeSet); } protected void updateMainComponent(TypeDeclaration mainType, MethodDeclaration mainConstructor, Node componentNode, diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 365a1c2..f6ad47d 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -50,6 +50,7 @@ import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.IFlowGraph; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; @@ -60,7 +61,7 @@ public class CodeGeneratorFromDataFlowGraph extends CodeGenerator { - public void generateCodeFromFlowGraph(DataTransferModel model, DataFlowGraph flowGraph, Collection components, ArrayList codes, + public void generateCodeFromFlowGraph(DataTransferModel model, IFlowGraph flowGraph, Collection> components, ArrayList codes, Map> dependedRootComponentGraph, IPlatformSpecific platformSpec, ILanguageSpecific langSpec) { Map resourceComponents = new HashMap<>(); Map resourceConstructors = new HashMap<>(); @@ -83,7 +84,8 @@ } // For each components (1st pass). - for (Node componentNode: components) { + for (Set componentNodeSet: components) { + Node componentNode = componentNodeSet.iterator().next(); ResourceNode resourceNode = (ResourceNode) componentNode; TypeDeclaration component = null; if (generatesComponent(resourceNode.getResourceHierarchy())) { @@ -152,7 +154,8 @@ // For each components (2nd pass). Map priorMemberForInputChannel = new HashMap<>(); Set generatedResources = new HashSet<>(); - for (Node componentNode: components) { + for (Set componentNodeSet: components) { + Node componentNode = componentNodeSet.iterator().next(); // Declare this resource. ResourceNode resourceNode = (ResourceNode) componentNode; Type resStateType = getImplStateType(resourceNode.getResourceHierarchy(), langSpec); @@ -193,7 +196,7 @@ } } - if (!platformSpec.isMonolithic()) { + if (!platformSpec.isMonolithic() && !generatedResources.contains(resourceNode.getResourceHierarchy())) { // Declare the getter accessor in the root resource. declareGetterAccessorInTheRootResource(resourceNode, rootComponent, platformSpec, langSpec); } @@ -217,7 +220,7 @@ } // Add constructor parameters to the ancestor components. - for (ResourceNode root: flowGraph.getRootResourceNodes()) { + for (ResourceNode root: ((DataFlowGraph) flowGraph).getRootResourceNodes()) { addConstructorParameters(root.getResourceHierarchy(), resourceComponents, resourceConstructors, constructorParams, langSpec); } @@ -1050,7 +1053,7 @@ // generate a pull data transfer from a depending in/ref resource. Type srcResourceType = srcResPath.getResourceStateType(); String srcResName2 = langSpec.toVariableName(getComponentName(srcResPath.getResourceHierarchy(), langSpec)); - String srcPath2 = srcResPath.toString().replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String srcPath2 = srcResPath.toResourcePath().replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(stateGetter, srcResName2, srcPath2, srcResourceType, false, platformSpec, langSpec); bDeclareClientField = true; } @@ -1081,7 +1084,7 @@ stateGetter.addStatement(langSpec.getVariableDeclaration(srcResType2.getInterfaceTypeName(), srcResName2) + langSpec.getAssignment() + srcGetter + langSpec.getStatementDelimiter()); } else { - String srcPath2 = src2.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String srcPath2 = src2.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(stateGetter, srcResName2, srcPath2, srcResType2, false, platformSpec, langSpec); bDeclareClientField = true; } @@ -1098,7 +1101,7 @@ stateGetter.addStatement(langSpec.getVariableDeclaration(srcResType2.getInterfaceTypeName(), srcResName2) + langSpec.getAssignment() + dependingGetter + langSpec.getStatementDelimiter()); } else { - String srcPath2 = src2.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String srcPath2 = src2.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(stateGetter, srcResName2, srcPath2, srcResType2, false, platformSpec, langSpec); bDeclareClientField = true; } @@ -1202,7 +1205,7 @@ // for REST API Type parentResType = insideResPath.getResourceStateType(); String parentResName = langSpec.toVariableName(getComponentName(insideResPath.getResourceHierarchy(), langSpec)); - String parentResPath = insideResPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String parentResPath = insideResPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(stateGetter, parentResName, parentResPath, parentResType, true, platformSpec, langSpec); bDeclareClientField = true; } @@ -1887,7 +1890,7 @@ // for REST API Type parentResType = insideResPath.getResourceStateType(); String parentResName = langSpec.toVariableName(getComponentName(insideResPath.getResourceHierarchy(), langSpec)); - String parentResPath = insideResPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String parentResPath = insideResPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(update, parentResName, parentResPath, parentResType, true, platformSpec, langSpec); } } @@ -2066,7 +2069,7 @@ String dstPath = null; if (filledPaths != null && filledPaths.get(out1) != null) { ResourcePath filledDstPath = filledPaths.get(out1).getKey(); - dstPath = filledDstPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + dstPath = filledDstPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); } else { dstPath = dstRes.toResourcePath(pathParamsUrl); } @@ -2803,7 +2806,7 @@ // for REST API Type parentResType = insideResPath.getResourceStateType(); String parentResName = langSpec.toVariableName(getComponentName(insideResPath.getResourceHierarchy(), langSpec)); - String parentResPath = insideResPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String parentResPath = insideResPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(input, parentResName, parentResPath, parentResType, true, platformSpec, langSpec); } } @@ -2973,7 +2976,7 @@ String dstPath = null; if (filledPaths != null && filledPaths.get(out2) != null) { ResourcePath filledDstPath = filledPaths.get(out2).getKey(); - dstPath = filledDstPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + dstPath = filledDstPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); } else { dstPath = dstRes.toResourcePath(pathParamsUrl); } @@ -3198,7 +3201,7 @@ for (VariableDeclaration var: updateAccessor.getParameters()) { args.add(var.getName()); } - updateAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, updateMethodName, args)); + updateAccessor.addStatement(langSpec.getMethodInvocation(resourceAccess, updateMethodName, args) + langSpec.getStatementDelimiter()); rootComponent.addMethod(updateAccessor); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index 9ff7cfb..b744713 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -168,9 +168,9 @@ cu.addImport(new ImportDeclaration("java.util.*")); if (resourceNode.getResourceHierarchy().getParent() == null) { // For a root node. - cu.addImport(new ImportDeclaration("javax.ws.rs.*")); - cu.addImport(new ImportDeclaration("javax.ws.rs.client.*")); - cu.addImport(new ImportDeclaration("javax.ws.rs.core.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.client.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.core.*")); cu.addImport(new ImportDeclaration("org.springframework.stereotype.Component")); cu.addImport(new ImportDeclaration("com.fasterxml.jackson.databind.ObjectMapper")); cu.addImport(new ImportDeclaration("com.fasterxml.jackson.core.JsonProcessingException")); @@ -1128,7 +1128,7 @@ if (field.getType().equals(typeClient)) { for (CompilationUnit cu: codes) { if (cu.types().contains(component)) { - cu.addImport(new ImportDeclaration("javax.ws.rs.client.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.client.*")); break; } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index cbef7e0..42c2067 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -533,7 +533,7 @@ String dstPath = null; if (filledPaths != null && filledPaths.get(out) != null) { ResourcePath filledDstPath = filledPaths.get(out).getKey(); - dstPath = filledDstPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + dstPath = filledDstPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); } else { dstPath = dstRes.getResourceHierarchy().toResourcePath(pathParams); } @@ -716,7 +716,7 @@ String dstPath = null; if (filledPaths != null && filledPaths.get(out) != null) { ResourcePath filledDstPath = filledPaths.get(out).getKey(); - dstPath = filledDstPath.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + dstPath = filledDstPath.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); } else { dstPath = dstRes.getResourceHierarchy().toResourcePath(pathParams); } @@ -890,7 +890,7 @@ // generate a pull data transfer from a depending in/ref resource. Type srcResourceType = src2.getResourceStateType(); String srcResName2 = JerseyCodeGenerator.toVariableName(JerseyCodeGenerator.getComponentName(src2.getResourceHierarchy())); - String srcPath2 = src2.toString().replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String srcPath2 = src2.toResourcePath().replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(getter, srcResName2, srcPath2, srcResourceType); } } @@ -916,7 +916,7 @@ ResourcePath src2 = cm2.getResource(); Type srcResType2 = src2.getResourceStateType(); String srcResName2 = JerseyCodeGenerator.toVariableName(JerseyCodeGenerator.getComponentName(src2.getResourceHierarchy())); - String srcPath2 = src2.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String srcPath2 = src2.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(getter, srcResName2, srcPath2, srcResType2); } else { // a depending channel member. @@ -926,7 +926,7 @@ // generate a pull data transfer from a depending in/ref resource. Type srcResType2 = src2.getResourceStateType(); String srcResName2 = JerseyCodeGenerator.toVariableName(JerseyCodeGenerator.getComponentName(src2.getResourceHierarchy())); - String srcPath2 = src2.toString().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); + String srcPath2 = src2.toResourcePath().replaceAll(":.*\\}","\\}").replaceAll("\\{", "\"+").replaceAll("\\}", "+\""); generatePullDataTransfer(getter, srcResName2, srcPath2, srcResType2); } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseySpecific.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseySpecific.java index f954afb..a9f4c3c 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseySpecific.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseySpecific.java @@ -65,9 +65,12 @@ @Override public void addPlatformSpecificImports(CompilationUnit cu) { - cu.addImport(new ImportDeclaration("javax.ws.rs.*")); - cu.addImport(new ImportDeclaration("javax.ws.rs.client.*")); - cu.addImport(new ImportDeclaration("javax.ws.rs.core.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.client.*")); + cu.addImport(new ImportDeclaration("jakarta.ws.rs.core.*")); +// cu.addImport(new ImportDeclaration("javax.ws.rs.*")); +// cu.addImport(new ImportDeclaration("javax.ws.rs.client.*")); +// cu.addImport(new ImportDeclaration("javax.ws.rs.core.*")); cu.addImport(new ImportDeclaration("org.springframework.stereotype.Component")); cu.addImport(new ImportDeclaration("com.fasterxml.jackson.databind.ObjectMapper")); cu.addImport(new ImportDeclaration("com.fasterxml.jackson.core.JsonProcessingException")); diff --git a/AlgebraicDataflowArchitectureModel/src/models/Node.java b/AlgebraicDataflowArchitectureModel/src/models/Node.java index 3fa1e28..2954012 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/Node.java +++ b/AlgebraicDataflowArchitectureModel/src/models/Node.java @@ -1,11 +1,12 @@ package models; +import java.util.Collection; import java.util.HashSet; import java.util.Set; public class Node implements Cloneable { - private Set inEdges = null; - private Set outEdges = null; + protected Collection inEdges = null; + protected Collection outEdges = null; private NodeAttribute attribute; public Node() { @@ -13,7 +14,7 @@ outEdges = new HashSet<>(); } - public Set getInEdges() { + public Collection getInEdges() { return inEdges; } @@ -21,7 +22,7 @@ this.inEdges = inEdges; } - public Set getOutEdges() { + public Collection getOutEdges() { return outEdges; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdge.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdge.java new file mode 100644 index 0000000..e19986e --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdge.java @@ -0,0 +1,17 @@ +package models.controlFlowModel; + +import models.Edge; +import models.dataFlowModel.PushPullValue; + +public class CallEdge extends Edge { + private PushPullValue selectedOption = PushPullValue.PUSHorPULL; + + public CallEdge(ObjectNode src, ObjectNode dst, PushPullValue selectedOption) { + super(src, dst); + this.selectedOption = selectedOption; + } + + public PushPullValue getSelectedOption() { + return this.selectedOption; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallGraph.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallGraph.java new file mode 100644 index 0000000..8928877 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallGraph.java @@ -0,0 +1,66 @@ +package models.controlFlowModel; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import models.DirectedGraph; +import models.Node; +import models.dataFlowModel.PushPullValue; +import models.dataFlowModel.ResourceNode; + +public class CallGraph extends DirectedGraph { + protected Map statefulObjMap = null; + + public CallGraph() { + statefulObjMap = new HashMap<>(); + } + + public void addNode(Node node) { + if (node instanceof ResourceNode) { + ResourceNode resNode = (ResourceNode) node; + StatefulObjectNode objNode = statefulObjMap.get(resNode); + if (objNode == null) { + objNode = new StatefulObjectNode(resNode); + statefulObjMap.put(resNode, objNode); + super.addNode(objNode); + } + } else if (node instanceof StatefulObjectNode) { + StatefulObjectNode objNode = (StatefulObjectNode) node; + if (statefulObjMap.get(objNode.getResource()) == null) { + statefulObjMap.put(objNode.getResource(), objNode); + super.addNode(objNode); + } + } else { + super.addNode(node); + } + } + + public void addEdge(ResourceNode srcResNode, ResourceNode dstResNode, PushPullValue selectedOption) { + addNode(srcResNode); + addNode(dstResNode); + addEdge(new CallEdge(getStatefulObjectNode(srcResNode), getStatefulObjectNode(dstResNode), selectedOption)); + } + + public void insertEdge(ObjectNode srcObjNode, ObjectNode dstObjNode, PushPullValue selectedOption, int n) { + CallEdge edge = new CallEdge(srcObjNode, dstObjNode, selectedOption); + simpleAddEdge(edge); + addNode(srcObjNode); + addNode(dstObjNode); + srcObjNode.insertOutEdge(edge, n); + dstObjNode.addInEdge(edge); + } + + public StatefulObjectNode getStatefulObjectNode(ResourceNode resNode) { + return statefulObjMap.get(resNode); + } + + public Set getRootNodes() { + Set roots = new HashSet<>(getNodes()); + for (Node n: getNodes()) { + roots.removeAll(n.getSuccessors()); + } + return roots; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java new file mode 100644 index 0000000..083d3b0 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java @@ -0,0 +1,96 @@ +package models.controlFlowModel; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import models.Edge; +import models.Node; +import models.algebra.Expression; +import models.algebra.Term; +import models.algebra.Variable; +import models.dataConstraintModel.Channel; +import models.dataConstraintModel.ChannelMember; +import models.DirectedGraph; +import models.dataFlowModel.*; + +public class ControlFlowGraph extends DirectedGraph implements IFlowGraph { + private DataFlowGraph dataFlowGraph; + private CallGraph pushCallGraph; + private CallGraph pullCallGraph; + + public ControlFlowGraph(DataFlowGraph dataFlowGraph, DataTransferModel model) { + this.dataFlowGraph = dataFlowGraph; + this.pushCallGraph = new CallGraph(); + this.pullCallGraph = new CallGraph(); + for (Edge e: dataFlowGraph.getEdges()) { + PushPullAttribute pushPull = ((PushPullAttribute) ((DataFlowEdge) e).getAttribute()); + ResourceNode srcNode = (ResourceNode) e.getSource(); + ResourceNode dstNode = (ResourceNode) e.getDestination(); + if (pushPull.getOptions().get(0) == PushPullValue.PUSH) { + // same direction as the data flow + pushCallGraph.addEdge(srcNode, dstNode, PushPullValue.PUSH); + } else { + // reverse direction to the data flow + pullCallGraph.addEdge(dstNode, srcNode, PushPullValue.PULL); + } + } + for (Channel ch: model.getInputChannels()) { + DataTransferChannel cio = (DataTransferChannel) ch; + EventChannelObjectNode srcNode = new EventChannelObjectNode(cio); + for (ChannelMember cm: cio.getChannelMembers()) { + if (srcNode.getName() == null) { + Expression exp = cm.getStateTransition().getMessageExpression(); + if (exp instanceof Term) { + srcNode.setName(((Term) exp).getSymbol().getName()); + } else if (exp instanceof Variable) { + srcNode.setName(((Variable) exp).getName()); + } + } + ResourceNode dstResNode = dataFlowGraph.getResourceNode(cm.getResource()); + StatefulObjectNode dstNode = pushCallGraph.getStatefulObjectNode(dstResNode); + if (dstNode == null) { + pushCallGraph.addNode(dstResNode); + dstNode = pushCallGraph.getStatefulObjectNode(dstResNode); + } + // from an I/O channel to a resource + pushCallGraph.insertEdge(srcNode, dstNode, PushPullValue.PUSH, 0); + } + } + } + + public DataFlowGraph getDataFlowGraph() { + return dataFlowGraph; + } + + @Override + public Map> getAllComponentNodes() { + Map> allNodeSets = new HashMap<>(); + for (Node n: pushCallGraph.getNodes()) { + Set nodeSet = new HashSet<>(); + nodeSet.add(n); + allNodeSets.put(n, nodeSet); + } + for (Node n: pullCallGraph.getNodes()) { + if (n instanceof StatefulObjectNode) { + ResourceNode resNode = ((StatefulObjectNode) n).getResource(); + Set nodeSet = null; + if (pushCallGraph.getStatefulObjectNode(resNode) != null) { + // Merge a stateful object node in the push call graph and that in the pull call graph. + nodeSet = allNodeSets.get(pushCallGraph.getStatefulObjectNode(resNode)); + } else { + nodeSet = new HashSet<>(); + } + nodeSet.add(n); + allNodeSets.put(n, nodeSet); + } else { + Set nodeSet = new HashSet<>(); + nodeSet.add(n); + allNodeSets.put(n, nodeSet); + } + } + return allNodeSets; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EventChannelObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EventChannelObjectNode.java new file mode 100644 index 0000000..913ead5 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EventChannelObjectNode.java @@ -0,0 +1,26 @@ +package models.controlFlowModel; + +import models.dataFlowModel.DataTransferChannel; + +public class EventChannelObjectNode extends ObjectNode { + DataTransferChannel eventChannel = null; + + public EventChannelObjectNode(DataTransferChannel ioChannel) { + super(null); + this.eventChannel = ioChannel; + } + + public EventChannelObjectNode(String name, DataTransferChannel ioChannel) { + super(name); + this.eventChannel = ioChannel; + } + + public DataTransferChannel getIOChannel() { + return eventChannel; + } + + public void setIOChannel(DataTransferChannel ioChannel) { + this.eventChannel = ioChannel; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java new file mode 100644 index 0000000..b754e72 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNode.java @@ -0,0 +1,75 @@ +package models.controlFlowModel; + +import java.util.ArrayList; +import java.util.List; + +import models.Edge; +import models.Node; + +public class ObjectNode extends Node { + protected String name = ""; + + public ObjectNode(String name) { + inEdges = new ArrayList<>(); + outEdges = new ArrayList<>(); + + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public CallEdge getInEdge(int i) { + return (CallEdge) ((List) inEdges).get(i); + } + + public CallEdge getOutEdge(int i) { + return (CallEdge) ((List) outEdges).get(i); + } + + public CallEdge findEdgeInInEdges(final CallEdge edge) { + for (Edge e : inEdges) { + if (e instanceof CallEdge) return (CallEdge)e; + } + return null; + } + + public void insertOutEdge(CallEdge edge, int n) { + ((List) outEdges).add(n, edge); + } + + public int getChildrenNum() { + return outEdges.size(); + } + + public int getOutEdgeCallOrder(final CallEdge callEdge) { + for (int i = 0; i < outEdges.size(); i++) { + if (callEdge.equals(getOutEdge(i))) return i; + } + return -1; + } + + public ObjectNode getChildren(int i) { + return (ObjectNode) ((List) outEdges).get(i).getDestination(); + } + + /************************************************************* + * 指定したエッジ(出力側)の呼び出し順を変更する. + * @param curOrder 現在の呼び出し順 + * @param newCallOrder 新しい呼び出し順 + */ + public void sortOutEdgesByCallOrder(final int curOrder, final int newCallOrder) { + ArrayList edges = ((ArrayList)outEdges); + Edge selectedEdge = ((List)outEdges).get(curOrder); + + Edge tempEdge = ((List)outEdges).get(newCallOrder - 1); + + edges.set(newCallOrder - 1, selectedEdge); + edges.set(curOrder, tempEdge); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java new file mode 100644 index 0000000..a1e50cd --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java @@ -0,0 +1,17 @@ +package models.controlFlowModel; + +import models.dataFlowModel.ResourceNode; + +public class StatefulObjectNode extends ObjectNode { + private ResourceNode resource; + + public StatefulObjectNode(ResourceNode resource) { + super(resource.getResourceName()); + this.resource = resource; + } + + public ResourceNode getResource() { + return resource; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java index b24568f..bfd163b 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java @@ -198,4 +198,13 @@ public String toString() { return resourceHierarchy.toString(pathParams); } + + public String toResourcePath() { + List params = new ArrayList<>(); + String[] sideEffects = new String[] {""}; + for (Map.Entry param: pathParams) { + params.add("{" + param.getKey().toString() + "}"); + } + return resourceHierarchy.toResourcePath(params); + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java index a86dc97..1722d40 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java @@ -8,10 +8,11 @@ import java.util.Set; import models.DirectedGraph; +import models.Node; import models.dataConstraintModel.ResourceHierarchy; import models.dataConstraintModel.ResourcePath; -public class DataFlowGraph extends DirectedGraph { +public class DataFlowGraph extends DirectedGraph implements IFlowGraph { protected Set rootResourceNodes = null; protected Set rootChannelNodes = null; protected Map channelNodeMap = null; @@ -130,6 +131,17 @@ public ChannelNode getChannelNode(DataTransferChannel channel) { return channelNodeMap.get(channel); } + + @Override + public Map> getAllComponentNodes() { + Map> allNodeSets = new HashMap<>(); + for (Node n: getResourceNodes()) { + Set nodeSet = new HashSet<>(); + nodeSet.add(n); + allNodeSets.put(n, nodeSet); + } + return allNodeSets; + } public Collection getResourceNodes() { HashSet result = new HashSet<>(resourceNodeMap.values()); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/IFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/IFlowGraph.java new file mode 100644 index 0000000..06a950b --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/IFlowGraph.java @@ -0,0 +1,11 @@ +package models.dataFlowModel; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import models.Node; + +public interface IFlowGraph { + public Map> getAllComponentNodes(); +}