Search in sources :

Example 96 with Feature

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

the class CreateConnectionsSwitch method doModeTransitionConnections.

/**
 * As we are following connection declarations we need to check whether the
 * destination of the connection is named in one of the mode transitions of
 * the component instance that is the destination of the connection being
 * added
 *
 * @param parentci
 *            The component that is the context in which the connections are
 *            declared
 * @param pci
 *            PortConnectionInstance that is being created
 * @param conn
 *            connection being added to the ConnectionInstance
 * @return true if we created a ModetransitionInstance
 */
private boolean doModeTransitionConnections(final ComponentInstance parentci, ConnectionInfo connInfo, Connection conn) {
    boolean didTransition = false;
    if (!(conn instanceof PortConnection || conn instanceof FeatureGroupConnection)) {
        return false;
    }
    ComponentInstance parent = null;
    Context fc = conn.getAllDestinationContext();
    Element connContext = null;
    if (fc instanceof ComponentImplementation || fc instanceof FeatureGroup) {
        // we
        // have
        // an
        // outgoing
        // connection
        parent = (ComponentInstance) parentci.eContainer();
        connContext = parentci.getSubcomponent();
    } else if (fc instanceof Subcomponent) {
        parent = parentci.findSubcomponentInstance((Subcomponent) fc);
        connContext = ((Subcomponent) fc).getAllClassifier();
    }
    if (parent == null) {
        return false;
    }
    EList<ModeTransitionInstance> mtl = parent.getModeTransitionInstances();
    Feature f = (Feature) conn.getAllDestination();
    for (ModeTransitionInstance mti : mtl) {
        ModeTransition mt = mti.getModeTransition();
        Context co = null;
        for (ModeTransitionTrigger trigger : mt.getOwnedTriggers()) {
            TriggerPort tp = trigger.getTriggerPort();
            if (tp instanceof Port) {
                Port o = (Port) tp;
                co = trigger.getContext();
                NamedElement context = co;
                if (context instanceof FeatureGroup) {
                    context = parent.getSubcomponent().getAllClassifier();
                }
                if (f == o && context == connContext) {
                    final ConnectionInstance mtci = addConnectionInstance(parentci.getSystemInstance(), connInfo.convertToModeTransition(), mti);
                    fillInModes(mtci);
                    fillInModeTransitions(mtci);
                    didTransition = true;
                }
            } else {
            // TODO-LW: what if it's a processor port or internal event?
            }
        }
    }
    return didTransition;
}
Also used : Context(org.osate.aadl2.Context) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) ConnectedElement(org.osate.aadl2.ConnectedElement) Port(org.osate.aadl2.Port) TriggerPort(org.osate.aadl2.TriggerPort) TriggerPort(org.osate.aadl2.TriggerPort) ModeTransition(org.osate.aadl2.ModeTransition) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) InternalFeature(org.osate.aadl2.InternalFeature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) Feature(org.osate.aadl2.Feature) PortConnection(org.osate.aadl2.PortConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) NamedElement(org.osate.aadl2.NamedElement) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 97 with Feature

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

the class CreateConnectionsSwitch method doModeTransitionConnections.

// ------------------------------------------------------------------------
// Methods related to mode transition connections
// ------------------------------------------------------------------------
/**
 * handles the situation that a mode transition may name an event port in a
 * thread (or other leaf component instance) and that port is not the
 * destination of a connection instance - it is the start of a connection
 * instance
 *
 * @param ci
 *            ComponentInstance
 * @param fi
 *            FeatureInstance
 * @return true if we created a ModetransitionInstance
 */
private boolean doModeTransitionConnections(ComponentInstance ci, FeatureInstance fi) {
    boolean didTransition = false;
    if (fi.getCategory() == FeatureCategory.EVENT_PORT) {
        Subcomponent sub = ci.getSubcomponent();
        Feature f = fi.getFeature();
        for (ModeTransitionInstance mti : ci.getContainingComponentInstance().getModeTransitionInstances()) {
            for (ModeTransitionTrigger trigger : mti.getModeTransition().getOwnedTriggers()) {
                TriggerPort tp = trigger.getTriggerPort();
                if (tp instanceof Port) {
                    Port p = (Port) tp;
                    Context c = trigger.getContext();
                    if (f == p && c == sub) {
                        addConnectionInstance(ci.getSystemInstance(), ConnectionInfo.newModeTransition(fi), mti);
                        didTransition = true;
                    }
                } else {
                // TODO-LW: what if it's a processor port or internal
                // event?
                }
            }
        }
    }
    return didTransition;
}
Also used : Context(org.osate.aadl2.Context) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) Port(org.osate.aadl2.Port) TriggerPort(org.osate.aadl2.TriggerPort) TriggerPort(org.osate.aadl2.TriggerPort) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) InternalFeature(org.osate.aadl2.InternalFeature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) Feature(org.osate.aadl2.Feature) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger)

