XQueryCommand.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // System.Xml.Query.XQueryCommand
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Atsushi Enomoto ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2003
  9. // Copyright (C) Novell Inc., 2004
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if NET_2_0
  32. using System.Data;
  33. using System.Data.SqlXml;
  34. using System.IO;
  35. using System.Reflection;
  36. using System.Security.Policy;
  37. using System.Xml;
  38. using System.Xml.XPath;
  39. namespace System.Xml.Query
  40. {
  41. public class XQueryCommand
  42. {
  43. // They are obtained via reflection
  44. static Type implType;
  45. static MethodInfo compileMethod;
  46. static MethodInfo executeMethod;
  47. static XQueryCommand ()
  48. {
  49. implType = typeof (XPathNavigator).Assembly.GetType ("Mono.Xml.XPath2.XQueryCommandImpl");
  50. compileMethod = implType.GetMethod ("Compile");
  51. executeMethod = implType.GetMethod ("Execute");
  52. if (compileMethod == null)
  53. throw new InvalidOperationException ("Should not happen: XQueryCommandImpl.Compile() was not found.");
  54. if (executeMethod == null)
  55. throw new InvalidOperationException ("Should not happen: XQueryCommandImpl.Execute() was not found.");
  56. }
  57. #region Constructor
  58. [MonoTODO]
  59. public XQueryCommand ()
  60. {
  61. impl = Activator.CreateInstance (implType);
  62. }
  63. #endregion // Constructor
  64. object impl;
  65. #region Event
  66. public event QueryEventHandler OnMessageEvent;
  67. #endregion
  68. #region Methods
  69. // Compile
  70. [MonoTODO ("Null Evidence allowed?")]
  71. public void Compile (string query)
  72. {
  73. Compile (query, null);
  74. }
  75. public void Compile (string query, Evidence evidence)
  76. {
  77. Compile (new StringReader (query), evidence);
  78. }
  79. [MonoTODO ("Null Evidence allowed?")]
  80. public void Compile (TextReader query)
  81. {
  82. Compile (query, null);
  83. }
  84. [MonoTODO]
  85. public void Compile (TextReader query, Evidence evidence)
  86. {
  87. compileMethod.Invoke (impl, new object [] {query, evidence, this});
  88. }
  89. // Execute
  90. [MonoTODO ("Null args allowed?")]
  91. public void Execute (
  92. IXPathNavigable contextDocument,
  93. XmlWriter results)
  94. {
  95. Execute (contextDocument, null, null, results);
  96. }
  97. [MonoTODO ("Output StartDocument?")]
  98. public void Execute (
  99. XmlResolver dataSources,
  100. TextWriter results)
  101. {
  102. XmlWriter w = XmlWriter.Create (results);
  103. Execute (dataSources, null, w);
  104. }
  105. [MonoTODO ("Null args allowed?")]
  106. public void Execute (
  107. XmlResolver dataSources,
  108. XmlWriter results)
  109. {
  110. Execute (new XPathDocument (), dataSources, null, results);
  111. }
  112. [MonoTODO ("Null args allowed?")]
  113. public void Execute (
  114. IXPathNavigable contextDocument,
  115. XmlArgumentList args,
  116. XmlWriter results)
  117. {
  118. Execute (contextDocument, null, args, results);
  119. }
  120. [MonoTODO ("Null args allowed?")]
  121. public void Execute (
  122. IXPathNavigable contextDocument,
  123. XmlResolver resolver,
  124. XmlWriter results)
  125. {
  126. Execute (contextDocument, resolver, null, results);
  127. }
  128. [MonoTODO("Indentation?;write StartDocument?;Null args allowed?")]
  129. public void Execute (
  130. string contextDocumentUri,
  131. XmlResolver dataSources,
  132. Stream results)
  133. {
  134. Execute (contextDocumentUri, dataSources, null, results);
  135. }
  136. [MonoTODO("Indentation?;write StartDocument?;Null args allowed?")]
  137. public void Execute (
  138. string contextDocumentUri,
  139. XmlResolver dataSources,
  140. TextWriter results)
  141. {
  142. Execute (contextDocumentUri, dataSources, null, results);
  143. }
  144. [MonoTODO]
  145. public void Execute (
  146. string contextDocumentUri,
  147. XmlResolver dataSources,
  148. XmlWriter results)
  149. {
  150. Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, results);
  151. }
  152. [MonoTODO]
  153. public void Execute (
  154. XmlResolver dataSources,
  155. XmlArgumentList args,
  156. XmlWriter results)
  157. {
  158. Execute ((XPathNavigator) null, dataSources, args, results);
  159. }
  160. [MonoTODO]
  161. public void Execute (
  162. IXPathNavigable contextDocument,
  163. XmlResolver dataSources,
  164. XmlArgumentList args,
  165. XmlWriter results)
  166. {
  167. Execute (contextDocument != null ? contextDocument.CreateNavigator () : null, dataSources, args, results);
  168. }
  169. [MonoTODO]
  170. public void Execute (
  171. string contextDocumentUri,
  172. XmlResolver dataSources,
  173. XmlArgumentList args,
  174. Stream results)
  175. {
  176. Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, XmlWriter.Create (results));
  177. }
  178. [MonoTODO]
  179. public void Execute (
  180. string contextDocumentUri,
  181. XmlResolver dataSources,
  182. XmlArgumentList args,
  183. TextWriter results)
  184. {
  185. Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, XmlWriter.Create (results));
  186. }
  187. [MonoTODO]
  188. public void Execute (
  189. string contextDocumentUri,
  190. XmlResolver dataSources,
  191. XmlArgumentList args,
  192. XmlWriter results)
  193. {
  194. Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, results);
  195. }
  196. private void Execute (XPathNavigator context, XmlResolver ds, XmlArgumentList args, XmlWriter output)
  197. {
  198. executeMethod.Invoke (impl, new object [] {context, ds, args, output});
  199. }
  200. #endregion // Methods
  201. }
  202. }
  203. #endif // NET_2_0