Search in sources :

Example 1 with ErrorBehaviorEvent

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent in project osate2 by osate.

the class ErrorModelValidator method checkConditionElementType.

private void checkConditionElementType(ConditionElement conditionElement) {
    EventOrPropagation ep = EMV2Util.getErrorEventOrPropagation(conditionElement);
    if (ep == null) {
        return;
    }
    TypeSet triggerTS = null;
    String triggerName = "";
    if (ep instanceof ErrorPropagation) {
        triggerTS = ((ErrorPropagation) ep).getTypeSet();
        triggerName = "propagation " + EMV2Util.getPrintName((ErrorPropagation) ep);
    } else if (ep instanceof ErrorEvent) {
        triggerTS = ((ErrorEvent) ep).getTypeSet();
        triggerName = "event " + ((ErrorBehaviorEvent) ep).getName();
    }
    TypeSet condTS = conditionElement.getConstraint();
    if (condTS == null) {
        return;
    }
    if (triggerTS == null && condTS != null) {
        // it is ok for a state not to have a type set.
        error(conditionElement, "Condition has type constraint but referenced " + triggerName + " does not.");
    } else if (!EMV2TypeSetUtil.isNoError(condTS) && !EMV2TypeSetUtil.contains(triggerTS, condTS)) {
        error(conditionElement, "Condition type constraint " + EMV2Util.getPrintName(condTS) + "is not contained in type set " + EMV2Util.getPrintName(triggerTS) + "of referenced " + triggerName);
    }
}
Also used : TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) EventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.EventOrPropagation) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 2 with ErrorBehaviorEvent

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent in project osate2 by osate.

the class CreateEventPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return Operation.createSimple(ctx.getTarget(), ErrorBehaviorStateMachine.class, stateMachine -> {
        final ErrorBehaviorEvent newEvent = (ErrorBehaviorEvent) EcoreUtil.create(eventType);
        final String newEventName = ErrorModelNamingUtil.buildUniqueIdentifier(stateMachine, "new_event");
        newEvent.setName(newEventName);
        // Add the new event to the state machine
        stateMachine.getEvents().add(newEvent);
        return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newEvent).build();
    });
}
Also used : ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent)

Example 3 with ErrorBehaviorEvent

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent in project osate2 by osate.

the class CreateTransitionPaletteCommand method buildCreateOperation.

