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");
}
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);
}
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;
}
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();
}
}
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() + ".");
}
}
}
}
Aggregations