Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / XsltOld / InputScope.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="InputScope.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 namespace System.Xml.Xsl.XsltOld {
9     using Res = System.Xml.Utils.Res;
10     using System;
11     using System.Diagnostics;
12     using System.Xml;
13     using System.Xml.XPath;
14     using System.Collections;
15
16     internal class InputScope : DocumentScope {
17         private InputScope      parent;
18         private bool            forwardCompatibility;
19         private bool            canHaveApplyImports;
20         private Hashtable       variables;
21         private Hashtable       extensionNamespaces;
22         private Hashtable       excludedNamespaces;
23        
24         internal InputScope Parent {
25             get { return this.parent; }
26         }
27
28         internal Hashtable Variables {
29             get { return this.variables; }
30         }
31         
32         internal bool ForwardCompatibility {
33             get { return this.forwardCompatibility; }
34             set { this.forwardCompatibility = value; }
35         }
36
37         internal bool CanHaveApplyImports {
38             get { return this.canHaveApplyImports; }
39             set { this.canHaveApplyImports = value; }
40         }
41
42         internal InputScope(InputScope parent) {
43             Init(parent);
44         }
45
46         internal void Init(InputScope parent) {
47             this.scopes = null;
48             this.parent = parent;
49
50             if (this.parent != null) {
51                 this.forwardCompatibility = this.parent.forwardCompatibility;
52                 this.canHaveApplyImports  = this.parent.canHaveApplyImports;
53             }
54         }
55
56         internal void InsertExtensionNamespace(String nspace) {
57             if (this.extensionNamespaces == null ) {
58                 this.extensionNamespaces = new Hashtable();
59             }
60             this.extensionNamespaces[nspace] = null;
61         }
62         
63         internal bool IsExtensionNamespace(String nspace) {
64             if (extensionNamespaces == null ) {
65                 return false;
66             }
67             return extensionNamespaces.Contains(nspace);
68         }
69         
70         internal void InsertExcludedNamespace(String nspace) {
71             if (this.excludedNamespaces == null ) {
72                 this.excludedNamespaces = new Hashtable();
73             }
74             this.excludedNamespaces[nspace] = null;
75         }
76
77         internal bool IsExcludedNamespace(String nspace) {
78             if (excludedNamespaces == null ) {
79                 return false;
80             }
81             return excludedNamespaces.Contains(nspace);
82         }
83         
84         internal void InsertVariable(VariableAction variable) {
85             Debug.Assert(variable != null);
86
87             if (this.variables == null) {
88                 this.variables = new Hashtable();
89             }
90             this.variables[variable.Name] = variable;
91         }
92         
93         internal int GetVeriablesCount() {
94             if (this.variables == null) {
95                 return 0;
96             }
97             return this.variables.Count;
98         }
99
100         public VariableAction ResolveVariable(XmlQualifiedName qname) {
101             for (InputScope inputScope = this; inputScope != null; inputScope = inputScope.Parent) {
102                 if (inputScope.Variables != null) {
103                     VariableAction variable = (VariableAction) inputScope.Variables[qname];
104                     if(variable != null) {
105                         return variable;
106                     }
107                 }
108             }
109             return null;
110         }
111
112         public VariableAction ResolveGlobalVariable(XmlQualifiedName qname) {
113             InputScope prevScope = null;
114             for (InputScope inputScope = this; inputScope != null; inputScope = inputScope.Parent) {
115                 prevScope = inputScope;
116             }
117             return prevScope.ResolveVariable(qname);
118         }
119     }
120 }