Search in sources :

Example 56 with ComponentClassifier

use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.

the class AadlPrototypeUtil method getPrototypeBindingContextByContainer.

public static Element getPrototypeBindingContextByContainer(final BusinessObjectContext queryable) {
    BusinessObjectContext temp = queryable;
    while (temp != null) {
        Object bo = temp.getBusinessObject();
        if (bo instanceof ComponentClassifier || bo instanceof FeatureGroupType) {
            return (Classifier) bo;
        } else if (bo instanceof Subcomponent) {
            return (Subcomponent) bo;
        } else if (bo instanceof FeatureGroup) {
            if (temp.getParent() != null) {
                return getFeatureGroupTypeOrActual(temp.getParent(), (FeatureGroup) bo);
            }
            return null;
        }
        temp = temp.getParent();
    }
    return null;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroup(org.osate.aadl2.FeatureGroup) Subcomponent(org.osate.aadl2.Subcomponent) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 57 with ComponentClassifier

use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.

the class AadlSubcomponentUtil method setClassifier.

public static void setClassifier(final Subcomponent sc, final SubcomponentType selectedSubcomponentType) {
    // Import as necessary
    if (selectedSubcomponentType != null) {
        // Import its package if necessary
        final AadlPackage pkg = (AadlPackage) sc.getElementRoot();
        if (selectedSubcomponentType instanceof ComponentClassifier && selectedSubcomponentType.getNamespace() != null && pkg != null) {
            final PackageSection section = pkg.getPublicSection();
            final AadlPackage selectedClassifierPkg = (AadlPackage) selectedSubcomponentType.getNamespace().getOwner();
            if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
                AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
            }
        }
    }
    if (sc instanceof SystemSubcomponent) {
        ((SystemSubcomponent) sc).setSystemSubcomponentType((SystemSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof AbstractSubcomponent) {
        ((AbstractSubcomponent) sc).setAbstractSubcomponentType((AbstractSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ThreadGroupSubcomponent) {
        ((ThreadGroupSubcomponent) sc).setThreadGroupSubcomponentType((ThreadGroupSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ThreadSubcomponent) {
        ((ThreadSubcomponent) sc).setThreadSubcomponentType((ThreadSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof SubprogramSubcomponent) {
        ((SubprogramSubcomponent) sc).setSubprogramSubcomponentType((SubprogramSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof SubprogramGroupSubcomponent) {
        ((SubprogramGroupSubcomponent) sc).setSubprogramGroupSubcomponentType((SubprogramGroupSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof DataSubcomponent) {
        ((DataSubcomponent) sc).setDataSubcomponentType((DataSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof VirtualBusSubcomponent) {
        ((VirtualBusSubcomponent) sc).setVirtualBusSubcomponentType((VirtualBusSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof VirtualProcessorSubcomponent) {
        ((VirtualProcessorSubcomponent) sc).setVirtualProcessorSubcomponentType((VirtualProcessorSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof BusSubcomponent) {
        ((BusSubcomponent) sc).setBusSubcomponentType((BusSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ProcessSubcomponent) {
        ((ProcessSubcomponent) sc).setProcessSubcomponentType((ProcessSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ProcessorSubcomponent) {
        ((ProcessorSubcomponent) sc).setProcessorSubcomponentType((ProcessorSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof DeviceSubcomponent) {
        ((DeviceSubcomponent) sc).setDeviceSubcomponentType((DeviceSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof MemorySubcomponent) {
        ((MemorySubcomponent) sc).setMemorySubcomponentType((MemorySubcomponentType) selectedSubcomponentType);
    } else {
        throw new RuntimeException("Unexpected type: " + sc.getClass().getName());
    }
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ThreadSubcomponentType(org.osate.aadl2.ThreadSubcomponentType) PackageSection(org.osate.aadl2.PackageSection) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) ProcessorSubcomponentType(org.osate.aadl2.ProcessorSubcomponentType) VirtualProcessorSubcomponentType(org.osate.aadl2.VirtualProcessorSubcomponentType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) AbstractSubcomponentType(org.osate.aadl2.AbstractSubcomponentType) VirtualBusSubcomponentType(org.osate.aadl2.VirtualBusSubcomponentType) BusSubcomponentType(org.osate.aadl2.BusSubcomponentType) DeviceSubcomponent(org.osate.aadl2.DeviceSubcomponent) MemorySubcomponentType(org.osate.aadl2.MemorySubcomponentType) ThreadGroupSubcomponent(org.osate.aadl2.ThreadGroupSubcomponent) SubprogramGroupSubcomponentType(org.osate.aadl2.SubprogramGroupSubcomponentType) ProcessorSubcomponent(org.osate.aadl2.ProcessorSubcomponent) VirtualProcessorSubcomponent(org.osate.aadl2.VirtualProcessorSubcomponent) MemorySubcomponent(org.osate.aadl2.MemorySubcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) VirtualBusSubcomponentType(org.osate.aadl2.VirtualBusSubcomponentType) AadlPackage(org.osate.aadl2.AadlPackage) VirtualBusSubcomponent(org.osate.aadl2.VirtualBusSubcomponent) VirtualProcessorSubcomponent(org.osate.aadl2.VirtualProcessorSubcomponent) BusSubcomponent(org.osate.aadl2.BusSubcomponent) VirtualBusSubcomponent(org.osate.aadl2.VirtualBusSubcomponent) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) ProcessSubcomponent(org.osate.aadl2.ProcessSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent)

Example 58 with ComponentClassifier

use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.

the class AadlUiUtil method getPotentialClassifiersForEditing.

/**
 * Returns a list of classifiers for editing based on a specified business object.
 * If the specified object is of the specified type and passes the filter, only it is returned.
 * @param bo
 * @return
 */
public static <ClassifierType> List<ClassifierType> getPotentialClassifiersForEditing(final Object bo, final Class<ClassifierType> classifierClass, final Predicate<ClassifierType> filter, final boolean includeAllWhenBoIsMatch) {
    if (!includeAllWhenBoIsMatch) {
        if (matches(bo, classifierClass, filter)) {
            return Collections.singletonList(classifierClass.cast(bo));
        }
    }
    final List<ClassifierType> results = new ArrayList<>();
    if (bo instanceof ComponentType || bo instanceof FeatureGroupType) {
        addSelfAndExtended((Classifier) bo, classifierClass, results);
    } else if (bo instanceof ComponentImplementation) {
        final ComponentImplementation ci = (ComponentImplementation) bo;
        addSelfAndExtended(ci, classifierClass, results);
        addSelfAndExtended(ci.getType(), classifierClass, results);
    } else if (bo instanceof Subcomponent) {
        final ComponentClassifier subcomponentClassifier = ((Subcomponent) bo).getAllClassifier();
        addSelfAndExtended(subcomponentClassifier, classifierClass, results);
        if (subcomponentClassifier instanceof ComponentImplementation) {
            addSelfAndExtended(((ComponentImplementation) subcomponentClassifier).getType(), classifierClass, results);
        }
    } else if (bo instanceof FeatureGroup) {
        final FeatureGroupType fgType = ((FeatureGroup) bo).getAllFeatureGroupType();
        addSelfAndExtended(fgType, classifierClass, results);
    }
    return results.stream().filter(c -> classifierClass.isInstance(c)).map(classifierClass::cast).filter(filter).collect(Collectors.toList());
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) Element(org.osate.aadl2.Element) StepResult(org.osate.ge.operations.StepResult) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ComponentClassifier(org.osate.aadl2.ComponentClassifier) IProject(org.eclipse.core.resources.IProject) EClass(org.eclipse.emf.ecore.EClass) Classifier(org.osate.aadl2.Classifier) ComponentType(org.osate.aadl2.ComponentType) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FeatureGroup(org.osate.aadl2.FeatureGroup) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) ElementSelectionDialog(org.osate.ge.aadl2.ui.internal.dialogs.ElementSelectionDialog) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) FeatureGroupType(org.osate.aadl2.FeatureGroupType) List(java.util.List) Window(org.eclipse.jface.window.Window) ComponentCategory(org.osate.aadl2.ComponentCategory) AadlModelAccessUtil(org.osate.ge.aadl2.ui.AadlModelAccessUtil) Optional(java.util.Optional) NamedElement(org.osate.aadl2.NamedElement) OperationBuilder(org.osate.ge.operations.OperationBuilder) Collections(java.util.Collections) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentType(org.osate.aadl2.ComponentType) FeatureGroup(org.osate.aadl2.FeatureGroup) Subcomponent(org.osate.aadl2.Subcomponent) ArrayList(java.util.ArrayList) FeatureGroupType(org.osate.aadl2.FeatureGroupType)

Example 59 with ComponentClassifier

use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.

the class DefaultCreateSelectClassifierDialogModel method validate.

private String validate(final ClassifierOperationPart op, final ClassifierOperationPart baseOperation) {
    if (ClassifierOperationPartType.isCreate(op.getType())) {
        // Check identifier validity
        if (!AadlNamingUtil.isValidIdentifier(op.getIdentifier())) {
            return "The specified identifier is not a valid AADL identifier";
        }
        // Check component category
        if (ClassifierOperationPartType.isComponentClassifierCreate(op.getType())) {
            if (op.getComponentCategory() == null) {
                return "Select a component category.";
            }
            if (baseOperation != null && baseOperation.getType() == ClassifierOperationPartType.EXISTING) {
                // Check for a compatible component category when selecting an existing base classifier
                final Classifier baseClassifier = classifierCreationHelper.getResolvedClassifier(baseOperation.getSelectedClassifier());
                if (baseClassifier instanceof ComponentClassifier) {
                    final ComponentClassifier baseCategory = (ComponentClassifier) baseClassifier;
                    if (baseCategory.getCategory() != op.getComponentCategory() && (op.getType() != ClassifierOperationPartType.NEW_COMPONENT_TYPE || baseCategory.getCategory() != ComponentCategory.ABSTRACT)) {
                        return "Base: category(" + baseCategory.getCategory() + ") of the selected classifier is not compatible with category type of the " + StringUtil.snakeCaseToLowercaseWords(op.getType().name()) + "(" + op.getComponentCategory() + ").";
                    }
                }
            }
        }
        // Check package.
        final AadlPackage pkg = classifierCreationHelper.getResolvedPackage(op.getSelectedPackage());
        if (pkg == null) {
            return "Select a package.";
        }
        final PackageSection section = pkg.getPublicSection();
        if (section == null) {
            return "Unable to retrieve public section of package.";
        }
        // New Component Implementation validation
        if (op.getType() == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
            if (baseOperation == null) {
                return "Base classifier is invalid";
            } else if (!ClassifierOperationPartType.isCreate(baseOperation.getType()) && baseOperation.getType() != ClassifierOperationPartType.EXISTING) {
                if (baseOperation.getType() == ClassifierOperationPartType.NONE) {
                    return "Select a base for the new component implementation.";
                } else {
                    return "Invalid base classifier: " + baseOperation.getType();
                }
            }
        }
        final String newName = classifierCreationHelper.getName(op, baseOperation);
        if (newName == null) {
            return "Unable to build name. Check for model errors.";
        }
        // Check if the name is in use
        if (AadlNamingUtil.isNameInUse(section, newName)) {
            return "The specified name conflicts with an existing member of the package.";
        }
    } else if (op.getType() == ClassifierOperationPartType.EXISTING) {
        // Check that the classifier can be resolved.
        if (classifierCreationHelper.getResolvedClassifier(op.getSelectedClassifier()) == null) {
            return "Select a classifier.";
        }
    } else if (op.getType() == null) {
        return "Select a classifier type.";
    }
    return null;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier)

Example 60 with ComponentClassifier

use of org.osate.aadl2.ComponentClassifier in project osate2 by osate.

the class PrototypesModel method setPrototypeType.

@Override
public void setPrototypeType(final EditablePrototype prototype, final PrototypeType value) {
    // Check if the type is different by comparing EClass values
    final EClass currentEClass = prototype.prototype.eClass();
    final EClass newEClass = prototypeTypeToEClass(value);
    if (newEClass == currentEClass) {
        return;
    }
    modifyOwningClassifier("Set Prototype Type", prototype, c -> {
        getPrototypeByName(c, prototype.name).ifPresent(p -> {
            // Store location in list
            final int index = c.getOwnedPrototypes().indexOf(p);
            if (index == -1) {
                throw new RuntimeException("Unable to get index of prototype being modified");
            }
            // Store fields
            final String name = p.getName();
            final Prototype refined = p.getRefined();
            ComponentClassifier cc = null;
            FeatureGroupType fgt = null;
            boolean in = false;
            boolean out = false;
            boolean array = false;
            if (p instanceof ComponentPrototype) {
                final ComponentPrototype cp = (ComponentPrototype) p;
                cc = cp.getConstrainingClassifier();
                array = cp.isArray();
            } else if (p instanceof FeatureGroupPrototype) {
                final FeatureGroupPrototype fp = (FeatureGroupPrototype) p;
                fgt = fp.getConstrainingFeatureGroupType();
            } else if (p instanceof FeaturePrototype) {
                final FeaturePrototype fp = (FeaturePrototype) p;
                cc = fp.getConstrainingClassifier();
                in = fp.isIn();
                out = fp.isOut();
            }
            // Create new prototype
            final Prototype newPrototype = (Prototype) EcoreUtil.create(newEClass);
            c.getOwnedPrototypes().add(index, newPrototype);
            if (refined == null) {
                newPrototype.setName(name);
            } else {
                newPrototype.setRefined(refined);
            }
            // Set fields
            if (newPrototype instanceof ComponentPrototype) {
                final ComponentPrototype cp = (ComponentPrototype) newPrototype;
                cp.setConstrainingClassifier(cc);
                cp.setArray(array);
            } else if (newPrototype instanceof FeatureGroupPrototype) {
                final FeatureGroupPrototype fp = (FeatureGroupPrototype) newPrototype;
                fp.setConstrainingFeatureGroupType(fgt);
            } else if (newPrototype instanceof FeaturePrototype) {
                final FeaturePrototype fp = (FeaturePrototype) newPrototype;
                fp.setConstrainingClassifier(cc);
                fp.setIn(in);
                fp.setOut(out);
            }
            // Move property associations
            newPrototype.getOwnedPropertyAssociations().addAll(p.getOwnedPropertyAssociations());
            // Remove old prototype
            EcoreUtil.remove(p);
        });
    });
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentClassifier(org.osate.aadl2.ComponentClassifier) EClass(org.eclipse.emf.ecore.EClass) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) BusPrototype(org.osate.aadl2.BusPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ProcessorPrototype(org.osate.aadl2.ProcessorPrototype) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) EditablePrototype(org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype) DataPrototype(org.osate.aadl2.DataPrototype) MemoryPrototype(org.osate.aadl2.MemoryPrototype) Prototype(org.osate.aadl2.Prototype) ThreadPrototype(org.osate.aadl2.ThreadPrototype) VirtualProcessorPrototype(org.osate.aadl2.VirtualProcessorPrototype) SystemPrototype(org.osate.aadl2.SystemPrototype) VirtualBusPrototype(org.osate.aadl2.VirtualBusPrototype) ProcessPrototype(org.osate.aadl2.ProcessPrototype) ThreadGroupPrototype(org.osate.aadl2.ThreadGroupPrototype) SubprogramGroupPrototype(org.osate.aadl2.SubprogramGroupPrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) DevicePrototype(org.osate.aadl2.DevicePrototype) AbstractPrototype(org.osate.aadl2.AbstractPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

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