Search in sources :

Example 21 with ContainmentPathElement

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

the class ReferenceImpl method basicSetPath.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetPath(ContainmentPathElement newPath, NotificationChain msgs) {
    ContainmentPathElement oldPath = path;
    path = newPath;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, DeclarativePackage.REFERENCE__PATH, oldPath, newPath);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement)

Example 22 with ContainmentPathElement

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

the class PropertyUtils method isInAppliesTo.

private static PropertyAssociation isInAppliesTo(NamedElement owner, String propertyName) {
    EObject parent = owner.eContainer();
    String ownerName = owner.getName();
    while (parent != null) {
        if (parent instanceof NamedElement) {
            EList<PropertyAssociation> pas = ((NamedElement) parent).getOwnedPropertyAssociations();
            for (PropertyAssociation pa : pas) {
                String propName = pa.getProperty().getName();
                if (propName != null && propName.equalsIgnoreCase(propertyName)) {
                    for (ContainedNamedElement cne : pa.getAppliesTos()) {
                        EList<ContainmentPathElement> paths = cne.getContainmentPathElements();
                        ContainmentPathElement lastEl = paths.get(paths.size() - 1);
                        String lastElName = lastEl.getNamedElement().getName();
                        if (lastElName.equalsIgnoreCase(ownerName)) {
                            return pa;
                        }
                    }
                }
            }
        }
        parent = parent.eContainer();
    }
    return null;
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) EObject(org.eclipse.emf.ecore.EObject) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 23 with ContainmentPathElement

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

the class PropertyUtils method getSubcomponentList.

/**
 * May return an empty list.
 *
 * @param object
 * @param propertyName
 * @return
 */
public static List<Subcomponent> getSubcomponentList(NamedElement object, String propertyName) {
    List<Subcomponent> res = new ArrayList<Subcomponent>();
    PropertyAssociation pa = findPropertyAssociation(propertyName, object);
    if (pa == null) {
        return null;
    } else {
        Property p = pa.getProperty();
        if (p.getName().equalsIgnoreCase(propertyName)) {
            List<ModalPropertyValue> values = pa.getOwnedValues();
            if (values.size() == 1) {
                ModalPropertyValue v = values.get(0);
                PropertyExpression expr = v.getOwnedValue();
                if (expr instanceof ListValue) {
                    ListValue lv = (ListValue) expr;
                    for (PropertyExpression pe : lv.getOwnedListElements()) {
                        if (pe instanceof ReferenceValue) {
                            ReferenceValue c = ((ReferenceValue) pe);
                            for (ContainmentPathElement cpe : c.getContainmentPathElements()) {
                                res.add((Subcomponent) cpe.getNamedElement());
                            }
                        }
                    }
                }
            }
        }
        return res;
    }
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) ReferenceValue(org.osate.aadl2.ReferenceValue) ProcessorSubcomponent(org.osate.aadl2.ProcessorSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 24 with ContainmentPathElement

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

the class CacheContainedPropertyAssociationsSwitch method processContainedPropertyAssociations.

/**
 * Copy contained property associations to the instance model.
 * Don't fully evaluate the property expression. Just replace reference values with
 * a reference to the referenced instance object.
 *
 * @param modeContext
 * @param ci
 * @param propertyAssociations
 */
protected void processContainedPropertyAssociations(final ComponentInstance modeContext, final ComponentInstance ci, final EList<PropertyAssociation> propertyAssociations) {
    for (PropertyAssociation pa : propertyAssociations) {
        // OsateDebug.osateDebug ("[CacheContainedProperty] Process contained property association: " + pa.getProperty().getName());
        Property prop = pa.getProperty();
        if (Aadl2Util.isNull(prop) || Aadl2Util.isNull(prop.getType())) {
            continue;
        }
        for (ContainedNamedElement cne : pa.getAppliesTos()) {
            final EList<ContainmentPathElement> cpes = cne.getContainmentPathElements();
            if (cpes != null && !cpes.isEmpty()) {
                final NamedElement last = cpes.get(cpes.size() - 1).getNamedElement();
                final List<InstanceObject> ios = ci.findInstanceObjects(cpes);
                for (InstanceObject io : ios) {
                    // OsateDebug.osateDebug (" io=" + io);
                    PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                    newPA.setProperty(prop);
                    newPA.setPropertyAssociation(pa);
                    newPA.getOwnedValues().addAll(EcoreUtil.copyAll(pa.getOwnedValues()));
                    // replace reference values in the context of the contained PA's owner
                    for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
                        Element elem = content.next();
                        if (elem instanceof ReferenceValue) {
                            // TODO: LW what if ref to connection?
                            try {
                                PropertyExpression irv = ((ReferenceValue) elem).instantiate(ci);
                                if (irv != null) {
                                    EcoreUtil.replace(elem, irv);
                                }
                            } catch (InvalidModelException e) {
                                error(io, e.getMessage());
                            }
                        }
                    }
                    if (last instanceof Connection) {
                        final PropertyAssociation existingPA = scProps.retrieveSCProperty((ConnectionInstance) io, prop, (Connection) last);
                        if (existingPA != null && isConstant(existingPA)) {
                            /*
								 * Cannot put the error on the property association that is affected because it might
								 * be a declarative model element at this point. Need to report the error on the
								 * instance object itself.
								 */
                            getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant.  A contained property association in classifier \"" + pa.getContainingClassifier().getQualifiedName() + "\" tries to replace it.");
                        } else {
                            scProps.recordSCProperty((ConnectionInstance) io, prop, (Connection) last, newPA);
                        }
                    } else {
                        final PropertyAssociation existingPA = io.getPropertyValue(prop, false).first();
                        if (existingPA != null && isConstant(existingPA)) {
                            /*
								 * Cannot put the error on the property association that is affected because it might
								 * be a declarative model element at this point. Need to report the error on the
								 * instance object itself.
								 */
                            getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant.  A contained property association in classifier \"" + pa.getContainingClassifier().getQualifiedName() + "\" tries to replace it.");
                        } else {
                            io.removePropertyAssociations(prop);
                            io.getOwnedPropertyAssociations().add(newPA);
                        }
                    }
                }
            }
        }
        checkIfCancelled();
        if (cancelled()) {
            break;
        }
    }
}
Also used : PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Connection(org.osate.aadl2.Connection) InstanceObject(org.osate.aadl2.instance.InstanceObject) InvalidModelException(org.osate.aadl2.properties.InvalidModelException) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) PropertyExpression(org.osate.aadl2.PropertyExpression) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) Property(org.osate.aadl2.Property) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 25 with ContainmentPathElement

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

