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 ui;
import fr.inria.oasis.vercors.cttool.model.*;
import translator.*;
import ui.procsd.*;
import ui.prosmd.*;
import ui.prosmd.util.CorrespondanceSMDManager;
import java.util.*;
* Class GProactiveDesign
* Translation of graphical proactive designs into TURTLE modeling
* Creation: 10/07/2006
* @author Ludovic APVRILLE
*/
private TURTLEModeling tm;
private ProactiveDesignPanel pdp;
private List<ProCSDPort> portsList = new LinkedList<ProCSDPort>(); //list of ProCSDPort
private List<TGConnectorProCSD> connectorsList = new LinkedList<TGConnectorProCSD>(); //list of TGConnectorProCSD
private List<TGConnectorPortInterface> connectorsPortInterfacesList = new LinkedList<TGConnectorPortInterface>();
private List<ProCSDInterface> interfacesList = new LinkedList<ProCSDInterface>(); //list of ProCSDInterface
private List<ProCSDComponent> proCSDComponentsList = new LinkedList<ProCSDComponent>();
private List<CheckingError> checkingErrors = new LinkedList<CheckingError>();
// private CorrespondanceTGElement listE;
private CorrespondanceSMDManager corespManager;
private boolean buildErrors;
//Added by Solange ...and removed by Emil ..
private Component mainModelComp;
public GProactiveDesign(ProactiveDesignPanel _pdp) {
pdp = _pdp;
init();
//TraceManager.addDev(mainModelComp.prettyPrint());
}
private void init() {
checkingErrors = new LinkedList<CheckingError>();
// listE = new CorrespondanceTGElement();
portsList = new LinkedList<ProCSDPort>(); //list of ProCSDPort
connectorsList = new LinkedList<TGConnectorProCSD>(); //list of TGConnectorProCSD
interfacesList = new LinkedList<ProCSDInterface>(); //list of ProCSDInterface
proCSDComponentsList = new LinkedList<ProCSDComponent>();
ProactiveCSDPanel csd = (ProactiveCSDPanel) (pdp.panels.elementAt(0));
List<TGComponent> list = csd.getComponentList();
boolean cyclefound = false;
for (int i = 0; i < list.size(); i++) {
TGComponent tmp = list.get(i);
// listElement(tmp);
if (!parseStructureAndFillUpLists(tmp)) cyclefound = true;
}
if (cyclefound)
addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "Cycle found in component diagrams structure."));
updatePortsInformation();
}
public void updateAllMembranes() {
this.pdp.updateAllMembranes();
}
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
private Component createModelComp(ProCSDComponent comp) {
String modelCompName = comp.getValue();
if (comp.getThisCompDesign() != null) {
comp = comp.getThisCompDesign();
// modelCompName+="_"+comp.getValue();
}
Component modelComp = new ComponentImpl(modelCompName, isPrimitive(comp));
//we add attributes
List<TAttribute> attribs = comp.getMyAttributes();
for (int at = 0; at < attribs.size(); at++) {
TAttribute a = attribs.get(at);
Attribute attrib = new fr.inria.oasis.vercors.cttool.model.AttributeImpl(a.getId(), a.getType(), a.getAccess(), a.getInitialValue());
modelComp.addAttribute(attrib);
}
//we add ports
//we do not set the ports bindings at this time as all ports in the model
//are not already
//created
Vector<ProCSDPort> portsList = comp.getPortsList();
for (int k = 0; k < portsList.size(); k++) {
ProCSDPort p = portsList.get(k);
Port modelPort = null;
if (p instanceof ProCSDInPort) {
modelPort = new InPort(p.getValue(), modelComp);
}
if (p instanceof ProCSDOutPort) {
modelPort = new OutPort(p.getValue(), modelComp);
}
if (p.getMyInterface() != null) {
ProCSDInterface proI = p.getMyInterface();
Interface modelI = new InterfaceImpl(proI.getValue(), proI.isMandatory());
List<TAttribute> proMsgs = proI.getMyMessages();
for (int i = 0; i < proMsgs.size(); i++) {
TAttribute a = proMsgs.get(i);
Message m = new MessageImpl(a.getId());
modelI.addMessage(m);
}
modelPort.setInterface(modelI);
}
modelComp.addPort(modelPort);
}
//we add the behaviour Panel
modelComp.setBehaviour(comp.getMySMD());
Vector<ProCSDComponent> subComps = comp.getComponentList();
for (int k = 0; k < subComps.size(); k++) {
ProCSDComponent subComp = subComps.get(k);
Component sc = createModelComp(subComp);
modelComp.addSubComponent(sc);
sc.setFather(modelComp);
}
return modelComp;
}
private Component initModel(ProactiveCSDPanel mainCsd) throws Exception {
Component mainAppComp = new ComponentImpl("Application");
List<TGComponent> comps = mainCsd.getComponentList();
for (int k = 0; k < comps.size(); k++) {
TGComponent t = comps.get(k);
if (t instanceof ProCSDComponent) {
ProCSDComponent comp = (ProCSDComponent) t;
Component modelComp = createModelComp(comp);
mainAppComp.addSubComponent(modelComp);
modelComp.setFather(mainAppComp);
}
}
mainAppComp = updatePortsBindingInModel(mainAppComp, mainCsd);
return mainAppComp;
}
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
/*
* if the father of this port is designed in other diagram,
* it returns the port in that diagram corresponding to this port
* if not it return this port
*/
private ProCSDPort getRealPort(ProCSDPort p) {
if (p == null) return null;
ProCSDComponent father = (ProCSDComponent) p.getFather();
ProCSDComponent fatherDesign = father.getThisCompDesign();
if (fatherDesign != null) {
return fatherDesign.getPortByName(p.getValue());
} else
return p;
}
private void updatePortsBindingInModel(Component modelComp, ProCSDComponent proComp) throws Exception {
//we consider pairs of (model Out Port, ProCSDOutPort)
Vector<ProCSDPort> ports = proComp.getPortsList();
for (int k = 0; k < ports.size(); k++) {
ProCSDPort p = ports.get(k);
if (p instanceof ProCSDOutPort) {
ProCSDOutPort proPort = (ProCSDOutPort) p;
Port modelPort = modelComp.getPortByName(proPort.getValue());
ProCSDPort proToPort = getRealPort(proPort.getToPort());
if (proToPort != null) {
Port modelToPort = null;
ProCSDComponent proToPortFather = (ProCSDComponent) proToPort.getFather();
Component modelToPortFather = null;
if (proToPortFather == proComp.getFather()) {
modelToPortFather = modelComp.getFather();
} else {
String modelToPortFatherName = proPort.getToPort().getFather().getValue();
// if (proToPortFather.getThisCompDesign()!=null)
// modelToPortFatherName+="_"+proToPortFather.getThisCompDesign().getValue();
modelToPortFather = modelComp.getFather().getSubComponentByName(modelToPortFatherName);
}
modelToPort = modelToPortFather.getPortByName(proToPort.getValue());
modelPort.setToPort(modelToPort);
modelToPort.setFromPort(modelPort);
}//if proToPort!=null
ProCSDPort proFromPort = getRealPort(proPort.getFromPort());
if (proFromPort != null) {
Port modelFromPort = null;
//ProCSDComponent proFromPortFather =(ProCSDComponent)proFromPort.getFather();
String modelFromPortFatherName = proPort.getFromPort().getFather().getValue();
if (proFromPort != proPort.getFromPort()) {
modelFromPortFatherName = proPort.getFromPort().getFather().getValue();
}
//if (proFromPortFather.getThisCompDesign()!=null)
// modelFromPortFatherName+="_"+proFromPortFather.getThisCompDesign().getValue();
Component modelFromPortFather = modelComp.getSubComponentByName(modelFromPortFatherName);
modelFromPort = modelFromPortFather.getPortByName(proFromPort.getValue());
modelPort.setFromPort(modelFromPort);
modelFromPort.setToPort(modelPort);
}//if proFromPort!=null
}//if p is ProCSDOutPort
else if (p instanceof ProCSDInPort) {
ProCSDInPort proPort = (ProCSDInPort) p;
Port modelPort = modelComp.getPortByName(proPort.getValue());
ProCSDPort proFromPort = getRealPort(proPort.getFromPort());
if (proFromPort != null) {
if (proFromPort instanceof ProCSDInPort) {
Port modelFromPort = null;
ProCSDComponent proFromPortFather = (ProCSDComponent) proFromPort.getFather();
Component modelFromPortFather = null;
if (proFromPortFather == proComp.getFather()) {
modelFromPortFather = modelComp.getFather();
} else {
String modelFromPortFatherName = proPort.getFromPort().getFather().getValue();
if (proFromPortFather.getThisCompDesign() != null)
modelFromPortFatherName = proFromPortFather.getThisCompDesign().getValue();
modelFromPortFather = modelComp.getFather().getSubComponentByName(modelFromPortFatherName);
}
modelFromPort = modelFromPortFather.getPortByName(proFromPort.getValue());
modelPort.setFromPort(modelFromPort);
modelFromPort.setToPort(modelPort);
}//if fromport=ProCSDInPort
}//if proFromPort!=null
}//if p instanceof ProCSDInport
}//for all ports
if (proComp.getThisCompDesign() != null)
proComp = proComp.getThisCompDesign();
Vector<ProCSDComponent> v = proComp.getComponentList();
for (int k = 0; k < v.size(); k++) {
ProCSDComponent proSubComp = v.get(k);
String proSubCompName = proSubComp.getValue();
//if (proSubComp.getThisCompDesign()!=null)
//proSubCompName+="_"+proSubComp.getThisCompDesign().getValue();
Component modelSubComp = modelComp.getSubComponentByName(proSubCompName);
updatePortsBindingInModel(modelSubComp, proSubComp);
}
}//method update ports bindings in model
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
private Component updatePortsBindingInModel(Component mainComp, ProactiveCSDPanel mainCsd) throws Exception {
//we consider pairs of components (Component c, ProCSDComponent pc) and update potrs bindings in
List<TGComponent> comps = mainCsd.getComponentList();
for (int k = 0; k < comps.size(); k++) {
TGComponent t = comps.get(k);
if (t instanceof ProCSDComponent) {
ProCSDComponent proComp = (ProCSDComponent) t;
String proCompName = proComp.getValue();
//if (proComp.getThisCompDesign()!=null)
// proCompName+="_"+proComp.getThisCompDesign().getValue();
Component modelComp = mainComp.getSubComponentByName(proCompName);
if (modelComp == null) {
TraceManager.addDev("This is a fatal problem.");
addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "Fatal error in the model translator. Please excuse us for this problem. "));
}
updatePortsBindingInModel(modelComp, proComp);
}
}
return mainComp;
}
public TURTLEModeling generateTURTLEModeling() {
tm = new TURTLEModeling();
init();
if (checkingErrors.size() == 0)
try {
mainModelComp = initModel((ProactiveCSDPanel) (pdp.panels.elementAt(0)));
} catch (Exception e) {
TraceManager.addDev("This is probably just litle nice bug: Could not initializate model. Exception is: \n");
e.printStackTrace();
}
if (checkingErrors.size() != 0) return null;
addTClasses(tm, mainModelComp);
if (checkingErrors.size() == 0) addSynchronisations(tm, mainModelComp);
return tm;
}
public boolean checkSyntax() {
return checkingErrors.size() <= 0;
}
/*
* for each port :
* update the interface wich contains methods who pass through this port
* "push" the connection into the inside ports in order to have
* the connections between the primitives
*
*/
private void updatePortsInformation() {
for (int k = 0; k < connectorsList.size(); k++) {
TGConnectorProCSD c = connectorsList.get(k);
c.doPostLoading();
}
for (int k = 0; k < connectorsPortInterfacesList.size(); k++) {
TGConnectorPortInterface c = connectorsPortInterfacesList.get(k);
c.doPostLoading();
}
//ok
//we need to update the toPort and fromPort for the ports
//of the components who are designed in a diffrent diagram:
/* for (int k=0;k<portsList.size();k++)
{
ProCSDPort p=(ProCSDPort)portsList.get(k);
ProCSDComponent portFather=(ProCSDComponent)p.getFather();
ProCSDPort pOkBindings=portFather.getThisCompDesign().getPort(p.getValue());
if(pOkBindings!=null)
{
p.setToPort(pOkBindings.getToPort());
p.setFromPort(pOkBindings.getFromPort());
}
}
402
403
404
405
406
407
408
409
410
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
*/
//all this code is just used for compatibility with old CTTool versions.
//normaly we shouldn't do this
//at least I think...
//needs to be verified
//and verry well improved before
//all this very-badly-designed-software will be well packed
//and nicelly put into a trash bin
//Added by Solange
int isCompatible; //0: OK
//1: Port error
//2: compatibility error
ProCSDInterface myInterface = null;
TGConnectorAttribute myInterfaceConnector;
//first we consider all out ports
for (int i = 0; i < portsList.size(); i++) {
ProCSDPort op = portsList.get(i);
if (op.getType() == TGComponentManager.PROCSD_OUT_PORT) {
try {
myInterface = op.getMyInterface(interfacesList);
//Added by Solange
op.setMyInterface(myInterface);
// Added by Solange
myInterfaceConnector = op.getTGConnectorInterface();
// Added by Solange
myInterface.setMyConnector(myInterfaceConnector);
} catch (Exception e) {
if (op.getFather() == null) {
this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "Port " + op.getValue() + " doesn't belong to a component"));
return;
}
if (((ProCSDComponent) op.getFather()).getThisCompDesign() == null) {
this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "No interface found corresponding to port " + op.getValue()));
return;
}
}
ProCSDPort toP = op.getToPort();
// if (toP==null) toP=getConnectedProCSDPort(op);
//if(toP==null) toP=getDelegateConnectorProCSDPort(op);
//Commented because is not always an error to be free, by Solange
/* if (toP==null)
{
addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: out connection not found for "+op.toString()+" in component "+op.getFather().getValue());
//TraceManager.addDev("Error: no connection found for "+op.toString());
return;
}*/
if (toP != null) {
op.setToPort(toP);
toP.setFromPort(op);
}
//Added by Solange
if (myInterface != null) {
isCompatible = op.Compatibility(op, myInterface, interfacesList);
//Added by Solange
switch (isCompatible) {
case 0:// TraceManager.addDev("Compatibility test Out port... OK");
break;
case 1:
this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "Port " + op.toString() + " not connected"));
break;
case 2:
this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "No Interface Compatibility"));
break;
}
}
/* Delegate ports removed, by Solange
ProCSDPort dp = getConnectedDelegatePort(op);
if (dp!=null)
{ dp.setMyInterface(myInterface);
dp.setToPort(toP);
toP.setFromPort(dp);
ProCSDPort ddp=getFromInsideConnectedPort(dp);
while (ddp!=null)
{ ddp.setMyInterface(myInterface);
ddp.setToPort(toP);
toP.setFromPort(ddp);
ddp=getFromInsideConnectedPort(ddp);
}//while ddp!=null
}//if dp!=null
*/
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
}//if this port is an out port
}//for all ports (out)
//now we consider all in ports
for (int i = 0; i < portsList.size(); i++) {
ProCSDPort ip = portsList.get(i);
if (ip.getType() == TGComponentManager.PROCSD_IN_PORT) {
myInterface = ip.getMyInterface(interfacesList);
if (myInterface != null) {
//Added by Solange
ip.setMyInterface(myInterface);
// Added by Solange
myInterfaceConnector = ip.getTGConnectorInterface();
// Added by Solange
myInterface.setMyConnector(myInterfaceConnector);
//
}
ProCSDPort fromPort = ip.getFromPort();
//Added by Solange
// if(fromPort==null) fromPort=getDelegateConnectorProCSDPort(ip);
if (fromPort != null) {
ip.setFromPort(fromPort);
fromPort.setToPort(ip);
}
//Commented because is not always an error to be free, by Solange
/*if (fromPort==null)
{
addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: in connection not found for "+ip.toString()+" in component "+ip.getFather().getValue());
return;
}*/
//Added by Solange
isCompatible = ip.Compatibility(ip, myInterface, interfacesList);
//Added by Solange
switch (isCompatible) {
case 0: //TraceManager.addDev("Compatibility test In port... OK");
break;
case 1:
this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "Port " + ip.toString() + " not connected"));
break;
case 2:
this.addCheckingError(new CheckingError(CheckingError.STRUCTURE_ERROR, "No Interface Compatibility"));
break;
}
/* Delegate ports removed, by Solange
ProCSDPort dp=getConnectedDelegatePort(ip);
if (dp!=null)
{ dp.setMyInterface(myInterface);
dp.setFromPort(fromPort);
fromPort.setToPort(dp);
ProCSDPort ddp=getToInsideConnectedPort(dp);
while (ddp!=null)
{ ddp.setMyInterface(myInterface);
ddp.setFromPort(fromPort);
fromPort.setToPort(ddp);
ddp=getToInsideConnectedPort(ddp);
}//while ddp!=null
}//dp!=null
*/
}// ip is an input port
} // for all ports in
}
private boolean isPrimitive(ProCSDComponent comp) {
List<TGComponent> l = getSubComponents(comp, TGComponentManager.PROCSD_COMPONENT);
if (l == null) return true;
return l.size() == 0;
}
/*
* get subcomponents of type given as parameter
* @param type The type id from TGComponentManager
* @param tgc A component
* @return selectedSubComps A LinkedList of subcomponents of the type
*/
private List<TGComponent> getSubComponents(TGComponent tgc, int type) {
if (!(tgc.getType() == TGComponentManager.PROCSD_COMPONENT)) return null;
List<TGComponent> subcompList = getSubComponents(tgc);
List<TGComponent> selectedSubComps = new LinkedList<TGComponent>();
for (int i = 0; i < subcompList.size(); i++) {
TGComponent tmp = subcompList.get(i);
if (tmp.getType() == type)
selectedSubComps.add(tmp);
}
}
/*
* get subcomponents of all types
* @param tgc A component
* @return subcompList A LinkedList of subcomponents
*/
private List<TGComponent> getSubComponents(TGComponent tgc) {
List<TGComponent> subcompList = new LinkedList<TGComponent>();
int nb = tgc.getNbInternalTGComponent();
for (int j = 0; j < nb; j++) {
TGComponent tmp = tgc.getInternalTGComponent(j);
subcompList.add(tmp);
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
}
/*
* returns all ports of this component
* @param tgc A component
* @return portsList A LinkedList with ports of the component
*/
// private List<ProCSDPort> getPorts(TGComponent tgc)
// {
// if (!(tgc.getType()==TGComponentManager.PROCSD_COMPONENT)) return null;
// List<TGComponent> subcompList=getSubComponents(tgc);
// List<ProCSDPort> portsList=new LinkedList<ProCSDPort>();
// for (int i=0;i<subcompList.size();i++)
// {
// TGComponent tmp=subcompList.get(i);
// //Remove option delegate ports, by Solange
// if ((tmp.getType()==TGComponentManager.PROCSD_IN_PORT) || (tmp.getType()==TGComponentManager.PROCSD_OUT_PORT))// || ( tmp.getType()==TGComponentManager.PROCSD_DELEGATE_PORT))
// portsList.add( (ProCSDPort) tmp);
// }
// return portsList;
// }
/*
* gets the port connected to the port in parameter via a TGConnector ProCSD if there is one, null if not
* @param port A port
* @return p1 (or p2) The connected port, or null if not connected
*/
// private ProCSDPort getConnectedProCSDPort(ProCSDPort port)
// {
// //Remove option delegate ports, by Solange
// //if (port.getType()==TGComponentManager.PROCSD_DELEGATE_PORT) return null;
//
// //TraceManager.addDev("cherche un port pour le port " +port.getValue()); comented by Emil
//
// TGConnectorProCSD myConnector=port.getTGConnector();
//
// if (myConnector==null)
// {
// //Commented because is not always an error to be free, by Solange
// //addCheckingError(CheckingError.STRUCTURE_ERROR,"We didn't find any connector for the port " +port.getValue());
// return null;
// }
//
// // TraceManager.addDev("...... (ProCSDPort).. my connector is "+myConnector.toString());
//
// //ProCSDPort p1=myConnector.getMyPort1(portsList);
// ProCSDPort p1=myConnector.getMyPort1();
//
// /* if (p1!=null) TraceManager.addDev(p1.toString());
// else
// */
//
// //TraceManager.addDev("......... my connector's Port1 is "+p1.toString());
//
// if ((p1!=null) && (!p1.equals(port))) return p1;
//
// ProCSDPort p2=myConnector.getMyPort2();
//
// if ((p2!=null) && (!p2.equals(port))) return p2;
//
// return null;
// }
//Added by Solange for the subcomponents
/*
* Method to find the port connected to a port when there are subcomponents involved
* @param port The port to be analyzed
* @return p1 (or p2) The port connected or null if not connected
*/
/*
public ProCSDPort getDelegateConnectorProCSDPort(ProCSDPort port)
{
TGConnectorDelegateProCSD myDelegateConnector=port.getTGConnectorDelegateIn();
if (myDelegateConnector==null)
myDelegateConnector=port.getTGConnectorDelegateOut();
if (myDelegateConnector==null)
{
// TraceManager.addDev("We didn't find any delegate connector for the port " +port.getValue());
return null;
}
ProCSDPort p1=myDelegateConnector.getMyPort1(portsList);
if ((p1!=null) && (!p1.equals(port))) return p1;
ProCSDPort p2=myDelegateConnector.getMyPort2(portsList);
if ((p2!=null) && (!p2.equals(port))) return p2;
return null;
}
*/
/*
* gets the delegate port connected to the port in parameter via a TGConnectorDelegateProCSD if there is one, null if not
* returns null for delegate ports
*
*/
//Delegate ports removes. Method is no t needed. By Solange
/*
private ProCSDPort getConnectedDelegatePort(ProCSDPort port)
{
if (port.getType()==TGComponentManager.PROCSD_DELEGATE_PORT) return null;
//TraceManager.addDev("cherche un port pour le port " +port.getValue());
TGConnectorDelegateProCSD myDelegateConnector=port.getTGConnectorDelegateIn();
if (myDelegateConnector==null)
myDelegateConnector=port.getTGConnectorDelegateOut();
if (myDelegateConnector==null)
{
//TraceManager.addDev("We didn't find any connector for the port " +port.getValue());
return null;
}
// TraceManager.addDev("...... (ProCSDPort).. my connector is "+myConnector.toString());
ProCSDPort p1=myDelegateConnector.getMyPort1(portsList);
//if (p1!=null) TraceManager.addDev(p1.toString());
//else
//TraceManager.addDev("......... my connector's Port1 is "+p1.toString());
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
if ((p1!=null) && (!p1.equals(port))) return p1;
ProCSDPort p2=myDelegateConnector.getMyPort2(portsList);
if ((p2!=null) && (!p2.equals(port))) return p2;
return null;
}
*/
/* private ProCSDPort getToOutsideConnectedPort(ProCSDPort dp)
{
TGComponent father=dp.getFather().getFather();
if (father==null)
{
addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
return null;
}
LinkedList fatherPorts=getPorts(father);
TGConnectorDelegateProCSD myDelegateConnectorOut=dp.getTGConnectorDelegateOut();
if (myDelegateConnectorOut==null) return null;
ProCSDPort p2=myDelegateConnectorOut.getMyPort2(fatherPorts);
if ((p2!=null) && (!p2.equals(dp))) return p2;
return null;
}
*/
/*
private ProCSDPort getFromOutsideConnectedPort(ProCSDPort dp)
{
TGComponent father=dp.getFather().getFather();
if (father==null)
{
addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
return null;
}
LinkedList fatherPorts=getPorts(father);
TGConnectorDelegateProCSD myDelegateConnectorIn=dp.getTGConnectorDelegateIn();
if (myDelegateConnectorIn==null) return null;
ProCSDPort p2=myDelegateConnectorIn.getMyPort1(fatherPorts);
if ((p2!=null) && (!p2.equals(dp))) return p2;
return null;
}
// private ProCSDPort getToInsideConnectedPort(ProCSDPort dp)
// {
// //we're looking for a port who's not a father port
// TGComponent father=dp.getFather().getFather();
// if (father==null)
// {
// addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
// return null;
// }
// LinkedList fatherPorts=getPorts(father);
//
// TGConnectorDelegateProCSD myDelegateConnectorOut=dp.getTGConnectorDelegateOut();
// if (myDelegateConnectorOut==null) return null;
// ProCSDPort p2=myDelegateConnectorOut.getMyPort2(portsList);
//
// if ((p2!=null) && (!p2.equals(dp)) && !fatherPorts.contains(p2)) return p2;
//
// return null;
//
//
//
// }
// private ProCSDPort getFromInsideConnectedPort(ProCSDPort dp)
// {
//
//// we're looking for a port who's not a father's port
// TGComponent father=dp.getFather().getFather();
// if (father==null)
// {
// addCheckingError(CheckingError.STRUCTURE_ERROR,"Error: forbiden delegate port at this level "+dp.getValue());
//
// return null;
// }
// LinkedList fatherPorts=getPorts(father);
//
// TGConnectorDelegateProCSD myDelegateConnectorIn=dp.getTGConnectorDelegateIn();
// if (myDelegateConnectorIn==null) return null;
// ProCSDPort p1=myDelegateConnectorIn.getMyPort1(portsList);
//
// if ((p1!=null) && (!p1.equals(dp)) && !fatherPorts.contains(p1)) return p1;
//
// return null;
//
// }
/*
* we are dealing with a comp specification within a
* ProActiveCompSpecificationCSDPanel
*
*/
private boolean parseStructureAndFillUpListsForCompDefinition(TGComponent t) {
if (t.getType() == TGComponentManager.PROCSD_INTERFACE) {
interfacesList.add((ProCSDInterface) t);
}
if (t.getType() == TGComponentManager.CONNECTOR_PROCSD) {
connectorsList.add((TGConnectorProCSD) t);
}
if (t.getType() == TGComponentManager.CONNECTOR_PROCSD_PORT_INTERFACE) {
connectorsPortInterfacesList.add((TGConnectorPortInterface) t);
}
/*
//Delegate ports removed, by Solange
if ( (t.getType()==TGComponentManager.PROCSD_IN_PORT) || (t.getType()==TGComponentManager.PROCSD_OUT_PORT))// || (t.getType()==TGComponentManager.PROCSD_DELEGATE_PORT))
portsList.add(t);
*/
if ((t.getType() == TGComponentManager.PROCSD_COMPONENT))
// if (ProCSDComponentsList.contains(t))
// return false;
// else
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
{
proCSDComponentsList.add((ProCSDComponent) t);
int nb = t.getNbInternalTGComponent();
for (int j = 0; j < nb; j++) {
TGComponent tgc = t.getInternalTGComponent(j);
if (!parseStructureAndFillUpListsForCompDefinition(tgc)) return false;
}
if (((ProCSDComponent) t).getMyDesignPanel() != null) {
ProActiveCompSpecificationCSDPanel specPanel = ((ProCSDComponent) t).getMyDesignPanel();
for (int q = 0; q < specPanel.componentList.size(); q++) {
TGComponent component = specPanel.componentList.get(q);
if (!parseStructureAndFillUpListsForCompDefinition(component)) return false;
}
}
}
return true;
}
/*
* Add a component to the corresponding list according to his type (interface, connector, port, component)
* @param t The component
*/
private boolean parseStructureAndFillUpLists(TGComponent t) {
if (t.getType() == TGComponentManager.PROCSD_INTERFACE) {
interfacesList.add((ProCSDInterface) t);
}
if (t.getType() == TGComponentManager.CONNECTOR_PROCSD) {
connectorsList.add((TGConnectorProCSD) t);
}
if (t.getType() == TGComponentManager.CONNECTOR_PROCSD_PORT_INTERFACE) {
connectorsPortInterfacesList.add((TGConnectorPortInterface) t);
}
//Delegate ports removed, by Solange
if ((t.getType() == TGComponentManager.PROCSD_IN_PORT) || (t.getType() == TGComponentManager.PROCSD_OUT_PORT))// || (t.getType()==TGComponentManager.PROCSD_DELEGATE_PORT))
portsList.add((ProCSDPort) t);
if ((t.getType() == TGComponentManager.PROCSD_COMPONENT)) {
// if (ProCSDComponentsList.contains(t))
// {
// return false;
// }
proCSDComponentsList.add((ProCSDComponent) t);
int nb = t.getNbInternalTGComponent();
for (int j = 0; j < nb; j++) {
TGComponent tgc = t.getInternalTGComponent(j);
parseStructureAndFillUpLists(tgc);
}
if (((ProCSDComponent) t).getMyDesignPanel() != null) {
ProActiveCompSpecificationCSDPanel specPanel = ((ProCSDComponent) t).getMyDesignPanel();
for (int q = 0; q < specPanel.componentList.size(); q++) {
TGComponent component = specPanel.componentList.get(q);
if (!parseStructureAndFillUpListsForCompDefinition(component))
return false;
}
}
}
return true;
}
/*
* Method implementing the algorithm used to create TClasses from a CTTool Component Model
* @param tm TurtleModeling to be updated with TClasses
* @param the main coponent of the aplication - the container of all components
*/
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
private void addTClasses(TURTLEModeling tm, Component appComp) {
Collection<Component> primitives = appComp.getAllPrimitives();
Iterator<Component> primitivesIterator = primitives.iterator();
while (primitivesIterator.hasNext()) {
Component comp = primitivesIterator.next();
TClass tclass = new TClass(comp.getPath().replaceAll("[.]", "_"), true);
// TraceManager.addDev("tClass created: "+comp.getValue());
Collection<Attribute> attribs = comp.getAttributes();
Iterator<Attribute> attribsIterator = attribs.iterator();
while (attribsIterator.hasNext()) {
Attribute modelAt = attribsIterator.next();
TAttribute a = new TAttribute(modelAt.getAccess(), modelAt.getName(), modelAt.getInitialValue(), modelAt.getType());
//if (a.getType() == TAttribute.NATURAL)
{
Param p = new Param(a.getId(), Param.NAT, a.getInitialValue());
p.setAccess(a.getAccessString());
tclass.addParameter(p);
}
}
Collection<Port> ports = comp.getPorts();
Iterator<Port> portsIterator = ports.iterator();
while (portsIterator.hasNext()) {
Port p = portsIterator.next();
Interface myInterface = p.getInterface();
if (myInterface == null) {
addCheckingError(CheckingError.STRUCTURE_ERROR, "No interface found for the port " + p.getName() + " in component " + p.getFather().getPath());
return;
}
Collection<Message> messages = myInterface.getMessages();
//LinkedList gates=myInterface.getMyMessages();
Iterator<Message> msgsIterator = messages.iterator();
while (msgsIterator.hasNext()) {
Message msg = msgsIterator.next();
//!!!! to see:
// the gate type
// internal gates
Gate gt = new Gate(p.getName() + "_" + msg.getName(), Gate.GATE, false);
tclass.addGate(gt);
}
}//for ports
tm.addTClass(tclass);