use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition in project osate2 by osate.
the class ErrorModelValidator method checkTransitionTargetTriggerTypes.
private void checkTransitionTargetTriggerTypes(ErrorBehaviorTransition ebt) {
if (ebt.isSteadyState()) {
return;
}
ErrorBehaviorState targetstate = ebt.getTarget();
if (targetstate != null) {
TypeSet targetTS = targetstate.getTypeSet();
if (targetTS == null) {
return;
}
TypeSet tt = ebt.getTargetToken();
if (tt != null) {
return;
}
// state requires a type
if (ebt.getCondition() instanceof ConditionElement) {
// either the event must be typed or the source state must be typed
EventOrPropagation ep = EMV2Util.getErrorEventOrPropagation((ConditionElement) ebt.getCondition());
if (ep instanceof ErrorEvent) {
ErrorEvent ev = (ErrorEvent) ep;
TypeSet evTS = ev.getTypeSet();
if (evTS == null) {
TypeSet srcTS = ebt.getSource().getTypeSet();
if (srcTS == null) {
error(ebt, "Target state " + targetstate.getName() + " requires type but the triggering error event " + EMV2Util.getPrintName(ev) + " or source state " + EMV2Util.getPrintName(ebt.getSource()) + " does not have a type");
} else {
// source typeset must be contained in target type set
if (!EMV2TypeSetUtil.contains(targetTS, srcTS)) {
error(ebt, "Target state " + targetstate.getName() + " does not contain types of source state " + EMV2Util.getPrintName(ebt.getSource()));
}
}
} else {
// error event has type. It must be consistent with the expected state type
if (!EMV2TypeSetUtil.contains(targetTS, evTS)) {
error(ebt, "Target state " + targetstate.getName() + " does not contain types of error event " + EMV2Util.getPrintName(ev));
}
}
} else if (ep instanceof ErrorPropagation) {
ErrorPropagation eprop = (ErrorPropagation) ep;
// we can check type compatibility
if (!EMV2TypeSetUtil.contains(targetTS, eprop.getTypeSet())) {
error(ebt, "Target state " + targetstate.getName() + " does not contain types of error propagation " + EMV2Util.getPrintName(eprop));
}
}
} else {
// full condition expression
// type transformation & events must be typed
ErrorBehaviorStateMachine ebsm = (ErrorBehaviorStateMachine) targetstate.eContainer();
if (ebsm.getUseTransformation().isEmpty()) {
error(ebt, "Target state " + targetstate.getName() + " does not include a target type but requires types. For conditions on multiple elements a target type must be assigned explicitly or a type transformation must be specified in the error behavior state machine" + EMV2Util.getPrintName(ebsm));
}
}
}
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition in project osate2 by osate.
the class ErrorModelValidator method checkTransitionSourceTypes.
private void checkTransitionSourceTypes(ErrorBehaviorTransition ebt) {
ErrorBehaviorState ebs = ebt.getSource();
if (ebs == null) {
return;
}
TypeSet ebsTS = ebs.getTypeSet();
TypeSet srcTS = ebt.getTypeTokenConstraint();
if (srcTS == null) {
return;
}
if (ebsTS == null && srcTS != null) {
error(ebt, "Source state " + ebs.getName() + " does not have a type set declared but the transition source specifies " + EMV2Util.getPrintName(srcTS));
} else if (!EMV2TypeSetUtil.contains(ebsTS, srcTS)) {
error(ebt, "Source type " + EMV2Util.getPrintName(srcTS) + " is not contained in type set of error behavior state \'" + ebs.getName() + "\'");
}
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition in project osate2 by osate.
the class EMV2Util method getAllErrorBehaviorTransitions.
/**
* return list of ErrorBehaviorTransition including those inherited from classifiers being extended
* @param cl Classifier
* @param unnamed Collection of unnamed ErrorBehaviorTransition
* @return Collection<ErrorBehaviorTransition> list of ErrorBehaviorTransition as HashMap for quick lookup of names
*/
private static HashMap<String, ErrorBehaviorTransition> getAllErrorBehaviorTransitions(Classifier cl, Collection<ErrorBehaviorTransition> unnamed) {
HashMap<String, ErrorBehaviorTransition> result = new LinkedHashMap<>();
EList<ErrorModelSubclause> emslist = getAllContainingClassifierEMV2Subclauses(cl);
boolean foundEBSM = false;
for (ErrorModelSubclause errorModelSubclause : emslist) {
ErrorBehaviorStateMachine ebsm = errorModelSubclause.getUseBehavior();
EList<ErrorBehaviorTransition> eflist = errorModelSubclause.getTransitions();
for (ErrorBehaviorTransition ebt : eflist) {
if (ebt.getName() == null) {
unnamed.add(ebt);
} else {
if (!result.containsKey(ebt.getName())) {
result.put(ebt.getName(), ebt);
}
}
}
if (!foundEBSM && ebsm != null) {
foundEBSM = true;
eflist = ebsm.getTransitions();
for (ErrorBehaviorTransition ebt : eflist) {
if (ebt.getName() == null) {
unnamed.add(ebt);
} else {
if (!result.containsKey(ebt.getName())) {
result.put(ebt.getName(), ebt);
}
}
}
}
}
return result;
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition in project osate2 by osate.
the class FHAReport method processHazards.
protected void processHazards(ComponentInstance ci, WriteToFile report) {
for (ErrorBehaviorTransition trans : EMV2Util.getAllErrorBehaviorTransitions(ci.getComponentClassifier())) {
ConditionExpression cond = trans.getCondition();
if (cond instanceof ConditionElement) {
ConditionElement condElement = (ConditionElement) trans.getCondition();
EventOrPropagation eop = EMV2Util.getErrorEventOrPropagation(condElement);
if (eop instanceof ErrorEvent) {
ErrorEvent errorEvent = (ErrorEvent) eop;
List<EMV2PropertyAssociation> PA = getHazardsPropertyInCurrentFormat(ci, errorEvent, errorEvent.getTypeSet());
List<EMV2PropertyAssociation> Sev = EMV2Properties.getSeverityProperty(ci, errorEvent, errorEvent.getTypeSet());
List<EMV2PropertyAssociation> Like = EMV2Properties.getLikelihoodProperty(ci, errorEvent, errorEvent.getTypeSet());
reportHazardProperty(ci, PA, Sev, Like, errorEvent, errorEvent.getTypeSet(), errorEvent, report);
}
// condElement.getIncoming()
}
}
for (ErrorBehaviorState state : EMV2Util.getAllErrorBehaviorStates(ci)) {
List<EMV2PropertyAssociation> PA = getHazardsPropertyInCurrentFormat(ci, state, state.getTypeSet());
List<EMV2PropertyAssociation> Sev = EMV2Properties.getSeverityProperty(ci, state, state.getTypeSet());
List<EMV2PropertyAssociation> Like = EMV2Properties.getLikelihoodProperty(ci, state, state.getTypeSet());
reportHazardProperty(ci, PA, Sev, Like, state, state.getTypeSet(), state, report);
}
// report all error sources as hazards if they have the property
Collection<ErrorSource> eslist = EMV2Util.getAllErrorSources(ci.getComponentClassifier());
Collection<ErrorPropagation> oeplist = EMV2Util.getAllOutgoingErrorPropagations(ci.getComponentClassifier());
for (ErrorSource errorSource : eslist) {
NamedElement ne = errorSource.getSourceModelElement();
ErrorBehaviorState failureMode = errorSource.getFailureModeReference();
List<EMV2PropertyAssociation> HazardPA = Collections.emptyList();
List<EMV2PropertyAssociation> Sev = Collections.emptyList();
List<EMV2PropertyAssociation> Like = Collections.emptyList();
TypeSet ts = null;
NamedElement target = null;
Element localContext = null;
// not dealing with type set as failure mode
if (failureMode != null) {
// state is originating hazard, possibly with a type set
ts = failureMode.getTypeSet();
// error source a local context
HazardPA = getHazardsPropertyInCurrentFormat(ci, failureMode, ts);
Sev = EMV2Properties.getSeverityProperty(ci, failureMode, ts);
Like = EMV2Properties.getLikelihoodProperty(ci, failureMode, ts);
target = failureMode;
localContext = errorSource;
}
if (HazardPA.isEmpty()) {
// error source is originating hazard
ts = errorSource.getTypeTokenConstraint();
if (ts == null && ne instanceof ErrorPropagation) {
ts = ((ErrorPropagation) ne).getTypeSet();
}
HazardPA = getHazardsPropertyInCurrentFormat(ci, errorSource, ts);
Sev = EMV2Properties.getSeverityProperty(ci, errorSource, ts);
Like = EMV2Properties.getLikelihoodProperty(ci, errorSource, ts);
target = errorSource;
localContext = null;
if (HazardPA.isEmpty() && errorSource.getFailureModeType() != null) {
ts = errorSource.getFailureModeType();
HazardPA = getHazardsPropertyInCurrentFormat(ci, errorSource, ts);
Sev = EMV2Properties.getSeverityProperty(ci, errorSource, ts);
Like = EMV2Properties.getLikelihoodProperty(ci, errorSource, ts);
}
}
if (!HazardPA.isEmpty()) {
reportHazardProperty(ci, HazardPA, Sev, Like, target, ts, localContext, report);
}
}
for (ErrorPropagation ep : oeplist) {
TypeSet ts = null;
NamedElement target = null;
Element localContext = null;
// error propagation is originating hazard
ts = ep.getTypeSet();
List<EMV2PropertyAssociation> HazardPA = getHazardsPropertyInCurrentFormat(ci, ep, ts);
List<EMV2PropertyAssociation> Sev = EMV2Properties.getSeverityProperty(ci, ep, ts);
List<EMV2PropertyAssociation> Like = EMV2Properties.getLikelihoodProperty(ci, ep, ts);
target = ep;
localContext = null;
// XXX we may have more than one matching hazard
if (!HazardPA.isEmpty()) {
reportHazardProperty(ci, HazardPA, Sev, Like, target, ts, localContext, report);
}
}
}
use of org.osate.xtext.aadl2.errormodel.errorModel.ErrorBehaviorTransition in project osate2 by osate.
the class PropagationGraphBackwardTraversal method traverseErrorBehaviorState.
/**
* process error state. Recursively deal with source states of transitions (an PRIORITY AND gate).
* We only process error events (not recover or repair) and error propagations referenced by the expression.
* @param component ComponentInstance
* @param state ErrorBehaviorState
* @param type ErrorTypes
* @return EObject (can be null)
*/
public EObject traverseErrorBehaviorState(ComponentInstance component, ErrorBehaviorState state, TypeToken type, BigDecimal inscale) {
if (state == null) {
return null;
}
List<EObject> subResults = new LinkedList<EObject>();
Collection<ErrorBehaviorTransition> transitions = EMV2Util.getAllErrorBehaviorTransitions(component);
BigDecimal combinedscale = inscale;
for (ErrorBehaviorTransition ebt : transitions) {
ConditionExpression conditionExpression = null;
BigDecimal branchscale = BigOne;
boolean sameState = false;
Collection<TypeToken> newtypes = new LinkedList<TypeToken>();
if (ebt.getTarget() != null && EMV2Util.isSame(state, ebt.getTarget())) {
if (ebt.getTargetToken() != null) {
Collection<TypeToken> filteredtypes = filterTokenThroughConstraint(ebt.getTargetToken(), type);
for (TypeToken filteredtype : filteredtypes) {
if (contains(ebt.getTargetToken(), filteredtype)) {
conditionExpression = ebt.getCondition();
if (ebt.getSource() != null && EMV2Util.isSame(state, ebt.getSource()) && isSame(type, ebt.getTypeTokenConstraint())) {
sameState = true;
newtypes.add(filteredtype);
}
}
}
} else {
conditionExpression = ebt.getCondition();
if (ebt.getSource() != null && EMV2Util.isSame(state, ebt.getSource()) && isSame(type, ebt.getTypeTokenConstraint())) {
sameState = true;
newtypes.add(type);
}
}
} else if (!ebt.getDestinationBranches().isEmpty()) {
// deal with transition branches
EList<TransitionBranch> tbs = ebt.getDestinationBranches();
for (TransitionBranch transitionBranch : tbs) {
if (ebt.getSource() != null && EMV2Util.isSame(ebt.getSource(), transitionBranch.getTarget()) && ebt.getSource().getTypeSet() == null && transitionBranch.getTarget().getTypeSet() == null) {
sameState = true;
}
if (transitionBranch.getTarget() != null) {
if (EMV2Util.isSame(transitionBranch.getTarget(), state)) {
if (ebt.getTargetToken() != null) {
Collection<TypeToken> filteredtypes = filterTokenThroughConstraint(ebt.getTargetToken(), type);
for (TypeToken filteredtype : filteredtypes) {
if (contains(transitionBranch.getTargetToken(), filteredtype)) {
conditionExpression = ebt.getCondition();
if (EMV2Util.isSame(ebt.getSource(), state) && isSame(type, ebt.getTypeTokenConstraint())) {
sameState = true;
newtypes.add(filteredtype);
}
}
}
} else {
conditionExpression = ebt.getCondition();
}
}
} else if (transitionBranch.isSteadyState()) {
// same state
if (ebt.getSource() != null && EMV2Util.isSame(state, ebt.getSource()) && isSame(type, ebt.getTypeTokenConstraint())) {
conditionExpression = ebt.getCondition();
sameState = true;
newtypes.add(type);
}
}
if (conditionExpression != null) {
// get branch prob value
BranchValue val = transitionBranch.getValue();
if (val.getRealvalue() != null) {
branchscale = new BigDecimal(EMV2Util.stripUnderScore(val.getRealvalue()));
} else if (val.getSymboliclabel() != null) {
Classifier cl = EMV2Util.getAssociatedClassifier(ebt);
List<EMV2PropertyAssociation> pa = EMV2Properties.getProperty(val.getSymboliclabel().getQualifiedName(), cl, ebt, null);
for (EMV2PropertyAssociation emv2PropertyAssociation : pa) {
branchscale = BigDecimal.valueOf(EMV2Properties.getRealValue(emv2PropertyAssociation));
}
} else if (val.isOthers()) {
branchscale = BigOne;
for (TransitionBranch tb : tbs) {
BranchValue valcount = tb.getValue();
if (valcount.getRealvalue() != null) {
branchscale = branchscale.subtract(new BigDecimal(EMV2Util.stripUnderScore(valcount.getRealvalue())));
} else if (valcount.getSymboliclabel() != null) {
Classifier cl = EMV2Util.getAssociatedClassifier(ebt);
List<EMV2PropertyAssociation> pa = EMV2Properties.getProperty(valcount.getSymboliclabel().getQualifiedName(), cl, ebt, null);
for (EMV2PropertyAssociation emv2PropertyAssociation : pa) {
branchscale = branchscale.subtract(new BigDecimal(EMV2Properties.getRealValue(emv2PropertyAssociation)));
}
}
}
}
// XXX why break?
break;
}
}
} else if (ebt.isSteadyState()) {
// same state
if (ebt.getSource() != null && EMV2Util.isSame(state, ebt.getSource()) && isSame(type, ebt.getTypeTokenConstraint())) {
conditionExpression = ebt.getCondition();
sameState = true;
newtypes.add(type);
}
}
combinedscale = inscale.multiply(branchscale);
if (!sameState && conditionExpression != null) {
// don't include transition staying in same state
EObject conditionResult = processCondition(component, conditionExpression, newtypes == null ? type : null, combinedscale, false);
// we also do not traverse back if left is allstates.
if (conditionResult != null) {
EObject stateResult = null;
if (!(sameState || ebt.isAllStates())) {
if (newtypes.isEmpty()) {
stateResult = traverseErrorBehaviorState(component, ebt.getSource(), null, combinedscale);
} else {
List<EObject> subsubResults = new LinkedList<EObject>();
for (TypeToken typeToken : newtypes) {
EObject newEvent = traverseErrorBehaviorState(component, state, typeToken, combinedscale);
if (newEvent != null) {
addSubresult(subsubResults, newEvent);
}
}
if (subsubResults.isEmpty()) {
stateResult = processErrorBehaviorState(component, state, type, inscale);
} else if (subsubResults.size() == 1) {
stateResult = subsubResults.get(0);
} else {
stateResult = processTypesetElements(component, state, type, subsubResults, combinedscale);
}
}
}
if (stateResult != null) {
EObject tmpresult = processTransitionCondition(component, ebt.getSource(), type, conditionResult, stateResult, combinedscale);
if (tmpresult != null) {
addSubresult(subResults, tmpresult);
}
} else if (stateResult == null) {
addSubresult(subResults, conditionResult);
}
}
}
}
if (!subResults.isEmpty()) {
return postProcessErrorBehaviorState(component, state, type, subResults, combinedscale);
}
// or if no transitions specified for state machine
if (transitions.isEmpty()) {
// processErrorBehaviorState(component, state, type);
return traverseCompositeErrorStateOnly(component, state, type, inscale);
} else {
// Do not include
return null;
}
}
Aggregations