Search in sources :

Example 21 with SubprogramSubcomponent

use of org.osate.aadl2.SubprogramSubcomponent in project osate2 by osate.

the class CreateAadlConnectionPaletteCommand method getConnectedElementForBusinessObjectContext.

/**
 * Builds a ConnectedElement for the specific business object.
 * @param boc
 * @param connectionType
 * @param disableNesting
 * @param limitBoc is an optional business object context which limits the path of the connected element
 * @return
 */
private ConnectedElement getConnectedElementForBusinessObjectContext(final BusinessObjectContext boc, final EClass connectionType, final boolean disableNesting, final BusinessObjectContext limitBoc) {
    final Object bo = boc.getBusinessObject();
    if (!(bo instanceof ConnectionEnd)) {
        return null;
    }
    // Build a list of business objects which make up the path to the connection end.
    boolean pathIncludesSubcomponent = false;
    final LinkedList<Object> path = new LinkedList<>();
    for (BusinessObjectContext tmp = boc; tmp != null && tmp != limitBoc && tmp.getBusinessObject() != null; tmp = tmp.getParent()) {
        if (tmp.getBusinessObject() instanceof ComponentImplementation || tmp.getBusinessObject() instanceof SubprogramCallSequence) {
            break;
        } else if (tmp.getBusinessObject() instanceof Subcomponent) {
            if (pathIncludesSubcomponent) {
                // If two subcomponents are encountered then the element is nested and is inaccessible.
                return null;
            }
            pathIncludesSubcomponent = true;
        }
        path.add(0, tmp.getBusinessObject());
    }
    if (path.size() == 0) {
        return null;
    }
    final Object[] pathObjects = path.toArray();
    final Object firstBo = pathObjects[0];
    final boolean allowNested = !disableNesting && connectionType == Aadl2Package.eINSTANCE.getFeatureConnection();
    // If nesting is not allowed, then the number of objects must be at most 2.
    if (!allowNested && pathObjects.length > 2) {
        return null;
    }
    final ConnectedElement ce = AgeAadlUtil.getAadl2Factory().createConnectedElement();
    // Add the context
    int i = 0;
    if (pathObjects.length > 1) {
        if (!(firstBo instanceof Context)) {
            return null;
        }
        ce.setContext((Context) firstBo);
        i++;
    }
    // Add the first connection end
    if (!(pathObjects[i] instanceof ConnectionEnd)) {
        return null;
    }
    ce.setConnectionEnd((ConnectionEnd) pathObjects[i]);
    i++;
    // Add other segments
    ConnectedElement tmp = ce;
    for (; i < pathObjects.length; i++) {
        tmp = tmp.createNext();
        if (!(pathObjects[i] instanceof ConnectionEnd)) {
            return null;
        }
        tmp.setConnectionEnd((ConnectionEnd) pathObjects[i]);
    }
    // SubprogramSubcomponent elements are never a valid context
    if (ce.getContext() instanceof SubprogramSubcomponent) {
        return null;
    }
    return ce;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) BusinessObjectContext(org.osate.ge.BusinessObjectContext) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) Context(org.osate.aadl2.Context) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) LinkedList(java.util.LinkedList) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) FeatureGroupConnectionEnd(org.osate.aadl2.FeatureGroupConnectionEnd) PortConnectionEnd(org.osate.aadl2.PortConnectionEnd) FeatureConnectionEnd(org.osate.aadl2.FeatureConnectionEnd) ConnectionEnd(org.osate.aadl2.ConnectionEnd) AccessConnectionEnd(org.osate.aadl2.AccessConnectionEnd) ParameterConnectionEnd(org.osate.aadl2.ParameterConnectionEnd) ConnectedElement(org.osate.aadl2.ConnectedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)18 FeatureGroup (org.osate.aadl2.FeatureGroup)6 SubprogramAccess (org.osate.aadl2.SubprogramAccess)6 SubprogramGroupSubcomponent (org.osate.aadl2.SubprogramGroupSubcomponent)5 AbstractSubcomponent (org.osate.aadl2.AbstractSubcomponent)4 ComponentClassifier (org.osate.aadl2.ComponentClassifier)4 Subcomponent (org.osate.aadl2.Subcomponent)4 SubprogramGroupAccess (org.osate.aadl2.SubprogramGroupAccess)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EList (org.eclipse.emf.common.util.EList)3 AadlPackage (org.osate.aadl2.AadlPackage)3 Classifier (org.osate.aadl2.Classifier)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 ComponentPrototype (org.osate.aadl2.ComponentPrototype)3 DataSubcomponent (org.osate.aadl2.DataSubcomponent)3 Feature (org.osate.aadl2.Feature)3 FeatureGroupType (org.osate.aadl2.FeatureGroupType)3 NamedElement (org.osate.aadl2.NamedElement)3 ThreadSubcomponent (org.osate.aadl2.ThreadSubcomponent)3