the class CacheContainedPropertyAssociationsSwitch method processContainedPropertyAssociations.

protected void processContainedPropertyAssociations(final FeatureInstance fi, final EList<PropertyAssociation> propertyAssociations) {
    for (PropertyAssociation pa : propertyAssociations) {
        Property prop = pa.getProperty();
        if (Aadl2Util.isNull(prop) || Aadl2Util.isNull(prop.getType())) {
            // PA is missing the prop def, skip to the next one
            continue;
        }
        for (ContainedNamedElement cne : pa.getAppliesTos()) {
            final EList<ContainmentPathElement> cpes = cne.getContainmentPathElements();
            if (cpes != null && !cpes.isEmpty()) {
                final Collection<FeatureInstance> ios = fi.findFeatureInstances(cpes);
                if (!ios.isEmpty()) {
                    for (InstanceObject io : ios) {
                        PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
                        newPA.setProperty(prop);
                        newPA.setPropertyAssociation(pa);
                        newPA.getOwnedValues().addAll(EcoreUtil.copyAll(pa.getOwnedValues()));
                        // replace reference values in the context of the contained PA's owner
                        for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
                            Element elem = content.next();
                            if (elem instanceof ReferenceValue) {
                                PropertyExpression irv = ((ReferenceValue) elem).instantiate(fi);
                                if (irv != null) {
                                    EcoreUtil.replace(elem, irv);
                                }
                            }
                        }
                        final PropertyAssociation existingPA = io.getPropertyValue(prop, false).first();
                        if (existingPA != null && isConstant(existingPA)) {
                            /*
								 * Cannot put the error on the property association that is affected because it might
								 * be a declarative model element at this point. Need to report the error on the
								 * instance object itself.
								 */
                            final String classifierName = pa.getContainingClassifier().getQualifiedName();
                            final Element owner = pa.getOwner();
                            final String featureName = (owner instanceof Feature) ? ("." + ((Feature) owner).getName()) : "";
                            getErrorManager().error(io, "Property association for \"" + prop.getQualifiedName() + "\" is constant.  A contained property association in classifier \"" + classifierName + featureName + "\" tries to replace it.");
                        } else {
                            io.removePropertyAssociations(prop);
                            io.getOwnedPropertyAssociations().add(newPA);
                        }
                    }
                }
            }
        }
        checkIfCancelled();
        if (cancelled()) {
            break;
        }
    }
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Feature(org.osate.aadl2.Feature) InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyAssociationInstance(org.osate.aadl2.instance.PropertyAssociationInstance) PropertyExpression(org.osate.aadl2.PropertyExpression) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) Property(org.osate.aadl2.Property)

Aggregations

ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)52 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)27 NamedElement (org.osate.aadl2.NamedElement)24 PropertyAssociation (org.osate.aadl2.PropertyAssociation)19 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)15 ReferenceValue (org.osate.aadl2.ReferenceValue)14 Property (org.osate.aadl2.Property)12 Subcomponent (org.osate.aadl2.Subcomponent)12 IntegerLiteral (org.osate.aadl2.IntegerLiteral)11 ListValue (org.osate.aadl2.ListValue)11 NamedValue (org.osate.aadl2.NamedValue)11 ArrayRange (org.osate.aadl2.ArrayRange)10 RangeValue (org.osate.aadl2.RangeValue)10 RealLiteral (org.osate.aadl2.RealLiteral)10 RecordValue (org.osate.aadl2.RecordValue)10 BooleanLiteral (org.osate.aadl2.BooleanLiteral)9 ClassifierValue (org.osate.aadl2.ClassifierValue)9 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)9 StringLiteral (org.osate.aadl2.StringLiteral)9 EObject (org.eclipse.emf.ecore.EObject)7