2 // System.Data.Common.DbProviderFactoriesConfigurationHandler.cs
5 // Sureshkumar T (tsureshkumar@novell.com)
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Tim Coleman, 2003
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 using System
.Globalization
;
39 using System
.Configuration
;
41 namespace System
.Data
.Common
{
42 public class DbProviderFactoriesConfigurationHandler
: IConfigurationSectionHandler
47 public DbProviderFactoriesConfigurationHandler ()
51 #endregion // Constructors
56 public virtual object Create (object parent
, object configContext
, XmlNode section
)
58 DataSet ds
= new DataSet ("DbProviderFactories");
59 CreateDataTables (ds
, section
);
63 internal virtual void CreateDataTables (DataSet ds
, XmlNode section
)
65 DataTable dt
= ds
.Tables
.Add ("DbProviderFactories");
66 DataColumn
[] columns
= new DataColumn
[5];
67 columns
[0] = new DataColumn ("Name", typeof (string));
68 columns
[1] = new DataColumn ("Description", typeof (string));
69 columns
[2] = new DataColumn ("InvariantName", typeof (string));
70 columns
[3] = new DataColumn ("AssemblyQualifiedName", typeof (string));
71 columns
[4] = new DataColumn ("SupportedClasses", typeof (int));
72 dt
.Columns
.AddRange (columns
);
73 dt
.PrimaryKey
= new DataColumn
[] {columns [2]}
;
75 foreach (XmlNode node
in section
.SelectNodes (".//DbProviderFactories")) {
77 RemoveRows (dt
, node
);
81 internal string GetAttributeValue (XmlNode node
, string name
)
83 XmlAttribute attr
= node
.Attributes
[name
];
85 throw new ConfigurationException ("Required Attribute '" + name
+
86 "' is missing!", node
);
87 string value = attr
.Value
;
89 throw new ConfigurationException ("Attribute '" + name
+ "' cannot be empty!",
94 internal virtual void AddRows (DataTable dt
, XmlNode factoriesNode
)
96 foreach (XmlNode addNode
in factoriesNode
.SelectNodes (".//add")) {
97 if (addNode
.NodeType
!= XmlNodeType
.Element
)
101 string description
= "";
102 string invariant
= "";
104 string supportedClasses
= "";
107 name
= GetAttributeValue (addNode
, "name");
108 description
= GetAttributeValue (addNode
, "description");
109 invariant
= GetAttributeValue (addNode
, "invariant");
110 type
= GetAttributeValue (addNode
, "type");
111 supportedClasses
= GetAttributeValue (addNode
, "support");
113 support
= int.Parse (supportedClasses
, NumberStyles
.HexNumber
);
115 DataRow row
= dt
.NewRow ();
117 row
[1] = description
;
126 internal virtual void RemoveRows (DataTable dt
, XmlNode removeNode
)
128 foreach (XmlNode node
in removeNode
.SelectNodes (".//remove")) {
129 if (node
.NodeType
!= XmlNodeType
.Element
)
132 string invariant
= GetAttributeValue (node
, "invariant");
133 DataRow row
= dt
.Rows
.Find (invariant
);
140 #endregion // Methods