diff --git a/src/GraphMinimize.java b/src/GraphMinimize.java index 54bfc4d117ada3a06b17c35411872b1b5e300275..8b3ee5a2fb8deb5f5c7651697efff8d98a7855cf 100755 --- a/src/GraphMinimize.java +++ b/src/GraphMinimize.java @@ -47,10 +47,6 @@ */ import java.io.File; -import java.io.FileOutputStream; -import java.util.ArrayList; - - import myutil.*; import ui.graph.*; diff --git a/src/RemoteSimulationControl.java b/src/RemoteSimulationControl.java index aa3b289e4f452e42978aa5357dc161de269f77a8..8a9adc328806739718900af20f8e6bdf5e67d954 100755 --- a/src/RemoteSimulationControl.java +++ b/src/RemoteSimulationControl.java @@ -160,7 +160,7 @@ public class RemoteSimulationControl extends Thread { System.out.println("Could not connect to host: " + host + " on port: " + port + ". Retrying soon."); } try { - Thread.currentThread().sleep(2000); + Thread.sleep(2000); } catch (InterruptedException ie) { } } diff --git a/src/launch_configurations/TTool.launch b/src/launch_configurations/TTool.launch index be13e19c7187d4eb500e32913101c2f5d2011397..de57c03b9f786cfe6f19a8346aae0da8fbc02041 100644 --- a/src/launch_configurations/TTool.launch +++ b/src/launch_configurations/TTool.launch @@ -6,9 +6,6 @@ <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> <listEntry value="1"/> </listAttribute> -<mapAttribute key="org.eclipse.debug.core.environmentVariables"> -<mapEntry key="PATH" value="c:\cygwin64\bin"/> -</mapAttribute> <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="Main"/> <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-debug"/> diff --git a/src/launcher/ExecutionThread.java b/src/launcher/ExecutionThread.java index 8ab24d2b3389a3df03f27439825dc965875d7755..bce47aa21dca39f563a1a05207964e239586c8fd 100755 --- a/src/launcher/ExecutionThread.java +++ b/src/launcher/ExecutionThread.java @@ -53,38 +53,65 @@ import java.net.*; class ExecutionThread extends Thread { - private String cmd; - private int port; - private RshServer rsh; - private ServerSocket server = null; + private final String cmd; + private final int port; + private final RshServer rsh; + private ServerSocket server;// = null; private boolean go; - BufferedReader proc_in, proc_err; + private BufferedReader proc_in; + private BufferedReader proc_err; private Process proc; - private boolean piped; - private ExecutionThread et; + //private boolean piped; + private ExecutionThread parentExecThread; private boolean mustWaitForPiped; private OutputStream pipe; private boolean isStarted = false; + private boolean sendReturnCode; - public ExecutionThread(String _cmd, int _port, RshServer _rsh) { + private Integer returnCode; + + public ExecutionThread( final String _cmd, + final int startPortnumber, + final RshServer _rsh ) { cmd = _cmd; + //port = _port; rsh = _rsh; - port = _port; - findPortNumber(); + server = null; go = true; + returnCode = null; + mustWaitForPiped = false; + parentExecThread = null; + pipe = null; + proc = null; + proc_in = null; + proc_err = null; + + port = findPortNumber( startPortnumber ); } + + public Integer getReturnCode() { + return returnCode; + } + + public boolean isSendReturnCode() { + return sendReturnCode; + } + + public void setSendReturnCode(boolean sendReturnCode) { + this.sendReturnCode = sendReturnCode; + } public boolean isStarted() { return isStarted; } public void setPiped(ExecutionThread _et) { - et = _et; - piped = true; + parentExecThread = _et; + //piped = true; } public void setWaitForPipe() { @@ -102,7 +129,7 @@ class ExecutionThread extends Thread { } } - public synchronized void setMyPipe(OutputStream os) { + public synchronized void setMyPipe( final OutputStream os ) { pipe = os; notifyAll(); } @@ -112,157 +139,220 @@ class ExecutionThread extends Thread { return port; } - private void findPortNumber() { - for(int i=port + 1; i<port + 1000; i++) { + private int findPortNumber( final int startPortnumber ) { + for( int i = startPortnumber + 1; i < startPortnumber + 1000; i++ ) { try { server = new ServerSocket(i); server.setSoTimeout(60000); - port = i; - return; - } catch (Exception e) { + + return i; + //return; + } + catch (Exception e) { } } + + return startPortnumber; } private Socket waitForClient() { - Socket s = null; - TraceManager.addDev("process " + port + " is waiting for client"); + TraceManager.addDev( "process # " + port + " is waiting for client..." ); + try { - s = server.accept(); - } catch (Exception e) { + final Socket socket = server.accept(); + + TraceManager.addDev( "Processe # " + port + " got client." ); + + return socket; + } + catch (Exception e) { + TraceManager.addError( e ); + return null; } - TraceManager.addDev("processe " + port + " got client"); - return s; } public void closeConnect(Socket s) { try { s.close(); - } catch (IOException io) { + } + catch (IOException io) { + TraceManager.addError( io ); } } public void stopProcess() { go = false; - proc.destroy(); - proc_in = null; - //TraceManager.addDev("Stop process"); + + // Issue #18: It may happen that the process is requested to be stopped before it had time to start + // in which case it will be null + if ( proc != null && proc.isAlive() ) { + proc.destroy(); + } + + if ( proc_in != null ) { + try { + proc_in.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + + proc_in = null; + } + + if ( proc_err != null ) { + try { + proc_err.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + + proc_err = null; + } } - private void respond(PrintStream out, String s) { - try { - out.println(s); - out.flush(); - } catch (Exception e) { - } + private void respond( final PrintStream out, + final ResponseCode code, + final String message ) { + SocketComHelper.send( out, code, message); + //try { + //out.println( co de.name() + message ); + //out.flush(); +// } catch ( IOException e) { +// } } + private void handleReturnCode( PrintStream out ) + throws InterruptedException { + if ( sendReturnCode ) { + returnCode = proc.waitFor(); + final String message = "Ended command " + cmd + " with return code " + returnCode + "."; + TraceManager.addDev( message ); + respond( out, ResponseCode.PROCESS_OUTPUT, message ); + } + else { + returnCode = null; + respond( out, ResponseCode.PROCESS_END, null );//"5"); + } + } + @Override public void run() { isStarted = true; - TraceManager.addDev("Starting process for command " + cmd); + TraceManager.addDev( "Starting process for command " + cmd ); proc = null; - BufferedReader in = null; - String str; + // BufferedReader in = null; + //String str; + try { // print output in pipe - if (mustWaitForPiped) { - try { - proc = Runtime.getRuntime().exec(cmd); - if (piped) { - TraceManager.addDev("Giving my pipe to the other"); - et.setMyPipe(proc.getOutputStream()); + if ( mustWaitForPiped ) { + //try { + proc = Runtime.getRuntime().exec( cmd ); + + if ( parentExecThread != null ) { + TraceManager.addDev( "Giving my pipe to the other..." ); + parentExecThread.setMyPipe( proc.getOutputStream() ); } - TraceManager.addDev("Waiting for pipe"); + + TraceManager.addDev( "Waiting for pipe..." ); + waitingForPipe(); - TraceManager.addDev("Got pipe"); - proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); - proc_err = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - + + TraceManager.addDev( "Got pipe." ); + + proc_in = new BufferedReader( new InputStreamReader( proc.getInputStream() ) ); + proc_err = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ); + String str; + try { - while (((str = proc_in.readLine()) != null) && (go == true)){ - pipe.write((str + "\n").getBytes()); - } - while (((str = proc_err.readLine()) != null) && (go == true)){ - pipe.write((str + "\n").getBytes()); + while ( go && ( str = proc_in.readLine() ) != null ) { + TraceManager.addDev( "Writing " + str + " to pipe..." ); + pipe.write( ( str + "\n" ).getBytes() ); } - } catch (IOException e) { - } - } catch (Exception e) { - TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd); - } - try { - pipe.flush(); - pipe.close(); - } catch (Exception e) { - TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd); - } - TraceManager.addDev("Ending command " + cmd); + while ( go && ( str = proc_err.readLine() ) != null ) { + TraceManager.addError( "Writing " + str + " to pipe..." ); + pipe.write( (str + "\n").getBytes() ); + } +// } +// catch (IOException e) { +// TraceManager.addError( e ); +// } +// } +// catch (Exception e) { +// TraceManager.addError("Exception [" + e.getMessage() + "] occured when executing " + cmd, e ); +// } +// try { + } + catch (IOException e) { + TraceManager.addError("Exception [" + e.getMessage() + "] occured when executing " + cmd + "!", e ); + } + finally { + pipe.flush(); + pipe.close(); + } - // print output on socket - } else { - Socket s = waitForClient(); - if (s == null) { - TraceManager.addDev("Client did not connect on time"); - rsh.removeProcess(this); - return; - } + TraceManager.addDev( "Ending piped command " + cmd + "..." ); + } + else { + // print output on socket + Socket s = waitForClient(); - PrintStream out = null; + if (s == null) { + TraceManager.addDev("Client did not connect on time!"); + rsh.removeProcess( this ); + + return; + } - try { - TraceManager.addDev("Going to start command " + cmd); - out = new PrintStream(s.getOutputStream(), true); + TraceManager.addDev("Going to start command " + cmd + "..." ); + final PrintStream out = new PrintStream( s.getOutputStream(), true ); proc = Runtime.getRuntime().exec(cmd); - if (piped) { - TraceManager.addDev("Giving my pipe to the other"); - et.setMyPipe(proc.getOutputStream()); + if ( parentExecThread != null ) { + TraceManager.addDev( "Giving my pipe to the other..." ); + parentExecThread.setMyPipe( proc.getOutputStream() ); } - in = new BufferedReader(new InputStreamReader(s.getInputStream())); - - proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); + proc_in = new BufferedReader( new InputStreamReader( proc.getInputStream() ) ); + String str; //TraceManager.addDev("Reading the output stream of the process " + cmd); - while (((str = proc_in.readLine()) != null) && (go == true)){ - //System.out.println("out:" + str); - TraceManager.addDev("out " + str); - respond(out, "4" + str); + while ( go && ( str = proc_in.readLine() ) != null ) { + TraceManager.addDev( "Sending " + str + " from " + port + " to client..." ); + respond( out, ResponseCode.PROCESS_OUTPUT, str ); } proc_err = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - while (((str = proc_err.readLine()) != null) && (go == true)){ - //System.out.println("error out:" + str); - TraceManager.addDev("error out " + str); - respond(out, "4" + str); + while ( go && ( str = proc_err.readLine() ) != null ) { + TraceManager.addError( str ); + respond( out, ResponseCode.PROCESS_OUTPUT_ERROR, str ); } - /*int c; - while (((c = proc_in.read()) > 0) && (go == true)){ - System.out.println("char:" + (char)c); - TraceManager.addDev("out " + (char)c); - respond(out, "4" + c); - }*/ - } catch (Exception e) { - TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd); - } - TraceManager.addDev("Ending command " + cmd); - respond(out, "5"); - if (s != null) { - closeConnect(s); - } + handleReturnCode( out ); + + if ( s != null ) { + closeConnect( s ); + } + } } - - if (proc != null) { - proc.destroy(); + catch ( Throwable ex ) { + TraceManager.addError( "Exception occured when executing " + cmd, ex ); + } + finally { + if ( proc != null ) { + proc.destroy(); + } + + if ( !sendReturnCode ) { + rsh.removeProcess(this); + } } - - rsh.removeProcess(this); } } diff --git a/src/launcher/LauncherException.java b/src/launcher/LauncherException.java index 532ab7477c7e4631744051751d5d7bcb4214967f..dad9b6b6af38495c9ab570b15b607e64d792a914 100755 --- a/src/launcher/LauncherException.java +++ b/src/launcher/LauncherException.java @@ -48,8 +48,21 @@ package launcher; public class LauncherException extends Exception { - public LauncherException(String s) { - super(s); + /** + * + */ + private static final long serialVersionUID = 490922511550027307L; + + public LauncherException( String message ) { + super( message ); + } + + public LauncherException( Throwable cause ) { + super( cause ); + } + + public LauncherException( String message, + Throwable cause ) { + super ( message, cause ); } - } \ No newline at end of file diff --git a/src/launcher/RemoteExecutionThread.java b/src/launcher/RemoteExecutionThread.java index 7b3e040e8dcc54fa662ae35057ea41fa29e9582d..fd031b25cb773d1590662c2fb442909eb8fd1d84 100755 --- a/src/launcher/RemoteExecutionThread.java +++ b/src/launcher/RemoteExecutionThread.java @@ -67,7 +67,7 @@ public class RemoteExecutionThread extends Thread { rshc.sendFileData(fileName, data); } rshc.setCmd(cmd); - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); rshc.getDataFromProcess(); } catch (Exception e) { } diff --git a/src/launcher/RequestCode.java b/src/launcher/RequestCode.java new file mode 100644 index 0000000000000000000000000000000000000000..95b4aec9e8bbd4836328a0e9018e8f004753397d --- /dev/null +++ b/src/launcher/RequestCode.java @@ -0,0 +1,20 @@ +package launcher; + +public enum RequestCode { + + GET_SESSION_ID, // 00 + FREE_SESSION_ID, // 0 + PROCESS_CREATE_START, // 1 + PROCESS_KILL, // 6 + PROCESS_KILL_ALL, // 5 + PROCESS_PIPE, // 2 + PROCESS_CREATE, // 3 + PROCESS_START, // 4 + PROCESS_CHECK_RETURN_CODE, // new + PROCESS_GET_RETURN_CODE, // new + FILE_PUT, // 7 + FILE_GET, // 8 + FILE_APPEND, // new + FILE_SAVE, // new + FILE_DELETE, // 9 +} diff --git a/src/launcher/ResponseCode.java b/src/launcher/ResponseCode.java new file mode 100644 index 0000000000000000000000000000000000000000..90f38cea20a50eca951785fc9c9d5ce478ca73b0 --- /dev/null +++ b/src/launcher/ResponseCode.java @@ -0,0 +1,11 @@ +package launcher; + +public enum ResponseCode { + + FAILED, // 0 + SUCCESS, // 3 + PROCESS_OUTPUT, // 4 + PROCESS_OUTPUT_ERROR, // new + PROCESS_END, // 5 + FILE_DATA, // 8 +} diff --git a/src/launcher/RshClient.java b/src/launcher/RshClient.java index 3e2efe33fa002a5165491be39014668d6b437c80..5204c7077a0a5c0e936fc0caadc164828f994096 100755 --- a/src/launcher/RshClient.java +++ b/src/launcher/RshClient.java @@ -48,21 +48,20 @@ package launcher; import java.io.*; import java.net.*; -import javax.swing.*; import myutil.*; - public class RshClient { public static String sk; //Secret key for communicating with the launcher - private static String NO_HOST = "Application has no execution host"; + private static String NO_HOST = "Application has no execution host"; private static String INET = "Bad internet address for host "; private static String SERV_NOT_RESP = "Server not responding on "; private static String IO_ERROR = "Communication pb with server "; private static String PROC_FAILED = "Process could not be launched"; private static String FILE_FAILED = "File creation failed"; + public static String FAILED = "Request failed"; private static String ID_FAILED = "Wrong id"; private static int BUFSIZE = 511; @@ -74,13 +73,13 @@ public class RshClient { private int portString = -1; private int portString2 = -1; private Socket clientSocket = null; - private BufferedReader in; + private BufferedReader inReader; //private DataInputStream in2; private PrintStream out; //private int offset = 0; - private boolean go; - + // private boolean go; + public RshClient(String _cmd, String _host) { //System.out.println("Using port: " + port); cmd = _cmd; @@ -100,467 +99,536 @@ public class RshClient { cmd = _cmd; } - public void stopFillJTA() throws LauncherException { + public void stopCommand() + throws LauncherException { sendKillProcessRequest(); - go = false; - closeConnect(); + + // Issue #18: Socket is already closed by kiss process method + //go = false; + //closeConnect(); } public int getId() throws LauncherException { - connect(port); - send("00"); + connect(); + send( RequestCode.GET_SESSION_ID ); int id = readId(); closeConnect(); + return id; } public int freeId(int id) throws LauncherException { - connect(port); - send("0" + id); + connect(); + send( RequestCode.FREE_SESSION_ID, Integer.toString( id ) ); int idret = readId(); + if (idret != id) { throw new LauncherException(ID_FAILED); } + return idret; } - public void sendProcessRequest() throws LauncherException { - connect(port); - send("1" + cmd); - readPortString(); + public void sendExecuteCommandRequest() + throws LauncherException { + sendExecuteCommandRequest( false ); + } + + public void sendExecuteCommandRequest( final boolean checkReturnCode ) + throws LauncherException { + connect(); + + if ( checkReturnCode ) { + send( RequestCode.PROCESS_CREATE, cmd ); + readPortString(); + closeConnect(); + + final String procIdStr = Integer.toString( portString ); + connect(); + send( RequestCode.PROCESS_CHECK_RETURN_CODE, procIdStr ); + readServerResponse(); + closeConnect(); + + connect(); + send( RequestCode.PROCESS_START, procIdStr ); + readServerResponse(); + } + else { + send( RequestCode.PROCESS_CREATE_START, cmd ); + readPortString(); + } + closeConnect(); } - public void sendProcessRequest(String cmd1, String cmd2) throws LauncherException { - connect(port); - send("3" + cmd1); - int id1 = readPortString(); + public void sendExecutePipedCommandsRequest( String cmd1, + String cmd2 ) + throws LauncherException { + connect(); + send( RequestCode.PROCESS_CREATE, cmd1 ); + readPortString(); + final int id1 = portString; closeConnect(); - connect(port); - send("3" + cmd2); - int id2 = readPortString(); + connect(); + send( RequestCode.PROCESS_CREATE, cmd2); + readPortString(); + final int id2 = portString; closeConnect(); - connect(port); - send("2" + id1 + " " + id2); - readReturnPipedProcesses(); + connect(); + send( RequestCode.PROCESS_PIPE, id1 + " " + id2 ); + readServerResponse(); closeConnect(); - connect(port); - send("4" + id1); - readReturnPipedProcesses(); + connect(); + send( RequestCode.PROCESS_START, Integer.toString( id1 ) ); + readServerResponse(); closeConnect(); - connect(port); - send("4" + id2); - readReturnPipedProcesses(); + connect(); + send( RequestCode.PROCESS_START, Integer.toString( id2 ) ); + readServerResponse(); closeConnect(); portString = id2; portString2 = id1; } + public Integer getProcessReturnCode() + throws LauncherException { + connect(); + send( RequestCode.PROCESS_GET_RETURN_CODE, Integer.toString( portString ) ); + + try { + final String s = inReader.readLine(); + final ResponseCode code = SocketComHelper.responseCode( s ); + + if ( code != ResponseCode.SUCCESS ) { + throw new LauncherException( FAILED ); + } + + final String retCodeStr = SocketComHelper.message( code, s ); + + return Integer.decode( retCodeStr ); + } + catch( IOException io) { + throw new LauncherException( IO_ERROR, io ); + } + catch( final NumberFormatException ex ) { + return null; + } + finally { + closeConnect(); + + sendKillProcessRequest(); + } + } + public void sendFileData(String fileName, String data) throws LauncherException { - connect(port); - send("7" + fileName); + connect(); + send( RequestCode.FILE_PUT, fileName ); sendFileData(data); - send("7" + fileName); - readReturn(); + send( RequestCode.FILE_SAVE, fileName ); + readServerResponse(); closeConnect(); } public String getFileData(String fileName) throws LauncherException { - connect(port); - send("8" + fileName); + connect(); + send( RequestCode.FILE_GET, fileName ); String s = readDataUntilCompletion(); closeConnect(); + return s; } public void deleteFile(String fileName) throws LauncherException { - connect(port); - send("9" + fileName); - readReturn(); + connect(); + send( RequestCode.FILE_DELETE, fileName ); + readServerResponse(); closeConnect(); } - public void sendKillProcessRequest() throws LauncherException { - connect(port); - send("6" + portString); - closeConnect(); - if(portString2 != -1) { - connect(port); - send("6" + portString2); - closeConnect(); + public void sendKillProcessRequest() + throws LauncherException { + connect(); + send( RequestCode.PROCESS_KILL, Integer.toString( portString ) ); + + try { + readServerResponse(); + } + finally { + closeConnect(); + + if ( portString2 != -1 ) { + connect(); + send( RequestCode.PROCESS_KILL, Integer.toString( portString2 ) ); + + try { + readServerResponse(); + } + finally { + closeConnect(); + } + } } } public void sendKillAllProcessRequest() throws LauncherException { - connect(port); - send("5"); + connect(); + send( RequestCode.PROCESS_KILL_ALL ); + readServerResponse(); closeConnect(); } + + private BufferedReader createBufferedReader( final Socket socket ) + throws IOException { + return new BufferedReader( new InputStreamReader( socket.getInputStream() ) ); + } - public String getDataFromProcess() throws LauncherException { - go = true; + public String getDataFromProcess() + throws LauncherException { + // go = true; StringBuffer bf = new StringBuffer(); //System.out.println("Connect"); - connect(portString); - - String s; - - //System.out.println("Waiting for data"); - while (((s = readProcessData()) != null) && (go == true)) { - bf.append(s + "\n"); + final Socket socket = connect( portString ); + + try { + final BufferedReader reader = createBufferedReader( socket ); + + String data; + + //System.out.println("Waiting for data"); + while ( ( data = readProcessData( reader ) ) != null /*&& go*/ ) { + bf.append( data + "\n" ); + } + + return new String(bf); } - - //System.out.println("no more data : stopped"); - closeConnect(); - //System.out.println("Closed"); - - return new String(bf); - } - - public void fillJTA(JTextArea jta) throws LauncherException { - go = true; - - //System.out.println("Connect"); - connect(portString); - - String s; - - //TraceManager.addDev("Waiting for process data"); - while (((s = readProcessData()) != null) && (go == true)) { - //TraceManager.addDev("Adding to jta:" + s); - jta.append(s + "\n"); + catch ( final IOException ex ) { + throw new LauncherException( IO_ERROR, ex ); + } + finally { + closeConnect( socket ); } - - //System.out.println("no more data : stopped"); - closeConnect(); - //System.out.println("Closed"); - } - public void fillJTAByLine(JTextArea jta) throws LauncherException { - go = true; + public void writeCommandMessages( final Writer output ) + throws LauncherException { + + // Issue #18: the interruption is sent on the server side and we just continue writing until there is no more messages + // to empty the stream. + //go = true; - //System.out.println("Connect"); - connect(portString); + // Issue #18: There was a problem when killing the remote process since the old code would override the socked created + // by the killing command + final Socket socket = connect( portString ); + //connect(portString); - String s; - - //System.out.println("Waiting for data"); - while (((s = readProcessData()) != null) && (go == true)) { - jta.append(s + "\n"); + try { + final BufferedReader reader = createBufferedReader( socket ); + String readLine = reader.readLine(); + + while ( readLine != null ) { + final ResponseCode code = SocketComHelper.responseCode( readLine ); + final String message = SocketComHelper.message( code, readLine ); + + switch ( code ) { + case PROCESS_OUTPUT_ERROR : + output.append( message + "\n" ); + + break; + + default: + output.append( message + "\n" ); + + break; + } + + readLine = reader.readLine(); + } + } + catch( final IOException io ) { + throw new LauncherException( IO_ERROR, io ); + } + finally { + closeConnect( socket ); } - - //System.out.println("no more data : stopped"); - closeConnect(); - //System.out.println("Closed"); - + } +// Issue #18: This does the same as the method above so commented out +// public void fillJTAByLine(JTextArea jta) throws LauncherException { +// go = true; +// +// //System.out.println("Connect"); +// connect(portString); +// +// String s; +// +// //System.out.println("Waiting for data"); +// while (((s = readProcessData()) != null) && go ) { +// jta.append(s + "\n"); +// } +// +// //System.out.println("no more data : stopped"); +// closeConnect(); +// //System.out.println("Closed"); +// +// } + + public void closeConnect() + throws LauncherException { + closeConnect( clientSocket ); } - public void closeConnect() throws LauncherException { + private void closeConnect( final Socket socket ) + throws LauncherException { try { - clientSocket.close(); - } catch (IOException io) { - throw new LauncherException(SERV_NOT_RESP+host); + socket.close(); + } + catch ( IOException io ) { + throw new LauncherException( SERV_NOT_RESP + host, io ); } } - /* -- private -- */ - - - - private void send(String s) throws LauncherException { - TraceManager.addDev("Sending: " + s); + private void send(final RequestCode code ) + throws LauncherException { + send( code, "" ); + } - if (sk != null) { - // cipher the information - s = AESEncryptor.encrypt(sk, RshServer.iv, s); - TraceManager.addDev("Ciphered message to server=" + s); - } + private void send( final RequestCode code, + String message ) + throws LauncherException { + //TraceManager.addDev( "Sending message: " + message ); +// message = code.name() + message; +// +// if (sk != null) { +// // cipher the information +// message = AESEncryptor.encrypt(sk, RshServer.iv, message); +// TraceManager.addDev( "Ciphered message to server=" + message ); +// } try { - out.println(s); - out.flush(); - } catch (Exception e) { - throw new LauncherException(IO_ERROR); + SocketComHelper.send( out, code, message, sk ); +// out.println( message); +// out.flush(); + } + catch ( Throwable th ) { + throw new LauncherException( IO_ERROR, th ); } } private void sendFileData(String data) throws LauncherException { - //System.out.println("Sending data"); StringReader sr = new StringReader(data); BufferedReader br = new BufferedReader(sr); String s; + try { while((s = br.readLine()) != null) { - send("8" + s); + send( RequestCode.FILE_APPEND, s ); +// send("8" + s); } } catch (Exception e) { - throw new LauncherException(FILE_FAILED); + throw new LauncherException( FILE_FAILED, e ); } } - /*private boolean sendData(PrintStream out, FileInputStream fis) throws LauncherException { - System.out.println("Send data "); - - byte [] ba = new byte[BUFSIZE]; - int nbRead; - - //StringReader sr = new StringReader(data); - //BufferedReader br = new BufferedReader(sr); - try { - while((nbRead = fis.read(ba)) > -1) { - respond(out, "8" + new String(ba, 0, nbRead)); - } - fis.close(); - } catch (Exception e) { - return false; - } - return true; - }*/ - - public String readProcessData() throws LauncherException { - int nb; - String s = null; + private static String readProcessData( BufferedReader reader ) + throws LauncherException { + //int nb; + //String s = null; + try { - s = in.readLine(); - nb = Integer.decode(s.substring(0,1)).intValue(); - } catch(IOException io) { - throw new LauncherException(IO_ERROR); - } + final String line = reader.readLine(); + + final ResponseCode code = SocketComHelper.responseCode( line ); + //nb = Integer.decode(s.substring(0,1)).intValue(); + + if ( code == ResponseCode.PROCESS_END ) { + //if (nb == 5) { + return null; + } - if (nb == 5) { - return null; - } + String message = SocketComHelper.message( code, line ); //s = s.substring(1, s.length()); + +// if ( message == null ) { +// message = ""; +// } - s = s.substring(1, s.length()); - if (s == null) { - s = ""; + return message; + } + catch( final IOException io ) { + throw new LauncherException( IO_ERROR, io ); } - - return s; } - private String readDataUntilCompletion() throws LauncherException { - int nb=0, nbTotal, cpt = 0; - String s = null; - StringBuffer ret = new StringBuffer(); - char []c = new char[BUFSIZE+1]; - int read; - + private String readDataUntilCompletion() + throws LauncherException { try { +// int nbTotal, cpt = 0; + StringBuffer ret = new StringBuffer(); + //System.out.println("Reading first data "); - s = in.readLine(); - nb = Integer.decode(s.substring(0,1)).intValue(); - if (nb == 8) { - nbTotal = Integer.decode(s.substring(1,s.length())).intValue(); + String s = inReader.readLine(); + + final ResponseCode code = SocketComHelper.responseCode( s ); +// nb = Integer.decode(s.substring(0,1)).intValue(); + + if ( ResponseCode.FILE_DATA == code ) { + //if (nb == 8) { + char[] c = new char[BUFSIZE+1]; + int read; + int cpt = 0; + int nbTotal = Integer.decode( SocketComHelper.message( code, s ) );//Integer.decode(s.substring(1,s.length())).intValue(); //System.out.println("Total= " + nbTotal); - while (((cpt < nbTotal) && (read = in.read(c, 0, Math.min(BUFSIZE, nbTotal - cpt))) > -1)) { - //s = new String(c, 0, read); - //System.out.println("Nb read: " + read + " size of s =" + s.length()); - //nb = Integer.decode(s.substring(0,1)).intValue(); - //ret.append(s.substring(0, s.length())); + while (((cpt < nbTotal) && (read = inReader.read(c, 0, Math.min(BUFSIZE, nbTotal - cpt))) > -1)) { ret.append(c, 0, read); cpt += read; } - // Read last info - //System.out.println("Reading last info"); - nb = readReturn(); - //System.out.println("Return = " + nb); - //read = in.read(c, 0, 1); - //s = new String(c, 0, read); - //System.out.println("Last s=" + s + " read=" + read); - //nb = Integer.decode(s.substring(0,1)).intValue(); - //System.out.println("Last info=" + nb); - //nb= 3; - } - } catch(IOException io) { - throw new LauncherException(IO_ERROR); - } - - if (nb != 3) { - throw new LauncherException(FILE_FAILED); - } - return new String(ret); - } - - /*private String readDataUntilCompletionInfoLine() throws LauncherException { - int nb = 8; - String s = null; - StringBuffer ret = new StringBuffer(); - - - try { - //System.out.println("Reading data"); - while ((nb == 8) && ((s = in.readLine()) != null)) { - //System.out.println("read: " + s); - nb = Integer.decode(s.substring(0,1)).intValue(); - if (nb == 8) { - ret.append(s.substring(1, s.length()) + "\n"); - } - } - } catch(IOException io) { - throw new LauncherException(IO_ERROR); - } - - if (nb != 3) { - throw new LauncherException(FILE_FAILED); - } - - return new String(ret); - }*/ - - private int readReturn() throws LauncherException { - int nb; - String s = null; + // Read last info and check for success + readServerResponse(); +// +// if (nb != 3) { +// throw new LauncherException(FILE_FAILED); +// } + } - try { - //System.out.println("Reading line"); - s = in.readLine(); - TraceManager.addDev("Got from Server:" + s); - //System.out.println("Line read"); - //System.out.println("Converting nb s=>" + s + "<"); - nb = Integer.decode(s.substring(0,1)).intValue(); - //System.out.println("Nb = " + nb); - } catch(IOException io) { - System.out.println("Exception 0"); - throw new LauncherException(IO_ERROR); + return new String(ret); } - - if (nb != 3) { - System.out.println("Exception 1"); - throw new LauncherException(FILE_FAILED); + catch(IOException io) { + throw new LauncherException( IO_ERROR, io ); } - return nb; } - private int readId() throws LauncherException { - int nb; - String s = null; + private void readServerResponse() + throws LauncherException { + // int nb; + //String s = null; try { - s = in.readLine(); - nb = Integer.decode(s.substring(0,1)).intValue(); - } catch(IOException io) { - throw new LauncherException(IO_ERROR); + final String s = inReader.readLine(); + TraceManager.addDev("Got from Server:" + s); + + final ResponseCode code = SocketComHelper.responseCode( s ); + //nb = Integer.decode(s.substring(0,1)).intValue(); + + if ( code != ResponseCode.SUCCESS ) { + throw new LauncherException( FAILED ); + } } - - if (nb == 0) { - throw new LauncherException(ID_FAILED); + catch( IOException io ) { + throw new LauncherException( IO_ERROR, io ); } - - return nb; +// +// if (nb != 3) { +// System.out.println("Exception 1"); +// throw new LauncherException(FILE_FAILED); +// } +// return nb; } - private void readReturnPipedProcesses() throws LauncherException { - int nb; - String s = null; + private int readId() + throws LauncherException { +// int nb; +// String s = null; try { - s = in.readLine(); - nb = Integer.decode(s.substring(0,1)).intValue(); - } catch(IOException io) { - throw new LauncherException(IO_ERROR); - } + final String s = inReader.readLine(); + final int nb = Integer.decode(s.substring(0,1)); - if (nb != 3) { - throw new LauncherException(PROC_FAILED); + if ( nb == 0 ) { + throw new LauncherException(ID_FAILED); + } + + return nb; + } + catch( IOException io ) { + throw new LauncherException( IO_ERROR, io ); } +// +// return nb; } - - private int readPortString() throws LauncherException { - int nb; - String s = null; +// +// private void readReturnPipedProcesses() throws LauncherException { +//// int nb; +//// String s = null; +// try { +// final String s = inReader.readLine(); +// final ResponseCode code = SocketComHelper.responseCode( s ); +// //nb = Integer.decode(s.substring(0,1)).intValue(); +// +// if ( code != ResponseCode.SUCCESS ) { +// //if (nb != 3) { +// throw new LauncherException( PROC_FAILED ); +// } +// } +// catch(IOException io) { +// throw new LauncherException( IO_ERROR, io ); +// } +// } + + private void readPortString() throws LauncherException { + // int nb; + //String s = null; + try { - s = in.readLine(); - nb = Integer.decode(s.substring(0,1)).intValue(); - } catch(IOException io) { - throw new LauncherException(IO_ERROR); - } + final String s = inReader.readLine(); + final ResponseCode code = SocketComHelper.responseCode( s ); + //nb = Integer.decode(s.substring(0,1)).intValue(); - if (nb == 2) { - throw new LauncherException(PROC_FAILED); - } + if ( code == ResponseCode.FAILED ) { + //if (nb == 2) { + throw new LauncherException( PROC_FAILED ); + } - portString = -1; - portString2 = -1; - try { - portString = Integer.decode(s.substring(1, s.length())).intValue(); - } catch (Exception e) { - throw new LauncherException(IO_ERROR); - } + //portString = -1; + portString2 = -1; + + portString = Integer.decode( SocketComHelper.message( code, s ) );//// Integer.decode(s.substring(1, s.length())).intValue(); - if (portString <1) { - throw new LauncherException(PROC_FAILED); + if ( portString < 1) { + throw new LauncherException( PROC_FAILED ); + } + } + catch( IOException io ) { + throw new LauncherException( IO_ERROR, io ); } - - return portString; + } + + private void connect() + throws LauncherException { + clientSocket = connect( port ); + + try { + inReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + out = new PrintStream(clientSocket.getOutputStream()); + } + catch ( IOException ex ) { + throw new LauncherException(SERV_NOT_RESP+host, ex ); + } } - private void connect(int portNet) throws LauncherException { - InetAddress ina = null; - - //System.out.println("Connecting on port " + portNet); - + private Socket connect( final int portNet ) + throws LauncherException { if (host == null) { throw new LauncherException(NO_HOST); } try { - ina = InetAddress.getByName(host); - } catch (UnknownHostException e) { - throw new LauncherException(INET + host); - } + final InetAddress ina = InetAddress.getByName(host); - try { - clientSocket = new Socket(ina, portNet); - } catch (IOException io) { - throw new LauncherException(SERV_NOT_RESP+host); + try { + return new Socket( ina, portNet ); + } + catch ( IOException ex ) { + throw new LauncherException(SERV_NOT_RESP+host, ex ); + } } - - try { - in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - //in2 = new DataInputStream(clientSocket.getInputStream()); - out = new PrintStream(clientSocket.getOutputStream()); - //System.out.println("Connected on port " + portNet); - } catch (Exception e) { - throw new LauncherException(SERV_NOT_RESP+host); + catch (UnknownHostException e) { + throw new LauncherException(INET + host, e ); } } - - /*private void basicConnect() throws LauncherException { - InetAddress ina = null; - - if (host == null) { - throw new LauncherException(NO_HOST); - } - - try { - ina = InetAddress.getByName(host); - } catch (UnknownHostException e) { - throw new LauncherException(INET + host); - } - - try { - clientSocket = new Socket(ina, port); - } catch (IOException io) { - throw new LauncherException(SERV_NOT_RESP+host); - } - - try { - in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); - //in2 = new DataInputStream(clientSocket.getInputStream()); - out = new PrintStream(clientSocket.getOutputStream()); - } catch (Exception e) { - throw new LauncherException(SERV_NOT_RESP+host); - } - }*/ - } diff --git a/src/launcher/RshServer.java b/src/launcher/RshServer.java index 5d982995ccdf5aa959c64af27d835718068b57fc..318cf882c742c1189b02ed389d47b1827e1ee3ab 100755 --- a/src/launcher/RshServer.java +++ b/src/launcher/RshServer.java @@ -55,6 +55,7 @@ import java.io.InputStreamReader; import java.io.PrintStream; import java.net.ServerSocket; import java.net.Socket; +import java.util.Iterator; import java.util.Vector; import myutil.AESEncryptor; @@ -65,7 +66,7 @@ public class RshServer { private int port = PORT_NUMBER; private ServerSocket server = null; - private int id = 0; + //private int id = 0; private Vector<ExecutionThread> processes; private int MAX_PROC = 255; public static final String VERSION = "0.61"; @@ -80,46 +81,50 @@ public class RshServer { public static String iv = "Wh4t4b0utThisKe?"; public RshServer() { - startingServer(); + startingServer(); } public RshServer(String _sk) { - sk = _sk; - startingServer(); + sk = _sk; + startingServer(); } private void startingServer() { - processes = new Vector<ExecutionThread>(); - int i = 0; - for(i=0; i<100; i++) { - try { - server = new ServerSocket(port+i); - break; - } catch (Exception e) { - //System.out.println("Server could not start(Socket pb)"); - } - } - if (i == 100) { - TraceManager.addDev("Launching external applications is disabled: no socket is available"); - } else { - port = port +i; - launcher.RshClient.PORT_NUMBER = port; - TraceManager.addDev("Using port: " + port); - } + processes = new Vector<ExecutionThread>(); + int i = 0; + + for(i=0; i < 100; i++) { + try { + server = new ServerSocket(port+i); + + break; + } + catch (Exception e) { + //System.out.println("Server could not start(Socket pb)"); + } + } + + if (i == 100) { + TraceManager.addDev("Launching external applications is disabled: no socket is available"); + } + else { + port = port +i; + launcher.RshClient.PORT_NUMBER = port; + TraceManager.addDev("Using port: " + port); + } } - public void setNonSecure() { isSecure = false; } public String getSecretKey() { - return sk; + return sk; } public String getIV() { - return iv; + return iv; } private void printProcessRunning() { @@ -145,22 +150,50 @@ public class RshServer { } private Socket waitForClient() { - Socket s = null; + //Socket s = null; TraceManager.addDev("Waiting for command"); + try { - s = server.accept(); - } catch (Exception e) { + return server.accept(); + } + catch (Exception e) { nbTry ++; + return null; } - return s; + // return s; + } + + private void respond( final PrintStream out, + final ResponseCode code ) { + respond( out, code, null ); + } + + private void respond( final PrintStream out, + final String message ) { + respond( out, null, message ); } - private void respond(PrintStream out, String s) { + private void respond( final PrintStream out, + final ResponseCode code, + final String message ) { try { - out.println(s); - out.flush(); - } catch (Exception e) { + SocketComHelper.send( out, code, message ); +// final StringBuilder sentMess = new StringBuilder(); +// +// if ( code != null ) { +// sentMess.append( code.name() ); +// } +// +// if ( message != null ) { +// sentMess.append( message ); +// } +// +// out.println( sentMess.toString() ); +// out.flush(); + } + catch (Exception e) { + TraceManager.addError( e ); } } @@ -173,7 +206,7 @@ public class RshServer { // } // } - private int startNewProcess(String path) { + private int startNewProcess( String path ) { if (processes.size() >= MAX_PROC) { return -1; } @@ -192,7 +225,7 @@ public class RshServer { } - private int createNewProcess(String path) { + private int createNewProcess( final String path ) { if (processes.size() >= MAX_PROC) { return -1; } @@ -220,18 +253,26 @@ public class RshServer { } private boolean startProcess(int id) { - ExecutionThread et; - for(int i=0; i<processes.size(); i++) { - et = (ExecutionThread)(processes.elementAt(i)); - if (et.getPort() == id) { - if (et.isStarted()) { - return false; - } - et.start(); - return true; - } + ExecutionThread et = getExecutionThread( id ); + + if ( et == null || et.isStarted() ) { + return false; } - return false; + + et.start(); + + return true; +// for(int i=0; i<processes.size(); i++) { +// et = (ExecutionThread)(processes.elementAt(i)); +// if (et.getPort() == id) { +// if (et.isStarted()) { +// return false; +// } +// et.start(); +// return true; +// } +// } +// return false; } private ExecutionThread getExecutionThread(int id) { @@ -280,28 +321,46 @@ public class RshServer { printProcessRunning(); } - public void killProcess(int id) { + public boolean killProcess(int id) { ExecutionThread et; for(int i=0; i<processes.size(); i++) { et = processes.elementAt(i); + if (et.getPort() == id) { et.stopProcess(); processes.removeElement(et); TraceManager.addDev("Process " + id + " killed"); - return; + + return true; } } + printProcessRunning(); + + return false; } public void killAllProcesses() { - ExecutionThread et; - for(int i=0; i<processes.size(); i++) { - et = processes.elementAt(i); - et.stopProcess(); - processes.removeElement(et); - TraceManager.addDev("Process " + id + " killed"); + //ExecutionThread et; + final Iterator<ExecutionThread> procIt = processes.iterator(); + + while ( procIt.hasNext() ) { + final ExecutionThread et = procIt.next(); + et.stopProcess(); + procIt.remove(); + + TraceManager.addDev( "Process " + et.getId() + " killed." ); } + + // DB: Issue #18: This code does not iterate through all the elements because process.size() changes at every iteration +// ExecutionThread et; +// for(int i=0; i<processes.size(); i++) { +// et = processes.elementAt(i); +// et.stopProcess(); +// processes.removeElement(et); +// TraceManager.addDev("Process " + id + " killed"); +// } + printProcessRunning(); } @@ -320,114 +379,221 @@ public class RshServer { try { info = in.readLine(); - } catch (Exception e) { - TraceManager.addDev("Exception when reading client information=" + info); - return; + } + catch (Exception e) { + TraceManager.addError("Exception when reading client information=" + info, e ); + + return; } if (sk != null) { info = checkSecurity(info); - } - TraceManager.addDev("Got from client:" + info); + TraceManager.addDev("Got from client:" + info); - if (info != null) { + if ( info != null ) { + final RequestCode reqCode = SocketComHelper.requestCode( info ); + TraceManager.addDev("Received request code " + reqCode + "." ); + final String message = SocketComHelper.message( reqCode, info ); + TraceManager.addDev("Received request message '" + message + "'." ); - if (info.substring(0, 1).equals("0")) { // Session id - if (info.substring(1, 2).equals("0")) { // Get session id + switch ( reqCode ) { + // Session id + case GET_SESSION_ID: { +// if (info.substring(0, 1).equals("0")) { // Session id + //if (info.substring(1, 2).equals("0")) { // Get session id int id = getSessionId(); TraceManager.addDev("-> New session id = " + id); - respond(out, ""+id); // A zero response means error - } else { + respond(out, "" + id ); // A zero response means error + + break; + } + case FREE_SESSION_ID: { + //} else { try { - int id = Integer.decode(info.substring(1, 2)).intValue(); - freeSessionId(id); - TraceManager.addDev("-> Session id=" + id + " terminated"); - respond(out, ""+id); - } catch (Exception e) { - respond(out, "0"); + int id = Integer.decode( message );//.intValue(); + freeSessionId( id ); + TraceManager.addDev("-> Free session id=" + id + " terminated"); + respond( out, "" + id ); } - } - } else if (info.substring(0, 1).equals("1")) { - // start process at once - int id = startNewProcess(info.substring(1, info.length())); - if (id <0) { - respond(out, "2"); // fail - } else { - TraceManager.addDev("Process accepted on port " + id); - respond(out, "3" + id); // process created - } - } else if (info.substring(0, 1).equals("2")) { - // Piped processes - TraceManager.addDev("Piped processes"); - String str = info.substring(1, info.length()); - String str1, str2; - int index = str.indexOf(' '); - TraceManager.addDev("index = " + index); - if (index > 0) { - str1 = str.substring(0, index); - str2 = str.substring(index + 1, str.length()); - TraceManager.addDev("str = " + str + " str1 = *" + str1 + "* str2 = *" + str2 + "*"); - if (pipeProcesses(str1, str2)) { - TraceManager.addDev("Making piped processes"); - respond(out, "3"); // OK - } else { - TraceManager.addDev("Making piped processes FAILED"); - respond(out, "2"); // fail + catch ( Exception e ) { + respond( out, ResponseCode.FAILED ); + + TraceManager.addError( e ); } - } else { - TraceManager.addDev("Making piped processes FAILED"); - respond(out, "2"); // fail + + break; } - - } else if (info.substring(0, 1).equals("3")) { + case PROCESS_CREATE_START: { + //} else if (info.substring(0, 1).equals("1")) { + // start process at once + int id = startNewProcess( message );//info.substring(1, info.length())); + + if ( id < 0 ) { + respond(out, ResponseCode.FAILED ); // fail + } + else { + TraceManager.addDev("Process accepted on port " + id); + respond( out, ResponseCode.SUCCESS, Integer.toString( id ) ); // process created + } + + break; + } + case PROCESS_CHECK_RETURN_CODE: { + final ExecutionThread process = getExecutionThread( Integer.decode( message ) ); + + if ( process == null ) { + TraceManager.addError( "Process " + message + " not created!" ); + respond( out, ResponseCode.FAILED ); + } + else { + TraceManager.addDev("Process " + message + " will send its return code." ); + process.setSendReturnCode( true ); + respond( out, ResponseCode.SUCCESS ); // process created + } + + break; + } + case PROCESS_GET_RETURN_CODE: { + final ExecutionThread process = getExecutionThread( Integer.decode( message ) ); + + if ( process == null ) { + TraceManager.addError( "Process " + message + " not created!" ); + respond( out, ResponseCode.FAILED ); + } + else { + final String retCodeStr = String.valueOf( process.getReturnCode() ); + TraceManager.addDev("Sending return code " + retCodeStr + " for process " + message + "." ); + respond( out, ResponseCode.SUCCESS, retCodeStr ); + } + + break; + } + case PROCESS_PIPE: { + //else if (info.substring(0, 1).equals("2")) { + // Piped processes + TraceManager.addDev("Piped processes."); + //String str = info.substring(1, info.length()); + //String str1, str2; + final int index = message.indexOf(' '); + //TraceManager.addDev("index = " + index); + + if (index > 0) { + final String str1 = message.substring(0, index); + final String str2 = message.substring(index + 1 ); + TraceManager.addDev("str = " + message + " str1 = *" + str1 + "* str2 = *" + str2 + "*"); + + if (pipeProcesses(str1, str2)) { + TraceManager.addDev("Making piped processes..."); + respond( out, ResponseCode.SUCCESS ); // OK + } + else { + TraceManager.addDev("Making piped processes failed!"); + respond(out, ResponseCode.FAILED ); // fail + } + } + else { + TraceManager.addDev("Making piped processes FAILED"); + respond(out, ResponseCode.FAILED ); // fail + } + + break; + } + case PROCESS_CREATE: { + // } else if (info.substring(0, 1).equals("3")) { // create process - int id = createNewProcess(info.substring(1, info.length())); - if (id <0) { - respond(out, "2"); // fail - } else { - TraceManager.addDev("Process accepted on port " + id); - respond(out, "3" + id); // process created - } - } else if (info.substring(0, 1).equals("4")) { + int id = createNewProcess( message ); + + if ( id < 0 ) { + respond( out, ResponseCode.FAILED ); // fail + } + else { + TraceManager.addDev( "Process accepted on port " + id ); + respond( out, ResponseCode.SUCCESS, Integer.toString( id ) ); // process created + } + + break; + } + case PROCESS_START: { + //} else if (info.substring(0, 1).equals("4")) { // start already created process - if (startProcess(info.substring(1, info.length()))) { - TraceManager.addDev("Process started on port " + id); - respond(out, "3" + id); // process created - } else { - respond(out, "2"); // fail - } - } else if (info.substring(0, 1).equals("5")) { - // kill all processes - try { - killAllProcesses(); - } catch (Exception e) { - - } - }else if (info.substring(0, 1).equals("6")) { + if ( startProcess( message ) ) { + TraceManager.addDev("Process started on port " + message ); + respond(out, ResponseCode.SUCCESS, message ); // process created + } + else { + respond( out, ResponseCode.FAILED ); // fail + } + + break; + } + case PROCESS_KILL_ALL: { + //} else if (info.substring(0, 1).equals("5")) { + // kill all processes + try { + killAllProcesses(); + + respond( out, ResponseCode.SUCCESS ); + } + catch (Exception e) { + TraceManager.addError( e ); + + respond( out, ResponseCode.FAILED ); // fail + } + + break; + } + case PROCESS_KILL: { + //}else if (info.substring(0, 1).equals("6")) { // kill process - try { - int id = Integer.decode(info.substring(1, info.length())).intValue(); - TraceManager.addDev("Demand to kill: " + id); - killProcess(id); - } catch (Exception e) { - - } - } else if (info.substring(0, 1).equals("7")) { - //file : put - String fileName = info.substring(1, info.length()); - makeFileFromData(in, out, fileName); - } else if (info.substring(0, 1).equals("8")) { - //file : get - String fileName = info.substring(1, info.length()); - sendDataFile(in, out, fileName); - } else if (info.substring(0, 1).equals("9")) { - //file : delete - String fileName = info.substring(1, info.length()); - deleteFile(in, out, fileName); - } else { - System.exit(0); + try { + int id = Integer.decode( message ); + TraceManager.addDev("Demand to kill: " + id); + + if ( killProcess( id ) ) { + respond( out, ResponseCode.SUCCESS ); + } + else { + respond( out, ResponseCode.FAILED ); + } + } + catch (Exception e) { + TraceManager.addError( e ); + + respond( out, ResponseCode.FAILED ); // fail + } + + break; + } + case FILE_PUT: { + //} else if (info.substring(0, 1).equals("7")) { + //file : put + //String fileName = info.substring(1, info.length()); + makeFileFromData( in, out, message ); + + break; + } + case FILE_GET: { +// } else if (info.substring(0, 1).equals("8")) { + //file : get + //String fileName = info.substring(1, info.length()); + sendDataFile( in, out, message ); + + break; + } + case FILE_DELETE: { + //} else if (info.substring(0, 1).equals("9")) { + //file : delete + //String fileName = info.substring(1, info.length()); + deleteFile( in, out, message ); + + break; + } + default: + //} else { + // TODO: Is this really a good behavior? + System.exit(0); } } } @@ -438,7 +604,8 @@ public class RshServer { if (!isFileOkForSave(file)) { TraceManager.addDev("Cannot make file"); - respond(out, "2"); // fail + respond( out, ResponseCode.FAILED ); // fail + return; } @@ -446,52 +613,75 @@ public class RshServer { String info; TraceManager.addDev("Waiting for file data"); - while(true) { + + while( true ) { try { info = in.readLine(); - } catch (Exception e) { - return; + } + catch (Exception e) { + TraceManager.addError( e ); + + return; } - if (sk != null) { - info = checkSecurity(info); - } + if ( sk != null ) { + info = checkSecurity(info); + } + + final RequestCode code = SocketComHelper.requestCode( info ); + final String message = SocketComHelper.message( code, info ); - if ((info == null) || (info.length() == 0)) { + if ( code == null || code == RequestCode.FILE_SAVE ) {//|| (info.length() == 0)) { // Assumes it is an EOF TraceManager.addDev("Wrong EOF -> assumes it is an EOF"); + try { FileOutputStream fos = new FileOutputStream(file); fos.write((new String(fileData)).getBytes()); fos.close(); - } catch (Exception e) { - TraceManager.addDev("Error when feeding file"); - respond(out, "2"); // fail + } + catch (Exception e) { + TraceManager.addError("Error when feeding file", e ); + + respond( out, ResponseCode.FAILED ); // fail + return; } - respond(out, "3"); // file created + + respond( out, ResponseCode.SUCCESS ); // file created + return; - } else if (info.substring(0, 1).equals("8")) { + } + else if ( code == RequestCode.FILE_APPEND ) {//== info.substring(0, 1).equals("8")) { // fileData - fileData.append(info.substring(1, info.length()) + "\n"); - } else if (info.substring(0, 1).equals("7")) { - // EOF - TraceManager.addDev("EOF"); - try { - FileOutputStream fos = new FileOutputStream(file); - fos.write((new String(fileData)).getBytes()); - fos.close(); - } catch (Exception e) { - TraceManager.addDev("Error when feeding file"); - respond(out, "2"); // fail - return; - } - respond(out, "3"); // file created - return; - } else { + fileData.append( message + "\n" ); + } +// else if ( code == RequestCode.FILE_SAVE ) { +// // EOF +// TraceManager.addDev("EOF"); +// +// try { +// FileOutputStream fos = new FileOutputStream(file); +// fos.write((new String(fileData)).getBytes()); +// fos.close(); +// } +// catch (Exception e) { +// TraceManager.addError("Error when feeding file", e ); +// +// respond( out, ResponseCode.FAILED ); // fail +// +// return; +// } +// +// respond( out, ResponseCode.SUCCESS ); // file created +// +// return; +// } + else { TraceManager.addDev("Unknown PDU (file)=" + info); - respond(out, "2"); // fail + respond( out, ResponseCode.FAILED ); // fail + return; } } @@ -502,31 +692,30 @@ public class RshServer { File file = new File(fileName); if (!isFileOkForRead(file)) { - //System.out.println("Cannot read file"); - respond(out, "2"); // fail + respond( out, ResponseCode.FAILED ); // fail + return; } try { FileInputStream fis = new FileInputStream(file); - /*int nb = fis.available(); - System.out.println("New byte " + fileName); - byte [] ba = new byte[nb]; - fis.read(ba); - System.out.println("Reading " + fileName); - fis.close();*/ if (sendData(out, fis)) { //System.out.println("Sending 3 info to say OK"); - respond(out, "3"); - } else { + respond( out, ResponseCode.SUCCESS ); + } + else { TraceManager.addDev("Sending failed"); - respond(out, "2"); + respond( out, ResponseCode.FAILED ); } - } catch(Exception e) { - respond(out, "2"); // fail + } + catch(Exception e) { + TraceManager.addError( e ); + respond( out, ResponseCode.FAILED ); // fail + return; } + TraceManager.addDev("Sending completed"); } @@ -536,11 +725,15 @@ public class RshServer { try { file.delete(); - } catch(Exception e) { - respond(out, "2"); // fail + + respond( out, ResponseCode.SUCCESS ); + } + catch(Exception e) { + TraceManager.addError( e ); + respond( out, ResponseCode.FAILED ); // fail + return; } - respond(out, "3"); } public void startServer() { @@ -573,9 +766,11 @@ public class RshServer { return false; } } catch (Exception e) { - System.out.println("Exception file " + e.getMessage()); - return false; + TraceManager.addError( "Exception file " + e.getMessage(), e ); + + return false; } + return true; } @@ -588,16 +783,18 @@ public class RshServer { try { if (!file.exists()) { if (!file.createNewFile()) { - TraceManager.addDev("creation pb"); + TraceManager.addError("creation pb"); return false; } } if (!file.canWrite()) { - TraceManager.addDev("write pb"); + TraceManager.addError("write pb"); return false; } - } catch (Exception e) { - System.out.println("Exception file " + e.getMessage()); + } + catch (Exception e) { + TraceManager.addError( e ); + return false; } @@ -614,7 +811,8 @@ public class RshServer { //BufferedReader br = new BufferedReader(sr); try { // Sending first line : 8 + nbByte - respond(out, new String("8" + fis.available())); + respond(out, ResponseCode.FILE_DATA, Integer.toString( fis.available() ) ); +// respond(out, new String("8" + fis.available())); int cpt = 0; while((nbRead = fis.read(ba, 0, BUFSIZE)) > -1) { @@ -622,29 +820,32 @@ public class RshServer { out.write(ba, 0, nbRead); cpt += nbRead; } + TraceManager.addDev("Nb written:" + cpt); fis.close(); - } catch (Exception e) { - TraceManager.addDev("Exception when sending file: " + e.getMessage()); + } + catch (Exception e) { + TraceManager.addError( "Exception when sending file: " + e.getMessage(), e ); + return false; } + return true; } private String checkSecurity(String _ciphered) { - if (!isSecure) { - return _ciphered; // The string is in fact not ciphered - } - - if (sk == null) { - return null; - } - - String deciphered = AESEncryptor.decrypt(sk, iv, _ciphered); - - TraceManager.addDev("Deciphered=" + deciphered); - return deciphered; + if (!isSecure) { + return _ciphered; // The string is in fact not ciphered + } + + if (sk == null) { + return null; + } + + String deciphered = AESEncryptor.decrypt(sk, iv, _ciphered); + TraceManager.addDev("Deciphered=" + deciphered); + return deciphered; } } diff --git a/src/launcher/SocketComHelper.java b/src/launcher/SocketComHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..548bf6c1057908536f1c4d40b99a0dffca2978ec --- /dev/null +++ b/src/launcher/SocketComHelper.java @@ -0,0 +1,112 @@ +package launcher; + +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import myutil.AESEncryptor; +import myutil.TraceManager; + +public class SocketComHelper { + + private static final Comparator<Enum<?>> codeComparator = new Comparator<Enum<?>>() { + + @Override + public int compare( final Enum<?> code1, + final Enum<?> code2 ) { + // Sort by decreasing ordinal number + return Integer.valueOf( code2.ordinal() ).compareTo( code1.ordinal() ); + } + }; + + private static final List<RequestCode> sortedRequestCodes; + + static { + sortedRequestCodes = new ArrayList<RequestCode>( Arrays.asList( RequestCode.values() ) ); + Collections.sort( sortedRequestCodes, codeComparator ); + } + + private static final List<ResponseCode> sortedResponseCodes; + + static { + sortedResponseCodes = new ArrayList<ResponseCode>( Arrays.asList( ResponseCode.values() ) ); + Collections.sort( sortedResponseCodes, codeComparator ); + } + + private SocketComHelper() { + } + + public static RequestCode requestCode( final String message ) { + if ( message != null ) { + for ( final RequestCode code : sortedRequestCodes ) { + if ( message.startsWith( toString( code ) ) ) { + return code; + } + } + } + + return null; + } + + public static String message( final RequestCode code, + final String completeMessage ) { + return completeMessage.replaceFirst( toString( code ), "" ); + } + + public static void send( final PrintStream out, + final RequestCode code, + String message, + final String encryptionKey ) { + message = toString( code ) + message; + + if ( encryptionKey != null) { + // cipher the information + message = AESEncryptor.encrypt( encryptionKey, RshServer.iv, message); + TraceManager.addDev( "Ciphered message to server=" + message ); + } + + out.println( message); + out.flush(); + } + + public static ResponseCode responseCode( final String message ) { + if ( message != null ) { + for ( final ResponseCode code : sortedResponseCodes ) { + if ( message.startsWith( toString( code ) ) ) { + return code; + } + } + } + + return null; + } + + public static String message( final ResponseCode code, + final String completeMessage ) { + return completeMessage.replaceFirst( toString( code ), "" ); + } + + public static void send( final PrintStream out, + final ResponseCode code, + final String message ) { + final StringBuilder sentMess = new StringBuilder(); + + if ( code != null ) { + sentMess.append( toString( code ) ); + } + + if ( message != null ) { + sentMess.append( message ); + } + + out.println( sentMess.toString() ); + out.flush(); + } + + private static String toString( final Enum<?> code ) { + return String.valueOf( code.ordinal() ) + ":"; + } +} diff --git a/src/myutil/ErrorThread.java b/src/myutil/ErrorThread.java index 8ab0f8fde60f2da2f8d0b96e454edb72a55d70dc..35c1d2e1c2a8d5bb0ae05088ca1881ebb87110f8 100755 --- a/src/myutil/ErrorThread.java +++ b/src/myutil/ErrorThread.java @@ -69,7 +69,7 @@ public class ErrorThread extends Thread { String err; try { - while (((err = br.readLine()) != null) && (go == true) && (mpi.hasToContinue())) { + while (((err = br.readLine()) != null) && go && mpi.hasToContinue() ) { System.out.println("Error " + err); mpi.appendOut(err+"\n"); mpi.setError(); diff --git a/src/myutil/FileUtils.java b/src/myutil/FileUtils.java index 85d0873a06ff397a367d686b61583818cb3f6f34..ecae482a39dfdf2bdfcbf6cf70d6d534abc2f72d 100755 --- a/src/myutil/FileUtils.java +++ b/src/myutil/FileUtils.java @@ -79,8 +79,8 @@ public class FileUtils { } public static boolean checkFileForSave(File file) throws FileException { - boolean ok = true; - String pb = ""; + // boolean ok = true; + // String pb = ""; if (file == null) { return false; diff --git a/src/myutil/TraceManager.java b/src/myutil/TraceManager.java index 3270c67eca808df3bd1b215dd7e1c5c8d902a7b1..e661fa37eced9feaf969dc68cdb0e24c4dd50169 100644 --- a/src/myutil/TraceManager.java +++ b/src/myutil/TraceManager.java @@ -79,22 +79,27 @@ public class TraceManager { public static void addError( final String message, final Throwable error ) { - addError( message ); + if ( message != null ) { + switch( errPolicy ) { + case TO_CONSOLE: + System.err.println( message ); + break; + default: + System.err.println( message ); + } + } if ( error != null ) { error.printStackTrace(); } } - public static void addError(String _s) { - switch(errPolicy) { - case TO_CONSOLE: - System.err.println(_s); - break; - default: - System.err.println(_s); - } + public static void addError( final String message ) { + addError( message, null ); } + public static void addError( final Throwable error ) { + addError( null, error ); + } } // Class TraceManager diff --git a/src/remotesimulation/RemoteConnection.java b/src/remotesimulation/RemoteConnection.java index aba5dd587684b2e07280495c305cd9a357d7b2c3..284bf6d9a96d6ed255b26677db1c5977df196b97 100755 --- a/src/remotesimulation/RemoteConnection.java +++ b/src/remotesimulation/RemoteConnection.java @@ -139,7 +139,8 @@ public class RemoteConnection { } } - public String readOneLine() throws RemoteConnectionException { + public String readOneLine() + throws RemoteConnectionException { // int nb; String s = null; try { diff --git a/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java b/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java index ca7d47a8073b328b7be41d0bf903d5bb3568d816..9c81cfadf82359d571d7f3aa764c03ca6e49d06c 100644 --- a/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java +++ b/src/tmltranslator/tomappingsystemc2/DiploSimulatorCodeGenerator.java @@ -131,7 +131,7 @@ public class DiploSimulatorCodeGenerator implements IDiploSimulatorCodeGenerator debug = _debug; optimize = _optimize; tmlmapping.removeAllRandomSequences(); - tmlmapping.handleCPs(); + tmlmapping.handleCPs(); tmlmodeling = tmlmapping.getTMLModeling(); tasks = new ArrayList<MappedSystemCTask>(); //generateSystemCTasks(); diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java index 478533bdb3be2d52538dd16a5374c9def30df5e3..18d6231a741e1b74784038229273f452c66ef91f 100755 --- a/src/ui/GTURTLEModeling.java +++ b/src/ui/GTURTLEModeling.java @@ -246,8010 +246,7778 @@ import ui.graph.*; public class GTURTLEModeling { - //Added by Solange - - public GProactiveDesign gpdtemp; - - - // - private Vector panels; /* analysis, design, deployment, tml design */ - private TURTLEModeling tm; - private AvatarSpecification avatarspec; - // private AttackTree attackTree; - private AVATAR2UPPAAL avatar2uppaal; - private AVATAR2ProVerif avatar2proverif; - private boolean optimizeAvatar; - private int tmState; // 0:generated, 1: to be generated from mapping, 2: to be generated from TML modeling - - private TMLModeling tmlm; - private TMLMapping artificialtmap; - private TMLMapping tmap; - private TMLCP tmlcp; - private TML2Avatar t2a; - private RequirementModeling rm; - private NCStructure ncs; - private MainGUI mgui; - private CorrespondanceTGElement listE; - private String rtlotos; - - private EBRDD ebrdd; - - private UPPAALSpec uppaal; - private RelationTIFUPPAAL uppaalTIFTable; - private RelationTMLUPPAAL uppaalTMLTable; - - private ProVerifSpec proverif; - - private AVATAR2TPN avatar2tpn; - private TPN tpnFromAvatar; - - private String tpn; - private String sim; - private String dta; - private String dtadot; - private String rg; - private String rgdot; - private String rgaut; - private String rgautdot; - private String rgautproj; - private String rgautprojdot; - private String tlsa; - private String tlsadot; - - private ArrayList<RG> graphs; - private GraphTree gt; - - private int nbRTLOTOS; - private int nbSuggestedDesign; - // private int nbSuggestedAnalysis; - // private int nbTPN; - - //private ValidationDataTree vdt; - private SearchTree st; - private SyntaxAnalysisTree mcvdt; - private InvariantDataTree idt; - - private LinkedList<CheckingError> checkingErrors; - private LinkedList<CheckingError> warnings; - - private LinkedList<Invariant> invariants; - - ArrayList<TGConnectorInfo> pendingConnectors; - - private Vector savedOperations; - private Vector savedPanels; - private int nbMaxSavedOperations = 10; - private int pointerOperation; - - private DocumentBuilderFactory dbf; - private DocumentBuilder db; - private Document docCopy; - - private int decX, decY, decId; - - private static int graphId = 0; - - private int languageID; - public final static int RT_LOTOS = 0; - public final static int LOTOS = 1; - public final static int AUT = 2; - public final static int TPN = 3; - public final static int MATRIX = 4; - public final static int UPPAAL = 5; - public final static int PROVERIF = 6; - - private boolean undoRunning = false; + //Added by Solange + + public GProactiveDesign gpdtemp; + + + // + private Vector panels; /* analysis, design, deployment, tml design */ + private TURTLEModeling tm; + private AvatarSpecification avatarspec; + // private AttackTree attackTree; + private AVATAR2UPPAAL avatar2uppaal; + private AVATAR2ProVerif avatar2proverif; + private boolean optimizeAvatar; + private int tmState; // 0:generated, 1: to be generated from mapping, 2: to be generated from TML modeling + + private TMLModeling tmlm; + private TMLMapping artificialtmap; + private TMLMapping tmap; + private TMLCP tmlcp; + private TML2Avatar t2a; + private RequirementModeling rm; + private NCStructure ncs; + private MainGUI mgui; + private CorrespondanceTGElement listE; + private String rtlotos; + + private EBRDD ebrdd; + + private UPPAALSpec uppaal; + private RelationTIFUPPAAL uppaalTIFTable; + private RelationTMLUPPAAL uppaalTMLTable; + + private ProVerifSpec proverif; + + private AVATAR2TPN avatar2tpn; + private TPN tpnFromAvatar; + + private String tpn; + private String sim; + private String dta; + private String dtadot; + private String rg; + private String rgdot; + private String rgaut; + private String rgautdot; + private String rgautproj; + private String rgautprojdot; + private String tlsa; + private String tlsadot; + + private ArrayList<RG> graphs; + private GraphTree gt; + + private int nbRTLOTOS; + private int nbSuggestedDesign; + // private int nbSuggestedAnalysis; + // private int nbTPN; + + //private ValidationDataTree vdt; + private SearchTree st; + private SyntaxAnalysisTree mcvdt; + private InvariantDataTree idt; + + private LinkedList<CheckingError> checkingErrors; + private LinkedList<CheckingError> warnings; + + private LinkedList<Invariant> invariants; + + ArrayList<TGConnectorInfo> pendingConnectors; + + private Vector savedOperations; + private Vector savedPanels; + private int nbMaxSavedOperations = 10; + private int pointerOperation; + + private DocumentBuilderFactory dbf; + private DocumentBuilder db; + private Document docCopy; + + private int decX, decY, decId; + + private static int graphId = 0; + + private int languageID; + public final static int RT_LOTOS = 0; + public final static int LOTOS = 1; + public final static int AUT = 2; + public final static int TPN = 3; + public final static int MATRIX = 4; + public final static int UPPAAL = 5; + public final static int PROVERIF = 6; + + private boolean undoRunning = false; boolean hasCrypto=false; - //private Charset chset1, chset2; - - public GTURTLEModeling(MainGUI _mgui, Vector _panels) { - mgui = _mgui; - panels = _panels; - try { - dbf = DocumentBuilderFactory.newInstance(); - db = dbf.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - dbf = null; - db = null; - } - savedOperations = new Vector(); - savedPanels = new Vector(); - pointerOperation = -1; - - graphs = new ArrayList<RG>(); - invariants = new LinkedList<Invariant>(); - - //vdt = new ValidationDataTree(mgui); - mcvdt = new SyntaxAnalysisTree(mgui); - idt = new InvariantDataTree(mgui); - st = new SearchTree(mgui); - gt = new GraphTree(mgui); - - /*if (!Charset.isSupported("UTF-8")) { - ErrorGUI.exit(ErrorGUI.ERROR_CHARSET); - } - - chset1 = Charset.forName("UTF-8");*/ - } - - public int getLanguageID() { - return languageID; - } - - public boolean isRegularTM() { - if (tm == null ){ - return false; - } - return tm.isARegularTIFSpec(); - } - - public ArrayList<RG> getRGs() { - return graphs; - } - - public void addRG(RG newGraph) { - //TraceManager.addDev("Adding new graph " + newGraph); - graphs.add(newGraph); - } - - public void removeRG(RG oldGraph) { - //TraceManager.addDev("Adding new graph " + newGraph); - graphs.remove(oldGraph); - } - - - public LinkedList<Invariant> getInvariants() { - return invariants; - } - - - - public void addInvariant(Invariant _inv) { - invariants.add(_inv); - TraceManager.addDev("Adding invariant: " + _inv.toString()); - } - - public void clearInvariants() { - invariants.clear(); - } - - - - public String saveTIF() { - if (tm == null) { - TraceManager.addDev("NO TIF to save"); - return null; - } - - TIFExchange tif = new TIFExchange(); - tif.setTURTLEModeling(tm); - String ret = tif.saveInXMLTIF(); - TraceManager.addDev("TIF=\n" + ret); - return ret; - } - - public boolean openTIF(String s) { - TIFExchange tif = new TIFExchange(); - boolean ret = false; - - try { - ret = tif.loadFromXMLTIF(s); - if (ret) { - tm = tif.getTURTLEModeling(); - tmState = 0; - TraceManager.addDev("Got TIF"); - generateDesign(); - } - } catch (Exception e) { - TraceManager.addDev("Exception on TIF: " + e.getMessage()); - } - return ret; - } - - public boolean openSD(String s) { - SDExchange sde = new SDExchange(); - boolean ret = false; - - try { - ret = sde.loadFromXMLSD(s); - if (ret) { - //tm = tif.getTURTLEModeling(); - //tmState = 0; - TraceManager.addDev("Got SD"); - generateIOD(sde.getHMSC(), sde.getMSC()); - } - } catch (Exception e) { - TraceManager.addDev("Exception on SD: " + e.getMessage()); - } - return ret; - } - - /*public void mergeChoices(boolean nonDeterministic) { - if (tm != null) { - tm.mergeChoices(nonDeterministic); - } - }*/ - - public NCStructure getNCS() { - return ncs; - } - - public void generateRTLOTOS(File f) { - TURTLETranslator tt = new TURTLETranslator(tm); - rtlotos = tt.generateRTLOTOS(); - warnings = tt.getWarnings(); - nbRTLOTOS ++; - if (f != null) { - saveInFile(f, rtlotos); - } - languageID = RT_LOTOS; - mgui.setMode(MainGUI.RTLOTOS_OK); - } - - public void generateFullLOTOS(File f) { - reinitSIM(); - reinitDTA(); - reinitRG(); - reinitRGAUT(); - reinitRGAUTPROJDOT(); - //TraceManager.addDev("generate LOTOS"); - generateLOTOS(f); - } - - public void generateLOTOS(File f) { - //tm.print(); - TraceManager.addDev("Generating Lotos"); - TURTLETranslator tt = new TURTLETranslator(tm); - rtlotos = tt.generateLOTOS(true); - warnings = tt.getWarnings(); - TraceManager.addDev("Lotos generated"); - - - - nbRTLOTOS ++; - if (f != null) { - saveInFile(f, rtlotos); - } - TraceManager.addDev("LOTOS to file done"); - languageID = LOTOS; - mgui.setMode(MainGUI.RTLOTOS_OK); - } - - public void generateTPN(File f) { - //tm.print(); - TURTLE2TPN t2tpn = new TURTLE2TPN(tm); - tpn = t2tpn.generateTPN(false).toString(); - warnings = t2tpn.getWarnings(); - - // nbTPN ++; - if (f != null) { - TraceManager.addDev("Saving in file: " + f); - saveInFile(f, tpn); - } - languageID = TPN; - - // For debug purpose - //TraceManager.addDev(tpn); - - mgui.setMode(MainGUI.RTLOTOS_OK); - } - - public LinkedList generateAUT(String path) { - TML2AUT tml2aut = new TML2AUT(tmlm); - tml2aut.generateAutomatas(true); - try { - return tml2aut.saveInFiles(path); - } catch (FileException fe) { - return null; - } - } - - public boolean generateCCode( String _title ) { - - CheckingError ce; - int type; - TGComponent tgc; - String applicationName; - TMLModelCompiler CCode; - - if( tmap == null ) { - JOptionPane.showMessageDialog( mgui.frame, "C code is only generated from an architecture diagram with mapping information", "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); - return true; - } - // Get the file from DiplodocusPECPragma - LinkedList components = mgui.getCurrentArchiPanel().tmlap.getComponentList(); - // Parse the PEC file and the library of code snippets for each DIPLODOCUS unit - applicationName = tmap.getMappedTasks().get(0).getName().split("__")[0]; // Remember that it works only for one application - CCode = new TMLModelCompiler( _title, applicationName, mgui.frame, mgui.getAllTMLCP(), tmap ); - CCode.toTextFormat(); - try { - if( ConfigurationTTool.CCodeDirectory.equals("") ) { - JOptionPane.showMessageDialog( mgui.frame, - "No directory for C code generation found in config.xml. The C code cannot be generated.", - "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); - return true; - } - else { - CCode.saveFile( ConfigurationTTool.CCodeDirectory + File.separator, applicationName ); - } - } - catch( Exception e ) { - JOptionPane.showMessageDialog( mgui.frame, "The application C files could not be saved: " + e.getMessage(), "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); - return true; - } - return false; - } - - public boolean generateTMLTxt( String _title ) { - - - //This branch is activated if doing the syntax check from the architecture panel. - //It generates the text TML for the architecture and the application + mapping information - if (tmap != null) { - TMLMappingTextSpecification spec = new TMLMappingTextSpecification( _title ); - spec.toTextFormat( tmap ); //TMLMapping - try { - //TraceManager.addDev( "*** " + ConfigurationTTool.TMLCodeDirectory + File.separator ); - spec.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec" ); - } - catch( Exception e ) { - TraceManager.addError( "Files could not be saved: " + e.getMessage() ); - return false; - } - } - - if( tmlcp != null ) { //Use the data structure filled by translateToTML... and pass it to the appropriate toTextFormat() - TraceManager.addError( "About to generate the TMLText for CPs" ); - TMLCPTextSpecification specCP = new TMLCPTextSpecification( _title ); - - //get the architecture panel and the nodes - TMLArchiDiagramPanel tmlap = mgui.getTMLArchiDiagramPanels().get(0).tmlap; - LinkedList components = tmlap.getComponentList(); - ListIterator iterator = components.listIterator(); - TGComponent tgc; - - while(iterator.hasNext()) { - tgc = (TGComponent)(iterator.next()); - if (tgc instanceof TMLArchiCPNode) { - TMLArchiCPNode node = (TMLArchiCPNode) tgc; - TraceManager.addDev( "Found CP node: " + node.getName() ); - TraceManager.addDev( "with mapping info: " + node.getMappedUnits() ); - } - } - - ArrayList<TMLCommunicationPatternPanel> tmlcpPanelsList = new ArrayList<TMLCommunicationPatternPanel>(); - //get the TMLCommunicationPatternPanels :) - for( int i = 0; i < mgui.tabs.size(); i++ ) { - TURTLEPanel panel = (TURTLEPanel)( mgui.tabs.get(i) ); - if( panel instanceof TMLCommunicationPatternPanel ) { - tmlcpPanelsList.add( (TMLCommunicationPatternPanel) panel ); - TraceManager.addDev( "Found TMLCommunicationPatternPanel: " + ((TMLCommunicationPatternPanel)panel).toString() ); - } - } - - specCP.toTextFormat( tmlcp ); // the data structure tmlcp is filled with the info concerning the CP panel - // from which the button is pressed. If there are multiple CP panels this operation must be repeated for each panel. It - // should be no difficult to implement. - try { - specCP.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec.tmlcp" ); - } - catch( Exception e ) { - TraceManager.addError( "Writing TMLText for CPs, file could not be saved: " + e.getMessage() ); - return false; - } - - } else if (tmap == null) { - //This branch is activated if doing the syntax check from the application panel. - //It only generates the application TML text - if( tmap == null ) { - TMLTextSpecification spec = new TMLTextSpecification( _title ); - spec.toTextFormat( tmlm ); //TMLModeling - try { - spec.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec.tml" ); - } - catch( Exception e ) { - TraceManager.addError( "File could not be saved: " + e.getMessage() ); - return false; - } - } - - - } - return true; //temporary, just to check functionality - } - - public boolean generateUPPAALFromTIF(String path, boolean debug, int nb, boolean choices, boolean variables) { - TURTLE2UPPAAL turtle2uppaal = new TURTLE2UPPAAL(tm); - turtle2uppaal.setChoiceDeterministic(choices); - turtle2uppaal.setVariablesAsActions(variables); - uppaal = turtle2uppaal.generateUPPAAL(debug, nb); - TraceManager.addDev("Building relation table"); - uppaalTIFTable = turtle2uppaal.getRelationTIFUPPAAL(); - TraceManager.addDev("Building relation table done"); - uppaalTMLTable = null; - - languageID = UPPAAL; - mgui.setMode(MainGUI.UPPAAL_OK); - - try { - TraceManager.addDev("Saving specification in " + path + "\n"); - turtle2uppaal.saveInFile(path); - TraceManager.addDev("UPPAAL specification has been generated in " + path + "\n"); - return true; - } catch (FileException fe) { - TraceManager.addError("Exception: " + fe.getMessage()); - return false; - } - } - - public boolean generateUPPAALFromTML(String _path, boolean _debug, int _size, boolean choices) { - TraceManager.addDev("Generate UPPAAL from TML"); - TML2UPPAAL tml2uppaal = new TML2UPPAAL(tmlm); - //tml2uppaal.setChoiceDeterministic(choices); - tml2uppaal.setSizeInfiniteFIFO(_size); - uppaal = tml2uppaal.generateUPPAAL(_debug); - uppaalTMLTable = tml2uppaal.getRelationTMLUPPAAL(); - uppaalTIFTable = null; - languageID = UPPAAL; - mgui.setMode(MainGUI.UPPAAL_OK); - //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); - try { - tml2uppaal.saveInFile(_path); - return true; - } catch (FileException fe) { - TraceManager.addError("Exception: " + fe.getMessage()); - return false; - } - } - - public boolean generateUPPAALFromAVATAR(String _path) { - if (avatarspec == null) { - TraceManager.addDev("Null avatar spec"); - return false; - } - avatar2uppaal = new AVATAR2UPPAAL(avatarspec); - //tml2uppaal.setChoiceDeterministic(choices); - //tml2uppaal.setSizeInfiniteFIFO(_size); - uppaal = avatar2uppaal.generateUPPAAL(true, optimizeAvatar); - warnings = avatar2uppaal.getWarnings(); - uppaalTMLTable = null; - uppaalTIFTable = null; - languageID = UPPAAL; - mgui.setMode(MainGUI.UPPAAL_OK); - //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); - try { - avatar2uppaal.saveInFile(_path); - return true; - } catch (FileException fe) { - TraceManager.addError("Exception: " + fe.getMessage()); - return false; - } - } - - public AvatarSpecification getAvatarSpecification() { - return avatarspec; - } - - public AVATAR2UPPAAL getAvatar2Uppaal(){ - return avatar2uppaal; - } - public ProVerifOutputAnalyzer getProVerifOutputAnalyzer () { - return this.avatar2proverif.getOutputAnalyzer (); - } - - public boolean generateProVerifFromAVATAR(String _path, int _stateReachability, boolean _typed){ - return generateProVerifFromAVATAR(_path, _stateReachability, _typed, "1"); - } + //private Charset chset1, chset2; + + public GTURTLEModeling(MainGUI _mgui, Vector _panels) { + mgui = _mgui; + panels = _panels; + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + dbf = null; + db = null; + } + savedOperations = new Vector(); + savedPanels = new Vector(); + pointerOperation = -1; + + graphs = new ArrayList<RG>(); + invariants = new LinkedList<Invariant>(); + + //vdt = new ValidationDataTree(mgui); + mcvdt = new SyntaxAnalysisTree(mgui); + idt = new InvariantDataTree(mgui); + st = new SearchTree(mgui); + gt = new GraphTree(mgui); + + /*if (!Charset.isSupported("UTF-8")) { + ErrorGUI.exit(ErrorGUI.ERROR_CHARSET); + } + + chset1 = Charset.forName("UTF-8");*/ + } + + public int getLanguageID() { + return languageID; + } + + public boolean isRegularTM() { + if (tm == null ){ + return false; + } + return tm.isARegularTIFSpec(); + } + + public ArrayList<RG> getRGs() { + return graphs; + } + + public void addRG(RG newGraph) { + //TraceManager.addDev("Adding new graph " + newGraph); + graphs.add(newGraph); + } + + public void removeRG(RG oldGraph) { + //TraceManager.addDev("Adding new graph " + newGraph); + graphs.remove(oldGraph); + } + + + public LinkedList<Invariant> getInvariants() { + return invariants; + } + + + + public void addInvariant(Invariant _inv) { + invariants.add(_inv); + TraceManager.addDev("Adding invariant: " + _inv.toString()); + } + + public void clearInvariants() { + invariants.clear(); + } + + + + public String saveTIF() { + if (tm == null) { + TraceManager.addDev("NO TIF to save"); + return null; + } + + TIFExchange tif = new TIFExchange(); + tif.setTURTLEModeling(tm); + String ret = tif.saveInXMLTIF(); + TraceManager.addDev("TIF=\n" + ret); + return ret; + } + + public boolean openTIF(String s) { + TIFExchange tif = new TIFExchange(); + boolean ret = false; + + try { + ret = tif.loadFromXMLTIF(s); + if (ret) { + tm = tif.getTURTLEModeling(); + tmState = 0; + TraceManager.addDev("Got TIF"); + generateDesign(); + } + } catch (Exception e) { + TraceManager.addDev("Exception on TIF: " + e.getMessage()); + } + return ret; + } + + public boolean openSD(String s) { + SDExchange sde = new SDExchange(); + boolean ret = false; + + try { + ret = sde.loadFromXMLSD(s); + if (ret) { + //tm = tif.getTURTLEModeling(); + //tmState = 0; + TraceManager.addDev("Got SD"); + generateIOD(sde.getHMSC(), sde.getMSC()); + } + } catch (Exception e) { + TraceManager.addDev("Exception on SD: " + e.getMessage()); + } + return ret; + } + + /*public void mergeChoices(boolean nonDeterministic) { + if (tm != null) { + tm.mergeChoices(nonDeterministic); + } + }*/ + + public NCStructure getNCS() { + return ncs; + } + + public void generateRTLOTOS(File f) { + TURTLETranslator tt = new TURTLETranslator(tm); + rtlotos = tt.generateRTLOTOS(); + warnings = tt.getWarnings(); + nbRTLOTOS ++; + if (f != null) { + saveInFile(f, rtlotos); + } + languageID = RT_LOTOS; + mgui.setMode(MainGUI.RTLOTOS_OK); + } + + public void generateFullLOTOS(File f) { + reinitSIM(); + reinitDTA(); + reinitRG(); + reinitRGAUT(); + reinitRGAUTPROJDOT(); + //TraceManager.addDev("generate LOTOS"); + generateLOTOS(f); + } + + public void generateLOTOS(File f) { + //tm.print(); + TraceManager.addDev("Generating Lotos"); + TURTLETranslator tt = new TURTLETranslator(tm); + rtlotos = tt.generateLOTOS(true); + warnings = tt.getWarnings(); + TraceManager.addDev("Lotos generated"); + + + + nbRTLOTOS ++; + if (f != null) { + saveInFile(f, rtlotos); + } + TraceManager.addDev("LOTOS to file done"); + languageID = LOTOS; + mgui.setMode(MainGUI.RTLOTOS_OK); + } + + public void generateTPN(File f) { + //tm.print(); + TURTLE2TPN t2tpn = new TURTLE2TPN(tm); + tpn = t2tpn.generateTPN(false).toString(); + warnings = t2tpn.getWarnings(); + + // nbTPN ++; + if (f != null) { + TraceManager.addDev("Saving in file: " + f); + saveInFile(f, tpn); + } + languageID = TPN; + + // For debug purpose + //TraceManager.addDev(tpn); + + mgui.setMode(MainGUI.RTLOTOS_OK); + } + + public LinkedList generateAUT(String path) { + TML2AUT tml2aut = new TML2AUT(tmlm); + tml2aut.generateAutomatas(true); + try { + return tml2aut.saveInFiles(path); + } catch (FileException fe) { + return null; + } + } + + public boolean generateCCode( String _title ) { + + CheckingError ce; + int type; + TGComponent tgc; + String applicationName; + TMLModelCompiler CCode; + + if( tmap == null ) { + JOptionPane.showMessageDialog( mgui.frame, "C code is only generated from an architecture diagram with mapping information", "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); + return true; + } + // Get the file from DiplodocusPECPragma + LinkedList components = mgui.getCurrentArchiPanel().tmlap.getComponentList(); + // Parse the PEC file and the library of code snippets for each DIPLODOCUS unit + applicationName = tmap.getMappedTasks().get(0).getName().split("__")[0]; // Remember that it works only for one application + CCode = new TMLModelCompiler( _title, applicationName, mgui.frame, mgui.getAllTMLCP(), tmap ); + CCode.toTextFormat(); + try { + if( ConfigurationTTool.CCodeDirectory.equals("") ) { + JOptionPane.showMessageDialog( mgui.frame, + "No directory for C code generation found in config.xml. The C code cannot be generated.", + "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); + return true; + } + else { + CCode.saveFile( ConfigurationTTool.CCodeDirectory + File.separator, applicationName ); + } + } + catch( Exception e ) { + JOptionPane.showMessageDialog( mgui.frame, "The application C files could not be saved: " + e.getMessage(), "Control code generation failed", JOptionPane.INFORMATION_MESSAGE ); + return true; + } + return false; + } + + public boolean generateTMLTxt( String _title ) { + + + //This branch is activated if doing the syntax check from the architecture panel. + //It generates the text TML for the architecture and the application + mapping information + if (tmap != null) { + TMLMappingTextSpecification spec = new TMLMappingTextSpecification( _title ); + spec.toTextFormat( tmap ); //TMLMapping + try { + //TraceManager.addDev( "*** " + ConfigurationTTool.TMLCodeDirectory + File.separator ); + spec.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec" ); + } + catch( Exception e ) { + TraceManager.addError( "Files could not be saved: " + e.getMessage() ); + return false; + } + } + + if( tmlcp != null ) { //Use the data structure filled by translateToTML... and pass it to the appropriate toTextFormat() + TraceManager.addError( "About to generate the TMLText for CPs" ); + TMLCPTextSpecification specCP = new TMLCPTextSpecification( _title ); + + //get the architecture panel and the nodes + TMLArchiDiagramPanel tmlap = mgui.getTMLArchiDiagramPanels().get(0).tmlap; + LinkedList components = tmlap.getComponentList(); + ListIterator iterator = components.listIterator(); + TGComponent tgc; + + while(iterator.hasNext()) { + tgc = (TGComponent)(iterator.next()); + if (tgc instanceof TMLArchiCPNode) { + TMLArchiCPNode node = (TMLArchiCPNode) tgc; + TraceManager.addDev( "Found CP node: " + node.getName() ); + TraceManager.addDev( "with mapping info: " + node.getMappedUnits() ); + } + } + + ArrayList<TMLCommunicationPatternPanel> tmlcpPanelsList = new ArrayList<TMLCommunicationPatternPanel>(); + //get the TMLCommunicationPatternPanels :) + for( int i = 0; i < mgui.tabs.size(); i++ ) { + TURTLEPanel panel = (TURTLEPanel)( mgui.tabs.get(i) ); + if( panel instanceof TMLCommunicationPatternPanel ) { + tmlcpPanelsList.add( (TMLCommunicationPatternPanel) panel ); + TraceManager.addDev( "Found TMLCommunicationPatternPanel: " + ((TMLCommunicationPatternPanel)panel).toString() ); + } + } + + specCP.toTextFormat( tmlcp ); // the data structure tmlcp is filled with the info concerning the CP panel + // from which the button is pressed. If there are multiple CP panels this operation must be repeated for each panel. It + // should be no difficult to implement. + try { + specCP.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec.tmlcp" ); + } + catch( Exception e ) { + TraceManager.addError( "Writing TMLText for CPs, file could not be saved: " + e.getMessage() ); + return false; + } + + } else if (tmap == null) { + //This branch is activated if doing the syntax check from the application panel. + //It only generates the application TML text + if( tmap == null ) { + TMLTextSpecification spec = new TMLTextSpecification( _title ); + spec.toTextFormat( tmlm ); //TMLModeling + try { + spec.saveFile( ConfigurationTTool.TMLCodeDirectory + File.separator, "spec.tml" ); + } + catch( Exception e ) { + TraceManager.addError( "File could not be saved: " + e.getMessage() ); + return false; + } + } + + + } + return true; //temporary, just to check functionality + } + + public boolean generateUPPAALFromTIF(String path, boolean debug, int nb, boolean choices, boolean variables) { + TURTLE2UPPAAL turtle2uppaal = new TURTLE2UPPAAL(tm); + turtle2uppaal.setChoiceDeterministic(choices); + turtle2uppaal.setVariablesAsActions(variables); + uppaal = turtle2uppaal.generateUPPAAL(debug, nb); + TraceManager.addDev("Building relation table"); + uppaalTIFTable = turtle2uppaal.getRelationTIFUPPAAL(); + TraceManager.addDev("Building relation table done"); + uppaalTMLTable = null; + + languageID = UPPAAL; + mgui.setMode(MainGUI.UPPAAL_OK); + + try { + TraceManager.addDev("Saving specification in " + path + "\n"); + turtle2uppaal.saveInFile(path); + TraceManager.addDev("UPPAAL specification has been generated in " + path + "\n"); + return true; + } catch (FileException fe) { + TraceManager.addError("Exception: " + fe.getMessage()); + return false; + } + } + + public boolean generateUPPAALFromTML(String _path, boolean _debug, int _size, boolean choices) { + TraceManager.addDev("Generate UPPAAL from TML"); + TML2UPPAAL tml2uppaal = new TML2UPPAAL(tmlm); + //tml2uppaal.setChoiceDeterministic(choices); + tml2uppaal.setSizeInfiniteFIFO(_size); + uppaal = tml2uppaal.generateUPPAAL(_debug); + uppaalTMLTable = tml2uppaal.getRelationTMLUPPAAL(); + uppaalTIFTable = null; + languageID = UPPAAL; + mgui.setMode(MainGUI.UPPAAL_OK); + //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); + try { + tml2uppaal.saveInFile(_path); + return true; + } catch (FileException fe) { + TraceManager.addError("Exception: " + fe.getMessage()); + return false; + } + } + + public boolean generateUPPAALFromAVATAR(String _path) { + if (avatarspec == null) { + TraceManager.addDev("Null avatar spec"); + return false; + } + avatar2uppaal = new AVATAR2UPPAAL(avatarspec); + //tml2uppaal.setChoiceDeterministic(choices); + //tml2uppaal.setSizeInfiniteFIFO(_size); + uppaal = avatar2uppaal.generateUPPAAL(true, optimizeAvatar); + warnings = avatar2uppaal.getWarnings(); + uppaalTMLTable = null; + uppaalTIFTable = null; + languageID = UPPAAL; + mgui.setMode(MainGUI.UPPAAL_OK); + //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); + try { + avatar2uppaal.saveInFile(_path); + return true; + } catch (FileException fe) { + TraceManager.addError("Exception: " + fe.getMessage()); + return false; + } + } + + public AvatarSpecification getAvatarSpecification() { + return avatarspec; + } + + public AVATAR2UPPAAL getAvatar2Uppaal(){ + return avatar2uppaal; + } + public ProVerifOutputAnalyzer getProVerifOutputAnalyzer () { + return this.avatar2proverif.getOutputAnalyzer (); + } + + public boolean generateProVerifFromAVATAR(String _path, int _stateReachability, boolean _typed){ + return generateProVerifFromAVATAR(_path, _stateReachability, _typed, "1"); + } + + public int calcSec(){ + int overhead=0; + //count # of insecure channels? + return overhead; + } + public boolean channelAllowed(TMLMapping map, TMLChannel chan){ + TMLTask orig = chan.getOriginTask(); + TMLTask dest = chan.getDestinationTask(); + List<HwNode> path = getPath(map,orig, dest); + for (HwNode node:path){ + if (node instanceof HwBridge){ + for (String rule:((HwBridge) node).firewallRules){ + String t1 = rule.split("->")[0]; + String t2 = rule.split("->")[1]; + if (t1.equals(orig.getName().replaceAll("__","::")) || t1.equals("*")){ + if (t2.equals(dest.getName().replaceAll("__","::")) || t2.equals("*")){ + return false; + } + } + } + } + } + return true; + } + public List<HwNode> getPath(TMLMapping map, TMLTask t1, TMLTask t2){ + HwNode node1 = map.getHwNodeOf(t1); + HwNode node2 = map.getHwNodeOf(t2); + List<HwNode> path = new ArrayList<HwNode>(); + if (node1==node2){ + return path; + } + if (node1!=node2){ + //Navigate architecture for node + List<HwLink> links = map.getTMLArchitecture().getHwLinks(); + HwNode last = node1; + List<HwNode> found = new ArrayList<HwNode>(); + List<HwNode> done = new ArrayList<HwNode>(); + Map<HwNode, List<HwNode>> pathMap = new HashMap<HwNode, List<HwNode>>(); + for (HwLink link: links){ + if (link.hwnode == node1){ + found.add(link.bus); + List<HwNode> tmp = new ArrayList<HwNode>(); + tmp.add(link.bus); + pathMap.put(link.bus, tmp); + } + } + outerloop: + while (found.size()>0){ + HwNode curr = found.remove(0); + for (HwLink link: links){ + if (curr == link.bus){ + if (link.hwnode == node2){ + path = pathMap.get(curr); + break outerloop; + } + if (!done.contains(link.hwnode) && !found.contains(link.hwnode) && link.hwnode instanceof HwBridge){ + found.add(link.hwnode); + List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); + tmp.add(link.hwnode); + pathMap.put(link.hwnode, tmp); + } + } + else if (curr == link.hwnode){ + if (!done.contains(link.bus) && !found.contains(link.bus)){ + found.add(link.bus); + List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); + tmp.add(link.bus); + pathMap.put(link.bus, tmp); + } + } + } + done.add(curr); + } + } + return path; + } + public TMLMapping drawFirewall(TMLMapping map){ + System.out.println("DRAWING FIREWALL"); + TMLComponentDesignPanel tmlcdp = map.getTMLCDesignPanel(); + TMLModeling tmlm = map.getTMLModeling(); + TMLActivityDiagramPanel firewallADP = null; + TMLComponentTaskDiagramPanel tcdp = tmlcdp.tmlctdp; + if (TraceManager.devPolicy == TraceManager.TO_CONSOLE){ + MainGUI gui = tmlcdp.getMainGUI(); + int arch = mgui.tabs.indexOf(map.tmlap); + gui.cloneRenameTab(arch,"firewallArch"); + TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); + int ind = gui.tabs.indexOf(tmlcdp); + String tabName = gui.getTitleAt(tmlcdp); + gui.cloneRenameTab(ind, "firewallDesign"); + TMLComponentDesignPanel tcp = (TMLComponentDesignPanel) gui.tabs.get(gui.tabs.size()-1); + newarch.renameMapping(tabName, tabName+"_firewallDesign"); + + } + for (HwBridge firewallNode:map.getTMLArchitecture().getFirewalls()){ + TraceManager.addDev("Found firewall " + firewallNode.getName()); + TMLCPrimitiveComponent firewallComp = null; + TMLADStartState adStart=null; + TMLADForEverLoop adLoop = null; + TMLADChoice adChoice =null; + TMLADReadChannel adRC=null; + TMLADExecI exec=null; + TMLADWriteChannel adWC=null; + TMLADStopState adStop =null; + + + + int links = map.getArch().getLinkByHwNode(firewallNode).size(); + TraceManager.addDev("Links " + links); + + HwCPU cpu = new HwCPU(firewallNode.getName()); + map.getTMLArchitecture().replaceFirewall(firewallNode,cpu); + for (int link =0; link< links/2; link++){ + HashMap<TMLChannel, TMLChannel> inChans = new HashMap<TMLChannel, TMLChannel>(); + HashMap<TMLChannel, TMLChannel> outChans = new HashMap<TMLChannel, TMLChannel>(); + if (TraceManager.devPolicy == TraceManager.TO_CONSOLE){ + firewallComp = new TMLCPrimitiveComponent(0, 0, tmlcdp.tmlctdp.getMinX(), tmlcdp.tmlctdp.getMaxX(), tmlcdp.tmlctdp.getMinY(), tmlcdp.tmlctdp.getMaxY(), false, null, tmlcdp.tmlctdp); + tmlcdp.tmlctdp.addComponent(firewallComp,0,0,false,true); + firewallComp.setValueWithChange(firewallNode.getName()+link); + firewallADP = tmlcdp.getTMLActivityDiagramPanel(firewallNode.getName()+link); + } + ArrayList<TMLChannel> channelsCopy = tmlm.getChannels(); + ArrayList<TMLChannel> toAdd = new ArrayList<TMLChannel>(); + + TMLTask firewall = new TMLTask("TASK__"+firewallNode.getName()+"_"+link, firewallComp,firewallADP); + + + tmlm.addTask(firewall); + map.addTaskToHwExecutionNode(firewall,cpu); + TMLActivity act = firewall.getActivityDiagram(); + + TraceManager.addDev("FirewallADP " + firewallADP); + for (TMLChannel chan: channelsCopy){ + TMLTask orig = chan.getOriginTask(); + TMLTask dest = chan.getDestinationTask(); + TMLPort origPort = chan.getOriginPort(); + TMLPort destPort = chan.getDestinationPort(); + TMLChannel wr = new TMLChannel(chan.getName()+"_firewallIn"+link,chan.getReferenceObject()); + //Specify new channel attributes + wr.setSize(chan.getSize()); + wr.setMax(chan.getMax()); + wr.setPorts(origPort,destPort); + wr.setType(TMLChannel.BRBW); + wr.setPriority(chan.getPriority()); + wr.setTasks(orig, firewall); + TMLChannel rd = new TMLChannel(chan.getName()+"_firewallOut"+link, chan.getReferenceObject()); + rd.setTasks(firewall,dest); + rd.setSize(chan.getSize()); + rd.setMax(chan.getMax()); + rd.setPorts(origPort,destPort); + rd.setType(TMLChannel.BRBW); + rd.setPriority(chan.getPriority()); + inChans.put(chan,wr); + outChans.put(chan,rd); + toAdd.add(rd); + toAdd.add(wr); + map.listE.addCor(rd, (TGComponent) rd.getReferenceObject()); + map.listE.addCor(wr, (TGComponent) wr.getReferenceObject()); + } + tmlm.removeAllChannels(); + for (TMLChannel c:toAdd){ + tmlm.addChannel(c); + } + + + if (TraceManager.devPolicy == TraceManager.TO_CONSOLE){ + //Build activity diagram + //Get start state + adStart = (TMLADStartState) firewallADP.getComponentList().get(0); + //add loop + adLoop = new TMLADForEverLoop(400,150,firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + firewallADP.addComponent(adLoop,400,150,false,true); + TGConnector tmp =new TGConnectorTMLAD(adLoop.getX(), adLoop.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adStart.getTGConnectingPointAtIndex(0),adLoop.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, adLoop.getX(),adLoop.getY(),false,true); + //add choice + adChoice = new TMLADChoice(400,300, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + firewallADP.addComponent(adChoice, 400,300,false,true); + + tmp =new TGConnectorTMLAD(adChoice.getX(), adChoice.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adLoop.getTGConnectingPointAtIndex(1), adChoice.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, adChoice.getX(),adChoice.getY(),false,true); + for (TMLChannel chan: inChans.keySet()){ + TMLChannel newChan = inChans.get(chan); + TMLCChannelOutPort originPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); + TMLCChannelOutPort destPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); + for (TGComponent tg: tcdp.getComponentList()){ + if (tg instanceof TMLCPrimitiveComponent){ + if (tg.getValue().equals(newChan.getOriginTask().getName().split("__")[1])){ + originPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); + originPort.commName=newChan.getName(); + tcdp.addComponent(originPort,tg.getX(), tg.getY(),true,true); + } + else if (tg.getValue().equals(firewallNode.getName())){ + destPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); + destPort.isOrigin=false; + destPort.commName=newChan.getName(); + tcdp.addComponent(destPort,tg.getX(), tg.getY(),true,true); + } + } + } + TMLCPortConnector conn = new TMLCPortConnector(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp, originPort.getTGConnectingPointAtIndex(0), destPort.getTGConnectingPointAtIndex(0), new Vector()); + tcdp.addComponent(conn, 0,0,false,true); + + TMLChannel wrChan = outChans.get(chan); + for (TGComponent tg: tcdp.getComponentList()){ + if (tg instanceof TMLCPrimitiveComponent){ + if (tg.getValue().equals(firewallNode.getName())){ + originPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); + originPort.commName=wrChan.getName(); + tcdp.addComponent(originPort,tg.getX(), tg.getY(),true,true); + } + else if (tg.getValue().equals(wrChan.getDestinationTask().getName().split("__")[1])){ + destPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); + destPort.isOrigin=false; + destPort.commName=wrChan.getName(); + tcdp.addComponent(destPort,tg.getX(), tg.getY(),true,true); + } + } + } + conn = new TMLCPortConnector(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp, originPort.getTGConnectingPointAtIndex(0), destPort.getTGConnectingPointAtIndex(0), new Vector()); + tcdp.addComponent(conn, 0,0,false,true); + } + int xpos=200; + int i=1; + for (TMLChannel chan: inChans.keySet()){ + TMLChannel newChan = inChans.get(chan); + adRC = new TMLADReadChannel(xpos,350, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + adRC.setChannelName(newChan.getName()); + adRC.setSamples("1"); + + tmp =new TGConnectorTMLAD(adRC.getX(), adRC.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adChoice.getTGConnectingPointAtIndex(i), adRC.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, adRC.getX(),adRC.getY(),false,true); + + firewallADP.addComponent(adRC,xpos,350,false,true); + + //Execute for latency value + exec = new TMLADExecI(xpos,400,firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + + exec.setDelayValue(Integer.toString(firewallNode.latency)); + firewallADP.addComponent(exec,400,200,false,true); + + tmp =new TGConnectorTMLAD(exec.getX(), exec.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adRC.getTGConnectingPointAtIndex(1), exec.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, exec.getX(),exec.getY(),false,true); + + if (channelAllowed(map,chan)){ + TMLChannel wrChan = outChans.get(chan); + + adWC = new TMLADWriteChannel(xpos,400, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + adWC.setChannelName(wrChan.getName()); + adWC.setSamples("1"); + firewallADP.addComponent(adWC, xpos,400, false,true); + + tmp =new TGConnectorTMLAD(exec.getX(), exec.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,exec.getTGConnectingPointAtIndex(1), adWC.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, exec.getX(),exec.getY(),false,true); + + adStop = new TMLADStopState(xpos,500, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + firewallADP.addComponent(adStop, xpos,500, false,true); + tmp =new TGConnectorTMLAD(adStop.getX(), adStop.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adWC.getTGConnectingPointAtIndex(1), adStop.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, adStop.getX(),adStop.getY(),false,true); + } + else { + adStop = new TMLADStopState(xpos,500, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); + firewallADP.addComponent(adStop, xpos,500, false,true); + + tmp =new TGConnectorTMLAD(adStop.getX(), adStop.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,exec.getTGConnectingPointAtIndex(1), adStop.getTGConnectingPointAtIndex(0), new Vector()); + firewallADP.addComponent(tmp, adStop.getX(),adStop.getY(),false,true); + } + xpos+=100; + i++; + } + } + + TMLStartState start = new TMLStartState("start", adStart); + act.setFirst(start); + map.listE.addCor(start,adStart); + + //Add infinite loop + + TMLForLoop loop = new TMLForLoop("infiniteloop",adLoop); + loop.setInit(""); + loop.setCondition(""); + loop.setIncrement(""); + loop.setInfinite(true); + start.addNext(loop); + act.addElement(loop); + //Add choice + + TMLChoice choice = new TMLChoice("chooseChannel", adChoice); + act.addElement(choice); + loop.addNext(choice); + map.listE.addCor(choice,adChoice); + + + + + for (TMLChannel chan: inChans.keySet()){ + TMLChannel newChan = inChans.get(chan); + TMLChannel wrChan = outChans.get(chan); + //Add channels into firewall activity diagram + TMLReadChannel rd = new TMLReadChannel(newChan.getName(), adRC); + rd.setNbOfSamples("1"); + rd.addChannel(newChan); + choice.addNext(rd); + choice.addGuard(""); + + act.addElement(rd); + + //Execute for latency value + + TMLExecI ex = new TMLExecI("execi", exec); + ex.setAction(Integer.toString(firewallNode.latency)); + act.addElement(ex); + rd.addNext(ex); + + if (channelAllowed(map,chan)){ + + TMLWriteChannel wr = new TMLWriteChannel(wrChan.getName(), adWC); + wr.setNbOfSamples("1"); + wr.addChannel(wrChan); + ex.addNext(wr); + act.addElement(wr); + + TMLStopState stop = new TMLStopState("stop", adStop); + wr.addNext(stop); + act.addElement(stop); + + } + else { + TMLStopState stop = new TMLStopState("stop", adStop); + ex.addNext(stop); + act.addElement(stop); + } + for (TMLTask t:tmlm.getTasks()){ + TMLActivity actd = t.getActivityDiagram(); + actd.replaceWriteChannelWith(chan,newChan); + actd.replaceReadChannelWith(chan, outChans.get(chan)); + } + } + + } + + } + //Redo all reference objects + + map.listE.useDIPLOIDs(); + return map; + } + + public TMLMapping autoSecure(MainGUI gui, boolean autoConf, boolean autoAuth){ + //TODO add more options + // + if (tmap==null){ + return null; + } + int arch = gui.tabs.indexOf(tmap.tmlap); + gui.cloneRenameTab(arch,"enc"); + TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); + return autoSecure(gui, "enc", tmap,newarch,autoConf,autoAuth); + } + public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch){ + return autoSecure(gui,name,map,newarch,"100","0","100",true,false); + } + public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, boolean autoConf, boolean autoAuth){ + return autoSecure(gui,name,map,newarch,"100","0","100",autoConf,autoAuth); + } + + public TMLMapping autoSecure(MainGUI gui, String encComp, String overhead, String decComp){ + if (tmap==null){ + return null; + } + int arch = gui.tabs.indexOf(tmap.tmlap); + gui.cloneRenameTab(arch,"enc"); + TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); + return autoSecure(gui,"enc", tmap,newarch,encComp, overhead,decComp,true,false); + } + + public TMLMapping autoSecure(MainGUI gui, String encComp, String overhead, String decComp, boolean autoConf, boolean autoAuth){ + if (tmap==null){ + return null; + } + int arch = gui.tabs.indexOf(tmap.tmlap); + gui.cloneRenameTab(arch,"enc"); + TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); + return autoSecure(gui,"enc", tmap,newarch,encComp, overhead,decComp,autoConf,autoAuth); + } + public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, String encComp, String overhead, String decComp){ + return autoSecure(gui,name, tmap,newarch,encComp, overhead,decComp,true,false); + } + + + public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, String encComp, String overhead, String decComp, boolean autoConf, boolean autoAuth){ + HashMap<TMLTask, java.util.List<TMLTask>> toSecure = new HashMap<TMLTask, java.util.List<TMLTask>>(); + HashMap<TMLTask, java.util.List<TMLTask>> toSecureRev = new HashMap<TMLTask, java.util.List<TMLTask>>(); + HashMap<TMLTask, java.util.List<String>> insecureOutChannels = new HashMap<TMLTask, java.util.List<String>>(); + HashMap<TMLTask, java.util.List<String>> insecureInChannels = new HashMap<TMLTask, java.util.List<String>>(); + if (map==null){ + return null; + } + TMLModeling tmlmodel = map.getTMLModeling(); + java.util.List<TMLChannel> channels = tmlmodel.getChannels(); + for (TMLChannel channel: channels){ + for (TMLCPrimitivePort p: channel.ports){ + channel.checkConf = channel.checkConf || p.checkConf; + channel.checkAuth = channel.checkAuth || p.checkAuth; + } + } + + //Create clone of Component Diagram + Activity diagrams to secure + + TMLComponentDesignPanel tmlcdp = map.getTMLCDesignPanel(); + int ind = gui.tabs.indexOf(tmlcdp); + String tabName = gui.getTitleAt(tmlcdp); + gui.cloneRenameTab(ind, name); + TMLComponentDesignPanel t = (TMLComponentDesignPanel) gui.tabs.get(gui.tabs.size()-1); + map.setTMLDesignPanel(t); + TMLComponentTaskDiagramPanel tcdp = t.tmlctdp; + //Create clone of architecture panel and map tasks to it + newarch.renameMapping(tabName, tabName+"_"+name); + + for (TMLTask task: map.getTMLModeling().getTasks()){ + java.util.List<String> tmp = new ArrayList<String>(); + java.util.List<String> tmp2 = new ArrayList<String>(); + java.util.List<TMLTask> tmp3 = new ArrayList<TMLTask>(); + java.util.List<TMLTask> tmp4 = new ArrayList<TMLTask>(); + insecureInChannels.put(task, tmp); + insecureOutChannels.put(task, tmp2); + toSecure.put(task,tmp3); + toSecureRev.put(task,tmp4); + } + for (TMLTask task: map.getTMLModeling().getTasks()){ + //Check if all channel operators are secured + TMLActivityDiagramPanel tad = t.getTMLActivityDiagramPanel(task.getName()); + for (TGComponent tg:tad.getComponentList()){ + if (tg instanceof TMLADWriteChannel){ + TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; + if (writeChannel.securityContext.equals("")){ + + TMLChannel chan = tmlmodel.getChannelByName(tabName+"__"+writeChannel.getChannelName()); + //System.out.println("channel " + chan); + if (chan!=null){ + if (chan.checkConf){ + if (!securePath(map, chan.getOriginTask(), chan.getDestinationTask())){ + insecureOutChannels.get(chan.getOriginTask()).add(writeChannel.getChannelName()); + insecureInChannels.get(chan.getDestinationTask()).add(writeChannel.getChannelName()); + toSecure.get(chan.getOriginTask()).add(chan.getDestinationTask()); + toSecureRev.get(chan.getDestinationTask()).add(chan.getOriginTask()); + } + } + } + } + } + } + } + int num=0; + int nonceNum=0; + //Create reverse channels to send nonces if they don't already exist + if (autoAuth){ + + for (TMLTask task: toSecureRev.keySet()){ + TraceManager.addDev("Adding nonce to " + task.getName()); + LinkedList<TMLChannel> chans = tmlmodel.getChannelsFromMe(task); + for (TMLTask task2: toSecureRev.get(task)){ + boolean addChan = true; + for (TMLChannel chan:chans){ + if (chan.getDestinationTask()==task2){ + addChan=false; + } + } + if (addChan){ + TMLCChannelOutPort originPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); + TMLCChannelOutPort destPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); + for (TGComponent tg: tcdp.getComponentList()){ + if (tg instanceof TMLCPrimitiveComponent){ + if (tg.getValue().equals(task.getName().split("__")[1])){ + originPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); + originPort.commName="nonceCh"+task.getName().split("__")[1] + "_"+task2.getName().split("__")[1]; + tcdp.addComponent(originPort,tg.getX(), tg.getY(),true,true); + } + else if (tg.getValue().equals(task2.getName().split("__")[1])){ + destPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); + destPort.isOrigin=false; + destPort.commName="nonceCh"+task.getName().split("__")[1] + "_"+ task2.getName().split("__")[1]; + tcdp.addComponent(destPort,tg.getX(), tg.getY(),true,true); + } + } + } + tmlmodel.addChannel(new TMLChannel("nonceCh"+task.getName().split("__")[1] + "_"+ task2.getName().split("__")[1], originPort)); + //Add connection + TMLCPortConnector conn = new TMLCPortConnector(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp, originPort.getTGConnectingPointAtIndex(0), destPort.getTGConnectingPointAtIndex(0), new Vector()); + tcdp.addComponent(conn, 0,0,false,true); + } + } + } + } + //Search through activity diagram + for (TMLTask task:toSecure.keySet()){ + String title = task.getName().split("__")[0]; + TraceManager.addDev("Securing task " + task.getName()); + TMLActivityDiagramPanel tad = t.getTMLActivityDiagramPanel(task.getName()); + //Get start state position, shift everything down + int xpos=0; + int ypos=0; + TGConnector fromStart= new TGConnectorTMLAD(0, 0, 0, 0, 0, 0, false, null, tad, null, null, new Vector()); + TGConnectingPoint point = new TGConnectingPoint(null, 0, 0, false, false); + //Find states immediately before the write channel operator - public int calcSec(){ - int overhead=0; - //count # of insecure channels? - return overhead; - } - public boolean channelAllowed(TMLMapping map, TMLChannel chan){ - TMLTask orig = chan.getOriginTask(); - TMLTask dest = chan.getDestinationTask(); - List<HwNode> path = getPath(map,orig, dest); - for (HwNode node:path){ - if (node instanceof HwBridge){ - for (String rule:((HwBridge) node).firewallRules){ - String t1 = rule.split("->")[0]; - String t2 = rule.split("->")[1]; - if (t1.equals(orig.getName().replaceAll("__","::")) || t1.equals("*")){ - if (t2.equals(dest.getName().replaceAll("__","::")) || t2.equals("*")){ - return false; - } + //For each occurence of a write channel operator, add encryption/nonces before it + for (String channel: insecureOutChannels.get(task)){ + int yShift=50; + TMLChannel tmlc = tmlmodel.getChannelByName(title +"__"+channel); + //First, find the connector that points to it. We will add the encryption, nonce operators directly before the write channel operator + for (TGComponent tg: tad.getComponentList()){ + if (tg instanceof TMLADWriteChannel){ + TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; + if (writeChannel.getChannelName().equals(channel) && writeChannel.securityContext.equals("")){ + xpos = tg.getX(); + ypos = tg.getY(); + fromStart = tad.findTGConnectorEndingAt(tg.getTGConnectingPointAtIndex(0)); + if (fromStart!=null){ + point = fromStart.getTGConnectingPointP2(); + } + break; + } } - } - } - } - return true; - } - public List<HwNode> getPath(TMLMapping map, TMLTask t1, TMLTask t2){ - HwNode node1 = map.getHwNodeOf(t1); - HwNode node2 = map.getHwNodeOf(t2); - List<HwNode> path = new ArrayList<HwNode>(); - if (node1==node2){ - return path; - } - if (node1!=node2){ - //Navigate architecture for node - List<HwLink> links = map.getTMLArchitecture().getHwLinks(); - HwNode last = node1; - List<HwNode> found = new ArrayList<HwNode>(); - List<HwNode> done = new ArrayList<HwNode>(); - Map<HwNode, List<HwNode>> pathMap = new HashMap<HwNode, List<HwNode>>(); - for (HwLink link: links){ - if (link.hwnode == node1){ - found.add(link.bus); - List<HwNode> tmp = new ArrayList<HwNode>(); - tmp.add(link.bus); - pathMap.put(link.bus, tmp); - } - } - outerloop: - while (found.size()>0){ - HwNode curr = found.remove(0); - for (HwLink link: links){ - if (curr == link.bus){ - if (link.hwnode == node2){ - path = pathMap.get(curr); - break outerloop; - } - if (!done.contains(link.hwnode) && !found.contains(link.hwnode) && link.hwnode instanceof HwBridge){ - found.add(link.hwnode); - List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); - tmp.add(link.hwnode); - pathMap.put(link.hwnode, tmp); - } + } + //Add encryption operator + TMLADEncrypt enc = new TMLADEncrypt(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + TMLADReadChannel rd=new TMLADReadChannel(0, 0, 0, 0, 0, 0, false, null, tad); + if (autoAuth){ + //Receive any nonces if ensuring authenticity + rd = new TMLADReadChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + ArrayList<TMLChannel> matches = tmlmodel.getChannels(tmlc.getDestinationTask(), tmlc.getOriginTask()); + + if (matches.size()>0){ + rd.setChannelName(matches.get(0).getName().replaceAll(title+"__","")); } - else if (curr == link.hwnode){ - if (!done.contains(link.bus) && !found.contains(link.bus)){ - found.add(link.bus); - List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); - tmp.add(link.bus); - pathMap.put(link.bus, tmp); - } + else { + rd.setChannelName("nonceCh"+tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]); } - } - done.add(curr); - } - } - return path; - } - public TMLMapping drawFirewall(TMLMapping map){ - System.out.println("DRAWING FIREWALL"); - TMLComponentDesignPanel tmlcdp = map.getTMLCDesignPanel(); - TMLModeling tmlm = map.getTMLModeling(); - TMLActivityDiagramPanel firewallADP = null; - TMLComponentTaskDiagramPanel tcdp = tmlcdp.tmlctdp; - if (TraceManager.devPolicy == TraceManager.TO_CONSOLE){ - MainGUI gui = tmlcdp.getMainGUI(); - int arch = mgui.tabs.indexOf(map.tmlap); - gui.cloneRenameTab(arch,"firewallArch"); - TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); - int ind = gui.tabs.indexOf(tmlcdp); - String tabName = gui.getTitleAt(tmlcdp); - gui.cloneRenameTab(ind, "firewallDesign"); - TMLComponentDesignPanel tcp = (TMLComponentDesignPanel) gui.tabs.get(gui.tabs.size()-1); - newarch.renameMapping(tabName, tabName+"_firewallDesign"); - - } - for (HwBridge firewallNode:map.getTMLArchitecture().getFirewalls()){ - TraceManager.addDev("Found firewall " + firewallNode.getName()); - TMLCPrimitiveComponent firewallComp = null; - TMLADStartState adStart=null; - TMLADForEverLoop adLoop = null; - TMLADChoice adChoice =null; - TMLADReadChannel adRC=null; - TMLADExecI exec=null; - TMLADWriteChannel adWC=null; - TMLADStopState adStop =null; - - - - int links = map.getArch().getLinkByHwNode(firewallNode).size(); - TraceManager.addDev("Links " + links); - - HwCPU cpu = new HwCPU(firewallNode.getName()); - map.getTMLArchitecture().replaceFirewall(firewallNode,cpu); - for (int link =0; link< links/2; link++){ - HashMap<TMLChannel, TMLChannel> inChans = new HashMap<TMLChannel, TMLChannel>(); - HashMap<TMLChannel, TMLChannel> outChans = new HashMap<TMLChannel, TMLChannel>(); - if (TraceManager.devPolicy == TraceManager.TO_CONSOLE){ - firewallComp = new TMLCPrimitiveComponent(0, 0, tmlcdp.tmlctdp.getMinX(), tmlcdp.tmlctdp.getMaxX(), tmlcdp.tmlctdp.getMinY(), tmlcdp.tmlctdp.getMaxY(), false, null, tmlcdp.tmlctdp); - tmlcdp.tmlctdp.addComponent(firewallComp,0,0,false,true); - firewallComp.setValueWithChange(firewallNode.getName()+link); - firewallADP = tmlcdp.getTMLActivityDiagramPanel(firewallNode.getName()+link); - } - ArrayList<TMLChannel> channelsCopy = tmlm.getChannels(); - ArrayList<TMLChannel> toAdd = new ArrayList<TMLChannel>(); - - TMLTask firewall = new TMLTask("TASK__"+firewallNode.getName()+"_"+link, firewallComp,firewallADP); - - - tmlm.addTask(firewall); - map.addTaskToHwExecutionNode(firewall,cpu); - TMLActivity act = firewall.getActivityDiagram(); - - TraceManager.addDev("FirewallADP " + firewallADP); - for (TMLChannel chan: channelsCopy){ - TMLTask orig = chan.getOriginTask(); - TMLTask dest = chan.getDestinationTask(); - TMLPort origPort = chan.getOriginPort(); - TMLPort destPort = chan.getDestinationPort(); - TMLChannel wr = new TMLChannel(chan.getName()+"_firewallIn"+link,chan.getReferenceObject()); - //Specify new channel attributes - wr.setSize(chan.getSize()); - wr.setMax(chan.getMax()); - wr.setPorts(origPort,destPort); - wr.setType(TMLChannel.BRBW); - wr.setPriority(chan.getPriority()); - wr.setTasks(orig, firewall); - TMLChannel rd = new TMLChannel(chan.getName()+"_firewallOut"+link, chan.getReferenceObject()); - rd.setTasks(firewall,dest); - rd.setSize(chan.getSize()); - rd.setMax(chan.getMax()); - rd.setPorts(origPort,destPort); - rd.setType(TMLChannel.BRBW); - rd.setPriority(chan.getPriority()); - inChans.put(chan,wr); - outChans.put(chan,rd); - toAdd.add(rd); - toAdd.add(wr); - map.listE.addCor(rd, (TGComponent) rd.getReferenceObject()); - map.listE.addCor(wr, (TGComponent) wr.getReferenceObject()); - } - tmlm.removeAllChannels(); - for (TMLChannel c:toAdd){ - tmlm.addChannel(c); - } - - - if (TraceManager.devPolicy == TraceManager.TO_CONSOLE){ - //Build activity diagram - //Get start state - adStart = (TMLADStartState) firewallADP.getComponentList().get(0); - //add loop - adLoop = new TMLADForEverLoop(400,150,firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - firewallADP.addComponent(adLoop,400,150,false,true); - TGConnector tmp =new TGConnectorTMLAD(adLoop.getX(), adLoop.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adStart.getTGConnectingPointAtIndex(0),adLoop.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, adLoop.getX(),adLoop.getY(),false,true); - //add choice - adChoice = new TMLADChoice(400,300, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - firewallADP.addComponent(adChoice, 400,300,false,true); - - tmp =new TGConnectorTMLAD(adChoice.getX(), adChoice.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adLoop.getTGConnectingPointAtIndex(1), adChoice.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, adChoice.getX(),adChoice.getY(),false,true); - for (TMLChannel chan: inChans.keySet()){ - TMLChannel newChan = inChans.get(chan); - TMLCChannelOutPort originPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); - TMLCChannelOutPort destPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); - for (TGComponent tg: tcdp.getComponentList()){ - if (tg instanceof TMLCPrimitiveComponent){ - if (tg.getValue().equals(newChan.getOriginTask().getName().split("__")[1])){ - originPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); - originPort.commName=newChan.getName(); - tcdp.addComponent(originPort,tg.getX(), tg.getY(),true,true); - } - else if (tg.getValue().equals(firewallNode.getName())){ - destPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); - destPort.isOrigin=false; - destPort.commName=newChan.getName(); - tcdp.addComponent(destPort,tg.getX(), tg.getY(),true,true); - } - } - } - TMLCPortConnector conn = new TMLCPortConnector(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp, originPort.getTGConnectingPointAtIndex(0), destPort.getTGConnectingPointAtIndex(0), new Vector()); - tcdp.addComponent(conn, 0,0,false,true); - - TMLChannel wrChan = outChans.get(chan); - for (TGComponent tg: tcdp.getComponentList()){ - if (tg instanceof TMLCPrimitiveComponent){ - if (tg.getValue().equals(firewallNode.getName())){ - originPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); - originPort.commName=wrChan.getName(); - tcdp.addComponent(originPort,tg.getX(), tg.getY(),true,true); - } - else if (tg.getValue().equals(wrChan.getDestinationTask().getName().split("__")[1])){ - destPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); - destPort.isOrigin=false; - destPort.commName=wrChan.getName(); - tcdp.addComponent(destPort,tg.getX(), tg.getY(),true,true); + rd.securityContext = "nonce_"+ tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; + tad.addComponent(rd, xpos, ypos+yShift, false,true); + fromStart.setP2(rd.getTGConnectingPointAtIndex(0)); + fromStart=new TGConnectorTMLAD(enc.getX(), enc.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, null, null, new Vector()); + tad.addComponent(fromStart, xpos, ypos, false, true); + fromStart.setP1(rd.getTGConnectingPointAtIndex(1)); + yShift+=60; + //Move encryption operator after receive nonce component + enc.setCd(xpos, ypos+yShift); + if (tmlc!=null){ + enc.nonce= "nonce_"+ tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; + } + } + yShift+=60; + enc.securityContext = "autoEncrypt_"+channel; + enc.type = "Symmetric Encryption"; + enc.message_overhead = overhead; + enc.encTime= encComp; + enc.decTime=decComp; + tad.addComponent(enc, xpos ,ypos+yShift, false, true); + + fromStart.setP2(enc.getTGConnectingPointAtIndex(0)); + fromStart=new TGConnectorTMLAD(enc.getX(), enc.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, null, null, new Vector()); + tad.addComponent(fromStart, xpos, ypos, false, true); + fromStart.setP1(enc.getTGConnectingPointAtIndex(1)); + + //Direct the last TGConnector back to the start of the write channel operator + //if (insecureOutChannels.get(task).size()>0 && fromStart!=null || insecureInChannels.get(task).size()>0 && autoAuth){ + fromStart.setP2(point); + //} + for (TGComponent tg:tad.getComponentList()){ + if (tg instanceof TMLADWriteChannel){ + TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; + TraceManager.addDev("Inspecting write channel " + writeChannel.getChannelName()); + if (channel.equals(writeChannel.getChannelName()) && writeChannel.securityContext.equals("")){ + TraceManager.addDev("Securing write channel " + writeChannel.getChannelName()); + writeChannel.securityContext = "autoEncrypt_"+writeChannel.getChannelName(); + tad.repaint(); + } + } + if (tg.getY() >= ypos && tg !=enc && tg!=rd){ + tg.setCd(tg.getX(), tg.getY()+yShift); + } + } + } + for (String channel: insecureInChannels.get(task)){ + int yShift=50; + TMLChannel tmlc = tmlmodel.getChannelByName(title +"__"+channel); + TGConnector conn =new TGConnectorTMLAD(0, 0, 0, 0, 0, 0, false, null, tad, null, null, new Vector()); + TGConnectingPoint next = new TGConnectingPoint(null, 0, 0, false, false); + //Find read channel operator + TMLADReadChannel readChannel = new TMLADReadChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + for (TGComponent tg: tad.getComponentList()){ + if (tg instanceof TMLADReadChannel){ + readChannel = (TMLADReadChannel) tg; + if (readChannel.getChannelName().equals(channel) && readChannel.securityContext.equals("")){ + fromStart = tad.findTGConnectorEndingAt(tg.getTGConnectingPointAtIndex(0)); + if (fromStart!=null){ + point = fromStart.getTGConnectingPointP2(); + } + else { + continue; } - } + conn = tad.findTGConnectorStartingAt(tg.getTGConnectingPointAtIndex(1)); + xpos = fromStart.getX(); + ypos = fromStart.getY(); + if (conn==null){ + System.out.println("no connection"); + //Create a connector to decrypt operator + } + next = conn.getTGConnectingPointP2(); + break; + } } - conn = new TMLCPortConnector(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp, originPort.getTGConnectingPointAtIndex(0), destPort.getTGConnectingPointAtIndex(0), new Vector()); - tcdp.addComponent(conn, 0,0,false,true); + } + //Check if there is an operator to secure + if (fromStart==null){ + continue; } - int xpos=200; - int i=1; - for (TMLChannel chan: inChans.keySet()){ - TMLChannel newChan = inChans.get(chan); - adRC = new TMLADReadChannel(xpos,350, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - adRC.setChannelName(newChan.getName()); - adRC.setSamples("1"); - - tmp =new TGConnectorTMLAD(adRC.getX(), adRC.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adChoice.getTGConnectingPointAtIndex(i), adRC.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, adRC.getX(),adRC.getY(),false,true); - - firewallADP.addComponent(adRC,xpos,350,false,true); - - //Execute for latency value - exec = new TMLADExecI(xpos,400,firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - - exec.setDelayValue(Integer.toString(firewallNode.latency)); - firewallADP.addComponent(exec,400,200,false,true); - - tmp =new TGConnectorTMLAD(exec.getX(), exec.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adRC.getTGConnectingPointAtIndex(1), exec.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, exec.getX(),exec.getY(),false,true); - - if (channelAllowed(map,chan)){ - TMLChannel wrChan = outChans.get(chan); - - adWC = new TMLADWriteChannel(xpos,400, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - adWC.setChannelName(wrChan.getName()); - adWC.setSamples("1"); - firewallADP.addComponent(adWC, xpos,400, false,true); - - tmp =new TGConnectorTMLAD(exec.getX(), exec.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,exec.getTGConnectingPointAtIndex(1), adWC.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, exec.getX(),exec.getY(),false,true); - - adStop = new TMLADStopState(xpos,500, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - firewallADP.addComponent(adStop, xpos,500, false,true); - tmp =new TGConnectorTMLAD(adStop.getX(), adStop.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,adWC.getTGConnectingPointAtIndex(1), adStop.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, adStop.getX(),adStop.getY(),false,true); + TMLADWriteChannel wr = new TMLADWriteChannel(0, 0, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + if (autoAuth){ + //Create a nonce operator and a write channel operator + TMLADEncrypt nonce = new TMLADEncrypt(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + nonce.securityContext = "nonce_"+ tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; + nonce.type = "Nonce"; + nonce.message_overhead = overhead; + nonce.encTime= encComp; + nonce.decTime=decComp; + tad.addComponent(nonce, xpos ,ypos+yShift, false, true); + fromStart.setP2(nonce.getTGConnectingPointAtIndex(0)); + yShift+=50; + wr = new TMLADWriteChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + //Send nonce along channel, the newly created nonce channel or an existing channel with the matching sender and receiver + //Find matching channels + ArrayList<TMLChannel> matches = tmlmodel.getChannels(tmlc.getDestinationTask(), tmlc.getOriginTask()); + if (matches.size()>0){ + wr.setChannelName(matches.get(0).getName().replaceAll(title+"__","")); } else { - adStop = new TMLADStopState(xpos,500, firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false,null, firewallADP); - firewallADP.addComponent(adStop, xpos,500, false,true); - - tmp =new TGConnectorTMLAD(adStop.getX(), adStop.getY(), firewallADP.getMinX(), firewallADP.getMaxX(), firewallADP.getMinY(), firewallADP.getMaxY(), false, null,firewallADP,exec.getTGConnectingPointAtIndex(1), adStop.getTGConnectingPointAtIndex(0), new Vector()); - firewallADP.addComponent(tmp, adStop.getX(),adStop.getY(),false,true); + wr.setChannelName("nonceCh"+tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]); } - xpos+=100; - i++; + //send the nonce along the channel + wr.securityContext = "nonce_"+tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; + tad.addComponent(wr,xpos,ypos+yShift,false,true); + wr.makeValue(); + TGConnector tmp =new TGConnectorTMLAD(wr.getX(), wr.getY()+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null,tad,nonce.getTGConnectingPointAtIndex(1), wr.getTGConnectingPointAtIndex(0), new Vector()); + tad.addComponent(tmp, xpos,ypos,false,true); + fromStart=new TGConnectorTMLAD(wr.getX(), wr.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, wr.getTGConnectingPointAtIndex(1), null, new Vector()); + tad.addComponent(fromStart, xpos, ypos, false, true); + //Connect created write channel operator to start of read channel operator + fromStart.setP1(wr.getTGConnectingPointAtIndex(1)); + fromStart.setP2(point); + //Shift everything from the read channel on down + for (TGComponent tg:tad.getComponentList()){ + if (tg.getY() >= ypos && tg!=nonce && tg!=wr){ + tg.setCd(tg.getX(), tg.getY()+yShift); + } + } } + tad.repaint(); + + //Now add the decrypt operator + yShift=50; + TraceManager.addDev("Securing read channel " + readChannel.getChannelName()); + readChannel.securityContext = "autoEncrypt_"+readChannel.getChannelName(); + tad.repaint(); + //Add decryption operator if it does not already exist + xpos = conn.getX(); + ypos = conn.getY(); + TMLADDecrypt dec = new TMLADDecrypt(xpos+10, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); + dec.securityContext = "autoEncrypt_" + readChannel.getChannelName(); + tad.addComponent(dec, dec.getX(), dec.getY(), false, true); + conn.setP2(dec.getTGConnectingPointAtIndex(0)); + yShift+=60; + conn = new TGConnectorTMLAD(xpos,ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, dec.getTGConnectingPointAtIndex(1), next, new Vector()); + conn.setP1(dec.getTGConnectingPointAtIndex(1)); + conn.setP2(next); + tad.addComponent(conn, conn.getX(), conn.getY(), false,true); + //Shift everything down + for (TGComponent tg:tad.getComponentList()){ + if (tg instanceof TMLADReadChannel){ + readChannel = (TMLADReadChannel) tg; + TraceManager.addDev("Inspecting read channel " + readChannel.getChannelName()); + if (channel.equals(readChannel.getChannelName()) && readChannel.securityContext.equals("")){ + TraceManager.addDev("Securing read channel " + readChannel.getChannelName()); + readChannel.securityContext = "autoEncrypt_"+readChannel.getChannelName(); + + } + } + if (tg.getY() >= ypos && tg!=dec && tg!=wr){ + + tg.setCd(tg.getX(), tg.getY()+yShift); + } + } } - TMLStartState start = new TMLStartState("start", adStart); - act.setFirst(start); - map.listE.addCor(start,adStart); - //Add infinite loop + tad.repaint(); + } + + GTMLModeling gtm = new GTMLModeling(t, false); + TMLModeling newmodel = gtm.translateToTMLModeling(false,false); + for (TMLTask task:newmodel.getTasks()){ + task.setName(tabName+"_"+name+"__"+task.getName()); + } + for (TMLTask task: tmlmodel.getTasks()){ + HwExecutionNode node =(HwExecutionNode) map.getHwNodeOf(task); + if (newmodel.getTMLTaskByName(task.getName().replace(tabName,tabName+"_"+name))!=null){ + map.addTaskToHwExecutionNode(newmodel.getTMLTaskByName(task.getName().replace(tabName,tabName+"_"+name)), node); + map.removeTask(task); + } + else { + System.out.println("Can't find " + task.getName()); + } + } + //map.setTMLModeling(newmodel); + //System.out.println(map); + //TMLMapping newMap = gtm.translateToTMLMapping(); + map.setTMLModeling(newmodel); + return map; + } + public boolean securePath(TMLMapping map, TMLTask t1, TMLTask t2){ + //Check if a path between two tasks is secure + boolean secure=true; + java.util.List<HwLink> links = map.getTMLArchitecture().getHwLinks(); + HwExecutionNode node1 = (HwExecutionNode) map.getHwNodeOf(t1); + HwExecutionNode node2 = (HwExecutionNode) map.getHwNodeOf(t2); + java.util.List<HwNode> found = new ArrayList<HwNode>(); + java.util.List<HwNode> done = new ArrayList<HwNode>(); + java.util.List<HwNode> path = new ArrayList<HwNode>(); + Map<HwNode, java.util.List<HwNode>> pathMap = new HashMap<HwNode, java.util.List<HwNode>>(); + TraceManager.addDev("Links " + links); + if (node1==node2){ + return true; + } + for (HwLink link: links){ + if (link.hwnode == node1){ + found.add(link.bus); + java.util.List<HwNode> tmp = new ArrayList<HwNode>(); + tmp.add(link.bus); + pathMap.put(link.bus, tmp); + } + } + outerloop: + while (found.size()>0){ + HwNode curr = found.remove(0); + for (HwLink link: links){ + if (curr == link.bus){ + if (link.hwnode == node2){ + path = pathMap.get(curr); + break outerloop; + } + if (!done.contains(link.hwnode) && !found.contains(link.hwnode) && link.hwnode instanceof HwBridge){ + found.add(link.hwnode); + java.util.List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); + tmp.add(link.hwnode); + pathMap.put(link.hwnode, tmp); + } + } + else if (curr == link.hwnode){ + if (!done.contains(link.bus) && !found.contains(link.bus)){ + found.add(link.bus); + java.util.List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); + tmp.add(link.bus); + pathMap.put(link.bus, tmp); + } + } + } + done.add(curr); + } + if (path.size() ==0){ + System.out.println("no path"); + return true; + } + else { + HwBus bus; + //Check if all buses and bridges are private + for (HwNode n: path){ + if (n instanceof HwBus){ + bus = (HwBus) n; + if (bus.privacy ==0){ + return false; + } + } + } + } + return secure; + } + public void autoMapKeys(){ + System.out.println("Mapping keys"); + TraceManager.addDev("auto map keys"); + if (tmap==null){ + return; + } + java.util.List<HwLink> links = tmap.getArch().getHwLinks(); + //Find all Security Patterns, if they don't have an associated memory at encrypt and decrypt, map them + TMLModeling tmlm = tmap.getTMLModeling(); + if (tmlm.securityTaskMap ==null){ + return; + } + System.out.println(tmlm.securityTaskMap); + for (SecurityPattern sp: tmlm.securityTaskMap.keySet()){ + if (sp.type.contains("Encryption") || sp.type.equals("MAC")){ + TraceManager.addDev("Finding security "+sp); + for (TMLTask t:tmlm.securityTaskMap.get(sp)){ + ArrayList<HwMemory> mems = new ArrayList<HwMemory>(); + boolean keyFound=false; + HwExecutionNode node1 = (HwExecutionNode) tmap.getHwNodeOf(t); + //Try to find memory using only private buses + java.util.List<HwNode> toVisit = new ArrayList<HwNode>(); + // java.util.List<HwNode> toMemory = new ArrayList<HwNode>(); + java.util.List<HwNode> complete = new ArrayList<HwNode>(); + for (HwLink link:links){ + if (link.hwnode==node1){ + if (link.bus.privacy==1){ + toVisit.add(link.bus); + } + } + } + memloop: + while (toVisit.size()>0){ + HwNode curr = toVisit.remove(0); + for (HwLink link: links){ + if (curr == link.bus){ + if (link.hwnode instanceof HwMemory){ + mems.add((HwMemory) link.hwnode); + ArrayList<SecurityPattern> patterns = tmap.getMappedPatterns((HwMemory) link.hwnode); + String patternString= ""; + for (SecurityPattern pattern: patterns){ + if (pattern.name.equals(sp.name)){ + + keyFound=true; + break memloop; + } + patternString += pattern.name; + patternString += " "; + } + TraceManager.addDev("Memory "+ link.hwnode.getName() + " has currently mapped: " + patternString); + } + if (!complete.contains(link.hwnode) && !toVisit.contains(link.hwnode) && link.hwnode instanceof HwBridge){ + toVisit.add(link.hwnode); + } + } + else if (curr == link.hwnode){ + if (!complete.contains(link.bus) && !toVisit.contains(link.bus)){ + toVisit.add(link.bus); + } + } + } + complete.add(curr); + } + if (!keyFound){ + if (mems.size()>0){ + TMLArchiMemoryNode memNode= (TMLArchiMemoryNode) listE.getTG(mems.get(0)); + TMLArchiKey key = new TMLArchiKey(memNode.x, memNode.y, memNode.tdp.getMinX(), memNode.tdp.getMaxX(), memNode.tdp.getMinY(), memNode.tdp.getMaxY(), false, memNode, memNode.tdp); + key.setReferenceKey(sp.name); + key.makeFullValue(); + TraceManager.addDev("Adding " +sp.name+ " key to " +memNode.getName()); + TraceManager.addDev("Adding " +sp + " key to " +memNode.getName()); + memNode.tdp.addComponent(key, memNode.x, memNode.y, true,true); + memNode.tdp.repaint(); + } + else { + System.out.println("Can't map key to memory for " + sp.name + " on task " + t.getName()); + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Cannot map key in memory for " + sp.name + " on task " + t.getName()); + ce.setTDiagramPanel(tmap.tmlap.tmlap); + ce.setTGComponent(null); + checkingErrors.add(ce); + } + } + } + } + } + TraceManager.addDev("Mapping finished"); + } + + public void generateAvatarFromTML(boolean mc, boolean security){ + TraceManager.addDev("Generating Avatar from TML"); + if (avatarspec!=null){ + return; + } + else if (tmap!=null){ + t2a = new TML2Avatar(tmap, mc, security); + avatarspec = t2a.generateAvatarSpec("1"); + } + } + + public boolean generateProVerifFromAVATAR(String _path, int _stateReachability, boolean _typed, String loopLimit) { + if (avatarspec !=null){ + //use avspec + } + else if (tmap!=null){ + t2a = new TML2Avatar(tmap,false,true); + avatarspec = t2a.generateAvatarSpec(loopLimit); + drawPanel(avatarspec, mgui.getFirstAvatarDesignPanelFound()); + + } + else if (tmlm!=null){ + //Generate default mapping + tmap = tmlm.getDefaultMapping(); + tmap.setTMLDesignPanel((TMLComponentDesignPanel)mgui.getCurrentTURTLEPanel()); + t2a=new TML2Avatar(tmap,false,true); + avatarspec = t2a.generateAvatarSpec(loopLimit); + } + else if (avatarspec == null){ + return false; + } + + avatar2proverif = new AVATAR2ProVerif(avatarspec); + //tml2uppaal.setChoiceDeterministic(choices); + //tml2uppaal.setSizeInfiniteFIFO(_size); + proverif = avatar2proverif.generateProVerif(true, true, _stateReachability, _typed); + warnings = avatar2proverif.getWarnings(); + languageID = PROVERIF; + mgui.setMode(MainGUI.EDIT_PROVERIF_OK); + //mgui.setMode(MainGUI.MODEL_PROVERIF_OK); + //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); + try { + if (avatar2proverif.saveInFile(_path)){ + TraceManager.addDev("Specification generated in " + _path); + return true; + } + return false; + } catch (FileException fe) { + TraceManager.addError("Exception: " + fe.getMessage()); + return false; + } + } + + public TPN generateTPNFromAvatar() { + avatar2tpn = new AVATAR2TPN(avatarspec); + //tml2uppaal.setChoiceDeterministic(choices); + //tml2uppaal.setSizeInfiniteFIFO(_size); + tpnFromAvatar = avatar2tpn.generateTPN(true, true); + languageID = TPN; + return tpnFromAvatar; + } + + /*IntMatrix im = tpnFromAvatar.getIncidenceMatrix(); + TraceManager.addDev("Farkas computing on " + im.toString()); + im.Farkas(); + TraceManager.addDev("Farkas done:" + im.toString()); + + + + languageID = TPN; + mgui.setMode(MainGUI.EDIT_PROVERIF_OK); + //mgui.setMode(MainGUI.MODEL_PROVERIF_OK); + //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); + return true; + /*try { + avatar2tpn.saveInFile(_path); + TraceManager.addDev("Specification generated in " + _path); + return true; + } catch (FileException fe) { + TraceManager.addError("Exception: " + fe.getMessage()); + return false; + }*/ + + + public ArrayList<TGComponentAndUPPAALQuery> getUPPAALQueries() { + return getUPPAALQueries(mgui.getCurrentTURTLEPanel()); + } + + public ArrayList<TGComponentAndUPPAALQuery> getUPPAALQueries(TURTLEPanel tp) { + TraceManager.addDev("Searching for queries on " + mgui.getTabName(tp)); + ArrayList<TGComponent> list = new ArrayList<TGComponent>(); + ArrayList<TClass> tclasses; + tp.getAllCheckableTGComponent(list); + TGComponentAndUPPAALQuery tmpQ; + + ArrayList<TGComponentAndUPPAALQuery> listQ = new ArrayList<TGComponentAndUPPAALQuery>(); + + if (tp instanceof DesignPanel) { + ArrayList<ADComponent> listAD = listE.getADComponentCorrespondance(list); + + //TraceManager.addDev("List size:" + listAD.size()); + + if (listAD == null) { + return null; + } + + TClass t; + String s; + for(ADComponent adc:listAD) { + if (adc != null) { + t = tm.findTClass(adc); + //TraceManager.addDev("Found class:" + t.getName()); + if (t!= null) { + tclasses = new ArrayList<TClass>(); + tclasses.add(t); + // For handling tobjects + tm.addAllTClassesEndingWith(tclasses, "_" + t.getName()); + for(TClass tc: tclasses) { + //TraceManager.addDev("Analyzing class:" + tc.getName()); + s = uppaalTIFTable.getRQuery(tc, adc); + if (s != null) { + //TraceManager.addDev("Adding query:" + s); + tmpQ = new TGComponentAndUPPAALQuery(null, s + "$" + adc); + listQ.add(tmpQ); + } + } + } + } + } + } else if ((tp instanceof TMLComponentDesignPanel) || (tp instanceof TMLDesignPanel)) { + //TraceManager.addDev("uppaalTMLTable"); + ArrayList<TMLActivityElement> listAE = listE.getTMLActivityElementCorrespondance(list); + + if (listAE == null) { + return null; + } + + TMLTask task; + String s; + for(TMLActivityElement elt:listAE) { + if (elt != null) { + task = tmlm.findTMLTask(elt); + if (task!= null) { + s = uppaalTMLTable.getRQuery(task, elt); + if (s != null) { + //TraceManager.addDev("Adding query:" + s); + Object ref; + if (elt.getReferenceObject() instanceof TGComponent) { + tmpQ = new TGComponentAndUPPAALQuery((TGComponent)(elt.getReferenceObject()), s + "$" + elt); + } else { + tmpQ = new TGComponentAndUPPAALQuery(null, s + "$" + elt); + } + listQ.add(tmpQ); + } + } + } + } + + } else if ((avatar2uppaal != null) && (tp instanceof AvatarDesignPanel)) { + TraceManager.addDev("Making UPPAAL queries"); + for(TGComponent tgc: list) { + TraceManager.addDev("Making UPPAAL query for " + tgc); + String s = avatar2uppaal.getUPPAALIdentification(tgc); + TraceManager.addDev("Query: " + s); + if ((s!= null) && (s.length() > 0)) { + AvatarBlock block = avatar2uppaal.getBlockFromReferenceObject(tgc); + listQ.add(new TGComponentAndUPPAALQuery(tgc, s + "$" + block.getName() + "." + tgc)); + } else { + TraceManager.addDev("Could not make query for " + tgc); + } + } + } else if ((avatar2uppaal != null) && (tp instanceof AttackTreePanel)) { + TraceManager.addDev("Making UPPAAL queries"); + for(TGComponent tgc: list) { + TraceManager.addDev("Making UPPAAL query for " + tgc); + String s = avatar2uppaal.getUPPAALIdentification(tgc); + TraceManager.addDev("Query: " + s); + if ((s!= null) && (s.length() > 0)) { + AvatarBlock block = avatar2uppaal.getBlockFromReferenceObject(tgc); + listQ.add(new TGComponentAndUPPAALQuery(tgc, s + "$" + block.getName() + "." + tgc)); + } else { + TraceManager.addDev("Could not make query for " + tgc); + } + } + } + + return listQ; + } + + public LinkedList generateLOTOSAUT(String path) { + TML2AUTviaLOTOS tml2aut = new TML2AUTviaLOTOS(tmlm, tm); + tml2aut.generateLOTOS(true); + return tml2aut.getSpecs(); + /*try { + return tml2aut.saveInFiles(path); + } catch (FileException fe) { + return null; + }*/ + } + + public void generateSystemC() { + String path = ConfigurationTTool.SystemCCodeDirectory; + String list = FileUtils.deleteFiles(path, ".cpp"); + if (list.length() == 0) { + TraceManager.addDev("No cpp files were deleted\n"); + } else { + TraceManager.addDev("Files deleted:\n" + list + "\n"); + } + + list = FileUtils.deleteFiles(path, ".x"); + + if (list.length() == 0) { + TraceManager.addDev("No x files were deleted\n"); + } else { + TraceManager.addDev("Files deleted:\n" + list + "\n"); + } + + TML2SystemC tml2systc = new TML2SystemC(tmlm); + tml2systc.generateSystemC(true); + //tml2systc.print(); + try { + tml2systc.saveFile(path, "appmodel"); + } catch (FileException fe) { + TraceManager.addError("File could not be saved (SystemC)"); + } + + } + + + public void saveSIM(File f) { + if ((sim != null) && (f != null)) { + saveInFile(f, sim); + } + } + + public void saveDTA(File f) { + if ((dta != null) && (f != null)) { + saveInFile(f, dta); + } + } + + public void saveDTADOT(File f) { + if ((dtadot != null) && (f != null)) { + saveInFile(f, dtadot); + } + } + + public void saveRG(File f) { + if ((rg != null) && (f != null)) { + saveInFile(f, rg); + } + } + + public void saveTLSA(File f) { + if ((rg != null) && (f != null)) { + saveInFile(f, tlsa); + } + } + + public void saveRGAut(File f) { + if ((rgaut != null) && (f != null)) { + saveInFile(f, rgaut); + } + } + + public void saveRGDOT(File f) { + if ((rgdot != null) && (f != null)) { + saveInFile(f, rgdot); + } + } + + public void saveTLSADOT(File f) { + if ((rgdot != null) && (f != null)) { + saveInFile(f, tlsadot); + } + } + + public void saveRGAutDOT(File f) { + if ((rgautdot != null) && (f != null)) { + saveInFile(f, rgautdot); + } + } + + public void saveRGAutProj(File f) { + if ((rgautproj != null) && (f != null)) { + saveInFile(f, rgautproj); + } + } + + public void saveRGAutProjDOT(File f) { + if ((rgautprojdot != null) && (f != null)) { + saveInFile(f, rgautprojdot); + } + } + + public void modifyMinimizedGraph() { + /*AUTMappingGraph graph = new AUTMappingGraph(); + TraceManager.addDev("Building graph"); + graph.buildGraph(rgautproj); + TraceManager.addDev("Renaming transitions"); + graph.renameTransitions(); + TraceManager.addDev("Merging transitions 23/4=" + (23/4) + "23%4=" + (23%4)); + graph.mergeWriteTransitions(); + graph.mergeReadTransitions(); + graph.removeInternalTransitions(); + TraceManager.addDev("Printing graph:\n" + graph.toAUTStringFormat()); + TraceManager.addDev("Splitting transitions"); + graph.splitTransitions(); + modifiedaut = graph.toAUTStringFormat(); + TraceManager.addDev("Printing graph:\n" + modifiedaut); + TraceManager.addDev("Translation in DOT format"); + + // AUT 2 dot + String fileName = "graph"; + try { + RshClient rshc = new RshClient(getHostAldebaran()); + int id = rshc.getId(); + fileName = FileUtils.addBeforeFileExtension(fileName, "_" + id); + String data = rgautproj; + rshc.sendFileData(fileName + ".aut", data); + String cmd1 = getPathBcgio() + " -aldebaran " + fileName + ".aut" + " -graphviz " + fileName + ".dot"; + data = processCmd(rshc, cmd1); + data = rshc.getFileData(fileName + ".dot"); + modifiedautdot = data; + TraceManager.addDev("All done"); + } catch (LauncherException le) { + TraceManager.addDev("Error: conversion failed"); + }*/ + } + + protected String processCmd(RshClient rshc, String cmd) throws LauncherException { + rshc.setCmd(cmd); + String s = null; + rshc.sendExecuteCommandRequest(); + s = rshc.getDataFromProcess(); + return s; + } + + public void showSIM(int type) { + if (sim != null) { + JFrameSimulationTrace jfst = new JFrameSimulationTrace("Last simulation trace", sim, type); + jfst.setIconImage(IconManager.img8); + // jfst.setSize(900, 600); + GraphicLib.centerOnParent( jfst, 900, 600 ); + jfst.setVisible(true); + } + } + + public String showDTA() { + if (dta != null) { + return runDOTTY(dtadot); + } + return null; + } + + public String showRG() { + if (rg != null) { + return runDOTTY(rgdot); + } + return null; + } + + public String showTLSA() { + if (rg != null) { + return runDOTTY(tlsadot); + } + return null; + } + + public String showRGAut() { + if (rgaut != null) { + return runDOTTY(rgautdot); + } + return null; + } + + public String showRGDiplodocus() { + TraceManager.addDev("Show diplodocus graph located in " + ConfigurationTTool.GGraphPath + "/tree.dot"); + RemoteExecutionThread ret = new RemoteExecutionThread(ConfigurationTTool.DOTTYHost, null, null, ConfigurationTTool.DOTTYPath + " " + ConfigurationTTool.GGraphPath + "/tree.dot"); + ret.start(); + return null; + } + + public String showRGAutProj() { + if (rgaut != null) { + return runDOTTY(rgautprojdot); + } + return null; + } + + public static String showGGraph(String ggraph) { + if (ggraph != null) { + return runDOTTY(ggraph); + } + return null; + } + + public static String runDOTTY(String data) { + String fileName = "graph" + graphId + ".dot"; + graphId ++; + + RemoteExecutionThread ret = new RemoteExecutionThread(ConfigurationTTool.DOTTYHost, fileName, data, ConfigurationTTool.DOTTYPath + " " + fileName); + ret.start(); + + return null; + } + + public boolean useDynamicStructure(String data) { + int index1 = data.indexOf("behaviour"); + if (index1 == -1) { + return false; + } + + data = data.substring(index1, data.length()); + + return (data.indexOf("Queue_nat") != -1); + + } + + + + public void saveInFile(File file, String s) { + TraceManager.addDev("Saving in file " + file.getAbsolutePath() + " size of file=" + s.length()); + //TraceManager.addDev("Length of s=" + s.length()); + + int index1 = 0, index2; + int step = 1048576; + int length = s.length(); + //String sub; + + try { + FileOutputStream fos = new FileOutputStream(file); + while(index1<length) { + index2 = Math.min(index1+step, length); + fos.write(s.substring(index1, index2).getBytes()); + index1 += step; + } + fos.close(); + } catch(Exception e) { + JOptionPane.showMessageDialog(mgui.frame, "Specification could not be saved " + e.getMessage(), "Lotos File Error", JOptionPane.INFORMATION_MESSAGE); + TraceManager.addError("Specification could not be saved " + e.getMessage()); + } + + /*try { + FileOutputStream fos = new FileOutputStream(file); + fos.write(s.getBytes()); + fos.close(); + } catch(Exception e) { + JOptionPane.showMessageDialog(mgui.frame, "Specification could not be saved " + e.getMessage(), "Lotos File Error", JOptionPane.INFORMATION_MESSAGE); + TraceManager.addDev("Specification could not be saved " + e.getMessage()); + }*/ + } + + public String getLastRTLOTOSSpecification() { + return rtlotos; + } + + public String getLastTextualDTA() { + return dta; + } + + public String getLastGraphicalDTA() { + return dtadot; + } + + public String getLastTextualRG() { + return rg; + } + + public String getLastGraphicalRG() { + return rgdot; + } + + public String getLastTextualTLSA() { + return tlsa; + } + + public String getLastGraphicalTLSA() { + return tlsadot; + } + + public String getLastTextualRGAUT() { + return rgaut; + } + + public String getLastGraphicalRGAUT() { + return rgautdot; + } + + public String getLastTextualRGAUTProj() { + return rgautproj; + } + + public String getLastGraphicalRGAUTProj() { + return rgautprojdot; + } + + public String getLastProVerifSpecification() { + if (proverif == null) { + return ""; + } + + return proverif.getStringSpec(); + } + + public int getNbRTLOTOS() { + return nbRTLOTOS; + } + + public String getLastTextualDesign() { + if (tm == null) { + return ""; + } else { + return tm.printToStringBuffer().toString(); + } + } + + public int getNbSuggestedDesign() { + return nbSuggestedDesign; + } + + // formal validation + public void reinitSIM() { + sim = null; + mgui.setMode(MainGUI.SIM_KO); + } + + public void reinitDTA() { + dta = null; + dtadot = null; + mgui.setMode(MainGUI.DTADOT_KO); + } + + public void reinitRG() { + rg = null; + rgdot = null; + mgui.setMode(MainGUI.RGDOT_KO); + } + + public void reinitRGAUT() { + rgaut = null; + rgautdot = null; + mgui.setMode(MainGUI.RGAUTDOT_KO); + mgui.setMode(MainGUI.RGAUT_KO); + } + + public void reinitRGAUTPROJDOT() { + rgautprojdot = null; + mgui.setMode(MainGUI.RGAUTPROJDOT_KO); + } + + public void setSIM(String data) { + sim = data; + mgui.setMode(MainGUI.SIM_OK); + } + + public void setDTA(String data) { + dta = data; + } + + public void setDTADOT(String data) { + dtadot = data; + mgui.setMode(MainGUI.DTADOT_OK); + } + + public void setRG(String data) { + rg = data; + mgui.setMode(MainGUI.RGDOT_OK); + } + + public void setTLSA(String data) { + tlsa = data; + //mgui.setMode(MainGUI.TLSADOT_OK); + } + + public void setTLSADOT(String data) { + tlsadot = data; + mgui.setMode(MainGUI.TLSADOT_OK); + } + + public void setRGAut(String data) { + rgaut = data; + mgui.setMode(MainGUI.RGAUT_OK); + } + + public String getLastRGAUT() { + return rgaut; + } + + public void setRGDOT(String data) { + rgdot = data; + mgui.setMode(MainGUI.RGDOT_OK); + } + + public void setRGAutDOT(String data) { + rgautdot = data; + mgui.setMode(MainGUI.RGAUTDOT_OK); + } + + public void setRGAUTPROJ(String data) { + rgautproj = data; + } + + public void setRGAUTPROJDOT(String data) { + rgautprojdot = data; + mgui.setMode(MainGUI.RGAUTPROJDOT_OK); + } + + // Configuration + + public String getPathRTL() { + return ConfigurationTTool.RTLPath; + } + + public String getPathCaesar() { + return ConfigurationTTool.CaesarPath; + } + + public String getPathCaesarOpen() { + return ConfigurationTTool.CaesarOpenPath; + } + + public String getPathDTA2DOT() { + return ConfigurationTTool.DTA2DOTPath; + } + + public String getPathRGSTRAP() { + return ConfigurationTTool.RGSTRAPPath; + } + + public String getPathRG2TLSA() { + return ConfigurationTTool.RG2TLSAPath; + } + + public String getHost() { + return ConfigurationTTool.RTLHost; + } + + public static String getCaesarHost() { + return ConfigurationTTool.AldebaranHost; + } + + public static String getHostAldebaran() { + return ConfigurationTTool.AldebaranHost; + } + + public static String getPathAldebaran() { + return ConfigurationTTool.AldebaranPath; + } + + public static String getPathBcgio() { + return ConfigurationTTool.BcgioPath; + } + + public static String getPathBisimulator() { + return ConfigurationTTool.BisimulatorPath; + } + + public String getPathBcgmerge() { + return ConfigurationTTool.BcgmergePath; + } + + public String getPathBcgmin() { + return ConfigurationTTool.BcgminPath; + } + + public String getPathVerifyta() { + return ConfigurationTTool.UPPAALVerifierPath; + } + + public String getPathUPPAALVerifier() { + return ConfigurationTTool.UPPAALVerifierPath; + } + + public String getPathUPPAALFile() { + return ConfigurationTTool.UPPAALCodeDirectory; + } + + public String getUPPAALVerifierHost() { + return ConfigurationTTool.UPPAALVerifierHost; + } + + + + public TURTLEModeling getTURTLEModeling() { + return tm; + } + + public int getTURTLEModelingState() { + return tmState; + } + + public TMLModeling getTMLModeling() { + return tmlm; + } + public TML2Avatar getTML2Avatar(){ + return t2a; + } + public TMLMapping getArtificialTMLMapping() { + return artificialtmap; + } + + public TMLMapping getTMLMapping() { + return tmap; + } + + public UPPAALSpec getLastUPPAALSpecification() { + return uppaal; + } + + // TREE MANAGEMENT + + public String toString() { + return mgui.getTitle(); + } + + public int getChildCount() { + return panels.size() + 4; + } + + public Object getChild(int index) { + if (index < panels.size()) { + return panels.elementAt(index); + } else if (index == panels.size()) { + return mcvdt; + } else if (index == (panels.size() + 1)) { + return gt; + } else if (index == (panels.size() + 2)) { + return idt; + } else { + return st; + } + + } + + public int getIndexOfChild(Object child) { + int index = panels.indexOf(child); + + if (index > -1) { + return index; + } + + if (child == mcvdt) { + return panels.size(); + } + + if (child == gt) { + return panels.size() + 1; + } + + if (child == idt) { + return panels.size() + 2; + } + + return panels.size()+3; + } + + // Projection management + + public MasterGateManager getNewMasterGateManager() { + return new MasterGateManager(tm); + } + + // Assume the inputData is in AUT format: generated by RTL or CADP + public String performProjection(String inputData, LinkedList<TClassAndGateDS> gates) { + StringBuffer result = new StringBuffer(""); + StringReader sr = new StringReader(inputData); + BufferedReader br = new BufferedReader(sr); + String s; + String actionName, actionName1; + int index, index1, index2; + MasterGateManager mgm = new MasterGateManager(tm, 1); + Gate g; + GroupOfGates gog; + Hashtable <String, GroupOfGates> hashtable = new Hashtable<String, GroupOfGates>(); + + int cpt = 0; + + //TraceManager.addDev("input data=" + inputData); + + // Fill Hashtable + int j; + for (TClassAndGateDS tag: gates) { + //TraceManager.addDev("TClass:" + tag.getTClassName() + " Gate:" + tag.getGateName()); + //actionName = tag.getGateName(); + //g = mgm.getGate(tag.getTClassName(), actionName); + //TraceManager.addDev("actionName = " + actionName + " gateName = " + g.getName()); + //if (g != null) { + //gog = mgm.getGroupOfGatesByGate(g); + gog = mgm.groupOf(tag.getTClassName(), tag.getGateName()); + if (gog != null) { + //TraceManager.addDev("Found a gog: >" + gog.getMasterGateName() + "<"); + hashtable.put(gog.getMasterGateName().getName(), gog); + /*for(j=0;j<gog.size();j++) { + g = gog.getGateAt(j); + TraceManager.addDev("Putting: " + g.getName()); + hashtable.put(g.getName(), g); + }*/ + } + //} + } + + try { + while((s = br.readLine()) != null) { + /*if (cpt % 10000 == 0) { + TraceManager.addDev("cpt=" + cpt); + }*/ + cpt ++; + + if (s.startsWith("des")) { + result.append(s + "\n"); + } else if (s.startsWith("(")) { + index = s.indexOf("\"t\""); + if (index > 0) { + // temporal action + // replace t with i + s = s.replaceAll("\"t\"", "i"); + result.append(s + "\n"); + } else { + //exit action? + index = s.indexOf("\"exit\""); + if (index > 0) { + // exit action + // replace t with i + s = s.replaceAll("\"exit\"", "i"); + result.append(s + "\n"); + } else { + // regular action + // find the name of this action + index1 = s.indexOf("i("); + index2 = s.indexOf(")"); + actionName = s.substring(index1 + 2, index2); + index = actionName.indexOf("<"); + if (index < 0) { + actionName1 = actionName; + } else { + actionName1 = actionName.substring(0, index); + } + TraceManager.addDev("Action = >" + actionName1 + "<"); + + gog = hashtable.get(actionName1); + if (gog == null) { + TraceManager.addDev("Not in hash"); + result.append(makeIAction(s) + "\n"); + } else { + TraceManager.addDev("In hash"); + result.append(makeAction(s, actionName) + "\n"); + } + + // action to ignored or to project ? + /*g = mgm.getGate(actionName1); + if (g == null) { + //TraceManager.addDev("null1"); + result.append(makeIAction(s) + "\n"); + } else { + gog = mgm.getGroupOfGatesByGate(g); + if (gog == null) { + //TraceManager.addDev("null2"); + result.append(makeIAction(s) + "\n"); + } else { + if (!belongTo(gog, gates)) { + // Check if directly a master Gate! + // A completer ... + //TraceManager.addDev("null3"); + result.append(makeIAction(s) + "\n"); + } else { + //TraceManager.addDev("action added: " + actionName); + result.append(makeAction(s, actionName) + "\n"); + } + } + }*/ + } + + } + } + } + } catch (Exception e) { + TraceManager.addError("Exception during projection" + e.getMessage()); + return null; + } + return new String(result); + } + + // Assume the inputData is in AUT format and has been generated by CADP + // Note: might not work because of case sensitive problem... + public String convertCADP_AUT_to_RTL_AUT(String inputData, int max) { + StringBuffer result = new StringBuffer(""); + StringReader sr = new StringReader(inputData); + BufferedReader br = new BufferedReader(sr); + String s, s1; + String actionName; + int index1, index2, index3, index4; + Gate g; + String g0, g1, g2; + int cpt, transi=0; + MasterGateManager mgm = new MasterGateManager(tm, 1); + Hashtable ht = mgm.getGatesUpperCaseHashTable(); + warnings = new LinkedList<CheckingError> (); + + //TraceManager.addDev("input data=" + inputData); + + int cpt1 = 0; + + try { + while((s = br.readLine()) != null) { + cpt1 ++; + //if (cpt1 % 100000 == 0) { + //TraceManager.addDev("=" + cpt1 + " / " + transi); + //} + if (s.charAt(0) == '(') { + index1 = s.indexOf(","); + if ((index1 > -1) && ((index1+1) < s.length())) { + g1 = s.substring(0, index1 + 1); + s = s.substring(index1+1, s.length()); + + //TraceManager.addDev("g1=" + g1 + " s=" + s); + + index2 = s.indexOf(","); + if ((index2 > -1) && ((index2+1) < s.length())) { + g2 = s.substring(index2, s.length()); + s = s.substring(0, index2); + s = s.trim(); + + //TraceManager.addDev("g2=" + g2 + " s=" + s); + + // Get action id + // Most common case: no data + index3 = s.indexOf('"'); + if (index3 == -1) { // no data + actionName = s; + g0 = ""; + } else { + // Extract action name + actionName = s.substring(index3+1, s.indexOf('!')).trim(); + + // Format data + g0 = "<"; + cpt = 0; + while((index4 = s.indexOf('!')) > -1) { + s = s.substring(index4+1, s.length()); + if (cpt > 0) { + g0 += ","; + } + cpt ++; + index4 = s.indexOf('!'); + if (index4 > -1) { + g0 += s.substring(0, index4); + } else { + g0 += s.substring(0, s.indexOf('"')).trim(); + } + } + g0 += ">"; + } + + // Working on action name! + //g = mgm.getGateLowerCase(actionName); + g = (Gate)(ht.get(actionName)); + + if (g != null) { + //actionName1 = actionName; + actionName = g.getName(); + //TraceManager.addDev("actionName = " + g.getName()); + /*if (mgm.nbOfPossibleGatesLowerCase(actionName1) > 1) { + CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action " + actionName1 + " has several possible candidates ; " + actionName + " has been chosen"); + warnings.add(ce); + }*/ + } else { + TraceManager.addDev("actionName is not in hashtable: ->" + actionName + "<- length=" + actionName.length()); + } + + // Store result + result.append(g1 + "\"i(" + actionName + g0 + ")\"" + g2 + "\n"); + } + } + } else if (s.startsWith("des")) { + index1 = s.indexOf(","); + s1 = s.substring(index1+1, s.length()); + index1 = s1.indexOf(","); + s1 = s1.substring(0, index1).trim(); + //TraceManager.addDev("nb of transitions=" + s); + transi = Integer.decode(s1).intValue(); + if (transi > max) { + return null; + } + result.append(s + "\n"); + } + } + } catch (Exception e) { + TraceManager.addError("Exception convert0" + e.getMessage()); + return null; + } + return new String(result); + } + + /*public String convertCADP_AUT_to_RTL_AUT(String inputData, int max) { + StringBuffer result = new StringBuffer(""); + StringReader sr = new StringReader(inputData); + BufferedReader br = new BufferedReader(sr); + String s; + String actionName, actionName1; + int index, index1, index2, index3, index4, index5; + Gate g; + String g0, g1, g2; + int cpt, transi=0; + MasterGateManager mgm = new MasterGateManager(tm); + warnings = new Vector(); + + //TraceManager.addDev("input data=" + inputData); + + int cpt1 = 0; + + try { + while((s = br.readLine()) != null) { + cpt1 ++; + if (cpt1 % 100000 == 0) { + TraceManager.addDev("=" + cpt1 + " / " + transi); + } + if (s.charAt(0) == '(') { + index1 = s.indexOf(","); + if ((index1 > -1) && ((index1+1) < s.length())) { + g1 = s.substring(0, index1 + 1); + s = s.substring(index1+1, s.length()); + + //TraceManager.addDev("g1=" + g1 + " s=" + s); + + index2 = s.indexOf(","); + if ((index2 > -1) && ((index2+1) < s.length())) { + g2 = s.substring(index2, s.length()); + s = s.substring(0, index2); + s = s.trim(); + + //TraceManager.addDev("g2=" + g2 + " s=" + s); + + // Get action id + // Most common case: no data + index3 = s.indexOf('"'); + if (index3 == -1) { // no data + actionName = s; + g0 = ""; + } else { + // Extract action name + actionName = s.substring(index3+1, s.indexOf('!')).trim(); + + // Format data + g0 = "<"; + cpt = 0; + while((index4 = s.indexOf('!')) > -1) { + s = s.substring(index4+1, s.length()); + if (cpt > 0) { + g0 += ","; + } + cpt ++; + index4 = s.indexOf('!'); + if (index4 > -1) { + g0 += s.substring(0, index4); + } else { + g0 += s.substring(0, s.indexOf('"')).trim(); + } + } + g0 += ">"; + } + + // Working on action name! + g = mgm.getGateLowerCase(actionName); + + if (g != null) { + actionName1 = actionName; + actionName = g.getName(); + if (mgm.nbOfPossibleGatesLowerCase(actionName1) > 1) { + CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action " + actionName1 + " has several possible candidates ; " + actionName + " has been chosen"); + warnings.add(ce); + } + } + + // Store result + result.append(g1 + "\"i(" + actionName + g0 + ")\"" + g2 + "\n"); + } + } + } else if (s.startsWith("des")) { + index1 = s.indexOf(","); + s = s.substring(index1+1, s.length()); + index1 = s.indexOf(","); + s = s.substring(0, index1).trim(); + //TraceManager.addDev("nb of transitions=" + s); + transi = Integer.decode(s).intValue(); + if (transi > max) { + return null; + } + result.append(s + "\n"); + } + } + } catch (Exception e) { + TraceManager.addError("Exception09545 " + e.getMessage()); + return null; + } + return new String(result); + }*/ + + public boolean belongTo(GroupOfGates gog, Vector gates) { + int i, j; + TClassAndGateDS tcg; + String nameTClass, nameGate; + for(i=0; i<gog.size(); i++) { + nameTClass = gog.getTClassAt(i).getName(); + nameGate = gog.getGateAt(i).getName(); + for(j=0; j<gates.size(); j++) { + tcg = (TClassAndGateDS)(gates.elementAt(j)); + if ((tcg.getTClassName().compareTo(nameTClass) == 0) && (tcg.getGateName().compareTo(nameGate) == 0)) { + //TraceManager.addDev("Projected gate"); + return true; + } + } + + } + return false; + + } + + public String makeIAction(String s) { + int index1, index2; + index1 = s.indexOf("i("); + index2 = s.indexOf(")"); + return s.substring(0, index1-1) + "i" + s.substring(index2+2, s.length()); + } + + public String makeAction(String s, String actionName) { + int index1, index2; + index1 = s.indexOf("i("); + index2 = s.indexOf(")"); + return s.substring(0, index1) + actionName + s.substring(index2+1, s.length()); + } + + public void enableUndo(boolean b) { + undoRunning = !b; + } + + public boolean isUndoEnable() { + return !undoRunning; + } + + // UNDO MANAGEMENT + + // This function is not be performed when executing an undo + // if variable undoRunnin has been set to true + public void saveOperation(Point p) { + if (undoRunning) { + return; + } + + //TraceManager.addDev("Save operation"); + + String s = makeXMLFromTurtleModeling(-1); + + if ((pointerOperation > -1) && (pointerOperation < savedOperations.size() - 1)) { + // some save operations must be erased + for (int i = pointerOperation +1; i<savedOperations.size(); i++) { + savedOperations.removeElementAt(i); + savedPanels.removeElementAt(i); + i --; + } + } + + // save actions on tab + int size = savedPanels.size(); + if (size > 0) { + Point p1 = (Point)(savedPanels.elementAt(size - 1)); // panels are saved under the form of a point -> x = analysis/design, y = panel + if (p == null) + p = p1; + /*if ((p1.x != p.x) || (p1.y != p.y)){ + savedOperations.add(savedOperations.elementAt(size - 1)); + savedPanels.add(p); + if (savedOperations.size() > nbMaxSavedOperations) { + savedOperations.removeElementAt(0); + savedPanels.removeElementAt(0); + } + }*/ + } + + savedOperations.add(s); + savedPanels.add(p); + if (savedOperations.size() > nbMaxSavedOperations) { + savedOperations.removeElementAt(0); + savedPanels.removeElementAt(0); + } + pointerOperation = savedOperations.size() - 1; + //TraceManager.addDev("Setting pointer to " + pointerOperation); + + selectBackwardMode(); + } + + public void backward() { + undoRunning = true; + TraceManager.addDev("Nb Of saved operations:" + savedOperations.size() + " pointer=" + pointerOperation); + if ((pointerOperation < 1) || (savedOperations.size() < 2)) { + TraceManager.addDev("Undo not possible"); + undoRunning = false; + return; + } + + removeAllComponents(); + mgui.reinitMainTabbedPane(); + try { + pointerOperation --; + TraceManager.addDev("Decrementing pointer =" + pointerOperation); + loadModelingFromXML((String)(savedOperations.elementAt(pointerOperation))); + + } catch (Exception e) { + TraceManager.addError("Exception in backward: " + e.getMessage()); + } + + TraceManager.addDev("Selecting tab"); + + Point p = (Point)(savedPanels.elementAt(pointerOperation)); + if (p != null) { + TraceManager.addDev("Selecting tab panel=" + p.getX() + " diagram=" + p.getY()); + TDiagramPanel tdp = mgui.selectTab(p); + tdp.mode = tdp.NORMAL; + tdp.setDraw(true); + tdp.repaint(); + } + + + TraceManager.addDev("Selecting backward mode"); + selectBackwardMode(); + undoRunning = false; + } + + public void selectBackwardMode() { + if (pointerOperation <0) { + mgui.setMode(MainGUI.NO_BACKWARD); + mgui.setMode(MainGUI.NO_FORWARD); + } else { + + // forward + if (pointerOperation < savedOperations.size() - 1) { + mgui.setMode(MainGUI.FORWARD); + } else { + mgui.setMode(MainGUI.NO_FORWARD); + } + + // backward + if (pointerOperation > 0) { + mgui.setMode(MainGUI.BACKWARD); + } else { + mgui.setMode(MainGUI.NO_BACKWARD); + } + } + } + + + public void forward() { + if ((pointerOperation < 0) || (pointerOperation > savedOperations.size() - 2)) { + return; + } + + undoRunning = true; + removeAllComponents(); + mgui.reinitMainTabbedPane(); + + try { + pointerOperation ++; + loadModelingFromXML((String)(savedOperations.elementAt(pointerOperation))); + } catch (Exception e) { + TraceManager.addError("Exception in forward: " + e.getMessage()); + } + + Point p = (Point)(savedPanels.elementAt(pointerOperation)); + if (p != null) { + TDiagramPanel tdp = mgui.selectTab(p); + tdp.mode = TDiagramPanel.NORMAL; + tdp.setDraw(true); + tdp.repaint(); + } + + selectBackwardMode(); + undoRunning = false; + } + + + // BUILDING A TURTLE MODELING AND CHECKING IT + public boolean checkTURTLEModeling(LinkedList<TClassInterface> tclasses, DesignPanel dp, boolean overideSyntaxChecking) { + // Builds a TURTLE modeling from diagrams + //warnings = new Vector(); + //checkingErrors = null; + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + //tm = new TURTLEModeling(); + //listE = new CorrespondanceTGElement(); + mgui.reinitCountOfPanels(); + + DesignPanelTranslator dpt = new DesignPanelTranslator(dp); + tm = dpt.generateTURTLEModeling(tclasses, ""); + tmState = 0; + + listE = dpt.getCorrespondanceTGElement(); + checkingErrors = dpt.getErrors(); + warnings = dpt.getWarnings(); + if ((checkingErrors != null) && (checkingErrors.size() >0)){ + return false; + } + + // modeling is built + // Now check it ! + if (!overideSyntaxChecking) { + TURTLEModelChecker tmc = new TURTLEModelChecker(tm, listE); + + checkingErrors = tmc.syntaxAnalysisChecking(); + warnings.addAll(tmc.getWarnings()); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + return false; + } else { + return true; + } + } + + return true; + } + + // BUILDING An AVATAR Design AND CHECKING IT + public boolean checkAvatarDesign(LinkedList<AvatarBDStateMachineOwner> blocks, AvatarDesignPanel adp, boolean _optimize) { + // Builds a TURTLE modeling from diagrams + //warnings = new Vector(); + //checkingErrors = null; + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + //tm = new TURTLEModeling(); + //listE = new CorrespondanceTGElement(); + mgui.reinitCountOfPanels(); + + //avatarspec = new AvatarSpecification("avatarspecification", adp); + + AvatarDesignPanelTranslator adpt = new AvatarDesignPanelTranslator(adp); + avatarspec = adpt.generateAvatarSpecification(blocks); + avatarspec.setInformationSource(adp); + optimizeAvatar = _optimize; + //TraceManager.addDev("AvatarSpec:" + avatarspec.toString() + "\n\n"); + tmState = 3; + + listE = adpt.getCorrespondanceTGElement(); + checkingErrors = adpt.getErrors(); + warnings = adpt.getWarnings(); + if ((checkingErrors != null) && (checkingErrors.size() >0)){ + return false; + } + return true; + + // Modeling is built + // Now check it ! + /*if (!overideSyntaxChecking) { + TURTLEModelChecker tmc = new TURTLEModelChecker(tm, listE); + + checkingErrors = tmc.syntaxAnalysisChecking(); + warnings.addAll(tmc.getWarnings()); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + return false; + } else { + return true; + } + } + + return true;*/ + } + + // Return values + // -1: error + // -2: no mutex + // -3: invariant for mutex not found + // else: invariant found! -> invariant index + public int computeMutex() { + if (avatarspec == null) { + return -1; + } + + AvatarDesignPanel adp = null; + + try { + adp = (AvatarDesignPanel)(avatarspec.getInformationSource()); + } catch (Exception e) { + TraceManager.addDev("Exception gtm: " + e.getMessage()); + return -1; + } + + // Building the list of all states in the mutex + LinkedList<TGComponent> compInMutex = adp.getListOfComponentsInMutex(); + TraceManager.addDev("Nb of elements in mutex:" + compInMutex.size()); + + if (compInMutex.size() ==0) { + return -2; + } + + LinkedList<TGComponent> comps; + boolean found; + int nbOfFound; + int cpt = 0; + // Go thru invariants, and see whether one contains + for(Invariant inv: invariants) { + comps = inv.getComponents(); + nbOfFound = 0; + for(TGComponent tgc_mutex: compInMutex) { + found = false; + for(TGComponent tgc_inv: comps) { + if (tgc_mutex == tgc_inv) { + found = true; + break; + } + } + if (!found) { + break; + } + nbOfFound ++; + } + if (nbOfFound == compInMutex.size()) { + TraceManager.addDev("Mutex found in inv:" + cpt); + for(TGComponent tgc: compInMutex) { + tgc.setMutexResult(TGComponent.MUTEX_OK); + } + return cpt; + } + cpt ++; + } + + + for(TGComponent tgc: compInMutex) { + tgc.setMutexResult(TGComponent.MUTEX_UNKNOWN); + } + + return -3; + + + } + + public void clearGraphicalInfoOnInvariants() { + if (avatarspec == null) { + return; + } + + AvatarDesignPanel adp = null; + + try { + adp = (AvatarDesignPanel)(avatarspec.getInformationSource()); + } catch (Exception e) { + TraceManager.addDev("Exception gtm: " + e.getMessage()); + return; + } + + if (adp == null) { + return; + } + + adp.removeAllMutualExclusionWithMasterMutex(); + + + + } + + + // Returns the number of states found + // Returns -1 in case of error + public int computeMutexStatesWith(AvatarSMDState state) { + Vector<TGComponent> list = new Vector<TGComponent>(); + + if (state == null) { + state.setMutexWith(TGComponent.MUTEX_UNKNOWN); + return -1; + } + + for(Invariant inv: invariants) { + if (inv.containsComponent(state)) { + // All other states are in mutual exclusion + for(TGComponent tgc: inv.getComponents()) { + if ((tgc instanceof AvatarSMDState) && (tgc != state)) { + if (tgc.getTDiagramPanel() != state.getTDiagramPanel()) { + if (!(list.contains(tgc))) { + tgc.setMutualExclusionWithMasterMutex(state.getTDiagramPanel().getName() + "/" + state.getStateName()); + list.add(tgc); + + } + } + } + } + } + } + + if (list.size() > 0) { + state.setMutexWith(TGComponent.MUTEX_OK); + } else { + state.setMutexWith(TGComponent.MUTEX_UNKNOWN); + } + + return list.size(); + + } + + + public void computeAllMutualExclusions() { + TURTLEPanel tp = mgui.getCurrentTURTLEPanel(); + + if (tp == null) { + return; + } + + if (!(tp instanceof AvatarDesignPanel)) { + return; + } + + AvatarDesignPanel adp = (AvatarDesignPanel)(tp); + adp.reinitMutualExclusionStates(); + + // First step: build a list of all states being in invariants + Vector<AvatarSMDState> v = new Vector<AvatarSMDState>(); + for(Invariant inv: invariants) { + for(TGComponent tgc: inv.getComponents()) { + if (tgc instanceof AvatarSMDState) { + if (!(v.contains(tgc))) { + v.add((AvatarSMDState)tgc); + } + } + } + } + + // Then, add to all states its list of mutually exclusive states + + for(AvatarSMDState s: v) { + Vector<AvatarSMDState> v0 = new Vector<AvatarSMDState>(); + for(Invariant inv: invariants) { + if (inv.containsComponent(s)) { + for(TGComponent tgc: inv.getComponents()) { + if ((tgc instanceof AvatarSMDState) && (tgc != s)) { + if (tgc.getTDiagramPanel() != s.getTDiagramPanel()) { + if (!(v0.contains(tgc))) { + v0.add((AvatarSMDState)tgc); + } + } + } + } + } + } + TraceManager.addDev("State " + s.getStateName() + " has " + v0.size() + " mutually eclusive states"); + + for(AvatarSMDState s0: v0) { + s.addMutexState(s0); + } + } + + + } + + // From AVATAR to TURTLEModeling + public boolean translateAvatarSpecificationToTIF() { + AVATAR2TURTLE att = new AVATAR2TURTLE(avatarspec); + tm = att.generateTURTLEModeling(); + + TURTLEModelChecker tmc = new TURTLEModelChecker(tm, listE); + + checkingErrors = tmc.syntaxAnalysisChecking(); + warnings.addAll(tmc.getWarnings()); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + return false; + } else { + return true; + } + + } + + public LinkedList<CheckingError> getCheckingErrors() { + return checkingErrors; + } + + public LinkedList<CheckingError> getCheckingWarnings() { + return warnings; + } + + + // SAVING AND LOADING IN XML + public static String transformString(String s) { + if (s != null) { + s = Conversion.replaceAllChar(s, '&', "&"); + s = Conversion.replaceAllChar(s, '<', "<"); + s = Conversion.replaceAllChar(s, '>', ">"); + s = Conversion.replaceAllChar(s, '"', """); + s = Conversion.replaceAllChar(s, '\'', "'"); + } + return s; + } + + public static String encodeString(String s) { + return s; + } + + public static String decodeString(String s) throws MalformedModelingException { + if (s == null) + return s; + byte b[] = null; + try { + b = s.getBytes("ISO-8859-1"); + return new String(b); + } catch (Exception e) { + throw new MalformedModelingException(); + } + } + + public String mergeTURTLEGModeling(String modeling1, String modeling2) { + int index1 = modeling1.indexOf("</TURTLEGMODELING"); + int index2 = modeling2.indexOf("<TURTLEGMODELING"); + if ((index1 == -1) || (index2 == -1)) { + return null; + } + + String modeling = modeling1.substring(0, index1); + String tmp = modeling2.substring(index2, modeling2.length()); + index2 = modeling2.indexOf('<'); + if (index2 == -1) { + return null; + } + + tmp = tmp.substring(index2+1, tmp.length()); + + return modeling + tmp; + } + + public String makeXMLFromComponentOfADiagram(TDiagramPanel tdp, TGComponent tgc, int copyMaxId, int _decX, int _decY) { + StringBuffer sb = new StringBuffer(); + + //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGSELECTEDCOMPONENTS "); + sb.append("version=\"" + DefaultText.getVersion()); + sb.append("\" copyMaxId=\"" + copyMaxId); + sb.append("\" decX=\"" + _decX); + sb.append("\" decY=\"" + _decY); + sb.append("\" >\n\n"); + + StringBuffer s; + String str; + + s = tdp.saveComponentInXML(tgc); + + if (tgc instanceof AvatarBDBlock) { + AvatarSMDPanel asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); + s.append(asmdp.saveInXML()); + LinkedList<AvatarBDBlock> list = ((AvatarBDBlock)tgc).getFullBlockList(); + for(AvatarBDBlock b:list) { + asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), b.getValue()); + s.append(asmdp.saveInXML()); + } + } + + if (tgc instanceof AvatarBDLibraryFunction) { + AvatarSMDPanel asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), ((AvatarBDLibraryFunction) tgc).getFunctionName ()); + s.append(asmdp.saveInXML()); + } + + if (tgc instanceof TCDTClass) { + TActivityDiagramPanel tadp = mgui.getActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); + s.append(tadp.saveInXML()); + } + + if (tgc instanceof TOSClass) { + TURTLEOSActivityDiagramPanel tosadp = mgui.getTURTLEOSActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); + s.append(tosadp.saveInXML()); + } + + if (tgc instanceof TMLTaskOperator) { + TMLActivityDiagramPanel tmladp1 = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); + s.append(tmladp1.saveInXML()); + } + + if (tgc instanceof TMLCPrimitiveComponent) { + TMLActivityDiagramPanel tmladp2 = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); + s.append(tmladp2.saveInXML()); + } + + if (tgc instanceof TMLCCompositeComponent) { + TMLActivityDiagramPanel tmladp3; + ArrayList<TMLCPrimitiveComponent> list = ((TMLCCompositeComponent)tgc).getAllPrimitiveComponents(); + for (TMLCPrimitiveComponent comp: list) { + tmladp3 = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), comp.getValue()); + s.append(tmladp3.saveInXML()); + } + } + + if (s == null) { + return null; + } + sb.append(s); + sb.append("\n\n"); + sb.append("</TURTLEGSELECTEDCOMPONENTS>"); + + str = new String(sb); + str = encodeString(str); + + return str; + } + + + public String makeXMLFromSelectedComponentOfADiagram(TDiagramPanel tdp, int copyMaxId, int _decX, int _decY) { + StringBuffer sb = new StringBuffer(); + //TraceManager.addDev("Making copy"); + + //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGSELECTEDCOMPONENTS "); + sb.append("version=\"" + DefaultText.getVersion()); + sb.append("\" copyMaxId=\"" + copyMaxId); + sb.append("\" decX=\"" + _decX); + sb.append("\" decY=\"" + _decY); + sb.append("\" >\n\n"); + + StringBuffer s; + String str; + + s = tdp.saveSelectedInXML(); + + Vector v = tdp.selectedTclasses(); + + if ((v != null) && (v.size() > 0)) { + TCDTClass t; + TActivityDiagramPanel tadp; + for(int i=0; i<v.size(); i++) { + t = (TCDTClass)(v.elementAt(i)); + tadp = mgui.getActivityDiagramPanel(mgui.getCurrentSelectedIndex(), t.getValue()); + s.append(tadp.saveInXML()); + } + } + + //Added by Solange + //bug removed by Emil + if (tdp instanceof ProactiveCSDPanel) + { + v=((ProactiveCSDPanel)tdp).selectedProCSDComponent(null); + if ((v != null) && (v.size() > 0)) { + ProCSDComponent t; + ProactiveSMDPanel psmd; + for(int i=0; i<v.size(); i++) { + t = (ProCSDComponent)(v.elementAt(i)); + psmd = mgui.getSMDPanel(mgui.getCurrentSelectedIndex(), t.getValue()); + if (psmd!=null) + s.append(psmd.saveInXML()); + } + } + } + //until here + + + v = tdp.selectedTURTLEOSClasses(); + if ((v != null) && (v.size() > 0)) { + //TraceManager.addDev("Saving TURTLEOS activity diagram Panel..."); + TOSClass t; + TURTLEOSActivityDiagramPanel tosadp; + for(int i=0; i<v.size(); i++) { + t = (TOSClass)(v.elementAt(i)); + tosadp = mgui.getTURTLEOSActivityDiagramPanel(mgui.getCurrentSelectedIndex(), t.getValue()); + s.append(tosadp.saveInXML()); + } + } + + v = tdp.selectedTMLTasks(); + if ((v != null) && (v.size() > 0)) { + //TraceManager.addDev("Saving TML activity diagram Panel..."); + TMLTaskOperator t; + TMLActivityDiagramPanel tmladp; + for(int i=0; i<v.size(); i++) { + t = (TMLTaskOperator)(v.elementAt(i)); + tmladp = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), t.getValue()); + s.append(tmladp.saveInXML()); + } + } + + v = tdp.selectedAvatarBDBlocks(); + if ((v != null) && (v.size() > 0)) { + //TraceManager.addDev("Saving TML activity diagram Panel..."); + AvatarBDBlock abdb; + AvatarSMDPanel asmdp; + for(int i=0; i<v.size(); i++) { + abdb = (AvatarBDBlock)(v.elementAt(i)); + asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), abdb.getBlockName()); + s.append(asmdp.saveInXML()); + + } + } + + v = tdp.selectedCPrimitiveComponent(); + if ((v != null) && (v.size() > 0)) { + //TraceManager.addDev("Saving TML activity diagram Panel..."); + TMLCPrimitiveComponent ct; + TMLActivityDiagramPanel tmladp; + for(int i=0; i<v.size(); i++) { + ct = (TMLCPrimitiveComponent)(v.elementAt(i)); + tmladp = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), ct.getValue()); + s.append(tmladp.saveInXML()); + } + } + + if (s == null) { + return null; + } + sb.append(s); + sb.append("\n\n"); + sb.append("</TURTLEGSELECTEDCOMPONENTS>"); + + str = new String(sb); + str = encodeString(str); + + TraceManager.addDev("Copy done"); + //TraceManager.addDev(str); + + return str; + } + + public String makeOneDiagramXMLFromGraphicalModel(TURTLEPanel tp, int indexOfDiagram) { + StringBuffer sb = new StringBuffer(); + //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGMODELING version=\"" + DefaultText.getVersion() + "\">\n\n"); + + StringBuffer s; + String str; + + + s = tp.saveInXML(indexOfDiagram); + + sb.append(s); + sb.append("\n\n"); + + + sb.append("</TURTLEGMODELING>"); + + str = new String(sb); + str = encodeString(str); + + return str; + } + + public String makeXMLFromTurtleModeling(int index) { + StringBuffer sb = new StringBuffer(); + //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGMODELING version=\"" + DefaultText.getVersion() + "\">\n\n"); + + StringBuffer s; + String str; + + TURTLEPanel tp; + int i; + // search for diagram panels (Design) + for(i=0; i<panels.size(); i++) { + if ((index == -1) || (i == index)) { + tp = (TURTLEPanel)(panels.elementAt(i)); + s = tp.saveInXML(); + if (s == null) { + return null; + } + sb.append(s); + sb.append("\n\n"); + } + } + + sb.append("</TURTLEGMODELING>"); + + str = new String(sb); + str = encodeString(str); + + return str; + } + + public void removeAllComponents() { + TDiagramPanel tdp; + int i, j; + Vector panelss; + // search for diagram panels + for(i=0; i<panels.size(); i++) { + panelss = (Vector)(((TURTLEPanel)(panels.elementAt(i))).panels); + for(j=0; j<panelss.size(); j++) { + tdp = (TDiagramPanel)(panelss.elementAt(j)); + tdp.removeAll(); + } + } + } + + public void copyModelingFromXML(TDiagramPanel tdp, String s, int X, int Y) throws MalformedModelingException { + //TraceManager.addDev("copyModelingFromXML: " + s); + //TraceManager.addDev("tdp: " + tdp); + + //TraceManager.addDev(s); + //TraceManager.addDev("copyModelingFromXML:"); + //LinkedList ComponentsList=tdp.getComponentList(); + int beginIndex = tdp.getComponentList().size(); + + //Added by Solange + int cuenta=1; + + s = decodeString(s); + + //TraceManager.addDev("copy=" + s); + + ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); + if ((dbf == null) || (db == null)) { + throw new MalformedModelingException(); + } + + int i; + //int copyMaxId; + int _decX = 0, _decY = 0; + + try { + // building nodes from xml String + Document doc = db.parse(bais); + NodeList nl; + + decId = tdp.getMaxId() + 1; + TGComponent.setGeneralId(TGComponent.getGeneralId() + decId + 2); + nl = doc.getElementsByTagName("TURTLEGSELECTEDCOMPONENTS"); + + if (nl == null) { + return; + } + + Node adn; + Element elt; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + _decX = X - Integer.decode(elt.getAttribute("decX")).intValue(); + _decY = Y - Integer.decode(elt.getAttribute("decY")).intValue(); + //copyMaxId = Integer.decode(elt.getAttribute("copyMaxId")).intValue(); + } + } + + // Managing diagrams + if (tdp instanceof TClassDiagramPanel) { + TraceManager.addDev("TClassDiagramPanel copy"); + + nl = doc.getElementsByTagName("TClassDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + + TClassDiagramPanel tcdp = (TClassDiagramPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tcdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + tcdp.loadExtraParameters(elt); + + //TraceManager.addDev("Class diagram : " + tcdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tcdp); + makePostProcessing(tcdp); + //TraceManager.addDev("Class diagram : " + tcdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tcdp); + //TraceManager.addDev("Class diagram : " + tcdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tcdp); + //TraceManager.addDev("Class diagram : " + tcdp.getName() + " real points"); + connectConnectorsToRealPoints(tcdp); + tcdp.structureChanged(); + //TraceManager.addDev("Class diagram : " + tcdp.getName() + " post loading " + beginIndex); + makePostLoading(tcdp, beginIndex); + //TraceManager.addDev("Class diagram : " + tcdp.getName() + " post loading done"); + } + } + docCopy = null; + + } else if (tdp instanceof TActivityDiagramPanel) { + TraceManager.addDev("TActivityDiagramPanel copy"); + nl = doc.getElementsByTagName("TActivityDiagramPanelCopy"); + + if (nl == null) { + return; + } + + TActivityDiagramPanel tadp = (TActivityDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tadp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + tadp.loadExtraParameters(elt); + + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(tadp); + tadp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(tadp, beginIndex); + } + } + } else if (tdp instanceof InteractionOverviewDiagramPanel) { + + nl = doc.getElementsByTagName("InteractionOverviewDiagramPanelCopy"); + + if (nl == null) { + return; + } + + InteractionOverviewDiagramPanel iodp = (InteractionOverviewDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (iodp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), iodp); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), iodp); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), iodp); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " real points"); + connectConnectorsToRealPoints(iodp); + iodp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); + makePostLoading(iodp, beginIndex); + } + } + } else if (tdp instanceof SequenceDiagramPanel) { + //TraceManager.addDev("Sequence diagram!"); + nl = doc.getElementsByTagName("SequenceDiagramPanelCopy"); + + if (nl == null) { + return; + } + + SequenceDiagramPanel sdp = (SequenceDiagramPanel)tdp; + + //TraceManager.addDev("Sequence diagram!"); + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (sdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), sdp); + //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), sdp); + //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), sdp); + //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " real points"); + connectConnectorsToRealPoints(sdp); + sdp.structureChanged(); + //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " post loading"); + makePostLoading(sdp, beginIndex); + } + } + } else if (tdp instanceof UseCaseDiagramPanel) { + nl = doc.getElementsByTagName("UseCaseDiagramPanelCopy"); + + if (nl == null) { + return; + } + + UseCaseDiagramPanel ucdp = (UseCaseDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (ucdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ucdp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ucdp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ucdp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " real points"); + connectConnectorsToRealPoints(ucdp); + ucdp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); + makePostLoading(ucdp, beginIndex); + } + } + } else if (tdp instanceof TDeploymentDiagramPanel) { + nl = doc.getElementsByTagName("TDeploymentDiagramPanelCopy"); + + if (nl == null) { + return; + } + + TDeploymentDiagramPanel tddp = (TDeploymentDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tddp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tddp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tddp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tddp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " real points"); + connectConnectorsToRealPoints(tddp); + tddp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); + makePostLoading(tddp, beginIndex); + } + } + } else if (tdp instanceof NCDiagramPanel) { + nl = doc.getElementsByTagName("NCDiagramPanelCopy"); + + if (nl == null) { + return; + } + + NCDiagramPanel ncdp = (NCDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (ncdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ncdp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ncdp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ncdp); + //TraceManager.addDev("Activity diagram : " + sdp.getName() + " real points"); + connectConnectorsToRealPoints(ncdp); + ncdp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); + makePostLoading(ncdp, beginIndex); + } + } + } else if (tdp instanceof RequirementDiagramPanel) { + nl = doc.getElementsByTagName("TRequirementDiagramPanelCopy"); + + if (nl == null) { + return; + } + + RequirementDiagramPanel rdp = (RequirementDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (rdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), rdp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), rdp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), rdp); + connectConnectorsToRealPoints(rdp); + rdp.structureChanged(); + makePostLoading(rdp, beginIndex); + } + } + } else if (tdp instanceof EBRDDPanel) { + nl = doc.getElementsByTagName("EBRDDPanelCopy"); + + if (nl == null) { + return; + } + + EBRDDPanel ebrddp = (EBRDDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (ebrddp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ebrddp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ebrddp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ebrddp); + connectConnectorsToRealPoints(ebrddp); + ebrddp.structureChanged(); + makePostLoading(ebrddp, beginIndex); + } + } + } else if (tdp instanceof AttackTreeDiagramPanel) { + nl = doc.getElementsByTagName("AttackTreeDiagramPanelCopy"); + + if (nl == null) { + return; + } + + AttackTreeDiagramPanel atdp = (AttackTreeDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (atdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), atdp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), atdp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), atdp); + connectConnectorsToRealPoints(atdp); + atdp.structureChanged(); + makePostLoading(atdp, beginIndex); + } + } + } else if (tdp instanceof TMLTaskDiagramPanel) { + nl = doc.getElementsByTagName("TMLTaskDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + TMLTaskDiagramPanel tmltdp = (TMLTaskDiagramPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tmltdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + tmltdp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); - TMLForLoop loop = new TMLForLoop("infiniteloop",adLoop); - loop.setInit(""); - loop.setCondition(""); - loop.setIncrement(""); - loop.setInfinite(true); - start.addNext(loop); - act.addElement(loop); - //Add choice + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmltdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(tmltdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmltdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmltdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(tmltdp); + tmltdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(tmltdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + }else if (tdp instanceof DiplodocusMethodologyDiagramPanel) { + nl = doc.getElementsByTagName("DiplodocusMethodologyDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + DiplodocusMethodologyDiagramPanel tmltdp = (DiplodocusMethodologyDiagramPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; - TMLChoice choice = new TMLChoice("chooseChannel", adChoice); - act.addElement(choice); - loop.addNext(choice); - map.listE.addCor(choice,adChoice); + if (tmltdp == null) { + throw new MalformedModelingException(); + } + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + decX = _decX; + decY = _decY; + + tmltdp.loadExtraParameters(elt); + //TraceManager.addDev("Toto 2"); - for (TMLChannel chan: inChans.keySet()){ - TMLChannel newChan = inChans.get(chan); - TMLChannel wrChan = outChans.get(chan); - //Add channels into firewall activity diagram - TMLReadChannel rd = new TMLReadChannel(newChan.getName(), adRC); - rd.setNbOfSamples("1"); - rd.addChannel(newChan); - choice.addNext(rd); - choice.addGuard(""); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmltdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(tmltdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmltdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmltdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(tmltdp); + tmltdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(tmltdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } - act.addElement(rd); - //Execute for latency value + }else if (tdp instanceof AvatarMethodologyDiagramPanel) { + nl = doc.getElementsByTagName("AvatarMethodologyDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + AvatarMethodologyDiagramPanel amdp = (AvatarMethodologyDiagramPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (amdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + amdp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), amdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(amdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), amdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), amdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(amdp); + amdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(amdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + }else if (tdp instanceof SysmlsecMethodologyDiagramPanel) { + nl = doc.getElementsByTagName("SysmlsecMethodologyDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + SysmlsecMethodologyDiagramPanel amdp = (SysmlsecMethodologyDiagramPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (amdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + amdp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), amdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(amdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), amdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), amdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(amdp); + amdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(amdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + } else if (tdp instanceof TMLComponentTaskDiagramPanel) { + nl = doc.getElementsByTagName("TMLComponentTaskDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + TMLComponentTaskDiagramPanel tmlctdp = (TMLComponentTaskDiagramPanel)tdp; + //tmlctdp.updateReferences(); + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tmlctdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + tmlctdp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmlctdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(tmlctdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmlctdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmlctdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(tmlctdp); + tmlctdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(tmlctdp, beginIndex); + tmlctdp.hideConnectors(); + tmlctdp.updatePorts(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + tmlctdp.updatePorts(); + } else if (tdp instanceof TMLActivityDiagramPanel) { + nl = doc.getElementsByTagName("TMLActivityDiagramPanelCopy"); + + if (nl == null) { + return; + } + + TMLActivityDiagramPanel tmladp = (TMLActivityDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tmladp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //tmladp.loadExtraParameters(elt); + + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmladp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmladp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmladp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(tmladp); + tmladp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(tmladp, beginIndex); + } + } + } else if (tdp instanceof TMLCPPanel) { + nl = doc.getElementsByTagName("CommunicationPatternDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + TMLCPPanel tmlcpp = (TMLCPPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tmlcpp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //tmlcpp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmlcpp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(tmlcpp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmlcpp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmlcpp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(tmlcpp); + tmlcpp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(tmlcpp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + } else if (tdp instanceof TMLSDPanel) { + nl = doc.getElementsByTagName("TMLSDPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + TMLSDPanel tmlsdp = (TMLSDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tmlsdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //tmlcpp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmlsdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(tmlsdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmlsdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmlsdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(tmlsdp); + tmlsdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(tmlsdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + } else if (tdp instanceof TMLArchiDiagramPanel) { + nl = doc.getElementsByTagName("TMLArchiDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + TMLArchiDiagramPanel tmadp = (TMLArchiDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tmadp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + tmadp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmadp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(tmadp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmadp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmadp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(tmadp); + tmadp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(tmadp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + } else if (tdp instanceof TURTLEOSClassDiagramPanel) { + nl = doc.getElementsByTagName("TURTLEOSClassDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + TURTLEOSClassDiagramPanel toscdp = (TURTLEOSClassDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (toscdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //toscdp.loadExtraParameters(elt); + //TraceManager.addDev("Toto 2"); + //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), toscdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(toscdp); + //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), toscdp); + //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), toscdp); + //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " real points"); + connectConnectorsToRealPoints(toscdp); + toscdp.structureChanged(); + //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " post loading " + beginIndex); + makePostLoading(toscdp, beginIndex); + //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " post loading done"); + } + } + } else if (tdp instanceof TURTLEOSActivityDiagramPanel) { + nl = doc.getElementsByTagName("TURTLEOSActivityDiagramPanelCopy"); + + if (nl == null) { + return; + } + + TURTLEOSActivityDiagramPanel tosadp = (TURTLEOSActivityDiagramPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (tosadp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //tmladp.loadExtraParameters(elt); + + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tosadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tosadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tosadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(tosadp); + tosadp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(tosadp, beginIndex); + } + } + } else if (tdp instanceof ProactiveCSDPanel) { + //cuenta=beginIndex+1; + cuenta=mgui.tabs.size()-1; + nl = doc.getElementsByTagName("ProactiveCSDPanelCopy"); + if (nl.getLength()==0) + { + nl=doc.getElementsByTagName("ProactiveCSDPanel"); + } + docCopy = doc; + if (nl == null) + { + return; + } + ProactiveCSDPanel pcsdp = (ProactiveCSDPanel)tdp; + for(i=0; i<nl.getLength(); i++) + { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) + { + elt = (Element) adn; + if (pcsdp == null) + { + throw new MalformedModelingException(); + } + + + // int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //pcsdp.loadExtraParameters(elt); + //TraceManager.addDev("Toto 2"); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), pcsdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(pcsdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), pcsdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), pcsdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(pcsdp); + pcsdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(pcsdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + // Added by Solange + nl = doc.getElementsByTagName("ProactiveSMDPanel"); + if (nl == null) + { + return; + } + String name=""; + ProactiveSMDPanel psmdp; + for(i=0; i<nl.getLength(); i++) //Erased cuenta++ by Solange at the end condition of the for + { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) + { + elt = (Element) adn; + name=elt.getAttribute("name"); + //Added by Solange name at the beginning and cuenta + name=mgui.createProActiveSMD(cuenta,name); + psmdp=mgui.getSMDPanel(cuenta, name); + if (psmdp == null) + { + throw new MalformedModelingException(); + } + + // int xSel = Integer.decode(elt.getAttribute("minX")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("maxX")).intValue(); // - mgui.getCurrentTDiagramPanel().currentX; + // int widthSel = Integer.decode(elt.getAttribute("minY")).intValue(); // - mgui.getCurrentTDiagramPanel().currentY;; + // int heightSel = Integer.decode(elt.getAttribute("maxY")).intValue(); // - mgui.getCurrentTDiagramPanel().currentY;; + + decX = _decX; + decY = _decY; + + //tmladp.loadExtraParameters(elt); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), psmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), psmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), psmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(psmdp); + psmdp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(psmdp, beginIndex); + //until here + } + } + } else if (tdp instanceof ProactiveSMDPanel) { + //Changed by Solange, before it was like the first line + //nl = doc.getElementsByTagName("ProactiveSMDPanelCopy"); + nl = doc.getElementsByTagName("ProactiveSMDPanelCopy"); + + if (nl == null) { + return; + } + + ProactiveSMDPanel psmdp = (ProactiveSMDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (psmdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //tmladp.loadExtraParameters(elt); + + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), psmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), psmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), psmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(psmdp); + psmdp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(psmdp, beginIndex); + } + } + + // AVATAR + } else if (tdp instanceof AvatarBDPanel) { + nl = doc.getElementsByTagName("AVATARBlockDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + AvatarBDPanel abdp = (AvatarBDPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (abdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + abdp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), abdp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(abdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), abdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), abdp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(abdp); + abdp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(abdp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + + + } else if (tdp instanceof ADDDiagramPanel) { + nl = doc.getElementsByTagName("ADDDiagramPanelCopy"); + docCopy = doc; + + if (nl == null) { + return; + } + + //TraceManager.addDev("Toto 1"); + + + ADDDiagramPanel addp = (ADDDiagramPanel)tdp; + + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (addp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + addp.loadExtraParameters(elt); + + //TraceManager.addDev("Toto 2"); + + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), addp); + //TraceManager.addDev("Toto 3"); + makePostProcessing(addp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), addp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), addp); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); + connectConnectorsToRealPoints(addp); + addp.structureChanged(); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); + makePostLoading(addp, beginIndex); + //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); + } + } + + } else if (tdp instanceof AvatarSMDPanel) { + nl = doc.getElementsByTagName("AVATARStateMachineDiagramPanelCopy"); + + if (nl == null) { + return; + } + + AvatarSMDPanel asmdp = (AvatarSMDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (asmdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + //tmladp.loadExtraParameters(elt); + + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), asmdp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), asmdp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), asmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(asmdp); + asmdp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(asmdp, beginIndex); + } + } + } else if (tdp instanceof AvatarRDPanel) { + nl = doc.getElementsByTagName("AvatarRDPanelCopy"); + + if (nl == null) { + return; + } + + AvatarRDPanel ardp = (AvatarRDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (ardp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ardp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ardp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ardp); + connectConnectorsToRealPoints(ardp); + ardp.structureChanged(); + makePostLoading(ardp, beginIndex); + } + } + + } else if (tdp instanceof AvatarMADPanel) { + nl = doc.getElementsByTagName("AvatarMADPanelCopy"); + + if (nl == null) { + return; + } + + AvatarMADPanel amadp = (AvatarMADPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (amadp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), amadp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), amadp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), amadp); + connectConnectorsToRealPoints(amadp); + amadp.structureChanged(); + makePostLoading(amadp, beginIndex); + } + } + + } else if (tdp instanceof AvatarPDPanel) { + nl = doc.getElementsByTagName("AvatarPDPanelCopy"); + + if (nl == null) { + return; + } + + AvatarPDPanel apdp = (AvatarPDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (apdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), apdp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), apdp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), apdp); + connectConnectorsToRealPoints(apdp); + apdp.structureChanged(); + makePostLoading(apdp, beginIndex); + } + } + + } else if (tdp instanceof AvatarCDPanel) { + nl = doc.getElementsByTagName("AvatarCDPanelCopy"); + + if (nl == null) { + return; + } + + AvatarCDPanel acdp = (AvatarCDPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (acdp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), acdp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), acdp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), acdp); + connectConnectorsToRealPoints(acdp); + acdp.structureChanged(); + makePostLoading(acdp, beginIndex); + } + } + } else if (tdp instanceof AvatarADPanel) { + nl = doc.getElementsByTagName("AvatarADPanelCopy"); + + if (nl == null) { + return; + } + + AvatarADPanel aadp = (AvatarADPanel)tdp; + + for(i=0; i<nl.getLength(); i++) { + adn = nl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + + if (aadp == null) { + throw new MalformedModelingException(); + } + + //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); + //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); + //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); + //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); + + decX = _decX; + decY = _decY; + + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), aadp); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), aadp); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), aadp); + connectConnectorsToRealPoints(aadp); + aadp.structureChanged(); + makePostLoading(aadp, beginIndex); + } + } + } + + } catch (IOException e) { + TraceManager.addError("Loading 500: " + e.getMessage()); + throw new MalformedModelingException(); + } catch (SAXException saxe) { + TraceManager.addError("Loading 501 " + saxe.getMessage()); + throw new MalformedModelingException(); + } + } + + // Returns null if s is not a saved TURTLE modeling of an older format + public String upgradeSaved(String s) { + int index1, index2, index3; + StringBuffer sb = new StringBuffer("");; + //String tmp; + + index1 = s.indexOf("<TClassDiagramPanel"); + index2 = s.indexOf("<InteractionOverviewDiagramPanel "); + index3 = s.indexOf("</TURTLEGMODELING>"); + + if ((index1 <0) ||(index3 < 0)){ + return null; + } + + sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGMODELING version=\"" + DefaultText.getVersion() + "\">\n\n"); + + if (index2 > -1) { + sb.append("<Modeling type=\"Analysis\" nameTab=\"Analysis\" >\n"); + sb.append(s.substring(index2, index3)); + sb.append("</Modeling>\n\n"); + } + + if (index2 < 0) { + index2 = index3; + } + sb.append("<Modeling type=\"Design\" nameTab=\"Design\" >\n"); + sb.append(s.substring(index1, index2)); + sb.append("</Modeling>\n\n"); + + sb.append(s.substring(index3, s.length())); + + //TraceManager.addDev("Got:" + sb); + + return sb.toString(); + } + + public void loadModelingFromXML(String s) throws MalformedModelingException { + + if (s == null) { + return; + } + + s = decodeString(s); + + decX = 0; + decY = 0; + decId = 0; + TGComponent.setGeneralId(100000); + + ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); + + if ((dbf == null) || (db == null)) { + throw new MalformedModelingException(); + } + + try { + // building nodes from xml String + Document doc = db.parse(bais); + NodeList panelNl; + //NodeList designPanelNl; + //NodeList analysisNl; + + int i; + //Element elt; + Node node; + + // Managing design panels + panelNl = doc.getElementsByTagName("Modeling"); + + if (panelNl.getLength() == 0) { + // Modeling saved in old format? + s = upgradeSaved(s); + if (s != null) { + JOptionPane.showMessageDialog(mgui.frame, "The modeling has been converted to this new version of TTool", "Loading information", JOptionPane.INFORMATION_MESSAGE); + } + loadModelingFromXML(s); + return; + + } + //designPanelNl = doc.getElementsByTagName("Design"); + //analysisNl = doc.getElementsByTagName("Analysis"); + + pendingConnectors = new ArrayList<TGConnectorInfo>(); + + //TraceManager.addDev("nb de design=" + designPanelNl.getLength() + " nb d'analyse=" + analysisNl.getLength()); + boolean error = false; + for(i=0; i<panelNl.getLength(); i++) { + node = panelNl.item(i); + //TraceManager.addDev("Node = " + dnd); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + // create design, and get an index for it + try { + loadModeling(node); + } catch (MalformedModelingException mme) { + Element elt = (Element) node; + String type = elt.getAttribute("type"); + TraceManager.addDev("Error when loading diagram: " + elt + " " +type); + error = true; + } + } + } + if (error == true) { + throw new MalformedModelingException(); + } + + } catch (NumberFormatException nfe) { + TraceManager.addError("Loading 400 " + nfe.getMessage()); + throw new MalformedModelingException(); + } catch (IOException e) { + TraceManager.addError("Loading 600 " + e.getMessage()); + throw new MalformedModelingException(); + } catch (SAXException saxe) { + TraceManager.addError("Loading 601 " + saxe.getMessage()); + throw new MalformedModelingException(); + } + //TraceManager.addDev("making IDs"); + makeLastLoad(); + makeLovelyIds(); + //TraceManager.addDev("IDs done"); + } + + public void loadModeling(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String type = elt.getAttribute("type"); + // AVATAR + if (type.compareTo("ADD") == 0) { + loadAvatarDeployment(node); + } else if (type.compareTo("AVATAR Design") == 0) { + loadAvatarDesign(node); + } else if (type.compareTo("Avatar Requirement") == 0) { + loadAvatarRequirement(node); + } else if (type.compareTo("Avatar MAD") == 0) { + loadAvatarMADs(node); + } else if (type.compareTo("Avatar Analysis") == 0) { + loadAvatarAnalysis(node); + + + // TURTLE + } else if (type.compareTo("Design") == 0) { + loadDesign(node); + } else if (type.compareTo("Analysis") == 0) { + loadAnalysis(node); + } else if (type.compareTo("Deployment") == 0) { + loadDeployment(node); + } else if (type.compareTo("NC diagram") == 0) { + loadNC(node); + } else if (type.compareTo("Requirement") == 0) { + loadRequirement(node); + } else if (type.compareTo("AttackTree") == 0) { + loadAttackTree(node); + } else if (type.compareTo("Diplodocus Methodology") == 0) { + loadDiplodocusMethodology(node); + } else if (type.compareTo("Avatar Methodology") == 0) { + loadAvatarMethodology(node); + } else if (type.compareTo("Sysmlsec Methodology") == 0) { + loadSysmlsecMethodology(node); + } else if (type.compareTo("TML Design") == 0) { + loadTMLDesign(node); + } else if (type.compareTo("TML Component Design") == 0) { + loadTMLComponentDesign(node); + } else if (type.compareTo("TML CP") == 0) { + loadTMLCP(node); + } else if (type.compareTo("TML Architecture") == 0) { + loadTMLArchitecture(node); + } else if (type.compareTo("TURTLE-OS Design") == 0) { + loadTURTLEOSDesign(node); + } else if (type.compareTo("ProActive Design") == 0) { + loadProActiveDesign(node); + } else { + throw new MalformedModelingException(); + } + } + + public void loadAvatarDesign(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createAvatarDesign(nameTab); + + diagramNl = node.getChildNodes(); + + /* First load all Block diagrams, then all state machines + * This is done this way so that state machines can rely on + * informations provided by blocks. For instance we can check + * that an attribute used in a state machine really exists. + */ + for(int j=0; j<diagramNl.getLength(); j++) { + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) node; + if (elt.getTagName().compareTo("AVATARBlockDiagramPanel") == 0) + // Class diagram + loadAvatarBD(elt, indexDesign); + } + } + for(int j=0; j<diagramNl.getLength(); j++) { + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) node; + if (elt.getTagName().compareTo("AVATARStateMachineDiagramPanel") == 0) + // Managing activity diagrams + loadAvatarSMD(elt, indexDesign); + } + } + } + + public void loadAvatarDeployment(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexReq; + int cpt_req = 0; + + TraceManager.addDev("Loading ADD 0"); + + nameTab = elt.getAttribute("nameTab"); + + indexReq = mgui.createADD(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Deployment nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("ADDDiagramPanel") == 0) { + TraceManager.addDev("Loading ADD 1"); + loadADDDiagram(elt, indexReq, cpt_req); + cpt_req ++; + } + } + } + } + + public void loadAvatarRequirement(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexReq; + int cpt_req = 0; + + + nameTab = elt.getAttribute("nameTab"); + + indexReq = mgui.createAvatarRequirement(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Deployment nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("AvatarRDPanel") == 0) { + loadAvatarRD(elt, indexReq, cpt_req); + cpt_req ++; + } else if (elt.getTagName().compareTo("AvatarPDPanel") == 0) { + loadAvatarPD(elt, indexReq, cpt_req); + cpt_req ++; + } + } + } + } + + public void loadAttackTree(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexTree; + int cpttdp = 0; + + + nameTab = elt.getAttribute("nameTab"); + + indexTree = mgui.createAttackTree(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Deployment nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("AttackTreeDiagramPanel") == 0) { + loadAttackTreeDiagram(elt, indexTree, cpttdp); + cpttdp ++; + } + } + } + } + + public void loadAvatarMADs(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexReq; + int cpt_req = 0; + + + nameTab = elt.getAttribute("nameTab"); + + TraceManager.addDev("Creating MAD panel "); + + indexReq = mgui.createAvatarMADs(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + TraceManager.addDev("MADs nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("AvatarMADPanel") == 0) { + loadAvatarMAD(elt, indexReq, cpt_req); + cpt_req ++; + } + } + } + } + + public void loadDesign(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createDesign(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TClassDiagramPanel") == 0) { + // Class diagram + loadTClassDiagram(elt, indexDesign); + } else { // Managing activity diagrams + if (elt.getTagName().compareTo("TActivityDiagramPanel") == 0) { + // Managing activity diagrams + loadTActivityDiagram(elt, indexDesign); + } + } + } + } + } + + public void loadAnalysis(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexAnalysis; + int cpt = 0; + + nameTab = elt.getAttribute("nameTab"); + + indexAnalysis = mgui.createAnalysis(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("InteractionOverviewDiagramPanel") == 0) { + // IOD + loadIODiagram(elt, indexAnalysis); + cpt ++; + } else { // Managing sequence diagrams + if (elt.getTagName().compareTo("SequenceDiagramPanel") == 0) { + loadSequenceDiagram(elt, indexAnalysis); + cpt ++; + } else if (elt.getTagName().compareTo("UseCaseDiagramPanel") == 0) { + // Managing use case diagrams + loadUseCaseDiagram(elt, indexAnalysis, cpt); + cpt ++; + } /*else if (elt.getTagName().compareTo("AvatarCDPanel") == 0) { + // Managing use case diagrams + loadAvatarCD(elt, indexAnalysis, cpt); + cpt ++; + } else if (elt.getTagName().compareTo("AvatarADPanel") == 0) { + // Managing use case diagrams + loadAvatarAD(elt, indexAnalysis, cpt); + cpt ++; + }*/ + } + } + } + } + + public void loadTMLCP(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexTMLCP; + int cpt = 0; + + nameTab = elt.getAttribute("nameTab"); + + indexTMLCP = mgui.createTMLCP(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("CommunicationPatternDiagramPanel") == 0) { + // CP + loadTMLCPDiagram(elt, indexTMLCP); + cpt ++; + } else { // Managing sequence diagrams + if (elt.getTagName().compareTo("TMLSDPanel") == 0) { + loadTMLSDDiagram(elt, indexTMLCP); + cpt ++; + } + } + } + } + } + + public void loadAvatarAnalysis(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexAnalysis; + int cpt = 0; + + //TraceManager.addDev("Loading Avatar analysis"); + + nameTab = elt.getAttribute("nameTab"); + + indexAnalysis = mgui.createAvatarAnalysis(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + + if (elt.getTagName().compareTo("SequenceDiagramPanel") == 0) { + //TraceManager.addDev("Loading seq diag"); + loadSequenceDiagram(elt, indexAnalysis); + //TraceManager.addDev("Loading seq diag done"); + cpt ++; + } else if (elt.getTagName().compareTo("UseCaseDiagramPanel") == 0) { + // Managing use case diagrams + //TraceManager.addDev("Loading ucd diag"); + loadUseCaseDiagram(elt, indexAnalysis, cpt); + //TraceManager.addDev("Loading ucd diag done"); + + cpt ++; + } else if (elt.getTagName().compareTo("AvatarCDPanel") == 0) { + // Managing use case diagrams + //TraceManager.addDev("Loading cd diag"); + loadAvatarCD(elt, indexAnalysis, cpt); + //TraceManager.addDev("Loading cd diag done"); + cpt ++; + } else if (elt.getTagName().compareTo("AvatarADPanel") == 0) { + // Managing use case diagrams + //TraceManager.addDev("Loading ad diag"); + loadAvatarAD(elt, indexAnalysis, cpt); + //TraceManager.addDev("Loading ad diag done"); + cpt ++; + } + + } + } + } + + public void loadDeployment(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexAnalysis; + + + nameTab = elt.getAttribute("nameTab"); + + indexAnalysis = mgui.createDeployment(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Deployment nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TDeploymentDiagramPanel") == 0) { + // IOD + loadTDeploymentDiagram(elt, indexAnalysis); + } + } + } + } + + public void loadNC(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexAnalysis; + + + nameTab = elt.getAttribute("nameTab"); + + indexAnalysis = mgui.createNC(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Deployment nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("NCDiagramPanel") == 0) { + // IOD + loadNCDiagram(elt, indexAnalysis); + } + } + } + } + + public void loadRequirement(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexReq; + int cpt_req = 0; + + + nameTab = elt.getAttribute("nameTab"); + + indexReq = mgui.createRequirement(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Deployment nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TRequirementDiagramPanel") == 0) { + loadRequirementDiagram(elt, indexReq, cpt_req); + cpt_req ++; + } else if (elt.getTagName().compareTo("EBRDDPanel") == 0) { + loadEBRDD(elt, indexReq, cpt_req); + cpt_req ++; + } + } + } + } + + + + public void loadDiplodocusMethodology(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createDiplodocusMethodology(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("DiplodocusMethodologyDiagramPanel") == 0) { + // Class diagram + //TraceManager.addDev("Loading TML CD"); + loadDiplodocusMethodologyDiagram(elt, indexDesign); + //TraceManager.addDev("End loading TML CD"); + } + } + } + } + + public void loadAvatarMethodology(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createAvatarMethodology(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("AvatarMethodologyDiagramPanel") == 0) { + // Class diagram + TraceManager.addDev("Loading Avatar methodo"); + loadAvatarMethodologyDiagram(elt, indexDesign); + TraceManager.addDev("End Loading avatar methodo"); + } + } + } + } + + public void loadSysmlsecMethodology(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createSysmlsecMethodology(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("SysmlsecMethodologyDiagramPanel") == 0) { + // Class diagram + TraceManager.addDev("Loading SysMLSec methodo"); + loadSysmlsecMethodologyDiagram(elt, indexDesign); + TraceManager.addDev("End loading SysMLSec methodo"); + } + } + } + } + + public void loadTMLDesign(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createTMLDesign(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TMLTaskDiagramPanel") == 0) { + // Class diagram + //TraceManager.addDev("Loading TML CD"); + loadTMLTaskDiagram(elt, indexDesign); + //TraceManager.addDev("End loading TML CD"); + } else { // Managing activity diagrams + if (elt.getTagName().compareTo("TMLActivityDiagramPanel") == 0) { + // Managing activity diagrams + //TraceManager.addDev("Loading TML AD"); + loadTMLActivityDiagram(elt, indexDesign); + } + } + } + } + } + + public void loadTMLComponentDesign(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createTMLComponentDesign(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TMLComponentTaskDiagramPanel") == 0) { + // Component diagram + //TraceManager.addDev("Loading TML Component diagram"); + loadTMLComponentTaskDiagram(elt, indexDesign); + //TraceManager.addDev("End loading TML CD"); + } else { // Managing activity diagrams + if (elt.getTagName().compareTo("TMLActivityDiagramPanel") == 0) { + // Managing activity diagrams + //TraceManager.addDev("Loading TML AD"); + loadTMLActivityDiagram(elt, indexDesign); + } + } + } + } + } + + public void loadTMLArchitecture(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createTMLArchitecture(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + TraceManager.addDev("TML Architecture nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TMLArchiDiagramPanel") == 0) { + TraceManager.addDev("Loading TML DD" + elt.getTagName() ); + loadTMLArchitectureDiagram(elt, indexDesign); + TraceManager.addDev("End loading TML DD"); + } + } + } + } + + public void loadTURTLEOSDesign(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createTURTLEOSDesign(nameTab); + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("TURTLEOSClassDiagramPanel") == 0) { + // Class diagram + //TraceManager.addDev("Loading TURTLEOS CD"); + loadTURTLEOSClassDiagram(elt, indexDesign); + //TraceManager.addDev("End loading TML CD"); + } else { // Managing activity diagrams + if (elt.getTagName().compareTo("TURTLEOSActivityDiagramPanel") == 0) { + // Managing activity diagrams + //TraceManager.addDev("Loading TURTLEOS AD"); + loadTURTLEOSActivityDiagram(elt, indexDesign); + } + } + } + } + } + + public void loadProActiveDesign(Node node) throws MalformedModelingException, SAXException { + Element elt = (Element) node; + String nameTab; + NodeList diagramNl; + int indexDesign; + + + nameTab = elt.getAttribute("nameTab"); + + indexDesign = mgui.createProActiveDesign(nameTab); + + + diagramNl = node.getChildNodes(); + + for(int j=0; j<diagramNl.getLength(); j++) { + //TraceManager.addDev("Design nodes: " + j); + node = diagramNl.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + if (elt.getTagName().compareTo("ProactiveCSDPanel") == 0) { + // Class diagram + //TraceManager.addDev("Loading TML CD"); + loadProactiveCSD(elt, indexDesign); + //TraceManager.addDev("End loading TML CD"); + } else { // Managing activity diagrams + if (elt.getTagName().compareTo("ProactiveSMDPanel") == 0) { + // Managing activity diagrams + //TraceManager.addDev("Loading TML AD"); + loadProactiveSMD(elt, indexDesign); + } + } + } + } + } + + public void loadDiagram(Element elt, TDiagramPanel tdp) throws MalformedModelingException, SAXException { + int x, y; + double zoom = 0; + try { + x = Integer.decode(elt.getAttribute("minX")).intValue(); + tdp.setMinX(x); + x = Integer.decode(elt.getAttribute("maxX")).intValue(); + tdp.setMaxX(x); + y = Integer.decode(elt.getAttribute("minY")).intValue(); + tdp.setMinY(y); + y = Integer.decode(elt.getAttribute("maxY")).intValue(); + tdp.setMaxY(y); + tdp.updateSize(); + zoom = Double.parseDouble(elt.getAttribute("zoom")); + if (zoom != 0) { + tdp.setZoom(zoom); + mgui.updateZoomInfo(); + } + } catch (Exception e) { + // Model was saved in an older version of TTool + } + + // for TClassdiagram Panel + if (tdp instanceof TClassDiagramPanel) { + ((TClassDiagramPanel)tdp).loadExtraParameters(elt); + } + + if (tdp instanceof TActivityDiagramPanel) { + ((TActivityDiagramPanel)tdp).loadExtraParameters(elt); + } + + if (tdp instanceof TMLTaskDiagramPanel) { + ((TMLTaskDiagramPanel)tdp).loadExtraParameters(elt); + } + + if (tdp instanceof TMLComponentTaskDiagramPanel) { + ((TMLComponentTaskDiagramPanel)tdp).loadExtraParameters(elt); + } + + if (tdp instanceof TMLArchiDiagramPanel) { + ((TMLArchiDiagramPanel)tdp).loadExtraParameters(elt); + } + + + if (tdp instanceof AvatarBDPanel) { + ((AvatarBDPanel)tdp).loadExtraParameters(elt); + } + + //TraceManager.addDev("Element" + elt.toString()); + // Loads components of the class diagram + //TraceManager.addDev("Components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tdp); + //TraceManager.addDev("Post processing"); + makePostProcessing(tdp); + //TraceManager.addDev("Connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tdp); + //TraceManager.addDev("Subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tdp); + //TraceManager.addDev("RealPoints"); + connectConnectorsToRealPoints(tdp); + //TraceManager.addDev("Structure changed"); + tdp.structureChanged(); + //TraceManager.addDev("Post loading"); + makePostLoading(tdp, 0); + + //TraceManager.addDev("Test connectors"); + if (tdp instanceof TMLComponentTaskDiagramPanel) { + //TraceManager.addDev("Connectors..."); + ((TMLComponentTaskDiagramPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof EBRDDPanel) { + //TraceManager.addDev("Connectors..."); + ((EBRDDPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof AttackTreeDiagramPanel) { + //TraceManager.addDev("Connectors..."); + ((AttackTreeDiagramPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof AvatarBDPanel) { + //TraceManager.addDev("Connectors..."); + ((AvatarBDPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof AvatarSMDPanel) { + //TraceManager.addDev("Connectors..."); + ((AvatarSMDPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof AvatarPDPanel) { + //TraceManager.addDev("Connectors..."); + ((AvatarPDPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof AvatarCDPanel) { + //TraceManager.addDev("Connectors..."); + ((AvatarCDPanel)tdp).setConnectorsToFront(); + } + + if (tdp instanceof AvatarADPanel) { + //TraceManager.addDev("Connectors..."); + ((AvatarADPanel)tdp).setConnectorsToFront(); + } + } + + // AVATAR + public void loadAvatarBD(Element elt, int indexDesign) throws MalformedModelingException, SAXException { + + String name; + TDiagramPanel tdp; + + // class diagram name + name = elt.getAttribute("name"); + mgui.setAvatarBDName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); - TMLExecI ex = new TMLExecI("execi", exec); - ex.setAction(Integer.toString(firewallNode.latency)); - act.addElement(ex); - rd.addNext(ex); + loadDiagram(elt, tdp); + } - if (channelAllowed(map,chan)){ + public void loadAvatarSMD(Element elt, int indexDesign) throws MalformedModelingException, SAXException { + String name; - TMLWriteChannel wr = new TMLWriteChannel(wrChan.getName(), adWC); - wr.setNbOfSamples("1"); - wr.addChannel(wrChan); - ex.addNext(wr); - act.addElement(wr); + name = elt.getAttribute("name"); + //TraceManager.addDev("Loading SMD of:" + name); + AvatarSMDPanel asmdp = mgui.getAvatarSMDPanel(indexDesign, name); - TMLStopState stop = new TMLStopState("stop", adStop); - wr.addNext(stop); - act.addElement(stop); + if (asmdp == null) { + throw new MalformedModelingException(); + } - } - else { - TMLStopState stop = new TMLStopState("stop", adStop); - ex.addNext(stop); - act.addElement(stop); - } - for (TMLTask t:tmlm.getTasks()){ - TMLActivity actd = t.getActivityDiagram(); - actd.replaceWriteChannelWith(chan,newChan); - actd.replaceReadChannelWith(chan, outChans.get(chan)); - } - } + asmdp.removeAll(); - } + mgui.selectDummyTab (indexDesign); + loadDiagram(elt, asmdp); + mgui.forgetDummyTab (); + } - } - //Redo all reference objects + public void loadAvatarRD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - map.listE.useDIPLOIDs(); - return map; - } + name = elt.getAttribute("name"); + mgui.createAvatarRD(indexAnalysis, name); - public void addHSM(MainGUI gui, String taskName){ - - } - public TMLMapping autoSecure(MainGUI gui, boolean autoConf, boolean autoAuth){ - //TODO add more options - // - if (tmap==null){ - return null; - } - int arch = gui.tabs.indexOf(tmap.tmlap); - gui.cloneRenameTab(arch,"enc"); - TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); - return autoSecure(gui, "enc", tmap,newarch,autoConf,autoAuth); - } - public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch){ - return autoSecure(gui,name,map,newarch,"100","0","100",true,false); - } - public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, boolean autoConf, boolean autoAuth){ - return autoSecure(gui,name,map,newarch,"100","0","100",autoConf,autoAuth); - } + TDiagramPanel tdp = mgui.getAvatarRDPanel(indexAnalysis, indexTab, name); - public TMLMapping autoSecure(MainGUI gui, String encComp, String overhead, String decComp){ - if (tmap==null){ - return null; - } - int arch = gui.tabs.indexOf(tmap.tmlap); - gui.cloneRenameTab(arch,"enc"); - TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); - return autoSecure(gui,"enc", tmap,newarch,encComp, overhead,decComp,true,false); - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - public TMLMapping autoSecure(MainGUI gui, String encComp, String overhead, String decComp, boolean autoConf, boolean autoAuth){ - if (tmap==null){ - return null; - } - int arch = gui.tabs.indexOf(tmap.tmlap); - gui.cloneRenameTab(arch,"enc"); - TMLArchiPanel newarch = (TMLArchiPanel) gui.tabs.get(gui.tabs.size()-1); - return autoSecure(gui,"enc", tmap,newarch,encComp, overhead,decComp,autoConf,autoAuth); - } - public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, String encComp, String overhead, String decComp){ - return autoSecure(gui,name, tmap,newarch,encComp, overhead,decComp,true,false); - } + loadDiagram(elt, tdp); + } + public void loadAvatarMAD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - public TMLMapping autoSecure(MainGUI gui, String name, TMLMapping map, TMLArchiPanel newarch, String encComp, String overhead, String decComp, boolean autoConf, boolean autoAuth){ - HashMap<TMLTask, java.util.List<TMLTask>> toSecure = new HashMap<TMLTask, java.util.List<TMLTask>>(); - HashMap<TMLTask, java.util.List<TMLTask>> toSecureRev = new HashMap<TMLTask, java.util.List<TMLTask>>(); - HashMap<TMLTask, java.util.List<String>> secOutChannels = new HashMap<TMLTask, java.util.List<String>>(); - HashMap<TMLTask, java.util.List<String>> secInChannels = new HashMap<TMLTask, java.util.List<String>>(); - HashMap<TMLTask, java.util.List<String>> nonceOutChannels = new HashMap<TMLTask, java.util.List<String>>(); - HashMap<TMLTask, java.util.List<String>> nonceInChannels = new HashMap<TMLTask, java.util.List<String>>(); - HashMap<TMLTask, java.util.List<String>> macOutChannels = new HashMap<TMLTask, java.util.List<String>>(); - HashMap<TMLTask, java.util.List<String>> macInChannels = new HashMap<TMLTask, java.util.List<String>>(); - - ArrayList<String> nonAuthChans = new ArrayList<String>(); - ArrayList<String> nonSecChans = new ArrayList<String>(); - - if (map==null){ - return null; - } - //Perform ProVerif Analysis - TML2Avatar t2a = new TML2Avatar(tmap,false,true); - AvatarSpecification avatarspec = t2a.generateAvatarSpec("1"); - - if (avatarspec == null){ - return null; - } - - avatar2proverif = new AVATAR2ProVerif(avatarspec); - try { - proverif = avatar2proverif.generateProVerif(true, true, 1, true); - warnings = avatar2proverif.getWarnings(); - - if (!avatar2proverif.saveInFile("pvspec")){ - return null; - } - - RshClient rshc = new RshClient(ConfigurationTTool.ProVerifVerifierHost); - - rshc.setCmd(ConfigurationTTool.ProVerifVerifierPath + " -in pitype pvspec"); - rshc.sendProcessRequest(); - String data = rshc.getDataFromProcess(); - - ProVerifOutputAnalyzer pvoa = getProVerifOutputAnalyzer (); - pvoa.analyzeOutput(data, true); - for (String nonConf: pvoa.getNonSecretStrings()){ - nonSecChans.add(nonConf); - System.out.println(nonConf + " is not secret"); - } - for (String nonAuth: pvoa.getNonSatisfiedAuthenticity()) { - String chanName= nonAuth.split("_chData")[0]; - nonAuthChans.add(chanName); - System.out.println(nonAuth); - } - System.out.println("all results displayed"); - - } - catch (Exception e){ - System.out.println("ProVerif Analysis Failed"); - } - TMLModeling tmlmodel = map.getTMLModeling(); - java.util.List<TMLChannel> channels = tmlmodel.getChannels(); - for (TMLChannel channel: channels){ - for (TMLCPrimitivePort p: channel.ports){ - channel.checkConf = channel.checkConf || p.checkConf; - channel.checkAuth = channel.checkAuth || p.checkAuth; - } - } - - //Create clone of Component Diagram + Activity diagrams to secure - - TMLComponentDesignPanel tmlcdp = map.getTMLCDesignPanel(); - int ind = gui.tabs.indexOf(tmlcdp); - String tabName = gui.getTitleAt(tmlcdp); - gui.cloneRenameTab(ind, name); - TMLComponentDesignPanel t = (TMLComponentDesignPanel) gui.tabs.get(gui.tabs.size()-1); - map.setTMLDesignPanel(t); - TMLComponentTaskDiagramPanel tcdp = t.tmlctdp; - //Create clone of architecture panel and map tasks to it - newarch.renameMapping(tabName, tabName+"_"+name); - - for (TMLTask task: map.getTMLModeling().getTasks()){ - java.util.List<String> tmp = new ArrayList<String>(); - java.util.List<String> tmp2 = new ArrayList<String>(); - java.util.List<TMLTask> tmp3 = new ArrayList<TMLTask>(); - java.util.List<TMLTask> tmp4 = new ArrayList<TMLTask>(); - java.util.List<String> tmp5 = new ArrayList<String>(); - java.util.List<String> tmp6 = new ArrayList<String>(); - java.util.List<String> tmp7 = new ArrayList<String>(); - java.util.List<String> tmp8 = new ArrayList<String>(); - secInChannels.put(task, tmp); - secOutChannels.put(task, tmp2); - toSecure.put(task,tmp3); - toSecureRev.put(task,tmp4); - nonceInChannels.put(task,tmp5); - nonceOutChannels.put(task,tmp6); - macInChannels.put(task,tmp7); - macOutChannels.put(task,tmp8); - } - //With the proverif results, check which channels need to be secured - for (TMLTask task: map.getTMLModeling().getTasks()){ - //Check if all channel operators are secured - TMLActivityDiagramPanel tad = t.getTMLActivityDiagramPanel(task.getName()); - for (TGComponent tg:tad.getComponentList()){ - if (tg instanceof TMLADWriteChannel){ - TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; - if (writeChannel.securityContext.equals("")){ - - TMLChannel chan = tmlmodel.getChannelByName(tabName+"__"+writeChannel.getChannelName()); - //System.out.println("channel " + chan); - if (chan!=null){ - if (chan.checkConf){ - // System.out.println(chan.getOriginTask().getName().split("__")[1]); - if (nonSecChans.contains(chan.getOriginTask().getName().split("__")[1]+"__"+writeChannel.getChannelName()+"_chData")){ - // if (!securePath(map, chan.getOriginTask(), chan.getDestinationTask())){ - secOutChannels.get(chan.getOriginTask()).add(writeChannel.getChannelName()); - secInChannels.get(chan.getDestinationTask()).add(writeChannel.getChannelName()); - toSecure.get(chan.getOriginTask()).add(chan.getDestinationTask()); - if (chan.checkAuth && autoAuth){ - toSecureRev.get(chan.getDestinationTask()).add(chan.getOriginTask()); - nonceOutChannels.get(chan.getOriginTask()).add(writeChannel.getChannelName()); - nonceInChannels.get(chan.getDestinationTask()).add(writeChannel.getChannelName()); - } - } - } - else if (chan.checkAuth && autoAuth){ - if (nonAuthChans.contains(chan.getDestinationTask().getName().split("__")[1]+"__"+writeChannel.getChannelName())){ - toSecure.get(chan.getOriginTask()).add(chan.getDestinationTask()); - macOutChannels.get(chan.getOriginTask()).add(writeChannel.getChannelName()); - macInChannels.get(chan.getDestinationTask()).add(writeChannel.getChannelName()); - } - } - } - } - } - } - } - System.out.println("macoutchans "+ macOutChannels); - System.out.println("macinchans " +macInChannels); - System.out.println("nonsecin " +secInChannels); - System.out.println("nonsecout " +secOutChannels); - System.out.println("noncein " +nonceInChannels); - System.out.println("nonceout " +nonceOutChannels); - - // System.out.println(secOutChanannels.toString()); - int num=0; - int nonceNum=0; - //Create reverse channels to send nonces if they don't already exist - // if (autoAuth){ - for (TMLTask task: toSecureRev.keySet()){ - TraceManager.addDev("Adding nonces to " + task.getName()); - LinkedList<TMLChannel> chans = tmlmodel.getChannelsFromMe(task); - for (TMLTask task2: toSecureRev.get(task)){ - boolean addChan = true; - for (TMLChannel chan:chans){ - if (chan.getDestinationTask()==task2){ - addChan=false; - } - } - if (addChan){ - TMLCChannelOutPort originPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); - TMLCChannelOutPort destPort = new TMLCChannelOutPort(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp); - for (TGComponent tg: tcdp.getComponentList()){ - if (tg instanceof TMLCPrimitiveComponent){ - if (tg.getValue().equals(task.getName().split("__")[1])){ - originPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); - originPort.commName="nonceCh"+task.getName().split("__")[1] + "_"+task2.getName().split("__")[1]; - tcdp.addComponent(originPort,tg.getX(), tg.getY(),true,true); - } - else if (tg.getValue().equals(task2.getName().split("__")[1])){ - destPort = new TMLCChannelOutPort(tg.getX(), tg.getY(), tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, tg, tcdp); - destPort.isOrigin=false; - destPort.commName="nonceCh"+task.getName().split("__")[1] + "_"+ task2.getName().split("__")[1]; - tcdp.addComponent(destPort,tg.getX(), tg.getY(),true,true); - } - } - } - tmlmodel.addChannel(new TMLChannel("nonceCh"+task.getName().split("__")[1] + "_"+ task2.getName().split("__")[1], originPort)); - //Add connection - TMLCPortConnector conn = new TMLCPortConnector(0, 0, tcdp.getMinX(), tcdp.getMaxX(), tcdp.getMinY(), tcdp.getMaxX(), true, null, tcdp, originPort.getTGConnectingPointAtIndex(0), destPort.getTGConnectingPointAtIndex(0), new Vector()); - tcdp.addComponent(conn, 0,0,false,true); - } - } - } - // } - //Add encryption/nonces to activity diagram - for (TMLTask task:toSecure.keySet()){ - String title = task.getName().split("__")[0]; - TraceManager.addDev("Securing task " + task.getName()); - TMLActivityDiagramPanel tad = t.getTMLActivityDiagramPanel(task.getName()); - //Get start state position, shift everything down - int xpos=0; - int ypos=0; - TGConnector fromStart= new TGConnectorTMLAD(0, 0, 0, 0, 0, 0, false, null, tad, null, null, new Vector()); - TGConnectingPoint point = new TGConnectingPoint(null, 0, 0, false, false); - //Find states immediately before the write channel operator - - //For each occurence of a write channel operator, add encryption/nonces before it - for (String channel: secOutChannels.get(task)){ - int yShift=50; - TMLChannel tmlc = tmlmodel.getChannelByName(title +"__"+channel); - //First, find the connector that points to it. We will add the encryption, nonce operators directly before the write channel operator - for (TGComponent tg: tad.getComponentList()){ - if (tg instanceof TMLADWriteChannel){ - TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; - if (writeChannel.getChannelName().equals(channel) && writeChannel.securityContext.equals("")){ - xpos = tg.getX(); - ypos = tg.getY(); - fromStart = tad.findTGConnectorEndingAt(tg.getTGConnectingPointAtIndex(0)); - if (fromStart!=null){ - point = fromStart.getTGConnectingPointP2(); - } - break; - } - } - } - //Add encryption operator - TMLADEncrypt enc = new TMLADEncrypt(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - TMLADReadChannel rd=new TMLADReadChannel(0, 0, 0, 0, 0, 0, false, null, tad); - if (nonceOutChannels.get(task).contains(channel)){ - //Receive any nonces if ensuring authenticity - rd = new TMLADReadChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - ArrayList<TMLChannel> matches = tmlmodel.getChannels(tmlc.getDestinationTask(), tmlc.getOriginTask()); - - if (matches.size()>0){ - rd.setChannelName(matches.get(0).getName().replaceAll(title+"__","")); - } - else { - rd.setChannelName("nonceCh"+tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]); - } - rd.securityContext = "nonce_"+ tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; - tad.addComponent(rd, xpos, ypos+yShift, false,true); - fromStart.setP2(rd.getTGConnectingPointAtIndex(0)); - fromStart=new TGConnectorTMLAD(enc.getX(), enc.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, null, null, new Vector()); - tad.addComponent(fromStart, xpos, ypos, false, true); - fromStart.setP1(rd.getTGConnectingPointAtIndex(1)); - yShift+=60; - //Move encryption operator after receive nonce component - enc.setCd(xpos, ypos+yShift); - if (tmlc!=null){ - enc.nonce= "nonce_"+ tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; - } - } - - enc.securityContext = "autoEncrypt_"+channel; - enc.type = "Symmetric Encryption"; - enc.message_overhead = overhead; - enc.encTime= encComp; - enc.decTime=decComp; - tad.addComponent(enc, xpos ,ypos+yShift, false, true); - yShift+=60; - fromStart.setP2(enc.getTGConnectingPointAtIndex(0)); - fromStart=new TGConnectorTMLAD(enc.getX(), enc.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, null, null, new Vector()); - tad.addComponent(fromStart, xpos, ypos, false, true); - fromStart.setP1(enc.getTGConnectingPointAtIndex(1)); - - //Direct the last TGConnector back to the start of the write channel operator - - fromStart.setP2(point); - //Shift components down to make room for the added ones, and add security contexts to write channels - for (TGComponent tg:tad.getComponentList()){ - if (tg instanceof TMLADWriteChannel){ - TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; - TraceManager.addDev("Inspecting write channel " + writeChannel.getChannelName()); - if (channel.equals(writeChannel.getChannelName()) && writeChannel.securityContext.equals("")){ - TraceManager.addDev("Securing write channel " + writeChannel.getChannelName()); - writeChannel.securityContext = "autoEncrypt_"+writeChannel.getChannelName(); - tad.repaint(); - } - } - if (tg.getY() >= ypos && tg !=enc && tg!=rd){ - tg.setCd(tg.getX(), tg.getY()+yShift); - } - } - tad.setMaxPanelSize(tad.getMaxX(), tad.getMaxY()+yShift); - } - - for (String channel: macOutChannels.get(task)){ - //Add MAC before writechannel - int yShift=50; - //TMLChannel tmlc = tmlmodel.getChannelByName(title +"__"+channel); - //First, find the connector that points to it. We will add the encryption, nonce operators directly before the write channel operator - for (TGComponent tg: tad.getComponentList()){ - if (tg instanceof TMLADWriteChannel){ - TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; - if (writeChannel.getChannelName().equals(channel) && writeChannel.securityContext.equals("")){ - xpos = tg.getX(); - ypos = tg.getY(); - fromStart = tad.findTGConnectorEndingAt(tg.getTGConnectingPointAtIndex(0)); - if (fromStart!=null){ - point = fromStart.getTGConnectingPointP2(); - } - break; - } - } - } - //Add encryption operator - TMLADEncrypt enc = new TMLADEncrypt(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - enc.securityContext = "autoEncrypt_"+channel; - enc.type = "MAC"; - enc.message_overhead = overhead; - enc.encTime= encComp; - enc.decTime=decComp; - enc.size=overhead; - tad.addComponent(enc, xpos ,ypos+yShift, false, true); - yShift+=60; - fromStart.setP2(enc.getTGConnectingPointAtIndex(0)); - fromStart=new TGConnectorTMLAD(enc.getX(), enc.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, null, null, new Vector()); - tad.addComponent(fromStart, xpos, ypos, false, true); - fromStart.setP1(enc.getTGConnectingPointAtIndex(1)); - - //Direct the last TGConnector back to the start of the write channel operator - - fromStart.setP2(point); - //Shift components down to make room for the added ones, and add security contexts to write channels - for (TGComponent tg:tad.getComponentList()){ - if (tg instanceof TMLADWriteChannel){ - TMLADWriteChannel writeChannel = (TMLADWriteChannel) tg; - TraceManager.addDev("Inspecting write channel " + writeChannel.getChannelName()); - if (channel.equals(writeChannel.getChannelName()) && writeChannel.securityContext.equals("")){ - TraceManager.addDev("Securing write channel " + writeChannel.getChannelName()); - writeChannel.securityContext = "autoEncrypt_"+writeChannel.getChannelName(); - tad.repaint(); - } - } - if (tg.getY() >= ypos && tg !=enc){ - tg.setCd(tg.getX(), tg.getY()+yShift); - } - } - tad.setMaxPanelSize(tad.getMaxX(), tad.getMaxY()+yShift); - } - - for (String channel: macInChannels.get(task)){ - //Add decryptmac after readchannel - int yShift=50; - TGConnector conn =new TGConnectorTMLAD(0, 0, 0, 0, 0, 0, false, null, tad, null, null, new Vector()); - TGConnectingPoint next = new TGConnectingPoint(null, 0, 0, false, false); - //Find read channel operator - TMLADReadChannel readChannel = new TMLADReadChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - for (TGComponent tg: tad.getComponentList()){ - if (tg instanceof TMLADReadChannel){ - readChannel = (TMLADReadChannel) tg; - if (readChannel.getChannelName().equals(channel) && readChannel.securityContext.equals("")){ - fromStart = tad.findTGConnectorEndingAt(tg.getTGConnectingPointAtIndex(0)); - if (fromStart!=null){ - point = fromStart.getTGConnectingPointP2(); - } - else { - continue; - } - conn = tad.findTGConnectorStartingAt(tg.getTGConnectingPointAtIndex(1)); - xpos = fromStart.getX(); - ypos = fromStart.getY(); - if (conn==null){ - System.out.println("no connection"); - //Create a connector to decrypt operator - } - next = conn.getTGConnectingPointP2(); - break; - } - } - } - //Check if there is an operator to secure - if (fromStart==null){ - continue; - } - TraceManager.addDev("Securing read channel " + readChannel.getChannelName()); - readChannel.securityContext = "autoEncrypt_"+readChannel.getChannelName(); - tad.repaint(); - //Add decryption operator if it does not already exist - xpos = conn.getX(); - ypos = conn.getY(); - TMLADDecrypt dec = new TMLADDecrypt(xpos+10, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - dec.securityContext = "autoEncrypt_" + readChannel.getChannelName(); - tad.addComponent(dec, dec.getX(), dec.getY(), false, true); - conn.setP2(dec.getTGConnectingPointAtIndex(0)); - yShift+=60; - conn = new TGConnectorTMLAD(xpos,ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, dec.getTGConnectingPointAtIndex(1), next, new Vector()); - conn.setP1(dec.getTGConnectingPointAtIndex(1)); - conn.setP2(next); - tad.addComponent(conn, conn.getX(), conn.getY(), false,true); - //Shift everything down - for (TGComponent tg:tad.getComponentList()){ - if (tg instanceof TMLADReadChannel){ - readChannel = (TMLADReadChannel) tg; - TraceManager.addDev("Inspecting read channel " + readChannel.getChannelName()); - if (channel.equals(readChannel.getChannelName()) && readChannel.securityContext.equals("")){ - TraceManager.addDev("Securing read channel " + readChannel.getChannelName()); - readChannel.securityContext = "autoEncrypt_"+readChannel.getChannelName(); - - } - } - if (tg.getY() >= ypos && tg!=dec){ - - tg.setCd(tg.getX(), tg.getY()+yShift); - } - } - - - tad.setMaxPanelSize(tad.getMaxX(), tad.getMaxY()+yShift); - tad.repaint(); - - } - for (String channel: secInChannels.get(task)){ - System.out.println("securting channel "+channel); - int yShift=20; - // String title = task.getName().split("__")[0]; - TMLChannel tmlc = tmlmodel.getChannelByName(title +"__"+channel); - TGConnector conn =new TGConnectorTMLAD(0, 0, 0, 0, 0, 0, false, null, tad, null, null, new Vector()); - TGConnectingPoint next = new TGConnectingPoint(null, 0, 0, false, false); - //Find read channel operator - TMLADReadChannel readChannel = new TMLADReadChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - for (TGComponent tg: tad.getComponentList()){ - if (tg instanceof TMLADReadChannel){ - readChannel = (TMLADReadChannel) tg; - if (readChannel.getChannelName().equals(channel) && readChannel.securityContext.equals("")){ - fromStart = tad.findTGConnectorEndingAt(tg.getTGConnectingPointAtIndex(0)); - if (fromStart!=null){ - point = fromStart.getTGConnectingPointP2(); - } - else { - continue; - } - conn = tad.findTGConnectorStartingAt(tg.getTGConnectingPointAtIndex(1)); - xpos = fromStart.getX(); - ypos = fromStart.getY(); - if (conn==null){ - System.out.println("no connection"); - //Create a connector to decrypt operator - } - next = conn.getTGConnectingPointP2(); - break; - } - } - } - //Check if there is an operator to secure - if (fromStart==null){ - continue; - } - TMLADWriteChannel wr = new TMLADWriteChannel(0, 0, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - if (nonceInChannels.get(task).contains(channel)){ - //Create a nonce operator and a write channel operator - TMLADEncrypt nonce = new TMLADEncrypt(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - nonce.securityContext = "nonce_"+ tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; - nonce.type = "Nonce"; - nonce.message_overhead = overhead; - nonce.encTime= encComp; - nonce.decTime=decComp; - tad.addComponent(nonce, xpos ,ypos+yShift, false, true); - fromStart.setP2(nonce.getTGConnectingPointAtIndex(0)); - yShift+=50; - wr = new TMLADWriteChannel(xpos, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - //Send nonce along channel, the newly created nonce channel or an existing channel with the matching sender and receiver - //Find matching channels - ArrayList<TMLChannel> matches = tmlmodel.getChannels(tmlc.getDestinationTask(), tmlc.getOriginTask()); - if (matches.size()>0){ - wr.setChannelName(matches.get(0).getName().replaceAll(title+"__","")); - } - else { - wr.setChannelName("nonceCh"+tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]); - } - //send the nonce along the channel - wr.securityContext = "nonce_"+tmlc.getDestinationTask().getName().split("__")[1] + "_"+tmlc.getOriginTask().getName().split("__")[1]; - tad.addComponent(wr,xpos,ypos+yShift,false,true); - wr.makeValue(); - TGConnector tmp =new TGConnectorTMLAD(wr.getX(), wr.getY()+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null,tad,nonce.getTGConnectingPointAtIndex(1), wr.getTGConnectingPointAtIndex(0), new Vector()); - tad.addComponent(tmp, xpos,ypos,false,true); - fromStart=new TGConnectorTMLAD(wr.getX(), wr.getY(), tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, wr.getTGConnectingPointAtIndex(1), null, new Vector()); - tad.addComponent(fromStart, xpos, ypos, false, true); - //Connect created write channel operator to start of read channel operator - fromStart.setP1(wr.getTGConnectingPointAtIndex(1)); - fromStart.setP2(point); - //Shift everything from the read channel on down - for (TGComponent tg:tad.getComponentList()){ - if (tg.getY() >= ypos && tg!=nonce && tg!=wr){ - tg.setCd(tg.getX(), tg.getY()+yShift); - } - } - } - //tad.repaint(); - - //Now add the decrypt operator - yShift=20; - TraceManager.addDev("Securing read channel " + readChannel.getChannelName()); - readChannel.securityContext = "autoEncrypt_"+readChannel.getChannelName(); - tad.repaint(); - //Add decryption operator if it does not already exist - xpos = next.getX(); - ypos = next.getY(); - TMLADDecrypt dec = new TMLADDecrypt(xpos+10, ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad); - dec.securityContext = "autoEncrypt_" + readChannel.getChannelName(); - tad.addComponent(dec, dec.getX(), dec.getY(), false, true); - conn.setP2(dec.getTGConnectingPointAtIndex(0)); - yShift+=100; - conn = new TGConnectorTMLAD(xpos,ypos+yShift, tad.getMinX(), tad.getMaxX(), tad.getMinY(), tad.getMaxY(), false, null, tad, dec.getTGConnectingPointAtIndex(1), next, new Vector()); - conn.setP1(dec.getTGConnectingPointAtIndex(1)); - conn.setP2(next); - tad.addComponent(conn, conn.getX(), conn.getY(), false,true); - //Shift everything down - for (TGComponent tg:tad.getComponentList()){ - if (tg instanceof TMLADReadChannel){ - readChannel = (TMLADReadChannel) tg; - TraceManager.addDev("Inspecting read channel " + readChannel.getChannelName()); - if (channel.equals(readChannel.getChannelName()) && readChannel.securityContext.equals("")){ - TraceManager.addDev("Securing read channel " + readChannel.getChannelName()); - readChannel.securityContext = "autoEncrypt_"+readChannel.getChannelName(); - - } - } - if (tg.getY() >= ypos && tg!=dec){ - - tg.setCd(tg.getX(), tg.getY()+yShift); - } - } - - tad.setMaxPanelSize(tad.getMaxX(), tad.getMaxY()+yShift); - - tad.repaint(); - } - } - GTMLModeling gtm = new GTMLModeling(t, false); - TMLModeling newmodel = gtm.translateToTMLModeling(false,false); - for (TMLTask task:newmodel.getTasks()){ - task.setName(tabName+"_"+name+"__"+task.getName()); - } - for (TMLTask task: tmlmodel.getTasks()){ - HwExecutionNode node =(HwExecutionNode) map.getHwNodeOf(task); - if (newmodel.getTMLTaskByName(task.getName().replace(tabName,tabName+"_"+name))!=null){ - map.addTaskToHwExecutionNode(newmodel.getTMLTaskByName(task.getName().replace(tabName,tabName+"_"+name)), node); - map.removeTask(task); - } - else { - System.out.println("Can't find " + task.getName()); - } - } - //map.setTMLModeling(newmodel); - //System.out.println(map); - //TMLMapping newMap = gtm.translateToTMLMapping(); - map.setTMLModeling(newmodel); - return map; - } - public boolean securePath(TMLMapping map, TMLTask t1, TMLTask t2){ - //Check if a path between two tasks is secure - boolean secure=true; - java.util.List<HwLink> links = map.getTMLArchitecture().getHwLinks(); - HwExecutionNode node1 = (HwExecutionNode) map.getHwNodeOf(t1); - HwExecutionNode node2 = (HwExecutionNode) map.getHwNodeOf(t2); - java.util.List<HwNode> found = new ArrayList<HwNode>(); - java.util.List<HwNode> done = new ArrayList<HwNode>(); - java.util.List<HwNode> path = new ArrayList<HwNode>(); - Map<HwNode, java.util.List<HwNode>> pathMap = new HashMap<HwNode, java.util.List<HwNode>>(); - TraceManager.addDev("Links " + links); - if (node1==node2){ - return true; - } - for (HwLink link: links){ - if (link.hwnode == node1){ - found.add(link.bus); - java.util.List<HwNode> tmp = new ArrayList<HwNode>(); - tmp.add(link.bus); - pathMap.put(link.bus, tmp); - } - } - outerloop: - while (found.size()>0){ - HwNode curr = found.remove(0); - for (HwLink link: links){ - if (curr == link.bus){ - if (link.hwnode == node2){ - path = pathMap.get(curr); - break outerloop; - } - if (!done.contains(link.hwnode) && !found.contains(link.hwnode) && link.hwnode instanceof HwBridge){ - found.add(link.hwnode); - java.util.List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); - tmp.add(link.hwnode); - pathMap.put(link.hwnode, tmp); - } - } - else if (curr == link.hwnode){ - if (!done.contains(link.bus) && !found.contains(link.bus)){ - found.add(link.bus); - java.util.List<HwNode> tmp = new ArrayList<HwNode>(pathMap.get(curr)); - tmp.add(link.bus); - pathMap.put(link.bus, tmp); - } - } - } - done.add(curr); - } - if (path.size() ==0){ - System.out.println("no path"); - return true; - } - else { - HwBus bus; - //Check if all buses and bridges are private - for (HwNode n: path){ - if (n instanceof HwBus){ - bus = (HwBus) n; - if (bus.privacy ==0){ - return false; - } - } - } - } - return secure; - } - public void autoMapKeys(){ - System.out.println("Mapping keys"); - TraceManager.addDev("auto map keys"); - if (tmap==null){ - return; - } - java.util.List<HwLink> links = tmap.getArch().getHwLinks(); - //Find all Security Patterns, if they don't have an associated memory at encrypt and decrypt, map them - TMLModeling tmlm = tmap.getTMLModeling(); - if (tmlm.securityTaskMap ==null){ - return; - } - System.out.println(tmlm.securityTaskMap); - for (SecurityPattern sp: tmlm.securityTaskMap.keySet()){ - if (sp.type.contains("Encryption") || sp.type.equals("MAC")){ - TraceManager.addDev("Finding security "+sp); - for (TMLTask t:tmlm.securityTaskMap.get(sp)){ - ArrayList<HwMemory> mems = new ArrayList<HwMemory>(); - boolean keyFound=false; - HwExecutionNode node1 = (HwExecutionNode) tmap.getHwNodeOf(t); - //Try to find memory using only private buses - java.util.List<HwNode> toVisit = new ArrayList<HwNode>(); - // java.util.List<HwNode> toMemory = new ArrayList<HwNode>(); - java.util.List<HwNode> complete = new ArrayList<HwNode>(); - for (HwLink link:links){ - if (link.hwnode==node1){ - if (link.bus.privacy==1){ - toVisit.add(link.bus); - } - } - } - memloop: - while (toVisit.size()>0){ - HwNode curr = toVisit.remove(0); - for (HwLink link: links){ - if (curr == link.bus){ - if (link.hwnode instanceof HwMemory){ - mems.add((HwMemory) link.hwnode); - ArrayList<SecurityPattern> patterns = tmap.getMappedPatterns((HwMemory) link.hwnode); - String patternString= ""; - for (SecurityPattern pattern: patterns){ - if (pattern.name.equals(sp.name)){ - - keyFound=true; - break memloop; - } - patternString += pattern.name; - patternString += " "; - } - TraceManager.addDev("Memory "+ link.hwnode.getName() + " has currently mapped: " + patternString); - } - if (!complete.contains(link.hwnode) && !toVisit.contains(link.hwnode) && link.hwnode instanceof HwBridge){ - toVisit.add(link.hwnode); - } - } - else if (curr == link.hwnode){ - if (!complete.contains(link.bus) && !toVisit.contains(link.bus)){ - toVisit.add(link.bus); - } - } - } - complete.add(curr); - } - if (!keyFound){ - if (mems.size()>0){ - TMLArchiMemoryNode memNode= (TMLArchiMemoryNode) listE.getTG(mems.get(0)); - TMLArchiKey key = new TMLArchiKey(memNode.x, memNode.y, memNode.tdp.getMinX(), memNode.tdp.getMaxX(), memNode.tdp.getMinY(), memNode.tdp.getMaxY(), false, memNode, memNode.tdp); - key.setReferenceKey(sp.name); - key.makeFullValue(); - TraceManager.addDev("Adding " +sp.name+ " key to " +memNode.getName()); - TraceManager.addDev("Adding " +sp + " key to " +memNode.getName()); - memNode.tdp.addComponent(key, memNode.x, memNode.y, true,true); - memNode.tdp.repaint(); - } - else { - System.out.println("Can't map key to memory for " + sp.name + " on task " + t.getName()); - CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, "Cannot map key in memory for " + sp.name + " on task " + t.getName()); - ce.setTDiagramPanel(tmap.tmlap.tmlap); - ce.setTGComponent(null); - checkingErrors.add(ce); - } - } - } - } - } - TraceManager.addDev("Mapping finished"); - } - - public void generateAvatarFromTML(boolean mc, boolean security){ - TraceManager.addDev("Generating Avatar from TML"); - if (avatarspec!=null){ - return; - } - else if (tmap!=null){ - t2a = new TML2Avatar(tmap, mc, security); - avatarspec = t2a.generateAvatarSpec("1"); - } - } - - public boolean generateProVerifFromAVATAR(String _path, int _stateReachability, boolean _typed, String loopLimit) { - if (avatarspec !=null){ - //use avspec - } - else if (tmap!=null){ - t2a = new TML2Avatar(tmap,false,true); - avatarspec = t2a.generateAvatarSpec(loopLimit); - drawPanel(avatarspec, mgui.getFirstAvatarDesignPanelFound()); - - } - else if (tmlm!=null){ - //Generate default mapping - tmap = tmlm.getDefaultMapping(); - tmap.setTMLDesignPanel((TMLComponentDesignPanel)mgui.getCurrentTURTLEPanel()); - t2a=new TML2Avatar(tmap,false,true); - avatarspec = t2a.generateAvatarSpec(loopLimit); - } - else if (avatarspec == null){ - return false; - } - - avatar2proverif = new AVATAR2ProVerif(avatarspec); - //tml2uppaal.setChoiceDeterministic(choices); - //tml2uppaal.setSizeInfiniteFIFO(_size); - proverif = avatar2proverif.generateProVerif(true, true, _stateReachability, _typed); - warnings = avatar2proverif.getWarnings(); - languageID = PROVERIF; - mgui.setMode(MainGUI.EDIT_PROVERIF_OK); - //mgui.setMode(MainGUI.MODEL_PROVERIF_OK); - //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); - try { - if (avatar2proverif.saveInFile(_path)){ - TraceManager.addDev("Specification generated in " + _path); - return true; - } - return false; - } catch (FileException fe) { - TraceManager.addError("Exception: " + fe.getMessage()); - return false; - } - } - - public TPN generateTPNFromAvatar() { - avatar2tpn = new AVATAR2TPN(avatarspec); - //tml2uppaal.setChoiceDeterministic(choices); - //tml2uppaal.setSizeInfiniteFIFO(_size); - tpnFromAvatar = avatar2tpn.generateTPN(true, true); - languageID = TPN; - return tpnFromAvatar; - } - - /*IntMatrix im = tpnFromAvatar.getIncidenceMatrix(); - TraceManager.addDev("Farkas computing on " + im.toString()); - im.Farkas(); - TraceManager.addDev("Farkas done:" + im.toString()); - - - - languageID = TPN; - mgui.setMode(MainGUI.EDIT_PROVERIF_OK); - //mgui.setMode(MainGUI.MODEL_PROVERIF_OK); - //uppaalTable = tml2uppaal.getRelationTIFUPPAAL(_debug); - return true; - /*try { - avatar2tpn.saveInFile(_path); - TraceManager.addDev("Specification generated in " + _path); - return true; - } catch (FileException fe) { - TraceManager.addError("Exception: " + fe.getMessage()); - return false; - }*/ - - - public ArrayList<TGComponentAndUPPAALQuery> getUPPAALQueries() { - return getUPPAALQueries(mgui.getCurrentTURTLEPanel()); - } - - public ArrayList<TGComponentAndUPPAALQuery> getUPPAALQueries(TURTLEPanel tp) { - TraceManager.addDev("Searching for queries on " + mgui.getTabName(tp)); - ArrayList<TGComponent> list = new ArrayList<TGComponent>(); - ArrayList<TClass> tclasses; - tp.getAllCheckableTGComponent(list); - TGComponentAndUPPAALQuery tmpQ; - - ArrayList<TGComponentAndUPPAALQuery> listQ = new ArrayList<TGComponentAndUPPAALQuery>(); - - if (tp instanceof DesignPanel) { - ArrayList<ADComponent> listAD = listE.getADComponentCorrespondance(list); - - //TraceManager.addDev("List size:" + listAD.size()); - - if (listAD == null) { - return null; - } - - TClass t; - String s; - for(ADComponent adc:listAD) { - if (adc != null) { - t = tm.findTClass(adc); - //TraceManager.addDev("Found class:" + t.getName()); - if (t!= null) { - tclasses = new ArrayList<TClass>(); - tclasses.add(t); - // For handling tobjects - tm.addAllTClassesEndingWith(tclasses, "_" + t.getName()); - for(TClass tc: tclasses) { - //TraceManager.addDev("Analyzing class:" + tc.getName()); - s = uppaalTIFTable.getRQuery(tc, adc); - if (s != null) { - //TraceManager.addDev("Adding query:" + s); - tmpQ = new TGComponentAndUPPAALQuery(null, s + "$" + adc); - listQ.add(tmpQ); - } - } - } - } - } - } else if ((tp instanceof TMLComponentDesignPanel) || (tp instanceof TMLDesignPanel)) { - //TraceManager.addDev("uppaalTMLTable"); - ArrayList<TMLActivityElement> listAE = listE.getTMLActivityElementCorrespondance(list); - - if (listAE == null) { - return null; - } - - TMLTask task; - String s; - for(TMLActivityElement elt:listAE) { - if (elt != null) { - task = tmlm.findTMLTask(elt); - if (task!= null) { - s = uppaalTMLTable.getRQuery(task, elt); - if (s != null) { - //TraceManager.addDev("Adding query:" + s); - Object ref; - if (elt.getReferenceObject() instanceof TGComponent) { - tmpQ = new TGComponentAndUPPAALQuery((TGComponent)(elt.getReferenceObject()), s + "$" + elt); - } else { - tmpQ = new TGComponentAndUPPAALQuery(null, s + "$" + elt); - } - listQ.add(tmpQ); - } - } - } - } - - } else if ((avatar2uppaal != null) && (tp instanceof AvatarDesignPanel)) { - TraceManager.addDev("Making UPPAAL queries"); - for(TGComponent tgc: list) { - TraceManager.addDev("Making UPPAAL query for " + tgc); - String s = avatar2uppaal.getUPPAALIdentification(tgc); - TraceManager.addDev("Query: " + s); - if ((s!= null) && (s.length() > 0)) { - AvatarBlock block = avatar2uppaal.getBlockFromReferenceObject(tgc); - listQ.add(new TGComponentAndUPPAALQuery(tgc, s + "$" + block.getName() + "." + tgc)); - } else { - TraceManager.addDev("Could not make query for " + tgc); - } - } - } else if ((avatar2uppaal != null) && (tp instanceof AttackTreePanel)) { - TraceManager.addDev("Making UPPAAL queries"); - for(TGComponent tgc: list) { - TraceManager.addDev("Making UPPAAL query for " + tgc); - String s = avatar2uppaal.getUPPAALIdentification(tgc); - TraceManager.addDev("Query: " + s); - if ((s!= null) && (s.length() > 0)) { - AvatarBlock block = avatar2uppaal.getBlockFromReferenceObject(tgc); - listQ.add(new TGComponentAndUPPAALQuery(tgc, s + "$" + block.getName() + "." + tgc)); - } else { - TraceManager.addDev("Could not make query for " + tgc); - } - } - } - - return listQ; - } - - public LinkedList generateLOTOSAUT(String path) { - TML2AUTviaLOTOS tml2aut = new TML2AUTviaLOTOS(tmlm, tm); - tml2aut.generateLOTOS(true); - return tml2aut.getSpecs(); - /*try { - return tml2aut.saveInFiles(path); - } catch (FileException fe) { - return null; - }*/ - } - - public void generateSystemC() { - String path = ConfigurationTTool.SystemCCodeDirectory; - String list = FileUtils.deleteFiles(path, ".cpp"); - if (list.length() == 0) { - TraceManager.addDev("No cpp files were deleted\n"); - } else { - TraceManager.addDev("Files deleted:\n" + list + "\n"); - } - - list = FileUtils.deleteFiles(path, ".x"); - - if (list.length() == 0) { - TraceManager.addDev("No x files were deleted\n"); - } else { - TraceManager.addDev("Files deleted:\n" + list + "\n"); - } - - TML2SystemC tml2systc = new TML2SystemC(tmlm); - tml2systc.generateSystemC(true); - //tml2systc.print(); - try { - tml2systc.saveFile(path, "appmodel"); - } catch (FileException fe) { - TraceManager.addError("File could not be saved (SystemC)"); - } - - } - - - public void saveSIM(File f) { - if ((sim != null) && (f != null)) { - saveInFile(f, sim); - } - } - - public void saveDTA(File f) { - if ((dta != null) && (f != null)) { - saveInFile(f, dta); - } - } - - public void saveDTADOT(File f) { - if ((dtadot != null) && (f != null)) { - saveInFile(f, dtadot); - } - } - - public void saveRG(File f) { - if ((rg != null) && (f != null)) { - saveInFile(f, rg); - } - } - - public void saveTLSA(File f) { - if ((rg != null) && (f != null)) { - saveInFile(f, tlsa); - } - } - - public void saveRGAut(File f) { - if ((rgaut != null) && (f != null)) { - saveInFile(f, rgaut); - } - } - - public void saveRGDOT(File f) { - if ((rgdot != null) && (f != null)) { - saveInFile(f, rgdot); - } - } - - public void saveTLSADOT(File f) { - if ((rgdot != null) && (f != null)) { - saveInFile(f, tlsadot); - } - } - - public void saveRGAutDOT(File f) { - if ((rgautdot != null) && (f != null)) { - saveInFile(f, rgautdot); - } - } - - public void saveRGAutProj(File f) { - if ((rgautproj != null) && (f != null)) { - saveInFile(f, rgautproj); - } - } - - public void saveRGAutProjDOT(File f) { - if ((rgautprojdot != null) && (f != null)) { - saveInFile(f, rgautprojdot); - } - } - - public void modifyMinimizedGraph() { - /*AUTMappingGraph graph = new AUTMappingGraph(); - TraceManager.addDev("Building graph"); - graph.buildGraph(rgautproj); - TraceManager.addDev("Renaming transitions"); - graph.renameTransitions(); - TraceManager.addDev("Merging transitions 23/4=" + (23/4) + "23%4=" + (23%4)); - graph.mergeWriteTransitions(); - graph.mergeReadTransitions(); - graph.removeInternalTransitions(); - TraceManager.addDev("Printing graph:\n" + graph.toAUTStringFormat()); - TraceManager.addDev("Splitting transitions"); - graph.splitTransitions(); - modifiedaut = graph.toAUTStringFormat(); - TraceManager.addDev("Printing graph:\n" + modifiedaut); - TraceManager.addDev("Translation in DOT format"); - - // AUT 2 dot - String fileName = "graph"; - try { - RshClient rshc = new RshClient(getHostAldebaran()); - int id = rshc.getId(); - fileName = FileUtils.addBeforeFileExtension(fileName, "_" + id); - String data = rgautproj; - rshc.sendFileData(fileName + ".aut", data); - String cmd1 = getPathBcgio() + " -aldebaran " + fileName + ".aut" + " -graphviz " + fileName + ".dot"; - data = processCmd(rshc, cmd1); - data = rshc.getFileData(fileName + ".dot"); - modifiedautdot = data; - TraceManager.addDev("All done"); - } catch (LauncherException le) { - TraceManager.addDev("Error: conversion failed"); - }*/ - } - - protected String processCmd(RshClient rshc, String cmd) throws LauncherException { - rshc.setCmd(cmd); - String s = null; - rshc.sendProcessRequest(); - s = rshc.getDataFromProcess(); - return s; - } - - public void showSIM(int type) { - if (sim != null) { - JFrameSimulationTrace jfst = new JFrameSimulationTrace("Last simulation trace", sim, type); - jfst.setIconImage(IconManager.img8); - // jfst.setSize(900, 600); - GraphicLib.centerOnParent( jfst, 900, 600 ); - jfst.setVisible(true); - } - } - - public String showDTA() { - if (dta != null) { - return runDOTTY(dtadot); - } - return null; - } - - public String showRG() { - if (rg != null) { - return runDOTTY(rgdot); - } - return null; - } - - public String showTLSA() { - if (rg != null) { - return runDOTTY(tlsadot); - } - return null; - } - - public String showRGAut() { - if (rgaut != null) { - return runDOTTY(rgautdot); - } - return null; - } - - public String showRGDiplodocus(String graphName) { - TraceManager.addDev("Show diplodocus graph located in " + ConfigurationTTool.GGraphPath + "/" + graphName + ".dot"); - RemoteExecutionThread ret = new RemoteExecutionThread(ConfigurationTTool.DOTTYHost, null, null, ConfigurationTTool.DOTTYPath + " " + ConfigurationTTool.GGraphPath + "/tree.dot"); - ret.start(); - return null; - } - - public String showRGAutProj() { - if (rgaut != null) { - return runDOTTY(rgautprojdot); - } - return null; - } - - public static String showGGraph(String ggraph) { - if (ggraph != null) { - return runDOTTY(ggraph); - } - return null; - } - - public static String runDOTTY(String data) { - String fileName = "graph" + graphId + ".dot"; - graphId ++; - - RemoteExecutionThread ret = new RemoteExecutionThread(ConfigurationTTool.DOTTYHost, fileName, data, ConfigurationTTool.DOTTYPath + " " + fileName); - ret.start(); - - return null; - } - - public boolean useDynamicStructure(String data) { - int index1 = data.indexOf("behaviour"); - if (index1 == -1) { - return false; - } - - data = data.substring(index1, data.length()); - - return (data.indexOf("Queue_nat") != -1); - - } - - - - public void saveInFile(File file, String s) { - TraceManager.addDev("Saving in file " + file.getAbsolutePath() + " size of file=" + s.length()); - //TraceManager.addDev("Length of s=" + s.length()); - - int index1 = 0, index2; - int step = 1048576; - int length = s.length(); - //String sub; - - try { - FileOutputStream fos = new FileOutputStream(file); - while(index1<length) { - index2 = Math.min(index1+step, length); - fos.write(s.substring(index1, index2).getBytes()); - index1 += step; - } - fos.close(); - } catch(Exception e) { - JOptionPane.showMessageDialog(mgui.frame, "Specification could not be saved " + e.getMessage(), "Lotos File Error", JOptionPane.INFORMATION_MESSAGE); - TraceManager.addError("Specification could not be saved " + e.getMessage()); - } - - /*try { - FileOutputStream fos = new FileOutputStream(file); - fos.write(s.getBytes()); - fos.close(); - } catch(Exception e) { - JOptionPane.showMessageDialog(mgui.frame, "Specification could not be saved " + e.getMessage(), "Lotos File Error", JOptionPane.INFORMATION_MESSAGE); - TraceManager.addDev("Specification could not be saved " + e.getMessage()); - }*/ - } - - public String getLastRTLOTOSSpecification() { - return rtlotos; - } - - public String getLastTextualDTA() { - return dta; - } - - public String getLastGraphicalDTA() { - return dtadot; - } - - public String getLastTextualRG() { - return rg; - } - - public String getLastGraphicalRG() { - return rgdot; - } - - public String getLastTextualTLSA() { - return tlsa; - } - - public String getLastGraphicalTLSA() { - return tlsadot; - } - - public String getLastTextualRGAUT() { - return rgaut; - } - - public String getLastGraphicalRGAUT() { - return rgautdot; - } - - public String getLastTextualRGAUTProj() { - return rgautproj; - } - - public String getLastGraphicalRGAUTProj() { - return rgautprojdot; - } - - public String getLastProVerifSpecification() { - if (proverif == null) { - return ""; - } - - return proverif.getStringSpec(); - } - - public int getNbRTLOTOS() { - return nbRTLOTOS; - } - - public String getLastTextualDesign() { - if (tm == null) { - return ""; - } else { - return tm.printToStringBuffer().toString(); - } - } - - public int getNbSuggestedDesign() { - return nbSuggestedDesign; - } - - // formal validation - public void reinitSIM() { - sim = null; - mgui.setMode(MainGUI.SIM_KO); - } - - public void reinitDTA() { - dta = null; - dtadot = null; - mgui.setMode(MainGUI.DTADOT_KO); - } - - public void reinitRG() { - rg = null; - rgdot = null; - mgui.setMode(MainGUI.RGDOT_KO); - } - - public void reinitRGAUT() { - rgaut = null; - rgautdot = null; - mgui.setMode(MainGUI.RGAUTDOT_KO); - mgui.setMode(MainGUI.RGAUT_KO); - } - - public void reinitRGAUTPROJDOT() { - rgautprojdot = null; - mgui.setMode(MainGUI.RGAUTPROJDOT_KO); - } - - public void setSIM(String data) { - sim = data; - mgui.setMode(MainGUI.SIM_OK); - } - - public void setDTA(String data) { - dta = data; - } - - public void setDTADOT(String data) { - dtadot = data; - mgui.setMode(MainGUI.DTADOT_OK); - } - - public void setRG(String data) { - rg = data; - mgui.setMode(MainGUI.RGDOT_OK); - } - - public void setTLSA(String data) { - tlsa = data; - //mgui.setMode(MainGUI.TLSADOT_OK); - } - - public void setTLSADOT(String data) { - tlsadot = data; - mgui.setMode(MainGUI.TLSADOT_OK); - } - - public void setRGAut(String data) { - rgaut = data; - mgui.setMode(MainGUI.RGAUT_OK); - } - - public String getLastRGAUT() { - return rgaut; - } - - public void setRGDOT(String data) { - rgdot = data; - mgui.setMode(MainGUI.RGDOT_OK); - } - - public void setRGAutDOT(String data) { - rgautdot = data; - mgui.setMode(MainGUI.RGAUTDOT_OK); - } - - public void setRGAUTPROJ(String data) { - rgautproj = data; - } - - public void setRGAUTPROJDOT(String data) { - rgautprojdot = data; - mgui.setMode(MainGUI.RGAUTPROJDOT_OK); - } - - // Configuration - - public String getPathRTL() { - return ConfigurationTTool.RTLPath; - } - - public String getPathCaesar() { - return ConfigurationTTool.CaesarPath; - } - - public String getPathCaesarOpen() { - return ConfigurationTTool.CaesarOpenPath; - } - - public String getPathDTA2DOT() { - return ConfigurationTTool.DTA2DOTPath; - } - - public String getPathRGSTRAP() { - return ConfigurationTTool.RGSTRAPPath; - } - - public String getPathRG2TLSA() { - return ConfigurationTTool.RG2TLSAPath; - } - - public String getHost() { - return ConfigurationTTool.RTLHost; - } - - public static String getCaesarHost() { - return ConfigurationTTool.AldebaranHost; - } - - public static String getHostAldebaran() { - return ConfigurationTTool.AldebaranHost; - } - - public static String getPathAldebaran() { - return ConfigurationTTool.AldebaranPath; - } - - public static String getPathBcgio() { - return ConfigurationTTool.BcgioPath; - } - - public static String getPathBisimulator() { - return ConfigurationTTool.BisimulatorPath; - } - - public String getPathBcgmerge() { - return ConfigurationTTool.BcgmergePath; - } - - public String getPathBcgmin() { - return ConfigurationTTool.BcgminPath; - } - - public String getPathVerifyta() { - return ConfigurationTTool.UPPAALVerifierPath; - } - - public String getPathUPPAALVerifier() { - return ConfigurationTTool.UPPAALVerifierPath; - } - - public String getPathUPPAALFile() { - return ConfigurationTTool.UPPAALCodeDirectory; - } - - public String getUPPAALVerifierHost() { - return ConfigurationTTool.UPPAALVerifierHost; - } - - - - public TURTLEModeling getTURTLEModeling() { - return tm; - } - - public int getTURTLEModelingState() { - return tmState; - } - - public TMLModeling getTMLModeling() { - return tmlm; - } - public TML2Avatar getTML2Avatar(){ - return t2a; - } - public TMLMapping getArtificialTMLMapping() { - return artificialtmap; - } - - public TMLMapping getTMLMapping() { - return tmap; - } - - public UPPAALSpec getLastUPPAALSpecification() { - return uppaal; - } - - // TREE MANAGEMENT - - public String toString() { - return mgui.getTitle(); - } - - public int getChildCount() { - return panels.size() + 4; - } - - public Object getChild(int index) { - if (index < panels.size()) { - return panels.elementAt(index); - } else if (index == panels.size()) { - return mcvdt; - } else if (index == (panels.size() + 1)) { - return gt; - } else if (index == (panels.size() + 2)) { - return idt; - } else { - return st; - } - - } - - public int getIndexOfChild(Object child) { - int index = panels.indexOf(child); - - if (index > -1) { - return index; - } - - if (child == mcvdt) { - return panels.size(); - } - - if (child == gt) { - return panels.size() + 1; - } - - if (child == idt) { - return panels.size() + 2; - } - - return panels.size()+3; - } - - // Projection management - - public MasterGateManager getNewMasterGateManager() { - return new MasterGateManager(tm); - } - - // Assume the inputData is in AUT format: generated by RTL or CADP - public String performProjection(String inputData, LinkedList<TClassAndGateDS> gates) { - StringBuffer result = new StringBuffer(""); - StringReader sr = new StringReader(inputData); - BufferedReader br = new BufferedReader(sr); - String s; - String actionName, actionName1; - int index, index1, index2; - MasterGateManager mgm = new MasterGateManager(tm, 1); - Gate g; - GroupOfGates gog; - Hashtable <String, GroupOfGates> hashtable = new Hashtable<String, GroupOfGates>(); - - int cpt = 0; - - //TraceManager.addDev("input data=" + inputData); - - // Fill Hashtable - int j; - for (TClassAndGateDS tag: gates) { - //TraceManager.addDev("TClass:" + tag.getTClassName() + " Gate:" + tag.getGateName()); - //actionName = tag.getGateName(); - //g = mgm.getGate(tag.getTClassName(), actionName); - //TraceManager.addDev("actionName = " + actionName + " gateName = " + g.getName()); - //if (g != null) { - //gog = mgm.getGroupOfGatesByGate(g); - gog = mgm.groupOf(tag.getTClassName(), tag.getGateName()); - if (gog != null) { - //TraceManager.addDev("Found a gog: >" + gog.getMasterGateName() + "<"); - hashtable.put(gog.getMasterGateName().getName(), gog); - /*for(j=0;j<gog.size();j++) { - g = gog.getGateAt(j); - TraceManager.addDev("Putting: " + g.getName()); - hashtable.put(g.getName(), g); - }*/ - } - //} - } - - try { - while((s = br.readLine()) != null) { - /*if (cpt % 10000 == 0) { - TraceManager.addDev("cpt=" + cpt); - }*/ - cpt ++; - - if (s.startsWith("des")) { - result.append(s + "\n"); - } else if (s.startsWith("(")) { - index = s.indexOf("\"t\""); - if (index > 0) { - // temporal action - // replace t with i - s = s.replaceAll("\"t\"", "i"); - result.append(s + "\n"); - } else { - //exit action? - index = s.indexOf("\"exit\""); - if (index > 0) { - // exit action - // replace t with i - s = s.replaceAll("\"exit\"", "i"); - result.append(s + "\n"); - } else { - // regular action - // find the name of this action - index1 = s.indexOf("i("); - index2 = s.indexOf(")"); - actionName = s.substring(index1 + 2, index2); - index = actionName.indexOf("<"); - if (index < 0) { - actionName1 = actionName; - } else { - actionName1 = actionName.substring(0, index); - } - TraceManager.addDev("Action = >" + actionName1 + "<"); - - gog = hashtable.get(actionName1); - if (gog == null) { - TraceManager.addDev("Not in hash"); - result.append(makeIAction(s) + "\n"); - } else { - TraceManager.addDev("In hash"); - result.append(makeAction(s, actionName) + "\n"); - } - - // action to ignored or to project ? - /*g = mgm.getGate(actionName1); - if (g == null) { - //TraceManager.addDev("null1"); - result.append(makeIAction(s) + "\n"); - } else { - gog = mgm.getGroupOfGatesByGate(g); - if (gog == null) { - //TraceManager.addDev("null2"); - result.append(makeIAction(s) + "\n"); - } else { - if (!belongTo(gog, gates)) { - // Check if directly a master Gate! - // A completer ... - //TraceManager.addDev("null3"); - result.append(makeIAction(s) + "\n"); - } else { - //TraceManager.addDev("action added: " + actionName); - result.append(makeAction(s, actionName) + "\n"); - } - } - }*/ - } - - } - } - } - } catch (Exception e) { - TraceManager.addError("Exception during projection" + e.getMessage()); - return null; - } - return new String(result); - } - - // Assume the inputData is in AUT format and has been generated by CADP - // Note: might not work because of case sensitive problem... - public String convertCADP_AUT_to_RTL_AUT(String inputData, int max) { - StringBuffer result = new StringBuffer(""); - StringReader sr = new StringReader(inputData); - BufferedReader br = new BufferedReader(sr); - String s, s1; - String actionName; - int index1, index2, index3, index4; - Gate g; - String g0, g1, g2; - int cpt, transi=0; - MasterGateManager mgm = new MasterGateManager(tm, 1); - Hashtable ht = mgm.getGatesUpperCaseHashTable(); - warnings = new LinkedList<CheckingError> (); - - //TraceManager.addDev("input data=" + inputData); - - int cpt1 = 0; - - try { - while((s = br.readLine()) != null) { - cpt1 ++; - //if (cpt1 % 100000 == 0) { - //TraceManager.addDev("=" + cpt1 + " / " + transi); - //} - if (s.charAt(0) == '(') { - index1 = s.indexOf(","); - if ((index1 > -1) && ((index1+1) < s.length())) { - g1 = s.substring(0, index1 + 1); - s = s.substring(index1+1, s.length()); - - //TraceManager.addDev("g1=" + g1 + " s=" + s); - - index2 = s.indexOf(","); - if ((index2 > -1) && ((index2+1) < s.length())) { - g2 = s.substring(index2, s.length()); - s = s.substring(0, index2); - s = s.trim(); - - //TraceManager.addDev("g2=" + g2 + " s=" + s); - - // Get action id - // Most common case: no data - index3 = s.indexOf('"'); - if (index3 == -1) { // no data - actionName = s; - g0 = ""; - } else { - // Extract action name - actionName = s.substring(index3+1, s.indexOf('!')).trim(); - - // Format data - g0 = "<"; - cpt = 0; - while((index4 = s.indexOf('!')) > -1) { - s = s.substring(index4+1, s.length()); - if (cpt > 0) { - g0 += ","; - } - cpt ++; - index4 = s.indexOf('!'); - if (index4 > -1) { - g0 += s.substring(0, index4); - } else { - g0 += s.substring(0, s.indexOf('"')).trim(); - } - } - g0 += ">"; - } - - // Working on action name! - //g = mgm.getGateLowerCase(actionName); - g = (Gate)(ht.get(actionName)); - - if (g != null) { - //actionName1 = actionName; - actionName = g.getName(); - //TraceManager.addDev("actionName = " + g.getName()); - /*if (mgm.nbOfPossibleGatesLowerCase(actionName1) > 1) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action " + actionName1 + " has several possible candidates ; " + actionName + " has been chosen"); - warnings.add(ce); - }*/ - } else { - TraceManager.addDev("actionName is not in hashtable: ->" + actionName + "<- length=" + actionName.length()); - } - - // Store result - result.append(g1 + "\"i(" + actionName + g0 + ")\"" + g2 + "\n"); - } - } - } else if (s.startsWith("des")) { - index1 = s.indexOf(","); - s1 = s.substring(index1+1, s.length()); - index1 = s1.indexOf(","); - s1 = s1.substring(0, index1).trim(); - //TraceManager.addDev("nb of transitions=" + s); - transi = Integer.decode(s1).intValue(); - if (transi > max) { - return null; - } - result.append(s + "\n"); - } - } - } catch (Exception e) { - TraceManager.addError("Exception convert0" + e.getMessage()); - return null; - } - return new String(result); - } - - /*public String convertCADP_AUT_to_RTL_AUT(String inputData, int max) { - StringBuffer result = new StringBuffer(""); - StringReader sr = new StringReader(inputData); - BufferedReader br = new BufferedReader(sr); - String s; - String actionName, actionName1; - int index, index1, index2, index3, index4, index5; - Gate g; - String g0, g1, g2; - int cpt, transi=0; - MasterGateManager mgm = new MasterGateManager(tm); - warnings = new Vector(); - - //TraceManager.addDev("input data=" + inputData); - - int cpt1 = 0; - - try { - while((s = br.readLine()) != null) { - cpt1 ++; - if (cpt1 % 100000 == 0) { - TraceManager.addDev("=" + cpt1 + " / " + transi); - } - if (s.charAt(0) == '(') { - index1 = s.indexOf(","); - if ((index1 > -1) && ((index1+1) < s.length())) { - g1 = s.substring(0, index1 + 1); - s = s.substring(index1+1, s.length()); - - //TraceManager.addDev("g1=" + g1 + " s=" + s); - - index2 = s.indexOf(","); - if ((index2 > -1) && ((index2+1) < s.length())) { - g2 = s.substring(index2, s.length()); - s = s.substring(0, index2); - s = s.trim(); - - //TraceManager.addDev("g2=" + g2 + " s=" + s); - - // Get action id - // Most common case: no data - index3 = s.indexOf('"'); - if (index3 == -1) { // no data - actionName = s; - g0 = ""; - } else { - // Extract action name - actionName = s.substring(index3+1, s.indexOf('!')).trim(); - - // Format data - g0 = "<"; - cpt = 0; - while((index4 = s.indexOf('!')) > -1) { - s = s.substring(index4+1, s.length()); - if (cpt > 0) { - g0 += ","; - } - cpt ++; - index4 = s.indexOf('!'); - if (index4 > -1) { - g0 += s.substring(0, index4); - } else { - g0 += s.substring(0, s.indexOf('"')).trim(); - } - } - g0 += ">"; - } - - // Working on action name! - g = mgm.getGateLowerCase(actionName); - - if (g != null) { - actionName1 = actionName; - actionName = g.getName(); - if (mgm.nbOfPossibleGatesLowerCase(actionName1) > 1) { - CheckingError ce = new CheckingError(CheckingError.BEHAVIOR_ERROR, "Action " + actionName1 + " has several possible candidates ; " + actionName + " has been chosen"); - warnings.add(ce); - } - } - - // Store result - result.append(g1 + "\"i(" + actionName + g0 + ")\"" + g2 + "\n"); - } - } - } else if (s.startsWith("des")) { - index1 = s.indexOf(","); - s = s.substring(index1+1, s.length()); - index1 = s.indexOf(","); - s = s.substring(0, index1).trim(); - //TraceManager.addDev("nb of transitions=" + s); - transi = Integer.decode(s).intValue(); - if (transi > max) { - return null; - } - result.append(s + "\n"); - } - } - } catch (Exception e) { - TraceManager.addError("Exception09545 " + e.getMessage()); - return null; - } - return new String(result); - }*/ - - public boolean belongTo(GroupOfGates gog, Vector gates) { - int i, j; - TClassAndGateDS tcg; - String nameTClass, nameGate; - for(i=0; i<gog.size(); i++) { - nameTClass = gog.getTClassAt(i).getName(); - nameGate = gog.getGateAt(i).getName(); - for(j=0; j<gates.size(); j++) { - tcg = (TClassAndGateDS)(gates.elementAt(j)); - if ((tcg.getTClassName().compareTo(nameTClass) == 0) && (tcg.getGateName().compareTo(nameGate) == 0)) { - //TraceManager.addDev("Projected gate"); - return true; - } - } - - } - return false; - - } - - public String makeIAction(String s) { - int index1, index2; - index1 = s.indexOf("i("); - index2 = s.indexOf(")"); - return s.substring(0, index1-1) + "i" + s.substring(index2+2, s.length()); - } - - public String makeAction(String s, String actionName) { - int index1, index2; - index1 = s.indexOf("i("); - index2 = s.indexOf(")"); - return s.substring(0, index1) + actionName + s.substring(index2+1, s.length()); - } - - public void enableUndo(boolean b) { - undoRunning = !b; - } - - public boolean isUndoEnable() { - return !undoRunning; - } - - // UNDO MANAGEMENT - - // This function is not be performed when executing an undo - // if variable undoRunnin has been set to true - public void saveOperation(Point p) { - if (undoRunning) { - return; - } - - //TraceManager.addDev("Save operation"); - - String s = makeXMLFromTurtleModeling(-1); - - if ((pointerOperation > -1) && (pointerOperation < savedOperations.size() - 1)) { - // some save operations must be erased - for (int i = pointerOperation +1; i<savedOperations.size(); i++) { - savedOperations.removeElementAt(i); - savedPanels.removeElementAt(i); - i --; - } - } - - // save actions on tab - int size = savedPanels.size(); - if (size > 0) { - Point p1 = (Point)(savedPanels.elementAt(size - 1)); // panels are saved under the form of a point -> x = analysis/design, y = panel - if (p == null) - p = p1; - /*if ((p1.x != p.x) || (p1.y != p.y)){ - savedOperations.add(savedOperations.elementAt(size - 1)); - savedPanels.add(p); - if (savedOperations.size() > nbMaxSavedOperations) { - savedOperations.removeElementAt(0); - savedPanels.removeElementAt(0); - } - }*/ - } - - savedOperations.add(s); - savedPanels.add(p); - if (savedOperations.size() > nbMaxSavedOperations) { - savedOperations.removeElementAt(0); - savedPanels.removeElementAt(0); - } - pointerOperation = savedOperations.size() - 1; - //TraceManager.addDev("Setting pointer to " + pointerOperation); - - selectBackwardMode(); - } - - public void backward() { - undoRunning = true; - TraceManager.addDev("Nb Of saved operations:" + savedOperations.size() + " pointer=" + pointerOperation); - if ((pointerOperation < 1) || (savedOperations.size() < 2)) { - TraceManager.addDev("Undo not possible"); - undoRunning = false; - return; - } - - removeAllComponents(); - mgui.reinitMainTabbedPane(); - try { - pointerOperation --; - TraceManager.addDev("Decrementing pointer =" + pointerOperation); - loadModelingFromXML((String)(savedOperations.elementAt(pointerOperation))); - - } catch (Exception e) { - TraceManager.addError("Exception in backward: " + e.getMessage()); - } - - TraceManager.addDev("Selecting tab"); - - Point p = (Point)(savedPanels.elementAt(pointerOperation)); - if (p != null) { - TraceManager.addDev("Selecting tab panel=" + p.getX() + " diagram=" + p.getY()); - TDiagramPanel tdp = mgui.selectTab(p); - tdp.mode = tdp.NORMAL; - tdp.setDraw(true); - tdp.repaint(); - } - - - TraceManager.addDev("Selecting backward mode"); - selectBackwardMode(); - undoRunning = false; - } - - public void selectBackwardMode() { - if (pointerOperation <0) { - mgui.setMode(MainGUI.NO_BACKWARD); - mgui.setMode(MainGUI.NO_FORWARD); - } else { - - // forward - if (pointerOperation < savedOperations.size() - 1) { - mgui.setMode(MainGUI.FORWARD); - } else { - mgui.setMode(MainGUI.NO_FORWARD); - } - - // backward - if (pointerOperation > 0) { - mgui.setMode(MainGUI.BACKWARD); - } else { - mgui.setMode(MainGUI.NO_BACKWARD); - } - } - } - - - public void forward() { - if ((pointerOperation < 0) || (pointerOperation > savedOperations.size() - 2)) { - return; - } - - undoRunning = true; - removeAllComponents(); - mgui.reinitMainTabbedPane(); - - try { - pointerOperation ++; - loadModelingFromXML((String)(savedOperations.elementAt(pointerOperation))); - } catch (Exception e) { - TraceManager.addError("Exception in forward: " + e.getMessage()); - } - - Point p = (Point)(savedPanels.elementAt(pointerOperation)); - if (p != null) { - TDiagramPanel tdp = mgui.selectTab(p); - tdp.mode = TDiagramPanel.NORMAL; - tdp.setDraw(true); - tdp.repaint(); - } - - selectBackwardMode(); - undoRunning = false; - } - - - // BUILDING A TURTLE MODELING AND CHECKING IT - public boolean checkTURTLEModeling(LinkedList<TClassInterface> tclasses, DesignPanel dp, boolean overideSyntaxChecking) { - // Builds a TURTLE modeling from diagrams - //warnings = new Vector(); - //checkingErrors = null; - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - //tm = new TURTLEModeling(); - //listE = new CorrespondanceTGElement(); - mgui.reinitCountOfPanels(); - - DesignPanelTranslator dpt = new DesignPanelTranslator(dp); - tm = dpt.generateTURTLEModeling(tclasses, ""); - tmState = 0; - - listE = dpt.getCorrespondanceTGElement(); - checkingErrors = dpt.getErrors(); - warnings = dpt.getWarnings(); - if ((checkingErrors != null) && (checkingErrors.size() >0)){ - return false; - } - - // modeling is built - // Now check it ! - if (!overideSyntaxChecking) { - TURTLEModelChecker tmc = new TURTLEModelChecker(tm, listE); - - checkingErrors = tmc.syntaxAnalysisChecking(); - warnings.addAll(tmc.getWarnings()); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - return false; - } else { - return true; - } - } - - return true; - } - - // BUILDING An AVATAR Design AND CHECKING IT - public boolean checkAvatarDesign(LinkedList<AvatarBDStateMachineOwner> blocks, AvatarDesignPanel adp, boolean _optimize) { - // Builds a TURTLE modeling from diagrams - //warnings = new Vector(); - //checkingErrors = null; - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - //tm = new TURTLEModeling(); - //listE = new CorrespondanceTGElement(); - mgui.reinitCountOfPanels(); - - //avatarspec = new AvatarSpecification("avatarspecification", adp); - - AvatarDesignPanelTranslator adpt = new AvatarDesignPanelTranslator(adp); - avatarspec = adpt.generateAvatarSpecification(blocks); - avatarspec.setInformationSource(adp); - optimizeAvatar = _optimize; - //TraceManager.addDev("AvatarSpec:" + avatarspec.toString() + "\n\n"); - tmState = 3; - - listE = adpt.getCorrespondanceTGElement(); - checkingErrors = adpt.getErrors(); - warnings = adpt.getWarnings(); - if ((checkingErrors != null) && (checkingErrors.size() >0)){ - return false; - } - return true; - - // Modeling is built - // Now check it ! - /*if (!overideSyntaxChecking) { - TURTLEModelChecker tmc = new TURTLEModelChecker(tm, listE); - - checkingErrors = tmc.syntaxAnalysisChecking(); - warnings.addAll(tmc.getWarnings()); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - return false; - } else { - return true; - } - } - - return true;*/ - } - - // Return values - // -1: error - // -2: no mutex - // -3: invariant for mutex not found - // else: invariant found! -> invariant index - public int computeMutex() { - if (avatarspec == null) { - return -1; - } - - AvatarDesignPanel adp = null; - - try { - adp = (AvatarDesignPanel)(avatarspec.getInformationSource()); - } catch (Exception e) { - TraceManager.addDev("Exception gtm: " + e.getMessage()); - return -1; - } - - // Building the list of all states in the mutex - LinkedList<TGComponent> compInMutex = adp.getListOfComponentsInMutex(); - TraceManager.addDev("Nb of elements in mutex:" + compInMutex.size()); - - if (compInMutex.size() ==0) { - return -2; - } - - LinkedList<TGComponent> comps; - boolean found; - int nbOfFound; - int cpt = 0; - // Go thru invariants, and see whether one contains - for(Invariant inv: invariants) { - comps = inv.getComponents(); - nbOfFound = 0; - for(TGComponent tgc_mutex: compInMutex) { - found = false; - for(TGComponent tgc_inv: comps) { - if (tgc_mutex == tgc_inv) { - found = true; - break; - } - } - if (!found) { - break; - } - nbOfFound ++; - } - if (nbOfFound == compInMutex.size()) { - TraceManager.addDev("Mutex found in inv:" + cpt); - for(TGComponent tgc: compInMutex) { - tgc.setMutexResult(TGComponent.MUTEX_OK); - } - return cpt; - } - cpt ++; - } - - - for(TGComponent tgc: compInMutex) { - tgc.setMutexResult(TGComponent.MUTEX_UNKNOWN); - } - - return -3; - - - } - - public void clearGraphicalInfoOnInvariants() { - if (avatarspec == null) { - return; - } - - AvatarDesignPanel adp = null; - - try { - adp = (AvatarDesignPanel)(avatarspec.getInformationSource()); - } catch (Exception e) { - TraceManager.addDev("Exception gtm: " + e.getMessage()); - return; - } - - if (adp == null) { - return; - } - - adp.removeAllMutualExclusionWithMasterMutex(); - - - - } - - - // Returns the number of states found - // Returns -1 in case of error - public int computeMutexStatesWith(AvatarSMDState state) { - Vector<TGComponent> list = new Vector<TGComponent>(); - - if (state == null) { - state.setMutexWith(TGComponent.MUTEX_UNKNOWN); - return -1; - } - - for(Invariant inv: invariants) { - if (inv.containsComponent(state)) { - // All other states are in mutual exclusion - for(TGComponent tgc: inv.getComponents()) { - if ((tgc instanceof AvatarSMDState) && (tgc != state)) { - if (tgc.getTDiagramPanel() != state.getTDiagramPanel()) { - if (!(list.contains(tgc))) { - tgc.setMutualExclusionWithMasterMutex(state.getTDiagramPanel().getName() + "/" + state.getStateName()); - list.add(tgc); - - } - } - } - } - } - } - - if (list.size() > 0) { - state.setMutexWith(TGComponent.MUTEX_OK); - } else { - state.setMutexWith(TGComponent.MUTEX_UNKNOWN); - } - - return list.size(); - - } - - - public void computeAllMutualExclusions() { - TURTLEPanel tp = mgui.getCurrentTURTLEPanel(); - - if (tp == null) { - return; - } - - if (!(tp instanceof AvatarDesignPanel)) { - return; - } - - AvatarDesignPanel adp = (AvatarDesignPanel)(tp); - adp.reinitMutualExclusionStates(); - - // First step: build a list of all states being in invariants - Vector<AvatarSMDState> v = new Vector<AvatarSMDState>(); - for(Invariant inv: invariants) { - for(TGComponent tgc: inv.getComponents()) { - if (tgc instanceof AvatarSMDState) { - if (!(v.contains(tgc))) { - v.add((AvatarSMDState)tgc); - } - } - } - } - - // Then, add to all states its list of mutually exclusive states - - for(AvatarSMDState s: v) { - Vector<AvatarSMDState> v0 = new Vector<AvatarSMDState>(); - for(Invariant inv: invariants) { - if (inv.containsComponent(s)) { - for(TGComponent tgc: inv.getComponents()) { - if ((tgc instanceof AvatarSMDState) && (tgc != s)) { - if (tgc.getTDiagramPanel() != s.getTDiagramPanel()) { - if (!(v0.contains(tgc))) { - v0.add((AvatarSMDState)tgc); - } - } - } - } - } - } - TraceManager.addDev("State " + s.getStateName() + " has " + v0.size() + " mutually eclusive states"); - - for(AvatarSMDState s0: v0) { - s.addMutexState(s0); - } - } - - - } - - // From AVATAR to TURTLEModeling - public boolean translateAvatarSpecificationToTIF() { - AVATAR2TURTLE att = new AVATAR2TURTLE(avatarspec); - tm = att.generateTURTLEModeling(); - - TURTLEModelChecker tmc = new TURTLEModelChecker(tm, listE); - - checkingErrors = tmc.syntaxAnalysisChecking(); - warnings.addAll(tmc.getWarnings()); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - return false; - } else { - return true; - } - - } - - public LinkedList<CheckingError> getCheckingErrors() { - return checkingErrors; - } - - public LinkedList<CheckingError> getCheckingWarnings() { - return warnings; - } - - - // SAVING AND LOADING IN XML - public static String transformString(String s) { - if (s != null) { - s = Conversion.replaceAllChar(s, '&', "&"); - s = Conversion.replaceAllChar(s, '<', "<"); - s = Conversion.replaceAllChar(s, '>', ">"); - s = Conversion.replaceAllChar(s, '"', """); - s = Conversion.replaceAllChar(s, '\'', "'"); - } - return s; - } - - public static String encodeString(String s) { - return s; - } - - public static String decodeString(String s) throws MalformedModelingException { - if (s == null) - return s; - byte b[] = null; - try { - b = s.getBytes("ISO-8859-1"); - return new String(b); - } catch (Exception e) { - throw new MalformedModelingException(); - } - } - - public String mergeTURTLEGModeling(String modeling1, String modeling2) { - int index1 = modeling1.indexOf("</TURTLEGMODELING"); - int index2 = modeling2.indexOf("<TURTLEGMODELING"); - if ((index1 == -1) || (index2 == -1)) { - return null; - } - - String modeling = modeling1.substring(0, index1); - String tmp = modeling2.substring(index2, modeling2.length()); - index2 = modeling2.indexOf('<'); - if (index2 == -1) { - return null; - } - - tmp = tmp.substring(index2+1, tmp.length()); - - return modeling + tmp; - } - - public String makeXMLFromComponentOfADiagram(TDiagramPanel tdp, TGComponent tgc, int copyMaxId, int _decX, int _decY) { - StringBuffer sb = new StringBuffer(); - - //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGSELECTEDCOMPONENTS "); - sb.append("version=\"" + DefaultText.getVersion()); - sb.append("\" copyMaxId=\"" + copyMaxId); - sb.append("\" decX=\"" + _decX); - sb.append("\" decY=\"" + _decY); - sb.append("\" >\n\n"); - - StringBuffer s; - String str; - - s = tdp.saveComponentInXML(tgc); - - if (tgc instanceof AvatarBDBlock) { - AvatarSMDPanel asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); - s.append(asmdp.saveInXML()); - LinkedList<AvatarBDBlock> list = ((AvatarBDBlock)tgc).getFullBlockList(); - for(AvatarBDBlock b:list) { - asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), b.getValue()); - s.append(asmdp.saveInXML()); - } - } - - if (tgc instanceof AvatarBDLibraryFunction) { - AvatarSMDPanel asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), ((AvatarBDLibraryFunction) tgc).getFunctionName ()); - s.append(asmdp.saveInXML()); - } - - if (tgc instanceof TCDTClass) { - TActivityDiagramPanel tadp = mgui.getActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); - s.append(tadp.saveInXML()); - } - - if (tgc instanceof TOSClass) { - TURTLEOSActivityDiagramPanel tosadp = mgui.getTURTLEOSActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); - s.append(tosadp.saveInXML()); - } - - if (tgc instanceof TMLTaskOperator) { - TMLActivityDiagramPanel tmladp1 = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); - s.append(tmladp1.saveInXML()); - } - - if (tgc instanceof TMLCPrimitiveComponent) { - TMLActivityDiagramPanel tmladp2 = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), tgc.getValue()); - s.append(tmladp2.saveInXML()); - } - - if (tgc instanceof TMLCCompositeComponent) { - TMLActivityDiagramPanel tmladp3; - ArrayList<TMLCPrimitiveComponent> list = ((TMLCCompositeComponent)tgc).getAllPrimitiveComponents(); - for (TMLCPrimitiveComponent comp: list) { - tmladp3 = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), comp.getValue()); - s.append(tmladp3.saveInXML()); - } - } - - if (s == null) { - return null; - } - sb.append(s); - sb.append("\n\n"); - sb.append("</TURTLEGSELECTEDCOMPONENTS>"); - - str = new String(sb); - str = encodeString(str); - - return str; - } - - - public String makeXMLFromSelectedComponentOfADiagram(TDiagramPanel tdp, int copyMaxId, int _decX, int _decY) { - StringBuffer sb = new StringBuffer(); - //TraceManager.addDev("Making copy"); - - //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGSELECTEDCOMPONENTS "); - sb.append("version=\"" + DefaultText.getVersion()); - sb.append("\" copyMaxId=\"" + copyMaxId); - sb.append("\" decX=\"" + _decX); - sb.append("\" decY=\"" + _decY); - sb.append("\" >\n\n"); - - StringBuffer s; - String str; - - s = tdp.saveSelectedInXML(); - - Vector v = tdp.selectedTclasses(); - - if ((v != null) && (v.size() > 0)) { - TCDTClass t; - TActivityDiagramPanel tadp; - for(int i=0; i<v.size(); i++) { - t = (TCDTClass)(v.elementAt(i)); - tadp = mgui.getActivityDiagramPanel(mgui.getCurrentSelectedIndex(), t.getValue()); - s.append(tadp.saveInXML()); - } - } - - //Added by Solange - //bug removed by Emil - if (tdp instanceof ProactiveCSDPanel) - { - v=((ProactiveCSDPanel)tdp).selectedProCSDComponent(null); - if ((v != null) && (v.size() > 0)) { - ProCSDComponent t; - ProactiveSMDPanel psmd; - for(int i=0; i<v.size(); i++) { - t = (ProCSDComponent)(v.elementAt(i)); - psmd = mgui.getSMDPanel(mgui.getCurrentSelectedIndex(), t.getValue()); - if (psmd!=null) - s.append(psmd.saveInXML()); - } - } - } - //until here - - - v = tdp.selectedTURTLEOSClasses(); - if ((v != null) && (v.size() > 0)) { - //TraceManager.addDev("Saving TURTLEOS activity diagram Panel..."); - TOSClass t; - TURTLEOSActivityDiagramPanel tosadp; - for(int i=0; i<v.size(); i++) { - t = (TOSClass)(v.elementAt(i)); - tosadp = mgui.getTURTLEOSActivityDiagramPanel(mgui.getCurrentSelectedIndex(), t.getValue()); - s.append(tosadp.saveInXML()); - } - } - - v = tdp.selectedTMLTasks(); - if ((v != null) && (v.size() > 0)) { - //TraceManager.addDev("Saving TML activity diagram Panel..."); - TMLTaskOperator t; - TMLActivityDiagramPanel tmladp; - for(int i=0; i<v.size(); i++) { - t = (TMLTaskOperator)(v.elementAt(i)); - tmladp = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), t.getValue()); - s.append(tmladp.saveInXML()); - } - } - - v = tdp.selectedAvatarBDBlocks(); - if ((v != null) && (v.size() > 0)) { - //TraceManager.addDev("Saving TML activity diagram Panel..."); - AvatarBDBlock abdb; - AvatarSMDPanel asmdp; - for(int i=0; i<v.size(); i++) { - abdb = (AvatarBDBlock)(v.elementAt(i)); - asmdp = mgui.getAvatarSMDPanel(mgui.getCurrentSelectedIndex(), abdb.getBlockName()); - s.append(asmdp.saveInXML()); - - } - } - - v = tdp.selectedCPrimitiveComponent(); - if ((v != null) && (v.size() > 0)) { - //TraceManager.addDev("Saving TML activity diagram Panel..."); - TMLCPrimitiveComponent ct; - TMLActivityDiagramPanel tmladp; - for(int i=0; i<v.size(); i++) { - ct = (TMLCPrimitiveComponent)(v.elementAt(i)); - tmladp = mgui.getTMLActivityDiagramPanel(mgui.getCurrentSelectedIndex(), ct.getValue()); - s.append(tmladp.saveInXML()); - } - } - - if (s == null) { - return null; - } - sb.append(s); - sb.append("\n\n"); - sb.append("</TURTLEGSELECTEDCOMPONENTS>"); - - str = new String(sb); - str = encodeString(str); - - TraceManager.addDev("Copy done"); - //TraceManager.addDev(str); - - return str; - } - - public String makeOneDiagramXMLFromGraphicalModel(TURTLEPanel tp, int indexOfDiagram) { - StringBuffer sb = new StringBuffer(); - //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGMODELING version=\"" + DefaultText.getVersion() + "\">\n\n"); - - StringBuffer s; - String str; - - - s = tp.saveInXML(indexOfDiagram); - - sb.append(s); - sb.append("\n\n"); - - - sb.append("</TURTLEGMODELING>"); - - str = new String(sb); - str = encodeString(str); - - return str; - } - - public String makeXMLFromTurtleModeling(int index) { - StringBuffer sb = new StringBuffer(); - //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<TURTLEGMODELING>\n\n"); - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGMODELING version=\"" + DefaultText.getVersion() + "\">\n\n"); - - StringBuffer s; - String str; - - TURTLEPanel tp; - int i; - // search for diagram panels (Design) - for(i=0; i<panels.size(); i++) { - if ((index == -1) || (i == index)) { - tp = (TURTLEPanel)(panels.elementAt(i)); - s = tp.saveInXML(); - if (s == null) { - return null; - } - sb.append(s); - sb.append("\n\n"); - } - } - - sb.append("</TURTLEGMODELING>"); - - str = new String(sb); - str = encodeString(str); - - return str; - } - - public void removeAllComponents() { - TDiagramPanel tdp; - int i, j; - Vector panelss; - // search for diagram panels - for(i=0; i<panels.size(); i++) { - panelss = (Vector)(((TURTLEPanel)(panels.elementAt(i))).panels); - for(j=0; j<panelss.size(); j++) { - tdp = (TDiagramPanel)(panelss.elementAt(j)); - tdp.removeAll(); - } - } - } - - public void copyModelingFromXML(TDiagramPanel tdp, String s, int X, int Y) throws MalformedModelingException { - //TraceManager.addDev("copyModelingFromXML: " + s); - //TraceManager.addDev("tdp: " + tdp); - - //TraceManager.addDev(s); - //TraceManager.addDev("copyModelingFromXML:"); - //LinkedList ComponentsList=tdp.getComponentList(); - int beginIndex = tdp.getComponentList().size(); - - //Added by Solange - int cuenta=1; - - s = decodeString(s); - - //TraceManager.addDev("copy=" + s); - - ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); - if ((dbf == null) || (db == null)) { - throw new MalformedModelingException(); - } - - int i; - //int copyMaxId; - int _decX = 0, _decY = 0; - - try { - // building nodes from xml String - Document doc = db.parse(bais); - NodeList nl; - - decId = tdp.getMaxId() + 1; - TGComponent.setGeneralId(TGComponent.getGeneralId() + decId + 2); - nl = doc.getElementsByTagName("TURTLEGSELECTEDCOMPONENTS"); - - if (nl == null) { - return; - } - - Node adn; - Element elt; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - _decX = X - Integer.decode(elt.getAttribute("decX")).intValue(); - _decY = Y - Integer.decode(elt.getAttribute("decY")).intValue(); - //copyMaxId = Integer.decode(elt.getAttribute("copyMaxId")).intValue(); - } - } - - // Managing diagrams - if (tdp instanceof TClassDiagramPanel) { - TraceManager.addDev("TClassDiagramPanel copy"); - - nl = doc.getElementsByTagName("TClassDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - - TClassDiagramPanel tcdp = (TClassDiagramPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tcdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - tcdp.loadExtraParameters(elt); - - //TraceManager.addDev("Class diagram : " + tcdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tcdp); - makePostProcessing(tcdp); - //TraceManager.addDev("Class diagram : " + tcdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tcdp); - //TraceManager.addDev("Class diagram : " + tcdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tcdp); - //TraceManager.addDev("Class diagram : " + tcdp.getName() + " real points"); - connectConnectorsToRealPoints(tcdp); - tcdp.structureChanged(); - //TraceManager.addDev("Class diagram : " + tcdp.getName() + " post loading " + beginIndex); - makePostLoading(tcdp, beginIndex); - //TraceManager.addDev("Class diagram : " + tcdp.getName() + " post loading done"); - } - } - docCopy = null; - - } else if (tdp instanceof TActivityDiagramPanel) { - TraceManager.addDev("TActivityDiagramPanel copy"); - nl = doc.getElementsByTagName("TActivityDiagramPanelCopy"); - - if (nl == null) { - return; - } - - TActivityDiagramPanel tadp = (TActivityDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tadp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - tadp.loadExtraParameters(elt); - - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(tadp); - tadp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(tadp, beginIndex); - } - } - } else if (tdp instanceof InteractionOverviewDiagramPanel) { - - nl = doc.getElementsByTagName("InteractionOverviewDiagramPanelCopy"); - - if (nl == null) { - return; - } - - InteractionOverviewDiagramPanel iodp = (InteractionOverviewDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (iodp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), iodp); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), iodp); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), iodp); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " real points"); - connectConnectorsToRealPoints(iodp); - iodp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); - makePostLoading(iodp, beginIndex); - } - } - } else if (tdp instanceof SequenceDiagramPanel) { - //TraceManager.addDev("Sequence diagram!"); - nl = doc.getElementsByTagName("SequenceDiagramPanelCopy"); - - if (nl == null) { - return; - } - - SequenceDiagramPanel sdp = (SequenceDiagramPanel)tdp; - - //TraceManager.addDev("Sequence diagram!"); - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (sdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), sdp); - //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), sdp); - //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), sdp); - //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " real points"); - connectConnectorsToRealPoints(sdp); - sdp.structureChanged(); - //TraceManager.addDev("Sequence diagram: " + sdp.getName() + " post loading"); - makePostLoading(sdp, beginIndex); - } - } - } else if (tdp instanceof UseCaseDiagramPanel) { - nl = doc.getElementsByTagName("UseCaseDiagramPanelCopy"); - - if (nl == null) { - return; - } - - UseCaseDiagramPanel ucdp = (UseCaseDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (ucdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ucdp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ucdp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ucdp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " real points"); - connectConnectorsToRealPoints(ucdp); - ucdp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); - makePostLoading(ucdp, beginIndex); - } - } - } else if (tdp instanceof TDeploymentDiagramPanel) { - nl = doc.getElementsByTagName("TDeploymentDiagramPanelCopy"); - - if (nl == null) { - return; - } - - TDeploymentDiagramPanel tddp = (TDeploymentDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tddp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tddp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tddp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tddp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " real points"); - connectConnectorsToRealPoints(tddp); - tddp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); - makePostLoading(tddp, beginIndex); - } - } - } else if (tdp instanceof NCDiagramPanel) { - nl = doc.getElementsByTagName("NCDiagramPanelCopy"); - - if (nl == null) { - return; - } - - NCDiagramPanel ncdp = (NCDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (ncdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ncdp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ncdp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ncdp); - //TraceManager.addDev("Activity diagram : " + sdp.getName() + " real points"); - connectConnectorsToRealPoints(ncdp); - ncdp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + iodp.getName() + " post loading"); - makePostLoading(ncdp, beginIndex); - } - } - } else if (tdp instanceof RequirementDiagramPanel) { - nl = doc.getElementsByTagName("TRequirementDiagramPanelCopy"); - - if (nl == null) { - return; - } - - RequirementDiagramPanel rdp = (RequirementDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (rdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), rdp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), rdp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), rdp); - connectConnectorsToRealPoints(rdp); - rdp.structureChanged(); - makePostLoading(rdp, beginIndex); - } - } - } else if (tdp instanceof EBRDDPanel) { - nl = doc.getElementsByTagName("EBRDDPanelCopy"); - - if (nl == null) { - return; - } - - EBRDDPanel ebrddp = (EBRDDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (ebrddp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ebrddp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ebrddp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ebrddp); - connectConnectorsToRealPoints(ebrddp); - ebrddp.structureChanged(); - makePostLoading(ebrddp, beginIndex); - } - } - } else if (tdp instanceof AttackTreeDiagramPanel) { - nl = doc.getElementsByTagName("AttackTreeDiagramPanelCopy"); - - if (nl == null) { - return; - } - - AttackTreeDiagramPanel atdp = (AttackTreeDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (atdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), atdp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), atdp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), atdp); - connectConnectorsToRealPoints(atdp); - atdp.structureChanged(); - makePostLoading(atdp, beginIndex); - } - } - } else if (tdp instanceof TMLTaskDiagramPanel) { - nl = doc.getElementsByTagName("TMLTaskDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - TMLTaskDiagramPanel tmltdp = (TMLTaskDiagramPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmltdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - tmltdp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmltdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(tmltdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmltdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmltdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(tmltdp); - tmltdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(tmltdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - }else if (tdp instanceof DiplodocusMethodologyDiagramPanel) { - nl = doc.getElementsByTagName("DiplodocusMethodologyDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - DiplodocusMethodologyDiagramPanel tmltdp = (DiplodocusMethodologyDiagramPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmltdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - tmltdp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmltdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(tmltdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmltdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmltdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(tmltdp); - tmltdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(tmltdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - - - }else if (tdp instanceof AvatarMethodologyDiagramPanel) { - nl = doc.getElementsByTagName("AvatarMethodologyDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - AvatarMethodologyDiagramPanel amdp = (AvatarMethodologyDiagramPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (amdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - amdp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), amdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(amdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), amdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), amdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(amdp); - amdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(amdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - }else if (tdp instanceof SysmlsecMethodologyDiagramPanel) { - nl = doc.getElementsByTagName("SysmlsecMethodologyDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - SysmlsecMethodologyDiagramPanel amdp = (SysmlsecMethodologyDiagramPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (amdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - amdp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), amdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(amdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), amdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), amdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(amdp); - amdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(amdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - } else if (tdp instanceof TMLComponentTaskDiagramPanel) { - nl = doc.getElementsByTagName("TMLComponentTaskDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - TMLComponentTaskDiagramPanel tmlctdp = (TMLComponentTaskDiagramPanel)tdp; - //tmlctdp.updateReferences(); - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmlctdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - tmlctdp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmlctdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(tmlctdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmlctdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmlctdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(tmlctdp); - tmlctdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(tmlctdp, beginIndex); - tmlctdp.hideConnectors(); - tmlctdp.updatePorts(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - tmlctdp.updatePorts(); - } else if (tdp instanceof TMLActivityDiagramPanel) { - nl = doc.getElementsByTagName("TMLActivityDiagramPanelCopy"); - - if (nl == null) { - return; - } - - TMLActivityDiagramPanel tmladp = (TMLActivityDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmladp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //tmladp.loadExtraParameters(elt); - - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmladp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmladp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmladp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(tmladp); - tmladp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(tmladp, beginIndex); - } - } - } else if (tdp instanceof TMLCPPanel) { - nl = doc.getElementsByTagName("CommunicationPatternDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - TMLCPPanel tmlcpp = (TMLCPPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmlcpp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //tmlcpp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmlcpp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(tmlcpp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmlcpp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmlcpp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(tmlcpp); - tmlcpp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(tmlcpp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - } else if (tdp instanceof TMLSDPanel) { - nl = doc.getElementsByTagName("TMLSDPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - TMLSDPanel tmlsdp = (TMLSDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmlsdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //tmlcpp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmlsdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(tmlsdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmlsdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmlsdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(tmlsdp); - tmlsdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(tmlsdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - } else if (tdp instanceof TMLArchiDiagramPanel) { - nl = doc.getElementsByTagName("TMLArchiDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - TMLArchiDiagramPanel tmadp = (TMLArchiDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tmadp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - tmadp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmadp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(tmadp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmadp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmadp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(tmadp); - tmadp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(tmadp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - } else if (tdp instanceof TURTLEOSClassDiagramPanel) { - nl = doc.getElementsByTagName("TURTLEOSClassDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - TURTLEOSClassDiagramPanel toscdp = (TURTLEOSClassDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (toscdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //toscdp.loadExtraParameters(elt); - //TraceManager.addDev("Toto 2"); - //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), toscdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(toscdp); - //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), toscdp); - //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), toscdp); - //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " real points"); - connectConnectorsToRealPoints(toscdp); - toscdp.structureChanged(); - //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " post loading " + beginIndex); - makePostLoading(toscdp, beginIndex); - //TraceManager.addDev("TURTLEOS task diagram : " + toscdp.getName() + " post loading done"); - } - } - } else if (tdp instanceof TURTLEOSActivityDiagramPanel) { - nl = doc.getElementsByTagName("TURTLEOSActivityDiagramPanelCopy"); - - if (nl == null) { - return; - } - - TURTLEOSActivityDiagramPanel tosadp = (TURTLEOSActivityDiagramPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (tosadp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //tmladp.loadExtraParameters(elt); - - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tosadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tosadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tosadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(tosadp); - tosadp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(tosadp, beginIndex); - } - } - } else if (tdp instanceof ProactiveCSDPanel) { - //cuenta=beginIndex+1; - cuenta=mgui.tabs.size()-1; - nl = doc.getElementsByTagName("ProactiveCSDPanelCopy"); - if (nl.getLength()==0) - { - nl=doc.getElementsByTagName("ProactiveCSDPanel"); - } - docCopy = doc; - if (nl == null) - { - return; - } - ProactiveCSDPanel pcsdp = (ProactiveCSDPanel)tdp; - for(i=0; i<nl.getLength(); i++) - { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) - { - elt = (Element) adn; - if (pcsdp == null) - { - throw new MalformedModelingException(); - } - - - // int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //pcsdp.loadExtraParameters(elt); - //TraceManager.addDev("Toto 2"); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), pcsdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(pcsdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), pcsdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), pcsdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(pcsdp); - pcsdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(pcsdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - // Added by Solange - nl = doc.getElementsByTagName("ProactiveSMDPanel"); - if (nl == null) - { - return; - } - String name=""; - ProactiveSMDPanel psmdp; - for(i=0; i<nl.getLength(); i++) //Erased cuenta++ by Solange at the end condition of the for - { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) - { - elt = (Element) adn; - name=elt.getAttribute("name"); - //Added by Solange name at the beginning and cuenta - name=mgui.createProActiveSMD(cuenta,name); - psmdp=mgui.getSMDPanel(cuenta, name); - if (psmdp == null) - { - throw new MalformedModelingException(); - } - - // int xSel = Integer.decode(elt.getAttribute("minX")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("maxX")).intValue(); // - mgui.getCurrentTDiagramPanel().currentX; - // int widthSel = Integer.decode(elt.getAttribute("minY")).intValue(); // - mgui.getCurrentTDiagramPanel().currentY;; - // int heightSel = Integer.decode(elt.getAttribute("maxY")).intValue(); // - mgui.getCurrentTDiagramPanel().currentY;; - - decX = _decX; - decY = _decY; - - //tmladp.loadExtraParameters(elt); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), psmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), psmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), psmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(psmdp); - psmdp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(psmdp, beginIndex); - //until here - } - } - } else if (tdp instanceof ProactiveSMDPanel) { - //Changed by Solange, before it was like the first line - //nl = doc.getElementsByTagName("ProactiveSMDPanelCopy"); - nl = doc.getElementsByTagName("ProactiveSMDPanelCopy"); - - if (nl == null) { - return; - } - - ProactiveSMDPanel psmdp = (ProactiveSMDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (psmdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //tmladp.loadExtraParameters(elt); - - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), psmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), psmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), psmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(psmdp); - psmdp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(psmdp, beginIndex); - } - } - - // AVATAR - } else if (tdp instanceof AvatarBDPanel) { - nl = doc.getElementsByTagName("AVATARBlockDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - AvatarBDPanel abdp = (AvatarBDPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (abdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - abdp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), abdp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(abdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), abdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), abdp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(abdp); - abdp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(abdp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - - - } else if (tdp instanceof ADDDiagramPanel) { - nl = doc.getElementsByTagName("ADDDiagramPanelCopy"); - docCopy = doc; - - if (nl == null) { - return; - } - - //TraceManager.addDev("Toto 1"); - - - ADDDiagramPanel addp = (ADDDiagramPanel)tdp; - - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (addp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - addp.loadExtraParameters(elt); - - //TraceManager.addDev("Toto 2"); - - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), addp); - //TraceManager.addDev("Toto 3"); - makePostProcessing(addp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), addp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), addp); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " real points"); - connectConnectorsToRealPoints(addp); - addp.structureChanged(); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading " + beginIndex); - makePostLoading(addp, beginIndex); - //TraceManager.addDev("TML task diagram : " + tmltdp.getName() + " post loading done"); - } - } - - } else if (tdp instanceof AvatarSMDPanel) { - nl = doc.getElementsByTagName("AVATARStateMachineDiagramPanelCopy"); - - if (nl == null) { - return; - } - - AvatarSMDPanel asmdp = (AvatarSMDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (asmdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - //tmladp.loadExtraParameters(elt); - - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), asmdp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), asmdp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), asmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(asmdp); - asmdp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(asmdp, beginIndex); - } - } - } else if (tdp instanceof AvatarRDPanel) { - nl = doc.getElementsByTagName("AvatarRDPanelCopy"); - - if (nl == null) { - return; - } - - AvatarRDPanel ardp = (AvatarRDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (ardp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), ardp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), ardp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), ardp); - connectConnectorsToRealPoints(ardp); - ardp.structureChanged(); - makePostLoading(ardp, beginIndex); - } - } - - } else if (tdp instanceof AvatarMADPanel) { - nl = doc.getElementsByTagName("AvatarMADPanelCopy"); - - if (nl == null) { - return; - } - - AvatarMADPanel amadp = (AvatarMADPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (amadp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), amadp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), amadp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), amadp); - connectConnectorsToRealPoints(amadp); - amadp.structureChanged(); - makePostLoading(amadp, beginIndex); - } - } - - } else if (tdp instanceof AvatarPDPanel) { - nl = doc.getElementsByTagName("AvatarPDPanelCopy"); - - if (nl == null) { - return; - } - - AvatarPDPanel apdp = (AvatarPDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (apdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), apdp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), apdp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), apdp); - connectConnectorsToRealPoints(apdp); - apdp.structureChanged(); - makePostLoading(apdp, beginIndex); - } - } - - } else if (tdp instanceof AvatarCDPanel) { - nl = doc.getElementsByTagName("AvatarCDPanelCopy"); - - if (nl == null) { - return; - } - - AvatarCDPanel acdp = (AvatarCDPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (acdp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), acdp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), acdp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), acdp); - connectConnectorsToRealPoints(acdp); - acdp.structureChanged(); - makePostLoading(acdp, beginIndex); - } - } - } else if (tdp instanceof AvatarADPanel) { - nl = doc.getElementsByTagName("AvatarADPanelCopy"); - - if (nl == null) { - return; - } - - AvatarADPanel aadp = (AvatarADPanel)tdp; - - for(i=0; i<nl.getLength(); i++) { - adn = nl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - - if (aadp == null) { - throw new MalformedModelingException(); - } - - //int xSel = Integer.decode(elt.getAttribute("xSel")).intValue(); - //int ySel = Integer.decode(elt.getAttribute("ySel")).intValue(); - //int widthSel = Integer.decode(elt.getAttribute("widthSel")).intValue(); - //int heightSel = Integer.decode(elt.getAttribute("heightSel")).intValue(); - - decX = _decX; - decY = _decY; - - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), aadp); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), aadp); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), aadp); - connectConnectorsToRealPoints(aadp); - aadp.structureChanged(); - makePostLoading(aadp, beginIndex); - } - } - } - - } catch (IOException e) { - TraceManager.addError("Loading 500: " + e.getMessage()); - throw new MalformedModelingException(); - } catch (SAXException saxe) { - TraceManager.addError("Loading 501 " + saxe.getMessage()); - throw new MalformedModelingException(); - } - } - - // Returns null if s is not a saved TURTLE modeling of an older format - public String upgradeSaved(String s) { - int index1, index2, index3; - StringBuffer sb = new StringBuffer("");; - //String tmp; - - index1 = s.indexOf("<TClassDiagramPanel"); - index2 = s.indexOf("<InteractionOverviewDiagramPanel "); - index3 = s.indexOf("</TURTLEGMODELING>"); - - if ((index1 <0) ||(index3 < 0)){ - return null; - } - - sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n<TURTLEGMODELING version=\"" + DefaultText.getVersion() + "\">\n\n"); - - if (index2 > -1) { - sb.append("<Modeling type=\"Analysis\" nameTab=\"Analysis\" >\n"); - sb.append(s.substring(index2, index3)); - sb.append("</Modeling>\n\n"); - } - - if (index2 < 0) { - index2 = index3; - } - sb.append("<Modeling type=\"Design\" nameTab=\"Design\" >\n"); - sb.append(s.substring(index1, index2)); - sb.append("</Modeling>\n\n"); - - sb.append(s.substring(index3, s.length())); - - //TraceManager.addDev("Got:" + sb); - - return sb.toString(); - } - - public void loadModelingFromXML(String s) throws MalformedModelingException { - - if (s == null) { - return; - } - - s = decodeString(s); - - decX = 0; - decY = 0; - decId = 0; - TGComponent.setGeneralId(100000); - - ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); - - if ((dbf == null) || (db == null)) { - throw new MalformedModelingException(); - } - - try { - // building nodes from xml String - Document doc = db.parse(bais); - NodeList panelNl; - //NodeList designPanelNl; - //NodeList analysisNl; - - int i; - //Element elt; - Node node; - - // Managing design panels - panelNl = doc.getElementsByTagName("Modeling"); - - if (panelNl.getLength() == 0) { - // Modeling saved in old format? - s = upgradeSaved(s); - if (s != null) { - JOptionPane.showMessageDialog(mgui.frame, "The modeling has been converted to this new version of TTool", "Loading information", JOptionPane.INFORMATION_MESSAGE); - } - loadModelingFromXML(s); - return; - - } - //designPanelNl = doc.getElementsByTagName("Design"); - //analysisNl = doc.getElementsByTagName("Analysis"); - - pendingConnectors = new ArrayList<TGConnectorInfo>(); - - //TraceManager.addDev("nb de design=" + designPanelNl.getLength() + " nb d'analyse=" + analysisNl.getLength()); - boolean error = false; - for(i=0; i<panelNl.getLength(); i++) { - node = panelNl.item(i); - //TraceManager.addDev("Node = " + dnd); - - if (node.getNodeType() == Node.ELEMENT_NODE) { - // create design, and get an index for it - try { - loadModeling(node); - } catch (MalformedModelingException mme) { - Element elt = (Element) node; - String type = elt.getAttribute("type"); - TraceManager.addDev("Error when loading diagram: " + elt + " " +type); - error = true; - } - } - } - if (error == true) { - throw new MalformedModelingException(); - } - - } catch (NumberFormatException nfe) { - TraceManager.addError("Loading 400 " + nfe.getMessage()); - throw new MalformedModelingException(); - } catch (IOException e) { - TraceManager.addError("Loading 600 " + e.getMessage()); - throw new MalformedModelingException(); - } catch (SAXException saxe) { - TraceManager.addError("Loading 601 " + saxe.getMessage()); - throw new MalformedModelingException(); - } - //TraceManager.addDev("making IDs"); - makeLastLoad(); - makeLovelyIds(); - //TraceManager.addDev("IDs done"); - } - - public void loadModeling(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String type = elt.getAttribute("type"); - // AVATAR - if (type.compareTo("ADD") == 0) { - loadAvatarDeployment(node); - } else if (type.compareTo("AVATAR Design") == 0) { - loadAvatarDesign(node); - } else if (type.compareTo("Avatar Requirement") == 0) { - loadAvatarRequirement(node); - } else if (type.compareTo("Avatar MAD") == 0) { - loadAvatarMADs(node); - } else if (type.compareTo("Avatar Analysis") == 0) { - loadAvatarAnalysis(node); - - - // TURTLE - } else if (type.compareTo("Design") == 0) { - loadDesign(node); - } else if (type.compareTo("Analysis") == 0) { - loadAnalysis(node); - } else if (type.compareTo("Deployment") == 0) { - loadDeployment(node); - } else if (type.compareTo("NC diagram") == 0) { - loadNC(node); - } else if (type.compareTo("Requirement") == 0) { - loadRequirement(node); - } else if (type.compareTo("AttackTree") == 0) { - loadAttackTree(node); - } else if (type.compareTo("Diplodocus Methodology") == 0) { - loadDiplodocusMethodology(node); - } else if (type.compareTo("Avatar Methodology") == 0) { - loadAvatarMethodology(node); - } else if (type.compareTo("Sysmlsec Methodology") == 0) { - loadSysmlsecMethodology(node); - } else if (type.compareTo("TML Design") == 0) { - loadTMLDesign(node); - } else if (type.compareTo("TML Component Design") == 0) { - loadTMLComponentDesign(node); - } else if (type.compareTo("TML CP") == 0) { - loadTMLCP(node); - } else if (type.compareTo("TML Architecture") == 0) { - loadTMLArchitecture(node); - } else if (type.compareTo("TURTLE-OS Design") == 0) { - loadTURTLEOSDesign(node); - } else if (type.compareTo("ProActive Design") == 0) { - loadProActiveDesign(node); - } else { - throw new MalformedModelingException(); - } - } - - public void loadAvatarDesign(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createAvatarDesign(nameTab); - - diagramNl = node.getChildNodes(); - - /* First load all Block diagrams, then all state machines - * This is done this way so that state machines can rely on - * informations provided by blocks. For instance we can check - * that an attribute used in a state machine really exists. - */ - for(int j=0; j<diagramNl.getLength(); j++) { - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) node; - if (elt.getTagName().compareTo("AVATARBlockDiagramPanel") == 0) - // Class diagram - loadAvatarBD(elt, indexDesign); - } - } - for(int j=0; j<diagramNl.getLength(); j++) { - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) node; - if (elt.getTagName().compareTo("AVATARStateMachineDiagramPanel") == 0) - // Managing activity diagrams - loadAvatarSMD(elt, indexDesign); - } - } - } - - public void loadAvatarDeployment(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexReq; - int cpt_req = 0; - - TraceManager.addDev("Loading ADD 0"); - - nameTab = elt.getAttribute("nameTab"); - - indexReq = mgui.createADD(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Deployment nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("ADDDiagramPanel") == 0) { - TraceManager.addDev("Loading ADD 1"); - loadADDDiagram(elt, indexReq, cpt_req); - cpt_req ++; - } - } - } - } - - public void loadAvatarRequirement(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexReq; - int cpt_req = 0; - - - nameTab = elt.getAttribute("nameTab"); - - indexReq = mgui.createAvatarRequirement(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Deployment nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("AvatarRDPanel") == 0) { - loadAvatarRD(elt, indexReq, cpt_req); - cpt_req ++; - } else if (elt.getTagName().compareTo("AvatarPDPanel") == 0) { - loadAvatarPD(elt, indexReq, cpt_req); - cpt_req ++; - } - } - } - } - - public void loadAttackTree(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexTree; - int cpttdp = 0; - - - nameTab = elt.getAttribute("nameTab"); - - indexTree = mgui.createAttackTree(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Deployment nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("AttackTreeDiagramPanel") == 0) { - loadAttackTreeDiagram(elt, indexTree, cpttdp); - cpttdp ++; - } - } - } - } - - public void loadAvatarMADs(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexReq; - int cpt_req = 0; - - - nameTab = elt.getAttribute("nameTab"); - - TraceManager.addDev("Creating MAD panel "); - - indexReq = mgui.createAvatarMADs(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - TraceManager.addDev("MADs nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("AvatarMADPanel") == 0) { - loadAvatarMAD(elt, indexReq, cpt_req); - cpt_req ++; - } - } - } - } - - public void loadDesign(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createDesign(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TClassDiagramPanel") == 0) { - // Class diagram - loadTClassDiagram(elt, indexDesign); - } else { // Managing activity diagrams - if (elt.getTagName().compareTo("TActivityDiagramPanel") == 0) { - // Managing activity diagrams - loadTActivityDiagram(elt, indexDesign); - } - } - } - } - } - - public void loadAnalysis(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexAnalysis; - int cpt = 0; - - nameTab = elt.getAttribute("nameTab"); - - indexAnalysis = mgui.createAnalysis(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("InteractionOverviewDiagramPanel") == 0) { - // IOD - loadIODiagram(elt, indexAnalysis); - cpt ++; - } else { // Managing sequence diagrams - if (elt.getTagName().compareTo("SequenceDiagramPanel") == 0) { - loadSequenceDiagram(elt, indexAnalysis); - cpt ++; - } else if (elt.getTagName().compareTo("UseCaseDiagramPanel") == 0) { - // Managing use case diagrams - loadUseCaseDiagram(elt, indexAnalysis, cpt); - cpt ++; - } /*else if (elt.getTagName().compareTo("AvatarCDPanel") == 0) { - // Managing use case diagrams - loadAvatarCD(elt, indexAnalysis, cpt); - cpt ++; - } else if (elt.getTagName().compareTo("AvatarADPanel") == 0) { - // Managing use case diagrams - loadAvatarAD(elt, indexAnalysis, cpt); - cpt ++; - }*/ - } - } - } - } - - public void loadTMLCP(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexTMLCP; - int cpt = 0; - - nameTab = elt.getAttribute("nameTab"); - - indexTMLCP = mgui.createTMLCP(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("CommunicationPatternDiagramPanel") == 0) { - // CP - loadTMLCPDiagram(elt, indexTMLCP); - cpt ++; - } else { // Managing sequence diagrams - if (elt.getTagName().compareTo("TMLSDPanel") == 0) { - loadTMLSDDiagram(elt, indexTMLCP); - cpt ++; - } - } - } - } - } - - public void loadAvatarAnalysis(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexAnalysis; - int cpt = 0; - - //TraceManager.addDev("Loading Avatar analysis"); - - nameTab = elt.getAttribute("nameTab"); - - indexAnalysis = mgui.createAvatarAnalysis(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - - if (elt.getTagName().compareTo("SequenceDiagramPanel") == 0) { - //TraceManager.addDev("Loading seq diag"); - loadSequenceDiagram(elt, indexAnalysis); - //TraceManager.addDev("Loading seq diag done"); - cpt ++; - } else if (elt.getTagName().compareTo("UseCaseDiagramPanel") == 0) { - // Managing use case diagrams - //TraceManager.addDev("Loading ucd diag"); - loadUseCaseDiagram(elt, indexAnalysis, cpt); - //TraceManager.addDev("Loading ucd diag done"); - - cpt ++; - } else if (elt.getTagName().compareTo("AvatarCDPanel") == 0) { - // Managing use case diagrams - //TraceManager.addDev("Loading cd diag"); - loadAvatarCD(elt, indexAnalysis, cpt); - //TraceManager.addDev("Loading cd diag done"); - cpt ++; - } else if (elt.getTagName().compareTo("AvatarADPanel") == 0) { - // Managing use case diagrams - //TraceManager.addDev("Loading ad diag"); - loadAvatarAD(elt, indexAnalysis, cpt); - //TraceManager.addDev("Loading ad diag done"); - cpt ++; - } - - } - } - } - - public void loadDeployment(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexAnalysis; - - - nameTab = elt.getAttribute("nameTab"); - - indexAnalysis = mgui.createDeployment(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Deployment nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TDeploymentDiagramPanel") == 0) { - // IOD - loadTDeploymentDiagram(elt, indexAnalysis); - } - } - } - } - - public void loadNC(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexAnalysis; - - - nameTab = elt.getAttribute("nameTab"); - - indexAnalysis = mgui.createNC(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Deployment nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("NCDiagramPanel") == 0) { - // IOD - loadNCDiagram(elt, indexAnalysis); - } - } - } - } - - public void loadRequirement(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexReq; - int cpt_req = 0; - - - nameTab = elt.getAttribute("nameTab"); - - indexReq = mgui.createRequirement(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Deployment nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TRequirementDiagramPanel") == 0) { - loadRequirementDiagram(elt, indexReq, cpt_req); - cpt_req ++; - } else if (elt.getTagName().compareTo("EBRDDPanel") == 0) { - loadEBRDD(elt, indexReq, cpt_req); - cpt_req ++; - } - } - } - } - - - - public void loadDiplodocusMethodology(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createDiplodocusMethodology(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("DiplodocusMethodologyDiagramPanel") == 0) { - // Class diagram - //TraceManager.addDev("Loading TML CD"); - loadDiplodocusMethodologyDiagram(elt, indexDesign); - //TraceManager.addDev("End loading TML CD"); - } - } - } - } - - public void loadAvatarMethodology(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createAvatarMethodology(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("AvatarMethodologyDiagramPanel") == 0) { - // Class diagram - TraceManager.addDev("Loading Avatar methodo"); - loadAvatarMethodologyDiagram(elt, indexDesign); - TraceManager.addDev("End Loading avatar methodo"); - } - } - } - } - - public void loadSysmlsecMethodology(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createSysmlsecMethodology(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("SysmlsecMethodologyDiagramPanel") == 0) { - // Class diagram - TraceManager.addDev("Loading SysMLSec methodo"); - loadSysmlsecMethodologyDiagram(elt, indexDesign); - TraceManager.addDev("End loading SysMLSec methodo"); - } - } - } - } - - public void loadTMLDesign(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createTMLDesign(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TMLTaskDiagramPanel") == 0) { - // Class diagram - //TraceManager.addDev("Loading TML CD"); - loadTMLTaskDiagram(elt, indexDesign); - //TraceManager.addDev("End loading TML CD"); - } else { // Managing activity diagrams - if (elt.getTagName().compareTo("TMLActivityDiagramPanel") == 0) { - // Managing activity diagrams - //TraceManager.addDev("Loading TML AD"); - loadTMLActivityDiagram(elt, indexDesign); - } - } - } - } - } - - public void loadTMLComponentDesign(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createTMLComponentDesign(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TMLComponentTaskDiagramPanel") == 0) { - // Component diagram - //TraceManager.addDev("Loading TML Component diagram"); - loadTMLComponentTaskDiagram(elt, indexDesign); - //TraceManager.addDev("End loading TML CD"); - } else { // Managing activity diagrams - if (elt.getTagName().compareTo("TMLActivityDiagramPanel") == 0) { - // Managing activity diagrams - //TraceManager.addDev("Loading TML AD"); - loadTMLActivityDiagram(elt, indexDesign); - } - } - } - } - } - - public void loadTMLArchitecture(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createTMLArchitecture(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - TraceManager.addDev("TML Architecture nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TMLArchiDiagramPanel") == 0) { - TraceManager.addDev("Loading TML DD" + elt.getTagName() ); - loadTMLArchitectureDiagram(elt, indexDesign); - TraceManager.addDev("End loading TML DD"); - } - } - } - } - - public void loadTURTLEOSDesign(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createTURTLEOSDesign(nameTab); - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("TURTLEOSClassDiagramPanel") == 0) { - // Class diagram - //TraceManager.addDev("Loading TURTLEOS CD"); - loadTURTLEOSClassDiagram(elt, indexDesign); - //TraceManager.addDev("End loading TML CD"); - } else { // Managing activity diagrams - if (elt.getTagName().compareTo("TURTLEOSActivityDiagramPanel") == 0) { - // Managing activity diagrams - //TraceManager.addDev("Loading TURTLEOS AD"); - loadTURTLEOSActivityDiagram(elt, indexDesign); - } - } - } - } - } - - public void loadProActiveDesign(Node node) throws MalformedModelingException, SAXException { - Element elt = (Element) node; - String nameTab; - NodeList diagramNl; - int indexDesign; - - - nameTab = elt.getAttribute("nameTab"); - - indexDesign = mgui.createProActiveDesign(nameTab); - - - diagramNl = node.getChildNodes(); - - for(int j=0; j<diagramNl.getLength(); j++) { - //TraceManager.addDev("Design nodes: " + j); - node = diagramNl.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - if (elt.getTagName().compareTo("ProactiveCSDPanel") == 0) { - // Class diagram - //TraceManager.addDev("Loading TML CD"); - loadProactiveCSD(elt, indexDesign); - //TraceManager.addDev("End loading TML CD"); - } else { // Managing activity diagrams - if (elt.getTagName().compareTo("ProactiveSMDPanel") == 0) { - // Managing activity diagrams - //TraceManager.addDev("Loading TML AD"); - loadProactiveSMD(elt, indexDesign); - } - } - } - } - } - - public void loadDiagram(Element elt, TDiagramPanel tdp) throws MalformedModelingException, SAXException { - int x, y; - double zoom = 0; - try { - x = Integer.decode(elt.getAttribute("minX")).intValue(); - tdp.setMinX(x); - x = Integer.decode(elt.getAttribute("maxX")).intValue(); - tdp.setMaxX(x); - y = Integer.decode(elt.getAttribute("minY")).intValue(); - tdp.setMinY(y); - y = Integer.decode(elt.getAttribute("maxY")).intValue(); - tdp.setMaxY(y); - tdp.updateSize(); - zoom = Double.parseDouble(elt.getAttribute("zoom")); - if (zoom != 0) { - tdp.setZoom(zoom); - mgui.updateZoomInfo(); - } - } catch (Exception e) { - // Model was saved in an older version of TTool - } - - // for TClassdiagram Panel - if (tdp instanceof TClassDiagramPanel) { - ((TClassDiagramPanel)tdp).loadExtraParameters(elt); - } - - if (tdp instanceof TActivityDiagramPanel) { - ((TActivityDiagramPanel)tdp).loadExtraParameters(elt); - } - - if (tdp instanceof TMLTaskDiagramPanel) { - ((TMLTaskDiagramPanel)tdp).loadExtraParameters(elt); - } - - if (tdp instanceof TMLComponentTaskDiagramPanel) { - ((TMLComponentTaskDiagramPanel)tdp).loadExtraParameters(elt); - } - - if (tdp instanceof TMLArchiDiagramPanel) { - ((TMLArchiDiagramPanel)tdp).loadExtraParameters(elt); - } - - - if (tdp instanceof AvatarBDPanel) { - ((AvatarBDPanel)tdp).loadExtraParameters(elt); - } - - //TraceManager.addDev("Element" + elt.toString()); - // Loads components of the class diagram - //TraceManager.addDev("Components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tdp); - //TraceManager.addDev("Post processing"); - makePostProcessing(tdp); - //TraceManager.addDev("Connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tdp); - //TraceManager.addDev("Subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tdp); - //TraceManager.addDev("RealPoints"); - connectConnectorsToRealPoints(tdp); - //TraceManager.addDev("Structure changed"); - tdp.structureChanged(); - //TraceManager.addDev("Post loading"); - makePostLoading(tdp, 0); - - //TraceManager.addDev("Test connectors"); - if (tdp instanceof TMLComponentTaskDiagramPanel) { - //TraceManager.addDev("Connectors..."); - ((TMLComponentTaskDiagramPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof EBRDDPanel) { - //TraceManager.addDev("Connectors..."); - ((EBRDDPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof AttackTreeDiagramPanel) { - //TraceManager.addDev("Connectors..."); - ((AttackTreeDiagramPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof AvatarBDPanel) { - //TraceManager.addDev("Connectors..."); - ((AvatarBDPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof AvatarSMDPanel) { - //TraceManager.addDev("Connectors..."); - ((AvatarSMDPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof AvatarPDPanel) { - //TraceManager.addDev("Connectors..."); - ((AvatarPDPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof AvatarCDPanel) { - //TraceManager.addDev("Connectors..."); - ((AvatarCDPanel)tdp).setConnectorsToFront(); - } - - if (tdp instanceof AvatarADPanel) { - //TraceManager.addDev("Connectors..."); - ((AvatarADPanel)tdp).setConnectorsToFront(); - } - } + name = elt.getAttribute("name"); + mgui.createAvatarMAD(indexAnalysis, name); - // AVATAR - public void loadAvatarBD(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - String name; - TDiagramPanel tdp; + TDiagramPanel tdp = mgui.getAvatarMADPanel(indexAnalysis, indexTab, name); - // class diagram name - name = elt.getAttribute("name"); - mgui.setAvatarBDName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - - loadDiagram(elt, tdp); - } - - public void loadAvatarSMD(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - //TraceManager.addDev("Loading SMD of:" + name); - AvatarSMDPanel asmdp = mgui.getAvatarSMDPanel(indexDesign, name); - - if (asmdp == null) { - throw new MalformedModelingException(); - } - - asmdp.removeAll(); - - mgui.selectDummyTab (indexDesign); - loadDiagram(elt, asmdp); - mgui.forgetDummyTab (); - } - - public void loadAvatarRD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createAvatarRD(indexAnalysis, name); - - - TDiagramPanel tdp = mgui.getAvatarRDPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadAvatarMAD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createAvatarMAD(indexAnalysis, name); - - - TDiagramPanel tdp = mgui.getAvatarMADPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadADDDiagram(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - - TraceManager.addDev("ADD 2"); - mgui.createAvatarPD(indexAnalysis, name); - - TraceManager.addDev("ADD 3"); - TDiagramPanel tdp = mgui.getAvatarADDPanel(indexAnalysis, indexTab, name); - - TraceManager.addDev("ADD 3.1"); - - if (tdp == null) { - // Try to get the first diagram of the panel - tdp = mgui.getAvatarADDPanelByIndex(indexAnalysis, indexTab); - if (tdp == null) { - TraceManager.addDev("ADD 3.2"); - throw new MalformedModelingException(); - } - } - tdp.removeAll(); - TraceManager.addDev("ADD 4"); - - loadDiagram(elt, tdp); - TraceManager.addDev("ADD 5"); - } - - public void loadAvatarPD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createAvatarPD(indexAnalysis, name); - - TDiagramPanel tdp = mgui.getAvatarPDPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadAvatarCD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createAvatarCD(indexAnalysis, name); - - TDiagramPanel tdp = mgui.getAvatarCDPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadAvatarAD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createAvatarAD(indexAnalysis, name); - - TDiagramPanel tdp = mgui.getAvatarADPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - // TURTLE Design - public void loadTClassDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // class diagram name - name = elt.getAttribute("name"); - mgui.setClassDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - - loadDiagram(elt, tdp); - } - - public void loadTActivityDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - TActivityDiagramPanel tadp = mgui.getActivityDiagramPanel(indexDesign, name); - - if (tadp == null) { - throw new MalformedModelingException(); - } - - tadp.removeAll(); - - loadDiagram(elt, tadp); - } - - public void loadDiplodocusMethodologyDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // Diagram name - name = elt.getAttribute("name"); - mgui.setDiplodocusMethodologyDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - tdp.setName(name); - - TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - } - - public void loadAvatarMethodologyDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // class diagram name - name = elt.getAttribute("name"); - mgui.setAvatarMethodologyDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - tdp.setName(name); - - //TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - } - - public void loadSysmlsecMethodologyDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // class diagram name - name = elt.getAttribute("name"); - mgui.setSysmlsecMethodologyDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - tdp.setName(name); - - //TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - } - - public void loadTMLTaskDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // class diagram name - name = elt.getAttribute("name"); - mgui.setTMLTaskDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - - //TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - } - - public void loadTMLComponentTaskDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // Diagram name - name = elt.getAttribute("name"); - mgui.setTMLComponentTaskDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - - //TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - - ((TMLComponentTaskDiagramPanel)tdp).hideConnectors(); - ((TMLComponentTaskDiagramPanel)tdp).updatePorts(); - } - - public void loadTMLArchitectureDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // Diagram name - name = elt.getAttribute("name"); - mgui.setTMLArchitectureDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - - //TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - } - - public void loadTMLActivityDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - - //TraceManager.addDev("getting tmladp: " + name); - TMLActivityDiagramPanel tmladp = mgui.getTMLActivityDiagramPanel(indexDesign, name); - //TraceManager.addDev("Got tmladp"); - - - if (tmladp == null) { - //TraceManager.addDev("null tmladp"); - throw new MalformedModelingException(); - } - - tmladp.removeAll(); - - loadDiagram(elt, tmladp); - } - - public void loadTURTLEOSClassDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // class diagram name - name = elt.getAttribute("name"); - mgui.setTMLTaskDiagramName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - loadDiagram(elt, tdp); - } - - public void loadTURTLEOSActivityDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - TURTLEOSActivityDiagramPanel tosadp = mgui.getTURTLEOSActivityDiagramPanel(indexDesign, name); - - if (tosadp == null) { - throw new MalformedModelingException(); - } - - tosadp.removeAll(); - - loadDiagram(elt, tosadp); - } - - public void loadProactiveCSD(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - - String name; - TDiagramPanel tdp; - - // class diagram name - name = elt.getAttribute("name"); - // mgui.setProacticeCSDName(indexDesign, name); - tdp = mgui.getMainTDiagramPanel(indexDesign); - //ProactiveDesignPanel pdp=(ProactiveDesignPanel) mgui.getCurrentTURTLEPanel(); - ProactiveDesignPanel pdp=(ProactiveDesignPanel) tdp.tp; - if (!tdp.getName().equals(name)) - { - - //tdp=pdp.addCompositeStructureDiagram(name); - tdp=pdp.addProActiveCompSpecificationPanel(name); - } - - //TraceManager.addDev("tdp=" + tdp.getName()); - - loadDiagram(elt, tdp); - - } - - public void loadProactiveSMD(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - if (!(mgui.isProActiveSMDCreated(indexAnalysis, name))) { - mgui.createProActiveSMD(indexAnalysis, name); - } - ProactiveSMDPanel smd = mgui.getSMDPanel(indexAnalysis, name); - - if (smd == null) { - throw new MalformedModelingException(); - } - - smd.removeAll(); - - loadDiagram(elt, smd); - } - - public void loadIODiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - //mgui.setIODName(indexAnalysis, name); - if (!(mgui.isIODCreated(indexAnalysis, name))) { - mgui.createIODiagram(indexAnalysis, name); - } - - TDiagramPanel tdp = mgui.getIODiagramPanel(indexAnalysis, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadTMLCPDiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - if (!(mgui.isTMLCPCreated(indexAnalysis, name))) { - mgui.createTMLCPDiagram(indexAnalysis, name); - } - - TDiagramPanel tdp = mgui.getTMLCPDiagramPanel(indexAnalysis, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadTMLSDDiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - if (!(mgui.isTMLCPSDCreated(indexAnalysis, name))) { - mgui.createTMLCPSequenceDiagram(indexAnalysis, name); - } - - TDiagramPanel tdp = mgui.getTMLCPSDDiagramPanel(indexAnalysis, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadRequirementDiagram(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createRequirementDiagram(indexAnalysis, name); - - - TDiagramPanel tdp = mgui.getRequirementDiagramPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadEBRDD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.createEBRDD(indexAnalysis, name); - - - TDiagramPanel tdp = mgui.getEBRDDPanel(indexAnalysis, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadAttackTreeDiagram(Element elt, int indexDiag, int indexTab) throws MalformedModelingException, SAXException { - String name; - - //TraceManager.addDev("indexDiag=" + indexDiag); - - name = elt.getAttribute("name"); - mgui.createAttackTreeDiagram(indexDiag, name); - - TDiagramPanel tdp = mgui.getAttackTreeDiagramPanel(indexDiag, indexTab, name); - - if (tdp == null) { - throw new MalformedModelingException(); - } - tdp.removeAll(); - - loadDiagram(elt, tdp); - } - - public void loadSequenceDiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - if (!(mgui.isSDCreated(indexAnalysis, name))) { - mgui.createSequenceDiagram(indexAnalysis, name); - } - //TraceManager.addDev("Loading seq diag1"); - SequenceDiagramPanel sdp = mgui.getSequenceDiagramPanel(indexAnalysis, name); - //TraceManager.addDev("Loading seq diag2"); - - if (sdp == null) { - throw new MalformedModelingException(); - } - //TraceManager.addDev("Loading seq diag3"); - - sdp.removeAll(); - //TraceManager.addDev("Loading seq diag4"); - - loadDiagram(elt, sdp); - //TraceManager.addDev("Loading seq diag5"); - } - - public void loadUseCaseDiagram(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - /*if (!(mgui.isUCDCreated(indexAnalysis, name))) {*/ - mgui.createUseCaseDiagram(indexAnalysis, name); - //} - UseCaseDiagramPanel ucdp = mgui.getUseCaseDiagramPanel(indexAnalysis, indexTab, name); - - if (ucdp == null) { - throw new MalformedModelingException(); - } - - ucdp.removeAll(); - - loadDiagram(elt, ucdp); - } - - public void loadTDeploymentDiagram(Element elt, int indexDeployment) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.setDeploymentName(indexDeployment, name); - TDiagramPanel tdp = mgui.getMainTDiagramPanel(indexDeployment); - - loadDiagram(elt, tdp); - } - - public void loadNCDiagram(Element elt, int indexNC) throws MalformedModelingException, SAXException { - String name; - - name = elt.getAttribute("name"); - mgui.setNCName(indexNC, name); - TDiagramPanel tdp = mgui.getMainTDiagramPanel(indexNC); - - loadDiagram(elt, tdp); - } - - // reinit the id of all components - public void makeLovelyIds() { - TDiagramPanel tdp; - int id = 1; - int i, j; - TURTLEPanel tp; - // search for diagram panels - for(i=0; i<panels.size(); i++) { - tp = (TURTLEPanel)(panels.elementAt(i)); - for(j=0; j<tp.panels.size(); j++) { - tdp = (TDiagramPanel)(tp.panels.elementAt(j)); - id = tdp.makeLovelyIds(id); - //TraceManager.addDev("Lovely id =" + id); - } - } - - TGComponent.setGeneralId(id + 1); - } - - public void loadDiagramInformation(Element elt, TDiagramPanel tdp) throws MalformedModelingException { - int x, y; - double zoom = 0; - try { - x = Integer.decode(elt.getAttribute("minX")).intValue(); - tdp.setMinX(x); - x = Integer.decode(elt.getAttribute("maxX")).intValue(); - tdp.setMaxX(x); - y = Integer.decode(elt.getAttribute("minY")).intValue(); - tdp.setMinY(y); - y = Integer.decode(elt.getAttribute("maxY")).intValue(); - tdp.setMaxY(y); - tdp.updateSize(); - zoom = Double.parseDouble(elt.getAttribute("zoom")); - if (zoom != 0) { - tdp.setZoom(zoom); - mgui.updateZoomInfo(); - } - } catch (Exception e) { - // Model was saved in an older version of TTool - } - - if (tdp instanceof TActivityDiagramPanel) { - ((TActivityDiagramPanel)tdp).loadExtraParameters(elt); - } - } - - public void loadActivityDiagram(TDiagramPanel tdp, String oldValue, String newValue) throws MalformedModelingException { - //TraceManager.addDev("---> Load activity diagram"); - try { - NodeList activityDiagramNl = docCopy.getElementsByTagName("TActivityDiagramPanel"); - - TraceManager.addDev("Loading activity diagram of " + newValue + "Before : " + oldValue); - TraceManager.addDev(""+docCopy); - - if (activityDiagramNl == null) { - throw new MalformedModelingException(); - } - - Node adn; - Element elt; - TActivityDiagramPanel tadp; - String name; - int decXTmp = decX; - int decYTmp = decY; - int decIdTmp = decId; - - for(int i=0; i<activityDiagramNl.getLength(); i++) { - adn = activityDiagramNl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - // class diagram name - name = elt.getAttribute("name"); - //TraceManager.addDev("Name of activity diagram=" + name); - - if (name.equals(oldValue)) { - int indexDesign = mgui.getMajorIndexOf(tdp); - - if (indexDesign < 0) { - throw new MalformedModelingException(); - } - - tadp = mgui.getActivityDiagramPanel(indexDesign, newValue); - - //TraceManager.addDev("Searching panel"); - - if (tadp == null) { - throw new MalformedModelingException(); - } - - //TraceManager.addDev("Panel ok"); - - decX = 0; decY = 0; decId = 0; - - - - tadp.removeAll(); - - loadDiagramInformation(elt, tadp); - - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tadp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(tadp); - tadp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(tadp, 0); - } - } - } - decX = decXTmp; - decY = decYTmp; - decId = decIdTmp; - } catch (SAXException saxe) { - TraceManager.addError("Loading 701 " + saxe.getMessage()); - throw new MalformedModelingException(); - } - } - - public void loadAvatarSMD(TDiagramPanel tdp, String oldValue, String newValue) throws MalformedModelingException { - TraceManager.addDev("---> Load activity diagram of old=" + oldValue + " new=" + newValue); - try { - NodeList smdNl = docCopy.getElementsByTagName("AVATARStateMachineDiagramPanel"); - - //TraceManager.addDev("Loading state machine diagram of " + newValue + " Before : " + oldValue); - //TraceManager.addDev("smdNL: " + smdNl); - - if (smdNl == null) { - TraceManager.addDev("AVATAR: null doc"); - throw new MalformedModelingException(); - } - - Node adn; - Element elt; - AvatarSMDPanel asmdp; - String name; - int decXTmp = decX; - int decYTmp = decY; - int decIdTmp = decId; - - for(int i=0; i<smdNl.getLength(); i++) { - adn = smdNl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - // class diagram name - name = elt.getAttribute("name"); - TraceManager.addDev("Name of activity diagram=" + name); - - if (name.equals(oldValue)) { - int indexDesign = mgui.getMajorIndexOf(tdp); - - if (indexDesign < 0) { - throw new MalformedModelingException(); - } - - asmdp = mgui.getAvatarSMDPanel(indexDesign, newValue); - - TraceManager.addDev("Searching panel: " + newValue); - - if (asmdp == null) { - throw new MalformedModelingException(); - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - TraceManager.addDev("Panel ok"); + loadDiagram(elt, tdp); + } - decX = 0; decY = 0; decId = 0; + public void loadADDDiagram(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; + name = elt.getAttribute("name"); - asmdp.removeAll(); + TraceManager.addDev("ADD 2"); + mgui.createAvatarPD(indexAnalysis, name); - loadDiagramInformation(elt, asmdp); + TraceManager.addDev("ADD 3"); + TDiagramPanel tdp = mgui.getAvatarADDPanel(indexAnalysis, indexTab, name); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), asmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), asmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), asmdp); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); - connectConnectorsToRealPoints(asmdp); - asmdp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); - makePostLoading(asmdp, 0); - } - } - } - decX = decXTmp; - decY = decYTmp; - decId = decIdTmp; - } catch (SAXException saxe) { - TraceManager.addError("Loading 801 " + saxe.getMessage()); - throw new MalformedModelingException(); - } - } + TraceManager.addDev("ADD 3.1"); - public void loadTMLActivityDiagram(TDiagramPanel tdp, String oldValue, String newValue) throws MalformedModelingException { - //TraceManager.addDev("---> Load TML activity diagram"); - try { - if (docCopy == null) { - TraceManager.addDev("Null doc copy"); - } - NodeList activityDiagramNl = docCopy.getElementsByTagName("TMLActivityDiagramPanel"); + if (tdp == null) { + // Try to get the first diagram of the panel + tdp = mgui.getAvatarADDPanelByIndex(indexAnalysis, indexTab); + if (tdp == null) { + TraceManager.addDev("ADD 3.2"); + throw new MalformedModelingException(); + } + } + tdp.removeAll(); + TraceManager.addDev("ADD 4"); - //TraceManager.addDev("Loading activity diagram of " + newValue + "Before : " + oldValue); + loadDiagram(elt, tdp); + TraceManager.addDev("ADD 5"); + } - if (activityDiagramNl == null) { - //TraceManager.addDev("Null"); - throw new MalformedModelingException(); - } + public void loadAvatarPD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - Node adn; - Element elt; - TMLActivityDiagramPanel tmladp; - String name; - int decXTmp = decX; - int decYTmp = decY; - int decIdTmp = decId; - - for(int i=0; i<activityDiagramNl.getLength(); i++) { - adn = activityDiagramNl.item(i); - if (adn.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) adn; - // class diagram name - name = elt.getAttribute("name"); - //TraceManager.addDev("Name of activity diagram=" + name); - - if (name.equals(oldValue)) { - int indexDesign = mgui.getMajorIndexOf(tdp); - - if (indexDesign < 0) { - throw new MalformedModelingException(); - } + name = elt.getAttribute("name"); + mgui.createAvatarPD(indexAnalysis, name); - tmladp = mgui.getTMLActivityDiagramPanel(indexDesign, newValue); + TDiagramPanel tdp = mgui.getAvatarPDPanel(indexAnalysis, indexTab, name); - //TraceManager.addDev("Searching panel"); + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - if (tmladp == null) { - throw new MalformedModelingException(); - } + loadDiagram(elt, tdp); + } - //TraceManager.addDev("Panel ok"); + public void loadAvatarCD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - decX = 0; decY = 0; decId = 0; + name = elt.getAttribute("name"); + mgui.createAvatarCD(indexAnalysis, name); - tmladp.removeAll(); + TDiagramPanel tdp = mgui.getAvatarCDPanel(indexAnalysis, indexTab, name); - loadDiagramInformation(elt, tmladp); + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " components"); - makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmladp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " connectors"); - makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmladp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " subcomponents"); - makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmladp); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " real points"); - connectConnectorsToRealPoints(tmladp); - tmladp.structureChanged(); - //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " post loading"); - makePostLoading(tmladp, 0); - } - } - } - decX = decXTmp; - decY = decYTmp; - decId = decIdTmp; - } catch (SAXException saxe) { - TraceManager.addError("Loading 901 " + saxe.getMessage()); - throw new MalformedModelingException(); - } - } + loadDiagram(elt, tdp); + } - public void makePostLoading(TDiagramPanel tdp, int beginIndex) throws MalformedModelingException{ - TGComponent tgc; + public void loadAvatarAD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - //TraceManager.addDev("Post loading of diagram " + tdp.toString()); + name = elt.getAttribute("name"); + mgui.createAvatarAD(indexAnalysis, name); - LinkedList list = tdp.getComponentList(); + TDiagramPanel tdp = mgui.getAvatarADPanel(indexAnalysis, indexTab, name); - for(int i=0; i<list.size()-beginIndex; i++) { - tgc = (TGComponent)(list.get(i)); - //TraceManager.addDev(tgc.getName()); - //TraceManager.addDev(tgc.getValue()); - tgc.makePostLoading(decId); - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - //TraceManager.addDev("Post loading of diagram " + tdp.toString() + " achieved"); - } + loadDiagram(elt, tdp); + } - public void makeXMLComponents(NodeList nl, TDiagramPanel tdp) throws SAXException, MalformedModelingException { - Node n; - //Element elt; - TGComponent tgc; + // TURTLE Design + public void loadTClassDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - if (tdp == null) { - throw new MalformedModelingException(); - } - boolean error = false; - - for(int i=0; i<nl.getLength(); i++) { - n = nl.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { - try { - tgc = makeXMLComponent(n, tdp); - //TraceManager.addDev("About to add component= " + tgc); - if ((tgc != null) && (tgc.getFather() == null)) { - //TraceManager.addDev("Component added to diagram tgc=" + tgc); - tdp.addBuiltComponent(tgc); - } else { - //TraceManager.addDev("Component not added to diagram"); - } - } catch (MalformedModelingException mme) { - TraceManager.addDev ("Could not create component " + n); - error = true; - } - } - } + String name; + TDiagramPanel tdp; - if (error) { - throw new MalformedModelingException(); - } - } + // class diagram name + name = elt.getAttribute("name"); + mgui.setClassDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); + loadDiagram(elt, tdp); + } - public TGComponent makeXMLComponent(Node n, TDiagramPanel tdp) throws SAXException, MalformedModelingException { - Element elt; - Element elt1; - //TraceManager.addDev(n.toString()); - TGComponent tgc = null; - TGComponent father; + public void loadTActivityDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { + String name; - // - try { - - NodeList nl = n.getChildNodes(); - elt = (Element)n; - elt1 = elt; - //TraceManager.addDev("elt=" + elt); - - int myType = Integer.decode(elt.getAttribute("type")).intValue(); - int myId = Integer.decode(elt.getAttribute("id")).intValue() + decId; - - int myX = -1, myY = -1, myWidth = -1, myHeight =-1; - int myMinWidth = -1, myMinHeight = -1, myMinDesiredWidth = -1, myMinDesiredHeight = -1; - int myMinX = -1, myMaxX = -1, myMinY = -1, myMaxY = -1; - String myName = null, myValue = null; - Vector tgcpList = new Vector(); - Point p; - int i, x, y; - int fatherId = -1, fatherNum = -1; - String pre = "", post = ""; - String internalComment = ""; - boolean accessibility = false; - boolean latencyCheck = false; - boolean invariant = false; - boolean breakpoint = false; - boolean hidden = false; - boolean masterMutex = false; - boolean enable = true; - - for(i=0; i<nl.getLength(); i++) { - n = nl.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) n; - if (elt.getTagName().equals("cdparam")) { - myX = Integer.decode(elt.getAttribute("x")).intValue() + decX; - myY = Integer.decode(elt.getAttribute("y")).intValue() + decY; - } else if (elt.getTagName().equals("sizeparam")) { - myWidth = Integer.decode(elt.getAttribute("width")).intValue(); - myHeight = Integer.decode(elt.getAttribute("height")).intValue(); - myMinWidth = Integer.decode(elt.getAttribute("minWidth")).intValue(); - myMinHeight = Integer.decode(elt.getAttribute("minHeight")).intValue(); - myMinDesiredWidth = Integer.decode(elt.getAttribute("minDesiredWidth")).intValue(); - myMinDesiredHeight = Integer.decode(elt.getAttribute("minDesiredHeight")).intValue(); - } else if (elt.getTagName().equals("cdrectangleparam")) { - myMinX = Integer.decode(elt.getAttribute("minX")).intValue(); - myMaxX = Integer.decode(elt.getAttribute("maxX")).intValue(); - myMinY = Integer.decode(elt.getAttribute("minY")).intValue(); - myMaxY = Integer.decode(elt.getAttribute("maxY")).intValue(); - } else if (elt.getTagName().equals("infoparam")) { - myName = elt.getAttribute("name"); - myValue = elt.getAttribute("value"); - } else if (elt.getTagName().equals("hidden")) { - hidden = elt.getAttribute("value").equals("true"); - } else if (elt.getTagName().equals("enabled")) { - enable = elt.getAttribute("value").equals("true"); - } else if (elt.getTagName().equals("TGConnectingPoint")) { - x = Integer.decode(elt.getAttribute("num")).intValue(); - y = Integer.decode(elt.getAttribute("id")).intValue() + decId; - tgcpList.add(new Point(x, y)); - } else if (elt.getTagName().equals("father")) { - fatherId = Integer.decode(elt.getAttribute("id")).intValue(); - fatherNum = Integer.decode(elt.getAttribute("num")).intValue(); - } else if (elt.getTagName().equals("prejavacode")) { - pre += elt.getAttribute("value") + "\n"; - } else if (elt.getTagName().equals("postjavacode")) { - post += elt.getAttribute("value") + "\n"; - } else if (elt.getTagName().equals("InternalComment")) { - internalComment += elt.getAttribute("value") + "\n"; - } else if (elt.getTagName().equals("accessibility")) { - accessibility = true; - } else if (elt.getTagName().equals("latencyCheck")) { - latencyCheck = true; - } else if (elt.getTagName().equals("invariant")) { - invariant = true; - } else if (elt.getTagName().equals("mastermutex")) { - masterMutex = true; - } else if (elt.getTagName().equals("breakpoint")) { - breakpoint = true; - } - } - } + name = elt.getAttribute("name"); + TActivityDiagramPanel tadp = mgui.getActivityDiagramPanel(indexDesign, name); - if ((myId == -1) || (myX == -1) || (myY == -1) || (myWidth == -1) || (myHeight == -1)) { - throw new MalformedModelingException(); - } + if (tadp == null) { + throw new MalformedModelingException(); + } - //TraceManager.addDev("Making TGComponent of type " + myType + " and of name " + myName); - //TGComponent is ready to be built - if(fatherId != -1) { - fatherId += decId; - // internal component - //TraceManager.addDev("I am " + myName); - //TraceManager.addDev("Searching for component with id " + fatherId); - father = tdp.findComponentWithId(fatherId); - if (father == null) { - throw new MalformedModelingException(); - } + tadp.removeAll(); - //TraceManager.addDev("Done"); - //TraceManager.addDev("Father My value is " + father.getValue()); - //TraceManager.addDev("My class is " + father.getClass()); - - //TraceManager.addDev("Searching for component " + fatherNum + " at " + tgc.getName()); - tgc = father.getInternalTGComponent(fatherNum); - - if (tgc == null) { - // To be added to its father -> swallow component - if (father instanceof SwallowTGComponent) { - //TraceManager.addDev("1 Must add the component to its father:"); - tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); - //TraceManager.addDev("2 Must add the component to its father:" + tgc); - if (tgc instanceof SwallowedTGComponent) { - //TraceManager.addDev("3 Must add the component to its father:"); - ((SwallowTGComponent)father).addSwallowedTGComponent(tgc, myX, myY); - //TraceManager.addDev("Swallowed to father = " + father.getValue() + ". My name=" + myName + " decId=" + decId); - } else { - throw new MalformedModelingException(); - } - } else { - throw new MalformedModelingException(); - } - } + loadDiagram(elt, tadp); + } - if (tgc != null) { - tgc.setCdRectangle(myMinX, myMaxX, myMinY, myMaxY); - tgc.setCd(myX, myY); - //TraceManager.addDev("set cd of " + tgc.getName()); - } - } else { - tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); - } - // TraceManager.addDev("TGComponent (" + tgc + ") built " + myType); + public void loadDiplodocusMethodologyDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - if (tgc == null) { - throw new MalformedModelingException(); - } + String name; + TDiagramPanel tdp; - if (myName != null) { - tgc.setName(myName); - } + // Diagram name + name = elt.getAttribute("name"); + mgui.setDiplodocusMethodologyDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); + tdp.setName(name); - tgc.setHidden(hidden); - tgc.setEnabled(enable); - - /*if (tgc instanceof TCDTObject) { - TraceManager.addDev("Loading " + myValue); - }*/ - - String oldClassName = myValue; - //TraceManager.addDev("Old class name=" + oldClassName); - //Added by Solange - if ((myValue != null) && (!myValue.equals(null))){ - if (tgc instanceof ProCSDComponent) - { - //Added by Solange - //And removed by emil - //myValue=generateNameIfInUse(myValue); - // tgc.setValueWithChange(myValue); - //TraceManager.addDev("myValue=" + myValue); - } - //until here - if ((tgc instanceof TCDTClass) && (decId >0)){ - if (tdp.isAlreadyATClassName(myValue)) { - myValue = tdp.findTClassName(myValue+"_"); - } - } - if ((tgc instanceof TMLTaskOperator) && (decId >0)){ - if (tdp.isAlreadyATMLTaskName(myValue)) { - myValue = tdp.findTMLTaskName(myValue+"_"); - } - } + TraceManager.addDev("tdp=" + tdp.getName()); - if ((tgc instanceof AvatarBDBlock) && (decId >0)){ - if (tdp.isAlreadyAnAvatarBDBlockName(myValue)) { - myValue = tdp.findAvatarBDBlockName(myValue+"_"); - } - } + loadDiagram(elt, tdp); + } - if ((tgc instanceof TMLCPrimitiveComponent) && (decId >0)){ - if (tdp.isAlreadyATMLPrimitiveComponentName(myValue)) { - myValue = tdp.findTMLPrimitiveComponentName(myValue+"_"); - } - //TraceManager.addDev("MyValue=" + myValue); - } - if ((tgc instanceof TOSClass) && (decId >0)){ - if (tdp.isAlreadyATOSClassName(myValue)) { - myValue = tdp.findTOSClassName(myValue+"_"); - } - } - //TraceManager.addDev("myValue=" + myValue); - tgc.setValueWithChange(myValue); - //TraceManager.addDev("value done"); - if ((tgc instanceof TCDTClass) && (decId >0)){ - loadActivityDiagram(tdp, oldClassName, myValue); - } + public void loadAvatarMethodologyDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - if ((tgc instanceof AvatarBDBlock) && (decId >0)){ - //TraceManager.addDev("Going to load ad of task " + oldClassName + " myValue=" + myValue); - loadAvatarSMD(tdp, oldClassName, myValue); - } + String name; + TDiagramPanel tdp; - if ((tgc instanceof TMLTaskOperator) && (decId >0)){ - //TraceManager.addDev("Going to load ad of task " + oldClassName + " myValue=" + myValue); - loadTMLActivityDiagram(tdp, oldClassName, myValue); - } + // class diagram name + name = elt.getAttribute("name"); + mgui.setAvatarMethodologyDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); + tdp.setName(name); - if ((tgc instanceof TMLCPrimitiveComponent) && (decId >0)){ - //TraceManager.addDev("Going to load ad of component " + oldClassName + " myValue=" + myValue); - loadTMLActivityDiagram(tdp, oldClassName, myValue); - } - } + //TraceManager.addDev("tdp=" + tdp.getName()); - tgc.forceId(myId); - tgc.setLoaded(true); - tgc.setInternalLoaded(false); - tgc.setMinSize(myMinWidth, myMinHeight); - tgc.setMinDesiredSize(myMinDesiredWidth, myMinDesiredHeight); - tgc.resize(myWidth, myHeight); - tgc.hasBeenResized(); + loadDiagram(elt, tdp); + } - //TraceManager.addDev("Options set"); + public void loadSysmlsecMethodologyDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - if (pre.compareTo("") != 0) { - tgc.setPreJavaCode(pre); - } - if (post.compareTo("") != 0) { - tgc.setPostJavaCode(post); - } + String name; + TDiagramPanel tdp; - if (internalComment.compareTo("") != 0) { - tgc.setInternalComment(internalComment); - } + // class diagram name + name = elt.getAttribute("name"); + mgui.setSysmlsecMethodologyDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); + tdp.setName(name); - if (accessibility) { - tgc.setCheckableAccessibility(accessibility); + //TraceManager.addDev("tdp=" + tdp.getName()); - } + loadDiagram(elt, tdp); + } - if (latencyCheck) { - tgc.setCheckLatency(latencyCheck); + public void loadTMLTaskDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - } - if (invariant) { - tgc.setCheckableInvariant(invariant); - } + String name; + TDiagramPanel tdp; - if (masterMutex) { - tgc.setMasterMutex(true); - } + // class diagram name + name = elt.getAttribute("name"); + mgui.setTMLTaskDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); - if (breakpoint) { - tgc.setBreakpoint(breakpoint); - } + //TraceManager.addDev("tdp=" + tdp.getName()); - //extra param - // TraceManager.addDev("Extra params" + tgc.getClass()); - // TraceManager.addDev("My value = " + tgc.getValue()); - tgc.loadExtraParam(elt1.getElementsByTagName("extraparam"), decX, decY, decId); - // TraceManager.addDev("Extra param ok"); - - if ((tgc instanceof TCDTObject) && (decId > 0)) { - TCDTObject to = (TCDTObject)tgc; - //TraceManager.addDev("Setting TObject name to: " + to.getObjectName()); - //TraceManager.addDev("Setting TObject name to: " + tdp.findTObjectName(to.getObjectName())); - to.setObjectName(tdp.findTObjectName(to.getObjectName())); - } + loadDiagram(elt, tdp); + } - //TraceManager.addDev(tgc.toString()); + public void loadTMLComponentTaskDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - //TraceManager.addDev("Making connecting points " + tgcpList.size()); - for(i=0; i<tgcpList.size(); i++) { - p = (Point)(tgcpList.elementAt(i)); - if (!tgc.setIdTGConnectingPoint(p.x, p.y)) { - //TraceManager.addDev("Warning: a connecting point has been removed"); - //throw new MalformedModelingException(); - } - } + String name; + TDiagramPanel tdp; - //TraceManager.addDev("Not yet except!"); - if (decId >0) { - tdp.bringToFront(tgc); - } - //TraceManager.addDev("Connecting points done " + myType); + // Diagram name + name = elt.getAttribute("name"); + mgui.setTMLComponentTaskDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); - /*if (tgc instanceof TCDTObject) { - TraceManager.addDev("getValue " + tgc.getValue()); - }*/ + //TraceManager.addDev("tdp=" + tdp.getName()); - } catch (Exception e) { - // TraceManager.addError("Exception XML Component "/* + e.getMessage() + "trace=" + e.getStackTrace()*/); - throw new MalformedModelingException(); - } - return tgc; - } + loadDiagram(elt, tdp); - //method added by Solange + ((TMLComponentTaskDiagramPanel)tdp).hideConnectors(); + ((TMLComponentTaskDiagramPanel)tdp).updatePorts(); + } - public String generateNameIfInUse(String myName) - { - if (!(mgui.getCurrentTURTLEPanel().nameInUse(myName))) - { - return myName; - } + public void loadTMLArchitectureDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - String other; - for(int w=0; w<100000; w++) - { - other = myName + "_" + w; - if (!(mgui.getCurrentTURTLEPanel().nameInUse(other))) - { - return other; - } - } - return null; - } - //until here + String name; + TDiagramPanel tdp; - public void makePostProcessing(TDiagramPanel tdp) throws MalformedModelingException{ - //TraceManager.addDev("Make post processing!"); - if (tdp instanceof TClassDiagramPanel) { - ((TClassDiagramPanel)tdp).makePostLoadingProcessing(); - } - //TraceManager.addDev("Post processing is over"); - } + // Diagram name + name = elt.getAttribute("name"); + mgui.setTMLArchitectureDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); - public void makeXMLConnectors(NodeList nl, TDiagramPanel tdp) throws SAXException, MalformedModelingException { - Node n; - //Element elt; - TGConnector tgco = null; - int i; + //TraceManager.addDev("tdp=" + tdp.getName()); - if (tdp == null) { - throw new MalformedModelingException(); - } + loadDiagram(elt, tdp); + } - for(i=0; i<nl.getLength(); i++) { - n = nl.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { - tgco = makeXMLConnector(n, tdp); - if (tgco != null) { - tdp.addBuiltConnector(tgco); - } else { - TraceManager.addDev("Connector error"); - throw new MalformedModelingException(); - } - } - } - } + public void loadTMLActivityDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { + String name; - public void connectConnectorsToRealPoints(TDiagramPanel tdp) throws MalformedModelingException { - LinkedList list = tdp.getComponentList(); - TGConnectingPoint p1, p2, p3, p4; - //TGConnectingPointTmp p; - int i; - TGComponent tgc; - //TGComponent tgctmp; - TGConnector tgco = null; - //boolean error = false; - TGConnectorInfo tgcoinfo; - - - //connect connectors to their real connecting point - //TraceManager.addDev("Valid connectors ?"); - for(i=0; i<list.size(); i++) { - tgc = (TGComponent)(list.get(i)); - if (tgc instanceof TGConnector) { - tgco = (TGConnector)tgc; - p1 = tgco.getTGConnectingPointP1(); - p2 = tgco.getTGConnectingPointP2(); - if ((p1 instanceof TGConnectingPointTmp) && (p2 instanceof TGConnectingPointTmp)){ - //TraceManager.addDev("Searching for id " + p1.getId()); - p3 = tdp.findConnectingPoint(p1.getId()); - //TraceManager.addDev("Searching for id " + p2.getId()); - p4 = tdp.findConnectingPoint(p2.getId()); - if (((p3 ==null) || (p4 == null)) &&(decId != 0)) { - if (list.remove(tgc)) { - i --; - } else { - throw new MalformedModelingException(); - } - } else { - if ((p3 == null) ||(p4 == null)) { - //warning = true; - if (p3 == null) { - //TraceManager.addDev("Error on first id"); - } - if (p4 == null) { - //TraceManager.addDev("Error on second id"); - } - tgcoinfo = new TGConnectorInfo(); - tgcoinfo.connector = tgco; - pendingConnectors.add(tgcoinfo); - TraceManager.addDev("One connector added to pending list"); - } else { - tgco.setP1(p3); - p3.setFree(false); - tgco.setP2(p4); - p4.setFree(false); - } - } - } - } - } + name = elt.getAttribute("name"); - /*for(TGConnector con: connectorsToRemove) { - list.remove(con); - }*/ + //TraceManager.addDev("getting tmladp: " + name); + TMLActivityDiagramPanel tmladp = mgui.getTMLActivityDiagramPanel(indexDesign, name); + //TraceManager.addDev("Got tmladp"); - /*if (error) { - TraceManager.addDev("Connecting error: " + connectorsToRemove.size() + " connectors have been removed"); - throw new MalformedModelingException(); - }*/ - } - public void makeLastLoad() { - // Update references on all diagrams - //TraceManager.addDev("Updating ports"); - //mgui.updateAllPorts(); - - // Update ports on all diagrams - //TraceManager.addDev("Updating references / ports"); - mgui.updateAllReferences(); - - mgui.updateAllPorts(); - - //TraceManager.addDev("Pending connectors"); - // Make use of pending connectors - TGConnectingPoint p1, p2, p3, p4; - TDiagramPanel tdp; - TGConnector tgco; - for(TGConnectorInfo info: pendingConnectors) { - tgco = info.connector; - if (tgco != null) { - tdp = tgco.getTDiagramPanel(); - if (tdp != null) { - p1 = tgco.getTGConnectingPointP1(); - p2 = tgco.getTGConnectingPointP2(); - if ((p1 instanceof TGConnectingPointTmp) && (p2 instanceof TGConnectingPointTmp)){ - TraceManager.addDev("Searching for id " + p1.getId()); - p3 = tdp.findConnectingPoint(p1.getId()); - TraceManager.addDev("Searching for id " + p2.getId()); - p4 = tdp.findConnectingPoint(p2.getId()); - if ((p3 == null) ||(p4 == null)) { - //warning = true; - if (p3 == null) { - TraceManager.addDev("Error on first id"); - } - if (p4 == null) { - TraceManager.addDev("Error on second id"); - } - TraceManager.addDev("One connector ignored"); - } else { - tgco.setP1(p3); - p3.setFree(false); - tgco.setP2(p4); - p4.setFree(false); - } - } - } - } - } - pendingConnectors.clear(); - //TraceManager.addDev("Last load done"); - } + if (tmladp == null) { + //TraceManager.addDev("null tmladp"); + throw new MalformedModelingException(); + } - public TGConnector makeXMLConnector(Node n, TDiagramPanel tdp) throws SAXException, MalformedModelingException { - Element elt, elt1; - TGConnector tgco = null; - //TGComponent tgc = null; - - //TraceManager.addDev(n.toString()); - - try { - - NodeList nl = n.getChildNodes(); - elt = (Element)n; - elt1 = elt; - - int myType = Integer.decode(elt.getAttribute("type")).intValue(); - int myId = Integer.decode(elt.getAttribute("id")).intValue() + decId; - - int myX = -1, myY = -1, myWidth = -1, myHeight =-1; - int myMinWidth = -1, myMinHeight = -1, myMinDesiredWidth = -1, myMinDesiredHeight = -1; - int myMaxWidth = -1, myMaxHeight = -1; - String myName = null, myValue = null; - int tmpx, tmpy, tmpid; - TGConnectingPoint p1 = null, p2=null; - Vector pointList = new Vector(); - - Vector tgcpList = new Vector(); - Point p; - int i, x, y; - //int fatherId = -1, fatherNum = -1; - boolean automaticDrawing = true; - - for(i=0; i<nl.getLength(); i++) { - n = nl.item(i); - if (n.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element) n; - if (elt.getTagName().equals("cdparam")) { - myX = Integer.decode(elt.getAttribute("x")).intValue() + decX; - myY = Integer.decode(elt.getAttribute("y")).intValue() + decY; - } else if (elt.getTagName().equals("sizeparam")) { - myWidth = Integer.decode(elt.getAttribute("width")).intValue(); - myHeight = Integer.decode(elt.getAttribute("height")).intValue(); - myMinWidth = Integer.decode(elt.getAttribute("minWidth")).intValue(); - myMinHeight = Integer.decode(elt.getAttribute("minHeight")).intValue(); - if ((elt.getAttribute("maxWidth") != null) && (elt.getAttribute("maxWidth").length() > 0)) { // Test is made for compatibility with old versions - //TraceManager.addDev("maxWidth = " + elt.getAttribute("maxWidth")); - myMaxWidth = Integer.decode(elt.getAttribute("maxWidth")).intValue(); - myMaxHeight = Integer.decode(elt.getAttribute("maxHeight")).intValue(); - } - myMinDesiredWidth = Integer.decode(elt.getAttribute("minDesiredWidth")).intValue(); - myMinDesiredHeight = Integer.decode(elt.getAttribute("minDesiredHeight")).intValue(); - } else if (elt.getTagName().equals("infoparam")) { - myName = elt.getAttribute("name"); - myValue = elt.getAttribute("value"); - } else if (elt.getTagName().equals("P1")) { - tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; - tmpy = Integer.decode(elt.getAttribute("y")).intValue() + decY; - tmpid = Integer.decode(elt.getAttribute("id")).intValue() + decId; - TGComponent tgc1 = TGComponentManager.addComponent(tmpx, tmpy, TGComponentManager.TAD_START_STATE, tdp); - p1 = new TGConnectingPointTmp(tgc1, tmpx, tmpy, tmpid); - //TraceManager.addDev("P1id = " + tmpid); - } else if (elt.getTagName().equals("P2")) { - tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; - tmpy = Integer.decode(elt.getAttribute("y")).intValue() + decY; - tmpid = Integer.decode(elt.getAttribute("id")).intValue() + decId; - TGComponent tgc2 = TGComponentManager.addComponent(tmpx, tmpy, TGComponentManager.TAD_START_STATE, tdp); - p2 = new TGConnectingPointTmp(tgc2, tmpx, tmpy, tmpid); - //TraceManager.addDev("P2id = " + tmpid); - } else if (elt.getTagName().equals("Point")) { - tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; - tmpy = Integer.decode(elt.getAttribute("y")).intValue() + decY; - pointList.add(new Point(tmpx, tmpy)); - } else if (elt.getTagName().equals("TGConnectingPoint")) { - x = Integer.decode(elt.getAttribute("num")).intValue(); - y = Integer.decode(elt.getAttribute("id")).intValue() + decId; - tgcpList.add(new Point(x, y)); - //TraceManager.addDev(" adding Connecting point !"); - } else if (elt.getTagName().equals("AutomaticDrawing")) { - //TraceManager.addDev("AutomaticDrawing=" + elt.getAttribute("data")); - if (elt.getAttribute("data").compareTo("true") == 0) { - automaticDrawing = true; - //TraceManager.addDev("set to true"); - } else { - automaticDrawing = false; - } - //automaticDrawing = Boolean.getBoolean(elt.getAttribute("data")); - } - } - } + tmladp.removeAll(); - if ((myType == -1) || (myId == -1) || (myX == -1) || (myY == -1) || (myWidth == -1) || (myHeight == -1) || (p1 == null) || (p2 == null)) { - throw new MalformedModelingException(); - } + loadDiagram(elt, tmladp); + } - //TGConnector is ready to be built - //TraceManager.addDev("Making TGConnector of type " + myType); - tgco = TGComponentManager.addConnector(myX, myY, myType, tdp, p1, p2, pointList); - //TraceManager.addDev("TGConnector built " + myType); + public void loadTURTLEOSClassDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { - if (tgco == null) { - TraceManager.addDev( "TGCO is null myType: " + myType ); - throw new MalformedModelingException(); - } + String name; + TDiagramPanel tdp; - tgco.setAutomaticDrawing(automaticDrawing); + // class diagram name + name = elt.getAttribute("name"); + mgui.setTMLTaskDiagramName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); + loadDiagram(elt, tdp); + } - if (myName != null) { - tgco.setName(myName); - } - if ((myValue != null) && (!myValue.equals(null))){ - tgco.setValueWithChange(myValue); - } + public void loadTURTLEOSActivityDiagram(Element elt, int indexDesign) throws MalformedModelingException, SAXException { + String name; - tgco.forceId(myId); - tgco.setLoaded(true); - tgco.setInternalLoaded(false); - tgco.setMinSize(myMinWidth, myMinHeight); - tgco.setMaxSize(myMaxWidth, myMaxHeight); - tgco.setMinDesiredSize(myMinDesiredWidth, myMinDesiredHeight); - tgco.resize(myWidth, myHeight); - - tgco.loadExtraParam(elt1.getElementsByTagName("extraparam"), decX, decY, decId); - - //TraceManager.addDev("Making connecting points " + myType); - for(i=0; i<tgcpList.size(); i++) { - p = (Point)(tgcpList.elementAt(i)); - if (!tgco.setIdTGConnectingPoint(p.x, p.y)) { - throw new MalformedModelingException(); - } - } + name = elt.getAttribute("name"); + TURTLEOSActivityDiagramPanel tosadp = mgui.getTURTLEOSActivityDiagramPanel(indexDesign, name); - if (decId >0) { - tdp.bringToFront(tgco); - } + if (tosadp == null) { + throw new MalformedModelingException(); + } - //TraceManager.addDev("Connecting points done " + myType); + tosadp.removeAll(); - } catch (Exception e) { - TraceManager.addError("Exception on connectors: HERE I AM"); - throw new MalformedModelingException(); - } - return tgco; - } + loadDiagram(elt, tosadp); + } + public void loadProactiveCSD(Element elt, int indexDesign) throws MalformedModelingException, SAXException { + String name; + TDiagramPanel tdp; - public boolean buildTURTLEModelingFromAnalysis(AnalysisPanel ap) throws AnalysisSyntaxException { + // class diagram name + name = elt.getAttribute("name"); + // mgui.setProacticeCSDName(indexDesign, name); + tdp = mgui.getMainTDiagramPanel(indexDesign); + //ProactiveDesignPanel pdp=(ProactiveDesignPanel) mgui.getCurrentTURTLEPanel(); + ProactiveDesignPanel pdp=(ProactiveDesignPanel) tdp.tp; + if (!tdp.getName().equals(name)) + { - HMSC h; - //listE = new CorrespondanceTGElement(); - checkingErrors = new LinkedList<CheckingError> (); + //tdp=pdp.addCompositeStructureDiagram(name); + tdp=pdp.addProActiveCompSpecificationPanel(name); + } - AnalysisPanelTranslator apt = new AnalysisPanelTranslator(ap, mgui); + //TraceManager.addDev("tdp=" + tdp.getName()); - try { - h = apt.translateHMSC(); - listE = apt.getCorrespondanceTGElement(); - checkingErrors = apt.getErrors(); - apt.translateMSCs(h); - listE = apt.getCorrespondanceTGElement(); - checkingErrors = apt.getErrors(); - } catch (AnalysisSyntaxException ase) { - CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, ase.getMessage()); - checkingErrors.add(ce); - throw ase; - } + loadDiagram(elt, tdp); - SDTranslator sd = new SDTranslator(h); - checkingErrors = null; - warnings = new LinkedList<CheckingError> (); - //TraceManager.addDev("Step 02"); + } - mgui.setMode(mgui.VIEW_SUGG_DESIGN_KO); + public void loadProactiveSMD(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { + String name; - //TraceManager.addDev("Step 1"); - try { - tm = sd.toTURTLEModeling(); - tmState = 0; - } catch (SDTranslationException e) { - checkingErrors = new LinkedList<CheckingError> (); - CheckingError error = new CheckingError(CheckingError.STRUCTURE_ERROR, e.getMessage()); - checkingErrors.add(error); + name = elt.getAttribute("name"); + if (!(mgui.isProActiveSMDCreated(indexAnalysis, name))) { + mgui.createProActiveSMD(indexAnalysis, name); + } + ProactiveSMDPanel smd = mgui.getSMDPanel(indexAnalysis, name); - throw new AnalysisSyntaxException("Problem during translation to a design TURTLE modeling"); - } + if (smd == null) { + throw new MalformedModelingException(); + } - //TraceManager.addDev("Step 2"); + smd.removeAll(); - if (checkingErrors != null) { - return false; - } + loadDiagram(elt, smd); + } - // modeling is built - // Now check it ! - //TraceManager.addDev("Step 3"); - TURTLEModelChecker tmc = new TURTLEModelChecker(tm); - checkingErrors = tmc.syntaxAnalysisChecking(); - //TraceManager.addDev("Step 4"); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - return false; - } else { - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_OK); - return true; - } - } + public void loadIODiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { + String name; - public void generateDesign() { - generateDesign(tm); - } + name = elt.getAttribute("name"); + //mgui.setIODName(indexAnalysis, name); + if (!(mgui.isIODCreated(indexAnalysis, name))) { + mgui.createIODiagram(indexAnalysis, name); + } - public void generateDesign(TURTLEModeling tm) { - //TURTLEPanel tp = mgui.getCurrentTURTLEPanel(); - nbSuggestedDesign ++; - TURTLEModelingDrawer tmd = new TURTLEModelingDrawer(mgui); - tmd.setTURTLEModeling(tm); - tmd.draw(nbSuggestedDesign); - mgui.changeMade(null, -1); - } + TDiagramPanel tdp = mgui.getIODiagramPanel(indexAnalysis, name); - public void generateIOD(HMSC _hmsc, MSC _msc) { - MSCDrawer mscd = new MSCDrawer(mgui); - mscd.setHMSC(_hmsc); - mscd.setMSC(_msc); - mscd.drawFromMSC(nbSuggestedDesign); - nbSuggestedDesign ++; - mgui.changeMade(null, -1); - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); + loadDiagram(elt, tdp); + } - public boolean translateDeployment(DeploymentPanel dp) { - // Builds a TURTLE modeling from a deployment diagram - TraceManager.addDev("deployement"); - checkingErrors = new LinkedList<CheckingError> (); - warnings = new LinkedList<CheckingError> (); - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - tm = new TURTLEModeling(); - tmState = 0; - listE = new CorrespondanceTGElement(); - mgui.reinitCountOfPanels(); - - LinkedList ll; - ListIterator iterator, iterator2; - - // First step: adding all necessary classes + their ad - ll = dp.tddp.getListOfNodes(); - iterator = ll.listIterator(); - TDDNode node; - Vector artifacts; - TDDArtifact art; - int i; - DesignPanel dp2; - TGComponent tgc; - //TCDTClass tc; - String name; - TClass t; - DesignPanelTranslator dpt; - - // Loop on nodes - while(iterator.hasNext()) { - node = (TDDNode)(iterator.next()); - - // Loop on artifact - artifacts = node.getArtifactList(); - for(i=0; i<artifacts.size(); i++) { - art = (TDDArtifact)(artifacts.elementAt(i)); - dp2 = art.getDesignPanel(); - - iterator2 = dp2.tcdp.getComponentList().listIterator(); - LinkedList<TClassInterface> tclasses = new LinkedList<TClassInterface> (); - while(iterator2.hasNext()) { - tgc = (TGComponent)(iterator2.next()); - if (tgc instanceof TClassInterface) { - TraceManager.addDev("Found tclass: " + tgc.getValue()); - tclasses.add((TClassInterface) tgc); - } - } - if (tclasses.size() > 0) { - name = node.getNodeName() + "__" + art.getValue() + "__"; - dpt = new DesignPanelTranslator(dp2); - dpt.addTClasses(dp2, tclasses, name,tm); - dpt.addRelations(dp2, name,tm); - - listE.merge(dpt.getCorrespondanceTGElement()); - checkingErrors.addAll(dpt.getErrors()); - - // Set package name of tclasses - for(int j=0; j<tclasses.size(); j++) { - tgc = (TGComponent) tclasses.get (j); - t = listE.getTClass(tgc); - if (t != null) { - TraceManager.addDev("Setting package name of " + t.getName() + " to " + node.getNodeName()); - t.setPackageName(node.getNodeName()+"_"+art.getValue()); - } - } - } - } - } + public void loadTMLCPDiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { + String name; - // Second step : dealing with links! + name = elt.getAttribute("name"); + if (!(mgui.isTMLCPCreated(indexAnalysis, name))) { + mgui.createTMLCPDiagram(indexAnalysis, name); + } - DDTranslator ddt = new DDTranslator(dp, tm, listE); + TDiagramPanel tdp = mgui.getTMLCPDiagramPanel(indexAnalysis, name); - try { - TraceManager.addDev("Dealing with links!"); - ddt.translateLinks(); - } catch (DDSyntaxException e) { - //throw new AnalysisSyntaxException("Problem during translation to a design TURTLE modeling"); - TraceManager.addDev("Error during translation: " + e.getMessage()); - return false; - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - mgui.setMode(MainGUI.GEN_DESIGN_OK); + loadDiagram(elt, tdp); + } - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } + public void loadTMLSDDiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { + String name; - // modeling is built - // Now check it ! - TURTLEModelChecker tmc = new TURTLEModelChecker(tm); - checkingErrors = tmc.syntaxAnalysisChecking(); + name = elt.getAttribute("name"); + if (!(mgui.isTMLCPSDCreated(indexAnalysis, name))) { + mgui.createTMLCPSequenceDiagram(indexAnalysis, name); + } - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } else { - mgui.setMode(MainGUI.GEN_DESIGN_OK); - return true; - } - } + TDiagramPanel tdp = mgui.getTMLCPSDDiagramPanel(indexAnalysis, name); - public boolean translateAttackTreePanel(AttackTreePanel atp) { - AttackTreePanelTranslator att = new AttackTreePanelTranslator(atp); - /*attackTree =*/ att.translateToAttackTreeDataStructure(); - checkingErrors = att.getCheckingErrors(); - warnings = att.getWarnings(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } - avatarspec = att.generateAvatarSpec(); - TraceManager.addDev("Avatar spec:" + avatarspec); - return true; - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - public boolean translateNC(NCPanel ncp) { - TraceManager.addDev("Translating NC"); - checkingErrors = new LinkedList<CheckingError> (); - warnings = new LinkedList<CheckingError> (); - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - - GNCModeling gncm = new GNCModeling(ncp); - ncs = gncm.translateToNCStructure(); - listE = gncm.getCorrespondanceTable(); - - checkingErrors = gncm.getCheckingErrors(); - warnings = gncm.getCheckingWarnings(); - - TraceManager.addDev("errors:" + checkingErrors.size() + " warnings:" + warnings.size()); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } else { - // Generate XML file - try { - String fileName = "network.xml"; - if (ConfigurationTTool.NCDirectory != null) { - fileName = ConfigurationTTool.NCDirectory + fileName; - } - TraceManager.addDev("Saving in network structure in file: " + fileName); - FileUtils.saveFile(fileName, ncs.toISAENetworkXML()); - fileName = "traffics.xml"; - if (ConfigurationTTool.NCDirectory != null) { - fileName = ConfigurationTTool.NCDirectory + fileName; - } - TraceManager.addDev("Saving in traffics in file: " + fileName); - FileUtils.saveFile(fileName, ncs.toISAETrafficsXML()); - TraceManager.addDev("Save done"); - } catch (FileException fe) { - TraceManager.addError("Could not save NC in file:" + fe.getMessage()); - } - mgui.setMode(MainGUI.NC_OK); - return true; - } + loadDiagram(elt, tdp); + } - } + public void loadRequirementDiagram(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - private void nullifyTMLModeling() { - tmlm = null; - artificialtmap = null; - tmap = null; - tmlcp = null; - } + name = elt.getAttribute("name"); + mgui.createRequirementDiagram(indexAnalysis, name); - public boolean translateTMLDesign(Vector tasksToTakeIntoAccount, TMLDesignPanel tmldp, boolean optimize) { - nullifyTMLModeling(); - ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); - warnings = new LinkedList<CheckingError> (); - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - - GTMLModeling gtmlm = new GTMLModeling(tmldp, true); - gtmlm.setTasks(tasksToTakeIntoAccount); - tmlm = gtmlm.translateToTMLModeling(true); - //tmlm.removeAllRandomSequences(); - TraceManager.addDev("New TML Modeling:" + tmlm.toString()); - mgui.generateTMLTxt(); - artificialtmap = tmlm.getDefaultMapping(); - tmap = null; - listE = gtmlm.getCorrespondanceTable(); - //TraceManager.addDev("TML Modeling translated"); - //TraceManager.addDev("----- TML Modeling -----"); - //TraceManager.addDev(tmlm.toString()); - //TraceManager.addDev("------------------------"); - checkingErrors = gtmlm.getCheckingErrors(); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - return false; - } else { - if (optimize) { - warningsOptimize = tmlm.optimize(); - } + TDiagramPanel tdp = mgui.getRequirementDiagramPanel(indexAnalysis, indexTab, name); - tmState = 2; - mgui.resetAllDIPLOIDs(); - listE.useDIPLOIDs(); - return true; - //TraceManager.addDev("tm generated:"); - //tm.print(); - } - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - public Vector<CheckingError> convertToCheckingErrorTMLErrors(ArrayList<TMLError> warningsOptimize, TDiagramPanel _tdp) { - Vector<CheckingError> v = new Vector<CheckingError>(); - CheckingError warning; - for(TMLError error: warningsOptimize) { - warning = new CheckingError(CheckingError.BEHAVIOR_ERROR, error.message); - warning.setTDiagramPanel(_tdp); - warning.setTMLTask(error.task); - v.add(warning); - } - return v; - } + loadDiagram(elt, tdp); + } - public boolean translateTMLComponentDesign(Vector componentsToTakeIntoAccount, TMLComponentDesignPanel tmlcdp, boolean optimize) { - nullifyTMLModeling(); - // ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); - warnings = new LinkedList<CheckingError> (); - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - - GTMLModeling gctmlm = new GTMLModeling(tmlcdp, true); - gctmlm.putPrefixName(true); - gctmlm.setComponents(componentsToTakeIntoAccount); - tmlm = gctmlm.translateToTMLModeling(true); - mgui.generateTMLTxt(); - artificialtmap = tmlm.getDefaultMapping(); - tmap = null; - listE = gctmlm.getCorrespondanceTable(); - - //TraceManager.addDev("TML Modeling translated"); - //TraceManager.addDev("----- TML Modeling -----"); - //TraceManager.addDev(tmlm.toString()); - //TraceManager.addDev("------------------------"); - //mgui.generateTMLTxt(); - checkingErrors = gctmlm.getCheckingErrors(); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - return false; - } - else { - // if (optimize) { - // //TraceManager.addDev("OPTIMIZE"); - // warningsOptimize = tmlm.optimize(); - // } - - tmState = 2; - //TraceManager.addDev("tm generated:"); - mgui.resetAllDIPLOIDs(); - listE.useDIPLOIDs(); - return true; - //tm.print(); - } - } + public void loadEBRDD(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; - public boolean translateTMLModeling() { - TML2TURTLE tt = new TML2TURTLE(tmlm); - tm = tt.generateTURTLEModeling(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - TraceManager.addDev("Error in TURTLE generation"); - analyzeErrors(); - return false; - } else { - // Optimize - TraceManager.addDev("Optimize"); - tm.optimize(); - TraceManager.addDev("Optimize done"); - TURTLEModelChecker tmc = new TURTLEModelChecker(tm); - checkingErrors = tmc.syntaxAnalysisChecking(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - return false; - } else { - mgui.setMode(MainGUI.GEN_DESIGN_OK); - return true; - } - } - } + name = elt.getAttribute("name"); + mgui.createEBRDD(indexAnalysis, name); - public boolean checkSyntaxTMLMapping(Vector nodesToTakeIntoAccount, TMLArchiPanel tmlap, boolean optimize) { - ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); - warnings = new LinkedList<CheckingError> (); - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - //TraceManager.addDev("New TML Mapping"); - GTMLModeling gtmlm = new GTMLModeling(tmlap, true); - - - gtmlm.setNodes(nodesToTakeIntoAccount); //simply transforms the parameter from a Vector to LinkedList - nullifyTMLModeling(); - tmlm = null; - tm = null; - tmState = 1; - tmap = gtmlm.translateToTMLMapping(); - - listE = gtmlm.getCorrespondanceTable(); - - checkingErrors = gtmlm.getCheckingErrors(); - avatarspec = gtmlm.avspec; - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - analyzeErrors(); - warnings = gtmlm.getCheckingWarnings(); - return false; - } else { - //tmap.removeAllRandomSequences(); - if (optimize) { - warningsOptimize = tmap.optimize(); - } - warnings.addAll(convertToCheckingErrorTMLErrors(warningsOptimize, tmlap.tmlap)); - mgui.resetAllDIPLOIDs(); - listE.useDIPLOIDs(); - mgui.setMode(MainGUI.GEN_DESIGN_OK); - return true; - } - } - //Newly introduced to perform Syntax check of CP diagrams. Actually the mapping of CPs onto the architecture is done via SDs, - //onto the application is done onto blocks in the architecture. It would be better to have all the mapping information in one - //diagram. Up to now, not taking the mapping information into account - public boolean checkSyntaxTMLCP( Vector nodesToTakeIntoAccount, TMLCommunicationPatternPanel tmlcpp, boolean optimize ) { - - //nodesToTakeIntoAccount is the list of SDs and ADs corresponding that compose the CP selected for syntax checking - ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); - warnings = new LinkedList<CheckingError> (); - mgui.setMode( MainGUI.VIEW_SUGG_DESIGN_KO ); - GTMLModeling gtmlm = new GTMLModeling( tmlcpp, true ); - - TraceManager.addDev( "NodesToTakeIntoAccount :" + nodesToTakeIntoAccount.toString() ); - - //Useless because nodesToTakeIntoAccount does not include the mainCP! - //gtmlm.setDiagramPanels( nodesToTakeIntoAccount ); //passes the list of nodes (SDs and ADs) to gtml as a LinkedList - tmlm = null; - tm = null; - tmState = 1; - nullifyTMLModeling(); - //tmlcp is the data structure for a CP corresponding to the graphical description with diagrams - tmlcp = gtmlm.translateToTMLCPDataStructure( tmlcpp.getName() ); - //tmlcp.toString(); - /*TraceManager.addDev( "I AM ABOUT TO GENERATE THE TMLtxt CODE!" ); - mgui.generateTMLTxt(); //Now generating the TMLtxt code - TraceManager.addDev( "TMLtxt CODE GENERATION DONE" );*/ - listE = gtmlm.getCorrespondanceTable(); - //for( CorrespondanceTGElement element : listE.getNames() ) { - TraceManager.addDev( "Printing listE.getNames: " + listE.getNames().toString() ); - TraceManager.addDev( "Printing listE.getTG: " + listE.getTG().toString() ); - TraceManager.addDev( "Printing listE.getPanelNames: " + listE.getPanelNames().toString() ); - TraceManager.addDev( "Printing listE.getData: " + listE.getData().toString() ); - //} - checkingErrors = gtmlm.getCheckingErrors(); - - if( (checkingErrors != null) && (checkingErrors.size() > 0) ) { - //analyzeErrors(); - - return false; - } - /*else { - //tmcp.removeAllRandomSequences(); - if( optimize ) { - warningsOptimize = tmap.optimize(); - //warningsOptimize = tmcp.optimize(); - } - warnings.addAll( convertToCheckingErrorTMLErrors(warningsOptimize, tmlcpp.tmlcpp ) ); - mgui.resetAllDIPLOIDs(); - listE.useDIPLOIDs(); - mgui.setMode( MainGUI.GEN_DESIGN_OK ); - return true; - }*/ - return true; //It means that there are no errors - } + TDiagramPanel tdp = mgui.getEBRDDPanel(indexAnalysis, indexTab, name); - public boolean translateTMLMapping(boolean _sample, boolean _channel, boolean _event, boolean _request, boolean _exec, boolean _busTransfers, boolean _scheduling, boolean _taskState, boolean _channelState, boolean _branching, boolean _terminateCPU, boolean _terminateCPUs, boolean _clocked, String _tickValue, boolean _endClocked, boolean _countTick, boolean _maxCountTick, String _maxCountTickValue, boolean _randomTask) { - //TraceManager.addDev("TML=" + tmap.toString()); - Mapping2TIF m2tif = new Mapping2TIF(tmap); - m2tif.setShowSampleChannels(_sample); - m2tif.setShowChannels(_channel); - m2tif.setShowEvents(_event); - m2tif.setShowRequests(_request); - m2tif.setShowExecs(_exec); - m2tif.setShowBusTransfers(_busTransfers); - m2tif.setShowScheduling(_scheduling); - m2tif.setIsClocked(_clocked); - m2tif.setTickValue(_tickValue); - m2tif.setIsEndClocked(_endClocked); - m2tif.setIsCountTick(_countTick); - m2tif.hasMaxCountTick(_maxCountTick); - if (_maxCountTick) { - m2tif.setMaxCountTickValue(_maxCountTickValue); - } - m2tif.setShowTaskState(_taskState); - m2tif.setShowChannelState(_channelState); - m2tif.setShowBlockedCPU(_terminateCPU); - m2tif.setShowTerminateCPUs(_terminateCPUs); - m2tif.setShowBranching(_branching); - m2tif.setRandomTasks(_randomTask); - tm = m2tif.generateTURTLEModeling(); - //StringBuffer sb = tm.printToStringBuffer(); - //TraceManager.addDev("tm=" + sb); - - TraceManager.addDev("tm generated from TMAP"); - checkingErrors = m2tif.getCheckingErrors(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } - mgui.setMode(MainGUI.GEN_DESIGN_OK); - return true; - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); - //Added by Solange - public void generateLists(ProactiveDesignPanel pdp) { - gpdtemp = new GProactiveDesign(pdp); - } - // - - public boolean translateTURTLEOSDesign(TURTLEOSDesignPanel tosdp) { - warnings = new LinkedList<CheckingError> (); - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - //TraceManager.addDev("New TML Modeling"); - GTURTLEOSModeling gosm = new GTURTLEOSModeling(tosdp); - //gtmlm.setTasks(tasksToTakeIntoAccount); - //tmlm = gosm.translateToTMLModeling(); - //TraceManager.addDev("TML Modeling translated"); - //TraceManager.addDev("----- TML Modeling -----"); - //TraceManager.addDev(tmlm.toString()); - //TraceManager.addDev("------------------------"); - tm = gosm.generateTURTLEModeling(); - tmState = 0; - checkingErrors = gosm.getCheckingErrors(); - - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } else { - - //TraceManager.addDev("Optimize"); - tm.optimize(); - //TraceManager.addDev("Optimize done"); - TURTLEModelChecker tmc = new TURTLEModelChecker(tm); - checkingErrors = tmc.syntaxAnalysisChecking(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } else { - warnings = gosm.getCheckingWarnings(); - warnings.addAll(tmc.getWarnings()); - mgui.setMode(MainGUI.GEN_DESIGN_OK); - return true; - } - } - } + loadDiagram(elt, tdp); + } + public void loadAttackTreeDiagram(Element elt, int indexDiag, int indexTab) throws MalformedModelingException, SAXException { + String name; - public boolean translateProactiveDesign(ProactiveDesignPanel pdp) { - mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); - GProactiveDesign gpd = new GProactiveDesign(pdp); + //TraceManager.addDev("indexDiag=" + indexDiag); - tm = gpd.generateTURTLEModeling(); - tmState = 0; + name = elt.getAttribute("name"); + mgui.createAttackTreeDiagram(indexDiag, name); - if (gpd.checkSyntax() == false) { - TraceManager.addDev("Errors found"); - warnings = gpd.getCheckingWarnings(); - checkingErrors = gpd.getCheckingErrors(); - return false; - } - TURTLEModelChecker tmc = new TURTLEModelChecker(tm); - checkingErrors = tmc.syntaxAnalysisChecking(); - warnings = tmc.getWarnings(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } else { - //A faire: - // tm.optimize(); - // warnings = gpd.getCheckingWarnings(); - // warnings.addAll(tmc.getWarnings()); - mgui.setMode(MainGUI.GEN_DESIGN_OK); - return true; - } + TDiagramPanel tdp = mgui.getAttackTreeDiagramPanel(indexDiag, indexTab, name); - } + if (tdp == null) { + throw new MalformedModelingException(); + } + tdp.removeAll(); + loadDiagram(elt, tdp); + } - public void addStates(AvatarStateMachineElement asme, int x, int y, AvatarSMDPanel smp, AvatarBDBlock bl, Map<AvatarStateMachineElement, TGComponent> SMDMap, Map<AvatarStateMachineElement, TGComponent> locMap, Map<AvatarTransition, AvatarStateMachineElement> tranDestMap, Map<AvatarTransition, TGComponent> tranSourceMap){ - TGConnectingPoint tp = new TGConnectingPoint(null, x, y, false, false); - //Create dummy tgcomponent - TGComponent tgcomp = new AvatarSMDStartState(x,y,x,x*2,y,y*2,false,null,smp); - if (asme instanceof AvatarStartState){ - AvatarSMDStartState smdss = new AvatarSMDStartState(x, y, x, x*2, y, y*2, false, null, smp); - tgcomp = smdss; - smp.addComponent(smdss, x, y, false, true); - SMDMap.put(asme, smdss); - tp = smdss.tgconnectingPointAtIndex(0); - locMap.put(asme, smdss); - } - if (asme instanceof AvatarTransition){ - // - } - if (asme instanceof AvatarActionOnSignal){ - avatartranslator.AvatarSignal sig = ((AvatarActionOnSignal) asme).getSignal(); - if (sig.isIn()){ - AvatarSMDReceiveSignal smdrs = new AvatarSMDReceiveSignal(x, y, x, x*2, y, y*2, false, null, smp); - tgcomp=smdrs; - smp.addComponent(smdrs, x, y, false, true); - String name=sig.getName(); - - String params = ""; - if (((AvatarActionOnSignal)asme).getNbOfValues()!=0){ - params+=((AvatarActionOnSignal)asme).getValue(0); - for (int i=1; i<((AvatarActionOnSignal)asme).getNbOfValues(); i++){ - params +=","; - params += ((AvatarActionOnSignal)asme).getValue(i); - } - } - smdrs.setValue(name +"("+params+")"); - - // sig.setName(name); - smdrs.recalculateSize(); - SMDMap.put(asme, smdrs); - tp = smdrs.getFreeTGConnectingPoint(x+smdrs.getWidth()/2,y+smdrs.getHeight()); - TGConnectingPoint tp2 = smdrs.getFreeTGConnectingPoint(x+smdrs.getWidth()/2,y); - locMap.put(asme, smdrs); - if (bl.getAvatarSignalFromName(name) ==null){ - //bl.addSignal(new ui.AvatarSignal(0, name, new String[0], new String[0])); - } + public void loadSequenceDiagram(Element elt, int indexAnalysis) throws MalformedModelingException, SAXException { + String name; - } - else { - AvatarSMDSendSignal smdss = new AvatarSMDSendSignal(x, y, x, x*2, y, y*2, false, null, smp); - tgcomp=smdss; - smp.addComponent(smdss, x, y, false, true); - String name=sig.getName(); - //System.out.println("value " +((AvatarActionOnSignal)asme).getValues()); - - String params = ""; - if (((AvatarActionOnSignal)asme).getNbOfValues()!=0){ - params+=((AvatarActionOnSignal)asme).getValue(0); - for (int i=1; i<((AvatarActionOnSignal)asme).getNbOfValues(); i++){ - params +=","; - params += ((AvatarActionOnSignal)asme).getValue(i); - } - } - smdss.setValue(name +"("+params+")"); - smdss.recalculateSize(); - SMDMap.put(asme, smdss); - tp = smdss.getFreeTGConnectingPoint(x+smdss.getWidth()/2,y+smdss.getHeight()); - TGConnectingPoint tp2 = smdss.getFreeTGConnectingPoint(x+smdss.getWidth()/2,y); - locMap.put(asme, smdss); - if (bl.getAvatarSignalFromName(name) == null){ - // bl.addSignal(new ui.AvatarSignal(1, name, new String[0], new String[0])); - } - } + name = elt.getAttribute("name"); + if (!(mgui.isSDCreated(indexAnalysis, name))) { + mgui.createSequenceDiagram(indexAnalysis, name); + } + //TraceManager.addDev("Loading seq diag1"); + SequenceDiagramPanel sdp = mgui.getSequenceDiagramPanel(indexAnalysis, name); + //TraceManager.addDev("Loading seq diag2"); + + if (sdp == null) { + throw new MalformedModelingException(); + } + //TraceManager.addDev("Loading seq diag3"); + + sdp.removeAll(); + //TraceManager.addDev("Loading seq diag4"); - } - if (asme instanceof AvatarStopState){ - AvatarSMDStopState smdstop = new AvatarSMDStopState(x, y, x, x*2, y, y*2, false, null, smp); - tgcomp=smdstop; - SMDMap.put(asme, smdstop); - smp.addComponent(smdstop, x, y, false, true); - tp = smdstop.tgconnectingPointAtIndex(0); - locMap.put(asme, smdstop); - } - if (asme instanceof AvatarState){ - //check if empty checker state - /* if (asme.getName().contains("signalstate_")){ - //don't add the state, ignore next transition, - if (asme.getNexts().size()==1){ - AvatarStateMachineElement next = asme.getNext(0).getNext(0); - //Reroute transition - for (AvatarTransition at: tranDestMap.keySet()){ - if (tranDestMap.get(at) == asme){ - tranDestMap.put(at, next); - } - } - addStates(next, x, y, smp,bl, SMDMap, locMap, tranDestMap, tranSourceMap); - return; - } - }*/ - AvatarSMDState smdstate = new AvatarSMDState(x, y, x, x*2, y, y*2, false, null, smp); - tgcomp=smdstate; - smp.addComponent(smdstate, x, y, false, true); - smdstate.setValue(asme.getName()); - smdstate.recalculateSize(); - SMDMap.put(asme, smdstate); - tp = smdstate.getFreeTGConnectingPoint(x+smdstate.getWidth()/2,y+smdstate.getHeight()); - TGConnectingPoint tp2 = smdstate.getFreeTGConnectingPoint(x+smdstate.getWidth()/2,y); - locMap.put(asme, smdstate); - } - int i=0; - int diff=100; - int ydiff=50; - int num = asme.nbOfNexts(); - if (!(asme instanceof AvatarTransition)){ - for (AvatarStateMachineElement el:asme.getNexts()){ - if (!(el instanceof AvatarTransition)){ - System.out.println("ERROR: non-Transition " + asme + " connected to non-Transition " + el); - } - } - } - for (AvatarStateMachineElement el:asme.getNexts()){ - if (el instanceof AvatarTransition){ - tranSourceMap.put((AvatarTransition) el, tgcomp); - } - else { - if (asme instanceof AvatarTransition){ - AvatarTransition t = (AvatarTransition) asme; - tranDestMap.put(t, el); - } - } - if (!SMDMap.containsKey(el)){ - addStates(el, x+diff*(i-num/2), y+ydiff, smp, bl, SMDMap, locMap, tranDestMap, tranSourceMap); - } - i++; - } - smp.setMaxPanelSize(x+100,y+100); - return; - } + loadDiagram(elt, sdp); + //TraceManager.addDev("Loading seq diag5"); + } + + public void loadUseCaseDiagram(Element elt, int indexAnalysis, int indexTab) throws MalformedModelingException, SAXException { + String name; + + name = elt.getAttribute("name"); + /*if (!(mgui.isUCDCreated(indexAnalysis, name))) {*/ + mgui.createUseCaseDiagram(indexAnalysis, name); + //} + UseCaseDiagramPanel ucdp = mgui.getUseCaseDiagramPanel(indexAnalysis, indexTab, name); + + if (ucdp == null) { + throw new MalformedModelingException(); + } + + ucdp.removeAll(); + + loadDiagram(elt, ucdp); + } + + public void loadTDeploymentDiagram(Element elt, int indexDeployment) throws MalformedModelingException, SAXException { + String name; + + name = elt.getAttribute("name"); + mgui.setDeploymentName(indexDeployment, name); + TDiagramPanel tdp = mgui.getMainTDiagramPanel(indexDeployment); + + loadDiagram(elt, tdp); + } + + public void loadNCDiagram(Element elt, int indexNC) throws MalformedModelingException, SAXException { + String name; + + name = elt.getAttribute("name"); + mgui.setNCName(indexNC, name); + TDiagramPanel tdp = mgui.getMainTDiagramPanel(indexNC); + + loadDiagram(elt, tdp); + } - public void drawBlockProperties(AvatarBlock ab, AvatarBDBlock bl){ + // reinit the id of all components + public void makeLovelyIds() { + TDiagramPanel tdp; + int id = 1; + int i, j; + TURTLEPanel tp; + // search for diagram panels + for(i=0; i<panels.size(); i++) { + tp = (TURTLEPanel)(panels.elementAt(i)); + for(j=0; j<tp.panels.size(); j++) { + tdp = (TDiagramPanel)(tp.panels.elementAt(j)); + id = tdp.makeLovelyIds(id); + //TraceManager.addDev("Lovely id =" + id); + } + } + + TGComponent.setGeneralId(id + 1); + } + + public void loadDiagramInformation(Element elt, TDiagramPanel tdp) throws MalformedModelingException { + int x, y; + double zoom = 0; + try { + x = Integer.decode(elt.getAttribute("minX")).intValue(); + tdp.setMinX(x); + x = Integer.decode(elt.getAttribute("maxX")).intValue(); + tdp.setMaxX(x); + y = Integer.decode(elt.getAttribute("minY")).intValue(); + tdp.setMinY(y); + y = Integer.decode(elt.getAttribute("maxY")).intValue(); + tdp.setMaxY(y); + tdp.updateSize(); + zoom = Double.parseDouble(elt.getAttribute("zoom")); + if (zoom != 0) { + tdp.setZoom(zoom); + mgui.updateZoomInfo(); + } + } catch (Exception e) { + // Model was saved in an older version of TTool + } + + if (tdp instanceof TActivityDiagramPanel) { + ((TActivityDiagramPanel)tdp).loadExtraParameters(elt); + } + } + + public void loadActivityDiagram(TDiagramPanel tdp, String oldValue, String newValue) throws MalformedModelingException { + //TraceManager.addDev("---> Load activity diagram"); + try { + NodeList activityDiagramNl = docCopy.getElementsByTagName("TActivityDiagramPanel"); + + TraceManager.addDev("Loading activity diagram of " + newValue + "Before : " + oldValue); + TraceManager.addDev(""+docCopy); + + if (activityDiagramNl == null) { + throw new MalformedModelingException(); + } + + Node adn; + Element elt; + TActivityDiagramPanel tadp; + String name; + int decXTmp = decX; + int decYTmp = decY; + int decIdTmp = decId; + + for(int i=0; i<activityDiagramNl.getLength(); i++) { + adn = activityDiagramNl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + // class diagram name + name = elt.getAttribute("name"); + //TraceManager.addDev("Name of activity diagram=" + name); + + if (name.equals(oldValue)) { + int indexDesign = mgui.getMajorIndexOf(tdp); + + if (indexDesign < 0) { + throw new MalformedModelingException(); + } + + tadp = mgui.getActivityDiagramPanel(indexDesign, newValue); + + //TraceManager.addDev("Searching panel"); + + if (tadp == null) { + throw new MalformedModelingException(); + } + + //TraceManager.addDev("Panel ok"); + + decX = 0; decY = 0; decId = 0; + + + + tadp.removeAll(); + + loadDiagramInformation(elt, tadp); + + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tadp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(tadp); + tadp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(tadp, 0); + } + } + } + decX = decXTmp; + decY = decYTmp; + decId = decIdTmp; + } catch (SAXException saxe) { + TraceManager.addError("Loading 701 " + saxe.getMessage()); + throw new MalformedModelingException(); + } + } + + public void loadAvatarSMD(TDiagramPanel tdp, String oldValue, String newValue) throws MalformedModelingException { + TraceManager.addDev("---> Load activity diagram of old=" + oldValue + " new=" + newValue); + try { + NodeList smdNl = docCopy.getElementsByTagName("AVATARStateMachineDiagramPanel"); + + //TraceManager.addDev("Loading state machine diagram of " + newValue + " Before : " + oldValue); + //TraceManager.addDev("smdNL: " + smdNl); + + if (smdNl == null) { + TraceManager.addDev("AVATAR: null doc"); + throw new MalformedModelingException(); + } + + Node adn; + Element elt; + AvatarSMDPanel asmdp; + String name; + int decXTmp = decX; + int decYTmp = decY; + int decIdTmp = decId; + + for(int i=0; i<smdNl.getLength(); i++) { + adn = smdNl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + // class diagram name + name = elt.getAttribute("name"); + TraceManager.addDev("Name of activity diagram=" + name); + + if (name.equals(oldValue)) { + int indexDesign = mgui.getMajorIndexOf(tdp); + + if (indexDesign < 0) { + throw new MalformedModelingException(); + } + + asmdp = mgui.getAvatarSMDPanel(indexDesign, newValue); + + TraceManager.addDev("Searching panel: " + newValue); + + if (asmdp == null) { + throw new MalformedModelingException(); + } + + TraceManager.addDev("Panel ok"); + + decX = 0; decY = 0; decId = 0; + + + asmdp.removeAll(); + + loadDiagramInformation(elt, asmdp); + + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), asmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), asmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), asmdp); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " real points"); + connectConnectorsToRealPoints(asmdp); + asmdp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tadp.getName() + " post loading"); + makePostLoading(asmdp, 0); + } + } + } + decX = decXTmp; + decY = decYTmp; + decId = decIdTmp; + } catch (SAXException saxe) { + TraceManager.addError("Loading 801 " + saxe.getMessage()); + throw new MalformedModelingException(); + } + } + + public void loadTMLActivityDiagram(TDiagramPanel tdp, String oldValue, String newValue) throws MalformedModelingException { + //TraceManager.addDev("---> Load TML activity diagram"); + try { + if (docCopy == null) { + TraceManager.addDev("Null doc copy"); + } + NodeList activityDiagramNl = docCopy.getElementsByTagName("TMLActivityDiagramPanel"); + + //TraceManager.addDev("Loading activity diagram of " + newValue + "Before : " + oldValue); + + if (activityDiagramNl == null) { + //TraceManager.addDev("Null"); + throw new MalformedModelingException(); + } + + Node adn; + Element elt; + TMLActivityDiagramPanel tmladp; + String name; + int decXTmp = decX; + int decYTmp = decY; + int decIdTmp = decId; + + for(int i=0; i<activityDiagramNl.getLength(); i++) { + adn = activityDiagramNl.item(i); + if (adn.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) adn; + // class diagram name + name = elt.getAttribute("name"); + //TraceManager.addDev("Name of activity diagram=" + name); + + if (name.equals(oldValue)) { + int indexDesign = mgui.getMajorIndexOf(tdp); + + if (indexDesign < 0) { + throw new MalformedModelingException(); + } + + tmladp = mgui.getTMLActivityDiagramPanel(indexDesign, newValue); + + //TraceManager.addDev("Searching panel"); + + if (tmladp == null) { + throw new MalformedModelingException(); + } + + //TraceManager.addDev("Panel ok"); + + decX = 0; decY = 0; decId = 0; + + tmladp.removeAll(); + + loadDiagramInformation(elt, tmladp); + + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " components"); + makeXMLComponents(elt.getElementsByTagName("COMPONENT"), tmladp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " connectors"); + makeXMLConnectors(elt.getElementsByTagName("CONNECTOR"), tmladp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " subcomponents"); + makeXMLComponents(elt.getElementsByTagName("SUBCOMPONENT"), tmladp); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " real points"); + connectConnectorsToRealPoints(tmladp); + tmladp.structureChanged(); + //TraceManager.addDev("Activity diagram : " + tmladp.getName() + " post loading"); + makePostLoading(tmladp, 0); + } + } + } + decX = decXTmp; + decY = decYTmp; + decId = decIdTmp; + } catch (SAXException saxe) { + TraceManager.addError("Loading 901 " + saxe.getMessage()); + throw new MalformedModelingException(); + } + } + + public void makePostLoading(TDiagramPanel tdp, int beginIndex) throws MalformedModelingException{ + TGComponent tgc; + + //TraceManager.addDev("Post loading of diagram " + tdp.toString()); + + LinkedList list = tdp.getComponentList(); + + for(int i=0; i<list.size()-beginIndex; i++) { + tgc = (TGComponent)(list.get(i)); + //TraceManager.addDev(tgc.getName()); + //TraceManager.addDev(tgc.getValue()); + tgc.makePostLoading(decId); + } + + //TraceManager.addDev("Post loading of diagram " + tdp.toString() + " achieved"); + } + + public void makeXMLComponents(NodeList nl, TDiagramPanel tdp) throws SAXException, MalformedModelingException { + Node n; + //Element elt; + TGComponent tgc; + + if (tdp == null) { + throw new MalformedModelingException(); + } + boolean error = false; + + for(int i=0; i<nl.getLength(); i++) { + n = nl.item(i); + if (n.getNodeType() == Node.ELEMENT_NODE) { + try { + tgc = makeXMLComponent(n, tdp); + //TraceManager.addDev("About to add component= " + tgc); + if ((tgc != null) && (tgc.getFather() == null)) { + //TraceManager.addDev("Component added to diagram tgc=" + tgc); + tdp.addBuiltComponent(tgc); + } else { + //TraceManager.addDev("Component not added to diagram"); + } + } catch (MalformedModelingException mme) { + TraceManager.addDev ("Could not create component " + n); + error = true; + } + } + } + + if (error) { + throw new MalformedModelingException(); + } + } + + + public TGComponent makeXMLComponent(Node n, TDiagramPanel tdp) throws SAXException, MalformedModelingException { + Element elt; + Element elt1; + //TraceManager.addDev(n.toString()); + TGComponent tgc = null; + TGComponent father; + + // + try { + + NodeList nl = n.getChildNodes(); + elt = (Element)n; + elt1 = elt; + //TraceManager.addDev("elt=" + elt); + + int myType = Integer.decode(elt.getAttribute("type")).intValue(); + int myId = Integer.decode(elt.getAttribute("id")).intValue() + decId; + + int myX = -1, myY = -1, myWidth = -1, myHeight =-1; + int myMinWidth = -1, myMinHeight = -1, myMinDesiredWidth = -1, myMinDesiredHeight = -1; + int myMinX = -1, myMaxX = -1, myMinY = -1, myMaxY = -1; + String myName = null, myValue = null; + Vector tgcpList = new Vector(); + Point p; + int i, x, y; + int fatherId = -1, fatherNum = -1; + String pre = "", post = ""; + String internalComment = ""; + boolean accessibility = false; + boolean latencyCheck = false; + boolean invariant = false; + boolean breakpoint = false; + boolean hidden = false; + boolean masterMutex = false; + boolean enable = true; + + for(i=0; i<nl.getLength(); i++) { + n = nl.item(i); + if (n.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n; + if (elt.getTagName().equals("cdparam")) { + myX = Integer.decode(elt.getAttribute("x")).intValue() + decX; + myY = Integer.decode(elt.getAttribute("y")).intValue() + decY; + } else if (elt.getTagName().equals("sizeparam")) { + myWidth = Integer.decode(elt.getAttribute("width")).intValue(); + myHeight = Integer.decode(elt.getAttribute("height")).intValue(); + myMinWidth = Integer.decode(elt.getAttribute("minWidth")).intValue(); + myMinHeight = Integer.decode(elt.getAttribute("minHeight")).intValue(); + myMinDesiredWidth = Integer.decode(elt.getAttribute("minDesiredWidth")).intValue(); + myMinDesiredHeight = Integer.decode(elt.getAttribute("minDesiredHeight")).intValue(); + } else if (elt.getTagName().equals("cdrectangleparam")) { + myMinX = Integer.decode(elt.getAttribute("minX")).intValue(); + myMaxX = Integer.decode(elt.getAttribute("maxX")).intValue(); + myMinY = Integer.decode(elt.getAttribute("minY")).intValue(); + myMaxY = Integer.decode(elt.getAttribute("maxY")).intValue(); + } else if (elt.getTagName().equals("infoparam")) { + myName = elt.getAttribute("name"); + myValue = elt.getAttribute("value"); + } else if (elt.getTagName().equals("hidden")) { + hidden = elt.getAttribute("value").equals("true"); + } else if (elt.getTagName().equals("enabled")) { + enable = elt.getAttribute("value").equals("true"); + } else if (elt.getTagName().equals("TGConnectingPoint")) { + x = Integer.decode(elt.getAttribute("num")).intValue(); + y = Integer.decode(elt.getAttribute("id")).intValue() + decId; + tgcpList.add(new Point(x, y)); + } else if (elt.getTagName().equals("father")) { + fatherId = Integer.decode(elt.getAttribute("id")).intValue(); + fatherNum = Integer.decode(elt.getAttribute("num")).intValue(); + } else if (elt.getTagName().equals("prejavacode")) { + pre += elt.getAttribute("value") + "\n"; + } else if (elt.getTagName().equals("postjavacode")) { + post += elt.getAttribute("value") + "\n"; + } else if (elt.getTagName().equals("InternalComment")) { + internalComment += elt.getAttribute("value") + "\n"; + } else if (elt.getTagName().equals("accessibility")) { + accessibility = true; + } else if (elt.getTagName().equals("latencyCheck")) { + latencyCheck = true; + } else if (elt.getTagName().equals("invariant")) { + invariant = true; + } else if (elt.getTagName().equals("mastermutex")) { + masterMutex = true; + } else if (elt.getTagName().equals("breakpoint")) { + breakpoint = true; + } + } + } + + if ((myId == -1) || (myX == -1) || (myY == -1) || (myWidth == -1) || (myHeight == -1)) { + throw new MalformedModelingException(); + } + + //TraceManager.addDev("Making TGComponent of type " + myType + " and of name " + myName); + //TGComponent is ready to be built + if(fatherId != -1) { + fatherId += decId; + // internal component + //TraceManager.addDev("I am " + myName); + //TraceManager.addDev("Searching for component with id " + fatherId); + father = tdp.findComponentWithId(fatherId); + if (father == null) { + throw new MalformedModelingException(); + } + + //TraceManager.addDev("Done"); + //TraceManager.addDev("Father My value is " + father.getValue()); + //TraceManager.addDev("My class is " + father.getClass()); + + //TraceManager.addDev("Searching for component " + fatherNum + " at " + tgc.getName()); + tgc = father.getInternalTGComponent(fatherNum); + + if (tgc == null) { + // To be added to its father -> swallow component + if (father instanceof SwallowTGComponent) { + //TraceManager.addDev("1 Must add the component to its father:"); + tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); + //TraceManager.addDev("2 Must add the component to its father:" + tgc); + if (tgc instanceof SwallowedTGComponent) { + //TraceManager.addDev("3 Must add the component to its father:"); + ((SwallowTGComponent)father).addSwallowedTGComponent(tgc, myX, myY); + //TraceManager.addDev("Swallowed to father = " + father.getValue() + ". My name=" + myName + " decId=" + decId); + } else { + throw new MalformedModelingException(); + } + } else { + throw new MalformedModelingException(); + } + } + + if (tgc != null) { + tgc.setCdRectangle(myMinX, myMaxX, myMinY, myMaxY); + tgc.setCd(myX, myY); + //TraceManager.addDev("set cd of " + tgc.getName()); + } + } else { + tgc = TGComponentManager.addComponent(myX, myY, myType, tdp); + } + // TraceManager.addDev("TGComponent (" + tgc + ") built " + myType); + + if (tgc == null) { + throw new MalformedModelingException(); + } + + if (myName != null) { + tgc.setName(myName); + } + + tgc.setHidden(hidden); + tgc.setEnabled(enable); + + /*if (tgc instanceof TCDTObject) { + TraceManager.addDev("Loading " + myValue); + }*/ + + String oldClassName = myValue; + //TraceManager.addDev("Old class name=" + oldClassName); + //Added by Solange + if ((myValue != null) && (!myValue.equals(null))){ + if (tgc instanceof ProCSDComponent) + { + //Added by Solange + //And removed by emil + //myValue=generateNameIfInUse(myValue); + // tgc.setValueWithChange(myValue); + //TraceManager.addDev("myValue=" + myValue); + } + //until here + if ((tgc instanceof TCDTClass) && (decId >0)){ + if (tdp.isAlreadyATClassName(myValue)) { + myValue = tdp.findTClassName(myValue+"_"); + } + } + if ((tgc instanceof TMLTaskOperator) && (decId >0)){ + if (tdp.isAlreadyATMLTaskName(myValue)) { + myValue = tdp.findTMLTaskName(myValue+"_"); + } + } + + if ((tgc instanceof AvatarBDBlock) && (decId >0)){ + if (tdp.isAlreadyAnAvatarBDBlockName(myValue)) { + myValue = tdp.findAvatarBDBlockName(myValue+"_"); + } + } + + if ((tgc instanceof TMLCPrimitiveComponent) && (decId >0)){ + if (tdp.isAlreadyATMLPrimitiveComponentName(myValue)) { + myValue = tdp.findTMLPrimitiveComponentName(myValue+"_"); + } + //TraceManager.addDev("MyValue=" + myValue); + } + if ((tgc instanceof TOSClass) && (decId >0)){ + if (tdp.isAlreadyATOSClassName(myValue)) { + myValue = tdp.findTOSClassName(myValue+"_"); + } + } + //TraceManager.addDev("myValue=" + myValue); + tgc.setValueWithChange(myValue); + //TraceManager.addDev("value done"); + if ((tgc instanceof TCDTClass) && (decId >0)){ + loadActivityDiagram(tdp, oldClassName, myValue); + } + + if ((tgc instanceof AvatarBDBlock) && (decId >0)){ + //TraceManager.addDev("Going to load ad of task " + oldClassName + " myValue=" + myValue); + loadAvatarSMD(tdp, oldClassName, myValue); + } + + if ((tgc instanceof TMLTaskOperator) && (decId >0)){ + //TraceManager.addDev("Going to load ad of task " + oldClassName + " myValue=" + myValue); + loadTMLActivityDiagram(tdp, oldClassName, myValue); + } + + if ((tgc instanceof TMLCPrimitiveComponent) && (decId >0)){ + //TraceManager.addDev("Going to load ad of component " + oldClassName + " myValue=" + myValue); + loadTMLActivityDiagram(tdp, oldClassName, myValue); + } + } + + tgc.forceId(myId); + tgc.setLoaded(true); + tgc.setInternalLoaded(false); + tgc.setMinSize(myMinWidth, myMinHeight); + tgc.setMinDesiredSize(myMinDesiredWidth, myMinDesiredHeight); + tgc.resize(myWidth, myHeight); + tgc.hasBeenResized(); + + //TraceManager.addDev("Options set"); + + if (pre.compareTo("") != 0) { + tgc.setPreJavaCode(pre); + } + if (post.compareTo("") != 0) { + tgc.setPostJavaCode(post); + } + + if (internalComment.compareTo("") != 0) { + tgc.setInternalComment(internalComment); + } + + if (accessibility) { + tgc.setCheckableAccessibility(accessibility); + + } + + if (latencyCheck) { + tgc.setCheckLatency(latencyCheck); + + } + if (invariant) { + tgc.setCheckableInvariant(invariant); + } + + if (masterMutex) { + tgc.setMasterMutex(true); + } + + if (breakpoint) { + tgc.setBreakpoint(breakpoint); + } + + //extra param + // TraceManager.addDev("Extra params" + tgc.getClass()); + // TraceManager.addDev("My value = " + tgc.getValue()); + tgc.loadExtraParam(elt1.getElementsByTagName("extraparam"), decX, decY, decId); + // TraceManager.addDev("Extra param ok"); + + if ((tgc instanceof TCDTObject) && (decId > 0)) { + TCDTObject to = (TCDTObject)tgc; + //TraceManager.addDev("Setting TObject name to: " + to.getObjectName()); + //TraceManager.addDev("Setting TObject name to: " + tdp.findTObjectName(to.getObjectName())); + to.setObjectName(tdp.findTObjectName(to.getObjectName())); + } + + //TraceManager.addDev(tgc.toString()); + + //TraceManager.addDev("Making connecting points " + tgcpList.size()); + for(i=0; i<tgcpList.size(); i++) { + p = (Point)(tgcpList.elementAt(i)); + if (!tgc.setIdTGConnectingPoint(p.x, p.y)) { + //TraceManager.addDev("Warning: a connecting point has been removed"); + //throw new MalformedModelingException(); + } + } + + //TraceManager.addDev("Not yet except!"); + if (decId >0) { + tdp.bringToFront(tgc); + } + //TraceManager.addDev("Connecting points done " + myType); + + /*if (tgc instanceof TCDTObject) { + TraceManager.addDev("getValue " + tgc.getValue()); + }*/ + + } catch (Exception e) { + // TraceManager.addError("Exception XML Component "/* + e.getMessage() + "trace=" + e.getStackTrace()*/); + throw new MalformedModelingException(); + } + return tgc; + } + + //method added by Solange + + public String generateNameIfInUse(String myName) + { + if (!(mgui.getCurrentTURTLEPanel().nameInUse(myName))) + { + return myName; + } + + String other; + for(int w=0; w<100000; w++) + { + other = myName + "_" + w; + if (!(mgui.getCurrentTURTLEPanel().nameInUse(other))) + { + return other; + } + } + return null; + } + //until here + + public void makePostProcessing(TDiagramPanel tdp) throws MalformedModelingException{ + //TraceManager.addDev("Make post processing!"); + if (tdp instanceof TClassDiagramPanel) { + ((TClassDiagramPanel)tdp).makePostLoadingProcessing(); + } + //TraceManager.addDev("Post processing is over"); + } + + public void makeXMLConnectors(NodeList nl, TDiagramPanel tdp) throws SAXException, MalformedModelingException { + Node n; + //Element elt; + TGConnector tgco = null; + int i; + + if (tdp == null) { + throw new MalformedModelingException(); + } + + for(i=0; i<nl.getLength(); i++) { + n = nl.item(i); + if (n.getNodeType() == Node.ELEMENT_NODE) { + tgco = makeXMLConnector(n, tdp); + if (tgco != null) { + tdp.addBuiltConnector(tgco); + } else { + TraceManager.addDev("Connector error"); + throw new MalformedModelingException(); + } + } + } + } + + public void connectConnectorsToRealPoints(TDiagramPanel tdp) throws MalformedModelingException { + LinkedList list = tdp.getComponentList(); + TGConnectingPoint p1, p2, p3, p4; + //TGConnectingPointTmp p; + int i; + TGComponent tgc; + //TGComponent tgctmp; + TGConnector tgco = null; + //boolean error = false; + TGConnectorInfo tgcoinfo; + + + //connect connectors to their real connecting point + //TraceManager.addDev("Valid connectors ?"); + for(i=0; i<list.size(); i++) { + tgc = (TGComponent)(list.get(i)); + if (tgc instanceof TGConnector) { + tgco = (TGConnector)tgc; + p1 = tgco.getTGConnectingPointP1(); + p2 = tgco.getTGConnectingPointP2(); + if ((p1 instanceof TGConnectingPointTmp) && (p2 instanceof TGConnectingPointTmp)){ + //TraceManager.addDev("Searching for id " + p1.getId()); + p3 = tdp.findConnectingPoint(p1.getId()); + //TraceManager.addDev("Searching for id " + p2.getId()); + p4 = tdp.findConnectingPoint(p2.getId()); + if (((p3 ==null) || (p4 == null)) &&(decId != 0)) { + if (list.remove(tgc)) { + i --; + } else { + throw new MalformedModelingException(); + } + } else { + if ((p3 == null) ||(p4 == null)) { + //warning = true; + if (p3 == null) { + //TraceManager.addDev("Error on first id"); + } + if (p4 == null) { + //TraceManager.addDev("Error on second id"); + } + tgcoinfo = new TGConnectorInfo(); + tgcoinfo.connector = tgco; + pendingConnectors.add(tgcoinfo); + TraceManager.addDev("One connector added to pending list"); + } else { + tgco.setP1(p3); + p3.setFree(false); + tgco.setP2(p4); + p4.setFree(false); + } + } + } + } + } + + /*for(TGConnector con: connectorsToRemove) { + list.remove(con); + }*/ + + /*if (error) { + TraceManager.addDev("Connecting error: " + connectorsToRemove.size() + " connectors have been removed"); + throw new MalformedModelingException(); + }*/ + } + + public void makeLastLoad() { + // Update references on all diagrams + //TraceManager.addDev("Updating ports"); + //mgui.updateAllPorts(); + + // Update ports on all diagrams + //TraceManager.addDev("Updating references / ports"); + mgui.updateAllReferences(); + + mgui.updateAllPorts(); + + //TraceManager.addDev("Pending connectors"); + // Make use of pending connectors + TGConnectingPoint p1, p2, p3, p4; + TDiagramPanel tdp; + TGConnector tgco; + for(TGConnectorInfo info: pendingConnectors) { + tgco = info.connector; + if (tgco != null) { + tdp = tgco.getTDiagramPanel(); + if (tdp != null) { + p1 = tgco.getTGConnectingPointP1(); + p2 = tgco.getTGConnectingPointP2(); + if ((p1 instanceof TGConnectingPointTmp) && (p2 instanceof TGConnectingPointTmp)){ + TraceManager.addDev("Searching for id " + p1.getId()); + p3 = tdp.findConnectingPoint(p1.getId()); + TraceManager.addDev("Searching for id " + p2.getId()); + p4 = tdp.findConnectingPoint(p2.getId()); + if ((p3 == null) ||(p4 == null)) { + //warning = true; + if (p3 == null) { + TraceManager.addDev("Error on first id"); + } + if (p4 == null) { + TraceManager.addDev("Error on second id"); + } + TraceManager.addDev("One connector ignored"); + } else { + tgco.setP1(p3); + p3.setFree(false); + tgco.setP2(p4); + p4.setFree(false); + } + } + } + } + } + pendingConnectors.clear(); + //TraceManager.addDev("Last load done"); + } + + public TGConnector makeXMLConnector(Node n, TDiagramPanel tdp) throws SAXException, MalformedModelingException { + Element elt, elt1; + TGConnector tgco = null; + //TGComponent tgc = null; + + //TraceManager.addDev(n.toString()); + + try { + + NodeList nl = n.getChildNodes(); + elt = (Element)n; + elt1 = elt; + + int myType = Integer.decode(elt.getAttribute("type")).intValue(); + int myId = Integer.decode(elt.getAttribute("id")).intValue() + decId; + + int myX = -1, myY = -1, myWidth = -1, myHeight =-1; + int myMinWidth = -1, myMinHeight = -1, myMinDesiredWidth = -1, myMinDesiredHeight = -1; + int myMaxWidth = -1, myMaxHeight = -1; + String myName = null, myValue = null; + int tmpx, tmpy, tmpid; + TGConnectingPoint p1 = null, p2=null; + Vector pointList = new Vector(); + + Vector tgcpList = new Vector(); + Point p; + int i, x, y; + //int fatherId = -1, fatherNum = -1; + boolean automaticDrawing = true; + + for(i=0; i<nl.getLength(); i++) { + n = nl.item(i); + if (n.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element) n; + if (elt.getTagName().equals("cdparam")) { + myX = Integer.decode(elt.getAttribute("x")).intValue() + decX; + myY = Integer.decode(elt.getAttribute("y")).intValue() + decY; + } else if (elt.getTagName().equals("sizeparam")) { + myWidth = Integer.decode(elt.getAttribute("width")).intValue(); + myHeight = Integer.decode(elt.getAttribute("height")).intValue(); + myMinWidth = Integer.decode(elt.getAttribute("minWidth")).intValue(); + myMinHeight = Integer.decode(elt.getAttribute("minHeight")).intValue(); + if ((elt.getAttribute("maxWidth") != null) && (elt.getAttribute("maxWidth").length() > 0)) { // Test is made for compatibility with old versions + //TraceManager.addDev("maxWidth = " + elt.getAttribute("maxWidth")); + myMaxWidth = Integer.decode(elt.getAttribute("maxWidth")).intValue(); + myMaxHeight = Integer.decode(elt.getAttribute("maxHeight")).intValue(); + } + myMinDesiredWidth = Integer.decode(elt.getAttribute("minDesiredWidth")).intValue(); + myMinDesiredHeight = Integer.decode(elt.getAttribute("minDesiredHeight")).intValue(); + } else if (elt.getTagName().equals("infoparam")) { + myName = elt.getAttribute("name"); + myValue = elt.getAttribute("value"); + } else if (elt.getTagName().equals("P1")) { + tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; + tmpy = Integer.decode(elt.getAttribute("y")).intValue() + decY; + tmpid = Integer.decode(elt.getAttribute("id")).intValue() + decId; + TGComponent tgc1 = TGComponentManager.addComponent(tmpx, tmpy, TGComponentManager.TAD_START_STATE, tdp); + p1 = new TGConnectingPointTmp(tgc1, tmpx, tmpy, tmpid); + //TraceManager.addDev("P1id = " + tmpid); + } else if (elt.getTagName().equals("P2")) { + tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; + tmpy = Integer.decode(elt.getAttribute("y")).intValue() + decY; + tmpid = Integer.decode(elt.getAttribute("id")).intValue() + decId; + TGComponent tgc2 = TGComponentManager.addComponent(tmpx, tmpy, TGComponentManager.TAD_START_STATE, tdp); + p2 = new TGConnectingPointTmp(tgc2, tmpx, tmpy, tmpid); + //TraceManager.addDev("P2id = " + tmpid); + } else if (elt.getTagName().equals("Point")) { + tmpx = Integer.decode(elt.getAttribute("x")).intValue() + decX; + tmpy = Integer.decode(elt.getAttribute("y")).intValue() + decY; + pointList.add(new Point(tmpx, tmpy)); + } else if (elt.getTagName().equals("TGConnectingPoint")) { + x = Integer.decode(elt.getAttribute("num")).intValue(); + y = Integer.decode(elt.getAttribute("id")).intValue() + decId; + tgcpList.add(new Point(x, y)); + //TraceManager.addDev(" adding Connecting point !"); + } else if (elt.getTagName().equals("AutomaticDrawing")) { + //TraceManager.addDev("AutomaticDrawing=" + elt.getAttribute("data")); + if (elt.getAttribute("data").compareTo("true") == 0) { + automaticDrawing = true; + //TraceManager.addDev("set to true"); + } else { + automaticDrawing = false; + } + //automaticDrawing = Boolean.getBoolean(elt.getAttribute("data")); + } + } + } + + if ((myType == -1) || (myId == -1) || (myX == -1) || (myY == -1) || (myWidth == -1) || (myHeight == -1) || (p1 == null) || (p2 == null)) { + throw new MalformedModelingException(); + } + + //TGConnector is ready to be built + //TraceManager.addDev("Making TGConnector of type " + myType); + tgco = TGComponentManager.addConnector(myX, myY, myType, tdp, p1, p2, pointList); + //TraceManager.addDev("TGConnector built " + myType); + + if (tgco == null) { + TraceManager.addDev( "TGCO is null myType: " + myType ); + throw new MalformedModelingException(); + } + + tgco.setAutomaticDrawing(automaticDrawing); + + if (myName != null) { + tgco.setName(myName); + } + if ((myValue != null) && (!myValue.equals(null))){ + tgco.setValueWithChange(myValue); + } + + tgco.forceId(myId); + tgco.setLoaded(true); + tgco.setInternalLoaded(false); + tgco.setMinSize(myMinWidth, myMinHeight); + tgco.setMaxSize(myMaxWidth, myMaxHeight); + tgco.setMinDesiredSize(myMinDesiredWidth, myMinDesiredHeight); + tgco.resize(myWidth, myHeight); + + tgco.loadExtraParam(elt1.getElementsByTagName("extraparam"), decX, decY, decId); + + //TraceManager.addDev("Making connecting points " + myType); + for(i=0; i<tgcpList.size(); i++) { + p = (Point)(tgcpList.elementAt(i)); + if (!tgco.setIdTGConnectingPoint(p.x, p.y)) { + throw new MalformedModelingException(); + } + } + + if (decId >0) { + tdp.bringToFront(tgco); + } + + //TraceManager.addDev("Connecting points done " + myType); + + } catch (Exception e) { + TraceManager.addError("Exception on connectors: HERE I AM"); + throw new MalformedModelingException(); + } + return tgco; + } + + + + public boolean buildTURTLEModelingFromAnalysis(AnalysisPanel ap) throws AnalysisSyntaxException { + + HMSC h; + //listE = new CorrespondanceTGElement(); + checkingErrors = new LinkedList<CheckingError> (); + + AnalysisPanelTranslator apt = new AnalysisPanelTranslator(ap, mgui); + + try { + h = apt.translateHMSC(); + listE = apt.getCorrespondanceTGElement(); + checkingErrors = apt.getErrors(); + apt.translateMSCs(h); + listE = apt.getCorrespondanceTGElement(); + checkingErrors = apt.getErrors(); + } catch (AnalysisSyntaxException ase) { + CheckingError ce = new CheckingError(CheckingError.STRUCTURE_ERROR, ase.getMessage()); + checkingErrors.add(ce); + throw ase; + } + + SDTranslator sd = new SDTranslator(h); + checkingErrors = null; + warnings = new LinkedList<CheckingError> (); + //TraceManager.addDev("Step 02"); + + mgui.setMode(mgui.VIEW_SUGG_DESIGN_KO); + + //TraceManager.addDev("Step 1"); + try { + tm = sd.toTURTLEModeling(); + tmState = 0; + } catch (SDTranslationException e) { + checkingErrors = new LinkedList<CheckingError> (); + CheckingError error = new CheckingError(CheckingError.STRUCTURE_ERROR, e.getMessage()); + checkingErrors.add(error); + + throw new AnalysisSyntaxException("Problem during translation to a design TURTLE modeling"); + } + + //TraceManager.addDev("Step 2"); + + if (checkingErrors != null) { + return false; + } + + // modeling is built + // Now check it ! + //TraceManager.addDev("Step 3"); + TURTLEModelChecker tmc = new TURTLEModelChecker(tm); + checkingErrors = tmc.syntaxAnalysisChecking(); + //TraceManager.addDev("Step 4"); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + return false; + } else { + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_OK); + return true; + } + } + + public void generateDesign() { + generateDesign(tm); + } + + public void generateDesign(TURTLEModeling tm) { + //TURTLEPanel tp = mgui.getCurrentTURTLEPanel(); + nbSuggestedDesign ++; + TURTLEModelingDrawer tmd = new TURTLEModelingDrawer(mgui); + tmd.setTURTLEModeling(tm); + tmd.draw(nbSuggestedDesign); + mgui.changeMade(null, -1); + } + + public void generateIOD(HMSC _hmsc, MSC _msc) { + MSCDrawer mscd = new MSCDrawer(mgui); + mscd.setHMSC(_hmsc); + mscd.setMSC(_msc); + mscd.drawFromMSC(nbSuggestedDesign); + nbSuggestedDesign ++; + mgui.changeMade(null, -1); + } + + + public boolean translateDeployment(DeploymentPanel dp) { + // Builds a TURTLE modeling from a deployment diagram + TraceManager.addDev("deployement"); + checkingErrors = new LinkedList<CheckingError> (); + warnings = new LinkedList<CheckingError> (); + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + tm = new TURTLEModeling(); + tmState = 0; + listE = new CorrespondanceTGElement(); + mgui.reinitCountOfPanels(); + + LinkedList ll; + ListIterator iterator, iterator2; + + // First step: adding all necessary classes + their ad + ll = dp.tddp.getListOfNodes(); + iterator = ll.listIterator(); + TDDNode node; + Vector artifacts; + TDDArtifact art; + int i; + DesignPanel dp2; + TGComponent tgc; + //TCDTClass tc; + String name; + TClass t; + DesignPanelTranslator dpt; + + // Loop on nodes + while(iterator.hasNext()) { + node = (TDDNode)(iterator.next()); + + // Loop on artifact + artifacts = node.getArtifactList(); + for(i=0; i<artifacts.size(); i++) { + art = (TDDArtifact)(artifacts.elementAt(i)); + dp2 = art.getDesignPanel(); + + iterator2 = dp2.tcdp.getComponentList().listIterator(); + LinkedList<TClassInterface> tclasses = new LinkedList<TClassInterface> (); + while(iterator2.hasNext()) { + tgc = (TGComponent)(iterator2.next()); + if (tgc instanceof TClassInterface) { + TraceManager.addDev("Found tclass: " + tgc.getValue()); + tclasses.add((TClassInterface) tgc); + } + } + if (tclasses.size() > 0) { + name = node.getNodeName() + "__" + art.getValue() + "__"; + dpt = new DesignPanelTranslator(dp2); + dpt.addTClasses(dp2, tclasses, name,tm); + dpt.addRelations(dp2, name,tm); + + listE.merge(dpt.getCorrespondanceTGElement()); + checkingErrors.addAll(dpt.getErrors()); + + // Set package name of tclasses + for(int j=0; j<tclasses.size(); j++) { + tgc = (TGComponent) tclasses.get (j); + t = listE.getTClass(tgc); + if (t != null) { + TraceManager.addDev("Setting package name of " + t.getName() + " to " + node.getNodeName()); + t.setPackageName(node.getNodeName()+"_"+art.getValue()); + } + } + } + } + } + + // Second step : dealing with links! + + DDTranslator ddt = new DDTranslator(dp, tm, listE); + + try { + TraceManager.addDev("Dealing with links!"); + ddt.translateLinks(); + } catch (DDSyntaxException e) { + //throw new AnalysisSyntaxException("Problem during translation to a design TURTLE modeling"); + TraceManager.addDev("Error during translation: " + e.getMessage()); + return false; + } + + mgui.setMode(MainGUI.GEN_DESIGN_OK); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } + + // modeling is built + // Now check it ! + TURTLEModelChecker tmc = new TURTLEModelChecker(tm); + checkingErrors = tmc.syntaxAnalysisChecking(); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } else { + mgui.setMode(MainGUI.GEN_DESIGN_OK); + return true; + } + } + + public boolean translateAttackTreePanel(AttackTreePanel atp) { + AttackTreePanelTranslator att = new AttackTreePanelTranslator(atp); + /*attackTree =*/ att.translateToAttackTreeDataStructure(); + checkingErrors = att.getCheckingErrors(); + warnings = att.getWarnings(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } + avatarspec = att.generateAvatarSpec(); + TraceManager.addDev("Avatar spec:" + avatarspec); + return true; + } + + public boolean translateNC(NCPanel ncp) { + TraceManager.addDev("Translating NC"); + checkingErrors = new LinkedList<CheckingError> (); + warnings = new LinkedList<CheckingError> (); + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + + GNCModeling gncm = new GNCModeling(ncp); + ncs = gncm.translateToNCStructure(); + listE = gncm.getCorrespondanceTable(); + + checkingErrors = gncm.getCheckingErrors(); + warnings = gncm.getCheckingWarnings(); + + TraceManager.addDev("errors:" + checkingErrors.size() + " warnings:" + warnings.size()); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } else { + // Generate XML file + try { + String fileName = "network.xml"; + if (ConfigurationTTool.NCDirectory != null) { + fileName = ConfigurationTTool.NCDirectory + fileName; + } + TraceManager.addDev("Saving in network structure in file: " + fileName); + FileUtils.saveFile(fileName, ncs.toISAENetworkXML()); + fileName = "traffics.xml"; + if (ConfigurationTTool.NCDirectory != null) { + fileName = ConfigurationTTool.NCDirectory + fileName; + } + TraceManager.addDev("Saving in traffics in file: " + fileName); + FileUtils.saveFile(fileName, ncs.toISAETrafficsXML()); + TraceManager.addDev("Save done"); + } catch (FileException fe) { + TraceManager.addError("Could not save NC in file:" + fe.getMessage()); + } + mgui.setMode(MainGUI.NC_OK); + return true; + } + + } + + private void nullifyTMLModeling() { + tmlm = null; + artificialtmap = null; + tmap = null; + tmlcp = null; + } + + + public boolean translateTMLDesign(Vector tasksToTakeIntoAccount, TMLDesignPanel tmldp, boolean optimize) { + nullifyTMLModeling(); + ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); + warnings = new LinkedList<CheckingError> (); + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + + GTMLModeling gtmlm = new GTMLModeling(tmldp, true); + gtmlm.setTasks(tasksToTakeIntoAccount); + tmlm = gtmlm.translateToTMLModeling(true); + //tmlm.removeAllRandomSequences(); + TraceManager.addDev("New TML Modeling:" + tmlm.toString()); + mgui.generateTMLTxt(); + artificialtmap = tmlm.getDefaultMapping(); + tmap = null; + listE = gtmlm.getCorrespondanceTable(); + //TraceManager.addDev("TML Modeling translated"); + //TraceManager.addDev("----- TML Modeling -----"); + //TraceManager.addDev(tmlm.toString()); + //TraceManager.addDev("------------------------"); + checkingErrors = gtmlm.getCheckingErrors(); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + return false; + } else { + if (optimize) { + warningsOptimize = tmlm.optimize(); + } + + tmState = 2; + mgui.resetAllDIPLOIDs(); + listE.useDIPLOIDs(); + return true; + //TraceManager.addDev("tm generated:"); + //tm.print(); + } + } + + public Vector<CheckingError> convertToCheckingErrorTMLErrors(ArrayList<TMLError> warningsOptimize, TDiagramPanel _tdp) { + Vector<CheckingError> v = new Vector<CheckingError>(); + CheckingError warning; + for(TMLError error: warningsOptimize) { + warning = new CheckingError(CheckingError.BEHAVIOR_ERROR, error.message); + warning.setTDiagramPanel(_tdp); + warning.setTMLTask(error.task); + v.add(warning); + } + return v; + } + + public boolean translateTMLComponentDesign(Vector componentsToTakeIntoAccount, TMLComponentDesignPanel tmlcdp, boolean optimize) { + nullifyTMLModeling(); + // ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); + warnings = new LinkedList<CheckingError> (); + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + + GTMLModeling gctmlm = new GTMLModeling(tmlcdp, true); + gctmlm.putPrefixName(true); + gctmlm.setComponents(componentsToTakeIntoAccount); + tmlm = gctmlm.translateToTMLModeling(true); + mgui.generateTMLTxt(); + artificialtmap = tmlm.getDefaultMapping(); + tmap = null; + listE = gctmlm.getCorrespondanceTable(); + + //TraceManager.addDev("TML Modeling translated"); + //TraceManager.addDev("----- TML Modeling -----"); + //TraceManager.addDev(tmlm.toString()); + //TraceManager.addDev("------------------------"); + //mgui.generateTMLTxt(); + checkingErrors = gctmlm.getCheckingErrors(); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + return false; + } + else { + // if (optimize) { + // //TraceManager.addDev("OPTIMIZE"); + // warningsOptimize = tmlm.optimize(); + // } + + tmState = 2; + //TraceManager.addDev("tm generated:"); + mgui.resetAllDIPLOIDs(); + listE.useDIPLOIDs(); + return true; + //tm.print(); + } + } + + public boolean translateTMLModeling() { + TML2TURTLE tt = new TML2TURTLE(tmlm); + tm = tt.generateTURTLEModeling(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + TraceManager.addDev("Error in TURTLE generation"); + analyzeErrors(); + return false; + } else { + // Optimize + TraceManager.addDev("Optimize"); + tm.optimize(); + TraceManager.addDev("Optimize done"); + TURTLEModelChecker tmc = new TURTLEModelChecker(tm); + checkingErrors = tmc.syntaxAnalysisChecking(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + return false; + } else { + mgui.setMode(MainGUI.GEN_DESIGN_OK); + return true; + } + } + } + + public boolean checkSyntaxTMLMapping(Vector nodesToTakeIntoAccount, TMLArchiPanel tmlap, boolean optimize) { + ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); + warnings = new LinkedList<CheckingError> (); + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + //TraceManager.addDev("New TML Mapping"); + GTMLModeling gtmlm = new GTMLModeling(tmlap, true); + + + gtmlm.setNodes(nodesToTakeIntoAccount); //simply transforms the parameter from a Vector to LinkedList + nullifyTMLModeling(); + tmlm = null; + tm = null; + tmState = 1; + tmap = gtmlm.translateToTMLMapping(); + + listE = gtmlm.getCorrespondanceTable(); + + checkingErrors = gtmlm.getCheckingErrors(); + avatarspec = gtmlm.avspec; + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + analyzeErrors(); + warnings = gtmlm.getCheckingWarnings(); + return false; + } else { + //tmap.removeAllRandomSequences(); + if (optimize) { + warningsOptimize = tmap.optimize(); + } + warnings.addAll(convertToCheckingErrorTMLErrors(warningsOptimize, tmlap.tmlap)); + mgui.resetAllDIPLOIDs(); + listE.useDIPLOIDs(); + mgui.setMode(MainGUI.GEN_DESIGN_OK); + return true; + } + } + + //Newly introduced to perform Syntax check of CP diagrams. Actually the mapping of CPs onto the architecture is done via SDs, + //onto the application is done onto blocks in the architecture. It would be better to have all the mapping information in one + //diagram. Up to now, not taking the mapping information into account + public boolean checkSyntaxTMLCP( Vector nodesToTakeIntoAccount, TMLCommunicationPatternPanel tmlcpp, boolean optimize ) { + + //nodesToTakeIntoAccount is the list of SDs and ADs corresponding that compose the CP selected for syntax checking + ArrayList<TMLError> warningsOptimize = new ArrayList<TMLError>(); + warnings = new LinkedList<CheckingError> (); + mgui.setMode( MainGUI.VIEW_SUGG_DESIGN_KO ); + GTMLModeling gtmlm = new GTMLModeling( tmlcpp, true ); + + TraceManager.addDev( "NodesToTakeIntoAccount :" + nodesToTakeIntoAccount.toString() ); + + //Useless because nodesToTakeIntoAccount does not include the mainCP! + //gtmlm.setDiagramPanels( nodesToTakeIntoAccount ); //passes the list of nodes (SDs and ADs) to gtml as a LinkedList + tmlm = null; + tm = null; + tmState = 1; + nullifyTMLModeling(); + //tmlcp is the data structure for a CP corresponding to the graphical description with diagrams + tmlcp = gtmlm.translateToTMLCPDataStructure( tmlcpp.getName() ); + //tmlcp.toString(); + /*TraceManager.addDev( "I AM ABOUT TO GENERATE THE TMLtxt CODE!" ); + mgui.generateTMLTxt(); //Now generating the TMLtxt code + TraceManager.addDev( "TMLtxt CODE GENERATION DONE" );*/ + listE = gtmlm.getCorrespondanceTable(); + //for( CorrespondanceTGElement element : listE.getNames() ) { + TraceManager.addDev( "Printing listE.getNames: " + listE.getNames().toString() ); + TraceManager.addDev( "Printing listE.getTG: " + listE.getTG().toString() ); + TraceManager.addDev( "Printing listE.getPanelNames: " + listE.getPanelNames().toString() ); + TraceManager.addDev( "Printing listE.getData: " + listE.getData().toString() ); + //} + checkingErrors = gtmlm.getCheckingErrors(); + + if( (checkingErrors != null) && (checkingErrors.size() > 0) ) { + //analyzeErrors(); + + return false; + } + /*else { + //tmcp.removeAllRandomSequences(); + if( optimize ) { + warningsOptimize = tmap.optimize(); + //warningsOptimize = tmcp.optimize(); + } + warnings.addAll( convertToCheckingErrorTMLErrors(warningsOptimize, tmlcpp.tmlcpp ) ); + mgui.resetAllDIPLOIDs(); + listE.useDIPLOIDs(); + mgui.setMode( MainGUI.GEN_DESIGN_OK ); + return true; + }*/ + return true; //It means that there are no errors + } + + public boolean translateTMLMapping(boolean _sample, boolean _channel, boolean _event, boolean _request, boolean _exec, boolean _busTransfers, boolean _scheduling, boolean _taskState, boolean _channelState, boolean _branching, boolean _terminateCPU, boolean _terminateCPUs, boolean _clocked, String _tickValue, boolean _endClocked, boolean _countTick, boolean _maxCountTick, String _maxCountTickValue, boolean _randomTask) { + //TraceManager.addDev("TML=" + tmap.toString()); + Mapping2TIF m2tif = new Mapping2TIF(tmap); + m2tif.setShowSampleChannels(_sample); + m2tif.setShowChannels(_channel); + m2tif.setShowEvents(_event); + m2tif.setShowRequests(_request); + m2tif.setShowExecs(_exec); + m2tif.setShowBusTransfers(_busTransfers); + m2tif.setShowScheduling(_scheduling); + m2tif.setIsClocked(_clocked); + m2tif.setTickValue(_tickValue); + m2tif.setIsEndClocked(_endClocked); + m2tif.setIsCountTick(_countTick); + m2tif.hasMaxCountTick(_maxCountTick); + if (_maxCountTick) { + m2tif.setMaxCountTickValue(_maxCountTickValue); + } + m2tif.setShowTaskState(_taskState); + m2tif.setShowChannelState(_channelState); + m2tif.setShowBlockedCPU(_terminateCPU); + m2tif.setShowTerminateCPUs(_terminateCPUs); + m2tif.setShowBranching(_branching); + m2tif.setRandomTasks(_randomTask); + tm = m2tif.generateTURTLEModeling(); + //StringBuffer sb = tm.printToStringBuffer(); + //TraceManager.addDev("tm=" + sb); + + TraceManager.addDev("tm generated from TMAP"); + checkingErrors = m2tif.getCheckingErrors(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } + mgui.setMode(MainGUI.GEN_DESIGN_OK); + return true; + } + + //Added by Solange + public void generateLists(ProactiveDesignPanel pdp) { + gpdtemp = new GProactiveDesign(pdp); + } + // + + public boolean translateTURTLEOSDesign(TURTLEOSDesignPanel tosdp) { + warnings = new LinkedList<CheckingError> (); + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + //TraceManager.addDev("New TML Modeling"); + GTURTLEOSModeling gosm = new GTURTLEOSModeling(tosdp); + //gtmlm.setTasks(tasksToTakeIntoAccount); + //tmlm = gosm.translateToTMLModeling(); + //TraceManager.addDev("TML Modeling translated"); + //TraceManager.addDev("----- TML Modeling -----"); + //TraceManager.addDev(tmlm.toString()); + //TraceManager.addDev("------------------------"); + tm = gosm.generateTURTLEModeling(); + tmState = 0; + checkingErrors = gosm.getCheckingErrors(); + + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } else { + + //TraceManager.addDev("Optimize"); + tm.optimize(); + //TraceManager.addDev("Optimize done"); + TURTLEModelChecker tmc = new TURTLEModelChecker(tm); + checkingErrors = tmc.syntaxAnalysisChecking(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } else { + warnings = gosm.getCheckingWarnings(); + warnings.addAll(tmc.getWarnings()); + mgui.setMode(MainGUI.GEN_DESIGN_OK); + return true; + } + } + } + + + public boolean translateProactiveDesign(ProactiveDesignPanel pdp) { + mgui.setMode(MainGUI.VIEW_SUGG_DESIGN_KO); + GProactiveDesign gpd = new GProactiveDesign(pdp); + + tm = gpd.generateTURTLEModeling(); + tmState = 0; + + if (gpd.checkSyntax() == false) { + TraceManager.addDev("Errors found"); + warnings = gpd.getCheckingWarnings(); + checkingErrors = gpd.getCheckingErrors(); + return false; + } + TURTLEModelChecker tmc = new TURTLEModelChecker(tm); + checkingErrors = tmc.syntaxAnalysisChecking(); + warnings = tmc.getWarnings(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } else { + //A faire: + // tm.optimize(); + // warnings = gpd.getCheckingWarnings(); + // warnings.addAll(tmc.getWarnings()); + mgui.setMode(MainGUI.GEN_DESIGN_OK); + return true; + } + + } + + + public void addStates(AvatarStateMachineElement asme, int x, int y, AvatarSMDPanel smp, AvatarBDBlock bl, Map<AvatarStateMachineElement, TGComponent> SMDMap, Map<AvatarStateMachineElement, TGComponent> locMap, Map<AvatarTransition, AvatarStateMachineElement> tranDestMap, Map<AvatarTransition, TGComponent> tranSourceMap){ + TGConnectingPoint tp = new TGConnectingPoint(null, x, y, false, false); + //Create dummy tgcomponent + TGComponent tgcomp = new AvatarSMDStartState(x,y,x,x*2,y,y*2,false,null,smp); + if (asme instanceof AvatarStartState){ + AvatarSMDStartState smdss = new AvatarSMDStartState(x, y, x, x*2, y, y*2, false, null, smp); + tgcomp = smdss; + smp.addComponent(smdss, x, y, false, true); + SMDMap.put(asme, smdss); + tp = smdss.tgconnectingPointAtIndex(0); + locMap.put(asme, smdss); + } + if (asme instanceof AvatarTransition){ + // + } + if (asme instanceof AvatarActionOnSignal){ + avatartranslator.AvatarSignal sig = ((AvatarActionOnSignal) asme).getSignal(); + if (sig.isIn()){ + AvatarSMDReceiveSignal smdrs = new AvatarSMDReceiveSignal(x, y, x, x*2, y, y*2, false, null, smp); + tgcomp=smdrs; + smp.addComponent(smdrs, x, y, false, true); + String name=sig.minString(); + smdrs.setValue(name); + // sig.setName(name); + smdrs.recalculateSize(); + SMDMap.put(asme, smdrs); + tp = smdrs.getFreeTGConnectingPoint(x+smdrs.getWidth()/2,y+smdrs.getHeight()); + TGConnectingPoint tp2 = smdrs.getFreeTGConnectingPoint(x+smdrs.getWidth()/2,y); + locMap.put(asme, smdrs); + if (bl.getAvatarSignalFromName(name) ==null){ + //bl.addSignal(new ui.AvatarSignal(0, name, new String[0], new String[0])); + } + + } + else { + AvatarSMDSendSignal smdss = new AvatarSMDSendSignal(x, y, x, x*2, y, y*2, false, null, smp); + tgcomp=smdss; + smp.addComponent(smdss, x, y, false, true); + String name=sig.minString(); + smdss.setValue(name); + smdss.recalculateSize(); + SMDMap.put(asme, smdss); + tp = smdss.getFreeTGConnectingPoint(x+smdss.getWidth()/2,y+smdss.getHeight()); + TGConnectingPoint tp2 = smdss.getFreeTGConnectingPoint(x+smdss.getWidth()/2,y); + locMap.put(asme, smdss); + if (bl.getAvatarSignalFromName(name) == null){ + // bl.addSignal(new ui.AvatarSignal(1, name, new String[0], new String[0])); + } + } + + } + if (asme instanceof AvatarStopState){ + AvatarSMDStopState smdstop = new AvatarSMDStopState(x, y, x, x*2, y, y*2, false, null, smp); + tgcomp=smdstop; + SMDMap.put(asme, smdstop); + smp.addComponent(smdstop, x, y, false, true); + tp = smdstop.tgconnectingPointAtIndex(0); + locMap.put(asme, smdstop); + } + if (asme instanceof AvatarState){ + //check if empty checker state + /* if (asme.getName().contains("signalstate_")){ + //don't add the state, ignore next transition, + if (asme.getNexts().size()==1){ + AvatarStateMachineElement next = asme.getNext(0).getNext(0); + //Reroute transition + for (AvatarTransition at: tranDestMap.keySet()){ + if (tranDestMap.get(at) == asme){ + tranDestMap.put(at, next); + } + } + addStates(next, x, y, smp,bl, SMDMap, locMap, tranDestMap, tranSourceMap); + return; + } + }*/ + AvatarSMDState smdstate = new AvatarSMDState(x, y, x, x*2, y, y*2, false, null, smp); + tgcomp=smdstate; + smp.addComponent(smdstate, x, y, false, true); + smdstate.setValue(asme.getName()); + smdstate.recalculateSize(); + SMDMap.put(asme, smdstate); + tp = smdstate.getFreeTGConnectingPoint(x+smdstate.getWidth()/2,y+smdstate.getHeight()); + TGConnectingPoint tp2 = smdstate.getFreeTGConnectingPoint(x+smdstate.getWidth()/2,y); + locMap.put(asme, smdstate); + } + int i=0; + int diff=100; + int ydiff=50; + int num = asme.nbOfNexts(); + if (!(asme instanceof AvatarTransition)){ + for (AvatarStateMachineElement el:asme.getNexts()){ + if (!(el instanceof AvatarTransition)){ + System.out.println("ERROR: non-Transition " + asme + " connected to non-Transition " + el); + } + } + } + for (AvatarStateMachineElement el:asme.getNexts()){ + if (el instanceof AvatarTransition){ + tranSourceMap.put((AvatarTransition) el, tgcomp); + } + else { + if (asme instanceof AvatarTransition){ + AvatarTransition t = (AvatarTransition) asme; + tranDestMap.put(t, el); + } + } + if (!SMDMap.containsKey(el)){ + addStates(el, x+diff*(i-num/2), y+ydiff, smp, bl, SMDMap, locMap, tranDestMap, tranSourceMap); + } + i++; + } + return; + } + + public void drawBlockProperties(AvatarBlock ab, AvatarBDBlock bl){ for (avatartranslator.AvatarSignal sig:ab.getSignals()){ - String name=sig.getName().split("__")[sig.getName().split("__").length-1]; - // sig.setName(name); + String name=sig.getName().split("__")[sig.getName().split("__").length-1]; + // sig.setName(name); String[] types = new String[sig.getListOfAttributes().size()]; String[] typeIds = new String[sig.getListOfAttributes().size()]; int i=0; @@ -8259,15 +8027,15 @@ public class GTURTLEModeling { i++; } TraceManager.addDev("Adding signal "+sig); - bl.addSignal(new ui.AvatarSignal(sig.getInOut(), name, types, typeIds)); - } + bl.addSignal(new ui.AvatarSignal(sig.getInOut(), name, types, typeIds)); + } bl.setValueWithChange(ab.getName()); - for (AvatarAttribute attr: ab.getAttributes()){ - int type=5; - if (attr.getType()==AvatarType.BOOLEAN){ - type=4; + for (AvatarAttribute attr: ab.getAttributes()){ + int type=5; + if (attr.getType()==AvatarType.BOOLEAN){ + type=4; } if (attr.getType()==AvatarType.INTEGER){ type=0; @@ -8281,28 +8049,28 @@ public class GTURTLEModeling { if (attr.getName().contains("key_")){ hasCrypto=true; bl.addCryptoElements(); - } - } + } + } for (avatartranslator.AvatarMethod method: ab.getMethods()){ bl.addMethodIfApplicable(method.toString().replaceAll(" = 0","")); } } - public void drawPanel(AvatarSpecification avspec, AvatarDesignPanel adp){ + public void drawPanel(AvatarSpecification avspec, AvatarDesignPanel adp){ hasCrypto=false; - Map<String, Set<String>> originDestMap = new HashMap<String, Set<String>>(); - Map<String, AvatarBDBlock> blockMap = new HashMap<String, AvatarBDBlock>(); - if (adp ==null){ - return; - } - if (avspec==null){ - return; - } - AvatarBDPanel abd = adp.abdp; - - //Find all blocks, create nested blocks starting from top left - int xpos=10; - int ypos=40; + Map<String, Set<String>> originDestMap = new HashMap<String, Set<String>>(); + Map<String, AvatarBDBlock> blockMap = new HashMap<String, AvatarBDBlock>(); + if (adp ==null){ + return; + } + if (avspec==null){ + return; + } + AvatarBDPanel abd = adp.abdp; + + //Find all blocks, create nested blocks starting from top left + int xpos=10; + int ypos=40; //Create blocks recursively, starting from top level ones with no father //Lowest level blocks should be 100x100, next should be 100x(number of children*100+50)...etc, @@ -8338,7 +8106,7 @@ public class GTURTLEModeling { for (int level=0; level<maxLevel+1; level++){ for (AvatarBlock ab:avspec.getListOfBlocks()){ - if (blockLevelMap.get(ab)==level){ + if (blockLevelMap.get(ab)==level){ if (level==0){ AvatarBDBlock bl = new AvatarBDBlock(xpos, ypos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd); abd.addComponent(bl, xpos, ypos, false, true); @@ -8370,28 +8138,28 @@ public class GTURTLEModeling { } - for (AvatarRelation ar: avspec.getRelations()){ - String bl1 = ar.block1.getName(); - String bl2 = ar.block2.getName(); - if (originDestMap.containsKey(bl1)){ - originDestMap.get(bl1).add(bl2); - } - else { - Set<String> hs= new HashSet<String>(); - hs.add(bl2); - originDestMap.put(bl1, hs); - } - } - //Add Relations - - for (String bl1: originDestMap.keySet()){ - for (String bl2:originDestMap.get(bl1)){ - Vector points=new Vector(); + for (AvatarRelation ar: avspec.getRelations()){ + String bl1 = ar.block1.getName(); + String bl2 = ar.block2.getName(); + if (originDestMap.containsKey(bl1)){ + originDestMap.get(bl1).add(bl2); + } + else { + Set<String> hs= new HashSet<String>(); + hs.add(bl2); + originDestMap.put(bl1, hs); + } + } + //Add Relations + + for (String bl1: originDestMap.keySet()){ + for (String bl2:originDestMap.get(bl1)){ + Vector points=new Vector(); TGConnectingPoint p1= blockMap.get(bl1).findFirstFreeTGConnectingPoint(true,true); - p1.setFree(false); + p1.setFree(false); - TGConnectingPoint p2= blockMap.get(bl2).findFirstFreeTGConnectingPoint(true,true); - p2.setFree(false); + TGConnectingPoint p2= blockMap.get(bl2).findFirstFreeTGConnectingPoint(true,true); + p2.setFree(false); if (bl2.equals(bl1)){ //Add 2 point so the connection looks square @@ -8400,244 +8168,242 @@ public class GTURTLEModeling { p = new Point(p2.getX(), p2.getY()-10); points.add(p); } - AvatarBDPortConnector conn = new AvatarBDPortConnector(0, 0, 0, 0, 0, 0, true, null, abd, p1, p2, points); - abd.addComponent(conn, 0,0,false,true); + AvatarBDPortConnector conn = new AvatarBDPortConnector(0, 0, 0, 0, 0, 0, true, null, abd, p1, p2, points); + abd.addComponent(conn, 0,0,false,true); - //Add Relations to connector - for (AvatarRelation ar:avspec.getRelations()){ - if (ar.block1.getName().contains(bl1) && ar.block2.getName().contains(bl2) || ar.block1.getName().contains(bl2) && ar.block2.getName().contains(bl1)){ + //Add Relations to connector + for (AvatarRelation ar:avspec.getRelations()){ + if (ar.block1.getName().contains(bl1) && ar.block2.getName().contains(bl2) || ar.block1.getName().contains(bl2) && ar.block2.getName().contains(bl1)){ - //TGConnectingPoint p1= blockMap.get(bl1).getFreeTGConnectingPoint(blockMap.get(bl1).getX(), blockMap.get(bl1).getY()); - - conn.setAsynchronous(ar.isAsynchronous()); - conn.setBlocking(ar.isBlocking()); - conn.setPrivate(ar.isPrivate()); - conn.setSizeOfFIFO(ar.getSizeOfFIFO()); - //System.out.println(bl1 +" "+ ar.block1.getName() + " "+ ar.block2.getName()); + //TGConnectingPoint p1= blockMap.get(bl1).getFreeTGConnectingPoint(blockMap.get(bl1).getX(), blockMap.get(bl1).getY()); + + conn.setAsynchronous(ar.isAsynchronous()); + conn.setBlocking(ar.isBlocking()); + conn.setPrivate(ar.isPrivate()); + conn.setSizeOfFIFO(ar.getSizeOfFIFO()); + //System.out.println(bl1 +" "+ ar.block1.getName() + " "+ ar.block2.getName()); for (int i =0; i< ar.nbOfSignals(); i++){ - conn.addSignal(ar.getSignal1(i).toBasicString(),true,true); - conn.addSignal(ar.getSignal2(i).toBasicString(), false,false); + conn.addSignal(ar.getSignal1(i).toBasicString(),true,true); + conn.addSignal(ar.getSignal2(i).toBasicString(), false,false); // System.out.println("adding signal " +ar.getSignal1(i).toBasicString()); } - //System.out.println("Added Signals"); - conn.updateAllSignals(); - - - } - } - - /*for (ui.AvatarSignal sig:blockMap.get(bl1).getSignalList()){ - for (ui.AvatarSignal sig2: blockMap.get(bl2).getSignalList()){ - if (sig.getId().equals(sig2.getId())){ - conn.addSignal("in "+sig.getId(), true, true); - conn.addSignal("out "+sig.getId(), false, false); - } - } - }*/ - } - } - ypos+=100; - //Add Pragmas - AvatarBDPragma pragma=new AvatarBDPragma(xpos, ypos, xpos, xpos*2, ypos, ypos*2, false, null,abd); - String[] arr = new String[avspec.getPragmas().size()]; - String s=""; - int i=0; - for (AvatarPragma p: avspec.getPragmas()){ - - // arr[i] = p.getName(); - String t= ""; - String[] split = p.getName().split(" "); - if (p.getName().contains("#Confidentiality")){ - for (String str:split){ - if (str.contains(".")){ - String tmp = str.split("\\.")[0]; - String tmp2 = str.split("\\.")[1]; - t=t.concat(tmp.split("__")[tmp.split("__").length-1] + "." + tmp2.split("__")[tmp2.split("__").length-1] + " "); - } - else { - t=t.concat(str+" "); - } - } - } - else if (p.getName().contains("Authenticity")){ - System.out.println(p.getName()); - } - s=s.concat(t+"\n"); - i++; - } - pragma.setValue(s); - pragma.makeValue(); - abd.addComponent(pragma, xpos, ypos, false,true); - //Add message and key datatype if there is a cryptoblock - - xpos=50; - ypos+=200; + //System.out.println("Added Signals"); + conn.updateAllSignals(); + + + } + } + + /*for (ui.AvatarSignal sig:blockMap.get(bl1).getSignalList()){ + for (ui.AvatarSignal sig2: blockMap.get(bl2).getSignalList()){ + if (sig.getId().equals(sig2.getId())){ + conn.addSignal("in "+sig.getId(), true, true); + conn.addSignal("out "+sig.getId(), false, false); + } + } + }*/ + } + } + ypos+=100; + //Add Pragmas + AvatarBDPragma pragma=new AvatarBDPragma(xpos, ypos, xpos, xpos*2, ypos, ypos*2, false, null,abd); + String[] arr = new String[avspec.getPragmas().size()]; + String s=""; + int i=0; + for (AvatarPragma p: avspec.getPragmas()){ + + // arr[i] = p.getName(); + String t= ""; + String[] split = p.getName().split(" "); + if (p.getName().contains("#Confidentiality")){ + for (String str:split){ + if (str.contains(".")){ + String tmp = str.split("\\.")[0]; + String tmp2 = str.split("\\.")[1]; + t=t.concat(tmp.split("__")[tmp.split("__").length-1] + "." + tmp2.split("__")[tmp2.split("__").length-1] + " "); + } + else { + t=t.concat(str+" "); + } + } + } + else if (p.getName().contains("Authenticity")){ + } + s=s.concat(t+"\n"); + i++; + } + pragma.setValue(s); + pragma.makeValue(); + abd.addComponent(pragma, xpos, ypos, false,true); + //Add message and key datatype if there is a cryptoblock + + xpos=50; + ypos+=200; if (hasCrypto){ - AvatarBDDataType message = new AvatarBDDataType(xpos, ypos, xpos, xpos*2, ypos, ypos*2, false, null,abd); - message.setValue("Message"); + AvatarBDDataType message = new AvatarBDDataType(xpos, ypos, xpos, xpos*2, ypos, ypos*2, false, null,abd); + message.setValue("Message"); - abd.addComponent(message, xpos, ypos, false,true); + abd.addComponent(message, xpos, ypos, false,true); message.resize(200,100); - xpos+=400; + xpos+=400; - AvatarBDDataType key = new AvatarBDDataType(xpos, ypos, xpos, xpos*2, ypos, ypos*2, false, null,abd); - key.setValue("Key"); - TAttribute attr = new TAttribute(2, "data", "0", 8); - message.addAttribute(attr); - key.addAttribute(attr); + AvatarBDDataType key = new AvatarBDDataType(xpos, ypos, xpos, xpos*2, ypos, ypos*2, false, null,abd); + key.setValue("Key"); + TAttribute attr = new TAttribute(2, "data", "0", 8); + message.addAttribute(attr); + key.addAttribute(attr); key.resize(200,100); - abd.addComponent(key, xpos, ypos, false,true); + abd.addComponent(key, xpos, ypos, false,true); } - abd.setMaxPanelSize(xpos+100, ypos+100); - } + } public void buildStateMachine(AvatarBlock ab, AvatarBDBlock bl, AvatarSMDPanel smp){ Map<AvatarTransition, TGComponent> tranSourceMap = new HashMap<AvatarTransition, TGComponent>(); Map<AvatarTransition, AvatarStateMachineElement> tranDestMap = new HashMap<AvatarTransition, AvatarStateMachineElement>(); - Map<AvatarStateMachineElement, TGComponent> locMap = new HashMap<AvatarStateMachineElement, TGComponent>(); - Map<AvatarStateMachineElement, TGComponent> SMDMap = new HashMap<AvatarStateMachineElement, TGComponent>(); - - //Build the state machine - int smx=400; - int smy=40; - - if (smp==null){ - System.out.println("can't find"); - return; - } - smp.removeAll(); - AvatarStateMachine asm = ab.getStateMachine(); - //Remove the empty check states - - AvatarStartState start= asm.getStartState(); - addStates(start, smx, smy, smp, bl, SMDMap, locMap, tranDestMap, tranSourceMap); - //Add transitions - for (AvatarTransition t: tranSourceMap.keySet()){ - if (tranSourceMap.get(t)==null || tranDestMap.get(t)==null){ - continue; - } - int x=tranSourceMap.get(t).getX()+tranSourceMap.get(t).getWidth()/2; - int y=tranSourceMap.get(t).getY()+tranSourceMap.get(t).getHeight(); - - // TGConnectingPoint p1 = tranSourceMap.get(t).findFirstFreeTGConnectingPoint(true,false); - TGConnectingPoint p1 = tranSourceMap.get(t).closerFreeTGConnectingPoint(x, y, true, false); - if (p1==null){ - // p1= tranSourceMap.get(t).findFirstFreeTGConnectingPoint(true,true); - p1=tranSourceMap.get(t).closerFreeTGConnectingPoint(x,y,true, true); - } - x= locMap.get(tranDestMap.get(t)).getX()+ locMap.get(tranDestMap.get(t)).getWidth()/2; - y = locMap.get(tranDestMap.get(t)).getY(); - if (tranSourceMap.get(t).getY() > locMap.get(tranDestMap.get(t)).getY()){ - y=locMap.get(tranDestMap.get(t)).getY()+locMap.get(tranDestMap.get(t)).getHeight()/2; - if (tranSourceMap.get(t).getX() < locMap.get(tranDestMap.get(t)).getX()){ - x = locMap.get(tranDestMap.get(t)).getX(); - } - else { - x= locMap.get(tranDestMap.get(t)).getX()+locMap.get(tranDestMap.get(t)).getWidth(); - } - } - TGConnectingPoint p2 = locMap.get(tranDestMap.get(t)).closerFreeTGConnectingPoint(x,y,false, true); - if (p2==null){ - p2=locMap.get(tranDestMap.get(t)).closerFreeTGConnectingPoint(x,y,true, true); - } - Vector points = new Vector(); - if (p1==null || p2 ==null){ - System.out.println(tranSourceMap.get(t)+" "+locMap.get(tranDestMap.get(t))); - - System.out.println("Missing point "+ p1 + " "+p2); - return; - } - AvatarSMDConnector SMDcon = new AvatarSMDConnector((int) p1.getX(), (int) p1.getY(), (int) p1.getX(), (int) p1.getY(), (int) p1.getX(), (int) p1.getY(), true, null, smp, p1, p2, points); - //System.out.println(tranSourceMap.get(t)+" "+locMap.get(tranDestMap.get(t))); - ///System.out.println("FREE " +p1.isFree() + " "+ p2.isFree()); - p1.setFree(false); - p2.setFree(false); - String action=""; - if (t.getActions().size()==0){ - action=""; - } - else { - action=t.getActions().get(0).toString().replaceAll(" ",""); - } - SMDcon.setTransitionInfo(t.getGuard().toString(), action); - for (int i=1; i<t.getActions().size(); i++){ - SMDcon.setTransitionInfo("", t.getActions().get(i).toString().replaceAll(" ","")); - } - smp.addComponent(SMDcon, (int) p1.getX(), (int) p1.getY(), false, true); - } - } - - // Generates for all observers, a TURTLE modeling for checking it - public boolean generateTMsForRequirementAnalysis(Vector reqs, RequirementDiagramPanel rdp) { - rm = new RequirementModeling(reqs, rdp, mgui); - checkingErrors = rm.getCheckingErrors(); - warnings = rm.getWarnings(); - if ((checkingErrors != null) && (checkingErrors.size() > 0)){ - return false; - } else { - //mgui.setMode(mgui.GEN_DESIGN_OK); - languageID = MATRIX; - return true; - } - } - - public RequirementModeling getRequirementModeling() { - return rm; - } - - public void removeBreakpoint(Point p) { - if (listE == null) { - return; - } - - listE.removeBreakpoint(p); - } - - public void addBreakpoint(Point p) { - if (listE == null) { - return; - } - - listE.addBreakpoint(p); - } - - private void analyzeErrors() { - CheckingError ce; - TGComponent tgc; - - for(int i=0; i<checkingErrors.size(); i++) { - ce = (CheckingError)(checkingErrors.get(i)); - if (ce != null) { - tgc = ce.getTGComponent(); - if (tgc != null) { - analyzeErrorOnComponent(tgc); - } - } - } - } - - private void analyzeErrorOnComponent(TGComponent _tgc) { - if (_tgc instanceof BasicErrorHighlight) { - ((BasicErrorHighlight)_tgc).setStateAction(ErrorHighlight.UNKNOWN); - } else if (_tgc instanceof ActionStateErrorHighlight) { - ((ActionStateErrorHighlight)_tgc).setStateAction(ErrorHighlight.UNKNOWN_AS); - } - } - - public boolean makeEBRDD(EBRDDPanel tdp) { - EBRDDTranslator ebrddt = new EBRDDTranslator(); - ebrdd = ebrddt.generateEBRDD(tdp, tdp.getName()); - warnings = ebrddt.getWarnings(); - checkingErrors = ebrddt.getErrors(); - if (checkingErrors.size() > 0) { - return false; - } - TraceManager.addDev("the EBRDD:\n" + ebrdd.toString()); - return true; - } - - public void setElementsOfSearchTree(Vector<Object> elements) { - st.setElements(elements); - } + Map<AvatarStateMachineElement, TGComponent> locMap = new HashMap<AvatarStateMachineElement, TGComponent>(); + Map<AvatarStateMachineElement, TGComponent> SMDMap = new HashMap<AvatarStateMachineElement, TGComponent>(); + + //Build the state machine + int smx=400; + int smy=40; + + if (smp==null){ + System.out.println("can't find"); + return; + } + smp.removeAll(); + AvatarStateMachine asm = ab.getStateMachine(); + //Remove the empty check states + + AvatarStartState start= asm.getStartState(); + addStates(start, smx, smy, smp, bl, SMDMap, locMap, tranDestMap, tranSourceMap); + //Add transitions + for (AvatarTransition t: tranSourceMap.keySet()){ + if (tranSourceMap.get(t)==null || tranDestMap.get(t)==null){ + continue; + } + int x=tranSourceMap.get(t).getX()+tranSourceMap.get(t).getWidth()/2; + int y=tranSourceMap.get(t).getY()+tranSourceMap.get(t).getHeight(); + + // TGConnectingPoint p1 = tranSourceMap.get(t).findFirstFreeTGConnectingPoint(true,false); + TGConnectingPoint p1 = tranSourceMap.get(t).closerFreeTGConnectingPoint(x, y, true, false); + if (p1==null){ + // p1= tranSourceMap.get(t).findFirstFreeTGConnectingPoint(true,true); + p1=tranSourceMap.get(t).closerFreeTGConnectingPoint(x,y,true, true); + } + x= locMap.get(tranDestMap.get(t)).getX()+ locMap.get(tranDestMap.get(t)).getWidth()/2; + y = locMap.get(tranDestMap.get(t)).getY(); + if (tranSourceMap.get(t).getY() > locMap.get(tranDestMap.get(t)).getY()){ + y=locMap.get(tranDestMap.get(t)).getY()+locMap.get(tranDestMap.get(t)).getHeight()/2; + if (tranSourceMap.get(t).getX() < locMap.get(tranDestMap.get(t)).getX()){ + x = locMap.get(tranDestMap.get(t)).getX(); + } + else { + x= locMap.get(tranDestMap.get(t)).getX()+locMap.get(tranDestMap.get(t)).getWidth(); + } + } + TGConnectingPoint p2 = locMap.get(tranDestMap.get(t)).closerFreeTGConnectingPoint(x,y,false, true); + if (p2==null){ + p2=locMap.get(tranDestMap.get(t)).closerFreeTGConnectingPoint(x,y,true, true); + } + Vector points = new Vector(); + if (p1==null || p2 ==null){ + System.out.println(tranSourceMap.get(t)+" "+locMap.get(tranDestMap.get(t))); + + System.out.println("Missing point "+ p1 + " "+p2); + return; + } + AvatarSMDConnector SMDcon = new AvatarSMDConnector((int) p1.getX(), (int) p1.getY(), (int) p1.getX(), (int) p1.getY(), (int) p1.getX(), (int) p1.getY(), true, null, smp, p1, p2, points); + //System.out.println(tranSourceMap.get(t)+" "+locMap.get(tranDestMap.get(t))); + ///System.out.println("FREE " +p1.isFree() + " "+ p2.isFree()); + p1.setFree(false); + p2.setFree(false); + String action=""; + if (t.getActions().size()==0){ + action=""; + } + else { + action=t.getActions().get(0).toString().replaceAll(" ",""); + } + SMDcon.setTransitionInfo(t.getGuard().toString(), action); + for (int i=1; i<t.getActions().size(); i++){ + SMDcon.setTransitionInfo("", t.getActions().get(i).toString().replaceAll(" ","")); + } + smp.addComponent(SMDcon, (int) p1.getX(), (int) p1.getY(), false, true); + } + } + + // Generates for all observers, a TURTLE modeling for checking it + public boolean generateTMsForRequirementAnalysis(Vector reqs, RequirementDiagramPanel rdp) { + rm = new RequirementModeling(reqs, rdp, mgui); + checkingErrors = rm.getCheckingErrors(); + warnings = rm.getWarnings(); + if ((checkingErrors != null) && (checkingErrors.size() > 0)){ + return false; + } else { + //mgui.setMode(mgui.GEN_DESIGN_OK); + languageID = MATRIX; + return true; + } + } + + public RequirementModeling getRequirementModeling() { + return rm; + } + + public void removeBreakpoint(Point p) { + if (listE == null) { + return; + } + + listE.removeBreakpoint(p); + } + + public void addBreakpoint(Point p) { + if (listE == null) { + return; + } + + listE.addBreakpoint(p); + } + + private void analyzeErrors() { + CheckingError ce; + TGComponent tgc; + + for(int i=0; i<checkingErrors.size(); i++) { + ce = (CheckingError)(checkingErrors.get(i)); + if (ce != null) { + tgc = ce.getTGComponent(); + if (tgc != null) { + analyzeErrorOnComponent(tgc); + } + } + } + } + + private void analyzeErrorOnComponent(TGComponent _tgc) { + if (_tgc instanceof BasicErrorHighlight) { + ((BasicErrorHighlight)_tgc).setStateAction(ErrorHighlight.UNKNOWN); + } else if (_tgc instanceof ActionStateErrorHighlight) { + ((ActionStateErrorHighlight)_tgc).setStateAction(ErrorHighlight.UNKNOWN_AS); + } + } + + public boolean makeEBRDD(EBRDDPanel tdp) { + EBRDDTranslator ebrddt = new EBRDDTranslator(); + ebrdd = ebrddt.generateEBRDD(tdp, tdp.getName()); + warnings = ebrddt.getWarnings(); + checkingErrors = ebrddt.getErrors(); + if (checkingErrors.size() > 0) { + return false; + } + TraceManager.addDev("the EBRDD:\n" + ebrdd.toString()); + return true; + } + + public void setElementsOfSearchTree(Vector<Object> elements) { + st.setElements(elements); + } } diff --git a/src/ui/JTextAreaWriter.java b/src/ui/JTextAreaWriter.java new file mode 100644 index 0000000000000000000000000000000000000000..9a4fc95d898366c2b04f078ffe1987db0bb72507 --- /dev/null +++ b/src/ui/JTextAreaWriter.java @@ -0,0 +1,35 @@ +package ui; + +import java.io.IOException; +import java.io.Writer; + +import javax.swing.JTextArea; + +public class JTextAreaWriter extends Writer { + + private final JTextArea textArea; + + public JTextAreaWriter( final JTextArea textArea ) { + assert( textArea != null ); + + this.textArea = textArea; + } + + @Override + public void write( char[] cbuf, + int off, + int len ) + throws IOException { + textArea.append( new String( cbuf ).substring( off, off + len ) ); + } + + @Override + public void flush() + throws IOException { + } + + @Override + public void close() + throws IOException { + } +} diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index b62067fdc5cab343cbd69ef1f70196a1b9b2d411..dce0d0aa9da9bc0293dd044c93c697dc61c264cc 100644 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -4494,7 +4494,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe ConfigurationTTool.SystemCHost, ConfigurationTTool.SystemCCodeDirectory, ConfigurationTTool.SystemCCodeCompileCommand, ConfigurationTTool.SystemCCodeExecuteCommand, ConfigurationTTool.SystemCCodeInteractiveExecuteCommand, ConfigurationTTool.GGraphPath, _mode); //jgen.setSize(500, 750); - GraphicLib.centerOnParent( jgen, 500, 750 ); + GraphicLib.centerOnParent( jgen, 700, 750 ); jgen.setVisible(true); dtree.toBeUpdated(); diff --git a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java index 80b332130eaa2f9aaac0d2661028dda85ff27627..8bc492ad69189ef3f1af8f1417e139a9249f4ef8 100755 --- a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -1252,7 +1252,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen protected void processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); startThread(1); //t = new Thread(this); ////go = true; diff --git a/src/ui/window/JDialogAvatarExecutableCodeGeneration.java b/src/ui/window/JDialogAvatarExecutableCodeGeneration.java index 04680e6c81e14f92b46cc79ac494a39c700eae82..9beb87fd714d49baa3648b3843bc893222ac87bf 100644 --- a/src/ui/window/JDialogAvatarExecutableCodeGeneration.java +++ b/src/ui/window/JDialogAvatarExecutableCodeGeneration.java @@ -85,6 +85,7 @@ import myutil.ScrolledJTextArea; import myutil.TraceManager; import ui.AvatarDeploymentPanelTranslator; import ui.IconManager; +import ui.JTextAreaWriter; import ui.MainGUI; import ui.avatardd.ADDDiagramPanel; import ui.interactivesimulation.JFrameSimulationSDPanel; @@ -137,6 +138,7 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JFrame im //components protected JTextArea jta; + private JTextAreaWriter textAreaWriter; protected JButton start; protected JButton stop; protected JButton close; @@ -441,6 +443,8 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JFrame im jta.append("Select options and then, click on 'start' to launch code generation / compilation / execution\n"); Font f = new Font("Courrier", Font.BOLD, 12); jta.setFont(f); + textAreaWriter = new JTextAreaWriter( jta ); + jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); c.add(jsp, BorderLayout.CENTER); @@ -548,7 +552,7 @@ public class JDialogAvatarExecutableCodeGeneration extends javax.swing.JFrame im public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -882,8 +886,9 @@ list = FileUtils.deleteFiles(code1.getText() + TasksAndMainGenerator.getGenerat protected void processCmd(String cmd, JTextArea _jta) throws LauncherException { rshc.setCmd(cmd); - rshc.sendProcessRequest(); - rshc.fillJTA(_jta); + rshc.sendExecuteCommandRequest(); + rshc.writeCommandMessages( textAreaWriter ); + return; } diff --git a/src/ui/window/JDialogAvatarddExecutableCodeGeneration.java b/src/ui/window/JDialogAvatarddExecutableCodeGeneration.java index 894cf5a5ec62490e5abeb66d3c0e14c63a45d87f..c620e22dd2e2e465e9482ddbaeb3e1df0ce28d04 100755 --- a/src/ui/window/JDialogAvatarddExecutableCodeGeneration.java +++ b/src/ui/window/JDialogAvatarddExecutableCodeGeneration.java @@ -478,7 +478,7 @@ public class JDialogAvatarddExecutableCodeGeneration extends javax.swing.JFrame public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -710,8 +710,11 @@ public class JDialogAvatarddExecutableCodeGeneration extends javax.swing.JFrame protected void processCmd(String cmd, JTextArea _jta) throws LauncherException { rshc.setCmd(cmd); - rshc.sendProcessRequest(); - rshc.fillJTA(_jta); + rshc.sendExecuteCommandRequest(); + final Writer output = new StringWriter(); + rshc.writeCommandMessages( output ); + _jta.append( output.toString() ); + return; } diff --git a/src/ui/window/JDialogBisimulation.java b/src/ui/window/JDialogBisimulation.java index 03e1129bcab2298f6927feb619d4d197205d8b08..fdd23b3288929dee740b6bdfe6b9a3b7fe57037d 100755 --- a/src/ui/window/JDialogBisimulation.java +++ b/src/ui/window/JDialogBisimulation.java @@ -299,7 +299,7 @@ public class JDialogBisimulation extends javax.swing.JDialog implements ActionLi public void stopProcess() { if (rshc != null) { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -378,7 +378,7 @@ public class JDialogBisimulation extends javax.swing.JDialog implements ActionLi protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogBisimulationBisimulator.java b/src/ui/window/JDialogBisimulationBisimulator.java index 57fb73e79be966669f776f6adf27f89bddd7f469..2d60e96d5b400b129e8d8c98bdc5d3c00db7dd3f 100755 --- a/src/ui/window/JDialogBisimulationBisimulator.java +++ b/src/ui/window/JDialogBisimulationBisimulator.java @@ -348,7 +348,7 @@ public class JDialogBisimulationBisimulator extends javax.swing.JDialog implemen public void stopProcess() { if (rshc != null) { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -467,7 +467,7 @@ public class JDialogBisimulationBisimulator extends javax.swing.JDialog implemen protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogCCodeGeneration.java b/src/ui/window/JDialogCCodeGeneration.java index 157fd92b90f810288e343af94cf348a57eb7e19d..e99422a1b00e6d14ca517dcf714973de384c276e 100755 --- a/src/ui/window/JDialogCCodeGeneration.java +++ b/src/ui/window/JDialogCCodeGeneration.java @@ -421,7 +421,7 @@ public class JDialogCCodeGeneration extends javax.swing.JDialog implements Actio public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } diff --git a/src/ui/window/JDialogDSE.java b/src/ui/window/JDialogDSE.java index 7632b2eddcb0e546b3d35ffd8b2a8e7bb51e2bbd..2db7003e808a17c348942d297a44aa1e082be3f5 100644 --- a/src/ui/window/JDialogDSE.java +++ b/src/ui/window/JDialogDSE.java @@ -586,7 +586,7 @@ public class JDialogDSE extends javax.swing.JDialog implements ActionListener, R public void stopProcess() { if (rshc != null ){ try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } } diff --git a/src/ui/window/JDialogFormalValidation.java b/src/ui/window/JDialogFormalValidation.java index 29abbc46d1c7454b432ea0d90da7fa44e78ecd2a..1cba38a02d08a90848f036bb1ab9c2e9e35d48cf 100755 --- a/src/ui/window/JDialogFormalValidation.java +++ b/src/ui/window/JDialogFormalValidation.java @@ -357,7 +357,7 @@ public class JDialogFormalValidation extends javax.swing.JDialog implements Acti public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -597,14 +597,14 @@ public class JDialogFormalValidation extends javax.swing.JDialog implements Acti protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } protected String processPipedCmd(String cmd1, String cmd2) throws LauncherException { String s = null; - rshc.sendProcessRequest(cmd1, cmd2); + rshc.sendExecutePipedCommandsRequest(cmd1, cmd2); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogGenAUT.java b/src/ui/window/JDialogGenAUT.java index 93408b74a40f3e3844c4ab0dbfe0273ea2d53c6e..9a85e1fecf49936a1746f036842e85bb10294463 100755 --- a/src/ui/window/JDialogGenAUT.java +++ b/src/ui/window/JDialogGenAUT.java @@ -203,7 +203,7 @@ public class JDialogGenAUT extends javax.swing.JDialog implements ActionListener public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -289,7 +289,7 @@ public class JDialogGenAUT extends javax.swing.JDialog implements ActionListener protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogGenAUTS.java b/src/ui/window/JDialogGenAUTS.java index 5f564b7b758f4d8cc7a99383d07b869d5c5be8ae..1aef51c5c47ac30321454442c7eba33206a083fa 100755 --- a/src/ui/window/JDialogGenAUTS.java +++ b/src/ui/window/JDialogGenAUTS.java @@ -216,7 +216,7 @@ public class JDialogGenAUTS extends javax.swing.JDialog implements ActionListene public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -344,7 +344,7 @@ public class JDialogGenAUTS extends javax.swing.JDialog implements ActionListene protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogGraphModification.java b/src/ui/window/JDialogGraphModification.java index 634d2b63cc52b3ead03cfe6bbcc78bc6050ecf5c..392b76864c34f0f15b4cb210642a364a7d35c087 100755 --- a/src/ui/window/JDialogGraphModification.java +++ b/src/ui/window/JDialogGraphModification.java @@ -348,7 +348,7 @@ public class JDialogGraphModification extends javax.swing.JDialog implements Act public void stopProcess() { if (rshc != null) { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -527,7 +527,7 @@ public class JDialogGraphModification extends javax.swing.JDialog implements Act protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogLOTOSAnalysis.java b/src/ui/window/JDialogLOTOSAnalysis.java index da7e908c3346067cdc913412cf0dedd742a8ebc8..dcfc4080ab43d494445114092394955720f9dfe6 100755 --- a/src/ui/window/JDialogLOTOSAnalysis.java +++ b/src/ui/window/JDialogLOTOSAnalysis.java @@ -193,7 +193,7 @@ public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -280,7 +280,7 @@ protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogLOTOSValidation.java b/src/ui/window/JDialogLOTOSValidation.java index 0bfcee299ec80febfb98ee5229e7944dc4a6934b..0abd1ba6190a5839e8c41a1210e6c3aa4bb45e17 100755 --- a/src/ui/window/JDialogLOTOSValidation.java +++ b/src/ui/window/JDialogLOTOSValidation.java @@ -271,7 +271,7 @@ public class JDialogLOTOSValidation extends javax.swing.JDialog implements Actio public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -517,7 +517,7 @@ public class JDialogLOTOSValidation extends javax.swing.JDialog implements Actio protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogProVerifGeneration.java b/src/ui/window/JDialogProVerifGeneration.java index e0a5f9b46b90c351b98ff1cf822a47c7e6a960af..d507aa886b32816d3d9b5617c4b87750d311bd0d 100644 --- a/src/ui/window/JDialogProVerifGeneration.java +++ b/src/ui/window/JDialogProVerifGeneration.java @@ -318,7 +318,7 @@ public class JDialogProVerifGeneration extends javax.swing.JDialog implements Ac public void stopProcess() { if (rshc != null ){ try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } } @@ -501,7 +501,7 @@ public class JDialogProVerifGeneration extends javax.swing.JDialog implements Ac protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogProjection.java b/src/ui/window/JDialogProjection.java index cacd3793b8547f949065633fd526a610e25c2f5e..6022472f93c52daff82127f33deee576896c083b 100755 --- a/src/ui/window/JDialogProjection.java +++ b/src/ui/window/JDialogProjection.java @@ -584,7 +584,7 @@ public class JDialogProjection extends javax.swing.JDialog implements ActionList public void stopProcess() { if (rshc != null) { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -784,7 +784,7 @@ public class JDialogProjection extends javax.swing.JDialog implements ActionList protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogSimulation.java b/src/ui/window/JDialogSimulation.java index 3dfe583f3c4de60e5503a7efa62fb282f7783110..b8edd11e45487b3bc6a83f70cb51c1c17523f35e 100755 --- a/src/ui/window/JDialogSimulation.java +++ b/src/ui/window/JDialogSimulation.java @@ -212,7 +212,7 @@ public class JDialogSimulation extends javax.swing.JDialog implements ActionList public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -325,7 +325,7 @@ public class JDialogSimulation extends javax.swing.JDialog implements ActionList protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogSystemCGeneration.java b/src/ui/window/JDialogSystemCGeneration.java index 2e58d1465231a587aaf86bcb1285d84a5170bc7f..baad7eac42abdce520399380c9d04b1c4e2e04a9 100755 --- a/src/ui/window/JDialogSystemCGeneration.java +++ b/src/ui/window/JDialogSystemCGeneration.java @@ -59,6 +59,7 @@ import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; +import java.util.List; import java.util.Vector; import javax.swing.ButtonGroup; @@ -74,6 +75,8 @@ import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.ListSelectionModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -84,34 +87,29 @@ import myutil.GraphicLib; import myutil.MasterProcessInterface; import myutil.ScrolledJTextArea; import myutil.TraceManager; -//import ui.ebrdd.*; import req.ebrdd.EBRDD; import tepe.TEPE; -import tmltranslator.tomappingsystemc2.IDiploSimulatorCodeGenerator; import tmltranslator.tomappingsystemc2.DiploSimulatorFactory; +import tmltranslator.tomappingsystemc2.IDiploSimulatorCodeGenerator; import ui.AvatarRequirementPanelTranslator; import ui.IconManager; +import ui.JTextAreaWriter; import ui.MainGUI; import ui.avatarpd.AvatarPDPanel; - public class JDialogSystemCGeneration extends javax.swing.JDialog implements ActionListener, Runnable, MasterProcessInterface, ListSelectionListener { protected MainGUI mgui; - private static String textSysC1 = "Generate SystemC code in"; - private static String textSysC2 = "Compile SystemC code in"; - //private String textSysC3 = "with"; + private static String textSysC1 = "Generate C++ simulator code in"; + private static String textSysC2 = "Compile C++ simulator code in"; private static String textSysC4 = "Run simulation to completion:"; private static String textSysC5 = "Run interactive simulation:"; private static String textSysC6 = "Run formal verification:"; - private static String unitCycle = "1"; - - /*private static String[] simus = { "SystemC Simulator - LabSoC version", - "C++ Simulator - LabSoc version" };*/ + private static float unitCycleValue = 1; - private static String[] simus = { "C++ Simulator - LabSoc version" }; + private static String[] simus = { "Diplodocus C++ Simulator - LabSoc version" }; private static int selectedItem = 0; @@ -130,10 +128,9 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act protected final static int ERROR=4; int mode; - - //components protected JTextArea jta; + private JTextAreaWriter textAreaWriter; protected JButton start; protected JButton stop; protected JButton close; @@ -142,46 +139,29 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act protected ButtonGroup exegroup; protected JLabel gen, comp; protected JTextField code1, code2, unitcycle, compiler1, exe1, exe2, exe3, exe2int, exe2formal; - protected JTabbedPane jp1; + protected JTabbedPane tabbedPane; protected JScrollPane jsp; protected JCheckBox removeCppFiles, removeXFiles, debugmode, optimizemode; - protected JComboBox versionSimulator; - - //EBRDD - /*private static Vector validated, ignored; - private Vector val, ign; - private JList listIgnored; - private JList listValidated; - private JButton allValidated; - private JButton addOneValidated; - private JButton addOneIgnored; - private JButton allIgnored; - private JPanel panele1, panele2, panele3, panele4, panel5, panel6;*/ - + protected JComboBox<String> versionSimulator; //TEPED - private static Vector validatedTepe, ignoredTepe; - private Vector valTepe, ignTepe; - private JList listIgnoredTepe; - private JList listValidatedTepe; + private static Vector<AvatarPDPanel> validatedTepe, ignoredTepe; + private Vector<AvatarPDPanel> valTepe, ignTepe; + private JList<AvatarPDPanel> listIgnoredTepe; + private JList<AvatarPDPanel> listValidatedTepe; private JButton allValidatedTepe; private JButton addOneValidatedTepe; private JButton addOneIgnoredTepe; private JButton allIgnoredTepe; - private JPanel panele1Tepe, panele2Tepe, panele3Tepe, panele4Tepe, panel5Tepe, panel6Tepe; - - - + private JPanel panele1Tepe, panele2Tepe, panele3Tepe, panele4Tepe;//, panel5Tepe, panel6Tepe; private Thread t; private boolean go = false; - //private ProcessThread pt; - private boolean hasError = false; +// private boolean hasError = false; + private int errorTabIndex = -1; protected boolean startProcess = false; - //private TURTLE2Java t2j; - - private String hostSystemC; + private String simulatorHost; protected RshClient rshc; @@ -196,7 +176,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act /** Creates new form */ - public JDialogSystemCGeneration(Frame f, MainGUI _mgui, String title, String _hostSystemC, String _pathCode, String _pathCompiler, String _pathExecute, String _pathInteractiveExecute, String _graphPath, int _automatic) { + public JDialogSystemCGeneration(Frame f, MainGUI _mgui, String title, String _simulatorHost, String _pathCode, String _pathCompiler, String _pathExecute, String _pathInteractiveExecute, String _graphPath, int _automatic) { super(f, title, true); mgui = _mgui; @@ -228,7 +208,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } } - hostSystemC = _hostSystemC; + simulatorHost = _simulatorHost; automatic = _automatic; @@ -238,7 +218,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act myInitComponents(); pack(); - //getGlassPane().addMouseListener( new MouseAdapter() {}); getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (automatic > 0) { @@ -248,17 +227,17 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act protected void makeLists() { if (validatedTepe == null) { - validatedTepe = new Vector(); + validatedTepe = new Vector<AvatarPDPanel>(); } if (ignoredTepe == null) { - ignoredTepe = new Vector(); + ignoredTepe = new Vector<AvatarPDPanel>(); } - valTepe = new Vector(); - ignTepe = new Vector(); + valTepe = new Vector<AvatarPDPanel>(); + ignTepe = new Vector<AvatarPDPanel>(); - ArrayList<AvatarPDPanel> al = mgui.getAllAvatarPDPanels(); + final List<AvatarPDPanel> al = mgui.getAllAvatarPDPanels(); for(AvatarPDPanel panel: al) { if(validatedTepe.contains(panel)) { @@ -284,7 +263,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act c.setLayout(new BorderLayout()); //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - jp1 = new JTabbedPane(); + tabbedPane = new JTabbedPane(); JPanel jp01 = new JPanel(); GridBagLayout gridbag01 = new GridBagLayout(); @@ -313,7 +292,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act c01.gridheight = 1; gen = new JLabel(textSysC1); - //genJava.addActionListener(this); jp01.add(gen, c01); code1 = new JTextField(pathCode, 100); @@ -325,7 +303,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act c01.gridwidth = GridBagConstraints.REMAINDER; //end row jp01.add(new JLabel("1 time unit = "), c01); - unitcycle = new JTextField(unitCycle, 10); + unitcycle = new JTextField( Float.toString( unitCycleValue ), 10); jp01.add(unitcycle, c01); jp01.add(new JLabel("cycle"), c01); @@ -348,11 +326,10 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act jp01.add(new JLabel("Simulator used:"), c01); - versionSimulator = new JComboBox(simus); + versionSimulator = new JComboBox<String>(simus); versionSimulator.setSelectedIndex(selectedItem); versionSimulator.addActionListener(this); jp01.add(versionSimulator, c01); - //System.out.println("selectedItem=" + selectedItem); //devmode = new JCheckBox("Development version of the simulator"); //devmode.setSelected(true); @@ -364,7 +341,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act panele1Tepe = new JPanel(); panele1Tepe.setLayout(new BorderLayout()); panele1Tepe.setBorder(new javax.swing.border.TitledBorder("Ignored TEPE Diagrams")); - listIgnoredTepe = new JList(ignTepe); + listIgnoredTepe = new JList<AvatarPDPanel>(ignTepe); //listIgnored.setPreferredSize(new Dimension(200, 250)); listIgnoredTepe.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); listIgnoredTepe.addListSelectionListener(this); @@ -376,7 +353,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act panele2Tepe = new JPanel(); panele2Tepe.setLayout(new BorderLayout()); panele2Tepe.setBorder(new javax.swing.border.TitledBorder("TEPE Diagrams taken into account")); - listValidatedTepe = new JList(valTepe); + listValidatedTepe = new JList<AvatarPDPanel>(valTepe); //listValidated.setPreferredSize(new Dimension(200, 250)); listValidatedTepe.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); listValidatedTepe.addListSelectionListener(this); @@ -435,7 +412,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act //GraphicLib.enableComponents(jp01, false); } - jp1.add("Generate code", jp01); + tabbedPane.add("Generate code", jp01); // Panel 02 c02.gridheight = 1; @@ -446,7 +423,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act c02.gridheight = 1; comp = new JLabel(textSysC2); - //compJava.addActionListener(this); jp02.add(comp, c02); code2 = new JTextField(pathCode, 100); @@ -459,7 +435,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act jp02.add(new JLabel(" "), c02); - jp1.add("Compile", jp02); + tabbedPane.add("Compile", jp02); // Panel 03 c03.gridheight = 1; @@ -473,7 +449,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act exe = new JRadioButton(textSysC4, false); exe.addActionListener(this); exegroup.add(exe); - //exeJava.addActionListener(this); jp03.add(exe, c03); exe2 = new JTextField(pathExecute, 100); @@ -484,7 +459,6 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act exeint = new JRadioButton(textSysC5, true); exeint.addActionListener(this); exegroup.add(exeint); - //exeJava.addActionListener(this); jp03.add(exeint, c03); exe2int = new JTextField(pathInteractiveExecute, 100); jp03.add(exe2int, c02); @@ -499,23 +473,33 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act jp03.add(new JLabel(" "), c03); - jp1.add("Execute", jp03); + tabbedPane.add("Execute", jp03); - c.add(jp1, BorderLayout.NORTH); + c.add(tabbedPane, BorderLayout.NORTH); if (automatic > 0) { - //GraphicLib.enableComponents(jp03, false); - GraphicLib.enableComponents(jp1, false); + GraphicLib.enableComponents(tabbedPane, false); } + + // Issue #18 + tabbedPane.addChangeListener( new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent e) { + setButtons(); + } + } ); jta = new ScrolledJTextArea(); jta.setEditable(false); jta.setMargin(new Insets(10, 10, 10, 10)); jta.setTabSize(3); if (automatic == 0) { - jta.append("Select options and then, click on 'start' to launch SystemC code generation / compilation\n"); + jta.append("Select options and then, click on 'start' to launch simulator C++ code generation / compilation\n"); } Font f = new Font("Courrier", Font.BOLD, 12); jta.setFont(f); + textAreaWriter = new JTextAreaWriter( jta ); + jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); c.add(jsp, BorderLayout.CENTER); @@ -589,6 +573,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act if (mode == STARTED) { stopProcess(); } + updateStaticList(); optimizeModeSelected = optimizemode.isSelected(); wasClosed = true; @@ -601,7 +586,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -634,71 +619,83 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } private void testGo() throws InterruptedException { - if (go == false) { + if ( !go ) { throw new InterruptedException("Stopped by user"); } } + + private boolean hasError() { + return errorTabIndex > -1; + } + + private void resetError() { + mode = NOT_STARTED; + errorTabIndex = - 1; + } + + private boolean canSwitchNextTab() { + return !hasError() && tabbedPane.getSelectedIndex() < 2; + } + + private boolean canExecute() { + return errorTabIndex < 0 || tabbedPane.getSelectedIndex() <= errorTabIndex; + } public void run() { - // String cmd; - // String data; - - - hasError = false; - try { - - if (automatic > 0) { - + if ( automatic > 0 ) { generateCode(); testGo(); - compileCode(); - testGo(); - executeSimulation(); - - } else { - - - // Code generation - if (jp1.getSelectedIndex() == 0) { - generateCode(); - } - - testGo(); - - - // Compilation - if (jp1.getSelectedIndex() == 1) { - compileCode(); - + + if ( canExecute() ) { + compileCode(); + + if ( canExecute() ) { + testGo(); + executeSimulation(); + } } - - if (jp1.getSelectedIndex() == 2) { - executeSimulation(); - } - - if ((hasError == false) && (jp1.getSelectedIndex() < 2)) { - jp1.setSelectedIndex(jp1.getSelectedIndex() + 1); + } + else { + if ( canExecute() ) { + resetError(); + + if ( tabbedPane.getSelectedIndex() == 0 ) { + generateCode(); + } + else if ( tabbedPane.getSelectedIndex() == 1 ) { + compileCode(); + } + else { + executeSimulation(); + } + + if ( canSwitchNextTab() ) { + tabbedPane.setSelectedIndex( tabbedPane.getSelectedIndex() + 1 ); + } } - } - - } catch (InterruptedException ie) { + } + catch (InterruptedException ie) { jta.append("Interrupted\n"); } - jta.append("\n\nReady to process next command\n"); + if ( hasError() ) { + jta.append("\nAn error occured when processing command!\n"); + } + else { + jta.append("\nReady to process next command.\n"); + } - checkMode(); + //updateMode(); setButtons(); - - //System.out.println("Selected item=" + selectedItem); } - private void generateCode() throws InterruptedException { + private void generateCode() + throws InterruptedException { String list; - jta.append("Generating SystemC code\n"); + jta.append("Generating simulator C++ code\n"); if (removeCppFiles.isSelected()) { jta.append("Removing all old h files\n"); @@ -728,118 +725,165 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } testGo(); - - try { - unitCycle = unitcycle.getText(); - } - catch ( Exception e) { - jta.append("Wrong number of cycles: " + unitcycle.getText()); - jta.append("Aborting"); - jta.append("\n\nReady to process next command\n"); - checkMode(); - setButtons(); - - return; + + if ( !validateData() ) { + return; } +// try { +// defaultUnitCycleValue = unitcycle.getText(); +// } +// catch ( final Throwable th ) { +// final String message = "Wrong number of cycles: " + unitcycle.getText() + "!"; +// jta.append( message ); +// jta.append("Aborting"); +// jta.append("\n\nReady to process next command\n"); +// //checkMode(); +// TraceManager.addError( message, th ); +// setError(); +// +// return; +// } + selectedItem = versionSimulator.getSelectedIndex(); switch( selectedItem ) { //Old SystemC generator - case 0: { //Simulator without CPs (Daniel's version) - // Making EBRDDs - ArrayList<EBRDD> al = new ArrayList<EBRDD>(); - ArrayList<TEPE> alTepe = new ArrayList<TEPE>(); - TEPE tepe; - AvatarRequirementPanelTranslator arpt = new AvatarRequirementPanelTranslator(); - for(int k=0; k<valTepe.size(); k++) { - testGo(); - tepe = arpt.generateTEPESpecification((AvatarPDPanel)(valTepe.get(k))); - jta.append("TEPE: " + tepe.getName() + "\n"); - jta.append("Checking syntax\n"); - // tepe.checkSyntax(); - alTepe.add(tepe); - jta.append("Done.\n"); - } - - final IDiploSimulatorCodeGenerator tml2systc; - - // Generating code - if (mgui.gtm.getTMLMapping() == null) { - if (mgui.gtm.getArtificialTMLMapping() == null) { - tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getTMLModeling(), al, alTepe ); - //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); - } - else { - TraceManager.addDev("Using artifical mapping"); - tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getArtificialTMLMapping(), al, alTepe ); - //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); - } - } - else { - tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getTMLMapping(), al, alTepe ); -// tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); - } - - try { - tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); - testGo(); - jta.append("SystemC code generation done\n"); + case 0: { //Simulator without CPs (Daniel's version) + // Making EBRDDs + List<EBRDD> al = new ArrayList<EBRDD>(); + List<TEPE> alTepe = new ArrayList<TEPE>(); + TEPE tepe; + AvatarRequirementPanelTranslator arpt = new AvatarRequirementPanelTranslator(); + + for(int k=0; k<valTepe.size(); k++) { + testGo(); + tepe = arpt.generateTEPESpecification( valTepe.get(k) ); + jta.append("TEPE: " + tepe.getName() + "\n"); + jta.append("Checking syntax\n"); + // tepe.checkSyntax(); + alTepe.add(tepe); + jta.append("Done.\n"); + } - for(TEPE tep: alTepe) { - TraceManager.addDev(tep.toString()); + final IDiploSimulatorCodeGenerator tml2systc; + + // Generating code + if (mgui.gtm.getTMLMapping() == null) { + if (mgui.gtm.getArtificialTMLMapping() == null) { + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getTMLModeling(), al, alTepe ); + //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLModeling(), al, alTepe); + } + else { + TraceManager.addDev("Using artifical mapping"); + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getArtificialTMLMapping(), al, alTepe ); + //tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getArtificialTMLMapping(), al, alTepe); + } + } + else { + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator( mgui.gtm.getTMLMapping(), al, alTepe ); + // tml2systc = new tmltranslator.tomappingsystemc2.TML2MappingSystemC(mgui.gtm.getTMLMapping(), al, alTepe); } - jta.append("Generating SystemC file\n"); - pathCode = code1.getText(); - tml2systc.saveFile(pathCode, "appmodel"); - jta.append("SystemC files generated\n"); - } - catch ( final Exception ex ) { - final String message = "Could not generate simulator code!"; - jta.append( message + System.lineSeparator() ); - TraceManager.addError( message );ex.printStackTrace(); - } - break; - } + + try { + tml2systc.generateSystemC(debugmode.isSelected(), optimizemode.isSelected()); + testGo(); + jta.append("Simulator code generation done\n"); + + for( final TEPE tep : alTepe ) { + TraceManager.addDev( tep.toString() ); + } + + jta.append("Saving C++ files...\n"); + + pathCode = code1.getText(); + tml2systc.saveFile(pathCode, "appmodel"); + + jta.append( "C++ files saved." + System.lineSeparator() ); + } + catch ( final Throwable th ) { + final String message = "Could not generate simulator code!"; + jta.append( System.lineSeparator() + message + System.lineSeparator() ); + + TraceManager.addError( message, th ); + setError(); + } + + break; + } } } //End of method generateCode() - public void compileCode() throws InterruptedException { + private boolean validateData() { + switch ( tabbedPane.getSelectedIndex() ) { + case 0: { + try { + unitCycleValue = Float.parseFloat( unitcycle.getText() ); + } + catch ( final NumberFormatException ex ) { + final String message = "Wrong number of cycles: " + unitcycle.getText() + "!"; + jta.append( message ); + jta.append("Aborting"); + jta.append("\n\nReady to process next command\n"); + TraceManager.addError( message, ex ); + setError(); + + return false; + } + + break; + } + default: + break; + } + + return true; + } + private void compileCode() + throws InterruptedException { String cmd = compiler1.getText(); - jta.append("Compiling SystemC code with command: \n" + cmd + "\n"); + jta.append("Compiling simulator code with command: \n" + cmd + "\n"); - rshc = new RshClient(hostSystemC); - // Assuma data are on the remote host - // Command + rshc = new RshClient( simulatorHost ); + + // Assume data are on the remote host Command try { - processCmd(cmd, jta); - if (jta.getText().contains("Error ")){ - mode = ERROR; - setButtons(); + if ( !processCmd( cmd, jta, 0 ) ) { + + // Issue #18: This check does not work when for example the locale is French so we + // explicitly return and test the value of the return code + //if ( jta.getText().contains("Error ") ) { +// mode = ERROR; +// setButtons(); + setError(); + return; } - //jta.append(data); - jta.append("Compilation done\n"); - } catch (LauncherException le) { - jta.append("Error: " + le.getMessage() + "\n"); - mode = STOPPED; - setButtons(); - return; - } catch (Exception e) { - mode = STOPPED; - setButtons(); - return; + jta.append("Compilation done.\n"); } + catch ( final Throwable th ) { + jta.append( "Error: " + th.getMessage() + ".\n"); + // mode = STOPPED; + //setButtons(); + TraceManager.addError( th ); + setError(); + + return; + } +// catch (Exception e) { +// mode = STOPPED; +// setButtons(); +// return; +// } } - public void executeSimulation() throws InterruptedException { - if (hasError) { - jta.append("Simulation not executed: error"); - return; - } - + private void executeSimulation() throws InterruptedException { +// if (hasError) { +// jta.append("Simulation not executed: error"); +// return; +// } int toDo = automatic; if (toDo == 0) { @@ -852,42 +896,32 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } } - - // String cmd; - switch(toDo) { - case ONE_TRACE: - executeSimulationCmd(exe2.getText(), "Generating one simulation trace"); - break; - case ANIMATION: - dispose(); - mgui.interactiveSimulationSystemC(getPathInteractiveExecute()); - break; - case FORMAL_VERIFICATION: - executeSimulationCmd(exe2formal.getText(), "Running formal verification"); - break; - + case ONE_TRACE: + executeSimulationCmd(exe2.getText(), "Generating one simulation trace"); + break; + case ANIMATION: + dispose(); + mgui.interactiveSimulationSystemC(getPathInteractiveExecute()); + break; + case FORMAL_VERIFICATION: + executeSimulationCmd(exe2formal.getText(), "Running formal verification"); + break; } - } - - public void executeSimulationCmd(String cmd, String text) throws InterruptedException { - - + private void executeSimulationCmd(String cmd, String text) throws InterruptedException { try { - - jta.append(text + " with command: \n" + cmd + "\n"); - rshc = new RshClient(hostSystemC); + rshc = new RshClient(simulatorHost); // It assumes that data are on the remote host // Command - processCmd(cmd, jta); - //jta.append(data); + processCmd(cmd, jta, 0 ); jta.append("Execution done\n"); - } catch (LauncherException le) { + } + catch (LauncherException le) { jta.append("Error: " + le.getMessage() + "\n"); mode = STOPPED; setButtons(); @@ -899,25 +933,23 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } } + protected boolean processCmd( final String cmd, + final JTextArea _jta, + final Integer okReturnCode ) + throws LauncherException { + rshc.setCmd( cmd ); + rshc.sendExecuteCommandRequest( okReturnCode != null ); - - - protected void processCmd(String cmd, JTextArea _jta) throws LauncherException { - rshc.setCmd(cmd); - String s = null; - rshc.sendProcessRequest(); - rshc.fillJTA(_jta); - //if ( - //s = rshc.getDataFromProcess(); - //return s; - return; - } - - protected void checkMode() { - if (mode!=ERROR){ - mode = NOT_STARTED; - } + rshc.writeCommandMessages( textAreaWriter ); + + return okReturnCode == null || okReturnCode.equals( rshc.getProcessReturnCode() ); } +// +// protected void checkMode() { +// if (mode!=ERROR){ +// mode = NOT_STARTED; +// } +// } protected void setButtons() { if (automatic == 0) { @@ -926,37 +958,44 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act start.setEnabled(true); stop.setEnabled(false); close.setEnabled(true); - //setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); getGlassPane().setVisible(false); + break; case STARTED: start.setEnabled(false); stop.setEnabled(true); close.setEnabled(false); getGlassPane().setVisible(true); - //setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + break; case STOPPED: break; case ERROR: - start.setEnabled(false); - stop.setEnabled(false); + start.setEnabled( canExecute() ); + stop.setEnabled( false ); close.setEnabled(true); + + // Issue #18: Resets the busy cursor to normal + getGlassPane().setVisible(false); + break; default: start.setEnabled(false); stop.setEnabled(false); close.setEnabled(true); getGlassPane().setVisible(false); + break; } - } else { + } + else { close.setEnabled(true); } } + @Override public boolean hasToContinue() { - return (go == true); + return go; } public void appendOut(String s) { @@ -964,7 +1003,9 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } public void setError() { - hasError = true; + errorTabIndex = tabbedPane.getSelectedIndex(); + mode = ERROR; + //hasError = true; } public boolean isInteractiveSimulationSelected() { @@ -1015,12 +1056,12 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act private void addOneIgnoredTepe() { int [] list = listValidatedTepe.getSelectedIndices(); - Vector v = new Vector(); - Object o; + Vector<AvatarPDPanel> v = new Vector<AvatarPDPanel>(); + //Object o; for (int i=0; i<list.length; i++){ - o = valTepe.elementAt(list[i]); - ignTepe.addElement(o); - v.addElement(o); + final AvatarPDPanel panel = valTepe.elementAt(list[i]); + ignTepe.addElement( panel ); + v.addElement( panel ); } valTepe.removeAll(v); @@ -1031,12 +1072,12 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act private void addOneValidatedTepe() { int [] list = listIgnoredTepe.getSelectedIndices(); - Vector v = new Vector(); - Object o; + Vector<AvatarPDPanel> v = new Vector<AvatarPDPanel>(); + //Object o; for (int i=0; i<list.length; i++){ - o = ignTepe.elementAt(list[i]); - valTepe.addElement(o); - v.addElement(o); + final AvatarPDPanel panel = ignTepe.elementAt(list[i]); + valTepe.addElement( panel ); + v.addElement( panel ); } ignTepe.removeAll(v); @@ -1062,8 +1103,8 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act } private void updateStaticList() { - validatedTepe = new Vector(); - ignoredTepe = new Vector(); + validatedTepe = new Vector<AvatarPDPanel>(); + ignoredTepe = new Vector<AvatarPDPanel>(); int i; for(i=0; i<ignTepe.size(); i++) { diff --git a/src/ui/window/JDialogTMatrixManagement.java b/src/ui/window/JDialogTMatrixManagement.java index 2b77604fe00d38db614574bc877be4641a46dda8..32d3da8fdf3560db5bc69ed429bab26bf3510f61 100755 --- a/src/ui/window/JDialogTMatrixManagement.java +++ b/src/ui/window/JDialogTMatrixManagement.java @@ -241,7 +241,7 @@ public class JDialogTMatrixManagement extends JFrame implements ActionListener, public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -380,17 +380,17 @@ public class JDialogTMatrixManagement extends JFrame implements ActionListener, protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); - s = rshc.getDataFromProcess(); - return s; - } - - protected String processPipedCmd(String cmd1, String cmd2) throws LauncherException { - String s = null; - rshc.sendProcessRequest(cmd1, cmd2); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } +// DB: Issue #18: This method is not used +// protected String processPipedCmd(String cmd1, String cmd2) throws LauncherException { +// String s = null; +// rshc.sendExecutePipedCommandsRequest(cmd1, cmd2); +// s = rshc.getDataFromProcess(); +// return s; +// } protected void checkMode() { diff --git a/src/ui/window/JDialogTPNValidation.java b/src/ui/window/JDialogTPNValidation.java index 0bbf64c4aab26fbde2afd8c588f2521aa48504f0..eec86b855578226da850cf30f17c45f54b45b9c9 100755 --- a/src/ui/window/JDialogTPNValidation.java +++ b/src/ui/window/JDialogTPNValidation.java @@ -199,7 +199,7 @@ public class JDialogTPNValidation extends javax.swing.JDialog implements ActionL public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -301,7 +301,7 @@ public class JDialogTPNValidation extends javax.swing.JDialog implements ActionL protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/src/ui/window/JDialogTextProcess.java b/src/ui/window/JDialogTextProcess.java index 04291246bec7d5ee7dc9929fa41f28b26052d171..1adbc9e60065a5301bef995b51888e1cb858d5c0 100755 --- a/src/ui/window/JDialogTextProcess.java +++ b/src/ui/window/JDialogTextProcess.java @@ -48,6 +48,7 @@ package ui.window; import java.awt.*; import java.awt.event.*; + import javax.swing.*; import launcher.*; import myutil.*; @@ -70,6 +71,7 @@ public class JDialogTextProcess extends javax.swing.JDialog implements ActionLis //components protected JTextArea jta; + private JTextAreaWriter textAreaWriter; protected JButton start; protected JButton stop; protected JButton close; @@ -110,7 +112,8 @@ public class JDialogTextProcess extends javax.swing.JDialog implements ActionLis Font f = new Font("Courrier", Font.BOLD, 12); jta.setFont(f); JScrollPane jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - + textAreaWriter = new JTextAreaWriter( jta ); + c.add(jsp, BorderLayout.CENTER); start = new JButton("Start", IconManager.imgic53); @@ -155,7 +158,7 @@ public class JDialogTextProcess extends javax.swing.JDialog implements ActionLis public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } @@ -184,7 +187,7 @@ public class JDialogTextProcess extends javax.swing.JDialog implements ActionLis rshc.sendFileData(fileName, spec); jta.append("Sending process request\n"); rshc.setCmd(Conversion.replaceAllString(cmd, "__FILENAME", fileName)); - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); } catch (LauncherException le) { jta.append(le.getMessage() + "\n"); @@ -199,7 +202,7 @@ public class JDialogTextProcess extends javax.swing.JDialog implements ActionLis try { jta.append("\nRTL Process:\n------------------\n"); - rshc.fillJTA(jta); + rshc.writeCommandMessages( textAreaWriter ); rshc.deleteFile(fileName); rshc.deleteFile(fileName+".sim"); diff --git a/src/ui/window/JDialogUPPAALValidation.java b/src/ui/window/JDialogUPPAALValidation.java index b90cfe86a162b823bd8856c1025af921075ac18e..339febba5cf83242e153d18266a461324086447c 100755 --- a/src/ui/window/JDialogUPPAALValidation.java +++ b/src/ui/window/JDialogUPPAALValidation.java @@ -300,7 +300,7 @@ public class JDialogUPPAALValidation extends javax.swing.JDialog implements Acti public void stopProcess() { try { - rshc.stopFillJTA(); + rshc.stopCommand(); } catch (LauncherException le) { } rshc = null; @@ -651,7 +651,7 @@ public class JDialogUPPAALValidation extends javax.swing.JDialog implements Acti protected String processCmd(String cmd) throws LauncherException { rshc.setCmd(cmd); String s = null; - rshc.sendProcessRequest(); + rshc.sendExecuteCommandRequest(); s = rshc.getDataFromProcess(); return s; } diff --git a/tests/util/fr.tpt.ttool.tests.util/.classpath b/tests/util/fr.tpt.ttool.tests.util/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..ac3a9c3963c0f22b1cdd2a92155880f908436418 --- /dev/null +++ b/tests/util/fr.tpt.ttool.tests.util/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry combineaccessrules="false" kind="src" path="/src"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/tests/util/fr.tpt.ttool.tests.util/.project b/tests/util/fr.tpt.ttool.tests.util/.project new file mode 100644 index 0000000000000000000000000000000000000000..7a3d164b32e075ae22952325540c1004151363e2 --- /dev/null +++ b/tests/util/fr.tpt.ttool.tests.util/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>fr.tpt.ttool.tests.util</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/tests/util/fr.tpt.ttool.tests.util/.settings/org.eclipse.jdt.core.prefs b/tests/util/fr.tpt.ttool.tests.util/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..3a21537071bf4118b9e1ee864cb4bc258aa48211 --- /dev/null +++ b/tests/util/fr.tpt.ttool.tests.util/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/tests/util/fr.tpt.ttool.tests.util/bin/.gitignore b/tests/util/fr.tpt.ttool.tests.util/bin/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..44fde9027b9415ffbb48dede03b1f60a754a152c --- /dev/null +++ b/tests/util/fr.tpt.ttool.tests.util/bin/.gitignore @@ -0,0 +1 @@ +/fr/ diff --git a/tests/util/fr.tpt.ttool.tests.util/launch/TestRshClient.launch b/tests/util/fr.tpt.ttool.tests.util/launch/TestRshClient.launch new file mode 100644 index 0000000000000000000000000000000000000000..be994b10555a84a3406900b134ff625d40877d85 --- /dev/null +++ b/tests/util/fr.tpt.ttool.tests.util/launch/TestRshClient.launch @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> +<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="fr.tpt.ttool.tests.util.remote.TestRshClient"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="fr.tpt.ttool.tests.util"/> +</launchConfiguration> diff --git a/tests/util/fr.tpt.ttool.tests.util/resources/helloWorld b/tests/util/fr.tpt.ttool.tests.util/resources/helloWorld new file mode 100755 index 0000000000000000000000000000000000000000..4a59186b2ba9badf0ac77be4561e72ba237d8917 Binary files /dev/null and b/tests/util/fr.tpt.ttool.tests.util/resources/helloWorld differ diff --git a/tests/util/fr.tpt.ttool.tests.util/resources/helloWorldNonStop b/tests/util/fr.tpt.ttool.tests.util/resources/helloWorldNonStop new file mode 100755 index 0000000000000000000000000000000000000000..82cc5e028dbc9d54b72a0f6bc1a8b590d7b11c52 Binary files /dev/null and b/tests/util/fr.tpt.ttool.tests.util/resources/helloWorldNonStop differ diff --git a/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java b/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java new file mode 100644 index 0000000000000000000000000000000000000000..77eade0ebe36778aeae0f2076191dbd07c07618f --- /dev/null +++ b/tests/util/fr.tpt.ttool.tests.util/src/fr/tpt/ttool/tests/util/remote/TestRshClient.java @@ -0,0 +1,324 @@ +package fr.tpt.ttool.tests.util.remote; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.StringWriter; +import java.io.Writer; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import launcher.LauncherException; +import launcher.RshClient; +import launcher.RshServer; +import myutil.FileException; +import myutil.FileUtils; + +public class TestRshClient { + + private static final String EXPECTED_COMMAND_OUTPUT = "!!!Hello World!!!" + System.lineSeparator(); + private static final String TEST_PROGRAM_NAME = "helloWorld"; + private static final String TEST_COMMAND = "./resources/" + TEST_PROGRAM_NAME; + private static final String TEST_COMMAND_NON_STOP = "./resources/helloWorldNonStop"; + private static final String TEST_FILE_NAME = "./resources/test.txt"; + private static final String TEST_FILE_DATA = "testDatafhkenomrcg ,jgh o"; + + + private RshClient client = null; + private static Thread serverThread = null; + + @BeforeClass + public static void setUpBeforeClass() + throws Exception { + RshClient.PORT_NUMBER = 8080; + RshServer.PORT_NUMBER = RshClient.PORT_NUMBER; + + final Runnable runnable = new Runnable() { + + @Override + public void run() { + new RshServer( null ).startServer(); + } + }; + + serverThread = new Thread( runnable ); + serverThread.start(); + Thread.sleep( 500 ); + } + + @Before + public void setUp() + throws Exception { + client = new RshClient( "localhost" ); + } + + @AfterClass + public static void tearDownAfterClass() + throws Exception { + serverThread.interrupt(); + } + + private void handleException( final Throwable th ) { + th.printStackTrace(); + fail( th.getLocalizedMessage() ); + } + + @Test + public void testStopCommand() { + final Runnable runnable = new Runnable() { + + @Override + public void run() { + try { + client.setCmd( TEST_COMMAND_NON_STOP ); + client.sendExecuteCommandRequest(); + final Writer writer = new StringWriter(); + client.writeCommandMessages( writer ); + } + catch (LauncherException e) { + handleException( e ); + } + } + }; + + final Thread thread = new Thread( runnable ); + thread.start(); + + try { + + // Ensure the remote process has enough time to start + Thread.sleep( 200 ); + client.stopCommand(); + + // Ensure the stop command has been processed on the server + Thread.sleep( 200 ); + assertTrue( killUnexistentProcess() ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( InterruptedException ex ) { + handleException( ex ); + } + } + + private boolean killUnexistentProcess() { + try { + client.sendKillProcessRequest(); + + return false; + } + catch ( LauncherException ex ) { + return RshClient.FAILED.equals( ex.getMessage() ); + } + } + + @Test + public void testGetId() { + try { + final int id = client.getId(); + assertTrue( id == 1 ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testFreeId() { + try { + client.freeId( 1 ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendExecuteCommandRequest() { + client.setCmd( TEST_COMMAND ); + + try { + client.sendExecuteCommandRequest(); + final Writer writer = new StringWriter(); + client.writeCommandMessages( writer ); + assertTrue( ( EXPECTED_COMMAND_OUTPUT + System.lineSeparator() ).equals( writer.toString() ) ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendExecuteCommandRequestBoolean() { + client.setCmd( TEST_COMMAND ); + + try { + client.sendExecuteCommandRequest( true ); + final Writer writer = new StringWriter(); + client.writeCommandMessages( writer ); + assertTrue( writer.toString().startsWith( EXPECTED_COMMAND_OUTPUT ) ); + + final Integer retCode = client.getProcessReturnCode(); + assertTrue( retCode != null && retCode == 0 ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendExecutePipedCommandsRequest() { + final String testFileName = "./resources/test_piped_commands.txt"; + final String expectedData = "Test Passed!" + System.lineSeparator(); + + try { + FileUtils.saveFile( testFileName, expectedData ); + client.sendExecutePipedCommandsRequest( "echo " + testFileName, "xargs cat" ); + final String data = client.getDataFromProcess(); + + assertTrue( "Piped commands returned " + data, expectedData.equals( data ) ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( FileException ex ) { + handleException( ex ); + } + finally { + new File( testFileName ).delete(); + } + } + + private boolean deleteTestFile() { + final File testFile = new File( TEST_FILE_NAME ); + + if ( testFile.exists() ) { + assertTrue( "Test file could not be deleted!", testFile.delete() ); + } + + return true; + } + + @Test + public void testSendFileData() { + deleteTestFile(); + + try { + client.sendFileData( TEST_FILE_NAME, TEST_FILE_DATA ); + + try { + final String readData = FileUtils.loadFile( TEST_FILE_NAME ); + + assertTrue( ( TEST_FILE_DATA + System.lineSeparator() ).equals( readData ) ); + } + catch ( FileException ex ) { + handleException( ex ); + } + } + catch( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testGetFileData() { + deleteTestFile(); + + try { + FileUtils.saveFile( TEST_FILE_NAME, TEST_FILE_DATA ); + + final String readData = client.getFileData( TEST_FILE_NAME ); + + assertTrue( TEST_FILE_DATA.equals( readData ) ); + } + catch ( FileException ex ) { + handleException( ex ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testDeleteFile() { + deleteTestFile(); + + try { + FileUtils.saveFile( TEST_FILE_NAME, TEST_FILE_DATA ); + + client.deleteFile( TEST_FILE_NAME ); + + assertFalse( new File( TEST_FILE_NAME ).exists() ); + } + catch ( FileException ex ) { + handleException( ex ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendKillProcessRequest() { + client.setCmd( TEST_COMMAND_NON_STOP ); + + try { + client.sendExecuteCommandRequest(); + Thread.sleep( 200 ); + client.sendKillProcessRequest(); + + Thread.sleep( 200 ); + assertTrue( killUnexistentProcess() ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( InterruptedException ex ) { + handleException( ex ); + } + } + + @Test + public void testSendKillAllProcessRequest() { + client.setCmd( TEST_COMMAND_NON_STOP ); + + try { + for ( int index = 0; index < 4; index++ ) { + client.sendExecuteCommandRequest(); + Thread.sleep( 200 ); + } + + client.sendKillAllProcessRequest(); + + Thread.sleep( 200 ); + assertTrue( killUnexistentProcess() ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + catch ( InterruptedException ex ) { + handleException( ex ); + } + } + + @Test + public void testGetDataFromProcess() { + client.setCmd( TEST_COMMAND ); + + try { + client.sendExecuteCommandRequest(); + final String messageFromProcess = client.getDataFromProcess(); + + assertTrue( ( EXPECTED_COMMAND_OUTPUT ).equals( messageFromProcess ) ); + } + catch ( LauncherException ex ) { + handleException( ex ); + } + } +}