diff --git a/src/main/java/cli/Action.java b/src/main/java/cli/Action.java index 2b83fb5f9a426d29ac5f34c18e628bdcfee57507..34338f99bcc4c96073bc0fed04261bc1ce09c196 100644 --- a/src/main/java/cli/Action.java +++ b/src/main/java/cli/Action.java @@ -59,14 +59,16 @@ import myutil.Conversion; import myutil.FileUtils; import myutil.PluginManager; import myutil.TraceManager; +import org.apache.batik.anim.timing.Trace; import proverifspec.ProVerifOutputAnalyzer; import proverifspec.ProVerifOutputListener; import proverifspec.ProVerifQueryAuthResult; import proverifspec.ProVerifQueryResult; -import tmltranslator.TMLMapping; -import tmltranslator.TMLMappingTextSpecification; -import tmltranslator.TMLModeling; -import tmltranslator.TMLTextSpecification; +import tmltranslator.*; +import tmltranslator.mutations.ApplyDiplodocusMutationException; +import tmltranslator.mutations.DiplodocusMutation; +import tmltranslator.mutations.DiplodocusMutationParser; +import tmltranslator.mutations.ParseDiplodocusMutationException; import ui.MainGUI; import ui.avatarinteractivesimulation.AvatarInteractiveSimulationActions; import ui.avatarinteractivesimulation.JFrameAvatarInteractiveSimulation; @@ -112,6 +114,10 @@ public class Action extends Command implements ProVerifOutputListener { private final static String CHECKSYNTAX = "check-syntax"; private final static String REMOVE_TIME = "remove-time-operators"; + private final static String DIPLO_MUTATION = "diplodocus-mutation"; + private final static String DIPLO_MUTATION_BATCH = "diplodocus-mutation-batch"; + private final static String DIPLO_DRAW = "diplodocus-print"; + private final static String DIPLO_PRINT = "diplodocus-draw"; private final static String DIPLO_INTERACTIVE_SIMULATION = "diplodocus-interactive-simulation"; private final static String DIPLO_FORMAL_VERIFICATION = "diplodocus-formal-verification"; private final static String DIPLO_ONETRACE_SIMULATION = "diplodocus-onetrace-simulation"; @@ -580,6 +586,193 @@ public class Action extends Command implements ProVerifOutputListener { } }; + Command drawDiplodocusModel = new Command() { + public String getCommand() { + return DIPLO_DRAW; + } + + public String getShortCommand() { + return "dd"; + } + + public String getDescription() { + return "Draws the current DIPLODOCUS (TML, TMARCHI, TMAP) model"; + } + + public String getUsage() { + return "\n"; + } + + + public String executeCommand(String command, Interpreter interpreter) { + + if (!interpreter.isTToolStarted()) { + return Interpreter.TTOOL_NOT_STARTED; + } + + + TMLModeling<?> tmlModel = interpreter.mgui.gtm.getTMLModeling(); + TMLMapping tmlMapping = interpreter.mgui.gtm.getTMLMapping(); + + DateFormat dateFormat = new SimpleDateFormat("_yyyyMMdd_HHmmss"); + Date date = new Date(); + String dateAndTime = dateFormat.format(date); + + if (tmlModel == null && tmlMapping == null) { + return "No model"; + } else{ + if (tmlModel != null){ + try { + interpreter.mgui.drawTMLSpecification(tmlModel,"TMLModel", dateAndTime); + } catch (MalformedTMLDesignException e) { + TraceManager.addDev("Exception in drawing TML model :" + e.getMessage()); + } + } + if (tmlMapping != null){ + try { + interpreter.mgui.drawTMAPSpecification(tmlMapping, "TMLMapping", dateAndTime); + } catch (MalformedTMLDesignException e) { + TraceManager.addDev("Exception in drawing TML model :" + e.getMessage()); + } + } + } + return null; + } + }; + + + Command makeMutationFromDiplodocus = new Command() { + public String getCommand() { + return DIPLO_MUTATION; + } + + public String getShortCommand() { + return "dm"; + } + + public String getDescription() { + return "Performs a mutation on a DIPLODOCUS (TML, TMAP or TARCHI) model"; + } + + public String getUsage() { + return "[DIPLODOCUS MUTATION]\n"; + } + + public String getExample() { + return "dm rm connection between task1.chOut and task2.chIn"; + } + + public String executeCommand(String command, Interpreter interpreter) { + + if (!interpreter.isTToolStarted()) { + return Interpreter.TTOOL_NOT_STARTED; + } + + String[] commands = command.split(" "); + if (commands.length < 1) { + return Interpreter.BAD; + } + + TMLModeling<?> tmlModel = interpreter.mgui.gtm.getTMLModeling(); + TMLMapping tmlMapping = interpreter.mgui.gtm.getTMLMapping(); + + try { + DiplodocusMutation dm = DiplodocusMutation.createFromString(command); + if (dm != null) { + switch (dm.getMutationType()){ + case "TMLmutation": + if(tmlModel == null){ + return "No TML model"; + } else{ + dm.apply(tmlModel); + } + //case "TARCHImutation": + + //case "TMAPmutation": + } + } + } catch (ParseDiplodocusMutationException e) { + TraceManager.addDev("Exception in parsing mutation: " + e.getMessage()); + } catch (ApplyDiplodocusMutationException e) { + TraceManager.addDev("Exception in applying mutation: " + e.getMessage()); + } + + return null; + } + + }; + + Command makeMutationBatchFromDiplodocus = new Command() { + public String getCommand() { + return DIPLO_MUTATION_BATCH; + } + + public String getShortCommand() { + return "dmb"; + } + + public String getDescription() { + return "Perform a series of mutations on a DIPLODOCUS (TML, TMAP or TARCHI) model"; + } + + public String getUsage() { + return "[MUTATION]\n"; + } + + public String getExample() { + return "dmb path_to_command_file"; + } + + public String executeCommand(String command, Interpreter interpreter) { + + if (!interpreter.isTToolStarted()) { + return Interpreter.TTOOL_NOT_STARTED; + } + + String[] commands = command.split(" "); + if (commands.length < 1) { + return Interpreter.BAD; + } + + TMLModeling<?> tmlModel = interpreter.mgui.gtm.getTMLModeling(); + TMLMapping tmlMapping = interpreter.mgui.gtm.getTMLMapping(); + + List<String> mutationList = null; + try { + mutationList = Files.readAllLines(new File(command).toPath()); + } catch (IOException e) { + throw new RuntimeException(e); + } + + for (String mutationCommand:mutationList){ + try { + DiplodocusMutation dm = DiplodocusMutation.createFromString(mutationCommand); + if (dm != null) { + switch (dm.getMutationType()){ + case "TMLmutation": + if(tmlModel == null){ + return "No TML model"; + } else{ + dm.apply(tmlModel); + } + //case "TARCHImutation": + + //case "TMAPmutation": + } + } + } catch (ParseDiplodocusMutationException e) { + TraceManager.addDev("Exception in parsing mutation: " + e.getMessage()); + return e.getMessage(); + } catch (ApplyDiplodocusMutationException e) { + TraceManager.addDev("Exception in applying mutation: " + e.getMessage()); + return e.getMessage(); + } + } + + return null; + } + }; + // Diplodocus interactive simulation Command diplodocusInteractiveSimulation = new Command() { public String getCommand() { @@ -1191,7 +1384,7 @@ public class Action extends Command implements ProVerifOutputListener { } public String getDescription() { - return "Perform a mutation on an AVATAR spec"; + return "Performs a mutation on an AVATAR spec"; } public String getUsage() { @@ -2153,6 +2346,9 @@ public class Action extends Command implements ProVerifOutputListener { addAndSortSubcommand(checkSyntax); addAndSortSubcommand(removeTimeOperators); + addAndSortSubcommand(makeMutationFromDiplodocus); + addAndSortSubcommand(makeMutationBatchFromDiplodocus); + addAndSortSubcommand(drawDiplodocusModel); addAndSortSubcommand(generateRGFromAvatar); addAndSortSubcommand(diplodocusInteractiveSimulation); addAndSortSubcommand(diplodocusFormalVerification); diff --git a/src/main/java/tmltranslator/TMLModeling.java b/src/main/java/tmltranslator/TMLModeling.java index e1e5b8c0d9a0a12976b789afd554bd249556c658..069a51cad535e645282dcea009bef93b2f0e184d 100755 --- a/src/main/java/tmltranslator/TMLModeling.java +++ b/src/main/java/tmltranslator/TMLModeling.java @@ -161,6 +161,10 @@ public class TMLModeling<E> { requests.add(request); } + public void removeRequest(TMLRequest request) { + requests.remove(request); + } + public void addEvent(TMLEvent event) { events.add(event); } @@ -1631,6 +1635,10 @@ public class TMLModeling<E> { channels.remove(ch); } + public void removeEvent(TMLEvent e) { + events.remove(e); + } + public void sortByName() { ArrayList<TMLTask> ttasks = new ArrayList<TMLTask>(); ArrayList<TMLChannel> tchannels = new ArrayList<TMLChannel>(); diff --git a/src/main/java/tmltranslator/TMLTask.java b/src/main/java/tmltranslator/TMLTask.java index 3085a74233c7a8d2b39a9e0dfa618e0f2086e904..6517fd4f09c3e1859718d8a024878b7d6c863673 100755 --- a/src/main/java/tmltranslator/TMLTask.java +++ b/src/main/java/tmltranslator/TMLTask.java @@ -417,14 +417,26 @@ public class TMLTask extends TMLElement { channelsList.add(_ch); } + public void removeTMLChannel(TMLChannel _ch) { + channelsList.remove(_ch); + } + public void addReadTMLChannel(TMLChannel _ch) { readTMLChannelsList.add(_ch); } + public void removeReadTMLChannel(TMLChannel _ch) { + readTMLChannelsList.remove(_ch); + } + public void addWriteTMLChannel(TMLChannel _ch) { writeTMLChannelsList.add(_ch); } + public void removeWriteTMLChannel(TMLChannel _ch) { + writeTMLChannelsList.remove(_ch); + } + /*public List<TMLChannel> getTMLChannels() { return new ArrayList<TMLChannel>(channelsList); }*/ @@ -441,6 +453,10 @@ public class TMLTask extends TMLElement { eventsList.add(_evt); } + public void removeTMLEvent(TMLEvent _evt) { + eventsList.remove(_evt); + } + public List<TMLEvent> getTMLEvents() { return new ArrayList<TMLEvent>(eventsList); } diff --git a/src/main/java/tmltranslator/mutations/AddAttributeMutation.java b/src/main/java/tmltranslator/mutations/AddAttributeMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..14e119630b9d7baa306080718a1f05c3a7e03628 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AddAttributeMutation.java @@ -0,0 +1,126 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.*; + +import java.util.Arrays; +import java.util.List; + +public class AddAttributeMutation extends AttributeMutation { + protected AddAttributeMutation(String _taskName, String _attributeName, String _attributeType) { + super(_taskName); + setAttributeName(_attributeName); + setAttributeType(_attributeType); + } + + protected AddAttributeMutation(String _taskName, String _attributeName, String _attributeType, String _initialValue) { + super(_taskName); + setAttributeName(_attributeName); + setAttributeType(_attributeType); + setInitialValue(_initialValue); + } + + public TMLAttribute createElement(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException{ + TMLTask task = getTask(_tmlModel); + if (task == null){ + throw new ApplyDiplodocusMutationException("Task " + this.getTaskName() + " does not exist in this model."); + } + + for (TMLAttribute a : task.getAttributes()){ + if (a.getName() == this.getName()){ + throw new ApplyDiplodocusMutationException("An attribute named " + this.getName() + " already exists in task " + getTaskName()); + } + } + + TMLType _type = new TMLType(getType()); + TMLAttribute attr; + if (hasInitialValue()){ + attr = new TMLAttribute(getName(), _type, getInitialValue()); + } else { + attr = new TMLAttribute(getName(), _type); + } + return attr; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLAttribute attr = createElement(_tmlModel); + getTask(_tmlModel).addAttribute(attr); + } + + public static AddAttributeMutation createFromString(String toParse) throws ParseDiplodocusMutationException { + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + AddAttributeMutation mutation = null; + + int index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.ATTRIBUTE); + if (tokens.length <= index + 2) { + throw new ParseDiplodocusMutationException("Missing attribute arguments. Expected format is add attribute type name[=val] in taskName"); + } + String _attributeType = tokens[index + 1]; + String _attributeName = tokens[index + 2]; + String[] types = {"INT","BOOL"}; + if (!Arrays.asList(types).contains(_attributeType.toUpperCase())){ + throw new ParseDiplodocusMutationException("Missing or wrong type. Expected format is add attribute type name[=val] in taskName, and " + + "type is int or bool."); + } + + index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.IN); + if (tokens.length == index + 1 || index == -1) { + throw new ParseDiplodocusMutationException("Missing task name. Expected format is add attribute type name[=val] in taskName"); + } + String _taskName = tokens[index + 1]; + + index = DiplodocusMutationParser.indexOf(tokens, "="); + if (index != -1) { + if (tokens.length == index + 1) { + throw new ParseDiplodocusMutationException("Missing attribute initial value. Expected format is add attribute type name[=val] in " + + "taskName"); + } + String _initialValue = tokens[index + 1]; + mutation = new AddAttributeMutation(_taskName, _attributeName, _attributeType, _initialValue); + } else { + mutation = new AddAttributeMutation(_taskName, _attributeName, _attributeType); + } + + mutation.setMutationType("TMLmutation"); + return mutation; + } + +} diff --git a/src/main/java/tmltranslator/mutations/AddDataConnectionMutation.java b/src/main/java/tmltranslator/mutations/AddDataConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..829a8a23b3c2c855b7622f8fb2ea0a5d45de6b4e --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AddDataConnectionMutation.java @@ -0,0 +1,138 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLChannel; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; + +public class AddDataConnectionMutation extends DataConnectionMutation{ + + protected AddDataConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName, String _connectionSemantics) { + super(_originTaskName, _destinationTaskName, _connectionName); + setConnectionSemantics(_connectionSemantics); + } + + protected AddDataConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName, String _connectionSemantics, int _bufferSize) { + super(_originTaskName, _destinationTaskName, _connectionName); + setConnectionSemantics(_connectionSemantics); + setBufferSize(_bufferSize); + } + + public TMLChannel createElement(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException{ + if (getDataConnection(_tmlModel)!=null){ + throw new ApplyDiplodocusMutationException("A data connection named " + getConnectionName() + " already exists in the current model."); + } + + TMLChannel channel = new TMLChannel(getConnectionName(), null); + int size = getBufferSize(); + + TMLTask _originTask = getOriginTask(_tmlModel); + TMLTask _destinationTask = getDestinationTask(_tmlModel); + if (_originTask==null){ + throw new ApplyDiplodocusMutationException("The task named " + getOriginTaskName() + " does not exist in the current model."); + } + if (_destinationTask==null){ + throw new ApplyDiplodocusMutationException("The task named " + getDestinationTaskName() + " does not exist in the current model."); + } + channel.setOriginTask(_originTask); + channel.setDestinationTask(_destinationTask); + channel.setMax(8); + if (getConnectionSemantics() == DiplodocusMutationParser.BRBW){ + channel.setType(TMLChannel.BRBW); + } + if (getConnectionSemantics() == DiplodocusMutationParser.BRNBW){ + channel.setType(TMLChannel.BRNBW); + } + if (getConnectionSemantics() == DiplodocusMutationParser.NBRNBW){ + channel.setType(TMLChannel.NBRNBW); + } + if (size == -1){ + channel.setSize(4); + } else { + channel.setSize(size); + } + return channel; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLChannel channel = createElement(_tmlModel); + _tmlModel.addChannel(channel); + } + + public static AddDataConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + AddDataConnectionMutation mutation = null; + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.BETWEEN); + if (tokens.length <= index + 3) { + throw new ParseDiplodocusMutationException("Missing task name. Expected syntax is add data connection connectionName between " + + "originTaskName and destinationTaskName"); + } + String _originTaskName = tokens[index+1]; + String _destinationTaskName = tokens[index+3]; + + if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.CONNECTION)){ + throw new ParseDiplodocusMutationException("Missing or invalid connection name. Expected syntax is add data connection connectionName " + + "between originTaskName and destinationTaskName with connectionName != 'connection'"); + } + String _connectionName = tokens[index-1]; + + index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.DATA); + if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.ADD)){ + mutation = new AddDataConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.BRBW); + } else if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.BRNBW)){ + mutation = new AddDataConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.BRNBW); + } else if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.NBRNBW)){ + mutation = new AddDataConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.NBRNBW); + } else if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.BRBW)){ + throw new ParseDiplodocusMutationException("Missing channel width. Expected syntax is add BRBW,integerValue data connection connectionName between originTaskName and destinationTaskName"); + } else if (tokens[index-2].toUpperCase().equals(DiplodocusMutationParser.BRBW) && tokens[index-1].equals(",")){ + throw new ParseDiplodocusMutationException("Missing channel width. Expected syntax is add BRBW,integerValue data connection connectionName between originTaskName and destinationTaskName"); + } else if (tokens[index-3].toUpperCase().equals(DiplodocusMutationParser.BRBW) && tokens[index-2].equals(",") && isNumeric(tokens[index-1])){ + mutation = new AddDataConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.BRBW, Integer.valueOf(tokens[index-1])); + } else if (tokens[index-3].toUpperCase().equals(DiplodocusMutationParser.BRBW) && tokens[index-2].equals(",") && !isNumeric(tokens[index-1])){ + throw new ParseDiplodocusMutationException("Channel width must be an integer written with Arabic digits."); + } + + mutation.setMutationType("TMLmutation"); + return mutation; + } +} diff --git a/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java b/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..c764278f249eff3c342034d1dc44e070c58cab6b --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AddEventConnectionMutation.java @@ -0,0 +1,175 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import avatartranslator.mutation.MutationParser; +import tmltranslator.TMLEvent; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; +import tmltranslator.TMLType; +import tmltranslator.tonetwork.Link; + +import java.util.LinkedList; +import java.util.List; + +public class AddEventConnectionMutation extends EventConnectionMutation{ + protected List<String> parameters; + + protected AddEventConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName, String _connectionSemantics) { + super(_originTaskName, _destinationTaskName, _connectionName); + setConnectionSemantics(_connectionSemantics); + } + + protected AddEventConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName, String _connectionSemantics, int _bufferSize) { + super(_originTaskName, _destinationTaskName, _connectionName); + setConnectionSemantics(_connectionSemantics); + setBufferSize(_bufferSize); + } + + public TMLEvent createElement(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException{ + if (getEventConnectionMutation(_tmlModel) != null){ + throw new ApplyDiplodocusMutationException("An event connection named " + getConnectionName() + " already exists in the current model."); + } + + TMLEvent event = new TMLEvent(getConnectionName(), null, getBufferSize(), false); + + TMLTask _originTask = getOriginTask(_tmlModel); + TMLTask _destinationTask = getDestinationTask(_tmlModel); + if (_originTask == null){ + throw new ApplyDiplodocusMutationException("The task named " + getOriginTaskName() + " does not exist in the current model."); + } + if (_destinationTask==null){ + throw new ApplyDiplodocusMutationException("The task named " + getDestinationTaskName() + " does not exist in the current model."); + } + event.setOriginTask(_originTask); + event.setDestinationTask(_destinationTask); + + if (getConnectionSemantics() == DiplodocusMutationParser.INFINITE){ + event.setBlocking(false); + event.setSizeFIFO(-1); + } else if (getConnectionSemantics() == DiplodocusMutationParser.FINITEBLOCKING){ + event.setBlocking(true); + } else if (getConnectionSemantics() == DiplodocusMutationParser.FINITENONBLOCKING){ + event.setBlocking(false); + } + + event.setSizeFIFO(getBufferSize()); + + return event; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLEvent event = createElement(_tmlModel); + if (parameters != null) { + for (String parameter : parameters) { + int type = 4; + if (parameter.toUpperCase().equals("INT")) { + type = TMLType.NATURAL; + } else if (parameter.toUpperCase().equals("BOOL")) { + type = TMLType.BOOLEAN; + } + event.addParam(new TMLType(type)); + } + } + _tmlModel.addEvent(event); + } + + public static AddEventConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + AddEventConnectionMutation mutation = null; + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.BETWEEN); + if (tokens.length <= index + 3) { + throw new ParseDiplodocusMutationException("Missing task name. Expected syntax is add event connection connectionName between " + + "originTaskName and destinationTaskName"); + } + String _originTaskName = tokens[index+1]; + String _destinationTaskName = tokens[index+3]; + + if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.CONNECTION)){ + throw new ParseDiplodocusMutationException("Missing or invalid connection name. Expected syntax is add event connection connectionName " + + "between originTaskName and destinationTaskName with connectionName != 'connection'"); + } + + boolean hasParameters = false; + String _connectionName; + if (DiplodocusMutationParser.indexOf(tokens,"(") != -1){ + hasParameters = true; + } + if (hasParameters){ + _connectionName = tokens[DiplodocusMutationParser.indexOf(tokens,"(")-1]; + } else { + _connectionName = tokens[index - 1]; + } + + index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.EVENT); + if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.ADD)){ + mutation = new AddEventConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.FINITEBLOCKING, 4); + } else if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.INFINITE)){ + mutation = new AddEventConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.INFINITE); + } else if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.FINITEBLOCKING)){ + throw new ParseDiplodocusMutationException("Missing event width. Expected syntax is add finiteBlocking,integerValue event connection " + + "connectionName between originTaskName and destinationTaskName"); + } else if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.FINITENONBLOCKING)){ + throw new ParseDiplodocusMutationException("Missing event width. Expected syntax is add finiteNonBlocking,integerValue event connection" + + " connectionName between originTaskName and destinationTaskName"); + } else if (tokens[index-2].toUpperCase().equals(DiplodocusMutationParser.FINITEBLOCKING) && tokens[index-1].equals(",")){ + throw new ParseDiplodocusMutationException("Missing event width. Expected syntax is add finiteBlocking,integerValue event connection " + + "connectionName between originTaskName and destinationTaskName"); + } else if (tokens[index-2].toUpperCase().equals(DiplodocusMutationParser.FINITENONBLOCKING) && tokens[index-1].equals(",")){ + throw new ParseDiplodocusMutationException("Missing event width. Expected syntax is add finiteNonBlocking,integerValue event connection" + + " connectionName between originTaskName and destinationTaskName"); + } else if (tokens[index-3].toUpperCase().equals(DiplodocusMutationParser.FINITEBLOCKING) && tokens[index-2].equals(",") && isNumeric(tokens[index-1])){ + mutation = new AddEventConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.FINITEBLOCKING, Integer.valueOf(tokens[index-1])); + } else if (tokens[index-3].toUpperCase().equals(DiplodocusMutationParser.FINITEBLOCKING) && tokens[index-2].equals(",") && !isNumeric(tokens[index-1])){ + throw new ParseDiplodocusMutationException("Event width must be an integer written with Arabic digits."); + } else if (tokens[index-3].toUpperCase().equals(DiplodocusMutationParser.FINITENONBLOCKING) && tokens[index-2].equals(",") && isNumeric(tokens[index-1])) { + mutation = new AddEventConnectionMutation(_originTaskName, _destinationTaskName, _connectionName, DiplodocusMutationParser.FINITENONBLOCKING, Integer.valueOf(tokens[index - 1])); + } else if (tokens[index-3].toUpperCase().equals(DiplodocusMutationParser.FINITENONBLOCKING) && tokens[index-2].equals(",") && !isNumeric(tokens[index-1])){ + throw new ParseDiplodocusMutationException("Event width must be an integer written with Arabic digits."); + } + + if (hasParameters){ + mutation.parameters = parseParameters(toParse); + } + mutation.setMutationType("TMLmutation"); + return mutation; + } +} diff --git a/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..5a4588d102b7402e5bf1451da4f7f81683c93147 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AddRequestConnectionMutation.java @@ -0,0 +1,131 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import avatartranslator.mutation.MutationParser; +import tmltranslator.TMLModeling; +import tmltranslator.TMLRequest; +import tmltranslator.TMLTask; +import tmltranslator.TMLType; + +import java.util.LinkedList; +import java.util.List; + +public class AddRequestConnectionMutation extends RequestConnectionMutation { + protected List<String> parameters; + + protected AddRequestConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(_originTaskName, _destinationTaskName, _connectionName); + } + + public TMLRequest createElement(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + if (getRequest(_tmlModel) != null){ + throw new ApplyDiplodocusMutationException("An request connection named " + getConnectionName() + " already exists in the current model."); + } + + TMLRequest request = new TMLRequest(getConnectionName(), null); + + TMLTask _originTask = getOriginTask(_tmlModel); + TMLTask _destinationTask = getDestinationTask(_tmlModel); + if (_originTask == null){ + throw new ApplyDiplodocusMutationException("The task named " + getOriginTaskName() + " does not exist in the current model."); + } + if (_destinationTask==null){ + throw new ApplyDiplodocusMutationException("The task named " + getDestinationTaskName() + " does not exist in the current model."); + } + request.addOriginTask(_originTask); + request.setDestinationTask(_destinationTask); + + return request; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLRequest request = createElement(_tmlModel); + if (parameters != null) { + for (String parameter : parameters) { + int type = 4; + if (parameter.toUpperCase().equals("INT")) { + type = TMLType.NATURAL; + } else if (parameter.toUpperCase().equals("BOOL")) { + type = TMLType.BOOLEAN; + } + request.addParam(new TMLType(type)); + } + } + _tmlModel.addRequest(request); + } + + public static AddRequestConnectionMutation createFromString (String toParse) throws ParseDiplodocusMutationException { + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.BETWEEN); + if (tokens.length <= index + 3) { + throw new ParseDiplodocusMutationException("Missing task name. Expected syntax is add request connection connectionName between " + + "originTaskName and destinationTaskName"); + } + String _originTaskName = tokens[index+1]; + String _destinationTaskName = tokens[index+3]; + + if (tokens[index-1].toUpperCase().equals(DiplodocusMutationParser.CONNECTION)){ + throw new ParseDiplodocusMutationException("Missing or invalid connection name. Expected syntax is add request connection " + + "connectionName between originTaskName and destinationTaskName with connectionName != 'connection'"); + } + + boolean hasParameters = false; + String _connectionName; + if (DiplodocusMutationParser.indexOf(tokens,"(") != -1){ + hasParameters = true; + } + if (hasParameters){ + _connectionName = tokens[DiplodocusMutationParser.indexOf(tokens,"(")-1]; + } else { + _connectionName = tokens[index - 1]; + } + + AddRequestConnectionMutation mutation = new AddRequestConnectionMutation(_originTaskName, _destinationTaskName, _connectionName); + if (hasParameters){ + mutation.parameters = parseParameters(toParse); + } + mutation.setMutationType("TMLmutation"); + + return mutation; + } + +} diff --git a/src/main/java/tmltranslator/mutations/AddTaskMutation.java b/src/main/java/tmltranslator/mutations/AddTaskMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..8c8d32bf9128c3cb9bf170df0b35193a6437b288 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AddTaskMutation.java @@ -0,0 +1,90 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.*; + +import java.util.List; + +public class AddTaskMutation extends TaskMutation { + protected AddTaskMutation(String _taskName) { + super(_taskName); + } + + public TMLTask createElement(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException{ + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + + for (TMLTask task : _tmlModel.getTasks()){ + if (task.getName().equals(getTaskName())){ + throw new ApplyDiplodocusMutationException("A task named " + getTaskName() + " already exists in the current model."); + } + if (task.getName().equals(appName + "__" + getTaskName())){ + throw new ApplyDiplodocusMutationException("A task named " + getTaskName() + " already exists in the current model."); + } + } + TMLTask task = new TMLTask(getTaskName(), _tmlModel, null); + return task; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLTask task = createElement(_tmlModel); + TMLActivity ad = task.getActivityDiagram(); + TMLStartState start = new TMLStartState("start",null); + TMLStopState stop = new TMLStopState("stop",null); + ad.setFirst(start); + task.addElement(start,stop); + _tmlModel.addTask(task); + } + + public static AddTaskMutation createFromString(String toParse) throws ParseDiplodocusMutationException { + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + int index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.TASK); + if (tokens.length == index + 1) { + throw new ParseDiplodocusMutationException("Task name missing. Expected format is add task taskName"); + } + String _taskName = tokens[index + 1]; + AddTaskMutation mutation = new AddTaskMutation(_taskName); + mutation.setMutationType("TMLmutation"); + return mutation; + } +} diff --git a/src/main/java/tmltranslator/mutations/ApplyDiplodocusMutationException.java b/src/main/java/tmltranslator/mutations/ApplyDiplodocusMutationException.java new file mode 100644 index 0000000000000000000000000000000000000000..367a9397d1bcb2cf5cb2d885e1930904df095c32 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/ApplyDiplodocusMutationException.java @@ -0,0 +1,45 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +public class ApplyDiplodocusMutationException extends DiplodocusMutationException { + public ApplyDiplodocusMutationException(String message){ + super(message); + } +} diff --git a/src/main/java/tmltranslator/mutations/AttributeMutation.java b/src/main/java/tmltranslator/mutations/AttributeMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..563bd959703838f32da5f8a5efb084a49d822e4c --- /dev/null +++ b/src/main/java/tmltranslator/mutations/AttributeMutation.java @@ -0,0 +1,97 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLType; +public abstract class AttributeMutation extends TaskMutation{ + + private String attributeType; + private String attributeName; + private String initialValue; + private Boolean hasInitialValue = false; + + protected AttributeMutation(String _taskName) { + super(_taskName); + } + + protected void setAttributeName(String _name) { + attributeName = _name; + } + + public String getName() { + return attributeName; + } + + protected void setAttributeType(String _type) { + attributeType = _type; + } + + public int getType() { + return TMLType.getType(attributeType); + } + + protected void setInitialValue(String _initialValue) { + hasInitialValue = true; + initialValue = _initialValue; + } + + public Boolean hasInitialValue() { + return hasInitialValue; + } + + public String getInitialValue() { + if (hasInitialValue()) return initialValue; + return null; + } + + public static AttributeMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + switch (DiplodocusMutationParser.findMutationToken(toParse)){ + case DiplodocusMutationParser.ADD: + return AddAttributeMutation.createFromString(toParse); + case DiplodocusMutationParser.RM: + case DiplodocusMutationParser.REMOVE: + return RemoveAttributeMutation.createFromString(toParse); + default: + break; + } + return null; + } + + +} diff --git a/src/main/java/tmltranslator/mutations/CloneTaskMutation.java b/src/main/java/tmltranslator/mutations/CloneTaskMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..b8ccae0f9b36c7707e83c22d9445628302f13b53 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/CloneTaskMutation.java @@ -0,0 +1,112 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLCheckingError; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; + +public class CloneTaskMutation extends TaskMutation{ + + private String newTaskName; + protected CloneTaskMutation(String _taskName, String _newTaskName) { + super(_taskName); + setNewTaskName(_newTaskName); + } + + protected void setNewTaskName(String _newTaskName){ + newTaskName = _newTaskName; + } + + protected String getNewTaskName(){ + return newTaskName; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLTask task = getTask(_tmlModel); + TMLTask newTask = null; + + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + + for (TMLTask t : _tmlModel.getTasks()){ + if (t.getName().equals(getNewTaskName())){ + throw new ApplyDiplodocusMutationException("A task named " + getNewTaskName() + " already exists in the current model."); + } + if (t.getName().equals(appName + "__" + getNewTaskName())){ + throw new ApplyDiplodocusMutationException("A task named " + getNewTaskName() + " already exists in the current model."); + } + } + + if (task == null){ + throw new ApplyDiplodocusMutationException("Task " + getTaskName() + " does not exist in the current model."); + } + try { + newTask = task.deepClone(_tmlModel); + } catch (TMLCheckingError e) { + throw new RuntimeException(e); + } + newTask.setName(getNewTaskName()); + _tmlModel.addTask(newTask); + } + + public static CloneTaskMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.TASK); + if (tokens.length == index + 1) { + throw new ParseDiplodocusMutationException("Task name missing. Expected format is clone task taskName in newTaskName"); + } + String _taskName = tokens[index + 1]; + + index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.IN); + if (tokens.length == index + 1) { + throw new ParseDiplodocusMutationException("New task name missing. Expected format is clone task taskName in newTaskName"); + } + String _newTaskName = tokens[index + 1]; + + CloneTaskMutation mutation = new CloneTaskMutation(_taskName, _newTaskName); + mutation.setMutationType("TMLmutation"); + return mutation; + } + +} diff --git a/src/main/java/tmltranslator/mutations/ConnectionMutation.java b/src/main/java/tmltranslator/mutations/ConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..fa5b4647c52970a012862f3f68d536ee1b361c3f --- /dev/null +++ b/src/main/java/tmltranslator/mutations/ConnectionMutation.java @@ -0,0 +1,174 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import avatartranslator.mutation.MutationParser; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; + +import java.util.LinkedList; +import java.util.List; + +public abstract class ConnectionMutation extends DiplodocusMutation{ + private String connectionName; + private String connectionSemantics; + private String originTaskName; + private String destinationTaskName; + private int bufferSize = -1; + protected ConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(); + setOriginTaskName(_originTaskName); + setDestinationTaskName(_destinationTaskName); + setConnectionName(_connectionName); + } + + protected ConnectionMutation(String _connectionName){ + super(); + setConnectionName(_connectionName); + } + + protected ConnectionMutation(){ + super(); + } + + public void setConnectionName(String _connectionName){ + connectionName = _connectionName; + } + + public void setConnectionSemantics(String _connectionSemantics){ + connectionSemantics = _connectionSemantics; + } + + public void setOriginTaskName(String _originTaskName){ + originTaskName = _originTaskName; + } + + public void setDestinationTaskName(String _destinationTaskName){ + destinationTaskName = _destinationTaskName; + } + + public String getConnectionName(){ + return connectionName; + } + + public String getConnectionSemantics(){ + return connectionSemantics; + } + + public String getOriginTaskName(){ + return originTaskName; + } + + public String getDestinationTaskName(){ + return destinationTaskName; + } + + public void setBufferSize(int _bufferSize){ + bufferSize = _bufferSize; + } + + public int getBufferSize(){ + return bufferSize; + } + + protected TMLTask getOriginTask(TMLModeling<?> _tmlmodel){ + String appName = ""; + if (_tmlmodel.getTasks().size() != 0){ + appName = _tmlmodel.getTasks().get(0).getName().split("__")[0]; + } + TMLTask task = _tmlmodel.getTMLTaskByName(originTaskName); + if (task!=null){ + return task; + } + return _tmlmodel.getTMLTaskByName(appName + "__" + originTaskName); + } + + protected TMLTask getDestinationTask(TMLModeling<?> _tmlmodel){ + String appName = ""; + if (_tmlmodel.getTasks().size() != 0){ + appName = _tmlmodel.getTasks().get(0).getName().split("__")[0]; + } + TMLTask task = _tmlmodel.getTMLTaskByName(destinationTaskName); + if (task!=null){ + return task; + } + return _tmlmodel.getTMLTaskByName(appName + "__" + destinationTaskName); + } + + public static boolean isNumeric(String str) { + return str.matches("-?\\d+(\\.\\d+)?"); + } + + public static List<String> parseParameters(String toParse) throws ParseDiplodocusMutationException{ + List<String> _parameters = new LinkedList<>(); + String[] tokens = MutationParser.tokenise(toParse); + + int endIndex; + int closingBracketIndex = DiplodocusMutationParser.indexOf(tokens,")"); + if (closingBracketIndex == -1){ + throw new ParseDiplodocusMutationException("Missing ) at the end of the parameters list."); + } else { + endIndex = closingBracketIndex ; + } + for(int i = DiplodocusMutationParser.indexOf(tokens,"(") + 1; i < endIndex; i += 2) { + if (!(tokens[i].toUpperCase().equals("INT") || tokens[i].toUpperCase().equals("BOOL"))){ + throw new ParseDiplodocusMutationException("Incorrect type provided in parameters list or incorrect list format. Expected types are" + + " int or bool, and expected list format is (type1,type2,...,typen)."); + } + _parameters.add(tokens[i]); + } + + return _parameters; + } + + public static ConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + switch (DiplodocusMutationParser.findConnectionTypeToken(toParse)) { + case DiplodocusMutationParser.DATA: + return DataConnectionMutation.createFromString(toParse); + case DiplodocusMutationParser.EVENT: + return EventConnectionMutation.createFromString(toParse); + case DiplodocusMutationParser.REQUEST: + return RequestConnectionMutation.createFromString(toParse); + default: + break; + } + return null; + } + +} diff --git a/src/main/java/tmltranslator/mutations/DataConnectionMutation.java b/src/main/java/tmltranslator/mutations/DataConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..6716893a4fc9a3c3f0a7acaab03be8a2857f1158 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/DataConnectionMutation.java @@ -0,0 +1,114 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLChannel; +import tmltranslator.TMLModeling; + +import java.util.List; + +public abstract class DataConnectionMutation extends ConnectionMutation{ + //private Boolean BRBW, NBRNBW, BRNBW; + protected DataConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(_originTaskName, _destinationTaskName, _connectionName); + } + + protected DataConnectionMutation(String _connectionName){ + super(_connectionName); + } + + protected DataConnectionMutation(){ + super(); + } + + /*public void setBRBW(boolean b){ + BRBW = b; + } + + public Boolean isBRBW(){ + return BRBW; + } + + public void setNBRNBW(boolean b){ + NBRNBW = b; + } + + public boolean isNBRNBW(){ + return NBRNBW; + } + + public void setBRNBW(boolean b){ + BRNBW = b; + } + + public boolean isBRNBW(){ + return BRNBW; + } + */ + + public TMLChannel getDataConnection(TMLModeling<?> _tmlModel){ + List<TMLChannel> channels = _tmlModel.getChannels(); + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + for (TMLChannel c:channels){ + if (c.getName().equals(getConnectionName())) { + return c; + } else if (c.getName().equals(appName + "__" + getConnectionName())) { + return c; + } + } + return null; + } + + public static DataConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + switch (DiplodocusMutationParser.findMutationToken(toParse)) { + case DiplodocusMutationParser.ADD: + return AddDataConnectionMutation.createFromString(toParse); + case DiplodocusMutationParser.RM: + case DiplodocusMutationParser.REMOVE: + return RemoveDataConnectionMutation.createFromString(toParse); + default: + break; + } + return null; + } + +} diff --git a/src/main/java/tmltranslator/mutations/DiplodocusMutation.java b/src/main/java/tmltranslator/mutations/DiplodocusMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..e989bdd433504bb74bc6e86103d6eb730c9f0d51 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/DiplodocusMutation.java @@ -0,0 +1,74 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLModeling; + +public abstract class DiplodocusMutation { + protected DiplodocusMutation(){ + super(); + } + + protected String mutationType; + + public void setMutationType(String type){ + mutationType = type; + } + + public String getMutationType(){ + return mutationType; + } + + public abstract void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException; + + public static DiplodocusMutation createFromString(String toParse) throws ParseDiplodocusMutationException { + toParse = toParse.trim(); + + switch (DiplodocusMutationParser.findElementToken(toParse)){ + case DiplodocusMutationParser.TASK: + return TaskMutation.createFromString(toParse); + case DiplodocusMutationParser.ATTRIBUTE: + return AttributeMutation.createFromString(toParse); + case DiplodocusMutationParser.CONNECTION: + return ConnectionMutation.createFromString(toParse); + } + return null; + } + +} diff --git a/src/main/java/tmltranslator/mutations/DiplodocusMutationException.java b/src/main/java/tmltranslator/mutations/DiplodocusMutationException.java new file mode 100644 index 0000000000000000000000000000000000000000..f01222f9587db5d811daa742b6def1f42e6f4858 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/DiplodocusMutationException.java @@ -0,0 +1,45 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +public class DiplodocusMutationException extends Exception{ + public DiplodocusMutationException(String message){ + super(message); + } +} diff --git a/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java b/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java new file mode 100644 index 0000000000000000000000000000000000000000..871ceb0c98bf96256b4490b17e04dca57c5bb786 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java @@ -0,0 +1,224 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import java.util.UUID; + +public interface DiplodocusMutationParser { + + public static final String ADD = "ADD"; + public static final String REMOVE = "REMOVE"; + public static final String RM = "RM"; + public static final String CLONE = "CLONE"; + public static final String MODIFY = "MODIFY"; + public static final String MD = "MD"; + public static final String TASK = "TASK"; + public static final String CONNECTION = "CONNECTION"; + public static final String PORT = "PORT"; + public static final String ATTRIBUTE = "ATTRIBUTE"; + public static final String DATA = "DATA"; + public static final String EVENT = "EVENT"; + public static final String REQUEST = "REQUEST"; + public static final String INPUT = "INPUT"; + public static final String OUTPUT = "OUTPUT"; + public static final String IN = "IN"; + public static final String FROM = "FROM"; + public static final String TO = "TO"; + public static final String AND = "AND"; + public static final String WITH = "WITH"; + public static final String AT = "AT"; + public static final String BETWEEN = "BETWEEN"; + public static final String BRBW = "BRBW"; + public static final String BRNBW = "BRNBW"; + public static final String NBRNBW = "NBRNBW"; + public static final String INFINITE = "INFINITE"; + public static final String FINITEBLOCKING = "FINITEBLOCKING"; + public static final String FINITENONBLOCKING = "FINITENONBLOCKING"; + + public static final String[] MUTATION_TOKENS = {ADD, RM, REMOVE, MD, MODIFY, CLONE}; + public static final String[] ELEMENT_TOKENS = {TASK, CONNECTION, PORT, ATTRIBUTE}; + public static final String[] CONNECTION_TYPE_TOKEN = {DATA, EVENT, REQUEST}; + public static final String[] INOUT_TOKENS = {INPUT, OUTPUT}; + public static final String[] KEYWORD_TOKENS = {IN, FROM, TO, WITH, AND, AT, BETWEEN}; + public static final String[] SEMANTICS_TOKENS = {BRBW, BRNBW, NBRNBW, INFINITE, FINITEBLOCKING, FINITENONBLOCKING}; + + public static final int UNDEFINED_TYPE = -1; + public static final int NAME_TYPE = 0; + public static final int UUID_TYPE = 1; + + public static boolean isToken(String str) { + if (findMutationToken(str).length() > 0) return true; + if (findElementToken(str).length() > 0) return true; + if (findInOutToken(str).length() > 0) return true; + if (findKeywordToken(str).length() > 0) return true; + return false; + } + + public static String tokensToString(String[] tokens) { + int len = tokens.length; + + String out = "[ " + tokens[0]; + + for(int i = 1; i < len; i++) { + out += " ; " + tokens[i]; + } + + out += " ]"; + + return out; + + } + + public static String[] tokenise(String _toParse, String tokens) { + //TraceManager.addDev(_toParse + " ; " + tokens); + int len = tokens.length(); + String toParse = _toParse; + for (int index = 0; index < len; index++) { + String c = String.valueOf(tokens.charAt(index)); + toParse = toParse.replace(c, "~" + c + "~"); + } + //TraceManager.addDev(toParse); + String[] out = toParse.split("(~[ ]*)+"); + //TraceManager.addDev(tokensToString(out)); + return out; + } + + public static String[] tokenise(String toParse) { + return tokenise(toParse, "(),[] "); + } + + public static int indexOf(int from, String[] arr, String token) { + int len = arr.length; + for (int index = from; index < len; index++) { + //TraceManager.addDev(token + " =? " + arr[index].toUpperCase()); + if (token.toUpperCase().equals(arr[index].toUpperCase())) return index; + } + return -1; + } + + public static int indexOf(String[] arr, String token) { + return indexOf(0, arr, token); + } + + public static boolean isTokenIn(int index, String[] arr, String token) { + return indexOf(index, arr, token) != -1; + } + + public static boolean isTokenIn(String[] arr, String token) { + return isTokenIn(0, arr, token); + } + + public static boolean isTokenIn(String s, String token) { + return isTokenIn(tokenise(s.toUpperCase()), token); + } + + public static String findToken(String[] arr, String[] tokens) { + for(String token : tokens) { + if(isTokenIn(arr, token)) return token; + } + return ""; + } + + public static String findToken(String str, String[] tokens) { + return findToken(tokenise(str.toUpperCase()), tokens); + } + + public static String findMutationToken(String str) { + return findToken(str, MUTATION_TOKENS); + } + + public static String findElementToken(String str) { + return findToken(str, ELEMENT_TOKENS); + } + + public static String findConnectionTypeToken(String str) { return findToken(str,CONNECTION_TYPE_TOKEN); } + + public static String findInOutToken(String[] arr) { + return findToken(arr, INOUT_TOKENS); + } + + public static String findInOutToken(String str) { + return findToken(str, INOUT_TOKENS); + } + + public static String findKeywordToken(String[] arr) { + return findToken(arr, KEYWORD_TOKENS); + } + + public static String findKeywordToken(String str) { + return findToken(str, KEYWORD_TOKENS); + } + + public static String findSemanticsToken(String[] arr) { + return findToken(arr, SEMANTICS_TOKENS); + } + + public static String findSemanticsToken(String str) { + return findToken(str, SEMANTICS_TOKENS); + } + + public static int UUIDType(String _name) { + if(isUUID(_name)) { + return UUID_TYPE; + } + return NAME_TYPE; + } + + public static boolean isUUID(String str) { + try { + UUID.fromString(str); + return true; + } catch (Exception e) { + return false; + } + } + + public static String concatenate(int startIndex, int endIndex, String[] arr) { + String out = arr[startIndex]; + for(int i = startIndex + 1; i < endIndex && i < arr.length; i++) { + out += " " + arr[i]; + } + return out; + } + + public static String concatenate(int startIndex, String[] arr) { + return concatenate(startIndex, arr.length, arr); + } + +} \ No newline at end of file diff --git a/src/main/java/tmltranslator/mutations/EventConnectionMutation.java b/src/main/java/tmltranslator/mutations/EventConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..85432eaab8996adbe7b665a7fb352e33ff1b08c1 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/EventConnectionMutation.java @@ -0,0 +1,87 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLEvent; +import tmltranslator.TMLModeling; + +import java.util.List; + +public abstract class EventConnectionMutation extends ConnectionMutation{ + private Boolean infinite, finiteBlocking, finiteNonBlocking; + protected EventConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(_originTaskName, _destinationTaskName, _connectionName); + } + + protected EventConnectionMutation(String _connectionName){ + super(_connectionName); + } + + protected EventConnectionMutation(){ + super(); + } + + public TMLEvent getEventConnectionMutation(TMLModeling<?> _tmlModel){ + List<TMLEvent> events = _tmlModel.getEvents(); + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + + TMLEvent event = _tmlModel.getEventByName(getConnectionName()); + if (event != null){ + return event; + } else { + return _tmlModel.getEventByName(appName + "__" + getConnectionName() + "__" + appName + "__" + getConnectionName()); + } + } + + public static EventConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + switch (DiplodocusMutationParser.findMutationToken(toParse)) { + case DiplodocusMutationParser.ADD: + return AddEventConnectionMutation.createFromString(toParse); + case DiplodocusMutationParser.RM: + case DiplodocusMutationParser.REMOVE: + return RemoveEventConnectionMutation.createFromString(toParse); + default: + break; + } + return null; + } +} diff --git a/src/main/java/tmltranslator/mutations/ParseDiplodocusMutationException.java b/src/main/java/tmltranslator/mutations/ParseDiplodocusMutationException.java new file mode 100644 index 0000000000000000000000000000000000000000..e254d3b47ec8978f7abd982037eee8a235311728 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/ParseDiplodocusMutationException.java @@ -0,0 +1,47 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +public class ParseDiplodocusMutationException extends DiplodocusMutationException { + + public ParseDiplodocusMutationException(String message) { + super(message); + } + +} diff --git a/src/main/java/tmltranslator/mutations/RemoveAttributeMutation.java b/src/main/java/tmltranslator/mutations/RemoveAttributeMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..d98f968f9f474bc577fc462868ffcc21187a220f --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RemoveAttributeMutation.java @@ -0,0 +1,86 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLAttribute; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; + +public class RemoveAttributeMutation extends AttributeMutation{ + protected RemoveAttributeMutation(String _taskName, String _attributeName) { + super(_taskName); + setAttributeName(_attributeName); + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLTask task = getTask(_tmlModel); + if (task == null){ + throw new ApplyDiplodocusMutationException("Task " + this.getTaskName() + " does not exist in this model."); + } + + TMLAttribute attr = task.getAttributeByName(getName()); + if (attr == null){ + throw new ApplyDiplodocusMutationException("Attribute " + this.getName() + " does not exist in task " + this.getTaskName() + "."); + } else { + task.getAttributes().remove(attr); + } + } + + public static RemoveAttributeMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.ATTRIBUTE); + if (tokens.length == index + 1) { + throw new ParseDiplodocusMutationException("Missing attribute name. Expected format is remove attribute name in taskName"); + } + String _attributeName = tokens[index + 1]; + + index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.IN); + if (tokens.length == index + 1 || index == -1) { + throw new ParseDiplodocusMutationException("Missing task name. Expected format is remove attribute name in taskName"); + } + String _taskName = tokens[index + 1]; + + RemoveAttributeMutation mutation = new RemoveAttributeMutation(_taskName, _attributeName); + mutation.setMutationType("TMLmutation"); + return mutation; + } + +} diff --git a/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..e5b7010841ce54e8cada217cdbc9c46d80f3f7a8 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java @@ -0,0 +1,113 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLChannel; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; + +import java.util.ArrayList; + +public class RemoveDataConnectionMutation extends DataConnectionMutation{ + String originPortName; + String destinationPortName; + protected RemoveDataConnectionMutation(String _connectionName) { + super(_connectionName); + } + protected RemoveDataConnectionMutation(String _originPortName, String _destinationPortName) { + super(); + originPortName = _originPortName; + destinationPortName = _destinationPortName; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLChannel channel = null; + + if (getConnectionName() != null) { + channel = getDataConnection(_tmlModel); + } else if (originPortName != null && destinationPortName != null) { + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + channel = _tmlModel.getChannelByName(appName + "__" + originPortName + "__" + appName + "__" + destinationPortName); + } + if (channel == null) { + if (getConnectionName() != null) { + throw new ApplyDiplodocusMutationException("There is no channel named " + getConnectionName() + " in this model."); + } else { + throw new ApplyDiplodocusMutationException("There is no channel between ports " + originPortName + " and " + destinationPortName + " in this model."); + } + } else { + _tmlModel.removeChannel(channel); + ArrayList<TMLTask> allTasks = channel.getAllTasks(); + for (TMLTask t : allTasks) { + t.removeTMLChannel(channel); + t.removeReadTMLChannel(channel); + t.removeReadTMLChannel(channel); + } + } + } + + public static RemoveDataConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + RemoveDataConnectionMutation mutation = null; + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.CONNECTION); + if (tokens.length == index+1) { + throw new ParseDiplodocusMutationException("Connection name missing. Expected syntax is remove data connection connectionName."); + } + else { + int indexDot = DiplodocusMutationParser.indexOf(tokens,","); + if (indexDot == -1) { + mutation = new RemoveDataConnectionMutation(tokens[index + 1]); + } else { + if (tokens.length <= indexDot+1){ + throw new ParseDiplodocusMutationException("Port name missing. Expected syntax is remove data connection originPortName," + + "destinationPortName"); + } + mutation = new RemoveDataConnectionMutation(tokens[indexDot-1], tokens[indexDot+1]); + } + } + + mutation.setMutationType("TMLmutation"); + return mutation; + } +} diff --git a/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..62d39da2b9783be4d6c3cd93def5cb5e97701dca --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java @@ -0,0 +1,113 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLEvent; +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; + +import java.util.List; + +public class RemoveEventConnectionMutation extends EventConnectionMutation{ + protected String originPortName; + protected String destinationPortName; + protected RemoveEventConnectionMutation(String _originTaskName) { + super(_originTaskName); + } + protected RemoveEventConnectionMutation(String _originPortName, String _destinationPortName) { + super(); + originPortName = _originPortName; + destinationPortName = _destinationPortName; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLEvent event = null; + if (getConnectionName() != null) { + event = getEventConnectionMutation(_tmlModel); + } else if (originPortName != null && destinationPortName != null) { + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + event = _tmlModel.getEventByName(appName + "__" + originPortName + "__" + appName + "__" + destinationPortName); + } + if (event == null){ + if (getConnectionName() != null) { + throw new ApplyDiplodocusMutationException("There is no event named " + getConnectionName() + " in this model."); + } else { + throw new ApplyDiplodocusMutationException("There is no event between ports " + originPortName + " and " + destinationPortName + " " + "in this model."); + } + } else { + _tmlModel.removeEvent(event); + List<TMLTask> allTasks = event.getOriginTasks(); + allTasks.addAll(event.getDestinationTasks()); + allTasks.add(event.getOriginTask()); + allTasks.add(event.getDestinationTask()); + for (TMLTask t : allTasks) { + t.removeTMLEvent(event); + } + } + } + + public static RemoveEventConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + RemoveEventConnectionMutation mutation = null; + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.CONNECTION); + if (tokens.length == index+1) { + throw new ParseDiplodocusMutationException("Connection name missing. Expected syntax is remove event connection connectionName."); + } + else { + int indexDot = DiplodocusMutationParser.indexOf(tokens,","); + if (indexDot == -1) { + mutation = new RemoveEventConnectionMutation(tokens[index + 1]); + } else { + if (tokens.length <= indexDot+1){ + throw new ParseDiplodocusMutationException("Port name missing. Expected syntax is remove event connection originPortName," + + "destinationPortName"); + } + mutation = new RemoveEventConnectionMutation(tokens[indexDot-1], tokens[indexDot+1]); + } + } + + mutation.setMutationType("TMLmutation"); + return mutation; + } +} diff --git a/src/main/java/tmltranslator/mutations/RemoveRequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveRequestConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..5cd3b3735ca63a5a0c7ee97f45e8d70e0fa3e885 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RemoveRequestConnectionMutation.java @@ -0,0 +1,110 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLModeling; +import tmltranslator.TMLRequest; +import tmltranslator.TMLTask; + +public class RemoveRequestConnectionMutation extends RequestConnectionMutation { + protected String originPortName; + protected String destinationPortName; + protected RemoveRequestConnectionMutation(String _connectionName) { + super(_connectionName); + } + + protected RemoveRequestConnectionMutation(String _originPortName, String _destinationPortName) { + super(); + originPortName = _originPortName; + destinationPortName = _destinationPortName; + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLRequest request = null; + if (getConnectionName() != null){ + request = getRequest(_tmlModel); + } else if (originPortName != null && destinationPortName != null) { + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + request = _tmlModel.getRequestByName(appName + "__" + destinationPortName); + } + if (request == null){ + if (getConnectionName() != null) { + throw new ApplyDiplodocusMutationException("There is no request named " + getConnectionName() + " in this model."); + } else { + throw new ApplyDiplodocusMutationException("There is no request between ports " + originPortName + " and " + destinationPortName + " in this model."); + } + } else { + _tmlModel.removeRequest(request); + for (TMLTask t : request.getOriginTasks()) { + t.setRequest(null); + } + request.getDestinationTask().setRequest(null); + } + } + + public static RemoveRequestConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + RemoveRequestConnectionMutation mutation = null; + + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + + int index = DiplodocusMutationParser.indexOf(tokens,DiplodocusMutationParser.CONNECTION); + if (tokens.length == index+1) { + throw new ParseDiplodocusMutationException("Connection name missing. Expected syntax is remove event connection connectionName."); + } + else { + int indexDot = DiplodocusMutationParser.indexOf(tokens,","); + if (indexDot == -1) { + mutation = new RemoveRequestConnectionMutation(tokens[index + 1]); + } else { + if (tokens.length <= indexDot+1){ + throw new ParseDiplodocusMutationException("Port name missing. Expected syntax is remove request connection originPortName," + + "destinationPortName"); + } + mutation = new RemoveRequestConnectionMutation(tokens[indexDot-1], tokens[indexDot+1]); + } + } + + mutation.setMutationType("TMLmutation"); + return mutation; + } +} diff --git a/src/main/java/tmltranslator/mutations/RemoveTaskMutation.java b/src/main/java/tmltranslator/mutations/RemoveTaskMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..14e43e6ea03dd35545b01ac43009628f6d96b5b0 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RemoveTaskMutation.java @@ -0,0 +1,73 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLModeling; +import tmltranslator.TMLTask; +import java.util.List; + +public class RemoveTaskMutation extends TaskMutation { + + protected RemoveTaskMutation(String _taskName) { + super(_taskName); + } + + @Override + public void apply(TMLModeling<?> _tmlModel) throws ApplyDiplodocusMutationException { + TMLTask task = getTask(_tmlModel); + if (task == null){ + throw new ApplyDiplodocusMutationException("The task named " + getTaskName() + " does not exist in the current model."); + } + List<TMLTask> taskList = _tmlModel.getTasks(); + taskList.remove(task); + } + + public static RemoveTaskMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + String[] tokens = DiplodocusMutationParser.tokenise(toParse); + int index = DiplodocusMutationParser.indexOf(tokens, DiplodocusMutationParser.TASK); + if (tokens.length == index + 1) { + throw new ParseDiplodocusMutationException("Block name missing. Expected syntax is [remove task taskName]"); + } + String _taskName = tokens[index + 1]; + RemoveTaskMutation mutation = new RemoveTaskMutation(_taskName); + mutation.setMutationType("TMLmutation"); + return mutation; + } + +} diff --git a/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..5419b2ef74fec16a267043e70b7dd7435e3fe41b --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java @@ -0,0 +1,84 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.TMLModeling; +import tmltranslator.TMLRequest; + +public abstract class RequestConnectionMutation extends ConnectionMutation { + protected RequestConnectionMutation(String _originTaskName, String _destinationTaskName, String _connectionName) { + super(_originTaskName, _destinationTaskName, _connectionName); + } + + protected RequestConnectionMutation(){ + super(); + } + + protected RequestConnectionMutation(String _connectionName) { + super(_connectionName); + } + + public TMLRequest getRequest(TMLModeling<?> _tmlModel){ + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + + TMLRequest request = _tmlModel.getRequestByName(getConnectionName()); + if (request != null){ + return request; + } else { + return _tmlModel.getRequestByName(appName + "__" + getConnectionName()); + } + } + + public static RequestConnectionMutation createFromString(String toParse) throws ParseDiplodocusMutationException{ + switch (DiplodocusMutationParser.findMutationToken(toParse)) { + case DiplodocusMutationParser.ADD: + return AddRequestConnectionMutation.createFromString(toParse); + case DiplodocusMutationParser.RM: + case DiplodocusMutationParser.REMOVE: + return RemoveRequestConnectionMutation.createFromString(toParse); + default: + break; + } + return null; + } + +} diff --git a/src/main/java/tmltranslator/mutations/TaskMutation.java b/src/main/java/tmltranslator/mutations/TaskMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..31e4dbfe4e47ec555019e650b4a15581f5bb7ee3 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/TaskMutation.java @@ -0,0 +1,85 @@ +/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + * + * ludovic.apvrille AT enst.fr + * + * This software is a computer program whose purpose is to allow the + * edition of TURTLE analysis, design and deployment diagrams, to + * allow the generation of RT-LOTOS or Java code from this diagram, + * and at last to allow the analysis of formal validation traces + * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + * from INRIA Rhone-Alpes. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. + */ + +package tmltranslator.mutations; + +import tmltranslator.*; + +public abstract class TaskMutation extends DiplodocusMutation { + + private String taskName; + + protected TaskMutation(String _taskName){ + super(); + setTaskName(_taskName); + } + + private void setTaskName(String _taskName){ + taskName = _taskName; + } + + public String getTaskName(){ + return taskName; + } + + protected TMLTask getTask(TMLModeling<?> _tmlModel){ + String appName = ""; + if (_tmlModel.getTasks().size() != 0){ + appName = _tmlModel.getTasks().get(0).getName().split("__")[0]; + } + TMLTask task = _tmlModel.getTMLTaskByName(taskName); + if (task!=null){ + return task; + } + return _tmlModel.getTMLTaskByName(appName + "__" + taskName); + } + + public static TaskMutation createFromString(String toParse) throws ParseDiplodocusMutationException { + switch (DiplodocusMutationParser.findMutationToken(toParse)){ + case DiplodocusMutationParser.ADD: + return AddTaskMutation.createFromString(toParse); + case DiplodocusMutationParser.CLONE: + return CloneTaskMutation.createFromString(toParse); + case DiplodocusMutationParser.RM: + case DiplodocusMutationParser.REMOVE: + return RemoveTaskMutation.createFromString(toParse); + } + return null; + } + +}