2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Mono.Data / Provider.cs
1 //\r
2 // Mono.Data.Provider\r
3 //\r
4 // Authors:\r
5 //   Brian Ritchie (brianlritchie@hotmail.com) \r
6 //  \r
7 //\r
8 // Copyright (C) Brian Ritchie, 2002\r
9 // \r
10 //\r
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32 using System;\r
33 using System.Data;\r
34 using System.Reflection;\r
35 \r
36 namespace Mono.Data\r
37 {\r
38         public class Provider\r
39         {\r
40                 private string name = null;\r
41                 private string connectionTypeName;\r
42                 private string adapterTypeName;\r
43                 private string commandTypeName;\r
44                 private Type connectionType;\r
45                 private Type adapterType;\r
46                 private Type commandType;\r
47                 private string assemblyName;\r
48                 private string description;\r
49       \r
50                 public Provider(string _name, string _connection, \r
51                         string _dataadapter, string _command, string _assembly,\r
52                         string _description)\r
53                 {\r
54                         name = _name;\r
55                         connectionTypeName = _connection;\r
56                         adapterTypeName = _dataadapter;\r
57                         assemblyName = _assembly;\r
58                         commandTypeName = _command;\r
59                         description = _description;\r
60                 }\r
61 \r
62                 public Provider(string _name, Type _connection, Type _dataadapter, Type _command,\r
63                         string _description)\r
64                 {\r
65                         name = _name;\r
66                         connectionTypeName = _connection.FullName;\r
67                         adapterTypeName = _dataadapter.FullName;\r
68                         commandTypeName = _command.FullName;\r
69                         connectionType = _connection;\r
70                         adapterType = _dataadapter;\r
71                         commandType = _command;\r
72                         description = _description;\r
73                 }\r
74 \r
75                 public string Name\r
76                 {\r
77                         get {return name;}\r
78                 }\r
79 \r
80                 public string Description\r
81                 {\r
82                         get {return description;}\r
83                 }\r
84 \r
85                 public Type ConnectionType\r
86                 {\r
87                         get \r
88                         {\r
89                                 if (connectionType==null)\r
90                                 {\r
91                                         connectionType=Type.GetType(connectionTypeName+","+assemblyName);\r
92                                 }\r
93                                 return connectionType;\r
94                         }\r
95                 }\r
96 \r
97                 public Type DataAdapterType\r
98                 {\r
99                         get \r
100                         {\r
101                                 if (adapterType==null)\r
102                                 {\r
103                                         adapterType=Type.GetType(adapterTypeName+","+assemblyName);\r
104                                 }\r
105                                 return adapterType;\r
106                         }\r
107                 }\r
108 \r
109                 public Type CommandType\r
110                 {\r
111                         get \r
112                         {\r
113                                 if (commandType==null)\r
114                                 {\r
115                                         commandType=Type.GetType(commandTypeName+","+assemblyName);\r
116                                 }\r
117                                 return commandType;\r
118                         }\r
119                 }\r
120 \r
121                 public IDbConnection CreateConnection()\r
122                 {\r
123                         return (IDbConnection) Activator.CreateInstance(ConnectionType);\r
124                 }\r
125 \r
126                 public IDbDataAdapter CreateDataAdapter()\r
127                 {\r
128                         return (IDbDataAdapter) Activator.CreateInstance(DataAdapterType);\r
129                 }\r
130 \r
131                 public IDbCommand CreateCommand()\r
132                 {\r
133                         return (IDbCommand) Activator.CreateInstance(CommandType);\r
134                 }\r
135         }\r
136 }\r