2 // XQueryStaticContext.cs - XQuery static context components
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.Globalization;
35 using System.Security.Policy;
37 using System.Xml.Query;
38 using System.Xml.Schema;
39 using Mono.Xml.XPath2;
41 namespace Mono.Xml.XPath2
43 // Holds static context, that is created for each module.
44 internal class XQueryStaticContext
46 public static XQueryStaticContext Optimize (XQueryStaticContext ctx)
48 // FIXME: do type promotion and expression reduction
52 // Don't keep XQueryCompileOptions and XQueryMainModule
53 // inside this class. I don't want them affect this instance
54 // by being modified externally after the compilation.
56 public XQueryStaticContext (
57 XQueryCompileOptions options,
58 XQueryCompileContext compileContext,
59 ExprSequence queryBody,
60 XmlSchemaSet inScopeSchemas,
61 IDictionary inScopeVariables,
62 XQueryFunctionTable functionSignatures,
63 IXmlNamespaceResolver nsResolver,
64 string defaultFunctionNamespace,
65 bool preserveWhitespace,
66 bool constructionSpace,
70 XQueryCommandImpl commandImpl)
72 // Initialization phase.
73 compat = options.Compatibility;
74 nameTable = options.NameTable;
75 this.queryBody = queryBody;
76 this.nsResolver = nsResolver;
77 this.defaultFunctionNamespace = defaultFunctionNamespace;
78 // elemNSManager = new XmlNamespaceManager (nameTable);
79 // funcNSManager = new XmlNamespaceManager (nameTable);
80 xqueryFlagger = options.XQueryFlagger;
81 xqueryStaticFlagger = options.XQueryStaticFlagger;
82 // xqueryResolver = options.KnownDocumentResolver;
83 knownCollections = (IDictionary) options.KnownCollections.Clone ();
84 functions = functionSignatures;
85 this.compileContext = compileContext;
86 this.inScopeSchemas = inScopeSchemas;
87 this.inScopeVariables = inScopeVariables;
88 this.preserveWhitespace = preserveWhitespace;
89 this.preserveConstructionSpace = constructionSpace;
90 this.defaultOrdered = defaultOrdered;
91 this.baseUri = baseUri;
92 this.defaultCollation = options.DefaultCollation;
93 // FIXME: set contextItemStaticType
94 // FIXME: set extDocResolver
96 this.evidence = evidence;
97 this.commandImpl = commandImpl;
100 // It holds in-effect components et. al.
101 XQueryCompileContext compileContext;
103 XmlNameTable nameTable;
104 Evidence evidence; // for safe custom function execution / safe assembly loading
105 XQueryCommandImpl commandImpl; // for event delegate
107 ExprSequence queryBody;
109 // See XQuery 1.0, 2.1.1 "Static Context"
110 XmlQueryDialect compat; // XPath 1.0 compatibility mode
111 IXmlNamespaceResolver nsResolver; // Manages "statically known namespaces" and "default element/type namespace"
112 string defaultFunctionNamespace; // default function namespace
113 XmlSchemaSet inScopeSchemas; // in-scope schemas
114 IDictionary inScopeVariables;
115 Type contextItemStaticType; // TODO: context item static type?
116 XQueryFunctionTable functions;
118 // Statically known collations is not defined here. It is equal to all supported CultureInfo.
119 // IDictionary staticallyKnownCollations;
121 CultureInfo defaultCollation; // or TextInfo ?
122 bool preserveConstructionSpace; // construction mode
123 bool defaultOrdered; // Ordering mode
124 bool preserveWhitespace; // Xml space policy
126 // XmlResolver extDocResolver; // statically known documents
127 IDictionary knownCollections; // statically known collections
129 bool xqueryStaticFlagger;
133 public XQueryCompileContext CompileContext {
134 get { return compileContext; }
137 public XmlQueryDialect Compatibility {
138 get { return compat; }
141 public ExprSequence QueryBody {
142 get { return queryBody; }
145 public XmlNameTable NameTable {
146 get { return nameTable; }
149 public Evidence Evidence {
150 get { return evidence; }
153 public CultureInfo DefaultCollation {
154 get { return defaultCollation; }
157 public XmlSchemaSet InScopeSchemas {
158 get { return inScopeSchemas; }
161 // in-scope functions.
162 public XQueryFunctionTable InScopeFunctions {
163 get { return functions; }
166 // in-scope variables. XmlQualifiedName to XPathItem
167 public IDictionary InScopeVariables {
168 get { return inScopeVariables; }
171 public bool PreserveWhitespace {
172 get { return preserveWhitespace; }
175 public bool PreserveConstructionSpace {
176 get { return preserveConstructionSpace; }
179 public bool DefaultOrdered {
180 get { return defaultOrdered; }
183 // statically known collections. string to ICollection (or XPathItemIterator, or XPathNodeIterator).
184 public IDictionary KnownCollections {
185 get { return knownCollections; }
188 public bool XQueryFlagger {
189 get { return xqueryFlagger; }
192 public bool XQueryStaticFlagger {
193 get { return xqueryStaticFlagger; }
196 public string BaseUri {
197 get { return baseUri; }
200 public IXmlNamespaceResolver NSResolver {
201 get { return nsResolver; }
204 public string DefaultFunctionNamespace {
205 get { return defaultFunctionNamespace; }
206 set { defaultFunctionNamespace = value; }
209 // FIXME: consider those from imported modules
210 public XQueryFunction ResolveFunction (XmlQualifiedName name)
212 XQueryFunction f = functions [name];
218 // FIXME: wait for W3C clarification.
219 internal CultureInfo GetCulture (string collation)
224 internal void OnMessageEvent (object sender, QueryEventArgs e)
226 commandImpl.ProcessMessageEvent (sender, e);