use of org.osate.aadl2.properties.PropertyIsModalException in project osate2 by osate.
the class Aadl2Validator method checkPortConnectionClassifiers.
/**
* Checks legality rule L13 for section 9.2 (Port Connections) "For
* connections between data ports, event data ports, and data access, the
* data classifier of the source port must match the data type of the
* destination port. The Classifier_Matching_Rule property specifies the
* rule to be applied to match the data classifier of a connection source to
* the data classifier of a connection destination."
*
* Checks legality rule L14 for section 9.2 (Port Connections) "The
* following rules are supported:
*
* -Classifier_Match: The source data type and data implementation must be
* identical to the data type or data implementation of the destination. If
* the destination classifier is a component type, then any implementation
* of the source matches. This is the default rule.
*
* -Equivalence: An indication that the two classifiers of a connection are
* considered to match if they are listed in the
* Supported_Classifier_Equivalence_Matches property. Acceptable data
* classifiers matches are specified as
* Supported_Classifier_Equivalence_Matches property with pairs of
* classifier values representing acceptable matches. Either element of the
* pair can be the source or destination classifier. Equivalence is intended
* to be used when the data types are considered to be identical, i.e., no
* conversion is necessary. The Supported_Classifier_Equivalence_Matches
* property is declared globally as a property constant.
*
* -Subset: A mapping of (a subset of) data elements of the source port data
* type to all data elements of the destination port data type. Acceptable
* data classifier matches are specified as
* Supported_Classifier_Subset_Matches property with pairs of classifier
* values representing acceptable matches. The first element of each pair
* specifies the acceptable source classifier, while the second element
* specifies the acceptable destination classifier. The
* Supported_Classifier_Subset_Matches property is declared globally as a
* property constant. A virtual bus or bus must represent a protocol that
* supports subsetting, such as OMG DDS.
*
* -Conversion: A mapping of the source port data type to the destination
* port data type, where the source port data type requires a conversion to
* the destination port data type. Acceptable data classifier matches are
* specified as Supported_Type_Conversions property with pairs of classifier
* values representing acceptable matches. The first element of each pair
* specifies the acceptable source classifier, while the second element
* specifies the acceptable destination classifier. The
* Supported_Type_Conversions property may be declared globally as a
* property constant. A virtual bus or bus must support the conversion from
* the source data classifier to the destination classifier."
*/
private void checkPortConnectionClassifiers(PortConnection connection) {
ConnectionEnd source = connection.getAllLastSource();
ConnectionEnd destination = connection.getAllLastDestination();
if ((source instanceof DataAccess || source instanceof DataSubcomponent || source instanceof DataPort || source instanceof EventDataPort) && (destination instanceof DataAccess || destination instanceof DataSubcomponent || destination instanceof DataPort || destination instanceof EventDataPort)) {
Classifier sourceClassifier;
Classifier destinationClassifier;
final boolean sourceIsSubcomponent = source instanceof DataSubcomponent;
final boolean destIsSubcomponent = destination instanceof DataSubcomponent;
if (sourceIsSubcomponent) {
sourceClassifier = ((DataSubcomponent) source).getAllClassifier();
} else {
sourceClassifier = ((Feature) source).getAllClassifier();
}
if (destIsSubcomponent) {
destinationClassifier = ((DataSubcomponent) destination).getAllClassifier();
} else {
destinationClassifier = ((Feature) destination).getAllClassifier();
}
if (sourceClassifier == null && destinationClassifier != null) {
warning("Expected " + (sourceIsSubcomponent ? "subcomponent" : "feature") + " \'" + source.getName() + "' to have classifier '" + destinationClassifier.getQualifiedName() + '\'', connection, Aadl2Package.eINSTANCE.getConnection_Source());
} else if (sourceClassifier != null && destinationClassifier == null) {
warning("Expected " + (destIsSubcomponent ? "subcomponent" : "feature") + " \'" + destination.getName() + "' to have classifier '" + sourceClassifier.getQualifiedName() + '\'', connection, Aadl2Package.eINSTANCE.getConnection_Destination());
} else if (sourceClassifier != null && destinationClassifier != null) {
try {
final ClassifierMatchingRule classifierMatchingRuleValue = org.osate.aadl2.contrib.modeling.ModelingProperties.getClassifierMatchingRule(connection).orElse(ClassifierMatchingRule.CLASSIFIER_MATCH);
if (classifierMatchingRuleValue == ClassifierMatchingRule.CLASSIFIER_MATCH) {
if (!testClassifierMatchRule(connection, source, sourceClassifier, destination, destinationClassifier)) {
error(connection, '\'' + source.getName() + "' and '" + destination.getName() + "' have incompatible classifiers.");
}
} else if (classifierMatchingRuleValue == ClassifierMatchingRule.EQUIVALENCE) {
if (!testClassifierMatchRule(connection, source, sourceClassifier, destination, destinationClassifier) && !classifiersFoundInSupportedClassifierEquivalenceMatchesProperty(connection, sourceClassifier, destinationClassifier)) {
error(connection, "The types of '" + source.getName() + "' and '" + destination.getName() + "' ('" + sourceClassifier.getQualifiedName() + "' and '" + destinationClassifier.getQualifiedName() + "') are incompatible and they are not listed as matching classifiers in the property constant '" + AadlProject.SUPPORTED_CLASSIFIER_EQUIVALENCE_MATCHES + "'.");
}
} else if (classifierMatchingRuleValue == ClassifierMatchingRule.SUBSET) {
if (!classifiersFoundInSupportedClassifierSubsetMatchesProperty(connection, sourceClassifier, destinationClassifier) && !isDataSubset(sourceClassifier, destinationClassifier)) {
error(connection, "The data type of '" + source.getName() + "' ('" + sourceClassifier.getQualifiedName() + "') is not a subset of the data type of '" + destination.getName() + "' ('" + destinationClassifier.getQualifiedName() + "') based on name matching or the property constant '" + AadlProject.SUPPORTED_CLASSIFIER_SUBSET_MATCHES + "'.");
}
} else if (classifierMatchingRuleValue == ClassifierMatchingRule.CONVERSION) {
if (!testClassifierMatchRule(connection, source, sourceClassifier, destination, destinationClassifier) && !classifiersFoundInSupportedTypeConversionsProperty(connection, sourceClassifier, destinationClassifier)) {
error(connection, "The types of '" + source.getName() + "' and '" + destination.getName() + "' ('" + sourceClassifier.getQualifiedName() + "' and '" + destinationClassifier.getQualifiedName() + "') are incompatible and they are not listed as matching classifiers in the property constant '" + AadlProject.SUPPORTED_TYPE_CONVERSIONS + "'.");
}
}
} catch (PropertyIsModalException e) {
// ignored exception. handled in separate validation method checkConnectionPropertyIsModal(Connection connection)
}
}
}
}
use of org.osate.aadl2.properties.PropertyIsModalException 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.PropertyIsModalException 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.PropertyIsModalException 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.PropertyIsModalException 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