예제 #1
0
 public NvdlValidatingReader(XmlReader reader, NvdlRules rules,
                             XmlResolver resolver, NvdlConfig config)
     : base(reader)
 {
     dispatcher = new NvdlDispatcher(new SimpleRules(
                                         new NvdlCompileContext(
                                             rules, config, resolver)), this);
 }
예제 #2
0
		public NvdlValidatingReader (XmlReader reader, NvdlRules rules,
			XmlResolver resolver, NvdlConfig config)
			: base (reader)
		{
			dispatcher = new NvdlDispatcher (new SimpleRules (
				new NvdlCompileContext (
				rules, config, resolver)), this);
		}
예제 #3
0
        private NvdlRules ReadRules()
        {
            NvdlRules el = new NvdlRules();

            FillLocation(el);
            el.SchemaType = reader.GetAttribute("schemaType");
            el.StartMode  = reader.GetAttribute("startMode");
            FillForeignAttribute(el);
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return(el);
            }
            reader.Read();
            do
            {
                reader.MoveToContent();
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                if (reader.NamespaceURI != Nvdl.Namespace)
                {
                    el.Foreign.Add(XDocument.ReadFrom(reader));
                    continue;
                }
                switch (reader.LocalName)
                {
                case "mode":
                    el.Modes.Add(ReadMode());
                    break;

                case "namespace":
                    el.Rules.Add(ReadNamespace());
                    break;

                case "anyNamespace":
                    el.Rules.Add(ReadAnyNamespace());
                    break;

                case "trigger":
                    el.Triggers.Add(ReadTrigger());
                    break;
                }
            } while (!reader.EOF);
            if (!reader.EOF)
            {
                reader.Read();
            }
            return(el);
        }
예제 #4
0
		private NvdlRules ReadRules ()
		{
			NvdlRules el = new NvdlRules ();
			FillLocation (el);
			el.SchemaType = reader.GetAttribute ("schemaType");
			el.StartMode = reader.GetAttribute ("startMode");
			FillForeignAttribute (el);
			if (reader.IsEmptyElement) {
				reader.Skip ();
				return el;
			}
			reader.Read ();
			do {
				reader.MoveToContent ();
				if (reader.NodeType == XmlNodeType.EndElement)
					break;
				if (reader.NamespaceURI != Nvdl.Namespace) {
					el.Foreign.Add (doc.ReadNode (reader));
					continue;
				}
				switch (reader.LocalName) {
				case "mode":
					el.Modes.Add (ReadMode ());
					break;
				case "namespace":
					el.Rules.Add (ReadNamespace ());
					break;
				case "anyNamespace":
					el.Rules.Add (ReadAnyNamespace ());
					break;
				case "trigger":
					el.Triggers.Add (ReadTrigger ());
					break;
				}
			} while (!reader.EOF);
			if (!reader.EOF)
				reader.Read ();
			return el;
		}
예제 #5
0
		public NvdlValidatingReader (XmlReader reader, NvdlRules rules, XmlResolver resolver)
			: this (reader, rules, resolver, Nvdl.DefaultConfig)
		{
		}
예제 #6
0
		public NvdlValidatingReader (XmlReader reader, NvdlRules rules)
			: this (reader, rules, new XmlUrlResolver ())
		{
		}
예제 #7
0
 public NvdlCompileContext(NvdlRules rules, NvdlConfig config, XmlResolver resolver)
 {
     this.rules    = rules;
     this.config   = config;
     this.resolver = resolver;
 }
예제 #8
0
        private void SimplifyPhase1(NvdlCompileContext ctx)
        {
            NvdlRules rules = ctx.Rules;
            // 6.4.1 : just ignore "Foreign" property.
            // 6.4.2 : already ignored on reading nvdl.
            // 6.4.3 : done in SOM
            // 6.4.4 : FIXME: must be done.
            // 6.4.5 : FIXME: considered in compiler.
            // 6.4.6 : FIXME: considered in compiler.
            // 6.4.7 : FIXME: considered in compiler.

            // 6.4.8 : here
            NvdlModeList list      = rules.Modes;
            NvdlMode     startMode = null;

            if (rules.Modes.Count > 0)
            {
                if (rules.Rules.Count > 0)
                {
                    throw new NvdlCompileException("Modes and rules cannot coexist in 'rules' element.", rules);
                }
                else if (rules.StartMode == null)
                {
                    throw new NvdlCompileException("startMode is missing in 'rules' element when modes are specified.", rules);
                }
                foreach (NvdlMode m in rules.Modes)
                {
                    if (m.Name == rules.StartMode)
                    {
                        startMode = m;
                        break;
                    }
                }
                if (startMode == null)
                {
                    throw new NvdlCompileException("Matching 'mode' element specified by 'startMode' does not exist.", rules);
                }
            }
            else
            {
                if (rules.Rules.Count == 0)
                {
                    throw new NvdlCompileException("Neither modes nor rules exists in 'rules' element.", rules);
                }
                list                   = new NvdlModeList();
                startMode              = new NvdlMode();
                startMode.SourceUri    = rules.SourceUri;
                startMode.LineNumber   = rules.LineNumber;
                startMode.LinePosition = rules.LinePosition;
                startMode.Name         = "(startMode)";
                list.Add(startMode);
                foreach (NvdlRule rule in rules.Rules)
                {
                    startMode.Rules.Add(rule);
                }
            }

            // 6.4.9 : done in SimpleMode.ctor() and
            // SimpleRule.ctor(), using ctx.CompiledModes.
            foreach (NvdlMode m in list)
            {
                SimpleMode sm = new SimpleMode(m, ctx);
                ctx.AddCompiledMode(sm.Name, sm);
                if (m == startMode)
                {
                    this.startMode = sm;
                }
            }

            // 6.4.10 : done in SimpleRule.Simplify

            ArrayList tl = new ArrayList();

            for (int i = 0; i < rules.Triggers.Count; i++)
            {
                tl.Add(new SimpleTrigger(rules.Triggers [i]));
            }
            triggers = (SimpleTrigger [])tl.ToArray(
                typeof(SimpleTrigger));

            modes = (SimpleMode [])
                    new ArrayList(ctx.GetCompiledModes())
                    .ToArray(typeof(SimpleMode));
        }
예제 #9
0
		public NvdlCompileContext (NvdlRules rules, NvdlConfig config, XmlResolver resolver)
		{
			this.rules = rules;
			this.config = config;
			this.resolver = resolver;
		}
예제 #10
0
 public NvdlValidatingReader(XmlReader reader, NvdlRules rules, XmlResolver resolver)
     : this(reader, rules, resolver, Nvdl.DefaultConfig)
 {
 }
예제 #11
0
 public NvdlValidatingReader(XmlReader reader, NvdlRules rules)
     : this(reader, rules, new XmlUrlResolver())
 {
 }