use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class ValidateConnectionsSwitch method endsWithReverse.
private boolean endsWithReverse(ConnectionInstance test, ConnectionInstance conni) {
List<ConnectionReference> testRefs = test.getConnectionReferences();
List<ConnectionReference> connRefs = conni.getConnectionReferences();
if (connRefs.size() >= testRefs.size()) {
return false;
}
ListIterator<ConnectionReference> testing = test.getConnectionReferences().listIterator(test.getConnectionReferences().size());
Iterator<ConnectionReference> prefix = connRefs.iterator();
while (prefix.hasNext()) {
ConnectionReference t = testing.previous();
ConnectionReference p = prefix.next();
if (t.getConnection() != p.getConnection()) {
return false;
}
if (!prefix.hasNext()) {
return t.getSource() == p.getDestination();
}
}
return false;
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class ValidateConnectionsSwitch method startsWith.
private boolean startsWith(ConnectionInstance test, ConnectionInstance conni) {
List<ConnectionReference> testRefs = test.getConnectionReferences();
List<ConnectionReference> connRefs = conni.getConnectionReferences();
if (connRefs.size() >= testRefs.size()) {
return false;
}
Iterator<ConnectionReference> testing = testRefs.iterator();
Iterator<ConnectionReference> prefix = connRefs.iterator();
while (prefix.hasNext()) {
ConnectionReference t = testing.next();
ConnectionReference p = prefix.next();
if (t.getConnection() != p.getConnection()) {
return false;
}
if (!prefix.hasNext()) {
return t.getDestination() == p.getDestination();
}
}
return false;
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class ValidateConnectionsSwitch method startsWithReverse.
private boolean startsWithReverse(ConnectionInstance test, ConnectionInstance conni) {
List<ConnectionReference> testRefs = test.getConnectionReferences();
List<ConnectionReference> connRefs = conni.getConnectionReferences();
if (connRefs.size() >= testRefs.size()) {
return false;
}
Iterator<ConnectionReference> testing = testRefs.iterator();
ListIterator<ConnectionReference> prefix = connRefs.listIterator(connRefs.size());
while (prefix.hasPrevious()) {
ConnectionReference t = testing.next();
ConnectionReference p = prefix.previous();
if (t.getConnection() != p.getConnection()) {
return false;
}
if (!prefix.hasPrevious()) {
return t.getDestination() == p.getSource();
}
}
return false;
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class CreateConnectionsSwitch method addConnectionInstance.
protected ConnectionInstance addConnectionInstance(final SystemInstance systemInstance, final ConnectionInfo connInfo, final ConnectionInstanceEnd dstI) {
// with aggregate data ports will be sources/destinations missing
int numConns = connInfo.connections.size();
if (connInfo.sources.size() != numConns || connInfo.destinations.size() != numConns) {
// happens if conn leaves system to aggregate data port
warning(connInfo.container, "Connection from " + connInfo.sources.get(0).getInstanceObjectPath() + " to " + dstI.getInstanceObjectPath() + " could not be instantiated.");
return null;
}
// check for duplicate connection instance
// with arrays we can get duplicates that we don't need
ComponentInstance container = connInfo.container;
List<Connection> conns = connInfo.connections;
if (container == null) {
container = systemInstance;
}
for (ConnectionInstance test : container.getConnectionInstances()) {
// check for duplicates and do not create
if (connInfo.src == test.getSource() && dstI == test.getDestination() && conns.size() == test.getConnectionReferences().size()) {
ListIterator<Connection> i = conns.listIterator();
boolean isDuplicate = true;
for (ConnectionReference ref : test.getConnectionReferences()) {
if (ref.getConnection() != i.next()) {
isDuplicate = false;
break;
}
}
if (!isDuplicate) {
// also test reverse direction
isDuplicate = true;
i = conns.listIterator(conns.size());
for (ConnectionReference ref : test.getConnectionReferences()) {
if (ref.getConnection() != i.previous()) {
isDuplicate = false;
break;
}
}
}
if (isDuplicate) {
return null;
}
}
}
boolean duplicate = false;
// Generate a name for the connection
String containerPath = (connInfo.container != null) ? container.getInstanceObjectPath() : systemInstance.getName();
int len = containerPath.length() + 1;
String srcPath = connInfo.src.getInstanceObjectPath();
StringBuffer sb = new StringBuffer();
String dstPath = "xxx";
int i = (srcPath.startsWith(containerPath)) ? len : 0;
srcPath = srcPath.substring(i);
sb.append(srcPath);
sb.append(" -> ");
if (dstI != null) {
dstPath = dstI.getInstanceObjectPath();
i = (dstPath.startsWith(containerPath)) ? len : 0;
dstPath = dstPath.substring(i);
sb.append(dstPath);
}
ConnectionInstance conni = null;
if (!duplicate) {
conni = connInfo.createConnectionInstance(sb.toString(), dstI);
if (conni == null) {
warning(container, "Connection sequence from " + srcPath + " to " + dstPath + " is only outgoing. No connection instance created.");
return null;
} else {
container.getConnectionInstances().add(conni);
}
fillInModes(conni);
fillInModeTransitions(conni);
}
return conni;
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class CreateEndToEndFlowsSwitch method isValidContinuation.
boolean isValidContinuation(EndToEndFlowInstance etei, ConnectionInstance conni, FlowSpecification fspec) {
/*
* Issue 2009: Check if the connection instance connects to the flow spec. Here we have a weird
* situation. If the subcomponent the flow spec is qualified by is only described by a component type, then
* connection end is going to match up with the beginning of the flow. That's fine. If the component
* has a classifier implementation AND the flow spec has a flow implementation, then everything will also
* fine: either the connection instance is correct and reaches the start of the flow implementation, or it
* is incorrect and doesn't. But we can also have the case that the subcomponent is described by a
* component implementation but the flow spec does not have a flow implementation. In this case we
* still may have the case the connection instance continues into the subcomponent and terminates at a
* subsubcomponent. But the flow spec that we have here will be at the edge of the original subcomponent.
* so the end connection instance will not match up with the start of the flow spec.
*
* So what we really need to do is walk backwards along the connections that make up the connection instance
* until we find one that connects to the flow because as wee the connection instance may "punch through" the
* subcomponent.
*/
final FlowEnd inEnd = fspec.getAllInEnd();
final Context flowCxt = inEnd.getContext();
final Feature flowIn = inEnd.getFeature();
final List<Feature> flowInRefined = flowIn.getAllFeatureRefinements();
final EList<ConnectionReference> connRefs = conni.getConnectionReferences();
int idx = connRefs.size() - 1;
boolean result = false;
while (!result && idx >= 0) {
final Connection conn = connRefs.get(idx).getConnection();
result = isValidContinuationConnectionEnd(flowCxt, flowIn, flowInRefined, conn.getDestination());
if (!result && conn.isBidirectional()) {
result = isValidContinuationConnectionEnd(flowCxt, flowIn, flowInRefined, conn.getSource());
}
idx -= 1;
}
return result;
}
Aggregations