use of org.osate.aadl2.BasicPropertyAssociation in project osate2 by osate.
the class Collocated method toPropertyExpression.
@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
if (!targets.isPresent() && !location.isPresent()) {
throw new IllegalStateException("Record must have at least one field set.");
}
RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
targets.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, TARGETS__URI, TARGETS__NAME));
fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field, element1 -> {
return CodeGenUtil.toPropertyExpression(element1);
}));
});
location.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, LOCATION__URI, LOCATION__NAME));
fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
});
return recordValue;
}
use of org.osate.aadl2.BasicPropertyAssociation in project osate2 by osate.
the class PriorityMapping method toPropertyExpression.
@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
if (!aadlPriority.isPresent() && !rtosPriority.isPresent()) {
throw new IllegalStateException("Record must have at least one field set.");
}
RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
aadlPriority.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, AADL_PRIORITY__URI, AADL_PRIORITY__NAME));
fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
});
rtosPriority.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, RTOS_PRIORITY__URI, RTOS_PRIORITY__NAME));
fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field));
});
return recordValue;
}
use of org.osate.aadl2.BasicPropertyAssociation in project osate2 by osate.
the class AccessTime method toPropertyExpression.
@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
if (!first.isPresent() && !last.isPresent()) {
throw new IllegalStateException("Record must have at least one field set.");
}
RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
first.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, FIRST__URI, FIRST__NAME));
fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
});
last.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, LAST__URI, LAST__NAME));
fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
});
return recordValue;
}
use of org.osate.aadl2.BasicPropertyAssociation in project osate2 by osate.
the class AssignTime method toPropertyExpression.
@Override
public RecordValue toPropertyExpression(ResourceSet resourceSet) {
if (!fixed.isPresent() && !perbyte.isPresent()) {
throw new IllegalStateException("Record must have at least one field set.");
}
RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue();
fixed.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, FIXED__URI, FIXED__NAME));
fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
});
perbyte.ifPresent(field -> {
BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue();
fieldAssociation.setProperty(loadField(resourceSet, PERBYTE__URI, PERBYTE__NAME));
fieldAssociation.setOwnedValue(field.toPropertyExpression(resourceSet));
});
return recordValue;
}
use of org.osate.aadl2.BasicPropertyAssociation in project osate2 by osate.
the class PropertyUtils method getValue.
/**
* Returns the first property expression or abstract named element (
* EnumerationLiteral, Property, PropertyConstant, UnitLiteral) that matches
* to the given String object within the given ProperyExpression object.
* If the property expression doesn't exist, it returns {@code null}.
*
* @param pe the given ProperyExpression object
* @param toBeMatched the given String object
* @return the first matching property expression or abstract named element.
* otherwise return {@code null}
*
* @throws UnsupportedOperationException for other property values than:
* _ StringLiteral
* _ ListValue (recursion supported)
* _ ClassifierValue
* _ InstanceReferenceValue
* _ ComputedValue
* _ RecordValue (based on field matching)
* _ NamedValue (returns abstract named element)
*/
public static Element getValue(PropertyExpression pe, String toBeMatched) {
Element tmp = null;
int id = pe.eClass().getClassifierID();
switch(id) {
case Aadl2Package.STRING_LITERAL:
{
StringLiteral sl = (StringLiteral) pe;
if (sl.getValue().equalsIgnoreCase(toBeMatched)) {
return sl;
}
return null;
}
case Aadl2Package.LIST_VALUE:
{
ListValue lv = (ListValue) pe;
EList<PropertyExpression> pel = lv.getOwnedListElements();
for (PropertyExpression ownedPe : pel) {
tmp = getValue(ownedPe, toBeMatched);
if (tmp != null) {
return tmp;
}
}
return null;
}
case Aadl2Package.RECORD_VALUE:
{
RecordValue rv = (RecordValue) pe;
for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
if (bpa.getProperty().getName().equalsIgnoreCase(toBeMatched)) {
return bpa.getValue();
}
}
return null;
}
case Aadl2Package.CLASSIFIER_VALUE:
{
ClassifierValue cv = (ClassifierValue) pe;
if (cv.getClassifier().getName().equalsIgnoreCase(toBeMatched)) {
return cv;
} else {
return null;
}
}
case Aadl2Package.REFERENCE_VALUE:
{
InstanceReferenceValue irv = (InstanceReferenceValue) pe;
if (irv.getReferencedInstanceObject().getName().equalsIgnoreCase(toBeMatched)) {
return irv;
} else {
return null;
}
}
case Aadl2Package.COMPUTED_VALUE:
{
ComputedValue cv = (ComputedValue) pe;
if (cv.getFunction().equalsIgnoreCase(toBeMatched)) {
return cv;
} else {
return null;
}
}
case Aadl2Package.NAMED_VALUE:
{
NamedValue nv = (NamedValue) pe;
AbstractNamedValue anv = nv.getNamedValue();
if (anv instanceof NamedElement) {
NamedElement ne = (NamedElement) anv;
String name = ((NamedElement) anv).getName();
// Consider as a final node.
if (name.equalsIgnoreCase(toBeMatched)) {
return ne;
} else if (// Or a structure.
ne instanceof Property) {
Property p = (Property) ne;
if (p.getDefaultValue() != null) {
tmp = getValue(p.getDefaultValue(), toBeMatched);
return tmp;
}
}
} else {
String msg = anv.getClass().getSimpleName() + " is not supported";
System.err.println(msg);
throw new UnsupportedOperationException(msg);
}
return null;
}
default:
{
String msg = pe.getClass().getSimpleName() + " is not supported";
System.err.println(msg);
throw new UnsupportedOperationException(msg);
}
}
}
Aggregations