Commit 09005ac1 authored by Liana Soima's avatar Liana Soima
Browse files

Relationship between ArgumentElements


Signed-off-by: Liana Soima's avatarLiana Soima <soima@fortiss.org>
Issue-Ref: 4054
parent 07d1148b
package org.fortiss.af3.safetycases.compose;
import static org.fortiss.af3.safetycases.utils.SafetyCasesAnalysisUtils.alreadyExistingConnection;
import static org.fortiss.af3.safetycases.utils.SafetyCasesAnalysisUtils.createsACircleDependency;
import static org.fortiss.af3.safetycases.utils.SafetyCasesModelElementFactory.createInContextOf;
import static org.fortiss.af3.safetycases.utils.SafetyCasesModelElementFactory.createSupportedBy;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.safetycases.model.ArgumentElementBase;
import org.fortiss.af3.safetycases.model.AwayGoal;
import org.fortiss.af3.safetycases.model.ContextualElement;
import org.fortiss.af3.safetycases.model.ExitConnector;
import org.fortiss.af3.safetycases.model.Goal;
import org.fortiss.af3.safetycases.model.InContextOf;
import org.fortiss.af3.safetycases.model.SafetyCasesConnection;
import org.fortiss.af3.safetycases.model.SafetyCasesConnector;
......@@ -98,6 +102,16 @@ public class ConnectionCompositor extends
if(((ExitConnector)source).getOutgoing().size() != 0) {
return false;
}
ArgumentElementBase src = (ArgumentElementBase)source.getGSNElement();
ArgumentElementBase dst = (ArgumentElementBase)target.getGSNElement();
if(createsACircleDependency(src, dst) || alreadyExistingConnection(src, dst)) {
return false;
}
// Two goals cannot be directly connected; a strategy must exist between them.
if((dst instanceof Goal || dst instanceof AwayGoal) &&
(src instanceof Goal || src instanceof AwayGoal)) {
return false;
}
}
return true;
}
......
......@@ -15,7 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.safetycases.utils;
import org.fortiss.af3.safetycases.model.ArgumentElement;
import org.fortiss.af3.safetycases.model.ArgumentElementBase;
import org.fortiss.af3.safetycases.model.ExitConnector;
/**
* This class provides utility methods for analyzing a safety case model.
......@@ -36,14 +38,49 @@ public class SafetyCasesAnalysisUtils {
*/
public static boolean createsACircleDependency(ArgumentElementBase source,
ArgumentElementBase target) {
boolean eq = false;
if(source.equals(target)) {
return true;
}
if(source.getEntryConnectors().size() != 0) {
// Get the element above the current element in the argumentation structure (parent of
// the current element).
ArgumentElementBase parent = (ArgumentElementBase)source.getEntryConnectors().get(0)
.getIncoming().get(0).getSource().getOwner();
boolean createsACircleDependencyRecursion = createsACircleDependency(parent, target);
boolean equal = parent.equals(target);
return equal || createsACircleDependencyRecursion;
for(ExitConnector connection : target.getExitConnectors()) {
boolean equal = false;
if(connection.getOutgoing().size() != 0) {
// Outgoing list of an ExitConnector list can contain a single value.
ArgumentElement argEl =
(ArgumentElement)connection.getOutgoing().get(0).getTarget().getOwner();
equal = argEl.equals(source);
boolean createsACircleDependencyRecursion =
createsACircleDependency(source, argEl);
equal = equal || createsACircleDependencyRecursion;
}
// Makes sure that any ExitConnector doesn't contain a circular dependency.
eq = eq || equal;
}
return eq;
}
return false;
}
/**
* @param source
* The source of the connection.
* @param target
* The target of the connection.
* @return True if the ArgumentElement already contains a connection to the targeted element.
*/
public static boolean alreadyExistingConnection(ArgumentElementBase source,
ArgumentElementBase target) {
for(ExitConnector connection : source.getExitConnectors()) {
if(connection.getOutgoing().size() != 0) {
// Outgoing list of an ExitConnector list can contain a single value.
ArgumentElement argEl =
(ArgumentElement)connection.getOutgoing().get(0).getTarget().getOwner();
if(target.equals(argEl)) {
return true;
}
}
}
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment