* FileSystemInfo.cs: corrected COM visibility of UTC properties
[mono.git] / mcs / class / System.Data.SqlXml / System.Xml / XmlDataSourceResolver.cs
1 //
2 // XmlDataSourceResolver.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // (C)2003 Novell inc.
8 //
9 #if NET_1_2
10
11 using System;
12 using System.Collections;
13 using System.Data;
14 using System.Data.SqlXml;
15 using System.Net;
16
17 namespace System.Xml
18 {
19         public class XmlDataSourceResolver : XmlResolver
20         {
21                 XmlNameTable nameTable;
22                 Hashtable table;
23
24                 public XmlDataSourceResolver ()
25                         : this (new NameTable ())
26                 {
27                 }
28
29                 public XmlDataSourceResolver (XmlNameTable nameTable)
30                 {
31                         this.nameTable = nameTable;
32                         table = new Hashtable ();
33                 }
34
35                 public virtual int Count {
36                         get { return table.Count; }
37                 }
38
39                 public ICredentials Credentials {
40                         set { throw new NotImplementedException (); }
41                 }
42
43                 public virtual object this [string query] {
44                         get { return table [new Uri (query, true, true)]; }
45                 }
46
47                 public virtual void Add (string name, IDbConnection dbConnection)
48                 {
49                         table.Add (new Uri (name), dbConnection);
50                 }
51
52                 public virtual void Add (string name, IDbTransaction dbTransaction)
53                 {
54                         table.Add (new Uri (name), dbTransaction);
55                 }
56
57                 public virtual void Add (string name, string sourceUri)
58                 {
59                         table.Add (new Uri (name), sourceUri);
60                 }
61
62                 public virtual void Add (string name, XmlReader documentReader)
63                 {
64                         table.Add (new Uri (name), documentReader);
65                 }
66
67                 public virtual void Add (string name, XPathNavigator2 document)
68                 {
69                         table.Add (new Uri (name), document);
70                 }
71
72                 public virtual void Clear ()
73                 {
74                         table.Clear ();
75                 }
76
77                 public virtual bool Contains (string name)
78                 {
79                         return table.ContainsKey (new Uri (name, true, true));
80                 }
81
82                 public override object GetEntity (Uri absoluteUri,
83                         string role,
84                         Type ofObjectToReturn)
85                 {
86                         if (absoluteUri == null)
87                                 throw new ArgumentNullException ("absoluteUri");
88
89                         if (ofObjectToReturn == null)
90                                 throw new ArgumentNullException ("ofObjectToReturn");
91
92                         object o = table [absoluteUri];
93                         if (o == null)
94                                 return null;
95
96                         Type type = o.GetType ();
97                         if (type == ofObjectToReturn)
98                                 return o;
99                         else if (type.IsSubClassOf (ofObjectToReturn))
100                                 return o;
101
102                         switch (ofObjectToReturn.FullName) {
103                         case "System.Data.IDbConnection":
104                                 throw new NotImplementedException ();
105                         case "System.Xml.XPathNavigator2":
106                                 return GetXPathNavigator (o);
107                         case "System.Array": // array of IXPathNavigable
108                                 throw new NotImplementedException ();
109                         default:
110                                 throw new NotSupportedException ();
111                         }
112                 }
113
114                 private XPathNavigator2 GetXPathNavigator (object o)
115                 {
116                         if (o is string)
117                                 return new XPathDocument2 (new XmlTextReader (o as string)).CreateNavigator ();
118                         else if (o is XmlReader)
119                                 return new XPathDocument2 (o as XmlReader).CreateNavigator ();
120                         else
121                                 throw new NotImplementedException ();
122                 }
123
124                 public IDictionaryEnumerator GetEnumerator ()
125                 {
126                         return table.GetEnumerator ();
127                 }
128
129                 public void Remove (string name)
130                 {
131                         table.Remove (new Uri (name, true, true));
132                 }
133
134                 public override Uri ResolveUri (Uri baseUri, string relativeUri)
135                 {
136                         // XmlDataSourceResolver has no concept of base URIs.
137                         
138                         // Note that this constructor uses new .NET 1.2 feature.
139                         return new Uri (relativeUri, true, true)
140                 }
141         }
142 }
143
144 #endif