use of org.osate.aadl2.ContainedNamedElement in project osate2 by osate.
the class SetBindingTool method createPropertyAssociations.
private void createPropertyAssociations(final AadlModificationService aadlModService) {
final BusinessObjectContext ciBoc = currentWindow.getComponentImplementationBoc();
final ComponentImplementation ci = (ComponentImplementation) ciBoc.getBusinessObject();
aadlModService.modify(Modification.create(ci, new SimpleModifier<ComponentClassifier>() {
@Override
public void modify(final ComponentClassifier ci) {
for (final BusinessObjectContext bocToBind : currentWindow.getBocsToBind()) {
final PropertyAssociation newPa = AgeAadlUtil.getAadl2Factory().createPropertyAssociation();
// Set property
newPa.setProperty(currentWindow.getSelectedProperty());
// Set applies to
if (ciBoc != bocToBind) {
setContainedNamedElementPath(newPa.createAppliesTo(), ciBoc, bocToBind);
}
// Create owned values
final ModalPropertyValue pv = newPa.createOwnedValue();
final ListValue lv = (ListValue) pv.createOwnedValue(Aadl2Package.eINSTANCE.getListValue());
for (final BusinessObjectContext targetBoc : currentWindow.getTargetBocs()) {
// Ignore diagram selections
final ReferenceValue rv = (ReferenceValue) lv.createOwnedListElement(Aadl2Package.eINSTANCE.getReferenceValue());
setContainedNamedElementPath(rv, ciBoc, targetBoc);
}
removeOldPropertyAssociation(ci, newPa);
// Add the property association
ci.setNoProperties(false);
ci.getOwnedPropertyAssociations().add(newPa);
}
}
// Deletes any existing property associations/removes the bound element from any property associations that matches the property association
// being created.
private void removeOldPropertyAssociation(final ComponentClassifier cc, final PropertyAssociation newPa) {
final List<PropertyAssociation> propertyAssociationsToDelete = new ArrayList<PropertyAssociation>();
for (final PropertyAssociation existingPa : cc.getOwnedPropertyAssociations()) {
// If Property matches
if (newPa.getProperty().getFullName().equals(existingPa.getProperty().getFullName())) {
if (existingPa.getAppliesTos().size() == 0 || newPa.getAppliesTos().size() == 0) {
if (existingPa.getAppliesTos().size() == 0 && newPa.getAppliesTos().size() == 0) {
propertyAssociationsToDelete.add(existingPa);
}
} else {
final List<ContainedNamedElement> containedElementsToDelete = new ArrayList<ContainedNamedElement>();
for (final ContainedNamedElement existingContainedElement : existingPa.getAppliesTos()) {
if (containmentPathsMatch(existingContainedElement.getPath(), newPa.getAppliesTos().get(0).getPath())) {
// Add the contained element to the list of objects to delete
containedElementsToDelete.add(existingContainedElement);
}
}
// Delete objects
for (final EObject ce : containedElementsToDelete) {
EcoreUtil.delete(ce);
}
// Delete the property association if it was the last element in the applies to clause
if (existingPa.getAppliesTos().size() == 0) {
propertyAssociationsToDelete.add(existingPa);
}
}
}
}
// Delete property association(s) that are being replaced
for (final PropertyAssociation pa : propertyAssociationsToDelete) {
EcoreUtil.delete(pa);
}
}
}));
}
use of org.osate.aadl2.ContainedNamedElement in project osate2 by osate.
the class EMV2Properties method isErrorModelElementProperty.
/**
* return the containment path if the stack combined with the target and optionally the type set match the containment path of a property association.
* It is sufficient for one of the paths in the PA to match.
* ciStack represents the path from the context of the PA to the component instance whose property we want to retrieve
* The desired type set ts must be contained in the type set named in the containment path
* @param propertyAssociation PropertyAssociation that is the candidate
* @param ciStack (can be null or empty) ComponentInstance in instance model hierarchy with the error model element, whose property we are retrieving (or null)
* @param target Element the target object in the error model whose property we retrieve
* @param ts type set that must contain the last element if it is a type
* @return ContainedNamedElement the containment path that matches
*/
public static EMV2PropertyAssociation isErrorModelElementProperty(EMV2PropertyAssociation propertyAssociation, NamedElement target, Stack<NamedElement> ciStack, ErrorTypes ts) {
boolean matchStack = false;
EList<EMV2Path> applies = propertyAssociation.getEmv2Path();
for (EMV2Path emv2Path : applies) {
ContainmentPathElement cp = emv2Path.getContainmentPath();
if (cp != null) {
matchStack = matchCIStack(ciStack, cp);
} else {
matchStack = matchCIStack(ciStack, emv2Path.getEmv2Target());
}
if (matchStack) {
// we are past the component portion of the path
String targetName = EMV2Util.getPrintName(target);
NamedElement pathTargetEME = EMV2Util.getErrorModelElement(emv2Path);
String pathName = EMV2Util.getPrintName(pathTargetEME);
if (targetName.equalsIgnoreCase(pathName)) {
ErrorTypes typeelement = EMV2Util.getErrorType(emv2Path);
if (typeelement != null && ts != null) {
// check to see if the desired ts is contained in the PA containment path
if (EMV2TypeSetUtil.contains(ts, typeelement) || EMV2TypeSetUtil.contains(typeelement, ts)) {
return propertyAssociation;
}
} else {
return propertyAssociation;
}
}
}
}
return null;
}
use of org.osate.aadl2.ContainedNamedElement in project osate2 by osate.
the class AbstractPropertiesSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == Aadl2Package.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case Aadl2Package.ARRAY_RANGE:
sequence_ArrayRange(context, (ArrayRange) semanticObject);
return;
case Aadl2Package.BASIC_PROPERTY_ASSOCIATION:
sequence_FieldPropertyAssociation(context, (BasicPropertyAssociation) semanticObject);
return;
case Aadl2Package.BOOLEAN_LITERAL:
sequence_BooleanLiteral(context, (BooleanLiteral) semanticObject);
return;
case Aadl2Package.CLASSIFIER_VALUE:
sequence_ComponentClassifierTerm(context, (ClassifierValue) semanticObject);
return;
case Aadl2Package.COMPUTED_VALUE:
sequence_ComputedTerm(context, (ComputedValue) semanticObject);
return;
case Aadl2Package.CONTAINED_NAMED_ELEMENT:
sequence_ContainmentPath(context, (ContainedNamedElement) semanticObject);
return;
case Aadl2Package.CONTAINMENT_PATH_ELEMENT:
sequence_ContainmentPathElement(context, (ContainmentPathElement) semanticObject);
return;
case Aadl2Package.INTEGER_LITERAL:
sequence_IntegerTerm(context, (IntegerLiteral) semanticObject);
return;
case Aadl2Package.LIST_VALUE:
sequence_ListTerm(context, (ListValue) semanticObject);
return;
case Aadl2Package.MODAL_PROPERTY_VALUE:
if (rule == grammarAccess.getModalPropertyValueRule()) {
sequence_ModalPropertyValue(context, (ModalPropertyValue) semanticObject);
return;
} else if (rule == grammarAccess.getOptionalModalPropertyValueRule()) {
sequence_OptionalModalPropertyValue(context, (ModalPropertyValue) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyValueRule()) {
sequence_PropertyValue(context, (ModalPropertyValue) semanticObject);
return;
} else
break;
case Aadl2Package.NAMED_VALUE:
if (rule == grammarAccess.getConstantValueRule() || rule == grammarAccess.getNumAltRule()) {
sequence_ConstantValue(context, (NamedValue) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getLiteralorReferenceTermRule()) {
sequence_LiteralorReferenceTerm(context, (NamedValue) semanticObject);
return;
} else
break;
case Aadl2Package.OPERATION:
sequence_SignedConstant(context, (Operation) semanticObject);
return;
case Aadl2Package.PROPERTY_ASSOCIATION:
if (rule == grammarAccess.getBasicPropertyAssociationRule()) {
sequence_BasicPropertyAssociation(context, (PropertyAssociation) semanticObject);
return;
} else if (rule == grammarAccess.getPModelRule() || rule == grammarAccess.getContainedPropertyAssociationRule()) {
sequence_ContainedPropertyAssociation(context, (PropertyAssociation) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyAssociationRule()) {
sequence_PropertyAssociation(context, (PropertyAssociation) semanticObject);
return;
} else
break;
case Aadl2Package.RANGE_VALUE:
sequence_NumericRangeTerm(context, (RangeValue) semanticObject);
return;
case Aadl2Package.REAL_LITERAL:
sequence_RealTerm(context, (RealLiteral) semanticObject);
return;
case Aadl2Package.RECORD_VALUE:
if (rule == grammarAccess.getOldRecordTermRule()) {
sequence_OldRecordTerm(context, (RecordValue) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getRecordTermRule()) {
sequence_RecordTerm(context, (RecordValue) semanticObject);
return;
} else
break;
case Aadl2Package.REFERENCE_VALUE:
sequence_ReferenceTerm(context, (ReferenceValue) semanticObject);
return;
case Aadl2Package.STRING_LITERAL:
sequence_StringTerm(context, (StringLiteral) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.osate.aadl2.ContainedNamedElement in project osate2 by osate.
the class PropertyUtils method getContainedSimplePropertyValue.
/**
* get a property association from the properties section of the containing classifier if the context.
* This method has been designed to work with end points of connections, i.e., consisting of a target and a context.
* The context must be a NamedElement in its containing classifier, i.e., a feature, feature group, subcomponent.
* The property holder is assumed to be contained in the context object, e.g., a feature in afeature group or a data subcomponent in a port, or feature in a subcomponent.
* The association must match the property definition.
* if the context is null then the containing classifier of the target is used and the path must be one or no path.
* The applies to clause of the property association must be of size 2 if the context is set and point to the context and then the property holder.
* The property value of the property association is assumed not to be modal.
* @param context NamedElement whose containing classifier's properties section is searched for the desired property
* @param target NamedElement the model element to which the property is applied to via the applies to clause
* @param pd Property the property definition
* @return
*/
public static PropertyExpression getContainedSimplePropertyValue(final NamedElement context, final NamedElement target, final Property pd) {
if (context == null) {
return target.getNonModalPropertyValue(pd);
}
Classifier cl = AadlUtil.getContainingClassifier(context);
EList<PropertyAssociation> props = cl.getAllPropertyAssociations();
for (PropertyAssociation propertyAssociation : props) {
if (propertyAssociation.getProperty().equals(pd)) {
// we found a property with the corect type
// now we need to check whether the applies to points to the holder
EList<ContainedNamedElement> appliestos = propertyAssociation.getAppliesTos();
for (ContainedNamedElement containedNamedElement : appliestos) {
EList<ContainmentPathElement> cpes = containedNamedElement.getContainmentPathElements();
if (cpes.size() == 2) {
NamedElement pathcxt = cpes.get(0).getNamedElement();
NamedElement pathelement = cpes.get(1).getNamedElement();
if (context.equals(pathcxt) && target.equals(pathelement)) {
EList<ModalPropertyValue> vallist = propertyAssociation.getOwnedValues();
if (!vallist.isEmpty()) {
ModalPropertyValue elem = vallist.get(0);
PropertyExpression res = elem.getOwnedValue();
if (res instanceof NamedValue) {
AbstractNamedValue nv = ((NamedValue) res).getNamedValue();
if (nv instanceof Property) {
res = target.getNonModalPropertyValue((Property) nv);
} else if (nv instanceof PropertyConstant) {
res = ((PropertyConstant) nv).getConstantValue();
}
}
return res;
}
}
}
}
}
}
return null;
}
use of org.osate.aadl2.ContainedNamedElement 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;
}
Aggregations