Search in sources :

Example 1 with PropertyDoesNotApplyToHolderException

use of org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException 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. Throws an exception if no property value exists or 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.
 * @return The maximum of the range value scaled to the given unit.
 * @throws InvalidModelException Thrown if the property value cannot be
 *             retrieved because the model is incomplete or otherwise
 *             invalid.
 * @throws PropertyNotPresentException Thrown if the property is undefined
 *             for ph.
 * @throws PropertyIsModalException Thrown if ph is modal and declarative.
 * @throws IllegalStateException Thrown if the lookup encounters a cycle of
 *             property reference dependencies.
 * @throws IllegalArgumentException Thrown if the given unit literal is not
 *             from the property's unit type or if ph, pd, or unit is null.
 * @throws PropertyDoesNotApplyToHolderException Thrown if pd does not apply
 *             to ph.
 * @throws PropertyIsListException Thrown if the property is not scalar.
 * @throws ClassCastException Thrown if the retrieved value is not a range
 *             value.
 */
public static double getScaledRangeMaximum(final NamedElement ph, final Property pd, final UnitLiteral unit) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException, PropertyIsListException, ClassCastException {
    final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ph, pd, unit);
    RangeValue rv = (RangeValue) pv;
    PropertyExpression maximum = rv.getMaximum().evaluate(null, 0).first().getValue();
    if (maximum instanceof NumberValue) {
        return ((NumberValue) maximum).getScaledValue(unit);
    }
    throw new InvalidModelException(maximum, "Cannot evaluate upper range limit");
}
Also used : InvalidModelException(org.osate.aadl2.properties.InvalidModelException) NumberValue(org.osate.aadl2.NumberValue) PropertyExpression(org.osate.aadl2.PropertyExpression) RangeValue(org.osate.aadl2.RangeValue)

Example 2 with PropertyDoesNotApplyToHolderException

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

the class PropertyUtils method getScaledRangeDelta.

/**
 * Return the delta value of a non-modal range property value scaled to a
 * given unit. Throws an exception if no property value exists or 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.
 * @return The delta of the range value scaled to the given unit.
 * @throws InvalidModelException Thrown if the property value cannot be
 *             retrieved because the model is incomplete or otherwise
 *             invalid.
 * @throws PropertyNotPresentException Thrown if the property is undefined
 *             for ph.
 * @throws PropertyIsModalException Thrown if ph is modal and declarative.
 * @throws IllegalStateException Thrown if the lookup encounters a cycle of
 *             property reference dependencies.
 * @throws IllegalArgumentException Thrown if the given unit literal is not
 *             from the property's unit type or if ph, pd, or unit is null.
 * @throws PropertyDoesNotApplyToHolderException Thrown if pd does not apply
 *             to ph.
 * @throws PropertyIsListException Thrown if the property is not scalar.
 * @throws ClassCastException Thrown if the retrieved value is not a range
 *             value.
 */
public static double getScaledRangeDelta(final NamedElement ph, final Property pd, final UnitLiteral unit) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException, PropertyIsListException, ClassCastException {
    final PropertyExpression pv = checkUnitsAndGetSimplePropertyValue(ph, pd, unit);
    RangeValue rv = (RangeValue) pv;
    return rv.getDeltaValue().getScaledValue(unit);
}
Also used : PropertyExpression(org.osate.aadl2.PropertyExpression) RangeValue(org.osate.aadl2.RangeValue)

Example 3 with PropertyDoesNotApplyToHolderException

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

the class PropertyUtils method getSimplePropertyListValue.

/**
 * get non-model proeprty list value
 */
public static PropertyExpression getSimplePropertyListValue(final NamedElement ph, final Property pd) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException, PropertyIsListException {
    PropertyExpression res;
    if (ph == null) {
        throw new IllegalArgumentException("NamedElement ph cannot be null.");
    }
    res = ph.getSimplePropertyValue(pd);
    if (res instanceof NamedValue) {
        AbstractNamedValue nv = ((NamedValue) res).getNamedValue();
        if (nv instanceof Property) {
            res = ph.getSimplePropertyValue((Property) nv);
        } else if (nv instanceof PropertyConstant) {
            res = ((PropertyConstant) nv).getConstantValue();
        }
    }
    return res;
}
Also used : AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) Property(org.osate.aadl2.Property) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 4 with PropertyDoesNotApplyToHolderException

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

the class NamedElementImpl method getPropertyValue.

/**
 * Returns the property value for the property specified by property
 *
 * @param property
 * 			  The property to lookup
 * @return AadlModalPropertyValue
 * @exception IllegalStateException
 * 				  Thrown if the lookup encounters a cycle of property
 * 				  reference dependencies.
 */
