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;
}
}
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;
}
}
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;
}
}
Aggregations