private List <IRule> LoadRule(IRule rule, ITransitionEvent data, ITransitionEventComparer comparer)
        {
            List <IRule>  nextRules = new List <IRule>();
            Stack <IRule> ruleStack = new Stack <IRule>();

            ruleStack.Push(rule);
            int count = 0;

            while (ruleStack.Count > 0)
            {
                rule = ruleStack.Pop();
                foreach (SCXMLTransition transition in rule.Transitions)
                {
                    if ((count == 0 && comparer.Compare(transition.Event, data) > -1) ||
                        transition.Event == null)
                    {
                        SCXMLRule nextRule = PrepareRule(transition.TargetRuleName);
                        nextRules.Add(nextRule);
                        ruleStack.Push(nextRule);

                        if (callback != null)
                        {
                            foreach (SCXMLDataEvent dataEvent in transition.DataEvents)
                            {
                                if (!dataEvent.IsTriggered)
                                {
                                    callback.OnEvent(dataEvent);
                                    dataEvent.IsTriggered = true;
                                }
                            }
                        }

                        // TODO: Comment break to suppport NFA
                        break;
                    }
                }

                if (callback != null)
                {
                    foreach (SCXMLDataEvent dataEvent in rule.DataEvents)
                    {
                        if (!dataEvent.IsTriggered)
                        {
                            callback.OnEvent(dataEvent);
                            dataEvent.IsTriggered = true;
                        }
                    }
                }

                count++;
            }

            return(nextRules);
        }
        private SCXMLRule PrepareRule(XmlNode node)
        {
            SCXMLRule rule = new SCXMLRule {
                Name = node.Attributes["id"].Value
            };

            foreach (XmlNode transition in node.SelectNodes(allTransitionsInARuleMatch))
            {
                SCXMLTransition scxmlTransition = new SCXMLTransition
                {
                    TargetRuleName = transition.Attributes["target"].Value,
                    Event          = new SCXMLTransitionEvent {
                        eventData = transition.Attributes["event"] == null ? null : transition.Attributes["event"].Value
                    }
                };

                foreach (XmlNode dataEvent in transition.SelectNodes(allDataEventsInATagMatch))
                {
                    scxmlTransition.DataEvents.Add(new SCXMLDataEvent
                    {
                        Name    = dataEvent.Attributes["event"].Value,
                        Context = dataEvent.Attributes["context"] == null ? null : dataEvent.Attributes["context"].Value
                    });
                }

                rule.Transitions.Add(scxmlTransition);
            }

            foreach (XmlNode dataEvent in node.SelectNodes(allDataEventsInATagMatch))
            {
                rule.DataEvents.Add(new SCXMLDataEvent
                {
                    Name    = dataEvent.Attributes["event"].Value,
                    Context = dataEvent.Attributes["context"] == null ? null : dataEvent.Attributes["context"].Value
                });
            }

            return(rule);
        }