Search in sources :

Example 6 with RefinableElement

use of org.osate.aadl2.RefinableElement 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(ProcessorSubcomponent object, String propertyName) {
    List<Subcomponent> res = new ArrayList<Subcomponent>();
    PropertyAssociation pa = findPropertyAssociation(propertyName, object);
    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 ListValue) {
                    ListValue lv = (ListValue) expr;
                    for (PropertyExpression pe : lv.getOwnedListElements()) {
                        if (pe instanceof ReferenceValue) {
                            ReferenceValue c = ((ReferenceValue) pe);
                            ContainmentPathElement cpe = c.getContainmentPathElements().get(c.getContainmentPathElements().size() - 1);
                            res.add((Subcomponent) cpe.getNamedElement());
                        }
                    }
                }
            }
        }
    }
    // try on a refined NamedElement
    if (object instanceof RefinableElement) {
        RefinableElement re = object;
        if (re.getRefinedElement() != null) {
            List<Subcomponent> l = getSubcomponentList((ProcessorSubcomponent) re.getRefinedElement(), propertyName);
            if (!l.isEmpty()) {
                res.addAll(l);
            }
        }
    }
    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) RefinableElement(org.osate.aadl2.RefinableElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 7 with RefinableElement

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

the class PropertyUtils method getFloatValue.

/**
 * Extract float value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static Float getFloatValue(NamedElement i, String propertyName, String unit) {
    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 NumberValue) {
                    NumberValue val = (NumberValue) expr;
                    float fVal = 0f;
                    if (val instanceof IntegerLiteral) {
                        fVal = ((IntegerLiteral) val).getValue();
                    } else if (val instanceof RealLiteral) {
                        fVal = (float) ((RealLiteral) val).getValue();
                    }
                    return UnitConversion.convertInMs(fVal, val.getUnit().getName());
                }
            }
        }
    }
    // try on a refined NamedElement
    if (i instanceof RefinableElement) {
        RefinableElement re = (RefinableElement) i;
        if (re.getRefinedElement() != null) {
            return getFloatValue(re.getRefinedElement(), propertyName, unit);
        }
    }
    return null;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) NumberValue(org.osate.aadl2.NumberValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) PropertyExpression(org.osate.aadl2.PropertyExpression) RefinableElement(org.osate.aadl2.RefinableElement) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 8 with RefinableElement

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

the class Aadl2Util method getRefinedName.

/**
 * refined Elements do not have an assigned name, but they have a reference to the Element they refine.
 * One of them is the original with an actually assigned name
 * @param ne Element whose name we are trying to retrieve
 * @param root The start of the search. Used to detect cycles
 * @return
 */
public static String getRefinedName(NamedElement ne, NamedElement root) {
    if (ne instanceof RefinableElement) {
        RefinableElement re = (RefinableElement) ne;
        RefinableElement ref = re.getRefinedElement();
        if (ref == root) {
            // terminate on cycle
            return null;
        }
        if (ref != null) {
            return getRefinedName(ref, root);
        }
        // no additional reference pointer, return name
        return ne.getName();
    }
    return null;
}
Also used : RefinableElement(org.osate.aadl2.RefinableElement)

Example 9 with RefinableElement

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

the class AgeAadlUtil method getRootRefinedElement.

/**
 * If the element is a refinable element, returns the root refined element. That is, it returns the refined element which is not refined.
 * Otherwise it returns the specified element.
 * @param ne
 * @return
 */
public static NamedElement getRootRefinedElement(NamedElement ne) {
    if (ne instanceof RefinableElement) {
        NamedElement refined = ne;
        do {
            ne = refined;
            refined = ((RefinableElement) ne).getRefinedElement();
        } while (refined != null);
    }
    return ne;
}
Also used : RefinableElement(org.osate.aadl2.RefinableElement) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

RefinableElement (org.osate.aadl2.RefinableElement)8 BasicProperty (org.osate.aadl2.BasicProperty)4 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)4 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)4 Property (org.osate.aadl2.Property)4 PropertyAssociation (org.osate.aadl2.PropertyAssociation)4 PropertyExpression (org.osate.aadl2.PropertyExpression)4 ArrayList (java.util.ArrayList)2 IntegerLiteral (org.osate.aadl2.IntegerLiteral)2 ListValue (org.osate.aadl2.ListValue)2 NamedElement (org.osate.aadl2.NamedElement)2 Subcomponent (org.osate.aadl2.Subcomponent)2 EOperation (org.eclipse.emf.ecore.EOperation)1 org.osate.aadl2 (org.osate.aadl2)1 AadlPackage (org.osate.aadl2.AadlPackage)1 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)1 ArrayDimension (org.osate.aadl2.ArrayDimension)1 ArrayableElement (org.osate.aadl2.ArrayableElement)1 Classifier (org.osate.aadl2.Classifier)1 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)1