private Operation buildCreateOperation(final BusinessObjectContext srcBoc, final ErrorBehaviorState targetStateReadonly) {
    final Object srcBo = srcBoc.getBusinessObject();
    final URI targetStateUri = EcoreUtil.getURI(targetStateReadonly);
    if (srcBo instanceof ErrorBehaviorState) {
        final ErrorBehaviorState srcStateReadonly = (ErrorBehaviorState) srcBo;
        final URI srcStateUri = EcoreUtil.getURI(srcStateReadonly);
        return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(getStateMachine(srcStateReadonly))).modifyPreviousResult(stateMachine -> {
            final ErrorBehaviorState targetState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(targetStateUri, true);
            final ErrorBehaviorState srcState = (ErrorBehaviorState) stateMachine.eResource().getResourceSet().getEObject(srcStateUri, true);
            final NamedElementCollectionSingleSelectorModel<ErrorBehaviorEvent> model = new NamedElementCollectionSingleSelectorModel<>(stateMachine.getEvents());
            if (!FilteringSelectorDialog.open(Display.getCurrent().getActiveShell(), "Select Event", new LabelFilteringListSelectorModel<>(model))) {
                return null;
            }
            final ErrorBehaviorEvent event = model.getSelectedElement();
            // Create the transition
            final ErrorBehaviorTransition newTransition = ErrorModelFactory.eINSTANCE.createErrorBehaviorTransition();
            newTransition.setSource(srcState);
            // Set the target
            if (srcState == targetState) {
                newTransition.setSteadyState(true);
            } else {
                newTransition.setTarget(targetState);
            }
            newTransition.setName(ErrorModelNamingUtil.buildUniqueIdentifier(stateMachine, "new_transition"));
            final ConditionElement conditionElement = ErrorModelFactory.eINSTANCE.createConditionElement();
            newTransition.setCondition(conditionElement);
            final EMV2PathElement conditionPathElement = ErrorModelFactory.eINSTANCE.createEMV2PathElement();
            conditionPathElement.setNamedElement(event);
            final QualifiedErrorEventOrPropagation errorEventOrPropogation = ErrorModelFactory.eINSTANCE.createQualifiedErrorEventOrPropagation();
            errorEventOrPropogation.setEmv2Target(conditionPathElement);
            conditionElement.setQualifiedErrorPropagationReference(errorEventOrPropogation);
            stateMachine.getTransitions().add(newTransition);
            return StepResultBuilder.create().showNewBusinessObject(srcBoc.getParent(), newTransition).build();
        }));
    } else if (srcBo instanceof ErrorBehaviorTransition || srcBo instanceof BehaviorTransitionTrunk || srcBo instanceof TransitionBranch) {
        // Get the transition to modify
        final ErrorBehaviorTransition transitionReadonly;
        if (srcBo instanceof ErrorBehaviorTransition) {
            transitionReadonly = (ErrorBehaviorTransition) srcBo;
        } else if (srcBo instanceof BehaviorTransitionTrunk) {
            transitionReadonly = ((BehaviorTransitionTrunk) srcBo).getTransition();
        } else if (srcBo instanceof TransitionBranch) {
            transitionReadonly = (ErrorBehaviorTransition) ((TransitionBranch) srcBo).eContainer();
        } else {
            throw new AadlGraphicalEditorException("Unexpected case: " + srcBo);
        }
        return Operation.createWithBuilder(createOp -> createOp.supply(() -> StepResult.forValue(transitionReadonly)).modifyPreviousResult(transition -> {
            final ErrorBehaviorState targetState = (ErrorBehaviorState) transition.eResource().getResourceSet().getEObject(targetStateUri, true);
            // Convert from using steady state and target field to using branches.
            if (transition.getDestinationBranches().isEmpty()) {
                final TransitionBranch firstBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
                final BranchValue firstBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
                firstBranchValue.setRealvalue("1.0");
                if (transition.isSteadyState()) {
                    firstBranch.setSteadyState(true);
                } else {
                    firstBranch.setTarget(transition.getTarget());
                }
                firstBranch.setValue(firstBranchValue);
                transition.getDestinationBranches().add(firstBranch);
                transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_Target());
                transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_TargetToken());
                transition.eUnset(ErrorModelPackage.eINSTANCE.getErrorBehaviorTransition_SteadyState());
            }
            // Create the new branch
            final TransitionBranch newBranch = ErrorModelFactory.eINSTANCE.createTransitionBranch();
            final BranchValue newBranchValue = ErrorModelFactory.eINSTANCE.createBranchValue();
            newBranchValue.setRealvalue("1.0");
            // Set the target
            if (transition.getSource() == targetState) {
                newBranch.setSteadyState(true);
            } else {
                newBranch.setTarget(targetState);
            }
            newBranch.setValue(newBranchValue);
            transition.getDestinationBranches().add(newBranch);
            return StepResultBuilder.create().build();
        }));
    } else {
        throw new AadlGraphicalEditorException("Unsupported case: " + srcBo);
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) NamedElementCollectionSingleSelectorModel(org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel) URI(org.eclipse.emf.common.util.URI) StepResult(org.osate.ge.operations.StepResult) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk) GetCreateConnectionOperationContext(org.osate.ge.palette.GetCreateConnectionOperationContext) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) CanStartConnectionContext(org.osate.ge.palette.CanStartConnectionContext) CreateConnectionPaletteCommand(org.osate.ge.palette.CreateConnectionPaletteCommand) BranchValue(org.osate.xtext.aadl2.errormodel.errorModel.BranchValue) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) Operation(org.osate.ge.operations.Operation) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) EObject(org.eclipse.emf.ecore.EObject) Display(org.eclipse.swt.widgets.Display) ErrorModelNamingUtil(org.osate.ge.errormodel.util.ErrorModelNamingUtil) FilteringSelectorDialog(org.osate.ge.swt.selectors.FilteringSelectorDialog) ErrorModelFactory(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelFactory) ErrorBehaviorStateMachine(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine) LabelFilteringListSelectorModel(org.osate.ge.swt.selectors.LabelFilteringListSelectorModel) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) Optional(java.util.Optional) ErrorModelPackage(org.osate.xtext.aadl2.errormodel.errorModel.ErrorModelPackage) QualifiedErrorEventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorEventOrPropagation) EMV2PathElement(org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement) QualifiedErrorEventOrPropagation(org.osate.xtext.aadl2.errormodel.errorModel.QualifiedErrorEventOrPropagation) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) NamedElementCollectionSingleSelectorModel(org.osate.ge.aadl2.ui.NamedElementCollectionSingleSelectorModel) BranchValue(org.osate.xtext.aadl2.errormodel.errorModel.BranchValue) URI(org.eclipse.emf.common.util.URI) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) AadlGraphicalEditorException(org.osate.ge.aadl2.AadlGraphicalEditorException) EObject(org.eclipse.emf.ecore.EObject) BehaviorTransitionTrunk(org.osate.ge.errormodel.model.BehaviorTransitionTrunk)

