use of org.osate.aadl2.RefinableElement 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(ProcessorSubcomponent object, String propertyName) {
List<Subcomponent> res = new ArrayList<Subcomponent>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
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 ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof ReferenceValue) {
ReferenceValue c = ((ReferenceValue) pe);
ContainmentPathElement cpe = c.getContainmentPathElements().get(c.getContainmentPathElements().size() - 1);
res.add((Subcomponent) cpe.getNamedElement());
}
}
}
}
}
}
// try on a refined NamedElement
if (object instanceof RefinableElement) {
RefinableElement re = object;
if (re.getRefinedElement() != null) {
List<Subcomponent> l = getSubcomponentList((ProcessorSubcomponent) re.getRefinedElement(), propertyName);
if (!l.isEmpty()) {
res.addAll(l);
}
}
}
return res;
}
use of org.osate.aadl2.RefinableElement in project osate2 by osate.
the class PropertyUtils method getFloatValue.
/**
* Extract float value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static Float getFloatValue(NamedElement i, String propertyName, String unit) {
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 NumberValue) {
NumberValue val = (NumberValue) expr;
float fVal = 0f;
if (val instanceof IntegerLiteral) {
fVal = ((IntegerLiteral) val).getValue();
} else if (val instanceof RealLiteral) {
fVal = (float) ((RealLiteral) val).getValue();
}
return UnitConversion.convertInMs(fVal, val.getUnit().getName());
}
}
}
}
// try on a refined NamedElement
if (i instanceof RefinableElement) {
RefinableElement re = (RefinableElement) i;
if (re.getRefinedElement() != null) {
return getFloatValue(re.getRefinedElement(), propertyName, unit);
}
}
return null;
}
use of org.osate.aadl2.RefinableElement in project osate2 by osate.
the class Aadl2Util method getRefinedName.
/**
* refined Elements do not have an assigned name, but they have a reference to the Element they refine.
* One of them is the original with an actually assigned name
* @param ne Element whose name we are trying to retrieve
* @param root The start of the search. Used to detect cycles
* @return
*/
public static String getRefinedName(NamedElement ne, NamedElement root) {
if (ne instanceof RefinableElement) {
RefinableElement re = (RefinableElement) ne;
RefinableElement ref = re.getRefinedElement();
if (ref == root) {
// terminate on cycle
return null;
}
if (ref != null) {
return getRefinedName(ref, root);
}
// no additional reference pointer, return name
return ne.getName();
}
return null;
}
use of org.osate.aadl2.RefinableElement in project osate2 by osate.
the class AgeAadlUtil method getRootRefinedElement.
/**
* If the element is a refinable element, returns the root refined element. That is, it returns the refined element which is not refined.
* Otherwise it returns the specified element.
* @param ne
* @return
*/
public static NamedElement getRootRefinedElement(NamedElement ne) {
if (ne instanceof RefinableElement) {
NamedElement refined = ne;
do {
ne = refined;
refined = ((RefinableElement) ne).getRefinedElement();
} while (refined != null);
}
return ne;
}
Aggregations