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);
}
}
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();
});
}
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);
}
}
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);
}
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);
}
}
}
}
}
Aggregations