2 // XmlDataSourceResolver.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
12 using System.Collections;
14 using System.Data.SqlXml;
19 public class XmlDataSourceResolver : XmlResolver
21 XmlNameTable nameTable;
24 public XmlDataSourceResolver ()
25 : this (new NameTable ())
29 public XmlDataSourceResolver (XmlNameTable nameTable)
31 this.nameTable = nameTable;
32 table = new Hashtable ();
35 public virtual int Count {
36 get { return table.Count; }
39 public ICredentials Credentials {
40 set { throw new NotImplementedException (); }
43 public virtual object this [string query] {
44 get { return table [new Uri (query, true, true)]; }
47 public virtual void Add (string name, IDbConnection dbConnection)
49 table.Add (new Uri (name), dbConnection);
52 public virtual void Add (string name, IDbTransaction dbTransaction)
54 table.Add (new Uri (name), dbTransaction);
57 public virtual void Add (string name, string sourceUri)
59 table.Add (new Uri (name), sourceUri);
62 public virtual void Add (string name, XmlReader documentReader)
64 table.Add (new Uri (name), documentReader);
67 public virtual void Add (string name, XPathNavigator2 document)
69 table.Add (new Uri (name), document);
72 public virtual void Clear ()
77 public virtual bool Contains (string name)
79 return table.ContainsKey (new Uri (name, true, true));
82 public override object GetEntity (Uri absoluteUri,
84 Type ofObjectToReturn)
86 if (absoluteUri == null)
87 throw new ArgumentNullException ("absoluteUri");
89 if (ofObjectToReturn == null)
90 throw new ArgumentNullException ("ofObjectToReturn");
92 object o = table [absoluteUri];
96 Type type = o.GetType ();
97 if (type == ofObjectToReturn)
99 else if (type.IsSubClassOf (ofObjectToReturn))
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 ();
110 throw new NotSupportedException ();
114 private XPathNavigator2 GetXPathNavigator (object o)
117 return new XPathDocument2 (new XmlTextReader (o as string)).CreateNavigator ();
118 else if (o is XmlReader)
119 return new XPathDocument2 (o as XmlReader).CreateNavigator ();
121 throw new NotImplementedException ();
124 public IDictionaryEnumerator GetEnumerator ()
126 return table.GetEnumerator ();
129 public void Remove (string name)
131 table.Remove (new Uri (name, true, true));
134 public override Uri ResolveUri (Uri baseUri, string relativeUri)
136 // XmlDataSourceResolver has no concept of base URIs.
138 // Note that this constructor uses new .NET 1.2 feature.
139 return new Uri (relativeUri, true, true)