Ejemplo n.º 1
0
        internal void SimplifyPhase2(NvdlCompileContext ctx)
        {
            ArrayList al = new ArrayList();

            ConsumeIncludes(al, ctx);
            SimpleRule anyElement   = null;
            SimpleRule anyAttribute = null;

            // 6.4.12 + part of 6.4.13
            CheckCollision(al, ref anyElement, ref anyAttribute);
            // 6.4.13
            if (anyElement == null)
            {
                NvdlAnyNamespace ann = new NvdlAnyNamespace();
                ann.SourceUri    = this.SourceUri;
                ann.LineNumber   = this.LineNumber;
                ann.LinePosition = this.LinePosition;

                NvdlReject reject = new NvdlReject();
                reject.SourceUri    = this.SourceUri;
                reject.LineNumber   = this.LineNumber;
                reject.LinePosition = this.LinePosition;
                ann.Actions.Add(reject);
                ann.Match = NvdlRuleTarget.Elements;

                al.Add(new SimpleRule(ann, false, ctx));
            }
            if (anyAttribute == null)
            {
                NvdlAnyNamespace ann = new NvdlAnyNamespace();
                ann.SourceUri    = this.SourceUri;
                ann.LineNumber   = this.LineNumber;
                ann.LinePosition = this.LinePosition;

                NvdlAttach attach = new NvdlAttach();
                attach.SourceUri    = this.SourceUri;
                attach.LineNumber   = this.LineNumber;
                attach.LinePosition = this.LinePosition;
                ann.Match           = NvdlRuleTarget.Attributes;
                ann.Actions.Add(attach);

                al.Add(new SimpleRule(ann, true, ctx));
            }
            rules = (SimpleRule [])al.ToArray(typeof(SimpleRule));
        }
Ejemplo n.º 2
0
        private SimpleRule FindAttributeRule(string ns, SimpleMode mode)
        {
            SimpleRule any = null;

            foreach (SimpleRule rule in mode.AttributeRules)
            {
                if (!rule.MatchNS(ns))
                {
                    continue;
                }
                if (!rule.IsAny)
                {
                    return(rule);
                }
                any = rule;
            }
            if (any != null)
            {
                return(any);
            }
            throw new NvdlValidationException("NVDL internal error: should not happen. No matching rule was found.", reader as IXmlLineInfo);
        }
Ejemplo n.º 3
0
 private void CheckCollision(ArrayList al, ref SimpleRule el, ref SimpleRule attr)
 {
     for (int i = 0; i < al.Count; i++)
     {
         SimpleRule r1 = (SimpleRule)al [i];
         if (r1.IsAny)
         {
             if (r1.MatchAttributes)
             {
                 attr = r1;
             }
             else
             {
                 el = r1;
             }
         }
         for (int j = i + 1; j < al.Count; j++)
         {
             SimpleRule r2 = (SimpleRule)al [j];
             if (r1.MatchAttributes != r2.MatchAttributes)
             {
                 continue;
             }
             if (r1.IsAny && r2.IsAny)
             {
                 throw new NvdlCompileException("collision in mode was found. Two anyNamespace elements.", this);
             }
             if (r1.IsAny || r2.IsAny)
             {
                 continue;
             }
             if (Nvdl.NSMatches(r1.NS, 0, r1.Wildcard,
                                r2.NS, 0, r2.Wildcard))
             {
                 throw new NvdlCompileException("collision in mode was found.", this);
             }
         }
     }
 }
Ejemplo n.º 4
0
        private SimpleRule FindElementRule(SimpleMode mode, XmlReader reader)
        {
            SimpleRule any = null;

            foreach (SimpleRule rule in mode.ElementRules)
            {
                if (rule.MatchNS(reader.NamespaceURI))
                {
                    if (!rule.IsAny)
                    {
                        return(rule);
                    }
                    else
                    {
                        any = rule;
                    }
                }
            }
            if (any != null)
            {
                return(any);
            }
            throw new NvdlValidationException("NVDL internal error: should not happen. No matching rule was found.", Reader as IXmlLineInfo);
        }
