Search in sources :

Example 11 with ComponentClassifier

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);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Subcomponent(org.osate.aadl2.Subcomponent) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 12 with ComponentClassifier

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;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) Mode(org.osate.aadl2.Mode) Subcomponent(org.osate.aadl2.Subcomponent) ArrayList(java.util.ArrayList) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier)

Example 13 with ComponentClassifier

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());
                    }
                }
            }
        }
    }
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) Mode(org.osate.aadl2.Mode) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property)

Example 14 with ComponentClassifier

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);
        }
    });
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) AadlPackage(org.osate.aadl2.AadlPackage) FeaturePrototype(org.osate.aadl2.FeaturePrototype) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 15 with ComponentClassifier

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);
            }
        }
    }));
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ArrayList(java.util.ArrayList) SimpleModifier(org.osate.ge.internal.services.AadlModificationService.SimpleModifier) EObject(org.eclipse.emf.ecore.EObject) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

ComponentClassifier (org.osate.aadl2.ComponentClassifier)76 Subcomponent (org.osate.aadl2.Subcomponent)26 Classifier (org.osate.aadl2.Classifier)22 EObject (org.eclipse.emf.ecore.EObject)19 NamedElement (org.osate.aadl2.NamedElement)19 ComponentImplementation (org.osate.aadl2.ComponentImplementation)16 ArrayList (java.util.ArrayList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)14 AadlPackage (org.osate.aadl2.AadlPackage)13 FeatureGroupType (org.osate.aadl2.FeatureGroupType)12 List (java.util.List)11 ComponentPrototype (org.osate.aadl2.ComponentPrototype)11 Element (org.osate.aadl2.Element)11 ComponentType (org.osate.aadl2.ComponentType)10 Feature (org.osate.aadl2.Feature)9 Mode (org.osate.aadl2.Mode)8 BusinessObjectContext (org.osate.ge.BusinessObjectContext)8 Collectors (java.util.stream.Collectors)7 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 ComponentCategory (org.osate.aadl2.ComponentCategory)7