2 // ConnectionConfig.cs - Holds information on a specific connection and
3 // corresponding engine to test.
6 // Gert Driesen (drieseng@users.sourceforge.net
8 // Copyright (c) 2008 Gert Driesen
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
33 using System.Collections;
34 using System.Configuration;
35 using System.Globalization;
38 namespace MonoTests.System.Data.Connected
40 internal sealed class ConnectionConfig
42 private readonly string name;
43 private readonly string factory;
44 private readonly string connectionString;
45 private readonly EngineConfig engine;
47 private ConnectionConfig (string name, string factory, string connectionString, EngineConfig engine)
50 this.factory = factory;
51 this.connectionString = connectionString;
55 internal static ConnectionConfig FromXml (XmlNode connNode, Hashtable engines)
57 return new ConnectionConfig (
58 GetAttribValue (connNode, "name", true),
59 GetAttribValue (connNode, "factory", true),
60 GetAttribValue (connNode, "connectionString", true),
61 GetEngine (connNode, engines));
68 public string Factory {
69 get { return factory; }
72 public string ConnectionString {
73 get { return connectionString; }
76 public EngineConfig Engine {
77 get { return engine; }
80 static string GetAttribValue (XmlNode node, string name, bool required)
82 XmlAttribute attr = node.Attributes [name];
85 throw CreateAttributeMissingException (name, node);
91 static EngineConfig GetEngine (XmlNode connNode, Hashtable engines)
93 XmlAttribute engineAttr = connNode.Attributes ["engine"];
94 if (engineAttr == null)
95 throw CreateAttributeMissingException ("engine", connNode);
97 string engineName = engineAttr.Value;
98 EngineConfig engine = (EngineConfig) engines [engineName];
100 string msg = string.Format (CultureInfo.InvariantCulture,
101 "Engine '{0}' does not exist.", engineName);
102 throw new ConfigurationErrorsException (msg, engineAttr);
107 static Exception CreateAttributeMissingException (string name, XmlNode node)
109 string msg = string.Format (CultureInfo.InvariantCulture,
110 "Missing '{0}' attribute.", name);
111 throw new ConfigurationErrorsException (msg, node);