コード例 #1
0
ファイル: RuleSet.cs プロジェクト: bbriggs/FieldWorks
 /**
  * Adds a rule to the rule set.
  * @param rule the rule to add.
  */
 public void addRule(Rule rule)
 {
     if (rule != null) m_rules.Add(rule);
 }
コード例 #2
0
ファイル: Rule.cs プロジェクト: bbriggs/FieldWorks
 /**
  * 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;
 }