Example #1
0
        //
        // Create a rule from an element
        //
        static CapabilitiesRule RuleFromElement(ParseState parseState, XmlNode element)
        {
            int                 ruletype;
            DelayedRegex        regex;
            CapabilitiesPattern pat;

            // grab tag name

            if (element.Name == "filter")
            {
                ruletype = CapabilitiesRule.Filter;
            }
            else if (element.Name == "case")
            {
                ruletype = CapabilitiesRule.Case;
            }
            else if (element.Name == "use")
            {
                HandlerBase.CheckForNonCommentChildNodes(element);

                string var   = HandlerBase.RemoveRequiredAttribute(element, "var");
                string strAs = HandlerBase.RemoveAttribute(element, "as");
                HandlerBase.CheckForUnrecognizedAttributes(element);

                if (strAs == null)
                {
                    strAs = String.Empty;
                }

                parseState.Evaluator.AddDependency(var);

                return(new CapabilitiesUse(var, strAs));
            }
            else
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Unknown_tag_in_caps_config, element.Name),
                          element);
            }

            // grab attributes
            String matchpat = HandlerBase.RemoveAttribute(element, "match");
            String testpat  = HandlerBase.RemoveAttribute(element, "with");

            HandlerBase.CheckForUnrecognizedAttributes(element);

            if (matchpat == null)
            {
                if (testpat != null)
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_specify_test_without_match), element);
                }
                regex = null;
                pat   = null;
            }
            else
            {
                try {
                    regex = new DelayedRegex(matchpat);
                }
                catch (Exception e) {
                    throw new ConfigurationErrorsException(e.Message, e, element);
                }

                if (testpat == null)
                {
                    pat = CapabilitiesPattern.Default;
                }
                else
                {
                    pat = new CapabilitiesPattern(testpat);
                }
            }

            // grab contents
            ArrayList subrules = RuleListFromElement(parseState, element, false);

            return(new CapabilitiesSection(ruletype, regex, pat, subrules));
        }