Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / Mono.Xml.Ext / Mono.Xml.XPath2 / XQueryStaticContext.cs
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.
27 //
28
29
30 using System;
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.Globalization;
34 using System.IO;
35 using System.Security.Policy;
36 using System.Xml;
37 using System.Xml.Query;
38 using System.Xml.Schema;
39 using Mono.Xml.XPath2;
40
41 namespace Mono.Xml.XPath2
42 {
43         // Holds static context, that is created for each module.
44         internal class XQueryStaticContext
45         {
46                 public static XQueryStaticContext Optimize (XQueryStaticContext ctx)
47                 {
48                         // FIXME: do type promotion and expression reduction
49                         return ctx;
50                 }
51
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.
55
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,
67                         bool defaultOrdered,
68                         string baseUri,
69                         Evidence evidence,
70                         XQueryCommandImpl commandImpl)
71                 {
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
95
96                         this.evidence = evidence;
97                         this.commandImpl = commandImpl;
98                 }
99
100                 // It holds in-effect components et. al.
101                 XQueryCompileContext compileContext;
102
103                 XmlNameTable nameTable;
104                 Evidence evidence; // for safe custom function execution / safe assembly loading
105                 XQueryCommandImpl commandImpl; // for event delegate
106
107                 ExprSequence queryBody;
108
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;
117
118                 // Statically known collations is not defined here. It is equal to all supported CultureInfo.
119 //              IDictionary staticallyKnownCollations;
120
121                 CultureInfo defaultCollation; // or TextInfo ?
122                 bool preserveConstructionSpace; // construction mode
123                 bool defaultOrdered; // Ordering mode
124                 bool preserveWhitespace; // Xml space policy
125                 string baseUri;
126 //              XmlResolver extDocResolver; // statically known documents
127                 IDictionary knownCollections; // statically known collections
128                 bool xqueryFlagger;
129                 bool xqueryStaticFlagger;
130
131                 // Properties
132
133                 public XQueryCompileContext CompileContext {
134                         get { return compileContext; }
135                 }
136
137                 public XmlQueryDialect Compatibility {
138                         get { return compat; }
139                 }
140
141                 public ExprSequence QueryBody {
142                         get { return queryBody; }
143                 }
144
145                 public XmlNameTable NameTable {
146                         get { return nameTable; }
147                 }
148
149                 public Evidence Evidence {
150                         get { return evidence; }
151                 }
152
153                 public CultureInfo DefaultCollation {
154                         get { return defaultCollation; }
155                 }
156
157                 public XmlSchemaSet InScopeSchemas {
158                         get { return inScopeSchemas; }
159                 }
160
161                 // in-scope functions.
162                 public XQueryFunctionTable InScopeFunctions {
163                         get { return functions; }
164                 }
165
166                 // in-scope variables. XmlQualifiedName to XPathItem
167                 public IDictionary InScopeVariables {
168                         get { return inScopeVariables; }
169                 }
170
171                 public bool PreserveWhitespace {
172                         get { return preserveWhitespace; }
173                 }
174
175                 public bool PreserveConstructionSpace {
176                         get { return preserveConstructionSpace; }
177                 }
178
179                 public bool DefaultOrdered {
180                         get { return defaultOrdered; }
181                 }
182
183                 // statically known collections. string to ICollection (or XPathItemIterator, or XPathNodeIterator).
184                 public IDictionary KnownCollections {
185                         get { return knownCollections; }
186                 }
187
188                 public bool XQueryFlagger {
189                         get { return xqueryFlagger; }
190                 }
191
192                 public bool XQueryStaticFlagger {
193                         get { return xqueryStaticFlagger; }
194                 }
195
196                 public string BaseUri {
197                         get { return baseUri; }
198                 }
199
200                 public IXmlNamespaceResolver NSResolver {
201                         get { return nsResolver; }
202                 }
203
204                 public string DefaultFunctionNamespace {
205                         get { return defaultFunctionNamespace; }
206                         set { defaultFunctionNamespace = value; }
207                 }
208
209                 // FIXME: consider those from imported modules
210                 public XQueryFunction ResolveFunction (XmlQualifiedName name)
211                 {
212                         XQueryFunction f = functions [name];
213                         if (f != null)
214                                 return f;
215                         return null;
216                 }
217
218                 // FIXME: wait for W3C clarification.
219                 internal CultureInfo GetCulture (string collation)
220                 {
221                         return null;
222                 }
223
224                 internal void OnMessageEvent (object sender, QueryEventArgs e)
225                 {
226                         commandImpl.ProcessMessageEvent (sender, e);
227                 }
228         }
229 }