Search in sources :

Example 16 with ModalPropertyValue

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

the class PropertyUtils method getStringValue.

/**
 * Extract String value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static String getStringValue(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 StringLiteral) {
                    return ((StringLiteral) expr).getValue();
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) StringLiteral(org.osate.aadl2.StringLiteral) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 17 with ModalPropertyValue

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

the class PropertyUtils method getBooleanValue.

/**
 * Extract boolean value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static Boolean getBooleanValue(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 BooleanLiteral) {
                    return (boolean) ((BooleanLiteral) expr).getValue();
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) BooleanLiteral(org.osate.aadl2.BooleanLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 18 with ModalPropertyValue

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

the class PropertyUtils method getMaxRangeValue.

/**
 * Extract maximum range value from a specified property. May return null.
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static NumberValue getMaxRangeValue(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 RangeValue) {
                    NumberValue n = ((RangeValue) expr).getMaximumValue();
                    return n;
                } else if (expr instanceof NumberValue) {
                    return (NumberValue) expr;
                }
            }
        }
    }
    return null;
}
Also used : 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) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) RangeValue(org.osate.aadl2.RangeValue)

Example 19 with ModalPropertyValue

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

the class PropertyUtils method getIntValue.

/**
 * Extract integer value from a specified property. May return null
 *
 * @param i
 *            component instance.
 * @param propertyName
 *            property name.
 * @return property value.
 */
public static Long getIntValue(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 IntegerLiteral) {
                    return ((IntegerLiteral) expr).getValue();
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 20 with ModalPropertyValue

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

the class PropertyUtils method getIntListValue.

/**
 * TODO: DOC ME !
 *
 * May return null.
 *
 * @param object
 * @param propertyName
 * @return
 */
public static List<Long> getIntListValue(NamedElement object, String propertyName) {
    List<Long> res = new ArrayList<Long>();
    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 IntegerLiteral) {
                            Long c = ((IntegerLiteral) pe).getValue();
                            res.add(c);
                        }
                    }
                }
            }
        }
    }
    // try on a refined NamedElement
    if (object instanceof RefinableElement) {
        RefinableElement re = (RefinableElement) object;
        if (re.getRefinedElement() != null) {
            List<Long> l = getIntListValue(re.getRefinedElement(), propertyName);
            if (l != null) {
                res.addAll(l);
            }
        }
    }
    return res;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) 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)

Aggregations

ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)56 PropertyAssociation (org.osate.aadl2.PropertyAssociation)44 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)29 PropertyExpression (org.osate.aadl2.PropertyExpression)29 Property (org.osate.aadl2.Property)28 BasicProperty (org.osate.aadl2.BasicProperty)21 ListValue (org.osate.aadl2.ListValue)20 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)11 IntegerLiteral (org.osate.aadl2.IntegerLiteral)11 NamedValue (org.osate.aadl2.NamedValue)11 ReferenceValue (org.osate.aadl2.ReferenceValue)11 ArrayList (java.util.ArrayList)10 Mode (org.osate.aadl2.Mode)10 RangeValue (org.osate.aadl2.RangeValue)10 StringLiteral (org.osate.aadl2.StringLiteral)10 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)9 RecordValue (org.osate.aadl2.RecordValue)9 BooleanLiteral (org.osate.aadl2.BooleanLiteral)8 ClassifierValue (org.osate.aadl2.ClassifierValue)7 RealLiteral (org.osate.aadl2.RealLiteral)7