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;
}
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getEnumValue.
/**
* Extract enumeration value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
* enumeration.
*/
public static String getEnumValue(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 EnumerationLiteral) {
return ((EnumerationLiteral) expr).getName();
} else if (expr instanceof NamedValue) {
NamedValue nv = (NamedValue) expr;
if (nv.getNamedValue() instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) nv.getNamedValue();
return el.getName();
}
}
}
}
}
// try on a refined NamedElement
if (i instanceof RefinableElement) {
RefinableElement re = (RefinableElement) i;
if (re.getRefinedElement() != null) {
return getEnumValue(re.getRefinedElement(), propertyName);
}
}
return null;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getRecordValue.
/**
* * TODO: DOC ME !
*
* May return null
*
* @param i
* @param propertyName
* @return
*/
public static RecordValue getRecordValue(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 RecordValue) {
return ((RecordValue) expr);
}
}
}
}
return null;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method setFloatValue.
public static boolean setFloatValue(NamedElement e, String propertyName, float value) {
PropertyAssociation pa = findPropertyAssociation(propertyName, e);
if (pa != null) {
RealLiteral r = Aadl2Factory.eINSTANCE.createRealLiteral();
r.setValue(value);
r.setUnit(getUnit(pa));
pa.getOwnedValues().get(0).setOwnedValue(r);
return true;
}
return false;
}
use of org.osate.aadl2.PropertyAssociation in project osate2 by osate.
the class PropertyUtils method getComponentInstanceList.
/**
* TODO: DOC ME !
*
* May return null.
*
* @param object
* @param propertyName
* @return
*/
public static List<ComponentInstance> getComponentInstanceList(NamedElement object, String propertyName) {
List<ComponentInstance> res = null;
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa != null) {
res = new ArrayList<ComponentInstance>();
Property p = pa.getProperty();
if (p.getName().equals(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 InstanceReferenceValue) {
InstanceReferenceValue c = ((InstanceReferenceValue) pe);
res.add((ComponentInstance) c.getReferencedInstanceObject());
}
}
}
}
}
}
return res;
}
Aggregations