/// <summary> /// Check if this rule corresponds to a transition for this state machine /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(RuleCondition obj, bool visitSubNodes) { Rules.RuleCondition ruleCondition = (Rules.RuleCondition) obj; foreach (Action action in ruleCondition.Actions) { try { foreach (VariableUpdateStatement update in action.UpdateStatements) { Type targetType = update.TargetType; if (targetType is StateMachine) { Expression expressionTree = update.Expression; if (expressionTree != null) { // HaCK: This is a bit rough, but should be sufficient for now... foreach (State stt1 in GetStates(expressionTree)) { // TargetState is the target state either in this state machine or in a sub state machine State targetState = StateMachine.StateInThisStateMachine(stt1); int transitionCount = Transitions.Count; bool filteredOut = false; // Finds the enclosing state of this action to determine the source state of this transition State enclosingState = EnclosingFinder<State>.find(action); if (enclosingState != null) { filteredOut = filteredOut || AddTransition(update, stt1, null, enclosingState); } if (!filteredOut) { foreach (PreCondition preCondition in ruleCondition.AllPreConditions) { // A transition from one state to another has been found foreach (State stt2 in GetStates(preCondition.Expression)) { filteredOut = filteredOut || AddTransition(update, stt1, preCondition, stt2); } } } if (Transitions.Count == transitionCount) { if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine) { if (!filteredOut) { Action enclosingAction = update.Root as Action; if (enclosingAction != null) { // No precondition could be found => one can reach this state at anytime if ( !findMatchingTransition(enclosingAction.RuleCondition, null, targetState)) { Transitions.Add(new Transition(null, null, update, targetState)); } } } } } } } else { action.AddError("Cannot parse expression"); } } } } catch (Exception e) { } } base.visit(obj, visitSubNodes); }
public virtual void visit(RuleCondition obj) { visit(obj, true); }
public virtual void visit(RuleCondition obj, bool visitSubNodes) { visit ((ReqRelated) obj, false); if (visitSubNodes){ IXmlBBase[] Subs = acceptor.subElements((IXmlBBase)obj); if (Subs != null){ for (int i=0; i<Subs.Length; i++) { dispatch(Subs[i], true); } // If } // If } }
public void copyTo(RuleCondition other) { base.copyTo(other); other.aPreConditions = aPreConditions; other.aActions = aActions; other.aSubRules = aSubRules; }
public void insertConditions(int idx, RuleCondition el,Lock aLock) { __setDirty(true); allConditions().Insert (idx, el); NotifyControllers(aLock); }
public void appendConditions(Lock aLock,RuleCondition el) { __setDirty(true); el.__setDirty(true); allConditions().Add(el); acceptor.connectSon (this, el); NotifyControllers(aLock); }
/// <summary> /// Check if this rule corresponds to a transition for this state machine /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(RuleCondition obj, bool visitSubNodes) { Rules.RuleCondition ruleCondition = (Rules.RuleCondition)obj; foreach (Action action in ruleCondition.Actions) { try { foreach (VariableUpdateStatement update in action.UpdateStatements) { Type targetType = update.TargetType; if (targetType is StateMachine) { Expression expressionTree = update.Expression; if (expressionTree != null) { // HaCK: This is a bit rough, but should be sufficient for now... foreach (State stt1 in GetStates(expressionTree)) { // TargetState is the target state either in this state machine or in a sub state machine State targetState = StateMachine.StateInThisStateMachine(stt1); int transitionCount = Transitions.Count; bool filteredOut = false; // Finds the enclosing state of this action to determine the source state of this transition State enclosingState = EnclosingFinder <State> .find(action); if (enclosingState != null) { filteredOut = filteredOut || AddTransition(update, stt1, null, enclosingState); } if (!filteredOut) { foreach (PreCondition preCondition in ruleCondition.AllPreConditions) { // A transition from one state to another has been found foreach (State stt2 in GetStates(preCondition.Expression)) { filteredOut = filteredOut || AddTransition(update, stt1, preCondition, stt2); } } } if (Transitions.Count == transitionCount) { if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine) { if (!filteredOut) { Action enclosingAction = update.Root as Action; if (enclosingAction != null) { // No precondition could be found => one can reach this state at anytime if ( !findMatchingTransition(enclosingAction.RuleCondition, null, targetState)) { Transitions.Add(new Transition(null, null, update, targetState)); } } } } } } } else { action.AddError("Cannot parse expression"); } } } } catch (Exception e) { } } base.visit(obj, visitSubNodes); }
public override void visit(RuleCondition obj, bool subNodes) { Rules.RuleCondition ruleCondition = obj as Rules.RuleCondition; if (ruleCondition != null) { try { bool found = false; ruleCondition.Messages.Clear(); foreach (Rules.PreCondition preCondition in ruleCondition.PreConditions) { BinaryExpression expression = checkExpression(preCondition, preCondition.ExpressionText) as BinaryExpression; if (expression != null) { if (expression.IsSimpleEquality()) { ITypedElement variable = expression.Left.Ref as ITypedElement; if (variable != null) { if (variable.Type != null) { // Check that when preconditions are based on a request, // the corresponding action affects the value Request.Disabled to the same variable if (variable.Type.Name.Equals("Request") && expression.Right != null && expression.Right is UnaryExpression) { IValue val2 = expression.Right.Ref as IValue; if (val2 != null && "Response".CompareTo(val2.Name) == 0) { if (ruleCondition != null) { found = false; foreach (Rules.Action action in ruleCondition.Actions) { IVariable var = OverallVariableFinder.INSTANCE.findByName( action, preCondition.findVariable()); VariableUpdateStatement update = action.Modifies(var); if (update != null) { UnaryExpression updateExpr = update.Expression as UnaryExpression; if (updateExpr != null) { IValue val3 = updateExpr.Ref as IValue; if (val3 != null && val3.Name.CompareTo("Disabled") == 0) { found = true; break; } } } } if (!found) { preCondition.AddError( "Rules where the Pre conditions is based on a Request type variable must assign that variable the value 'Request.Disabled'"); } } } } } // Check that the outgoing variables are not read if (variable.Mode == acceptor.VariableModeEnumType.aOutgoing) { if (ruleCondition.Reads(variable)) { preCondition.AddError("An outgoing variable cannot be read"); } } // Check that the incoming variables are not modified if (variable.Mode == acceptor.VariableModeEnumType.aIncoming) { if (ruleCondition.Modifies(variable) != null) { preCondition.AddError("An incoming variable cannot be written"); } } } } } } } catch (Exception exception) { ruleCondition.AddException(exception); } } base.visit(obj, subNodes); }