Search in sources :

Example 1 with InstantiatedClassifier

use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.

the class InstanceUtil method resolveComponentPrototype.

/**
 * Find the binding for a given component prototype.
 *
 * @param proto the prototype to resolve
 * @param context the context in which the prototype is used, e.g., a
 *            subcomponent instance
 * @param classifierCache an optional cache of known instantiated
 *            classifiers, may be null
 * @return The component prototype actual that the prototype resolves to.
 */
public static ComponentPrototypeActual resolveComponentPrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    ComponentPrototypeActual cpa = null;
    ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) resolvePrototype(proto, context, classifierCache);
    if (cpb == null) {
        // cannot resolve
        return null;
    }
    EList<ComponentPrototypeActual> actuals = cpb.getActuals();
    if (actuals != null && actuals.size() > 0) {
        ComponentPrototypeActual actual = actuals.get(0);
        if (actual.getSubcomponentType() instanceof ComponentClassifier) {
            cpa = actual;
        } else {
            // resolve recursively
            cpa = resolveComponentPrototype((ComponentPrototype) actual.getSubcomponentType(), context.getContainingComponentInstance(), classifierCache);
        }
    }
    return cpa;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 2 with InstantiatedClassifier

use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.

the class InstanceUtil method resolveFeatureGroupPrototype.

/**
 * Find the binding for a given feature group prototype.
 *
 * @param proto the prototype to resolve
 * @param context the context in which the prototype is used, e.g., a
 *            subcomponent instance
 * @param classifierCache an optional cache of known instantiated
 *            classifiers, may be null
 * @return The feature group prototype actual the prototype is bound to.
 */
public static FeatureGroupPrototypeActual resolveFeatureGroupPrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    FeatureGroupPrototypeActual result = null;
    FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) resolvePrototype(proto, context, classifierCache);
    if (fgpb == null) {
        // cannot resolve
        return null;
    }
    FeatureGroupPrototypeActual actual = fgpb.getActual();
    if (actual.getFeatureType() instanceof FeatureGroupType) {
        result = actual;
    } else {
        // resolve recursively
        result = resolveFeatureGroupPrototype((FeatureGroupPrototype) actual.getFeatureType(), context.getContainingComponentInstance(), classifierCache);
    }
    return result;
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) FeatureGroupType(org.osate.aadl2.FeatureGroupType) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual)

Example 3 with InstantiatedClassifier

use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.

the class PropertyImpl method getPropertyValueFromDeclarativeModel.

protected void getPropertyValueFromDeclarativeModel(EvaluationContext ctx, PropertyAcc pas) throws InvalidModelException {
    InstanceObject io = ctx.getInstanceObject();
    List<? extends NamedElement> compDecls = io.getInstantiatedObjects();
    if (compDecls == null) {
    }
    // Here we assume compDecls is empty or has only one element
    if (!compDecls.isEmpty()) {
        NamedElement compDecl = compDecls.get(0);
        if (compDecl == null) {
            return;
        }
        InstantiatedClassifier ic = ctx.getClassifierCache().get(io);
        Classifier cl = (ic == null) ? null : ic.getClassifier();
        if (compDecl instanceof Subcomponent) {
            ((SubcomponentImpl) compDecl).getPropertyValue(this, pas, cl, false);
        } else if (compDecl instanceof FeatureGroup) {
            ((FeatureGroupImpl) compDecl).getPropertyValue(this, pas, cl, false);
        } else if (compDecl instanceof Feature) {
            ((FeatureImpl) compDecl).getPropertyValue(this, pas, cl, false);
        } else if (compDecl instanceof PortConnection) {
            ((PortConnectionImpl) compDecl).getPropertyValue(this, pas);
        } else {
            compDecl.getPropertyValueInternal(this, pas, true);
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureGroup(org.osate.aadl2.FeatureGroup) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Subcomponent(org.osate.aadl2.Subcomponent) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Classifier(org.osate.aadl2.Classifier) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) PortConnection(org.osate.aadl2.PortConnection)

Example 4 with InstantiatedClassifier

use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.

the class InstanceUtil method resolveFeaturePrototype.

/**
 * Find the binding for a given feature prototype.
 *
 * @param proto the prototype to resolve
 * @param context the context in which the prototype is used, e.g., a
 *            subcomponent instance
 * @param classifierCache an optional cache of known instantiated
 *            classifiers, may be null
 * @return The actual feature this prototype resolves to.
 */
public static FeaturePrototypeActual resolveFeaturePrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    FeaturePrototypeActual result = null;
    FeaturePrototypeBinding fpb = (FeaturePrototypeBinding) resolvePrototype(proto, context, classifierCache);
    if (fpb == null) {
        return null;
    }
    result = fpb.getActual();
    if (result instanceof FeaturePrototypeReference) {
        // resolve recursively
        result = resolveFeaturePrototype(((FeaturePrototypeReference) fpb.getActual()).getPrototype(), context.getContainingComponentInstance(), classifierCache);
    }
    return result;
}
Also used : FeaturePrototypeActual(org.osate.aadl2.FeaturePrototypeActual) FeaturePrototypeReference(org.osate.aadl2.FeaturePrototypeReference) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding)

