Copied remotely
[mono.git] / mcs / class / System.Data.SqlXml / System.Xml.Query / XQueryCommand.cs
1 //\r
2 // System.Xml.Query.XQueryCommand\r
3 //\r
4 // Author:\r
5 //   Tim Coleman (tim@timcoleman.com)\r
6 //   Atsushi Enomoto (atsushi@ximian.com)\r
7 //\r
8 // Copyright (C) Tim Coleman, 2003\r
9 // Copyright (C) Novell Inc., 2004\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 \r
33 #if NET_2_0\r
34 \r
35 using System.Data;\r
36 using System.Data.SqlXml;\r
37 using System.IO;\r
38 using System.Reflection;\r
39 using System.Security.Policy;\r
40 using System.Xml;\r
41 using System.Xml.XPath;\r
42 \r
43 namespace System.Xml.Query \r
44 {\r
45         public class XQueryCommand\r
46         {\r
47                 // They are obtained via reflection\r
48                 static Type implType;\r
49                 static MethodInfo compileMethod;\r
50                 static MethodInfo executeMethod;\r
51 \r
52                 static XQueryCommand ()\r
53                 {\r
54                         implType = typeof (XPathNavigator).Assembly.GetType ("Mono.Xml.XPath2.XQueryCommandImpl");\r
55                         compileMethod = implType.GetMethod ("Compile");\r
56                         executeMethod = implType.GetMethod ("Execute");\r
57                         if (compileMethod == null)\r
58                                 throw new InvalidOperationException ("Should not happen: XQueryCommandImpl.Compile() was not found.");\r
59                         if (executeMethod == null)\r
60                                 throw new InvalidOperationException ("Should not happen: XQueryCommandImpl.Execute() was not found.");\r
61                 }\r
62 \r
63                 #region Constructor\r
64 \r
65                 [MonoTODO]\r
66                 public XQueryCommand ()\r
67                 {\r
68                         impl = Activator.CreateInstance (implType);\r
69                 }\r
70 \r
71                 #endregion // Constructor\r
72 \r
73                 object impl;\r
74 \r
75                 #region Event\r
76 \r
77                 public event QueryEventHandler OnMessageEvent;\r
78 \r
79                 #endregion\r
80 \r
81                 #region Methods\r
82 \r
83                 // Compile\r
84 \r
85                 [MonoTODO ("Null Evidence allowed?")]\r
86                 public void Compile (string query)\r
87                 {\r
88                         Compile (query, null);\r
89                 }\r
90 \r
91                 public void Compile (string query, Evidence evidence)\r
92                 {\r
93                         Compile (new StringReader (query), evidence);\r
94                 }\r
95 \r
96                 [MonoTODO ("Null Evidence allowed?")]\r
97                 public void Compile (TextReader query)\r
98                 {\r
99                         Compile (query, null);\r
100                 }\r
101 \r
102                 [MonoTODO]\r
103                 public void Compile (TextReader query, Evidence evidence)\r
104                 {\r
105                         compileMethod.Invoke (impl, new object [] {query, evidence, this});\r
106                 }\r
107 \r
108                 // Execute\r
109 \r
110                 [MonoTODO ("Null args allowed?")]\r
111                 public void Execute (\r
112                         IXPathNavigable contextDocument,\r
113                         XmlWriter results)\r
114                 {\r
115                         Execute (contextDocument, null, null, results);\r
116                 }\r
117 \r
118                 [MonoTODO ("Output StartDocument?")]\r
119                 public void Execute (\r
120                         XmlResolver dataSources, \r
121                         TextWriter results)\r
122                 {\r
123                         XmlWriter w = XmlWriter.Create (results);\r
124                         Execute (dataSources, null, w);\r
125                 }\r
126 \r
127                 [MonoTODO ("Null args allowed?")]\r
128                 public void Execute (\r
129                         XmlResolver dataSources, \r
130                         XmlWriter results)\r
131                 {\r
132                         Execute (new XPathDocument (), dataSources, null, results);\r
133                 }\r
134 \r
135                 [MonoTODO ("Null args allowed?")]\r
136                 public void Execute (\r
137                         IXPathNavigable contextDocument,\r
138                         XmlArgumentList args,\r
139                         XmlWriter results)\r
140                 {\r
141                         Execute (contextDocument, null, args, results);\r
142                 }\r
143 \r
144                 [MonoTODO ("Null args allowed?")]\r
145                 public void Execute (\r
146                         IXPathNavigable contextDocument,\r
147                         XmlResolver resolver,\r
148                         XmlWriter results)\r
149                 {\r
150                         Execute (contextDocument, resolver, null, results);\r
151                 }\r
152 \r
153                 [MonoTODO("Indentation?;write StartDocument?;Null args allowed?")]\r
154                 public void Execute (\r
155                         string contextDocumentUri,\r
156                         XmlResolver dataSources,\r
157                         Stream results)\r
158                 {\r
159                         Execute (contextDocumentUri, dataSources, null, results);\r
160                 }\r
161 \r
162                 [MonoTODO("Indentation?;write StartDocument?;Null args allowed?")]\r
163                 public void Execute (\r
164                         string contextDocumentUri, \r
165                         XmlResolver dataSources, \r
166                         TextWriter results)\r
167                 {\r
168                         Execute (contextDocumentUri, dataSources, null, results);\r
169                 }\r
170 \r
171                 [MonoTODO]\r
172                 public void Execute (\r
173                         string contextDocumentUri, \r
174                         XmlResolver dataSources, \r
175                         XmlWriter results)\r
176                 {\r
177                         Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, results);\r
178                 }\r
179 \r
180                 [MonoTODO]\r
181                 public void Execute (\r
182                         XmlResolver dataSources, \r
183                         XmlArgumentList args,\r
184                         XmlWriter results)\r
185                 {\r
186                         Execute ((XPathNavigator) null, dataSources, args, results);\r
187                 }\r
188 \r
189                 [MonoTODO]\r
190                 public void Execute (\r
191                         IXPathNavigable contextDocument, \r
192                         XmlResolver dataSources,\r
193                         XmlArgumentList args,\r
194                         XmlWriter results)\r
195                 {\r
196                         Execute (contextDocument != null ? contextDocument.CreateNavigator () : null, dataSources, args, results);\r
197                 }\r
198 \r
199                 [MonoTODO]\r
200                 public void Execute (\r
201                         string contextDocumentUri, \r
202                         XmlResolver dataSources,\r
203                         XmlArgumentList args,\r
204                         Stream results)\r
205                 {\r
206                         Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, XmlWriter.Create (results));\r
207                 }\r
208 \r
209                 [MonoTODO]\r
210                 public void Execute (\r
211                         string contextDocumentUri, \r
212                         XmlResolver dataSources,\r
213                         XmlArgumentList args,\r
214                         TextWriter results)\r
215                 {\r
216                         Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, XmlWriter.Create (results));\r
217                 }\r
218 \r
219                 [MonoTODO]\r
220                 public void Execute (\r
221                         string contextDocumentUri, \r
222                         XmlResolver dataSources,\r
223                         XmlArgumentList args,\r
224                         XmlWriter results)\r
225                 {\r
226                         Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, results);\r
227                 }\r
228 \r
229                 private void Execute (XPathNavigator context, XmlResolver ds, XmlArgumentList args, XmlWriter output)\r
230                 {\r
231                         executeMethod.Invoke (impl, new object [] {context, ds, args, output});\r
232                 }\r
233 \r
234                 #endregion // Methods\r
235         }\r
236 }\r
237 \r
238 #endif // NET_2_0\r