1 using System;
2 using System.Collections;
3 using System.Collections.Specialized;
4 using System.Xml;
5 using Commons.Xml;
6 
7 namespace Commons.Xml.Nvdl
8 {
9 	public class NvdlConfig
10 	{
11 		XmlResolver resolver = new XmlUrlResolver ();
12 		ArrayList providers = new ArrayList ();
13 
NvdlConfig()14 		public NvdlConfig ()
15 		{
16 			providers.Add (new NvdlBuiltInValidationProvider ());
17 		}
18 
AddProvider(NvdlValidationProvider provider)19 		public void AddProvider (NvdlValidationProvider provider)
20 		{
21 			providers.Add (provider);
22 		}
23 
24 		internal XmlResolver XmlResolverInternal {
25 			get { return resolver; }
26 		}
27 
28 		public XmlResolver XmlResolver {
29 			set { resolver = value; }
30 		}
31 
GetGenerator(NvdlValidate validate, string inheritSchemaType)32 		public NvdlValidatorGenerator GetGenerator (NvdlValidate validate, string inheritSchemaType)
33 		{
34 			this.resolver = this.XmlResolverInternal;
35 
36 			string schemaType = validate.SchemaType;
37 			if (schemaType == null)
38 				schemaType = inheritSchemaType;
39 			if (schemaType == null)
40 				schemaType = "application/xml";
41 
42 			foreach (NvdlValidationProvider p in providers) {
43 				NvdlValidatorGenerator g =
44 					p.CreateGenerator (validate, schemaType, this);
45 				if (g != null)
46 					return g;
47 			}
48 
49 			throw new NvdlCompileException (String.Format ("Either schema type '{0}' or the target schema document is not supported in this configuration. Add custom provider that supports this schema type.", schemaType), validate);
50 		}
51 	}
52 }
53