Example 4 with ErrorBehaviorEvent

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent in project osate2 by osate.

the class ErrorModelTooltipContributor method createLabel.

private void createLabel(final Composite parent, final EObject bo) {
    final boolean showSource = bo instanceof ErrorType || bo instanceof TypeSet || bo instanceof ErrorBehaviorTransition || bo instanceof TransitionBranch || bo instanceof ErrorBehaviorEvent || bo instanceof ErrorBehaviorState || bo instanceof ErrorPropagation || bo instanceof PropagationPoint || bo instanceof ErrorFlow || bo instanceof PropagationPath;
    if (!showSource) {
        return;
    }
    final INode n = NodeModelUtils.getNode(bo);
    if (n == null) {
        return;
    }
    final String txt = NodeModelUtils.getTokenText(n);
    if (txt == null) {
        return;
    }
    final Label lbl = new Label(parent, SWT.WRAP);
    lbl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    lbl.setText(txt);
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) PropagationPath(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPath) INode(org.eclipse.xtext.nodemodel.INode) ErrorFlow(org.osate.xtext.aadl2.errormodel.errorModel.ErrorFlow) TransitionBranch(org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch) Label(org.eclipse.swt.widgets.Label) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) ErrorType(org.osate.xtext.aadl2.errormodel.errorModel.ErrorType) PropagationPoint(org.osate.xtext.aadl2.errormodel.errorModel.PropagationPoint) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 5 with ErrorBehaviorEvent

use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent in project osate2 by osate.

the class PropagateErrorSources method startErrorFlows.

/**
 * traverse error flow if the component instance is an error source
 * @param ci component instance
 */
