use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class AadlClassifierUtil method getComponentClassifier.
/**
* Returns a component classifier for a specified business object. Only component implementations and subcomponents are supported.
* @param bo
* @return
*/
public static Optional<ComponentClassifier> getComponentClassifier(final Object bo) {
final ComponentClassifier ci;
if (bo instanceof BusinessObjectContext) {
return getComponentClassifier(((BusinessObjectContext) bo).getBusinessObject());
} else if (bo instanceof ComponentImplementation) {
ci = (ComponentImplementation) bo;
} else if (bo instanceof Subcomponent) {
final ComponentClassifier scClassifier = ((Subcomponent) bo).getAllClassifier();
ci = scClassifier instanceof ComponentClassifier ? scClassifier : null;
} else {
ci = null;
}
return Optional.ofNullable(ci);
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class PropertiesValidator method getMasterModes.
public List<Mode> getMasterModes(ContainedNamedElement cne) {
List<Mode> masterModes = new ArrayList<Mode>();
ComponentClassifier componentClassifier = null;
Subcomponent lastSubcomponent = getLastSubcomponent(cne);
if (null == lastSubcomponent) {
Classifier classifier = cne.getContainingClassifier();
if (classifier instanceof ComponentClassifier) {
componentClassifier = (ComponentClassifier) classifier;
}
} else {
componentClassifier = lastSubcomponent.getAllClassifier();
if (null != componentClassifier) {
masterModes = componentClassifier.getAllModes();
}
}
if (null != componentClassifier) {
masterModes = componentClassifier.getAllModes();
}
return masterModes;
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class PropertiesValidator method checkSubcomponentMissingModeValues.
public void checkSubcomponentMissingModeValues(Subcomponent subcomponent) {
ComponentClassifier subcompClassifier = subcomponent.getAllClassifier();
List<Mode> allModes = new ArrayList<Mode>();
List<PropertyAssociation> ownedPropertyAssociations = new ArrayList<PropertyAssociation>();
List<Property> ownedProperties = new ArrayList<Property>();
if (subcompClassifier != null) {
allModes = subcompClassifier.getAllModes();
ownedPropertyAssociations = subcomponent.getOwnedPropertyAssociations();
ownedProperties = new ArrayList<Property>();
}
for (PropertyAssociation ownedPropertyAssociation : ownedPropertyAssociations) {
ownedProperties.add(ownedPropertyAssociation.getProperty());
}
Map<Property, List<Mode>> propModesMap = buildPropertySetForModeMap(allModes, ownedPropertyAssociations);
for (PropertyAssociation ownedPropertyAssociation : ownedPropertyAssociations) {
for (Property keyProperty : propModesMap.keySet()) {
if (keyProperty.equals(ownedPropertyAssociation.getProperty())) {
List<Mode> mappedModes = propModesMap.get(keyProperty);
for (Mode nextMode : allModes) {
if (!mappedModes.contains(nextMode)) {
warning(ownedPropertyAssociation, "Value not set for mode " + nextMode.getName() + " for property " + keyProperty.getQualifiedName());
}
}
}
}
}
}
use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.
the class PrototypesModel method setConstrainingClassifier.
@Override
public void setConstrainingClassifier(final EditablePrototype prototype, final NamedElementOrDescription value) {
modifyPrototype("Set Constraining Classifier", prototype, p -> {
final EObject classifier = value.getResolvedValue(prototype.prototype.eResource().getResourceSet());
if (classifier != null) {
// Import its package if necessary
final AadlPackage pkg = (AadlPackage) p.getElementRoot();
if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
final PackageSection section = pkg.getPublicSection();
final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
}
}
}
// Update the classifier
if (p instanceof ComponentPrototype) {
((ComponentPrototype) p).setConstrainingClassifier((ComponentClassifier) classifier);
} else if (p instanceof FeatureGroupPrototype) {
((FeatureGroupPrototype) p).setConstrainingFeatureGroupType((FeatureGroupType) classifier);
} else if (p instanceof FeaturePrototype) {
((FeaturePrototype) p).setConstrainingClassifier((ComponentClassifier) classifier);
}
});
}
use of org.osate.aadl2.ComponentClassifier 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);
}
}
}));
}
Aggregations