/* 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 avatartranslator.tosysmlv2; import java.io.StringReader; import java.util.List; public class Avatar2SysMLNames { public final static int SYNC = 0; public final static int BFIFO = 1; public final static int NBFIFO = 2; public static String dataTypeSysMLname(String name){ return "'@dt:" + name.trim() + "'"; } public static String blockSysMLname(String name){ return "'@blk:" + name.trim() + "'"; } public static String attributeSysMLname(String _name){ if (_name == null) return null; String name = _name.trim(); String[] list = name.split("__"); StringBuffer result = new StringBuffer("'$" + list[0] + "'"); int length = list.length; for(int i = 1; i < length; i++) result.append(".'" + list[i] + "'"); return result.toString(); } public static String leftHandSysMLname(String name){ String aname = attributeSysMLname(name); int found = aname.indexOf("'.'"); if (found == -1) return aname; else return ( aname.substring(0,found) + "'::'" + aname.substring(found+3) ); } public static String methodSysMLname(String name){ return "'$" + name.trim() + "'"; } public static String fieldSysMLname(String name){ return "'" + name.trim() + "'"; } public static String relationSysMLname(String b1, String b2, int type, int n){ if (type == NBFIFO) return "'@NBF" + n + ":" + b1.trim() + "-" + b2.trim() + "'"; if (type == BFIFO) return "'@BF" + n + ":" + b1.trim() + "-" + b2.trim() + "'"; if (type == SYNC) return "'@SYN" + n + ":" + b1.trim() + "-" + b2.trim() + "'"; return ""; } public static String channelName(String b1, String b2, String s1, String s2, boolean in2out){ if(in2out) return b1.trim() + "." + s1.trim() + ">" + b2.trim() + "." + s2.trim(); else return b1.trim() + "." + s1.trim() + "<" + b2.trim() + "." + s2.trim(); } public static String signalSysMLname(String s){ return "'@sig:" + s + "'"; } public static String channelSysMLname(String _signalname, int type){ if (type == NBFIFO) return "'@nbf:" + _signalname.trim() + "'"; if (type == BFIFO) return "'@bf:" + _signalname.trim() + "'"; if (type == SYNC) return "'@syn:" + _signalname.trim() + "'"; return ""; } public static String messageSysMLname(String _blockname, String _signalsname){ return "'@MSG:" + _blockname.trim() + "." + _signalsname.trim() + "'"; } public static String startStateSysMLname(){ return "'@st:start'"; } public static String stopStateSysMLname(){ return "'@st:stop'"; } public static String standardStateSysMLname(String name){ return "'@st:standard." + name.trim() + "'"; } public static String randomStateSysMLname(int number){ return "'@st:random." + number + "'"; } public static String countStateSysMLname(String sigName, int number){ return "'@st:count." + sigName.trim() + "." + number + "'"; } public static String sendStateSysMLname(String sigName, int number){ return "'@st:send." + sigName.trim() + "." + number + "'"; } public static String receiveStateSysMLname(String sigName, int number){ return "'@st:receive." + sigName.trim() + "." + number + "'"; } public static String presendStateSysMLname(String sigName, int number){ return "'@st:presend." + sigName.trim() + "." + number + "'"; } public static String prereceiveStateSysMLname(String sigName, int number){ return "'@st:prereceive." + sigName.trim() + "." + number + "'"; } public static String setTimerStateSysMLname(String timerName, int number){ return "'@st:set." + timerName.trim() + "." + number + "'"; } public static String resetTimerStateSysMLname(String timerName, int number){ return "'@st:reset." + timerName.trim() + "." + number + "'"; } public static String expireTimerStateSysMLname(String timerName, int number){ return "'@st:expire." + timerName.trim() + "." + number + "'"; } public static String presetTimerStateSysMLname(String timerName, int number){ return "'@st:preset." + timerName.trim() + "." + number + "'"; } public static String preresetTimerStateSysMLname(String timerName, int number){ return "'@st:prereset." + timerName.trim() + "." + number + "'"; } public static String preexpireTimerStateSysMLname(String timerName, int number){ return "'@st:preexpire." + timerName.trim() + "." + number + "'"; } public static String timerBlockSysMLname(String timerName){ return "'@tmr:" + timerName.trim() + "'"; } public static String expr2SysML(String _expr) { Avatar2SysMLParser parser = new Avatar2SysMLParser(new Avatar2SysMLLexer(new StringReader (_expr))); try { return (String)parser.parse().value; } catch (java.lang.Exception e) { return ""; } } // TO IMPLEMENT }