Skip to content
Snippets Groups Projects
Commit db6fbe04 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Adding DDtranslator files

parent 69f250c4
No related branches found
No related tags found
No related merge requests found
/**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.
/**
* Class DDStructLink
* Creation: 31/05/2005
* version 1.0 31/05/2005
* @author Ludovic APVRILLE
* @see
*/
package ddtranslator;
import translator.*;
public class DDStructLink {
public Gate lgate;
public Gate rgate;
public Gate linklg;
public Gate linkrg;
public boolean added;
public DDStructLink() {
}
} // Class
\ No newline at end of file
/**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.
/**
* Class DDStructSynchro
* Creation: 03/06/2005
* version 1.0 03/06/2005
* @author Ludovic APVRILLE
* @see
*/
package ddtranslator;
import java.util.*;
import translator.*;
public class DDStructSynchro {
private LinkedList list;
public DDStructSynchro() {
list = new LinkedList();
}
public DDStructSynchro(String actionValue, TClass t) {
list = new LinkedList();
constructList(actionValue, t);
}
// assumes that it contains no "!" operator
public void constructList(String actionValue, TClass t) {
String stmp, paramName;
Param p;
char c = '?';
int index, index1, index2, index3, index4, index5;
String s = actionValue;
if ((s == null) || (s.length() == 0))
return;
while ( (index = s.indexOf(c)) != -1) {
stmp = s.substring(index+1, s.length());
index1 = stmp.indexOf('!');
index2 = stmp.indexOf('?');
index3 = stmp.length();
if (index1 == -1) {
index1 = index3;
}
if (index2 == -1) {
index2 = index3;
}
index4 = Math.min(index1, index2);
index4 = Math.min(index4, index3);
if (index4 > 0) {
paramName = s.substring(index+1, index4+index+1);
paramName = paramName.trim();
index5 = paramName.indexOf(":");
if (index5>0) {
paramName = paramName.substring(0, index5);
}
p = t.getParamByName(paramName);
//System.out.println("Param=" + paramName);
if (p != null) {
list.add(p.getType());
} else {
return;
}
}
s = s.substring(index4+index+1, s.length());
}
}
public String getRegularCall() {
//System.out.println("synchro size=" + list.size());
String call = "";
int x = 0;
int b = 0;
String type;
ListIterator iterator = list.listIterator();
while(iterator.hasNext()) {
type = (String)(iterator.next());
if (type.compareTo(Param.NAT) ==0) {
call += "?x" + x + ":nat";
x ++;
} else {
call += "?b" + b + ":nat";
b ++;
}
}
return call;
}
public int nbNat() {
int nb = 0;
ListIterator iterator = list.listIterator();
String type;
while(iterator.hasNext()) {
type = (String)(iterator.next());
if (type.compareTo(Param.NAT) ==0) {
nb ++;
}
}
return nb;
}
public int nbBool() {
int nb = 0;
ListIterator iterator = list.listIterator();
String type;
while(iterator.hasNext()) {
type = (String)(iterator.next());
if (type.compareTo(Param.BOOL) ==0) {
nb ++;
}
}
return nb;
}
public int compareTo(Object o) {
if (o instanceof DDStructSynchro) {
DDStructSynchro ddss = (DDStructSynchro)o;
LinkedList listd = ddss.getList();
if (list.size() == listd.size()) {
ListIterator li1 = list.listIterator();
ListIterator li2 = listd.listIterator();
String s1, s2;
while(li1.hasNext()) {
s1 = (String)(li1.next());
s2 = (String)(li2.next());
if (s1.compareTo(s2) != 0) {
return -1;
}
}
return 0;
}
return -1;
}
return -1;
}
public LinkedList getList() {
return list;
}
public int size() {
return list.size();
}
public boolean isInList(LinkedList _list) {
ListIterator iterator = _list.listIterator();
DDStructSynchro ddss;
while(iterator.hasNext()) {
ddss = (DDStructSynchro)(iterator.next());
if (compareTo(ddss) == 0) {
return true;
}
}
return false;
}
} // Class
\ No newline at end of file
/**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.
/**
* Class DDSyntaxException
* Creation: 31/05/2005
* version 1.0 31/05/2005
* @author Ludovic APVRILLE
* @see
*/
package ddtranslator;
public class DDSyntaxException extends Exception {
public DDSyntaxException() {
super("DD does not follows the restricted format");
}
public DDSyntaxException(String msg) {
super("DD does not follows the restricted format: " + msg);
}
} // Class
\ No newline at end of file
/**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.
/**
* Class DDTranslator
* Creation: 31/05/2004
* @version 1.0 31/05/2004
* @author Ludovic APVRILLE
* @see
*/
package ddtranslator;
import java.util.*;
import translator.*;
import ui.*;
import ui.cd.*;
import ui.dd.*;
public class DDTranslator {
private TURTLEModeling tm;
private DeploymentPanel dp;
private CorrespondanceTGElement listE;
public DDTranslator(DeploymentPanel _dp, TURTLEModeling _tm, CorrespondanceTGElement _listE) {
dp = _dp;
tm = _tm;
listE = _listE;
}
public void translateLinks() throws DDSyntaxException {
// We go throughout links
LinkedList ll;
ListIterator iterator;
TDDNode node;
TGConnectorLinkNode link;
VectorLRArtifactTClassGate assocs;
LRArtifactTClassGate lratg;
TClassLinkNode t;
TClass tcl;
int i;
ll = dp.tddp.getListOfLinks();
iterator = ll.listIterator();
TClassLinkNode.reinitName();
// Loop on links
while(iterator.hasNext()) {
link = (TGConnectorLinkNode)(iterator.next());
assocs = link.getList();
System.out.println("assocs=" + assocs);
if (assocs.size() > 0) {
System.out.println("translateLinks : assocs > 0");
t = new TClassLinkNode(TClassLinkNode.generateName());
t.setDelay(link.getDelay());
tm.addTClass(t);
t.prepareTClass();
for(i=0; i<assocs.size(); i++) {
lratg = assocs.getElementAt(i);
makeSynchro(link, lratg, t, link.getOriginNode(), link.getDestinationNode());
}
t.finishTClass();
}
}
// Loop on TClassLinkNode
/* for(i=0; i<tm.classNb(); i++) {
tcl = getTClassAtIndex(i);
if (tcl instanceof TClassLinkNode) {
t = (TClassLinkNode)tcl;
}
}*/
}
private void makeSynchro(TGConnectorLinkNode link, LRArtifactTClassGate lratg, TClassLinkNode t, TDDNode node1, TDDNode node2) {
// Find all possible receiving at destination side
TCDTClass gtclass, gtclass2;
DDStructSynchro synchro;
ActivityDiagram ad;
int i;
ADComponent adc;
Gate g = null;
String actionOnGate = null;
int maxBool = 0;
int maxNat = 0;
int id;
System.out.println("Making synchro");
// Prepare struct
DDStructLink ddsl = new DDStructLink();
gtclass = findTClass(lratg.left.art, lratg.left.tcl);
TClass tclass1 = listE.getTClass(gtclass);
gtclass2 = findTClass(lratg.right.art, lratg.right.tcl);
TClass tclass2 = listE.getTClass(gtclass2);
System.out.println("Making synchro: step 1 gtclass="+ gtclass.getClassName() + "gtclass2="+ gtclass2.getClassName());
if ((tclass1 == null) || (tclass2 == null)) {
return;
}
System.out.println("Making synchro: step 1 tclass1="+ tclass1.getName() + "tclass2="+ tclass2.getName());
ddsl.lgate = tclass1.getGateByName(lratg.left.gat);
ddsl.rgate = tclass2.getGateByName(lratg.right.gat);
if ((ddsl.lgate == null) || (ddsl.rgate == null)) {
return;
}
System.out.println("Making synchro: step 2");
// Create gates for the link;
id = t.getIdGate();
ddsl.linklg = t.addNewGateIfApplicable("g_l_" + id);
ddsl.linkrg = t.addNewGateIfApplicable("g_r_" + id);
// Set the right protocol on gates
ddsl.lgate.setProtocolJava(link.getImplementation());
ddsl.lgate.setLocalPortJava(link.getOriginPort());
ddsl.lgate.setDestPortJava(link.getDestinationPort());
ddsl.lgate.setDestHostJava(tclass2.getName().substring(0, tclass2.getName().indexOf('_')));
ddsl.lgate.setLocalHostJava(tclass1.getName().substring(0, tclass1.getName().indexOf('_')));
ddsl.rgate.setProtocolJava(link.getImplementation());
ddsl.rgate.setLocalPortJava(link.getDestinationPort());
ddsl.rgate.setDestPortJava(link.getOriginPort());
ddsl.rgate.setDestHostJava(tclass1.getName().substring(0, tclass1.getName().indexOf('_')));
ddsl.rgate.setLocalHostJava(tclass2.getName().substring(0, tclass2.getName().indexOf('_')));
System.out.println("*** -> Protocol = " + link.getImplementation());
System.out.println("*** -> hosts = host1=" + ddsl.lgate.getDestHostJava() + " host2=" + ddsl.rgate.getDestHostJava());
System.out.println("Toto01 -> looking for gate " + lratg.left.gat);
// Analyse Tclass1
System.out.println("Toto02");
LinkedList synchros = new LinkedList();
ad = tclass1.getActivityDiagram();
for(i=0; i<ad.size(); i++) {
adc = (ADComponent)(ad.elementAt(i));
g = null;
if (adc instanceof ADActionStateWithGate) {
g = ((ADActionStateWithGate)adc).getGate();
actionOnGate = ((ADActionStateWithGate)adc).getActionValue();
}
if (adc instanceof ADTLO) {
g = ((ADTLO)adc).getGate();
actionOnGate = ((ADTLO)adc).getAction();
}
if (g != null) {
if (g.getName().compareTo(lratg.left.gat) == 0) {
System.out.println("Gate=" + g.getName() + " action on gate=" + actionOnGate);
synchro = new DDStructSynchro(actionOnGate, tclass1);
if ((!(synchro.isInList(synchros))) && (synchro.size() > 0)) {
synchros.add(synchro);
maxBool = Math.max(synchro.nbBool(), maxBool);
maxNat = Math.max(synchro.nbNat(), maxNat);
System.out.println("Adding gate management");
ddsl.added = true;
t.addGateManagement(ddsl.linkrg, synchro.getRegularCall(), ddsl.linklg);
}
}
}
}
// Do the same at receiving side
//System.out.println("Toto03");
synchros = new LinkedList();
ad = tclass2.getActivityDiagram();
for(i=0; i<ad.size(); i++) {
adc = (ADComponent)(ad.elementAt(i));
g = null;
if (adc instanceof ADActionStateWithGate) {
g = ((ADActionStateWithGate)adc).getGate();
actionOnGate = ((ADActionStateWithGate)adc).getActionValue();
}
if (adc instanceof ADTLO) {
g = ((ADTLO)adc).getGate();
actionOnGate = ((ADTLO)adc).getAction();
}
if (g != null) {
if (g.getName().compareTo(lratg.right.gat) == 0) {
synchro = new DDStructSynchro(actionOnGate, tclass2);
if ((!(synchro.isInList(synchros))) && (synchro.size() > 0)) {
synchros.add(synchro);
maxBool = Math.max(synchro.nbBool(), maxBool);
maxNat = Math.max(synchro.nbNat(), maxNat);
ddsl.added = true;
//System.out.println("Adding gate management");
t.addGateManagement(ddsl.linklg, synchro.getRegularCall(), ddsl.linkrg);
}
}
}
}
// Add necessary parameters to the tclass
t.makeBoolParameters(maxBool);
t.makeNatParameters(maxNat);
// Add synchro relations
if (ddsl.added == true) {
//System.out.println("Adding synchro relation g1_save = " + g1_save + " g1=" + g1);
//System.out.println("Adding synchro relation g1_save = " + g2_save + " g3=" + g3);
tm.addSynchroRelation(tclass1, ddsl.lgate, t, ddsl.linklg);
tm.addSynchroRelation(t, ddsl.linkrg, tclass2, ddsl.rgate);
}
}
private TCDTClass findTClass(String artifact, String tclass) {
DesignPanel dpan = dp.tddp.getGUI().getDesignPanel(artifact);
if (dpan == null) {
return null;
}
return dpan.getTCDTClass(tclass);
}
}
\ No newline at end of file
/**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.
/**
* Class TClassLinkNode
* Creation: 01/06/2005
* @version 1.0 01/06/2005
* @author Ludovic APVRILLE
* @see
*/
package ddtranslator;
import myutil.*;
import translator.*;
public class TClassLinkNode extends TClass {
private static int id = 0;
private String delay = "10";
private ADParallel mainpar;
private int idGate = 0;
public TClassLinkNode(String name) {
super(name, true);
}
public static String generateName() {
id ++;
return "Link__" + (id-1);
}
public int getIdGate() {
int ret = idGate;
idGate ++;
return (idGate - 1);
}
public static void reinitName() {
id = 0;
}
public void prepareTClass() {
ActivityDiagram ad = new ActivityDiagram();
mainpar = new ADParallel();
ad.getStartState().addNext(mainpar);
ad.add(mainpar);
setActivityDiagram(ad);
}
/*public Gate addInputGate(String name) {
}
public Gate addOutputGate(String name) {
}*/
public void addGateManagement(Gate g1, String call, Gate g2) {
addGateManagement(g1, call, g2, delay);
}
public void addGateManagement(Gate g1, String call, Gate g2, String delay) {
ActivityDiagram ad = getActivityDiagram();
ADJunction adj1 = new ADJunction();
//System.out.println("Call=" + call);
ADActionStateWithGate ad1 = new ADActionStateWithGate(g1);
ad1.setActionValue(call);
ADParallel para = new ADParallel();
ADDelay addelay = new ADDelay();
addelay.setValue(delay);
ADActionStateWithGate ad2 = new ADActionStateWithGate(g2);
call = Conversion.replaceAllChar(call, '?', "!");
call = Conversion.replaceOp(call, ":nat", "");
//System.out.println("Call=" + call);
ad2.setActionValue(call);
ADStop adstop = new ADStop();
mainpar.addNext(adj1);
adj1.addNext(ad1);
ad1.addNext(para);
para.addNext(adj1);
para.addNext(addelay);
addelay.addNext(ad2);
ad2.addNext(adstop);
ad.add(adj1);
ad.add(ad1);
ad.add(para);
ad.add(addelay);
ad.add(ad2);
ad.add(adstop);
}
public void finishTClass() {
// Parallel with more than 5 nexts -> manage it !
}
public int getNbNext() {
return mainpar.getNbNext();
}
public void makeBoolParameters(int nb) {
for(int i=0; i<nb; i++) {
addNewParamIfApplicable("b" + i, Param.BOOL, "false");
}
}
public void makeNatParameters(int nb) {
for(int i=0; i<nb; i++) {
addNewParamIfApplicable("x" + i, Param.NAT, "0");
}
}
public void setDelay(String _delay) {
delay = _delay;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment