/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package RULES;
import CREATOR_CONDICTIONS_RULES.CreatorBinaryRules;
import CREATOR_CONDICTIONS_RULES.CreatorBinaryRules;
import CREATOR_CONDICTIONS_RULES.CreatorCondictionDesacopledChannels;
import CREATOR_CONDICTIONS_RULES.CreatorConditionAuto_Injection_Compatible;
import CREATOR_CONDICTIONS_RULES.CreatorConditionD3;
import CREATOR_CONDICTIONS_RULES.CreatorCondition_D1_D2;
import CREATOR_CONDICTIONS_RULES.CreatorCondition_D4;
import CREATOR_CONDICTIONS_RULES.CreatorCondition_D5;
import CREATOR_CONDICTIONS_RULES.CreatorCondition_D6;
import CREATOR_CONDICTIONS_RULES.CreatorCondition_D7;
import CREATOR_CONDICTIONS_RULES.CreatorProtocol;
import CREATOR_CONDICTIONS_RULES.CreatorUnaryRule;
import LOGIC.Contract;
import LOGIC.Instance;
import LOGIC.ObjectList;
import LOGIC.Protocols;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
/**
*
* @author forall
*/
public class CreatorRuleReflexiveComposition {
private LinkedList<Instance> instance = null;
private CreatorUnaryRule rule;
private Contract c;
private CreatorProtocol createP;
private LinkedList<Protocols> protChannel;
private CreatorCondition_D1_D2 d1;
private CreatorCondition_D1_D2 d2;
private CreatorConditionD3 d3;
private CreatorCondition_D4 condition_d4;
private CreatorCondition_D5 condition_D5;
private CreatorCondition_D6 condition_D6;
private CreatorCondition_D7 condition_D7;
private CreatorConditionAuto_Injection_Compatible injection;
private String eventoprotocol1 = "";
private String eventoprotocol2 = "";
public CreatorRuleReflexiveComposition( LinkedList<Instance> i, LinkedList<Protocols> listProtocols, ObjectList lt) {
instance = new LinkedList<>();
instance.addAll(i);
rule = new CreatorUnaryRule(i.get(0), lt, listProtocols);
c = new Contract();
c.setName("RuleReflexiveOf" + instance.get(0).getName());
protChannel = listProtocols;
createP = new CreatorProtocol(instance, listProtocols);
rule.setPegaComposicao(instance.get(0).getName() + "_FEED");
//enviando sepado prq na regra de feedback recebe apenas 1
d1 = new CreatorCondition_D1_D2(instance.get(0), listProtocols.get(0));
d2 = new CreatorCondition_D1_D2(instance.get(0), listProtocols.get(1));
d3 = new CreatorConditionD3(instance, listProtocols);
condition_d4 = new CreatorCondition_D4(instance, listProtocols);
condition_D5 = new CreatorCondition_D5(instance, listProtocols);
condition_D6 = new CreatorCondition_D6(instance, listProtocols);
condition_D7 = new CreatorCondition_D7(instance, listProtocols);
injection = new CreatorConditionAuto_Injection_Compatible(instance.get(0), listProtocols);
//pegando o nome do evento que passei por paramentro no protocolo
int pr1, pr2, pr3, pr4;
pr1 = listProtocols.get(0).getProtocol().indexOf("(");
pr2 = listProtocols.get(0).getProtocol().lastIndexOf(")");
eventoprotocol1 = listProtocols.get(0).getProtocol().substring(pr1 + 1, pr2);
pr3 = listProtocols.get(1).getProtocol().indexOf("(");
pr4 = listProtocols.get(1).getProtocol().lastIndexOf(")");
eventoprotocol2 = listProtocols.get(1).getProtocol().substring(pr3 + 1, pr4);
}
public void creatorRule() {
rule.creatorUnaryCSP();
//definindo functions inputc e outputc para verificação de self-injection
rule.setRule(rule.getRule() + "\n\n");
rule.setRule(rule.getRule() + "outputsC(c,P) = inter(outputs(P),{|c|})");
rule.setRule(rule.getRule() + "\n");
rule.setRule(rule.getRule() + "inputsC(c,P) = inter(inputs(P),{|c|})");
rule.setRule(rule.getRule() + "\n\n");
rule.setRule(rule.getRule()+ createP.creatorProtocol_and_DualProtocol());
//rule.setPegaComposicao("ResultComposition");
rule.setRule(rule.getRule() + "\n\n");
rule.setRule(rule.getRule() + "--REFLEXIVE COMPOSITION");
rule.setRule(rule.getRule() + "\n\n");
//implementação da regra
rule.setRule(rule.getRule() + rule.getPegaComposicao() + " = ");
rule.setRule(rule.getRule() + "REF(");
rule.setRule(rule.getRule() + instance.get(0).getName() + ", ");
rule.setRule(rule.getRule() + eventoprotocol1 + ", ");
rule.setRule(rule.getRule() + eventoprotocol2 + ")");
rule.setRule(rule.getRule() + "\n");
//rule.setRule(rule.getRule() + "assert ");
//rule.setRule(rule.getRule() + rule.getPegaComposicao() + ":[deadlock free[FD]]");
rule.setRule(rule.getRule()+ d1.implementation_Condition_D1());
rule.setRule(rule.getRule()+ d2.implementation_Condition_D1());
rule.setRule(rule.getRule()+ condition_d4.implementationCondiction_D4());
rule.setRule(rule.getRule()+ condition_D5.implementationCondiction_D5());
rule.setRule(rule.getRule()+ condition_D6.implementationCondition_D6_1());
rule.setRule(rule.getRule()+ condition_D6.implementationCondition_D6_2());
rule.setRule(rule.getRule()+ condition_D7.implementationCondition_D7());
rule.setRule(rule.getRule() + injection.condictionAuto_Injection_Compatible());
FileWriter rule2 = null;
try {
rule2 = new FileWriter(new File("cspFiles/" + c.getName() + ".csp"));
PrintWriter p = new PrintWriter(rule2);
p.flush();
// escreve no arquivo os tipos e canais que estão na string 'csp, em seguida escreve uma string com o
// comportamento que é recebido do comtrato
p.write(rule.getRule());
rule2.close();
p.close();
} catch (IOException ex) {
//Logger.getLogger(instance.getName()).log(Level.SEVERE, null, ex);
}
}
}