public void startErrorFlows(ComponentInstance ci) {
    Collection<ErrorSource> eslist = EMV2Util.getAllErrorSources(ci.getComponentClassifier());
    String componentText = ci.getComponentInstancePath();
    HashMultimap<ErrorPropagation, String> handledPropagations = HashMultimap.create();
    for (ErrorBehaviorEvent event : EMV2Util.getAllErrorBehaviorEvents(ci)) {
        if (!(event instanceof ErrorEvent) || !Util.conditionHolds((ErrorEvent) event, ci)) {
            continue;
        }
        TypeSet sourcetype = ((ErrorEvent) event).getTypeSet();
        if (sourcetype == null) {
            // no type on event
            for (ErrorBehaviorTransition trans : EMV2Util.getAllErrorBehaviorTransitions(ci)) {
                if (trans.getCondition() instanceof ConditionElement) {
                    ConditionElement conditionElement = (ConditionElement) trans.getCondition();
                    processTransition(ci, event, null, trans, conditionElement, componentText, handledPropagations);
                } else if (trans.getCondition() instanceof OrmoreExpression) {
                    EList<ConditionExpression> elems = ((OrmoreExpression) trans.getCondition()).getOperands();
                    for (ConditionExpression conditionExpression : elems) {
                        if (conditionExpression instanceof ConditionElement) {
                            ConditionElement conditionElement = (ConditionElement) conditionExpression;
                            processTransition(ci, event, null, trans, conditionElement, componentText, handledPropagations);
                        }
                    }
                } else if (trans.getCondition() instanceof OrExpression) {
                    EList<ConditionExpression> elems = ((OrExpression) trans.getCondition()).getOperands();
                    for (ConditionExpression conditionExpression : elems) {
                        if (conditionExpression instanceof ConditionElement) {
                            ConditionElement conditionElement = (ConditionElement) conditionExpression;
                            processTransition(ci, event, null, trans, conditionElement, componentText, handledPropagations);
                        }
                    }
                }
            }
        } else {
            EList<TypeToken> tokens = EMV2TypeSetUtil.generateAllLeafTypeTokens(((ErrorEvent) event).getTypeSet(), EMV2Util.getUseTypes(event));
            for (TypeToken typeToken : tokens) {
                for (ErrorBehaviorTransition trans : EMV2Util.getAllErrorBehaviorTransitions(ci)) {
                    // the only one that makes sense is an or of error events
                    if (trans.getCondition() instanceof ConditionElement) {
                        ConditionElement conditionElement = (ConditionElement) trans.getCondition();
                        processTransition(ci, event, typeToken, trans, conditionElement, componentText, handledPropagations);
                    } else if (trans.getCondition() instanceof OrmoreExpression) {
                        EList<ConditionExpression> elems = ((OrmoreExpression) trans.getCondition()).getOperands();
                        for (ConditionExpression conditionExpression : elems) {
                            if (conditionExpression instanceof ConditionElement) {
                                ConditionElement conditionElement = (ConditionElement) conditionExpression;
                                processTransition(ci, event, typeToken, trans, conditionElement, componentText, handledPropagations);
                            }
                        }
                    } else if (trans.getCondition() instanceof OrExpression) {
                        EList<ConditionExpression> elems = ((OrExpression) trans.getCondition()).getOperands();
                        for (ConditionExpression conditionExpression : elems) {
                            if (conditionExpression instanceof ConditionElement) {
                                ConditionElement conditionElement = (ConditionElement) conditionExpression;
                                processTransition(ci, event, typeToken, trans, conditionElement, componentText, handledPropagations);
                            }
                        }
                    }
                }
            }
        }
    }
    for (ErrorSource errorSource : eslist) {
        if (!Util.conditionHolds(errorSource, ci)) {
            continue;
        }
        EMSUtil.unsetAll(ci.getSystemInstance());
        Collection<ErrorPropagation> eplist = EMV2Util.getOutgoingPropagationOrAll(errorSource);
        TypeSet ts = errorSource.getTypeTokenConstraint();
        ErrorBehaviorState failureMode = errorSource.getFailureModeReference();
        TypeSet failureTypeSet = null;
        if (failureMode != null) {
            failureTypeSet = failureMode.getTypeSet();
        } else {
            // reference to named type set
            // or type set constructor
            failureTypeSet = errorSource.getFailureModeType();
        }
        String failuremodeDesc = errorSource.getFailureModeDescription();
        for (ErrorPropagation ep : eplist) {
            TypeSet tsep = ep.getTypeSet();
            if (ts != null || tsep != null) {
                EList<TypeToken> result = ts != null ? ts.getTypeTokens() : tsep.getTypeTokens();
                for (TypeToken typeToken : result) {
                    String failuremodeText;
                    if (handledPropagations.containsEntry(ep, EMV2Util.getPrintName(typeToken))) {
                        continue;
                    }
                    if (failuremodeDesc == null) {
                        failuremodeText = generateOriginalFailureModeText(failureMode != null ? failureMode : (failureTypeSet != null ? failureTypeSet : typeToken));
                    } else {
                        failuremodeText = failuremodeDesc;
                    }
                    traceErrorPaths(ci, ep, typeToken, 2, componentText + "," + failuremodeText);
                }
            }
        }
    }
}
Also used : ErrorBehaviorState(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState) OrmoreExpression(org.osate.xtext.aadl2.errormodel.errorModel.OrmoreExpression) OrExpression(org.osate.xtext.aadl2.errormodel.errorModel.OrExpression) ConditionElement(org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement) ErrorBehaviorTransition(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition) ErrorSource(org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource) ErrorBehaviorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) ConditionExpression(org.osate.xtext.aadl2.errormodel.errorModel.ConditionExpression) TypeToken(org.osate.xtext.aadl2.errormodel.errorModel.TypeToken) TypeSet(org.osate.xtext.aadl2.errormodel.errorModel.TypeSet) ErrorEvent(org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Aggregations

ErrorBehaviorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorEvent)6 ErrorPropagation (org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)5 ErrorBehaviorState (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorState)4 TypeSet (org.osate.xtext.aadl2.errormodel.errorModel.TypeSet)4 ErrorBehaviorStateMachine (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorStateMachine)3 ErrorBehaviorTransition (org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition)3 EObject (org.eclipse.emf.ecore.EObject)2 Classifier (org.osate.aadl2.Classifier)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2 ConditionElement (org.osate.xtext.aadl2.errormodel.errorModel.ConditionElement)2 EMV2PathElement (org.osate.xtext.aadl2.errormodel.errorModel.EMV2PathElement)2 ErrorEvent (org.osate.xtext.aadl2.errormodel.errorModel.ErrorEvent)2 ErrorTypes (org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes)2 EventOrPropagation (org.osate.xtext.aadl2.errormodel.errorModel.EventOrPropagation)2 TransitionBranch (org.osate.xtext.aadl2.errormodel.errorModel.TransitionBranch)2 TypeToken (org.osate.xtext.aadl2.errormodel.errorModel.TypeToken)2 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EList (org.eclipse.emf.common.util.EList)1