Example 98 with Feature

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

the class CreateConnectionsSwitch method findDestinationFeatureInstance.

/**
 * Find the feature instance under FGI, whose name matches the the Feature at the other end
 * We do this by finding the connection declaration that goes down at the other end
 * It is found by matching the FGT name and then retrieving the feature instance matching the name
 * @param connInfo
 * @param fgi
 * @return FeatureInstance
 */
FeatureInstance findDestinationFeatureInstance(ConnectionInfo connInfo, FeatureInstance fgi) {
    List<ConnectionInstanceEnd> srclist = connInfo.sources;
    List<ConnectionInstanceEnd> dstlist = connInfo.destinations;
    ConnectionInstanceEnd target = null;
    for (int i = 0; i < srclist.size(); i++) {
        ConnectionInstanceEnd src = srclist.get(i);
        ConnectionInstanceEnd dst = dstlist.get(i);
        if (target != null && target != src) {
            if (src == target.eContainer()) {
                // we have a feature in a FG
                FeatureInstance targetFI = findFeatureInstance(fgi, target.getName());
                if (targetFI == null) {
                    // name does not match. We may have an inverse of feature group type with its own set of feature names
                    // In this case it is an index based match
                    int idx = dst.eContents().indexOf(target);
                    if (idx >= 0) {
                        targetFI = fgi.getFeatureInstances().get(idx);
                    }
                }
                return targetFI;
            } else {
                target = dst;
            }
        } else {
            target = dst;
        }
    }
    return null;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd)

Example 99 with Feature

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

the class ResolvePrototypeUtil method resolvePrototypeInContainmentPath.

