2 // System.Data.OleDb.OleDbConnection
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
8 // (C) 2006 Mainsoft Corporation (http://www.mainsoft.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Configuration;
36 using System.Collections;
37 using System.Collections.Specialized;
39 namespace Mainsoft.Data.Configuration
41 class ProvidersSectionHandler : IConfigurationSectionHandler
43 public virtual object Create (object parent, object configContext, XmlNode section) {
44 if (section.Attributes != null && section.Attributes.Count != 0)
45 ThrowException ("Unrecognized attribute", section);
47 ArrayList providers = new ArrayList();
49 XmlNodeList providerElements = section.SelectNodes ("provider");
50 foreach (XmlNode child in providerElements) {
51 XmlNodeType ntype = child.NodeType;
52 if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
55 if (ntype != XmlNodeType.Element)
56 ThrowException ("Only elements allowed", child);
58 object parentProvider = null;
59 XmlAttribute extends = child.Attributes["parent"];
60 if (extends != null) {
61 string super = extends.Value;
62 string sectionName = super.Substring(0, super.IndexOf('#'));
63 string id = super.Substring(sectionName.Length+1);
64 IList supers = (IList) ConfigurationSettings.GetConfig(sectionName);
65 for (int i = 0; i < supers.Count; i++) {
66 Hashtable ht = (Hashtable)supers[i];
67 string curId = (string)ht["id"];
68 if (String.CompareOrdinal(id,curId) == 0) {
73 child.Attributes.Remove(extends);
76 DictionarySectionHandler handler = new DictionarySectionHandler();
77 Hashtable col = (Hashtable) handler.Create (parentProvider, null, child);
80 if (parent != null && parent is IList) {
81 IList parentList = (IList)parent;
82 for (int i = 0; i < parentList.Count; i++) {
83 Hashtable htParent = (Hashtable)parentList[i];
84 string parentId = (string)htParent["id"];
85 bool overriden = false;
86 for (int y = 0; y < providers.Count; y++) {
87 Hashtable htMe = (Hashtable)providers[y];
88 string myId = (string)htMe["id"];
89 if (String.CompareOrdinal(parentId,myId) == 0) {
91 foreach (object key in htParent.Keys)
92 if (!htMe.ContainsKey(key))
93 htMe[key] = htParent[key];
99 providers.Add(htParent);
106 static internal void ThrowException (string msg, XmlNode node)
108 if (node != null && node.Name != String.Empty)
109 msg = msg + " (node name: " + node.Name + ") ";
110 throw new ConfigurationException (msg, node);