public PropertyAcc getPropertyValue(final Property property, final boolean all) throws IllegalStateException, InvalidModelException, PropertyDoesNotApplyToHolderException, IllegalArgumentException {
    // Error if the property is not acceptable
    if (property == null) {
        throw new IllegalArgumentException("Property property cannot be null.");
    }
    if (!acceptsProperty(property)) {
        throw new PropertyDoesNotApplyToHolderException(this, property, "Property " + property.getName() + " does not apply to " + getClass().getName());
    }
    // Check that we aren't already looking up this property
    final LinkedList<Property> stack = lookupStack.get();
    if (stack.contains(property)) {
        throw new IllegalStateException("Encountered circular dependency on property \"" + property.getName() + "\"");
    }
    try {
        stack.addFirst(property);
        PropertyAcc pas = new PropertyAcc(property);
        getPropertyValueInternal(property, pas, false, all);
        return pas;
    } finally {
        stack.removeFirst();
    }
}
Also used : PropertyDoesNotApplyToHolderException(org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException) PropertyAcc(org.osate.aadl2.properties.PropertyAcc) Property(org.osate.aadl2.Property)

Example 5 with PropertyDoesNotApplyToHolderException

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

the class NamedElementImpl method getNonModalPropertyValue.

/**
 * Retrieves the property value (single or list) of a non-modal property.  Throws an exception
 * if its a modal value or undefined.
 * @param property Property
 * @return The property expression or null if the property has no value.
 */
public PropertyExpression getNonModalPropertyValue(final Property property) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException {
    PropertyAssociation pa = getPropertyValue(property, false).first();
    if (pa == null) {
        if (property.getDefaultValue() == null) {
            throw new PropertyNotPresentException(this, property, "No property association was found");
        }
        return property.getDefaultValue();
    } else {
        if (!pa.isModal()) {
            // should always exist because it's not modal
            if (pa.getOwnedValues().isEmpty()) {
                throw new PropertyNotPresentException(this, property, "Property association has no value (yet)");
            }
            return pa.getOwnedValues().get(0).getOwnedValue();
        } else {
            // If we are an InstanceObject, get the value in the current SOM
            if (this instanceof InstanceObject) {
                final SystemInstance si = ((InstanceObject) this).getSystemInstance();
                final SystemOperationMode som = si.getCurrentSystemOperationMode();
                if (som != null) {
                    PropertyExpression defaultPE = null;
                    // find value in SOM
                    for (ModalPropertyValue mpv : pa.getOwnedValues()) {
                        if (mpv.getInModes() == null || mpv.getInModes().size() == 0) {
                            defaultPE = mpv.getOwnedValue();
                        } else if (mpv.getInModes().contains(som)) {
                            return mpv.getOwnedValue();
                        }
                    }
                    // default
                    if (defaultPE != null) {
                        return defaultPE;
                    }
                    // use global default
                    return property.getDefaultValue();
                } else {
                    throw new PropertyIsModalException(this, property, "Cannot use simple property lookup because the instance model has not been projected into a System Operation Mode." + "  This occurred when looking up Property " + property.getName() + " on NamedElement " + getName() + ".");
                }
            } else {
                throw new PropertyIsModalException(this, property, "A non-modal property lookup method was called for a modal property." + "  This occurred when looking up Property " + property.getName() + " on NamedElement " + getName() + ".");
            }
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) PropertyIsModalException(org.osate.aadl2.properties.PropertyIsModalException) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyNotPresentException(org.osate.aadl2.properties.PropertyNotPresentException) PropertyAssociation(org.osate.aadl2.PropertyAssociation) SystemInstance(org.osate.aadl2.instance.SystemInstance) PropertyExpression(org.osate.aadl2.PropertyExpression) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Aggregations

PropertyExpression (org.osate.aadl2.PropertyExpression)8 PropertyDoesNotApplyToHolderException (org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException)5 Property (org.osate.aadl2.Property)3 RangeValue (org.osate.aadl2.RangeValue)3 PropertyNotPresentException (org.osate.aadl2.properties.PropertyNotPresentException)3 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)2 PropertyAcc (org.osate.aadl2.properties.PropertyAcc)2 PropertyIsModalException (org.osate.aadl2.properties.PropertyIsModalException)2 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)1 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)1 ListValue (org.osate.aadl2.ListValue)1 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)1 NamedValue (org.osate.aadl2.NamedValue)1 NumberType (org.osate.aadl2.NumberType)1 NumberValue (org.osate.aadl2.NumberValue)1 PropertyAssociation (org.osate.aadl2.PropertyAssociation)1 PropertyConstant (org.osate.aadl2.PropertyConstant)1 PropertyType (org.osate.aadl2.PropertyType)1