Example 5 with InstantiatedClassifier

use of org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier in project osate2 by osate.

the class InstanceUtil method getInstantiatedClassifier.

/**
 * Get the component or feature group classifier that is instantiated by an
 * instance object. Resolve prototypes if needed.
 *
 * @param iobj the instance object
 * @param index the index of the instance object in an array
 * @param classifierCache an optional cache of known instantiated
 *            classifiers, may be null
 * @return the instantiated classifier together with bindings for anonymous
 *         classifiers
 */
public static InstantiatedClassifier getInstantiatedClassifier(InstanceObject iobj, int index, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    InstantiatedClassifier ic = null;
    if (classifierCache != null) {
        final InstantiatedClassifier temp = classifierCache.get(iobj);
        if (temp != null) {
            return temp == InstantiatedClassifier.NULL ? null : temp;
        }
    }
    if (iobj instanceof SystemInstance) {
        ic = new InstantiatedClassifier(((SystemInstance) iobj).getComponentImplementation(), null);
    }
    if (ic == null) {
        Classifier classifier = null;
        EList<PrototypeBinding> prototypeBindings = null;
        Prototype prototype = null;
        if (iobj instanceof ComponentInstance) {
            Subcomponent sub = ((ComponentInstance) iobj).getSubcomponent();
            classifier = sub.getClassifier();
            prototypeBindings = sub.getOwnedPrototypeBindings();
            prototype = sub.getPrototype();
        } else if (iobj instanceof FeatureInstance) {
            FeatureType ft = ((FeatureGroup) ((FeatureInstance) iobj).getFeature()).getFeatureType();
            classifier = (ft instanceof Classifier) ? (Classifier) ft : null;
            prototype = (ft instanceof Prototype) ? (Prototype) ft : null;
        } else {
            return null;
        }
        if (classifier != null) {
            ic = new InstantiatedClassifier(classifier, prototypeBindings);
        }
        // no classifier => try prototype
        if (ic == null) {
            if (prototype != null) {
                // resolve prototype
                if (prototype instanceof ComponentPrototype) {
                    ComponentPrototypeActual cpa = resolveComponentPrototype(prototype, iobj, classifierCache);
                    if (cpa != null) {
                        ic = new InstantiatedClassifier((ComponentClassifier) cpa.getSubcomponentType(), cpa.getBindings());
                    } else {
                        // ISSUE 986: If the constraining classifier is missing (null), then don't create an InstantiatedClassifier object
                        final ComponentClassifier cc = ((ComponentPrototype) prototype).getConstrainingClassifier();
                        if (cc != null) {
                            ic = new InstantiatedClassifier(cc, noBindings);
                        }
                    }
                } else if (prototype instanceof FeatureGroupPrototype) {
                    FeatureGroupPrototypeActual fpa = resolveFeatureGroupPrototype(prototype, iobj, classifierCache);
                    if (fpa != null) {
                        ic = new InstantiatedClassifier((FeatureGroupType) fpa.getFeatureType(), fpa.getBindings());
                    } else {
                        ic = new InstantiatedClassifier(((FeatureGroupPrototype) prototype).getConstrainingFeatureGroupType(), noBindings);
                    }
                }
            }
        }
    }
    if (classifierCache != null) {
        classifierCache.put(iobj, ic == null ? InstantiatedClassifier.NULL : ic);
    }
    return ic;
}
Also used : FeatureType(org.osate.aadl2.FeatureType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Prototype(org.osate.aadl2.Prototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) SystemInstance(org.osate.aadl2.instance.SystemInstance) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding)

Aggregations

ComponentClassifier (org.osate.aadl2.ComponentClassifier)4 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)4 InstantiatedClassifier (org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier)4 Classifier (org.osate.aadl2.Classifier)3 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)3 FeatureGroup (org.osate.aadl2.FeatureGroup)3 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)3 FeatureGroupType (org.osate.aadl2.FeatureGroupType)3 FeaturePrototypeBinding (org.osate.aadl2.FeaturePrototypeBinding)3 Subcomponent (org.osate.aadl2.Subcomponent)3 ComponentPrototype (org.osate.aadl2.ComponentPrototype)2 ComponentPrototypeActual (org.osate.aadl2.ComponentPrototypeActual)2 Feature (org.osate.aadl2.Feature)2 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)2 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)2 FeatureType (org.osate.aadl2.FeatureType)2 PrototypeBinding (org.osate.aadl2.PrototypeBinding)2 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)2 InstanceObject (org.osate.aadl2.instance.InstanceObject)2 SystemInstance (org.osate.aadl2.instance.SystemInstance)2