ce6688e4d1d552eee8ea11e6ac7b2c747462452e
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / XsltOld / NavigatorInput.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="NavigatorInput.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 Keywords = System.Xml.Xsl.Xslt.KeywordsTable;
15
16     internal class NavigatorInput {
17         private XPathNavigator     _Navigator;
18         private PositionInfo       _PositionInfo;
19         private InputScopeManager  _Manager;
20         private NavigatorInput     _Next;
21         private string             _Href;
22         private Keywords           _Atoms;
23
24         internal NavigatorInput Next {
25             get {
26                 return _Next;
27             }
28             set {
29                 _Next = value;
30             }
31         }
32
33         internal string Href {
34             get {
35                 return _Href;
36             }
37         }
38
39         internal Keywords Atoms {
40             get {
41                 return _Atoms;
42             }
43         }        
44
45         internal  XPathNavigator Navigator {
46             get {
47                 AssertInput();
48                 return _Navigator;
49             }
50         }
51
52         internal  InputScopeManager InputScopeManager {
53             get {
54                 AssertInput();
55                 return _Manager;
56             }
57         }
58
59         internal  bool Advance() {
60             AssertInput();
61             return _Navigator.MoveToNext();
62         }
63
64         internal  bool Recurse() {
65             AssertInput();
66             return _Navigator.MoveToFirstChild();
67         }
68
69         internal  bool ToParent() {
70             AssertInput();
71             return _Navigator.MoveToParent();
72         }
73
74         internal  void Close() {
75             _Navigator = null;
76             _PositionInfo = null;
77         }
78
79         //
80         // Input document properties
81         //
82
83         //
84         // XPathNavigator does not support line and position numbers
85         //
86
87         internal  int LineNumber { 
88             get { return _PositionInfo.LineNumber; }
89         }
90
91         internal  int LinePosition { 
92             get { return _PositionInfo.LinePosition; }
93         }
94
95         internal  XPathNodeType NodeType {
96             get {
97                 AssertInput();
98                 return _Navigator.NodeType;
99             }
100         }
101
102         internal  string Name {
103             get {
104                 AssertInput();
105                 return _Navigator.Name;
106             }
107         }
108
109         internal  string LocalName {
110             get {
111                 AssertInput();
112                 return _Navigator.LocalName;
113             }
114         }
115
116         internal  string NamespaceURI {
117             get {
118                 AssertInput();
119                 return _Navigator.NamespaceURI;
120             }
121         }
122
123         internal  string Prefix {
124             get {
125                 AssertInput();
126                 return _Navigator.Prefix;
127             }
128         }
129
130         internal  string Value {
131             get {
132                 AssertInput();
133                 return _Navigator.Value;
134             }
135         }
136
137         internal  bool IsEmptyTag {
138             get {
139                 AssertInput();
140                 return _Navigator.IsEmptyElement;
141             }
142         }
143
144         internal  string BaseURI {
145             get {
146                 return  _Navigator.BaseURI;
147             }
148         }
149         
150         internal  bool MoveToFirstAttribute() {
151             AssertInput();
152             return _Navigator.MoveToFirstAttribute();
153         }
154
155         internal  bool MoveToNextAttribute() {
156             AssertInput();
157             return _Navigator.MoveToNextAttribute();
158         }
159         internal  bool MoveToFirstNamespace() {
160             AssertInput();
161             return _Navigator.MoveToFirstNamespace(XPathNamespaceScope.ExcludeXml);
162         }
163
164         internal  bool MoveToNextNamespace() {
165             AssertInput();
166             return _Navigator.MoveToNextNamespace(XPathNamespaceScope.ExcludeXml);
167         }
168
169         //
170         // Constructor
171         //
172         internal NavigatorInput(XPathNavigator navigator, string baseUri, InputScope rootScope) {
173             if (navigator == null) {
174                 throw new ArgumentNullException("navigator");
175             }
176             if (baseUri == null) {
177                 throw new ArgumentNullException("baseUri");
178             }
179             Debug.Assert(navigator.NameTable != null);
180             _Next  = null;
181             _Href  = baseUri;
182             _Atoms = new Keywords(navigator.NameTable);
183             _Navigator = navigator;
184             _Manager   = new InputScopeManager(_Navigator, rootScope);
185             _PositionInfo = PositionInfo.GetPositionInfo(_Navigator);
186
187             /*BeginReading:*/
188             AssertInput();
189             if (NodeType == XPathNodeType.Root) {
190                 _Navigator.MoveToFirstChild();
191             }
192         }
193
194         internal NavigatorInput(XPathNavigator navigator): this(navigator, navigator.BaseURI, null) {}
195
196         //
197         // Debugging support
198         //
199         [System.Diagnostics.Conditional("DEBUG")]
200         internal void AssertInput() {
201             Debug.Assert(_Navigator != null);
202         }
203     }
204 }