Search in sources :

Example 56 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class CombinedErrorModelSubclause method create.

/**
 * Creates an instance for the specified classifier. Processes error model subclauses owned or inherited by the classifier.
 * @param classifier the classifier for which to create the instance.
 * @return the new instance
 */
public static CombinedErrorModelSubclause create(final Classifier classifier) {
    final Map<String, PropagationPoint> points = new HashMap<>();
    final Map<String, PropagationPath> paths = new HashMap<>();
    final Map<String, ErrorFlow> flows = new HashMap<>();
    final PropagationNode propagations = new PropagationNode();
    final Set<KeywordPropagationPointType> usedKeywordPointTypes = new HashSet<>();
    final EList<Classifier> classifiers = classifier.getSelfPlusAllExtended();
    if (classifier instanceof ComponentImplementation) {
        final ComponentType ct = ((ComponentImplementation) classifier).getType();
        if (ct != null) {
            classifiers.addAll(ct.getSelfPlusAllExtended());
        }
    }
    final boolean[] subclauseFound = { false };
    for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
        ErrorModelGeUtil.getAllErrorModelSubclauses(tmpClassifier).forEachOrdered(subclause -> {
            subclauseFound[0] = true;
            addAllToMap(subclause.getPoints(), points);
            addAllToMap(subclause.getPaths(), paths);
            addAllToMap(subclause.getFlows(), flows);
            // Create a tree for error propagations
            for (final ErrorPropagation propagation : subclause.getPropagations()) {
                propagations.put(propagation);
            }
            // 
            for (final ErrorPropagation propagation : subclause.getPropagations()) {
                if (propagation.getKind() != null) {
                    usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(propagation.getKind()));
                }
            }
            for (final ErrorFlow errorFlow : subclause.getFlows()) {
                if (errorFlow instanceof ErrorPath) {
                    final ErrorPath errorPath = (ErrorPath) errorFlow;
                    if (errorPath.isAllIncoming() || errorPath.isAllOutgoing()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    }
                    if (errorPath.getIncoming() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getIncoming().getKind()));
                    }
                    if (errorPath.getOutgoing() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorPath.getOutgoing().getKind()));
                    }
                } else if (errorFlow instanceof ErrorSink) {
                    final ErrorSink errorSink = (ErrorSink) errorFlow;
                    if (errorSink.isAllIncoming()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    } else if (errorSink.getIncoming() != null) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(errorSink.getIncoming().getKind()));
                    }
                } else if (errorFlow instanceof ErrorSource) {
                    final ErrorSource errorSrc = (ErrorSource) errorFlow;
                    if (errorSrc.isAll()) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.ALL);
                    } else if (errorSrc.getSourceModelElement() instanceof ErrorPropagation) {
                        usedKeywordPointTypes.add(KeywordPropagationPointType.getByKind(((ErrorPropagation) errorSrc.getSourceModelElement()).getKind()));
                    }
                }
            }
        });
    }
    return new CombinedErrorModelSubclause(subclauseFound[0], points, paths, flows, usedKeywordPointTypes, propagations);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) PropagationPath(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath) ComponentType(org.osate.aadl2.ComponentType) HashMap(java.util.HashMap) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) Classifier(org.osate.aadl2.Classifier) ErrorSink(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSink) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) ErrorPath(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPath) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation) KeywordPropagationPointType(org.osate.ge.errormodel.model.KeywordPropagationPointType) HashSet(java.util.HashSet)

Example 57 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType 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 58 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class ClassifierOperationExecutor method addStep.

/**
 * @param operation
 * @param part
 * @param basePart
 * @param pkgBoc if non-null then the operation result will indicate that the object should be added to the diagram.
 * @return
 */
