Search in sources :

Example 21 with PropertyAssociation

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

the class PropertyUtils method getEnumValue.

/**
 * Extract enumeration value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 *             enumeration.
 */
public static String getEnumValue(NamedElement i, String propertyName) {
    PropertyAssociation pa = findPropertyAssociation(propertyName, i);
    if (pa != null) {
        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 EnumerationLiteral) {
                    return ((EnumerationLiteral) expr).getName();
                } else if (expr instanceof NamedValue) {
                    NamedValue nv = (NamedValue) expr;
                    if (nv.getNamedValue() instanceof EnumerationLiteral) {
                        EnumerationLiteral el = (EnumerationLiteral) nv.getNamedValue();
                        return el.getName();
                    }
                }
            }
        }
    }
    // try on a refined NamedElement
    if (i instanceof RefinableElement) {
        RefinableElement re = (RefinableElement) i;
        if (re.getRefinedElement() != null) {
            return getEnumValue(re.getRefinedElement(), propertyName);
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) RefinableElement(org.osate.aadl2.RefinableElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral)

Example 22 with PropertyAssociation

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

the class PropertyUtils method getRecordValue.

/**
 *    * TODO: DOC ME !
 *
 * May return null
 *
 * @param i
 * @param propertyName
 * @return
 */
public static RecordValue getRecordValue(NamedElement i, String propertyName) {
    PropertyAssociation pa = findPropertyAssociation(propertyName, i);
    if (pa != null) {
        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 RecordValue) {
                    return ((RecordValue) expr);
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) RecordValue(org.osate.aadl2.RecordValue) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 23 with PropertyAssociation

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

the class PropertyUtils method setFloatValue.

public static boolean setFloatValue(NamedElement e, String propertyName, float value) {
    PropertyAssociation pa = findPropertyAssociation(propertyName, e);
    if (pa != null) {
        RealLiteral r = Aadl2Factory.eINSTANCE.createRealLiteral();
        r.setValue(value);
        r.setUnit(getUnit(pa));
        pa.getOwnedValues().get(0).setOwnedValue(r);
        return true;
    }
    return false;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation)

Example 24 with PropertyAssociation

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

the class PropertyUtils method getComponentInstanceList.

/**
 * TODO: DOC ME !
 *
 * May return null.
 *
 * @param object
 * @param propertyName
 * @return
 */
public static List<ComponentInstance> getComponentInstanceList(NamedElement object, String propertyName) {
    List<ComponentInstance> res = null;
    PropertyAssociation pa = findPropertyAssociation(propertyName, object);
    if (pa != null) {
        res = new ArrayList<ComponentInstance>();
        Property p = pa.getProperty();
        if (p.getName().equals(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 InstanceReferenceValue) {
                            InstanceReferenceValue c = ((InstanceReferenceValue) pe);
                            res.add((ComponentInstance) c.getReferencedInstanceObject());
                        }
                    }
                }
            }
        }
    }
    return res;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 25 with PropertyAssociation

use of org.osate.aadl2.PropertyAssociation 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)

Aggregations

PropertyAssociation (org.osate.aadl2.PropertyAssociation)90 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)51 Property (org.osate.aadl2.Property)49 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)45 PropertyExpression (org.osate.aadl2.PropertyExpression)41 BasicProperty (org.osate.aadl2.BasicProperty)28 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)28 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)27 NamedElement (org.osate.aadl2.NamedElement)24 ListValue (org.osate.aadl2.ListValue)21 ArrayList (java.util.ArrayList)19 NamedValue (org.osate.aadl2.NamedValue)18 Element (org.osate.aadl2.Element)15 ArraySizeProperty (org.osate.aadl2.ArraySizeProperty)13 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)13 ReferenceValue (org.osate.aadl2.ReferenceValue)13 EObject (org.eclipse.emf.ecore.EObject)12 Mode (org.osate.aadl2.Mode)12 Classifier (org.osate.aadl2.Classifier)11 IntegerLiteral (org.osate.aadl2.IntegerLiteral)11