**** Merged from MCS ****
[mono-project.git] / mcs / class / System.XML / System.Xml.Query / XQueryStaticContext.cs
blobe17033f21a93377268476007c962d20e6a7496ab
1 //
2 // XQueryStaticContext.cs - XQuery static context components
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
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.
29 #if NET_2_0
31 using System;
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Globalization;
35 using System.IO;
36 using System.Security.Policy;
37 using System.Xml;
38 using System.Xml.Query;
39 using System.Xml.Schema;
40 using Mono.Xml.XPath2;
42 namespace Mono.Xml.XPath2
44 // Holds static context, that is created for each module.
45 internal class XQueryStaticContext
47 public static XQueryStaticContext Optimize (XQueryStaticContext ctx)
49 // FIXME: do type promotion and expression reduction
50 return ctx;
53 // Don't keep XQueryCompileOptions and XQueryMainModule
54 // inside this class. I don't want them affect this instance
55 // by being modified externally after the compilation.
57 public XQueryStaticContext (
58 XQueryCompileOptions options,
59 XQueryCompileContext compileContext,
60 ExprSequence queryBody,
61 XmlSchemaSet inScopeSchemas,
62 IDictionary inScopeVariables,
63 XQueryFunctionTable functionSignatures,
64 IXmlNamespaceResolver nsResolver,
65 string defaultFunctionNamespace,
66 bool preserveWhitespace,
67 bool constructionSpace,
68 bool defaultOrdered,
69 string baseUri,
70 Evidence evidence,
71 XQueryCommandImpl commandImpl)
73 // Initialization phase.
74 compat = options.Compatibility;
75 nameTable = options.NameTable;
76 this.queryBody = queryBody;
77 this.nsResolver = nsResolver;
78 this.defaultFunctionNamespace = defaultFunctionNamespace;
79 // elemNSManager = new XmlNamespaceManager (nameTable);
80 // funcNSManager = new XmlNamespaceManager (nameTable);
81 xqueryFlagger = options.XQueryFlagger;
82 xqueryStaticFlagger = options.XQueryStaticFlagger;
83 // xqueryResolver = options.KnownDocumentResolver;
84 knownCollections = (IDictionary) options.KnownCollections.Clone ();
85 functions = functionSignatures;
86 this.compileContext = compileContext;
87 this.inScopeSchemas = inScopeSchemas;
88 this.inScopeVariables = inScopeVariables;
89 this.preserveWhitespace = preserveWhitespace;
90 this.preserveConstructionSpace = constructionSpace;
91 this.defaultOrdered = defaultOrdered;
92 this.baseUri = baseUri;
93 this.defaultCollation = options.DefaultCollation;
94 // FIXME: set contextItemStaticType
95 // FIXME: set extDocResolver
97 this.evidence = evidence;
98 this.commandImpl = commandImpl;
101 // It holds in-effect components et. al.
102 XQueryCompileContext compileContext;
104 XmlNameTable nameTable;
105 Evidence evidence; // for safe custom function execution / safe assembly loading
106 XQueryCommandImpl commandImpl; // for event delegate
108 ExprSequence queryBody;
110 // See XQuery 1.0, 2.1.1 "Static Context"
111 XmlQueryDialect compat; // XPath 1.0 compatibility mode
112 IXmlNamespaceResolver nsResolver; // Manages "statically known namespaces" and "default element/type namespace"
113 string defaultFunctionNamespace; // default function namespace
114 XmlSchemaSet inScopeSchemas; // in-scope schemas
115 IDictionary inScopeVariables;
116 Type contextItemStaticType; // TODO: context item static type?
117 XQueryFunctionTable functions;
119 // Statically known collations is not defined here. It is equal to all supported CultureInfo.
120 // IDictionary staticallyKnownCollations;
122 CultureInfo defaultCollation; // or TextInfo ?
123 bool preserveConstructionSpace; // construction mode
124 bool defaultOrdered; // Ordering mode
125 bool preserveWhitespace; // Xml space policy
126 string baseUri;
127 // XmlResolver extDocResolver; // statically known documents
128 IDictionary knownCollections; // statically known collections
129 bool xqueryFlagger;
130 bool xqueryStaticFlagger;
132 // Properties
134 public XQueryCompileContext CompileContext {
135 get { return compileContext; }
138 public XmlQueryDialect Compatibility {
139 get { return compat; }
142 public ExprSequence QueryBody {
143 get { return queryBody; }
146 public XmlNameTable NameTable {
147 get { return nameTable; }
150 public Evidence Evidence {
151 get { return evidence; }
154 public CultureInfo DefaultCollation {
155 get { return defaultCollation; }
158 public XmlSchemaSet InScopeSchemas {
159 get { return inScopeSchemas; }
162 // in-scope functions.
163 public XQueryFunctionTable InScopeFunctions {
164 get { return functions; }
167 // in-scope variables. XmlQualifiedName to XPathItem
168 public IDictionary InScopeVariables {
169 get { return inScopeVariables; }
172 public bool PreserveWhitespace {
173 get { return preserveWhitespace; }
176 public bool PreserveConstructionSpace {
177 get { return preserveConstructionSpace; }
180 public bool DefaultOrdered {
181 get { return defaultOrdered; }
184 // statically known collections. string to ICollection (or XPathItemIterator, or XPathNodeIterator).
185 public IDictionary KnownCollections {
186 get { return knownCollections; }
189 public bool XQueryFlagger {
190 get { return xqueryFlagger; }
193 public bool XQueryStaticFlagger {
194 get { return xqueryStaticFlagger; }
197 public string BaseUri {
198 get { return baseUri; }
201 public IXmlNamespaceResolver NSResolver {
202 get { return nsResolver; }
205 public string DefaultFunctionNamespace {
206 get { return defaultFunctionNamespace; }
207 set { defaultFunctionNamespace = value; }
210 // FIXME: consider those from imported modules
211 public XQueryFunction ResolveFunction (XmlQualifiedName name)
213 XQueryFunction f = functions [name];
214 if (f != null)
215 return f;
216 return null;
219 // FIXME: wait for W3C clarification.
220 internal CultureInfo GetCulture (string collation)
222 return null;
225 internal void OnMessageEvent (object sender, QueryEventArgs e)
227 commandImpl.ProcessMessageEvent (sender, e);
231 #endif