Search in sources :

Example 21 with PropertyLookupException

use of org.osate.aadl2.properties.PropertyLookupException in project osate2 by osate.

the class PropertyUtils method getInstanceObjectReference.

/**
 * Get an InstanceObject from an instance reference value. Throws an
 * exception if no property value exists or an error occurs.
 *
 * @param io The instance object from which to retrieve the property value.
 *            (We don't use a property holder because we can only get an
 *            instance reference value as a property value from an instance
 *            object.)
 * @param pd The property to retrieve.
 * @return The instance object of the property.
 */
public static InstanceObject getInstanceObjectReference(final InstanceObject io, final Property pd) {
    if (io == null) {
        return null;
    }
    try {
        final PropertyExpression pv = io.getSimplePropertyValue(pd);
        final InstanceObject ref = ((InstanceReferenceValue) pv).getReferencedInstanceObject();
        return ref;
    } catch (PropertyLookupException e) {
        return null;
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyExpression(org.osate.aadl2.PropertyExpression) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) PropertyLookupException(org.osate.aadl2.properties.PropertyLookupException)

Example 22 with PropertyLookupException

use of org.osate.aadl2.properties.PropertyLookupException in project osate2 by osate.

the class PropertyUtils method getScaledRangeMaximum.

/**
 * Return the maximum value of a non-modal range property value scaled to a
 * given unit. Returns a given default value if no property value exists.
 * Throws an exception if an error occurs.
 *
 * @param ph The property holder from which to retrieve the property value.
 * @param pd The property to retrieve.
 * @param unit The unit to scale the value to.
 * @param defaultVal The value to return if the property has no value.
 * @return The maximum of the range value scaled to the given unit.
 */
public static double getScaledRangeMaximum(final NamedElement ne, final Property pd, final UnitLiteral unit, final double defaultVal) {
    try {
        final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ne, pd, unit);
        final RangeValue rv = (RangeValue) pv;
        PropertyExpression maximum = rv.getMaximum().evaluate(null, 0).first().getValue();
        if (maximum instanceof NumberValue) {
            return ((NumberValue) maximum).getScaledValue(unit);
        } else {
            return defaultVal;
        }
    } catch (PropertyLookupException e) {
        return defaultVal;
    }
}
Also used : NumberValue(org.osate.aadl2.NumberValue) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyLookupException(org.osate.aadl2.properties.PropertyLookupException) RangeValue(org.osate.aadl2.RangeValue)

Example 23 with PropertyLookupException

use of org.osate.aadl2.properties.PropertyLookupException in project osate2 by osate.

the class PropertyUtils method getBooleanValue.

/**
 * Get a non-modal boolean property value. Returns a given default value if
 * no property value exists. Throws an exception if an error occurs.
 *
 * @param ph The property holder from which to retrieve the property value.
 * @param pd The property to retrieve.
 * @param defaultVal The value to return if the property has no value.
 * @return The boolean value of the property.
 */
public static boolean getBooleanValue(final NamedElement ph, final Property pd, final boolean defaultVal) {
    try {
        final PropertyExpression pv = getSimplePropertyValue(ph, pd);
        final BooleanLiteral v = (BooleanLiteral) pv;
        return v.getValue();
    } catch (PropertyLookupException e) {
        return defaultVal;
    }
}
Also used : BooleanLiteral(org.osate.aadl2.BooleanLiteral) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyLookupException(org.osate.aadl2.properties.PropertyLookupException)

Aggregations

PropertyLookupException (org.osate.aadl2.properties.PropertyLookupException)23 PropertyExpression (org.osate.aadl2.PropertyExpression)19 Property (org.osate.aadl2.Property)16 BasicProperty (org.osate.aadl2.BasicProperty)12 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)8 ArrayList (java.util.ArrayList)6 StringLiteral (org.osate.aadl2.StringLiteral)4 NamedValue (org.osate.aadl2.NamedValue)3 RangeValue (org.osate.aadl2.RangeValue)3 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)3 InstanceReferenceValue (org.osate.aadl2.instance.InstanceReferenceValue)3 IntegerLiteral (org.osate.aadl2.IntegerLiteral)2 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)2 UnitLiteral (org.osate.aadl2.UnitLiteral)2 PropertyAcc (org.osate.aadl2.properties.PropertyAcc)2 BooleanLiteral (org.osate.aadl2.BooleanLiteral)1 Classifier (org.osate.aadl2.Classifier)1 ComponentClassifier (org.osate.aadl2.ComponentClassifier)1 ComponentType (org.osate.aadl2.ComponentType)1 NumberValue (org.osate.aadl2.NumberValue)1