use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getMaxRangeValue.
/**
* Extract maximum range value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static NumberValue getMaxRangeValue(NamedElement i, String propertyName) {
PropertyAssociation pa = findPropertyAssociation(propertyName, i);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof RangeValue) {
NumberValue n = ((RangeValue) expr).getMaximumValue();
return n;
} else if (expr instanceof NumberValue) {
return (NumberValue) expr;
}
}
}
}
return null;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getIntValue.
/**
* Extract integer value from a specified property. May return null
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static Long getIntValue(NamedElement i, String propertyName) {
PropertyAssociation pa = findPropertyAssociation(propertyName, i);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof IntegerLiteral) {
return ((IntegerLiteral) expr).getValue();
}
}
}
}
return null;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method isInAppliesTo.
private static PropertyAssociation isInAppliesTo(NamedElement owner, String propertyName) {
EObject parent = owner.eContainer();
String ownerName = owner.getName();
while (parent != null) {
if (parent instanceof NamedElement) {
EList<PropertyAssociation> pas = ((NamedElement) parent).getOwnedPropertyAssociations();
for (PropertyAssociation pa : pas) {
String propName = pa.getProperty().getName();
if (propName != null && propName.equalsIgnoreCase(propertyName)) {
for (ContainedNamedElement cne : pa.getAppliesTos()) {
EList<ContainmentPathElement> paths = cne.getContainmentPathElements();
ContainmentPathElement lastEl = paths.get(paths.size() - 1);
String lastElName = lastEl.getNamedElement().getName();
if (lastElName.equalsIgnoreCase(ownerName)) {
return pa;
}
}
}
}
}
parent = parent.eContainer();
}
return null;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getIntListValue.
/**
* TODO: DOC ME !
*
* May return null.
*
* @param object
* @param propertyName
* @return
*/
public static List<Long> getIntListValue(NamedElement object, String propertyName) {
List<Long> res = new ArrayList<Long>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa == null) {
return null;
} else {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof IntegerLiteral) {
Long c = ((IntegerLiteral) pe).getValue();
res.add(c);
}
}
}
}
}
}
// try on a refined NamedElement
if (object instanceof RefinableElement) {
RefinableElement re = (RefinableElement) object;
if (re.getRefinedElement() != null) {
List<Long> l = getIntListValue(re.getRefinedElement(), propertyName);
if (l != null) {
res.addAll(l);
}
}
}
return res;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getSubcomponentList.
/**
* May return an empty list.
*
* @param object
* @param propertyName
* @return
*/
public static List<Subcomponent> getSubcomponentList(NamedElement object, String propertyName) {
List<Subcomponent> res = new ArrayList<Subcomponent>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa == null) {
return null;
} else {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof ReferenceValue) {
ReferenceValue c = ((ReferenceValue) pe);
for (ContainmentPathElement cpe : c.getContainmentPathElements()) {
res.add((Subcomponent) cpe.getNamedElement());
}
}
}
}
}
}
return res;
}
}
Aggregations