예제 #1
0
        /**
         * Parses the XML representation of a rule and creates a Rule
         * object based on it.
         * @param ruleElt the XML <rule> node and subnodes.
         * @return the rule that was read or null.
         */
        public static Rule readXml(XmlElement ruleElt)
        {
            Rule rule = null;
            Log  log  = Log.getOnly();

            if (ruleElt.Name.Equals("rule"))
            {       // get <when>
                XmlNodeList nodes = ruleElt.ChildNodes;
                if (nodes == null || 0 == nodes.Count)
                {
                    return(rule);
                }
                String    id      = XmlFiler.getStringAttr(ruleElt, "id", NoId);
                String    desc    = XmlFiler.getStringAttr(ruleElt, "desc", NoDesc);
                String    fireA   = XmlFiler.getStringAttr(ruleElt, "fire", NoDesc);
                bool      fire    = fireA.Equals("always");
                ArrayList when    = null;
                ArrayList actions = null;
                for (int n = 0; n < nodes.Count; n++)
                {         // one when and many action elements
                    XmlNode node = nodes.Item(n);
                    if (node.Name.Equals("when") && when == null)
                    {             // process the one when element
                        when = EmptyElement.readEmptyChildren(node);
                    }
                    else if (node.Name.Equals("when"))
                    {             // too many when elements
                        log.writeElt("fail");
                        log.writeAttr("rule", id);
                        log.writeAttr("when", "multiple");
                        log.endElt();
                        when = null;
                    }
                    else
                    {             // an action element
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            EmptyElement empty = EmptyElement.readXml(node);
                            if (actions == null)
                            {
                                actions = new ArrayList();
                            }
                            actions.Add(empty);
                        }
                    }
                }
                rule = new Rule(id, desc, fire, when, actions);
            }
            return(rule);
        }
예제 #2
0
        /**
         * Parses the XML representation of a parent with empty children.
         * @param parent the XML node with subnodes.
         * @return the empty children that were read or null.
         */
        public static ArrayList readEmptyChildren(XmlNode parent)
        {
            ArrayList   emptyList = null;
            XmlNodeList children  = parent.ChildNodes;

            for (int c = 0; c < children.Count; c++)
            {             // read children
                XmlNode child = children.Item(c);
                if (child.NodeType == XmlNodeType.Element)
                {
                    EmptyElement emptyChild = EmptyElement.readXml((XmlElement)child);
                    if (emptyList == null)
                    {
                        emptyList = new ArrayList();
                    }
                    emptyList.Add(emptyChild);
                }
            }
            return(emptyList);
        }
예제 #3
0
        /**
         * Reads an Xml file of rule-sets and a goal.
         * @return A list of the rule-sets.
         */
        public static ArrayList readXml(string rulesFile)
        {
            ArrayList   ruleSets  = null;
            XmlElement  rulesDoc  = XmlFiler.readXmlFile(rulesFile, "rules", ".");
            XmlNodeList ruleSetsN = rulesDoc.ChildNodes;

            for (int i = 0; i < ruleSetsN.Count; i++)
            {
                XmlNode rsN = ruleSetsN.Item(i);
                if (rsN.NodeType == XmlNodeType.Element)
                {
                    if (rsN.Name.Equals("rule-set"))
                    {
                        RuleSet rs = RuleSet.readXml((XmlElement)rsN);
                        if (rs != null)
                        {
                            if (ruleSets == null)
                            {
                                ruleSets = new ArrayList(3);
                            }
                            ruleSets.Add(rs);
                        }
                        else
                        {
                            Log log = Log.getOnly();
                            log.writeEltTime("fail");
                            log.writeAttr("rule-set", "not read");
                            log.endElt();
                        }
                    }
                    else                     // it's the goal action
                    {
                        m_goal = EmptyElement.readXml((XmlElement)rsN);
                    }
                }
            }
            return(ruleSets);
        }