Newer
Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package sdtranslator;
import myutil.Conversion;
import sddescription.Evt;
import translator.*;
import java.util.Vector;
* Class Evt
* Creation: 17/08/2004
* @version 1.1 17/08/2004
* @author Ludovic APVRILLE
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
public class ActionEvt {
//private ADComponent paraTC;
private ADActionStateWithGate firstActionAfterTC;
private ADComponent first;
private ADComponent last;
private ADChoice guarded;
private ADComponent mix;
//private boolean limit_0Added = false;
public Evt evt;
public ActivityDiagram ad;
public TClass t;
public ActionEvt(Evt _evt, ActivityDiagram _ad) {
evt = _evt;
first = new ADParallel();
last = new ADParallel();
ad = _ad;
ad.add(first);
ad.add(last);
}
public Evt getEvt() {
return evt;
}
private void setGuardedEvt(ADChoice adch) {
guarded = adch;
}
public ADChoice getGuarded() {
return guarded;
}
private void setMix(ADJunction adj) {
mix = adj;
}
public ADComponent getMix() {
return mix;
}
private void makeAD(ADComponent nextfirst, ADComponent lastnext) {
first.addNext(nextfirst);
lastnext.addNext(last);
ad.add(nextfirst);
if (nextfirst != lastnext) {
ad.add(lastnext);
}
}
private int getNbParam(String action) {
int index1 = action.indexOf('(');
if (index1 == -1) {
return 0;
}
return Conversion.nbOf(action, ',') + 1;
}
private String transformToTURTLEFormat(String action, boolean send) {
int index1 = action.indexOf('(');
if (index1 == -1) {
return action;
}
action = action.trim();
String ret = action.substring(0, index1);
if (send) {
ret += "!" + action.substring(index1 +1, action.length() -1);
} else {
ret += "?" + action.substring(index1 +1, action.length() -1);
}
if (send) {
ret = Conversion.replaceAllChar(ret, ',', "!");
} else {
ret = Conversion.replaceAllChar(ret, ',', "?");
}
ret = Conversion.replaceAllChar(ret, ' ', "");
return ret;
}
// builds the actions corresponding to the node and adds various components to the activity diagram
public EvtToLink translateEvt(TClass _t, ActivityDiagram ad) {
t = _t;
ADActionStateWithGate adsg = null;
ADActionStateWithParam adsp;
ADTimeInterval adti;
//ADActionStateWithParam adsp;
String action = evt.getActionId();
int index;
String gs, ps, actionValue;
Gate g;
Param p;
EvtToLink etl = null;
String nameGate, delay;
int nbParam = getNbParam(action);
ADChoice adch;
ADJunction adj;
switch(evt.getType()) {
case Evt.SYNC:
gs = t.getGateNameFromActionState(action);
g = t.addNewGateIfApplicable(gs);
adsg = new ADActionStateWithGate(g);
actionValue = t.getActionValueFromActionState(action);
actionValue = TURTLEModeling.addTypeToDataReceiving(t, actionValue);
adsg.setActionValue(actionValue);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.SYNC);
break;
case Evt.SEND_SYNC:
//TraceManager.addDev("Init action send = " + action);
action = transformToTURTLEFormat(action, true);
t.addParamFromAction(action);
//TraceManager.addDev("Modified action send = " + action);
gs = t.getGateNameFromActionState(action);
g = t.addNewGateIfApplicable(gs);
adsg = new ADActionStateWithGate(g);
actionValue = t.getActionValueFromActionState(action);
actionValue = TURTLEModeling.addTypeToDataReceiving(t, actionValue);
adsg.setActionValue(actionValue);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.SYNC);
break;
case Evt.RECV_SYNC:
//TraceManager.addDev("Init action recv = " + action);
action = transformToTURTLEFormat(action, false);
t.addParamFromAction(action);
//TraceManager.addDev("Modified action recv = " + action);
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
gs = t.getGateNameFromActionState(action);
g = t.addNewGateIfApplicable(gs);
adsg = new ADActionStateWithGate(g);
actionValue = t.getActionValueFromActionState(action);
actionValue = TURTLEModeling.addTypeToDataReceiving(t, actionValue);
adsg.setActionValue(actionValue);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.SYNC);
break;
case Evt.TIMER_SET:
nameGate = evt.getTimerName();
delay = evt.getTimerValue();
nameGate = BasicTimer.makeTimerSetGate(nameGate, t);
g = t.addNewGateIfApplicable(nameGate);
adsg = new ADActionStateWithGate(g);
adsg.setActionValue("!" + delay);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.TIMER_SET);
break;
case Evt.TIMER_EXP:
nameGate = evt.getTimerName();
nameGate = BasicTimer.makeTimerExpGate(nameGate, t);
g = t.addNewGateIfApplicable(nameGate);
adsg = new ADActionStateWithGate(g);
adsg.setActionValue("");
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.TIMER_EXP);
break;
case Evt.TIMER_RESET:
nameGate = evt.getTimerName();
nameGate = BasicTimer.makeTimerResetGate(nameGate, t);
g = t.addNewGateIfApplicable(nameGate);
adsg = new ADActionStateWithGate(g);
adsg.setActionValue("");
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.TIMER_RESET);
break;
case Evt.SEND_MSG:
action = transformToTURTLEFormat(action, true);
gs = t.getGateNameFromActionState(action);
g = t.addNewGateIfApplicable(gs);
adsg = new ADActionStateWithGate(g);
actionValue = t.getActionValueFromActionState(action);
actionValue = TURTLEModeling.addTypeToDataReceiving(t, actionValue);
adsg.setActionValue(actionValue);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.SEND_MSG, nbParam);
break;
case Evt.RECV_MSG:
action = transformToTURTLEFormat(action, false);
t.addParamFromAction(action);
gs = t.getGateNameFromActionState(action);
g = t.addNewGateIfApplicable(gs);
adsg = new ADActionStateWithGate(g);
actionValue = t.getActionValueFromActionState(action);
actionValue = TURTLEModeling.addTypeToDataReceiving(t, actionValue);
adsg.setActionValue(actionValue);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.RECV_MSG, nbParam);
break;
case Evt.INTERNAL_ACTION:
action = transformToTURTLEFormat(action, true);
gs = t.getGateNameFromActionState(action);
g = t.addNewGateIfApplicable(gs);
adsg = new ADActionStateWithGate(g);
actionValue = t.getActionValueFromActionState(action);
actionValue = TURTLEModeling.addTypeToDataReceiving(t, actionValue);
adsg.setActionValue(actionValue);
makeAD(adsg, adsg);
etl = new EvtToLink(evt, t, g, EvtToLink.INTERNAL_ACTION);
break;
case Evt.VARIABLE_SET:
gs = t.getParamNameFromActionState(action);
actionValue = t.getExprValueFromActionState(action);
p = t.addNewParamIfApplicable(gs, Param.NAT, "0");
adsp = new ADActionStateWithParam(p);
adsp.setActionValue(actionValue);
makeAD(adsp, adsp);
etl = new EvtToLink(evt, t, p, EvtToLink.VARIABLE_SET);
break;
case Evt.TIME_INTERVAL:
adti = new ADTimeInterval();
index = action.indexOf(",");
adti.setValue(action.substring(0, index), action.substring(index+1, action.length()));
makeAD(adti, adti);
etl = new EvtToLink(evt, t, EvtToLink.TIME_INTERVAL);
break;
case Evt.GUARD:
adch = new ADChoice();
//adch.addGuard("[" + evt.getActionId() + "]");
setGuardedEvt(adch);
makeAD(adch, adch);
break;
case Evt.ELSE_GUARD:
adch = new ADChoice();
setGuardedEvt(adch);
//adch.addGuard("[" + evt.getActionId() + "]");
makeAD(adch, adch);
break;
case Evt.END_GUARD:
adj = new ADJunction();
setMix(adj);
makeAD(adj, adj);
break;
default:
first.addNext(last);
}
firstActionAfterTC = adsg;
return etl;
}
public ADComponent getFirst() {
return first;
}
public ADComponent getLast() {
return last;
}
public void addBasicTCTo(int time1, int time2) {
ADDelay add = new ADDelay();
add.setValue(""+time1);
ADLatency adlat = new ADLatency();
adlat.setValue(""+(time2-time1));
/*ADTimeInterval adti = new ADTimeInterval();
adti.setValue(""+time1, ""+time2);
adti.setNewNext(first.getAllNext());*/
adlat.setNewNext(first.getAllNext());
add.addNext(adlat);
first.setNewNext(new Vector<ADComponent>());
first.addNext(add);
ad.add(add);
ad.add(adlat);
if (firstActionAfterTC != null) {
//TraceManager.addDev("Limit added to first action gate: " + firstActionAfterTC.getGate().getName());
firstActionAfterTC.setLimitOnGate("{" + (time2-time1) + "}");
}
}
public void addBeginCallTo(Gate g, Param p) {
TraceManager.addDev("Modifying begin with " + g);
t.addGate(g);
ADActionStateWithGate adsg = new ADActionStateWithGate(g);
adsg.setActionValue("!"+p.getName());
ADActionStateWithParam adincrement = new ADActionStateWithParam(p);
adincrement.setActionValue(p.getName() + "+1");
last.addNext(adsg);
last = new ADParallel();
adsg.addNext(adincrement);
adincrement.addNext(last);
ad.add(last);
ad.add(adsg);
ad.add(adincrement);
}
public void addBeginRTCCallTo(Gate g) {
TraceManager.addDev("Modifying begin with " + g);
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
t.addGate(g);
ADActionStateWithGate adsg = new ADActionStateWithGate(g);
last.addNext(adsg);
last = new ADParallel();
adsg.addNext(last);
ad.add(last);
ad.add(adsg);
}
public void addAbsoluteCallTo(Gate g_go, Gate g_ok, Gate g_expire) {
t.addGate(g_go);
t.addGate(g_ok);
t.addGate(g_expire);
ADActionStateWithGate adsg1 = new ADActionStateWithGate(g_go);
ADChoice adch = new ADChoice();
adsg1.addNext(adch);
adch.addNext(first);
ADActionStateWithGate adsg2 = new ADActionStateWithGate(g_ok);
last.addNext(adsg2);
last = new ADParallel();
adsg2.addNext(last);
ADActionStateWithGate adsg3 = new ADActionStateWithGate(g_expire);
adch.addNext(adsg3);
ADStop adstop = new ADStop();
adsg3.addNext(adstop);
ad.add(adsg1);
ad.add(adch);
ad.add(adsg2);
ad.add(adsg3);
ad.add(adstop);
ad.add(last);
first = adsg1;
}
public void addEndCallTo(Gate g_go, Gate g_ok, Param p) {
TraceManager.addDev("Modifying end with " + g_go);
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
t.addGate(g_go);
t.addGate(g_ok);
ADActionStateWithGate adsg1 = new ADActionStateWithGate(g_go);
adsg1.setActionValue("!" + p.getName());
adsg1.setNewNext(first.getAllNext());
first.setNewNext(new Vector<ADComponent>());
first.addNext(adsg1);
ADActionStateWithGate adsg2 = new ADActionStateWithGate(g_ok);
adsg2.setActionValue("{0}!"+p.getName());
ADActionStateWithParam adincrement = new ADActionStateWithParam(p);
adincrement.setActionValue(p.getName() + "+1");
last.addNext(adsg2);
last = new ADParallel();
adsg2.addNext(adincrement);
adincrement.addNext(last);
ad.add(adincrement);
ad.add(last);
ad.add(adsg1);
ad.add(adsg2);
/*t.addGate(g_expire);
ADPreempt adp = new ADPreempt();
ADActionStateWithGate adsg1 = new ADActionStateWithGate(g_end);
adsg1.setActionValue("!" + p.getName());
adsg1.setNewNext(first.getAllNext());
ADStop ads = new ADStop();
ADActionStateWithGate adsg2 = new ADActionStateWithGate(g_expire);
adsg2.setActionValue("!"+p.getName());
adsg2.addNext(ads);
adp.addNext(adsg1);
adp.addNext(adsg2);
first.setNewNext(new Vector());
first.addNext(adp);
ad.add(adp);
ad.add(adsg1);
ad.add(adsg2);
ad.add(ads);
ADActionStateWithGate adsg3 = new ADActionStateWithGate(g_cancel);
adsg3.setActionValue("!" + p.getName());
ADActionStateWithParam adincrement = new ADActionStateWithParam(p);
adincrement.setActionValue(p.getName() + "+1");
last.addNext(adsg3);
last = new ADParallel();
adsg3.addNext(adincrement);
adincrement.addNext(last);
ad.add(adincrement);
ad.add(last);
ad.add(adsg3);*/
}
public void addEndRTCCallTo(Gate g_check, Gate g_end, Gate g_expire) {
addAbsoluteCallTo(g_check, g_end, g_expire);
}