CreatorBinaryRules.java 5.31 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
 129
 130
 131
 132
 133
 134
 135
 136
 137
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package CREATOR_CONDICTIONS_RULES;

import CSP_CREATOR.CreatorTypesAndChannels;
import LOGIC.Channel;
import LOGIC.Instance;
import LOGIC.ObjectList;
import LOGIC.Protocols;
import java.util.LinkedList;

/**
*
* @author forall
*/
public class CreatorBinaryRules {

private String rule;
private String pegaComposicao;
private LinkedList<Instance> instance;
private ObjectList obl;
private CreatorTypesAndChannels typechannels;
private CreatorRenameFunction renameFunction;
private CreatorChannelFunction channelFunction;
private CreatorInputFunction inputFunction;
private CreatorOutputFunction outputFunction;

public CreatorBinaryRules(LinkedList<Instance> i, ObjectList ob, LinkedList<Protocols> p) {
instance = i;

obl = ob;
typechannels = new CreatorTypesAndChannels(ob);
typechannels.creatorTypesChannels();

renameFunction = new CreatorRenameFunction(i);
channelFunction = new CreatorChannelFunction(i, p);// null vai ser modificado para uma string que vai ser recebida de protocolos
inputFunction = new CreatorInputFunction(i, p);//Vai receber mais alguma coisa
outputFunction = new CreatorOutputFunction(i, p);
}

public String getRule() {
return rule;
}

public void setRule(String rule) {
this.rule = rule;
}

public String getPegaComposicao() {
return pegaComposicao;
}

public void setPegaComposicao(String pegaComposicao) {
this.pegaComposicao = pegaComposicao;
}

public void creatorBinaryCSP() {

setRule("");
setRule(getRule() + "include \"sequence_aux.csp\" \ninclude \"function_aux.csp\" \n"
+ "include \"auxiliar.csp\" \ninclude \"rules.csp\"");

setRule(getRule() + typechannels.getTypeChannel());
//não preciso de types e channels de contrato, pois estou declarando todos os tipos e canais do ObjectList
//no caso, todo canal q eu criar vai possuir algum tipo e canal dessa lista.

setRule(getRule() + "\n\n");

int st1 = instance.get(0).getContrato().getBehavior().indexOf("=");
int st2 = instance.get(1).getContrato().getBehavior().indexOf("=");
String s1 = instance.get(0).getContrato().getBehavior().substring(0, st1 - 1);
String s2 = instance.get(0).getContrato().getBehavior().substring(0, st2 - 1);

if (instance.get(0).getContrato().getBehavior().equals(instance.get(1).getContrato().getBehavior())) {
//se for igual, coloco só um comportamento
setRule(getRule() + "\n" + instance.get(0).getContrato().getBehavior() + "\n");
} else if (s1.equals(s2)) {
// se o nome dos processos forem iguais pego o maior
//pois tem um comportamento a mais especificado nele
if (instance.get(0).getContrato().getBehavior().length()
> instance.get(1).getContrato().getBehavior().length()) {
setRule(getRule() + "\n" + instance.get(0).getContrato().getBehavior() + "\n");
} else {
setRule(getRule() + "\n" + instance.get(1).getContrato().getBehavior() + "\n");
}
} else if (instance.get(0).getContrato().getBehavior().contains(instance.get(1).getContrato().getBehavior())) {

setRule(getRule() + "\n" + instance.get(0).getContrato().getBehavior() + "\n");
} else if (instance.get(1).getContrato().getBehavior().contains(instance.get(0).getContrato().getBehavior())) {

setRule(getRule() + "\n" + instance.get(1).getContrato().getBehavior() + "\n");
} else {
setRule(getRule() + "\n" + instance.get(0).getContrato().getBehavior() + "\n"
+ "\n\n" + instance.get(1).getContrato().getBehavior());
}


setRule(getRule() + "\n\n");
//declaração dos canais das instancias
/* for (Instance instance1 : instance) {// para cada objeto pertencente a lista instance, execute o que est[a logo a baixo
for (int i = 0; i < instance1.getChannel().size(); i++) {
//chama o método que cria o csp dos canais que estão associados ao contrato recebido
channelInstanciation(instance1.getChannel().get(i));

}
}*/

//setando processos auxiliares
setRule(getRule() + "\n\n");

setRule(getRule() + "\n" + obl.getProcessosAuxiliares() + "\n\n");

//creatorRenameFunction();
setRule(getRule() + renameFunction.creatorRenameFunction());
//creatorChannelFunction();
setRule(getRule() + channelFunction.creatorChannelFunction());
// creatorInputFunction();
setRule(getRule() + inputFunction.creatorInputFunction());
//creatorOutputFunction();
setRule(getRule() + outputFunction.creatorOutputFunction());
}

public void channelInstanciation(Channel Canal) {

setRule(getRule() + "\nchannel " + Canal.getName() + " : ");
for (int i = 0; i < Canal.getType().size(); i++) {
if (i == Canal.getType().size() - 1) {
setRule(getRule() + Canal.getType().get(i).getNome());
} else {
setRule(getRule() + Canal.getType().get(i).getNome() + ".");
}
}
}
}