Search in sources :

Example 96 with PropertyExpression

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

the class AadlBaUtils method processArrayDataRepresentation.

// Evaluates the array behavior of the given type in the Data Model Annex
// standard way. Set up dimension and dimension sizes of the given
// TypeHolder object.
// The given expression dimension is used as an dimension offset.
private static void processArrayDataRepresentation(Element el, TypeHolder type, int exprDim) throws DimensionException {
    // Treats only type declared as an array. Otherwise returns.
    if (type.getDataRep() == DataRepresentation.ARRAY) {
        // Fetches the array element data type.
        ClassifierValue cv = AadlBaUtils.getBaseType(type.getKlass());
        if (cv != null && cv.getClassifier() instanceof DataClassifier) {
            DataClassifier dc = (DataClassifier) cv.getClassifier();
            type.setKlass(dc);
            type.setDataRep(AadlBaUtils.getDataRepresentation(dc));
        } else {
            type.setKlass(null);
        }
        EList<PropertyExpression> pel = PropertyUtils.findPropertyExpression(type.getKlass(), DataModelProperties.DIMENSION);
        int declareDimBT = 0;
        long[] declareDimSizeBT;
        if (false == pel.isEmpty()) {
            // pel has only one element, according to AADL core standard.
            PropertyExpression pe = pel.get(pel.size() - 1);
            if (pe instanceof ListValue) {
                ListValue lv = (ListValue) pe;
                EList<PropertyExpression> lve = lv.getOwnedListElements();
                declareDimBT = lve.size();
                if (declareDimBT >= exprDim) {
                    declareDimSizeBT = new long[declareDimBT - exprDim];
                    for (int i = exprDim; i < declareDimBT; i++) {
                        IntegerLiteral il = (IntegerLiteral) lve.get(i);
                        declareDimSizeBT[i - exprDim] = il.getValue();
                    }
                    type.setDimension(declareDimBT - exprDim);
                    type.setDimensionSizes(declareDimSizeBT);
                } else {
                    String msg = "must be an array but is resolved as " + type.getKlass().getQualifiedName();
                    throw new DimensionException(el, msg, false);
                }
            }
        } else {
            // Returning -1 and null means that the expression is declared as an
            // array but the dimension property is not set.
            type.setDimension(-1);
            type.setDimensionSizes(null);
            return;
        // String msg = "is declared as an array but the dimension property is not set" ;
        // throw new DimensionException(el, msg, true) ;
        }
    } else {
        return;
    }
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) DataClassifier(org.osate.aadl2.DataClassifier) AadlString(org.osate.aadl2.AadlString) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 97 with PropertyExpression

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

the class PropertyUtils method getListValue.

public static ListValue getListValue(NamedElement ne, String propertyName) {
    PropertyAssociation pa = findPropertyAssociation(propertyName, ne);
    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) {
                    return (ListValue) expr;
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ListValue(org.osate.aadl2.ListValue) PropertyExpression(org.osate.aadl2.PropertyExpression) BasicProperty(org.osate.aadl2.BasicProperty) Property(org.osate.aadl2.Property)

Example 98 with PropertyExpression

use of org.osate.aadl2.PropertyExpression 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 99 with PropertyExpression

use of org.osate.aadl2.PropertyExpression 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 100 with PropertyExpression

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

Aggregations

PropertyExpression (org.osate.aadl2.PropertyExpression)405 Property (org.osate.aadl2.Property)300 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)246 ListValue (org.osate.aadl2.ListValue)89 BasicProperty (org.osate.aadl2.BasicProperty)51 PropertyAssociation (org.osate.aadl2.PropertyAssociation)41 TimeUnits (org.osate.aadl2.contrib.aadlproject.TimeUnits)40 PropertyLookupException (org.osate.aadl2.properties.PropertyLookupException)36 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)34 IntegerLiteral (org.osate.aadl2.IntegerLiteral)33 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)32 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)31 ArrayList (java.util.ArrayList)29 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)28 NamedElement (org.osate.aadl2.NamedElement)27 NamedValue (org.osate.aadl2.NamedValue)27 PropertyConstant (org.osate.aadl2.PropertyConstant)27 ClassifierValue (org.osate.aadl2.ClassifierValue)26 StringLiteral (org.osate.aadl2.StringLiteral)26 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)23