use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class ConnectionInfo method createConnectionInstance.
public ConnectionInstance createConnectionInstance(final String name, final ConnectionInstanceEnd dst) {
ConnectionInstance conni = InstanceFactory.eINSTANCE.createConnectionInstance();
conni.setName(name);
Iterator<Connection> connIter = connections.iterator();
Iterator<ComponentInstance> ctxIter = contexts.iterator();
// Iterator<ConnectionInstanceEnd> srcIter = sources.iterator();
Iterator<ConnectionInstanceEnd> dstIter = destinations.iterator();
Iterator<Boolean> oppIter = opposites.iterator();
ConnectionInstanceEnd dosrc = src;
ConnectionInstanceEnd dodst = null;
while (connIter.hasNext() && dstIter.hasNext()) {
ConnectionReference connRef = conni.createConnectionReference();
connRef.setConnection(connIter.next());
connRef.setContext(ctxIter.next());
connRef.setSource(dosrc);
dodst = resolveFeatureInstance(dosrc, dstIter.next());
connRef.setDestination(dodst);
dosrc = dodst;
connRef.setReverse(oppIter.next());
}
conni.setSource(src);
conni.setDestination(dst);
conni.setComplete(across);
kind = getKind(dst);
conni.setKind(kind);
return conni;
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class CreateConnectionsSwitch method generateModeCombinations.
private void generateModeCombinations(ConnectionInstance conni, ListIterator<ConnectionReference> refIter, List<ModeInstance> mis) {
if (!refIter.hasNext()) {
// add SOMs based on mis
SystemInstance si = (SystemInstance) conni.getElementRoot();
List<SystemOperationMode> somList = si.getSystemOperationModesFor(mis);
// check if all parts of the connection exist
outer: for (SystemOperationMode som : somList) {
if (conni.getSource().isActive(som) && conni.getDestination().isActive(som)) {
for (ConnectionReference cr : conni.getConnectionReferences()) {
if (!cr.getContext().isActive(som)) {
continue outer;
}
}
conni.getInSystemOperationModes().add(som);
}
}
} else {
ConnectionReference connRef = refIter.next();
Connection conn = connRef.getConnection();
ComponentInstance ci = connRef.getContext();
EList<Mode> connModes = conn.getAllInModes();
List<ModeInstance> nextMis = null;
if (connModes.isEmpty()) {
nextMis = getComponentModes(ci);
} else {
nextMis = connModes.stream().map(ci::findModeInstance).collect(Collectors.toList());
}
if (nextMis != null) {
for (ModeInstance mi : nextMis) {
mis.add(mi);
generateModeCombinations(conni, refIter, mis);
mis.remove(mi);
}
} else {
generateModeCombinations(conni, refIter, mis);
}
refIter.previous();
}
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class InstantiateModel method createNewConnection.
/**
* create a copy of the connection instance with the specified indices for the source and the destination
* @param conni
* @param srcIndices
* @param dstIndices
*/
private void createNewConnection(ConnectionInstance conni, List<Long> srcIndices, List<Long> dstIndices) {
LinkedList<String> names = new LinkedList<String>();
LinkedList<Integer> dims = new LinkedList<Integer>();
LinkedList<Integer> sizes = new LinkedList<Integer>();
ConnectionInstance newConn = EcoreUtil.copy(conni);
conni.getContainingComponentInstance().getConnectionInstances().add(newConn);
ConnectionReference topConnRef = Aadl2InstanceUtil.getTopConnectionReference(newConn);
analyzePath(conni.getContainingComponentInstance(), conni.getSource(), names, dims, sizes);
if (srcIndices.size() != sizes.size() && // filter out one side being an element without index (array of 1) (many to one mapping)
!(sizes.size() == 0 && dstIndices.size() == 1)) {
errManager.error(newConn, "Source indices " + srcIndices + " do not match source dimension " + sizes.size());
}
InstanceObject src = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, srcIndices, true);
names.clear();
dims.clear();
sizes.clear();
analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), names, dims, sizes);
if (dstIndices.size() != sizes.size() && // filter out one side being an element without index (array of 1) (many to one mapping)
!(sizes.size() == 0 && dstIndices.size() == 1)) {
errManager.error(newConn, "For " + newConn.getConnectionReferences().get(0).getFullName() + " : " + newConn.getFullName() + ", destination indices " + dstIndices + " do not match destination dimension " + sizes.size());
}
InstanceObject dst = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, dstIndices, false);
if (src == null) {
errManager.error(newConn, "Connection source not found");
}
if (dst == null) {
errManager.error(newConn, "Connection destination not found");
}
String containerPath = conni.getContainingComponentInstance().getInstanceObjectPath();
int len = containerPath.length() + 1;
String srcPath = (src != null) ? src.getInstanceObjectPath() : "Source end not found";
StringBuffer sb = new StringBuffer();
int i = (srcPath.startsWith(containerPath)) ? len : 0;
sb.append(srcPath.substring(i));
sb.append(" --> ");
String dstPath = (dst != null) ? dst.getInstanceObjectPath() : "Destination end not found";
i = (dstPath.startsWith(containerPath)) ? len : 0;
sb.append(dstPath.substring(i));
ConnectionInstance duplicate = (ConnectionInstance) AadlUtil.findNamedElementInList(conni.getContainingComponentInstance().getConnectionInstances(), sb.toString());
if (duplicate != null && duplicate != conni) {
// conni will be removed later
errManager.warning(newConn, "There is already another connection between the same endpoints");
}
newConn.setSource((ConnectionInstanceEnd) src);
newConn.setDestination((ConnectionInstanceEnd) dst);
newConn.setName(sb.toString());
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class InstantiateModel method resolveConnectionReference.
/**
* resolve downgoing source or destination of the connection reference.
* we do so by re-retrieving the feature instance based on the existing connection instance end name.
* If the connection reference is up or down going we also fill in the other end.
* @param targetConnRef
* @param result
* @param name
* @param doSource
*/
private ConnectionInstanceEnd resolveConnectionReference(ConnectionReference targetConnRef, ConnectionReference outerConnRef, ComponentInstance target, boolean doSource, long idx, long fgidx) {
ConnectionInstanceEnd src = targetConnRef.getSource();
ConnectionInstanceEnd dst = targetConnRef.getDestination();
if (doSource) {
if (target.getName().equalsIgnoreCase(src.getName())) {
// we point to a component instance, such as a bus or data component in an access connection
targetConnRef.setSource(target);
} else if (src instanceof FeatureInstance) {
// re-resolve the source feature
ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), src.getName(), idx);
if (found == null) {
Element parent = src.getOwner();
if (parent instanceof FeatureInstance) {
found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
}
}
if (found != null) {
targetConnRef.setSource(found);
}
}
// now we need to resolve the upper end (destination)
if (targetConnRef != outerConnRef) {
// we need to fix the context of the connection reference
ConnectionInstanceEnd outerSrc = outerConnRef.getSource();
targetConnRef.setContext(outerSrc.getComponentInstance());
// we are not at the top so we fix up the upper end of the connection reference
if ((dst.getOwner() instanceof ComponentInstance) && dst.getName().equalsIgnoreCase(outerSrc.getName())) {
targetConnRef.setDestination(outerSrc);
} else {
// the outer source points to the enclosing feature group. reresolve the feature in this feature group
ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(((FeatureInstance) outerSrc).getFeatureInstances(), dst.getName(), idx);
if (found == null) {
Element parent = dst.getOwner();
if (parent instanceof FeatureInstance) {
found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
}
}
if (found != null) {
targetConnRef.setDestination(found);
}
}
}
return targetConnRef.getSource();
} else {
if (target.getName().equalsIgnoreCase(dst.getName())) {
// we point to a component instance, such as a bus or data component in an access connection
targetConnRef.setDestination(target);
} else if (dst instanceof FeatureInstance) {
// re-resolve the source feature
ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), dst.getName(), idx);
if (found == null) {
Element parent = dst.getOwner();
if (parent instanceof FeatureInstance) {
found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
}
}
if (found != null) {
targetConnRef.setDestination(found);
}
}
// now we need to resolve the upper end (source)
if ((outerConnRef != null) && (targetConnRef != outerConnRef)) {
// we need to fix the context of the connection reference
ConnectionInstanceEnd outerDst = outerConnRef.getDestination();
targetConnRef.setContext(outerDst.getComponentInstance());
// we are not at the top so we fix up the upper end of the connection reference
if ((src.getOwner() instanceof ComponentInstance) && src.getName().equalsIgnoreCase(outerDst.getName())) {
targetConnRef.setSource(outerDst);
} else {
// the outer source points to the enclosing feature group. reresolve the feature in this feature group
ConnectionInstanceEnd found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(((FeatureInstance) outerDst).getFeatureInstances(), src.getName(), idx);
if (found == null) {
Element parent = src.getOwner();
if (parent instanceof FeatureInstance) {
found = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(target.getFeatureInstances(), ((FeatureInstance) parent).getName(), fgidx);
}
}
if (found != null) {
targetConnRef.setSource(found);
}
}
}
return targetConnRef.getDestination();
}
}
use of org.osate.aadl2.instance.ConnectionReference in project osate2 by osate.
the class InstantiateModel method createNewConnection.
/**
* create a copy of the connection instance with the specified indices for the source and the destination
* @param conni
* @param srcIndices
* @param dstIndices
* @return
*/
private void createNewConnection(ConnectionInstance conni, ComponentInstance targetComponent) {
LinkedList<Long> indices = new LinkedList<Long>();
LinkedList<String> names = new LinkedList<String>();
LinkedList<Integer> dims = new LinkedList<Integer>();
LinkedList<Integer> sizes = new LinkedList<Integer>();
ConnectionInstance newConn = EcoreUtil.copy(conni);
targetComponent.getConnectionInstances().add(newConn);
ConnectionReference topConnRef = Aadl2InstanceUtil.getTopConnectionReference(newConn);
analyzePath(conni.getContainingComponentInstance(), conni.getSource(), names, dims, sizes, indices);
InstanceObject src = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, indices, true);
names.clear();
dims.clear();
sizes.clear();
indices.clear();
analyzePath(conni.getContainingComponentInstance(), conni.getDestination(), names, dims, sizes, indices);
InstanceObject dst = resolveConnectionInstancePath(newConn, topConnRef, names, dims, sizes, indices, false);
if (src == null) {
errManager.error(newConn, "Connection source not found");
}
if (dst == null) {
errManager.error(newConn, "Connection destination not found");
}
String containerPath = targetComponent.getInstanceObjectPath();
int len = containerPath.length() + 1;
String srcPath = (src != null) ? src.getInstanceObjectPath() : "Source end not found";
StringBuffer sb = new StringBuffer();
int i = (srcPath.startsWith(containerPath)) ? len : 0;
sb.append(srcPath.substring(i));
sb.append(" --> ");
String dstPath = (dst != null) ? dst.getInstanceObjectPath() : "Destination end not found";
i = (dstPath.startsWith(containerPath)) ? len : 0;
sb.append(dstPath.substring(i));
newConn.setSource((ConnectionInstanceEnd) src);
newConn.setDestination((ConnectionInstanceEnd) dst);
newConn.setName(sb.toString());
}
Aggregations