XQueryStaticContext.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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.Xml;
  35. using System.Xml.Query;
  36. using System.Xml.Schema;
  37. using Mono.Xml.XPath2;
  38. namespace Mono.Xml.XPath2
  39. {
  40. // Holds static context, that is created for each module.
  41. internal class XQueryStaticContext
  42. {
  43. public static XQueryStaticContext Optimize (XQueryStaticContext ctx)
  44. {
  45. // FIXME: do type promotion and expression reduction
  46. return ctx;
  47. }
  48. // Don't keep XQueryCompileOptions and XQueryMainModule
  49. // inside this class. I don't want them affect this instance
  50. // by being modified externally after the compilation.
  51. public XQueryStaticContext (
  52. XQueryCompileOptions options,
  53. XQueryCompileContext compileContext,
  54. ExprSequence queryBody,
  55. XmlSchemaSet inScopeSchemas,
  56. IDictionary inScopeVariables,
  57. XQueryFunctionTable functionSignatures,
  58. IXmlNamespaceResolver nsResolver,
  59. string defaultFunctionNamespace,
  60. bool preserveWhitespace,
  61. bool constructionSpace,
  62. bool defaultOrdered,
  63. string baseUri)
  64. {
  65. // Initialization phase.
  66. compat = options.Compatibility;
  67. nameTable = options.NameTable;
  68. this.queryBody = queryBody;
  69. this.nsResolver = nsResolver;
  70. this.defaultFunctionNamespace = defaultFunctionNamespace;
  71. // elemNSManager = new XmlNamespaceManager (nameTable);
  72. // funcNSManager = new XmlNamespaceManager (nameTable);
  73. xqueryFlagger = options.XQueryFlagger;
  74. xqueryStaticFlagger = options.XQueryStaticFlagger;
  75. // xqueryResolver = options.KnownDocumentResolver;
  76. knownCollections = (IDictionary) options.KnownCollections.Clone ();
  77. functions = functionSignatures;
  78. this.compileContext = compileContext;
  79. this.inScopeSchemas = inScopeSchemas;
  80. this.inScopeVariables = inScopeVariables;
  81. this.preserveWhitespace = preserveWhitespace;
  82. this.preserveConstructionSpace = constructionSpace;
  83. this.defaultOrdered = defaultOrdered;
  84. this.baseUri = baseUri;
  85. this.defaultCollation = options.DefaultCollation;
  86. // FIXME: set contextItemStaticType
  87. // FIXME: set extDocResolver
  88. }
  89. // It holds in-effect components et. al.
  90. XQueryCompileContext compileContext;
  91. XmlNameTable nameTable;
  92. ExprSequence queryBody;
  93. // See XQuery 1.0, 2.1.1 "Static Context"
  94. XmlQueryDialect compat; // XPath 1.0 compatibility mode
  95. IXmlNamespaceResolver nsResolver; // Manages "statically known namespaces" and "default element/type namespace"
  96. string defaultFunctionNamespace; // default function namespace
  97. XmlSchemaSet inScopeSchemas; // in-scope schemas
  98. IDictionary inScopeVariables;
  99. Type contextItemStaticType; // TODO: context item static type?
  100. XQueryFunctionTable functions;
  101. // Statically known collations is not defined here. It is equal to all supported CultureInfo.
  102. // IDictionary staticallyKnownCollations;
  103. CultureInfo defaultCollation; // or TextInfo ?
  104. bool preserveConstructionSpace; // construction mode
  105. bool defaultOrdered; // Ordering mode
  106. bool preserveWhitespace; // Xml space policy
  107. string baseUri;
  108. // XmlResolver extDocResolver; // statically known documents
  109. IDictionary knownCollections; // statically known collections
  110. bool xqueryFlagger;
  111. bool xqueryStaticFlagger;
  112. // Properties
  113. public XQueryCompileContext CompileContext {
  114. get { return compileContext; }
  115. }
  116. public XmlQueryDialect Compatibility {
  117. get { return compat; }
  118. }
  119. public ExprSequence QueryBody {
  120. get { return queryBody; }
  121. }
  122. public XmlNameTable NameTable {
  123. get { return nameTable; }
  124. }
  125. public CultureInfo DefaultCollation {
  126. get { return defaultCollation; }
  127. }
  128. public XmlSchemaSet InScopeSchemas {
  129. get { return inScopeSchemas; }
  130. }
  131. // in-scope functions.
  132. public XQueryFunctionTable InScopeFunctions {
  133. get { return functions; }
  134. }
  135. // in-scope variables. XmlQualifiedName to XPathItem
  136. public IDictionary InScopeVariables {
  137. get { return inScopeVariables; }
  138. }
  139. public bool PreserveWhitespace {
  140. get { return preserveWhitespace; }
  141. }
  142. public bool PreserveConstructionSpace {
  143. get { return preserveConstructionSpace; }
  144. }
  145. public bool DefaultOrdered {
  146. get { return defaultOrdered; }
  147. }
  148. // statically known collections. string to ICollection (or XPathItemIterator, or XPathNodeIterator).
  149. public IDictionary KnownCollections {
  150. get { return knownCollections; }
  151. }
  152. public bool XQueryFlagger {
  153. get { return xqueryFlagger; }
  154. }
  155. public bool XQueryStaticFlagger {
  156. get { return xqueryStaticFlagger; }
  157. }
  158. public string BaseUri {
  159. get { return baseUri; }
  160. }
  161. public IXmlNamespaceResolver NSResolver {
  162. get { return nsResolver; }
  163. }
  164. public string DefaultFunctionNamespace {
  165. get { return defaultFunctionNamespace; }
  166. set { defaultFunctionNamespace = value; }
  167. }
  168. // FIXME: consider those from imported modules
  169. public XQueryFunction ResolveFunction (XmlQualifiedName name)
  170. {
  171. XQueryFunction f = functions [name];
  172. if (f != null)
  173. return f;
  174. return null;
  175. }
  176. // FIXME: wait for W3C clarification.
  177. internal CultureInfo GetCulture (string collation)
  178. {
  179. return null;
  180. }
  181. }
  182. }
  183. #endif