d3ea71921d940fe02e02ec21c4512a364d9f60a6.svn-base 5.06 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package RULES;

import CREATOR_CONDICTIONS_RULES.CreatorConditionD3;
import CREATOR_CONDICTIONS_RULES.CreatorProtocol;
import CREATOR_CONDICTIONS_RULES.CreatorBinaryRules;
import CREATOR_CONDICTIONS_RULES.CreatorCondition_D1_D2;
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.CreatorBinaryRules;
import LOGIC.Componente;
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 CreatorRuleCommunicationComposition {

private LinkedList<Instance> instance;
private CreatorBinaryRules rule;
private Contract c;
private Componente component;
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;
public CreatorRuleCommunicationComposition(LinkedList<Instance> i, LinkedList<Protocols> listProtocols, ObjectList lt) {
instance = i;
rule = new CreatorBinaryRules(i, lt, listProtocols);
c = new Contract();
c.setName("RuleCommunicationOf" + i.get(0).getName() + "_" + i.get(1).getName());
//component = new Componente();
//component.setName(i.get(0).getName() + "_" + i.get(1).getName() + "_Communication");
protChannel = listProtocols;
createP = new CreatorProtocol(i, listProtocols);

rule.setPegaComposicao(instance.get(0).getName() +"_"+ instance.get(1).getName());
//enviando sepado prq na regra de feedback recebe apenas 1
d1 = new CreatorCondition_D1_D2(i.get(0), listProtocols.get(0));
d2 = new CreatorCondition_D1_D2(i.get(1), listProtocols.get(1));
d3 = new CreatorConditionD3(i, listProtocols);
condition_d4 = new CreatorCondition_D4(i, listProtocols);
condition_D5 = new CreatorCondition_D5(i, listProtocols);
condition_D6 = new CreatorCondition_D6(i, listProtocols);
condition_D7 = new CreatorCondition_D7(i, listProtocols);
}

public void creatorRule() {

rule.creatorBinaryCSP();
rule.setRule(rule.getRule()+ createP.creatorProtocol_and_DualProtocol());

//rule.setPegaComposicao("ResultComposition");
rule.setRule(rule.getRule() + "\n\n");
rule.setRule(rule.getRule() + "--COMMUNICATION COMPOSITION");
rule.setRule(rule.getRule() + "\n\n");

//implementação da regra
rule.setRule(rule.getRule() + rule.getPegaComposicao() + " = ");
rule.setRule(rule.getRule() + "COMM(");
rule.setRule(rule.getRule() + instance.get(0).getName() + ", ");
rule.setRule(rule.getRule() + instance.get(1).getName() + ", ");
rule.setRule(rule.getRule() + protChannel.get(0).getCanal().getName() + ", ");
rule.setRule(rule.getRule() + protChannel.get(1).getCanal().getName() + ")");
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());
//Finding a valid protocol implementation
//protocolos
//rule.setRule(rule.getRule() + "\n\n" + createP.creatorFunction() + "\n\n");


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);
}
}
}