private OperationBuilder<Classifier> addStep(final OperationBuilder<?> operation, final ClassifierOperationPart part, final ClassifierOperationPart basePart, final BusinessObjectContext pkgBoc) {
    Objects.requireNonNull(part, "part must not be null");
    Objects.requireNonNull(part.getType(), "operation part type must not be null");
    switch(part.getType()) {
        case EXISTING:
            return operation.supply(() -> StepResultBuilder.create(classifierCreationHelper.getResolvedClassifier(part.getSelectedClassifier())).build());
        case NEW_COMPONENT_IMPLEMENTATION:
        case NEW_COMPONENT_TYPE:
        case NEW_FEATURE_GROUP_TYPE:
            final EClass creationEClass = getCreationEClass(part);
            final PackageSection unmodifiableSection = classifierCreationHelper.getResolvedPublicSection(part.getSelectedPackage());
            return operation.modifyModel(unmodifiableSection, (tag, prevResult) -> tag, (tag, section, prevResult) -> {
                // Create the new classifier
                final Classifier newClassifier = section.createOwnedClassifier(creationEClass);
                // Set name
                newClassifier.setName(classifierCreationHelper.getName(part, basePart));
                final Classifier baseOperationResult = resolveWithLiveResourceSetOrThrowIfProxy((Classifier) prevResult);
                // Handle component implementations
                if (newClassifier instanceof ComponentImplementation) {
                    final ComponentImplementation newImpl = (ComponentImplementation) newClassifier;
                    final ComponentType baseComponentType;
                    if (baseOperationResult instanceof ComponentType) {
                        final Realization realization = newImpl.createOwnedRealization();
                        baseComponentType = (ComponentType) baseOperationResult;
                        realization.setImplemented(baseComponentType);
                    } else if (baseOperationResult instanceof ComponentImplementation) {
                        final ComponentImplementation baseImpl = (ComponentImplementation) baseOperationResult;
                        final ImplementationExtension extension = newImpl.createOwnedExtension();
                        extension.setExtended(baseImpl);
                        final Realization realization = newImpl.createOwnedRealization();
                        realization.setImplemented(baseImpl.getType());
                        baseComponentType = baseImpl.getType();
                        // Import the base implementation's package
                        final AadlPackage baseImplPkg = (AadlPackage) baseImpl.getNamespace().getOwner();
                        AadlImportsUtil.addImportIfNeeded(section, baseImplPkg);
                    } else {
                        throw new RuntimeException("Invalid base classifier: " + baseOperationResult);
                    }
                    // Get the base component type
                    if (baseComponentType == null) {
                        throw new RuntimeException("Unable to determine base component type");
                    }
                    if (!AadlNameUtil.namesAreEqual(section, baseComponentType.getNamespace())) {
                        // Import the package if necessary
                        final AadlPackage baseComponentTypePkg = (AadlPackage) baseComponentType.getNamespace().getOwner();
                        AadlImportsUtil.addImportIfNeeded(section, baseComponentTypePkg);
                        // Create an alias for the component type
                        final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, baseComponentTypePkg, baseComponentType.getName());
                        if (!aliasDetails.exists) {
                            final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
                            ctr.setName(aliasDetails.aliasName);
                            ctr.setCategory(baseComponentType.getCategory());
                            ctr.setRenamedComponentType(baseComponentType);
                        }
                    }
                } else if (newClassifier instanceof ComponentType && baseOperationResult instanceof ComponentType) {
                    final ComponentType newType = (ComponentType) newClassifier;
                    final TypeExtension extension = newType.createOwnedExtension();
                    extension.setExtended((ComponentType) baseOperationResult);
                } else if (newClassifier instanceof FeatureGroupType && baseOperationResult instanceof FeatureGroupType) {
                    final FeatureGroupType newFgt = (FeatureGroupType) newClassifier;
                    final GroupExtension extension = newFgt.createOwnedExtension();
                    extension.setExtended((FeatureGroupType) baseOperationResult);
                }
                final StepResultBuilder<Classifier> resultBuilder = StepResultBuilder.create(newClassifier);
                // Hint for adding to diagram
                if (pkgBoc != null && newClassifier != null) {
                    resultBuilder.showNewBusinessObject(pkgBoc, newClassifier);
                }
                return resultBuilder.build();
            });
        case NONE:
            return operation.map(prevResult -> StepResultBuilder.create((Classifier) null).build());
        default:
            throw new RuntimeException("Unexpected operation: " + part.getType());
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) FeatureGroupType(org.osate.aadl2.FeatureGroupType) TypeExtension(org.osate.aadl2.TypeExtension) ImplementationExtension(org.osate.aadl2.ImplementationExtension) Classifier(org.osate.aadl2.Classifier) EClass(org.eclipse.emf.ecore.EClass) Realization(org.osate.aadl2.Realization) GroupExtension(org.osate.aadl2.GroupExtension) ComponentTypeRename(org.osate.aadl2.ComponentTypeRename)

Example 59 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class InstantiateModel method populateComponentInstance.

// --------------------------------------------------------------------------------------------
// Methods for instantiating the component hierarchy
// --------------------------------------------------------------------------------------------
/*
	 * Fill in modes, transitions, subcomponent instances, features, flow specs.
	 */