public static PrototypeBinding resolvePrototypeInContainmentPath(Prototype proto, ContainmentPathElement cpe) {
    if (cpe.getNamedElement() instanceof Subcomponent) {
        PrototypeBinding res = resolvePrototype(proto, AadlUtil.getContainingClassifier(cpe.getNamedElement()));
        if (res != null) {
            return res;
        }
    }
    ContainmentPathElement previous = getPrevious(cpe);
    if (previous != null) {
        // find prototype binding in namespace of previous element
        NamedElement ne = previous.getNamedElement();
        if (ne instanceof Subcomponent) {
            // look for prototype in prototype binding of subcomponent declaration
            PrototypeBinding res = resolvePrototype(proto, ne);
            if (res != null) {
                return res;
            } else {
                Subcomponent subcomponent = (Subcomponent) ne;
                while (subcomponent.getSubcomponentType() == null && subcomponent.getRefined() != null) {
                    subcomponent = subcomponent.getRefined();
                }
                ComponentClassifier subcomponentClassifier = null;
                if (subcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                    subcomponentClassifier = (ComponentClassifier) subcomponent.getSubcomponentType();
                } else if (subcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                    subcomponentClassifier = resolveComponentPrototype((ComponentPrototype) subcomponent.getSubcomponentType(), previous);
                }
                if (subcomponentClassifier != null) {
                    return resolvePrototype(proto, subcomponentClassifier);
                }
            }
        } else if (ne instanceof FeatureGroup) {
            FeatureGroup fg = (FeatureGroup) ne;
            while (fg.getFeatureType() == null && fg.getRefined() instanceof FeatureGroup) {
                fg = (FeatureGroup) fg.getRefined();
            }
            FeatureGroupType fgt = null;
            if (fg.getFeatureType() instanceof FeatureGroupType) {
                fgt = (FeatureGroupType) fg.getFeatureType();
            } else if (fg.getFeatureType() instanceof FeatureGroupPrototype) {
                fgt = resolveFeatureGroupPrototype((FeatureGroupPrototype) fg.getFeatureType(), previous);
            }
            if (fgt != null) {
                return resolvePrototype(proto, fgt);
            }
        } else if (ne instanceof Feature) {
        }
    } else {
        // the context is the entity with the property association
        // need to make sure we look in the correct name space
        Classifier cl = null;
        if (AadlUtil.getContainingSubcomponent(cpe) != null) {
            Subcomponent containingSubcomponent = AadlUtil.getContainingSubcomponent(cpe);
            PrototypeBinding res = resolvePrototype(proto, containingSubcomponent);
            if (res != null) {
                return res;
            }
            while (containingSubcomponent.getSubcomponentType() == null && containingSubcomponent.getRefined() != null) {
                containingSubcomponent = containingSubcomponent.getRefined();
            }
            if (containingSubcomponent.getSubcomponentType() instanceof ComponentClassifier) {
                cl = (ComponentClassifier) containingSubcomponent.getSubcomponentType();
            } else if (containingSubcomponent.getSubcomponentType() instanceof ComponentPrototype) {
                cl = resolveComponentPrototype((ComponentPrototype) containingSubcomponent.getSubcomponentType(), AadlUtil.getContainingClassifier(cpe));
            }
        } else if (AadlUtil.getContainingFeatureGroup(cpe) != null) {
            FeatureGroup containingFeatureGroup = AadlUtil.getContainingFeatureGroup(cpe);
            FeatureGroupType typeForContainingFeatureGroup = null;
            while (containingFeatureGroup.getFeatureType() == null && containingFeatureGroup.getRefined() instanceof FeatureGroup) {
                containingFeatureGroup = (FeatureGroup) containingFeatureGroup.getRefined();
            }
            if (containingFeatureGroup.getFeatureType() instanceof FeatureGroupType) {
                typeForContainingFeatureGroup = (FeatureGroupType) containingFeatureGroup.getFeatureType();
            } else if (containingFeatureGroup.getFeatureType() instanceof FeatureGroupPrototype) {
                typeForContainingFeatureGroup = resolveFeatureGroupPrototype((FeatureGroupPrototype) containingFeatureGroup.getFeatureType(), AadlUtil.getContainingClassifier(cpe));
            }
            if (typeForContainingFeatureGroup != null) {
                PrototypeBinding res = resolvePrototype(proto, typeForContainingFeatureGroup);
                if (res != null) {
                    return res;
                }
            }
        } else {
            cl = AadlUtil.getContainingClassifier(cpe);
        }
        PrototypeBinding res = resolvePrototype(proto, cl);
        return res;
    }
    return null;
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroup(org.osate.aadl2.FeatureGroup) Subcomponent(org.osate.aadl2.Subcomponent) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 100 with Feature

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

the class ResolvePrototypeUtil method resolveComponentPrototype.

/**
 * Find the binding for a given component prototype.
 *
 * @param proto the prototype to resolve
 * @param context the context of the feature or subcomponent in which the prototype is used, e.g., a
 *            ComponentType, FeatureGroupType, ComponentImplementation
 * @return The component prototype actual that the prototype resolves to.
 */
public static ComponentClassifier resolveComponentPrototype(ComponentPrototype proto, Element context) {
    ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) resolvePrototype(proto, context);
    if (cpb == null) {
        // look for constraining classifier
        ComponentPrototype refinedPrototype = proto;
        while (refinedPrototype.getConstrainingClassifier() != null && refinedPrototype.getRefined() instanceof ComponentPrototype) {
            refinedPrototype = (ComponentPrototype) refinedPrototype.getRefined();
        }
        if (refinedPrototype.getConstrainingClassifier() != null) {
            return refinedPrototype.getConstrainingClassifier();
        } else {
            return null;
        }
    }
    EList<ComponentPrototypeActual> actuals = cpb.getActuals();
    if (actuals != null && actuals.size() > 0) {
        ComponentPrototypeActual actual = actuals.get(0);
        if (actual.getSubcomponentType() instanceof ComponentClassifier) {
            return (ComponentClassifier) actual.getSubcomponentType();
        } else {
            if (actual.getSubcomponentType() instanceof ComponentPrototype && context instanceof ContainmentPathElement) {
                // resolve recursively if we are in a containment path
                return resolveComponentPrototype((ComponentPrototype) actual.getSubcomponentType(), getPrevious((ContainmentPathElement) context));
            }
        }
    }
    return null;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Aggregations

ArrayList (java.util.ArrayList)100 Feature (org.osate.aadl2.Feature)86 Feature (com.google.cloud.vision.v1.Feature)74 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)71 Image (com.google.cloud.vision.v1.Image)71 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)68 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)68 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)65 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)59 ByteString (com.google.protobuf.ByteString)48 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)47 Classifier (org.osate.aadl2.Classifier)45 NamedElement (org.osate.aadl2.NamedElement)42 ImageSource (com.google.cloud.vision.v1.ImageSource)39 Subcomponent (org.osate.aadl2.Subcomponent)39 FeatureGroup (org.osate.aadl2.FeatureGroup)33 FeatureGroupType (org.osate.aadl2.FeatureGroupType)33 FileInputStream (java.io.FileInputStream)30 ComponentClassifier (org.osate.aadl2.ComponentClassifier)30 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28