Search in sources :

Example 96 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance 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());
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) LinkedList(java.util.LinkedList)

Example 97 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance 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());
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) InstanceObject(org.osate.aadl2.instance.InstanceObject) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) LinkedList(java.util.LinkedList)

Example 98 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class InstantiateModel method resolveConnectionInstancePath.

/**
 * this method resolves the connection instance from the top connection reference down the source or the destination
 * @param newconn Connection Instance whose paths need to be resolved
 * @param topref Connection Reference going across components
 * @param names sequence of names of the path bottom up
 * @param dims Dimensions (bottom up) along the path
 * @param sizes Sizes of each dimension bottom up
 * @param indices The indices to be used for elements that are arrays
 * @param doSource Go down the source path or the destination path
 * @return ConnectionInstanceEnd the ultimate source/destination object (feature instance or component instance)
 */
private ConnectionInstanceEnd resolveConnectionInstancePath(ConnectionInstance newconn, ConnectionReference topref, List<String> names, List<Integer> dims, List<Integer> sizes, List<Long> indices, boolean doSource) {
    // the connection reference to be resolved
    ConnectionReference targetConnRef = topref;
    ConnectionReference outerConnRef = topref;
    ConnectionInstanceEnd resolutionContext = newconn.getContainingComponentInstance();
    // we have to process the indices backwards since we go top down
    // offset starts with the last element of the indices array
    int offset = indices.size() - 1;
    int count = dims.size() - 1;
    ConnectionInstanceEnd result = null;
    for (int nameidx = names.size() - 1; nameidx >= 0; nameidx--) {
        String name = names.get(nameidx);
        List<InstanceObject> owned = new ArrayList<InstanceObject>();
        int dim = dims.get(count);
        if (resolutionContext instanceof ComponentInstance) {
            // if nextConnRef is null it is because we are going to look up feature instances inside the last component instance
            owned.addAll(((ComponentInstance) resolutionContext).getComponentInstances());
            owned.addAll(((ComponentInstance) resolutionContext).getFeatureInstances());
        } else if (resolutionContext instanceof FeatureInstance) {
            owned.addAll(((FeatureInstance) resolutionContext).getFeatureInstances());
        }
        if (dim == 0) {
            resolutionContext = (ConnectionInstanceEnd) AadlUtil.findNamedElementInList(owned, name);
        // targetConnRef could be null once we are at the end and will resolve the feature name(s)
        // if (targetConnRef != null&& resolutionContext instanceof ComponentInstance){
        // result = resolveConnectionReference(targetConnRef, outerConnRef,(ComponentInstance)resolutionContext, doSource) ;
        // } else {
        // // the resolved feature has been found
        // result = resolutionContext;
        // }
        } else {
            // find the object based on its name and indices
            outer: for (InstanceObject io : owned) {
                if (io.getName().equalsIgnoreCase(name)) {
                    try {
                        if (io instanceof ComponentInstance) {
                            // we need to deal with possibly more than one index
                            int d = dim - 1;
                            for (long i : ((ComponentInstance) io).getIndices()) {
                                if (i != indices.get(offset - d)) {
                                    continue outer;
                                }
                                d--;
                            }
                        } else {
                            // we have a feature that may have an index or zero index
                            if (((FeatureInstance) io).getIndex() != indices.get(offset)) {
                                continue outer;
                            }
                        }
                    } catch (IndexOutOfBoundsException e) {
                        errManager.warning(newconn, "Too few indices for connection end, using fist array element");
                    }
                    resolutionContext = (ConnectionInstanceEnd) io;
                    break;
                }
            }
        }
        if (resolutionContext == null) {
            return null;
        }
        // resolve the connref
        if (targetConnRef != null && resolutionContext instanceof ComponentInstance) {
            int dimfeature = dims.get(0);
            int dimfg = 0;
            if (dims.size() > 1) {
                dimfg = dims.get(1);
            }
            result = resolveConnectionReference(targetConnRef, outerConnRef, (ComponentInstance) resolutionContext, doSource, dimfeature == 0 ? 0 : indices.get(0), dimfg == 0 ? 0 : (dimfeature == 0 ? indices.get(0) : indices.get(1)));
        } else {
            // the resolved feature has been found
            result = resolutionContext;
        }
        if (doSource) {
            if (targetConnRef != null && result instanceof FeatureInstance) {
                targetConnRef.setSource(result);
            }
            outerConnRef = targetConnRef;
            targetConnRef = Aadl2InstanceUtil.getPreviousConnectionReference(newconn, outerConnRef);
        } else {
            if (targetConnRef != null && result instanceof FeatureInstance) {
                targetConnRef.setDestination(result);
            }
            outerConnRef = targetConnRef;
            targetConnRef = Aadl2InstanceUtil.getNextConnectionReference(newconn, outerConnRef);
        }
        // reduce the offset by the processed indices of the element we just looked up
        offset -= dim;
        // reduce the index into the dims array to get the next number of dimensions
        count--;
    // now we need to update the connref pointers
    }
    return result;
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ArrayList(java.util.ArrayList) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 99 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class SCProperties method retrieveSCProperty.

public PropertyAssociation retrieveSCProperty(ConnectionInstance conni, Property prop, Connection conn) {
    PropertyAssociation result = null;
    while (conn != null && result == null) {
        result = get(get(scProps, conni), prop).get(conn);
        conn = conn.getRefined();
    }
    return result;
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation)

Example 100 with ConnectionInstance

use of org.osate.aadl2.instance.ConnectionInstance in project osate2 by osate.

the class ValidateConnectionsSwitch method endsWith.

private boolean endsWith(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());
    ListIterator<ConnectionReference> prefix = connRefs.listIterator(connRefs.size());
    while (prefix.hasPrevious()) {
        ConnectionReference t = testing.previous();
        ConnectionReference p = prefix.previous();
        if (t.getConnection() != p.getConnection()) {
            return false;
        }
        if (!prefix.hasPrevious()) {
            return t.getSource() == p.getSource();
        }
    }
    return false;
}
Also used : ConnectionReference(org.osate.aadl2.instance.ConnectionReference)

Aggregations

ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)71 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)64 ConnectionReference (org.osate.aadl2.instance.ConnectionReference)32 ConnectionInstanceEnd (org.osate.aadl2.instance.ConnectionInstanceEnd)28 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)25 Classifier (org.osate.aadl2.Classifier)22 InstanceObject (org.osate.aadl2.instance.InstanceObject)21 Connection (org.osate.aadl2.Connection)16 ArrayList (java.util.ArrayList)15 Element (org.osate.aadl2.Element)15 NamedElement (org.osate.aadl2.NamedElement)13 PropertyExpression (org.osate.aadl2.PropertyExpression)13 SystemInstance (org.osate.aadl2.instance.SystemInstance)13 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)13 ComponentClassifier (org.osate.aadl2.ComponentClassifier)12 ComponentImplementation (org.osate.aadl2.ComponentImplementation)10 ListValue (org.osate.aadl2.ListValue)10 BasicEList (org.eclipse.emf.common.util.BasicEList)9 Feature (org.osate.aadl2.Feature)9 EndToEndFlowInstance (org.osate.aadl2.instance.EndToEndFlowInstance)9