2005-06-05 Peter Bartok <pbartok@novell.com>
[mono.git] / mcs / class / System.Data.SqlXml / System.Xml.Query / XQueryCommand.cs
index afe80c412faf8d6f366f9432c78c90f3e85c9497..40d1bd748002e259589e35a32fda2eb6151ed849 100755 (executable)
 using System.Data;\r
 using System.Data.SqlXml;\r
 using System.IO;\r
+using System.Reflection;\r
+using System.Security.Policy;\r
+using System.Xml;\r
+using System.Xml.XPath;\r
 \r
 namespace System.Xml.Query \r
 {\r
        public class XQueryCommand\r
        {\r
-               #region Constructors\r
+               // They are obtained via reflection\r
+               static Type implType;\r
+               static MethodInfo compileMethod;\r
+               static MethodInfo executeMethod;\r
+\r
+               static XQueryCommand ()\r
+               {\r
+                       implType = typeof (XPathNavigator).Assembly.GetType ("Mono.Xml.XPath2.XQueryCommandImpl");\r
+                       compileMethod = implType.GetMethod ("Compile");\r
+                       executeMethod = implType.GetMethod ("Execute");\r
+                       if (compileMethod == null)\r
+                               throw new InvalidOperationException ("Should not happen: XQueryCommandImpl.Compile() was not found.");\r
+                       if (executeMethod == null)\r
+                               throw new InvalidOperationException ("Should not happen: XQueryCommandImpl.Execute() was not found.");\r
+               }\r
+\r
+               #region Constructor\r
 \r
                [MonoTODO]\r
                public XQueryCommand ()\r
                {\r
+                       impl = Activator.CreateInstance (implType);\r
                }\r
 \r
-               #endregion // Constructors\r
+               #endregion // Constructor\r
 \r
-               #region Properties\r
+               object impl;\r
 \r
-               [MonoTODO]\r
-               public SqlQueryOptions SqlQueryOptions {\r
-                       get { throw new NotImplementedException (); }\r
-                       set { throw new NotImplementedException (); }\r
-               }\r
+               #region Event\r
 \r
-               [MonoTODO]\r
-               public XmlMappingDictionary XmlMappingDictionary {\r
-                       get { throw new NotImplementedException (); }\r
-                       set { throw new NotImplementedException (); }\r
-               }\r
+               public event QueryEventHandler OnMessageEvent;\r
 \r
-               #endregion // Properties\r
+               #endregion\r
 \r
                #region Methods\r
 \r
@@ -75,10 +88,9 @@ namespace System.Xml.Query
                        Compile (query, null);\r
                }\r
 \r
-               [MonoTODO]\r
                public void Compile (string query, Evidence evidence)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Compile (new StringReader (query), evidence);\r
                }\r
 \r
                [MonoTODO ("Null Evidence allowed?")]\r
@@ -90,21 +102,7 @@ namespace System.Xml.Query
                [MonoTODO]\r
                public void Compile (TextReader query, Evidence evidence)\r
                {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-               // CompileView\r
-\r
-               [MonoTODO]\r
-               public void CompileView (string query, string mappingLocation)\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-               [MonoTODO]\r
-               public void CompileView (TextReader query, string mappingLocation)\r
-               {\r
-                       throw new NotImplementedException ();\r
+                       compileMethod.Invoke (impl, new object [] {query, evidence, this});\r
                }\r
 \r
                // Execute\r
@@ -122,7 +120,7 @@ namespace System.Xml.Query
                        XmlResolver dataSources, \r
                        TextWriter results)\r
                {\r
-                       XmlTextWriter w = new XmlTextWriter (results);\r
+                       XmlWriter w = XmlWriter.Create (results);\r
                        Execute (dataSources, null, w);\r
                }\r
 \r
@@ -131,7 +129,7 @@ namespace System.Xml.Query
                        XmlResolver dataSources, \r
                        XmlWriter results)\r
                {\r
-                       Execute ((IXPathNavigable) null, dataSources, null, results);\r
+                       Execute (new XPathDocument (), dataSources, null, results);\r
                }\r
 \r
                [MonoTODO ("Null args allowed?")]\r
@@ -176,7 +174,7 @@ namespace System.Xml.Query
                        XmlResolver dataSources, \r
                        XmlWriter results)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, results);\r
                }\r
 \r
                [MonoTODO]\r
@@ -185,7 +183,7 @@ namespace System.Xml.Query
                        XmlArgumentList args,\r
                        XmlWriter results)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Execute ((XPathNavigator) null, dataSources, args, results);\r
                }\r
 \r
                [MonoTODO]\r
@@ -195,7 +193,7 @@ namespace System.Xml.Query
                        XmlArgumentList args,\r
                        XmlWriter results)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Execute (contextDocument != null ? contextDocument.CreateNavigator () : null, dataSources, args, results);\r
                }\r
 \r
                [MonoTODO]\r
@@ -205,7 +203,7 @@ namespace System.Xml.Query
                        XmlArgumentList args,\r
                        Stream results)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, XmlWriter.Create (results));\r
                }\r
 \r
                [MonoTODO]\r
@@ -215,7 +213,7 @@ namespace System.Xml.Query
                        XmlArgumentList args,\r
                        TextWriter results)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, XmlWriter.Create (results));\r
                }\r
 \r
                [MonoTODO]\r
@@ -225,15 +223,12 @@ namespace System.Xml.Query
                        XmlArgumentList args,\r
                        XmlWriter results)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       Execute (new XPathDocument (XmlReader.Create (contextDocumentUri)), dataSources, args, results);\r
                }\r
 \r
-               // ExecuteView\r
-\r
-               [MonoTODO]\r
-               public void ExecuteView (IDbConnection connection, TextWriter results)\r
+               private void Execute (XPathNavigator context, XmlResolver ds, XmlArgumentList args, XmlWriter output)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       executeMethod.Invoke (impl, new object [] {context, ds, args, output});\r
                }\r
 \r
                #endregion // Methods\r