/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package CSP_CREATOR; import GUI.TelaInicial; import LOGIC.Channel; import LOGIC.Componente; import LOGIC.Contract; import LOGIC.Instance; import LOGIC.ObjectList; import LOGIC.Protocols; import java.io.Serializable; import java.util.LinkedList; /** * * @author sarah */ public class CreatorNewComponent extends Instance implements Serializable { private Contract c; private Componente component; LinkedList instance; private LinkedList prot; private String rename; public CreatorNewComponent(LinkedList i, LinkedList listProt) { component = new Componente(); instance = i; component.setInstance1(instance.get(0)); component.setInstance2(instance.get(1)); c = new Contract(); prot = listProt; rename = ""; } private Componente setarNewInstance() { // lista de canais //setando canais for (Instance instance1 : instance) { for (int i = 0; i < instance1.getChannel().size(); i++) { setChannelInInstanceList(instance1.getChannel().get(i)); System.out.println(instance1.getChannel().get(i)); } } //setando os eventos de in for (Instance instance1 : instance) { for (int i = 0; i < instance1.getIn().size(); i++) { component.setIn(instance1.getIn()); } } //setando os eventos de out for (Instance instance1 : instance) { for (int i = 0; i < instance1.getOut().size(); i++) { component.setOut(instance1.getOut()); } } //lista de protocolos for (Instance instance1 : instance) { for (int i = 0; i < instance1.getProtocolos().size(); i++) { component.setProtocolos(instance1.getProtocolos()); } } //nome contrato c.setName(instance.get(0).getName() +"_"+ instance.get(1).getName()); //setar canais de contrato for (Instance instance1 : instance) { for (int i = 0; i < instance1.getContrato().getChannel().size(); i++) { c.getChannel().add(instance1.getContrato().getChannel().get(i)); //setChannelInContractList(instance1.getContrato().getChannel().get(i)); //c.setChannel(instance1.getContrato().getChannel()); //System.out.println("Canais do contrato da instancia:" + // instance1.getContrato().getChannel() + "- " +c.getChannel()); } } //behavior do contrato if(instance.get(0).getContrato().getBehavior().equals(instance.get(1).getContrato().getBehavior())){ c.setBehavior(instance.get(0).getContrato().getBehavior()); } else{ c.setBehavior(instance.get(0).getContrato().getBehavior() + "\n"+ instance.get(1).getContrato().getBehavior()); } c.setBehavior("\n" + c.getBehavior() + instance.get(0).getName() +"_" + instance.get(1).getName() + " = "); component.setContrato(c); return component; } //criei um método para cada componente prq tanto comportamento como nome mudam public Componente creatorNewComponentIterleave() { component.setName(instance.get(0).getName() + "_" + instance.get(1).getName() + "_INTER"); component.setFlag(true); setarNewInstance(); //setando comportamento do novo componente //o comportamento é setado no contrato if(instance.get(0).getContrato().getBehavior().equals(instance.get(1).getContrato().getBehavior())){ c.setBehavior(instance.get(0).getContrato().getBehavior()); } else{ c.setBehavior(instance.get(0).getContrato().getBehavior() + "\n"+ instance.get(1).getContrato().getBehavior()); } //usando a função rename para colocar no comportamento do novo comp for (Instance instance1 : instance) { //c = instance1.getContrato(); rename = rename + "Inst_" + instance1.getName() + " = <"; for (int i = 0; i < instance1.getChannel().size(); i++) { if (i == instance1.getChannel().size() - 1) { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + ")"; } else { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + "),"; } } rename = rename + "> \n"; rename = rename + instance1.getName() + " = rename(" + instance1.getContrato().getName() + ", Inst_" + instance1.getName() + ") \n\n"; } c.setBehavior(instance.get(0).getName() + "_"+ instance.get(1).getName() + " = INTER(" + instance.get(0).getName() + ", " + instance.get(1).getName() + ")" + "\n"+ c.getBehavior()+ "\n\n" + rename); component.setContrato(c); return component; } //criei um método para cada componente prq tanto comportamento como nome mudam public Componente creatorNewComponentComunication() { component.setName(instance.get(0).getName() + "_" + instance.get(1).getName() + "_COMM"); component.setFlag(true); setarNewInstance(); //setando comportamento do novo componente //o comportamento é setado no contrato if(instance.get(0).getContrato().getBehavior().equals(instance.get(1).getContrato().getBehavior())){ c.setBehavior(instance.get(0).getContrato().getBehavior()); } else{ c.setBehavior(instance.get(0).getContrato().getBehavior() + "\n"+ instance.get(1).getContrato().getBehavior()); } //usando a função rename para colocar no comportamento do novo comp for (Instance instance1 : instance) { //c = instance1.getContrato(); rename = rename + "Inst_" + instance1.getName() + " = <"; for (int i = 0; i < instance1.getChannel().size(); i++) { if (i == instance1.getChannel().size() - 1) { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + ")"; } else { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + "),"; } } rename = rename + "> \n"; rename = rename + instance1.getName() + " = rename(" + instance1.getContrato().getName() + ", Inst_" + instance1.getName() + ") \n\n"; } //COMM(P,Q,c1,c2) c.setBehavior(instance.get(0).getName() + "_"+ instance.get(1).getName() + " = COMM(" + instance.get(0).getName() + ", " + instance.get(1).getName() + "," +prot.get(0).getCanal().getName() +","+ prot.get(1).getCanal().getName() +")" + "\n"+ c.getBehavior()+ "\n\n" + rename); component.setContrato(c); return component; } //criei um método para cada componente prq tanto comportamento como nome mudam public Componente creatorNewComponentFeedBack() { component.setName(instance.get(0).getName() + "_" + instance.get(1).getName() + "_FEED"); component.setFlag(true); setarNewInstance(); //setando comportamento do novo componente //o comportamento é setado no contrato if(instance.get(0).getContrato().getBehavior().equals(instance.get(1).getContrato().getBehavior())){ c.setBehavior(instance.get(0).getContrato().getBehavior()); } else{ c.setBehavior(instance.get(0).getContrato().getBehavior() + "\n"+ instance.get(1).getContrato().getBehavior()); } //usando a função rename para colocar no comportamento do novo comp for (Instance instance1 : instance) { //c = instance1.getContrato(); rename = rename + "Inst_" + instance1.getName() + " = <"; for (int i = 0; i < instance1.getChannel().size(); i++) { if (i == instance1.getChannel().size() - 1) { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + ")"; } else { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + "),"; } } rename = rename + "> \n"; rename = rename + instance1.getName() + " = rename(" + instance1.getContrato().getName() + ", Inst_" + instance1.getName() + ") \n\n"; } //FEED(P,c1,c2) c.setBehavior(instance.get(0).getName() + "_"+ instance.get(1).getName() + " = FEED(" + instance.get(0).getName() + ", " + prot.get(0).getCanal().getName() +","+ prot.get(1).getCanal().getName() +")" + "\n"+ c.getBehavior()+ "\n\n" + rename); component.setContrato(c); return component; } //criei um método para cada componente prq tanto comportamento como nome mudam public Componente creatorNewComponentReflexive() { component.setName(instance.get(0).getName() + "_" + instance.get(1).getName() + "_REF"); component.setFlag(true); setarNewInstance(); //setando comportamento do novo componente //o comportamento é setado no contrato if(instance.get(0).getContrato().getBehavior().equals(instance.get(1).getContrato().getBehavior())){ c.setBehavior(instance.get(0).getContrato().getBehavior()); } else{ c.setBehavior(instance.get(0).getContrato().getBehavior() + "\n"+ instance.get(1).getContrato().getBehavior()); } //usando a função rename para colocar no comportamento do novo comp for (Instance instance1 : instance) { //c = instance1.getContrato(); rename = rename + "Inst_" + instance1.getName() + " = <"; for (int i = 0; i < instance1.getChannel().size(); i++) { if (i == instance1.getChannel().size() - 1) { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + ")"; } else { rename = rename + "(" + instance1.getContrato().getChannel().get(i).getName() + "," + instance1.getChannel().get(i).getName() + "),"; } } rename = rename + "> \n"; rename = rename + instance1.getName() + " = rename(" + instance1.getContrato().getName() + ", Inst_" + instance1.getName() + ") \n\n"; } //REF(P,c1,c2) c.setBehavior(instance.get(0).getName() + "_"+ instance.get(1).getName() + " = REF(" + instance.get(0).getName() + ", " + prot.get(0).getCanal().getName() +","+ prot.get(1).getCanal().getName() +")" + "\n"+ c.getBehavior()+ "\n\n" + rename); component.setContrato(c); return component; } public void setChannelInInstanceList(Channel c) { if (isntChannelInInstanceList(c)) { component.getChannel().add(c); } } public boolean isntChannelInInstanceList(Channel c) { for (int i = 0; i < component.getChannel().size(); i++) { if (c == component.getChannel().get(i)) { return false; } } return true; } public boolean isntChannelInContractList(Channel channel) { for (int i = 0; i < c.getChannel().size(); i++) { if (channel == c.getChannel().get(i)) { return false; } } return true; } public void setChannelInContractList(Channel channel) { if (isntChannelInContractList(channel)) { c.getChannel().add(channel); } } }