9c997f1447041033ffb9f48760c9f21201f2f462
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / Core / XmlValidatingReader.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlValidatingReader.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 using System;
9 using System.IO;
10 using System.Text;
11 using System.Xml.Schema;
12 using System.Collections;
13 using System.Collections.Generic;
14 using System.Security.Permissions;
15
16 namespace System.Xml
17 {
18     [PermissionSetAttribute( SecurityAction.InheritanceDemand, Name = "FullTrust" )]
19     [Obsolete("Use XmlReader created by XmlReader.Create() method using appropriate XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202")]
20     public class XmlValidatingReader : XmlReader, IXmlLineInfo, IXmlNamespaceResolver {
21 //
22 // Member fields
23 //
24         XmlValidatingReaderImpl impl;
25 //
26 // Constructors
27 //
28         public XmlValidatingReader( XmlReader reader ) {
29             impl = new XmlValidatingReaderImpl( reader );
30             impl.OuterReader = this;
31         }
32         
33         public XmlValidatingReader( string xmlFragment, XmlNodeType fragType, XmlParserContext context ) {
34             if (xmlFragment == null) {
35                 throw new ArgumentNullException("xmlFragment");
36             }
37             impl = new XmlValidatingReaderImpl( xmlFragment, fragType, context );
38             impl.OuterReader = this;
39         }
40
41         public XmlValidatingReader( Stream xmlFragment, XmlNodeType fragType, XmlParserContext context ) {
42             if (xmlFragment == null) {
43                 throw new ArgumentNullException("xmlFragment");
44             }
45             impl = new XmlValidatingReaderImpl(xmlFragment, fragType, context);
46             impl.OuterReader = this;
47         }
48
49 //
50 // XmlReader members
51 //
52         public override XmlNodeType NodeType { 
53             get { return impl.NodeType; } 
54         }
55
56         public override string Name { 
57             get { return impl.Name; } 
58         }
59
60         public override string LocalName { 
61             get { return impl.LocalName; } 
62         }
63
64         public override string NamespaceURI { 
65             get { return impl.NamespaceURI; } 
66         }
67
68         public override string Prefix { 
69             get { return impl.Prefix; } 
70         }
71
72         public override bool HasValue { 
73             get { return impl.HasValue; } 
74         }
75
76         public override string Value { 
77             get { return impl.Value; } 
78         }
79
80         public override int Depth { 
81             get { return impl.Depth; } 
82         }
83
84         public override string BaseURI { 
85             get { return impl.BaseURI; } 
86         }
87
88         public override bool IsEmptyElement { 
89             get { return impl.IsEmptyElement; } 
90         }
91
92         public override bool IsDefault { 
93             get { return impl.IsDefault; } 
94         }
95
96         public override char QuoteChar { 
97             get { return impl.QuoteChar; } 
98         }
99
100         public override XmlSpace XmlSpace { 
101             get { return impl.XmlSpace; } 
102         }
103
104         public override string XmlLang { 
105             get { return impl.XmlLang; } 
106         }
107
108         // XmlTextReader does not override SchemaInfo, ValueType and ReadTypeValue
109
110         public override int AttributeCount { get { return impl.AttributeCount; } }
111
112         public override string GetAttribute( string name ) {
113             return impl.GetAttribute( name );
114         }
115
116         public override string GetAttribute( string localName, string namespaceURI ) {
117             return impl.GetAttribute( localName, namespaceURI );
118         }
119
120         public override string GetAttribute( int i ) {
121             return impl.GetAttribute( i );
122         }
123
124         public override bool MoveToAttribute( string name ) {
125             return impl.MoveToAttribute( name );
126         }
127
128         public override bool MoveToAttribute( string localName, string namespaceURI ) {
129             return impl.MoveToAttribute( localName, namespaceURI );
130         }
131
132         public override void MoveToAttribute( int i ) {
133             impl.MoveToAttribute( i );
134         }
135
136         public override bool MoveToFirstAttribute() {
137             return impl.MoveToFirstAttribute();
138         }
139
140         public override bool MoveToNextAttribute() {
141             return impl.MoveToNextAttribute();
142         }
143
144         public override bool MoveToElement() {
145             return impl.MoveToElement();
146         }
147
148         public override bool ReadAttributeValue() {
149             return impl.ReadAttributeValue();
150         }
151
152         public override bool Read() {
153             return impl.Read();
154         }
155
156         public override bool EOF { 
157             get { return impl.EOF; } 
158         }
159         
160         public override void Close() {
161             impl.Close();
162         }
163
164         public override ReadState ReadState { 
165             get { return impl.ReadState; } 
166         }
167         
168         public override XmlNameTable NameTable { 
169             get { return impl.NameTable; } 
170         }
171
172         public override String LookupNamespace( String prefix ) {
173             string ns = impl.LookupNamespace( prefix );
174             if ( ns != null && ns.Length == 0 ) {
175                 ns = null;
176             }
177             return ns;
178         }
179
180         public override bool CanResolveEntity  { 
181             get { return true; } 
182         }
183
184         public override void ResolveEntity() {
185             impl.ResolveEntity();
186         }
187
188     // Binary content access methods
189         public override bool CanReadBinaryContent {
190             get { return true; }
191         }
192
193         public override int ReadContentAsBase64( byte[] buffer, int index, int count ) {
194             return impl.ReadContentAsBase64( buffer, index, count );
195         }
196
197         public override int ReadElementContentAsBase64( byte[] buffer, int index, int count ) {
198             return impl.ReadElementContentAsBase64( buffer, index, count );
199         }
200
201         public override int ReadContentAsBinHex( byte[] buffer, int index, int count ) {
202             return impl.ReadContentAsBinHex( buffer, index, count );
203         }
204
205         public override int ReadElementContentAsBinHex( byte[] buffer, int index, int count ) {
206             return impl.ReadElementContentAsBinHex( buffer, index, count );
207         }
208
209         // Overriden helper methods
210
211         public override string ReadString() {
212             impl.MoveOffEntityReference();
213             return base.ReadString();
214         }
215         
216 //
217 // IXmlLineInfo members
218 //
219         public bool HasLineInfo() { return true; }
220
221         public int LineNumber { get { return impl.LineNumber; } }
222
223         public int LinePosition { get { return impl.LinePosition; } }
224
225 //
226 // IXmlNamespaceResolver members
227 //
228         IDictionary<string,string> IXmlNamespaceResolver.GetNamespacesInScope( XmlNamespaceScope scope ) {
229             return impl.GetNamespacesInScope( scope );
230         }
231
232         string IXmlNamespaceResolver.LookupNamespace(string prefix) {
233             return impl.LookupNamespace( prefix );
234         }
235
236         string IXmlNamespaceResolver.LookupPrefix( string namespaceName ) {
237             return impl.LookupPrefix( namespaceName );
238         }
239
240 //
241 // XmlValidatingReader 
242 //
243         public event ValidationEventHandler ValidationEventHandler {
244             add    { impl.ValidationEventHandler += value; }
245             remove { impl.ValidationEventHandler -= value; }
246         }
247
248         public object SchemaType {
249             get { return impl.SchemaType; }
250         }
251
252         public XmlReader Reader {
253             get { return impl.Reader; }
254         }
255
256         public ValidationType ValidationType {
257             get { return impl.ValidationType; }
258             set { impl.ValidationType = value; }
259         }
260
261         public XmlSchemaCollection Schemas {
262             get { return impl.Schemas; }
263         }
264
265         public EntityHandling EntityHandling {
266             get { return impl.EntityHandling; }
267             set { impl.EntityHandling = value; }
268         }
269         
270         public XmlResolver XmlResolver {
271             set { impl.XmlResolver = value; }
272         }
273
274         public bool Namespaces {
275             get { return impl.Namespaces; }
276             set { impl.Namespaces = value; }
277         }
278
279         public object ReadTypedValue() {
280             return impl.ReadTypedValue();
281         }
282
283         public Encoding Encoding {
284             get { return impl.Encoding; }
285         }
286 //
287 // Internal helper methods
288 //
289         internal XmlValidatingReaderImpl Impl {
290             get { return impl; }
291         }
292
293         internal override IDtdInfo DtdInfo {
294             get { return impl.DtdInfo; }
295         }
296     }
297 }