c638757447fbd83b7dd81f0be5d61976504dd6fd.svn-base 7.29 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
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package CSP_CREATOR;

import LOGIC.Channel;
import LOGIC.Contract;
import LOGIC.Instance;
import LOGIC.ObjectList;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author sarah
*/
public class CreatorInstance {

private Instance instance;
private Contract contract;
private String IOprocessInstantiation = "";
private String include = "";
private String behavior = "";
private String declarate = "";
private ObjectList obl;
private CreatorTypesAndChannels typechannel;
private CreatorIOProcess iop;

public CreatorInstance(Instance i, ObjectList ob) {
instance = i;
contract = instance.getContrato();
obl = ob;
typechannel = new CreatorTypesAndChannels(ob);
typechannel.creatorTypesChannels();
iop = new CreatorIOProcess(i);
iop.creatorIOProcess();
}

public void CSPCreatorInstance() {

declarate = declarate + typechannel.getTypeChannel();

for (int i = 0; i < obl.getContractList().size(); i++) {

behavior = behavior + "\n" + obl.getContractList().get(i).getBehavior();
}

for (int i = 0; i < instance.getChannel().size(); i++) {
//chama o método que cria o csp dos canais que estão associados ao contrato recebido
channelInstanciation(instance.getChannel().get(i));
}

functionrename();
functionGetChannelI();
functioninputI();
functionoutputI();

IOprocessInstantiation = IOprocessInstantiation + iop.getIoprocess();

include = "include \"sequence_aux.csp\" \ninclude \"function_aux.csp\" \n"
+ "include \"auxiliar.csp\" \ninclude \"rules.csp\"";
FileWriter ioprocess = null;
try {
ioprocess = new FileWriter(new File("cspFiles/"+instance.getName()+".csp"));

PrintWriter p = new PrintWriter(ioprocess);
p.flush();
p.write(include + "\n\n" + declarate + "\n\n" + behavior + "\n\n" + IOprocessInstantiation);
ioprocess.close();
p.close();
} catch (IOException ex) {
Logger.getLogger(instance.getName()).log(Level.SEVERE, null, ex);

}

}

public void functionrename() {

//rename
IOprocessInstantiation = IOprocessInstantiation + "\n\nRenameContract(i) = " + contract.getName() + " [[";
for (int i = 0; i < contract.getChannel().size(); i++) {
if (i == contract.getChannel().size() - 1) {
IOprocessInstantiation = IOprocessInstantiation + contract.getChannel().get(i).getName() + " <- " + instance.getChannel().get(i).getName();
} else {
IOprocessInstantiation = IOprocessInstantiation + contract.getChannel().get(i).getName() + " <- " + instance.getChannel().get(i).getName() + ",";
}

}
IOprocessInstantiation = IOprocessInstantiation + "]] \n";

IOprocessInstantiation = IOprocessInstantiation + "Inst_" + instance.getName() + " = <";
for (int i = 0; i < contract.getChannel().size(); i++) {
if (i == contract.getChannel().size() - 1) {
IOprocessInstantiation = IOprocessInstantiation + "(" + contract.getChannel().get(i).getName() + "," + instance.getChannel().get(i).getName() + ")";
} else {
IOprocessInstantiation = IOprocessInstantiation + "(" + contract.getChannel().get(i).getName() + "," + instance.getChannel().get(i).getName() + "),";
}

}
IOprocessInstantiation = IOprocessInstantiation + "> \n";

IOprocessInstantiation = IOprocessInstantiation + instance.getName() + " = rename(" + contract.getName() + ", Inst_" + instance.getName() + ") \n\n";


}

public void functionGetChannelI() {

//channels
IOprocessInstantiation = IOprocessInstantiation + "\nGET_CHANNELS(P) =";
IOprocessInstantiation = IOprocessInstantiation + "\n \t let f =";
IOprocessInstantiation = IOprocessInstantiation + "\n \t < \n \t (" + instance.getName() + ", { ";
IOprocessInstantiation = IOprocessInstantiation + "\n";
for (int i = 0; i < instance.getChannel().size(); i++) {

if (i == instance.getChannel().size() - 1) {
IOprocessInstantiation = IOprocessInstantiation + instance.getChannel().get(i).getName();
} else {
IOprocessInstantiation = IOprocessInstantiation + instance.getChannel().get(i).getName() + ",";
}
}
IOprocessInstantiation = IOprocessInstantiation + " }) \n \t > \n";
IOprocessInstantiation = IOprocessInstantiation + "\n \t within apply(f,P )";

}

public void functioninputI() {


//função inputs
IOprocessInstantiation = IOprocessInstantiation + "\n";
// verificação para o contrato
IOprocessInstantiation = IOprocessInstantiation + "\ninputs(P) = ";
IOprocessInstantiation = IOprocessInstantiation + "\n \t let f = \n";
IOprocessInstantiation = IOprocessInstantiation + "\n \t < \n ( " + instance.getName() + ", {| ";
// coloca todos os canais de in associado com seus tipos. ex: {|c.1, c.2|}
for (int i = 0; i < instance.getIn().size(); i++) {

if (i == instance.getIn().size() - 1) {
IOprocessInstantiation = IOprocessInstantiation + instance.getIn().get(i).getEvento();
} else {
IOprocessInstantiation = IOprocessInstantiation + instance.getIn().get(i).getEvento() + ", ";
}

}
IOprocessInstantiation = IOprocessInstantiation + " |}) \n \t > \n";
IOprocessInstantiation = IOprocessInstantiation + "\n \t within apply(f, P )";
IOprocessInstantiation = IOprocessInstantiation + "\n";

}

public void functionoutputI() {

//função outputs
IOprocessInstantiation = IOprocessInstantiation + "\noutputs(P) = ";
IOprocessInstantiation = IOprocessInstantiation + "\n \t let f =";
IOprocessInstantiation = IOprocessInstantiation + "\n \t < \n ( " + instance.getName() + ", {| ";
// coloca todos os canais de out associado com seus tipos. ex: {|c.1, c.2|}
for (int i = 0; i < instance.getOut().size(); i++) {
if (i == instance.getOut().size() - 1) {
IOprocessInstantiation = IOprocessInstantiation + instance.getOut().get(i).getEvento();
} else {
IOprocessInstantiation = IOprocessInstantiation + instance.getOut().get(i).getEvento() + ", ";
}

}
IOprocessInstantiation = IOprocessInstantiation + " |}) \n \t >";
IOprocessInstantiation = IOprocessInstantiation + "\n \t within apply(f,P)\n";


}

public void channelInstanciation(Channel Canal) {

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