[runtime] Don't reset abort exception in invoke wrapper
[mono.git] / mcs / class / System.Data / Test / ProviderTests / Common / ConnectionConfig.cs
1 //
2 // ConnectionConfig.cs  - Holds information on a specific connection and
3 // corresponding engine to test.
4 //
5 // Author:
6 //      Gert Driesen (drieseng@users.sourceforge.net
7 //
8 // Copyright (c) 2008 Gert Driesen
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Collections;
32 using System.Configuration;
33 using System.Globalization;
34 using System.Xml;
35
36 namespace MonoTests.System.Data
37 {
38         internal sealed class ConnectionConfig
39         {
40                 private readonly string name;
41                 private readonly string factory;
42                 private readonly string connectionString;
43                 private readonly EngineConfig engine;
44
45                 private ConnectionConfig (string name, string factory, string connectionString, EngineConfig engine)
46                 {
47                         this.name = name;
48                         this.factory = factory;
49                         this.connectionString = connectionString;
50                         this.engine = engine;
51                 }
52
53                 internal static ConnectionConfig FromXml (XmlNode connNode, Hashtable engines)
54                 {
55                         return new ConnectionConfig (
56                                 GetAttribValue (connNode, "name", true),
57                                 GetAttribValue (connNode, "factory", true),
58                                 GetAttribValue (connNode, "connectionString", true),
59                                 GetEngine (connNode, engines));
60                 }
61
62                 public string Name {
63                         get { return name; }
64                 }
65
66                 public string Factory {
67                         get { return factory; }
68                 }
69
70                 public string ConnectionString {
71                         get { return connectionString; }
72                 }
73
74                 public EngineConfig Engine {
75                         get { return engine; }
76                 }
77
78                 static string GetAttribValue (XmlNode node, string name, bool required)
79                 {
80                         XmlAttribute attr = node.Attributes [name];
81                         if (attr == null) {
82                                 if (required)
83                                         throw CreateAttributeMissingException (name, node);
84                                 return null;
85                         }
86                         return attr.Value;
87                 }
88
89                 static EngineConfig GetEngine (XmlNode connNode, Hashtable engines)
90                 {
91                         XmlAttribute engineAttr = connNode.Attributes ["engine"];
92                         if (engineAttr == null)
93                                 throw CreateAttributeMissingException ("engine", connNode);
94
95                         string engineName = engineAttr.Value;
96                         EngineConfig engine = (EngineConfig) engines [engineName];
97                         if (engine == null) {
98                                 string msg = string.Format (CultureInfo.InvariantCulture,
99                                         "Engine '{0}' does not exist.", engineName);
100                                 throw new ConfigurationErrorsException (msg, engineAttr);
101                         }
102                         return engine;
103                 }
104
105                 static Exception CreateAttributeMissingException (string name, XmlNode node)
106                 {
107                         string msg = string.Format (CultureInfo.InvariantCulture,
108                                 "Missing '{0}' attribute.", name);
109                         throw new ConfigurationErrorsException (msg, node);
110                 }
111         }
112 }