Ejemplo n.º 5
0
        private void PopulateInterp(
            NvdlDispatcher d, NvdlInterpretation i,
            NvdlSection parentState)
        {
            SimpleMode m    = FindContextMode(i.Action, parentState);
            SimpleRule rule = FindElementRule(m, dispatcher.Reader);

            foreach (SimpleAction a in rule.Actions)
            {
                NvdlInterpretation cur = i;
                for (; cur != null; cur = cur.Parent)
                {
                    if (cur.CreatedMode == m && cur.Action == a)
                    {
                        break;
                    }
                }
                if (cur == null)
                {
                    cur = CreateInterp(d, m, a, i);
                }
                ilist.Add(cur);
            }
        }
Ejemplo n.º 6
0
 internal void AddRuleContext(SimpleRule r, NvdlRule rctx)
 {
     ruleContexts.Add(r, rctx);
 }
Ejemplo n.º 7
0
 internal NvdlRule GetRuleContext(SimpleRule r)
 {
     return(ruleContexts [r] as NvdlRule);
 }
Ejemplo n.º 8
0
        // Public overrides

        public override bool Read()
        {
            // This class itself never proceeds, just checks if
            // the reader is placed on EOF.
            if (reader.EOF)
            {
                return(false);
            }

            MoveToElement();
            attributeCount = 0;

            if (nextPlaceHolder != XmlNodeType.None)
            {
                placeHolder     = nextPlaceHolder;
                nextPlaceHolder = XmlNodeType.None;
                return(true);
            }

            if (placeHolder != XmlNodeType.None)
            {
                // Inside placeHolder, ignore all contents.
                // The source XmlReader should proceed
                // regardless of this filtered reader.
                return(true);
            }

            if (!reader.MoveToFirstAttribute())
            {
                return(true);
            }

            // Attribute rule application
            attributeValidators.Clear();
            do
            {
                if (reader.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                {
                    continue;
                }
                // FIXME: could be more efficient
                SimpleRule rule = FindAttributeRule(
                    reader.NamespaceURI,
                    validate.CreatedMode);
                foreach (SimpleAction a in rule.Actions)
                {
                    SimpleResultAction ra =
                        a as SimpleResultAction;
                    if (ra != null &&
                        ra.ResultType == NvdlResultType.Attach)
                    {
                        AddAttribute();
                    }
                    if (ra != null)
                    {
                        continue;
                    }
                    attributeValidators [reader.NamespaceURI] = a;
                }
            }while (reader.MoveToNextAttribute());
            reader.MoveToElement();

            if (attributeValidators.Count > 0)
            {
                foreach (string ns in attributeValidators.Keys)
                {
                    ((SimpleValidate)attributeValidators [
                         ns]).ValidateAttributes(reader, ns);
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
		internal void AddRuleContext (SimpleRule r, NvdlRule rctx)
		{
			ruleContexts.Add (r, rctx);
		}
Ejemplo n.º 10
0
		internal NvdlRule GetRuleContext (SimpleRule r)
		{
			return ruleContexts [r] as NvdlRule;
		}
Ejemplo n.º 11
0
 internal NvdlRule GetRuleContext(SimpleRule r)
 {
     return(ruleContexts.ContainsKey(r) ? ruleContexts [r] : null);
 }
Ejemplo n.º 12
0
		private void CheckCollision (ArrayList al, ref SimpleRule el, ref SimpleRule attr)
		{
			for (int i = 0; i < al.Count; i++) {
				SimpleRule r1 = (SimpleRule) al [i];
				if (r1.IsAny) {
					if (r1.MatchAttributes)
						attr = r1;
					else
						el = r1;
				}
				for (int j = i + 1; j < al.Count; j++) {
					SimpleRule r2 = (SimpleRule) al [j];
					if (r1.MatchAttributes != r2.MatchAttributes)
						continue;
					if (r1.IsAny && r2.IsAny)
						throw new NvdlCompileException ("collision in mode was found. Two anyNamespace elements.", this);
					if (r1.IsAny || r2.IsAny)
						continue;
					if (Nvdl.NSMatches (r1.NS, 0, r1.Wildcard,
						r2.NS, 0, r2.Wildcard))
						throw new NvdlCompileException ("collision in mode was found.", this);
				}
			}
		}