protected void populateComponentInstance(ComponentInstance ci, int index) throws InterruptedException {
    ComponentImplementation impl = getComponentImplementation(ci);
    ComponentType type = getComponentType(ci);
    if (ci.getContainingComponentInstance() instanceof SystemInstance) {
        monitor.subTask("Creating instances in " + ci.getName());
    }
    /*
		 * Add modes. Must do this before adding subcomponents
		 * because we need to know what are the ModeInstances when processing
		 * modal subcomponents.
		 */
    if (impl != null) {
        fillModes(ci, impl.getAllModes());
    } else if (type != null) {
        fillModes(ci, type.getAllModes());
    }
    if (impl != null) {
        // Recursively add subcomponents
        instantiateSubcomponents(ci, impl);
    // TODO now add subprogram calls
    // EList callseqlist = compimpl.getXAllCallSequence();
    // for (Iterator it = callseqlist.iterator(); it.hasNext();) {
    // CallSequence cseq = (CallSequence) it.next();
    // 
    // EList calllist = cseq.getCall();
    // for (Iterator iit = calllist.iterator(); iit.hasNext();) {
    // final SubprogramSubcomponent call =
    // (SubprogramSubcomponent) iit.next();
    // instantiateSubcomponent(ci, cseq, call);
    // }
    // }
    }
    // do it only if subcomponent has type
    if (type != null) {
        instantiateFeatures(ci);
    }
    /*
		 * Add mode transitions. Must do this after adding subcomponents
		 * because we need reference subcomponent features as triggers.
		 */
    if (impl != null) {
        fillModeTransitions(ci, impl.getAllModeTransitions());
    } else if (type != null) {
        fillModeTransitions(ci, type.getAllModeTransitions());
    }
    if (type != null) {
        instantiateFlowSpecs(ci);
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 60 with ComponentType

use of org.geotoolkit.sml.xml.v100.ComponentType in project osate2 by osate.

the class PropertiesValidator method checkInheritedMissingModes.

public void checkInheritedMissingModes(Classifier classifier) {
    List<Mode> allModes = new ArrayList<Mode>();
    List<PropertyAssociation> propertyAssociations = new ArrayList<PropertyAssociation>();
    List<PropertyAssociation> ownedPropertyAssociations = new ArrayList<PropertyAssociation>();
    List<Property> ownedProperties = new ArrayList<Property>();
    Element warningTarget = null;
    if (classifier instanceof ComponentImplementation) {
        ComponentImplementation componentImpl = (ComponentImplementation) classifier;
        if (null == componentImpl.getExtended()) {
            return;
        }
        allModes = componentImpl.getAllModes();
        propertyAssociations = componentImpl.getAllPropertyAssociations();
        ownedPropertyAssociations = componentImpl.getOwnedPropertyAssociations();
        ownedProperties = new ArrayList<Property>();
        warningTarget = componentImpl.getOwnedExtension();
    } else if (classifier instanceof ComponentType) {
        ComponentType componentType = (ComponentType) classifier;
        if (null == componentType.getExtended()) {
            return;
        }
        allModes = componentType.getAllModes();
        propertyAssociations = componentType.getAllPropertyAssociations();
        ownedPropertyAssociations = componentType.getOwnedPropertyAssociations();
        ownedProperties = new ArrayList<Property>();
        warningTarget = componentType.getOwnedExtension();
    }
    for (PropertyAssociation ownedPropertyAssociation : ownedPropertyAssociations) {
        ownedProperties.add(ownedPropertyAssociation.getProperty());
    }
    Map<Property, List<Mode>> propModesMap = buildPropertySetForModeMap(allModes, propertyAssociations);
    for (Property keyProperty : propModesMap.keySet()) {
        if (ownedProperties.contains(keyProperty)) {
            continue;
        }
        List<Mode> mappedModes = propModesMap.get(keyProperty);
        for (Mode nextMode : allModes) {
            if (!mappedModes.contains(nextMode)) {
                warning(warningTarget, "Value not set for mode " + nextMode.getName() + " for property " + keyProperty.getQualifiedName());
            }
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) Mode(org.osate.aadl2.Mode) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) 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)

Aggregations

ComponentType (org.osate.aadl2.ComponentType)73 ComponentImplementation (org.osate.aadl2.ComponentImplementation)42 Classifier (org.osate.aadl2.Classifier)33 ComponentClassifier (org.osate.aadl2.ComponentClassifier)21 ArrayList (java.util.ArrayList)18 EObject (org.eclipse.emf.ecore.EObject)16 NamedElement (org.osate.aadl2.NamedElement)15 AnnexSubclause (org.osate.aadl2.AnnexSubclause)13 Feature (org.osate.aadl2.Feature)13 BasicEList (org.eclipse.emf.common.util.BasicEList)11 AadlPackage (org.osate.aadl2.AadlPackage)11 HashSet (java.util.HashSet)10 FeatureGroupType (org.osate.aadl2.FeatureGroupType)10 List (java.util.List)9 Subcomponent (org.osate.aadl2.Subcomponent)8 FeatureGroup (org.osate.aadl2.FeatureGroup)7 EList (org.eclipse.emf.common.util.EList)6 Property (org.osate.aadl2.Property)6 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)6 GetPropertyExpr (com.rockwellcollins.atc.agree.agree.GetPropertyExpr)5