XQueryStaticContext.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // XQueryStaticContext.cs - XQuery static context components
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Collections;
  31. using System.Collections.Specialized;
  32. using System.Globalization;
  33. using System.IO;
  34. using System.Security.Policy;
  35. using System.Xml;
  36. using System.Xml.Query;
  37. using System.Xml.Schema;
  38. using Mono.Xml.XPath2;
  39. namespace Mono.Xml.XPath2
  40. {
  41. // Holds static context, that is created for each module.
  42. internal class XQueryStaticContext
  43. {
  44. public static XQueryStaticContext Optimize (XQueryStaticContext ctx)
  45. {
  46. // FIXME: do type promotion and expression reduction
  47. return ctx;
  48. }
  49. // Don't keep XQueryCompileOptions and XQueryMainModule
  50. // inside this class. I don't want them affect this instance
  51. // by being modified externally after the compilation.
  52. public XQueryStaticContext (
  53. XQueryCompileOptions options,
  54. XQueryCompileContext compileContext,
  55. ExprSequence queryBody,
  56. XmlSchemaSet inScopeSchemas,
  57. IDictionary inScopeVariables,
  58. XQueryFunctionTable functionSignatures,
  59. IXmlNamespaceResolver nsResolver,
  60. string defaultFunctionNamespace,
  61. bool preserveWhitespace,
  62. bool constructionSpace,
  63. bool defaultOrdered,
  64. string baseUri,
  65. Evidence evidence,
  66. XQueryCommandImpl commandImpl)
  67. {
  68. // Initialization phase.
  69. compat = options.Compatibility;
  70. nameTable = options.NameTable;
  71. this.queryBody = queryBody;
  72. this.nsResolver = nsResolver;
  73. this.defaultFunctionNamespace = defaultFunctionNamespace;
  74. // elemNSManager = new XmlNamespaceManager (nameTable);
  75. // funcNSManager = new XmlNamespaceManager (nameTable);
  76. xqueryFlagger = options.XQueryFlagger;
  77. xqueryStaticFlagger = options.XQueryStaticFlagger;
  78. // xqueryResolver = options.KnownDocumentResolver;
  79. knownCollections = (IDictionary) options.KnownCollections.Clone ();
  80. functions = functionSignatures;
  81. this.compileContext = compileContext;
  82. this.inScopeSchemas = inScopeSchemas;
  83. this.inScopeVariables = inScopeVariables;
  84. this.preserveWhitespace = preserveWhitespace;
  85. this.preserveConstructionSpace = constructionSpace;
  86. this.defaultOrdered = defaultOrdered;
  87. this.baseUri = baseUri;
  88. this.defaultCollation = options.DefaultCollation;
  89. // FIXME: set contextItemStaticType
  90. // FIXME: set extDocResolver
  91. this.evidence = evidence;
  92. this.commandImpl = commandImpl;
  93. }
  94. // It holds in-effect components et. al.
  95. XQueryCompileContext compileContext;
  96. XmlNameTable nameTable;
  97. Evidence evidence; // for safe custom function execution / safe assembly loading
  98. XQueryCommandImpl commandImpl; // for event delegate
  99. ExprSequence queryBody;
  100. // See XQuery 1.0, 2.1.1 "Static Context"
  101. XmlQueryDialect compat; // XPath 1.0 compatibility mode
  102. IXmlNamespaceResolver nsResolver; // Manages "statically known namespaces" and "default element/type namespace"
  103. string defaultFunctionNamespace; // default function namespace
  104. XmlSchemaSet inScopeSchemas; // in-scope schemas
  105. IDictionary inScopeVariables;
  106. Type contextItemStaticType; // TODO: context item static type?
  107. XQueryFunctionTable functions;
  108. // Statically known collations is not defined here. It is equal to all supported CultureInfo.
  109. // IDictionary staticallyKnownCollations;
  110. CultureInfo defaultCollation; // or TextInfo ?
  111. bool preserveConstructionSpace; // construction mode
  112. bool defaultOrdered; // Ordering mode
  113. bool preserveWhitespace; // Xml space policy
  114. string baseUri;
  115. // XmlResolver extDocResolver; // statically known documents
  116. IDictionary knownCollections; // statically known collections
  117. bool xqueryFlagger;
  118. bool xqueryStaticFlagger;
  119. // Properties
  120. public XQueryCompileContext CompileContext {
  121. get { return compileContext; }
  122. }
  123. public XmlQueryDialect Compatibility {
  124. get { return compat; }
  125. }
  126. public ExprSequence QueryBody {
  127. get { return queryBody; }
  128. }
  129. public XmlNameTable NameTable {
  130. get { return nameTable; }
  131. }
  132. public Evidence Evidence {
  133. get { return evidence; }
  134. }
  135. public CultureInfo DefaultCollation {
  136. get { return defaultCollation; }
  137. }
  138. public XmlSchemaSet InScopeSchemas {
  139. get { return inScopeSchemas; }
  140. }
  141. // in-scope functions.
  142. public XQueryFunctionTable InScopeFunctions {
  143. get { return functions; }
  144. }
  145. // in-scope variables. XmlQualifiedName to XPathItem
  146. public IDictionary InScopeVariables {
  147. get { return inScopeVariables; }
  148. }
  149. public bool PreserveWhitespace {
  150. get { return preserveWhitespace; }
  151. }
  152. public bool PreserveConstructionSpace {
  153. get { return preserveConstructionSpace; }
  154. }
  155. public bool DefaultOrdered {
  156. get { return defaultOrdered; }
  157. }
  158. // statically known collections. string to ICollection (or XPathItemIterator, or XPathNodeIterator).
  159. public IDictionary KnownCollections {
  160. get { return knownCollections; }
  161. }
  162. public bool XQueryFlagger {
  163. get { return xqueryFlagger; }
  164. }
  165. public bool XQueryStaticFlagger {
  166. get { return xqueryStaticFlagger; }
  167. }
  168. public string BaseUri {
  169. get { return baseUri; }
  170. }
  171. public IXmlNamespaceResolver NSResolver {
  172. get { return nsResolver; }
  173. }
  174. public string DefaultFunctionNamespace {
  175. get { return defaultFunctionNamespace; }
  176. set { defaultFunctionNamespace = value; }
  177. }
  178. // FIXME: consider those from imported modules
  179. public XQueryFunction ResolveFunction (XmlQualifiedName name)
  180. {
  181. XQueryFunction f = functions [name];
  182. if (f != null)
  183. return f;
  184. return null;
  185. }
  186. // FIXME: wait for W3C clarification.
  187. internal CultureInfo GetCulture (string collation)
  188. {
  189. return null;
  190. }
  191. internal void OnMessageEvent (object sender, QueryEventArgs e)
  192. {
  193. commandImpl.ProcessMessageEvent (sender, e);
  194. }
  195. }
  196. }
  197. #endif