diff --git a/src/main/java/tmltranslator/TMLModeling.java b/src/main/java/tmltranslator/TMLModeling.java index e53e372ec200bc6b9c334c8c658e543cd237043e..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); } diff --git a/src/main/java/tmltranslator/mutations/ConnectionMutation.java b/src/main/java/tmltranslator/mutations/ConnectionMutation.java index 46d36113b9ec4d9b5e4a0a7e4648c3f4b597d3a3..2da73fac559c418ad5f522068ed444be2889d01b 100644 --- a/src/main/java/tmltranslator/mutations/ConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/ConnectionMutation.java @@ -59,6 +59,10 @@ public abstract class ConnectionMutation extends DiplodocusMutation{ setConnectionName(_connectionName); } + protected ConnectionMutation(){ + super(); + } + public void setConnectionName(String _connectionName){ connectionName = _connectionName; } @@ -133,6 +137,8 @@ public abstract class ConnectionMutation extends DiplodocusMutation{ return DataConnectionMutation.createFromString(toParse); case "EVENT": return EventConnectionMutation.createFromString(toParse); + case "REQUEST": + return RequestConnectionMutation.createFromString(toParse); default: break; } diff --git a/src/main/java/tmltranslator/mutations/DataConnectionMutation.java b/src/main/java/tmltranslator/mutations/DataConnectionMutation.java index 5bf995aa9bc6e1e32837b804724d208ff54d5fa7..1ff289701db52d35197e8c1052a1d1a2d78d1f2f 100644 --- a/src/main/java/tmltranslator/mutations/DataConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/DataConnectionMutation.java @@ -53,6 +53,10 @@ public abstract class DataConnectionMutation extends ConnectionMutation{ super(_connectionName); } + protected DataConnectionMutation(){ + super(); + } + /*public void setBRBW(boolean b){ BRBW = b; } diff --git a/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java b/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java index 562d867ce3f1a09c16a8f031e1ee0dfa2e8467bc..5217f0596f2bc4029912625b926025d2fe34e8a5 100644 --- a/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java +++ b/src/main/java/tmltranslator/mutations/DiplodocusMutationParser.java @@ -46,7 +46,7 @@ public interface DiplodocusMutationParser { /*public static final String[] ELEMENT_TOKENS = {"ATTRIBUTE", "METHOD", "INPUT", "OUTPUT", "STATE", "ACTION", "RANDOM", "SET", "RESET", "EXPIRE" , "TRANSITION", "CONNECTION", "LINK", "SIGNAL", "BLOCK"};*/ public static final String[] ELEMENT_TOKENS = {"TASK", "CONNECTION", "PORT", "ATTRIBUTE"}; - public static final String[] CONNECTION_TYPE_TOKEN = {"DATA", "EVENT"}; + 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", "LATENCY", "AT", "BETWEEN"}; public static final String[] PUBLIC_TOKENS = {"PUBLIC", "PRIVATE"}; diff --git a/src/main/java/tmltranslator/mutations/EventConnectionMutation.java b/src/main/java/tmltranslator/mutations/EventConnectionMutation.java index abe3a7d1c813873f6576a02945c4dc1c3a15df5c..6ef5eaee514b054a849351543659e7e41ec8808d 100644 --- a/src/main/java/tmltranslator/mutations/EventConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/EventConnectionMutation.java @@ -53,6 +53,10 @@ public abstract class EventConnectionMutation extends ConnectionMutation{ super(_connectionName); } + protected EventConnectionMutation(){ + super(); + } + /*public void setInfinite(boolean b){ infinite = b; } diff --git a/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java index 51ab7f70af3175677b7a68209eecbe94684c699d..bf711dc3bb0acc6dd59583f13880de6afa72456a 100644 --- a/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/RemoveDataConnectionMutation.java @@ -42,26 +42,47 @@ 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 = getDataConnection(_tmlModel); + 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) { - throw new ApplyDiplodocusMutationException("There is no channel named " + getConnectionName() + " in this model."); + 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); - TMLTask originTask = channel.getOriginTask(); - TMLTask destinationTask = channel.getDestinationTask(); - originTask.removeTMLChannel(channel); - originTask.removeReadTMLChannel(channel); - originTask.removeWriteTMLChannel(channel); - destinationTask.removeTMLChannel(channel); - destinationTask.removeReadTMLChannel(channel); - destinationTask.removeWriteTMLChannel(channel); + ArrayList<TMLTask> allTasks = channel.getAllTasks(); + for (TMLTask t : allTasks) { + t.removeTMLChannel(channel); + t.removeReadTMLChannel(channel); + t.removeReadTMLChannel(channel); + } } } @@ -74,7 +95,16 @@ public class RemoveDataConnectionMutation extends DataConnectionMutation{ throw new ParseDiplodocusMutationException("Connection name missing. Expected syntax is remove data connection connectionName."); } else { - mutation = new RemoveDataConnectionMutation(tokens[index+1]); + 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"); diff --git a/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java index a8d6bee51325f658e225ca7bcf6f0f429939211b..413b5c70d992159d10360742d208ad161f216cea 100644 --- a/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/RemoveEventConnectionMutation.java @@ -40,21 +40,49 @@ 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 = getEventConnectionMutation(_tmlModel); + 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){ - throw new ApplyDiplodocusMutationException("There is no event named " + getConnectionName() + " in this model."); + 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); - event.getOriginTask().removeTMLEvent(event); - event.getDestinationTask().removeTMLEvent(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); + } } } @@ -67,7 +95,16 @@ public class RemoveEventConnectionMutation extends EventConnectionMutation{ throw new ParseDiplodocusMutationException("Connection name missing. Expected syntax is remove event connection connectionName."); } else { - mutation = new RemoveEventConnectionMutation(tokens[index+1]); + 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"); diff --git a/src/main/java/tmltranslator/mutations/RemoveRequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/RemoveRequestConnectionMutation.java new file mode 100644 index 0000000000000000000000000000000000000000..192f36b64915803de01f60b6f7bc744509eded12 --- /dev/null +++ b/src/main/java/tmltranslator/mutations/RemoveRequestConnectionMutation.java @@ -0,0 +1,72 @@ +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,"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/RequestConnectionMutation.java b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java index bedbd31b4888bc1428588136330583b057d45c13..77f0e6ae0530795f7f7150f2457e25fd6a161ef8 100644 --- a/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java +++ b/src/main/java/tmltranslator/mutations/RequestConnectionMutation.java @@ -40,6 +40,7 @@ package tmltranslator.mutations; import tmltranslator.TMLModeling; import tmltranslator.TMLRequest; +import tmltranslator.TMLTask; import java.util.List; @@ -48,6 +49,10 @@ public abstract class RequestConnectionMutation extends ConnectionMutation { super(_originTaskName, _destinationTaskName, _connectionName); } + protected RequestConnectionMutation(){ + super(); + } + protected RequestConnectionMutation(String _connectionName) { super(_connectionName); } @@ -62,7 +67,7 @@ public abstract class RequestConnectionMutation extends ConnectionMutation { if (request != null){ return request; } else { - return _tmlModel.getRequestByName(appName + "__" + getConnectionName() + "__" + appName + "__" + getConnectionName()); + return _tmlModel.getRequestByName(appName + "__" + getConnectionName()); } } @@ -71,6 +76,7 @@ public abstract class RequestConnectionMutation extends ConnectionMutation { case "ADD": case "RM": case "REMOVE": + return RemoveRequestConnectionMutation.createFromString(toParse); default: break; }