2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System / System.Configuration / ConfigXmlDocument.cs
blobdb6f6c7631256b55134ac6f54cffbb926d112159
1 //
2 // System.Configuration.ConfigXmlDocument
3 //
4 // Authors:
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #if NET_2_0 && CONFIGURATION_DEP
31 using System.Configuration.Internal;
32 #endif
33 using System.IO;
34 using System.Security;
35 using System.Security.Permissions;
37 #if (XML_DEP)
38 using System.Xml;
40 namespace System.Configuration
42 [PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
43 public sealed class ConfigXmlDocument : XmlDocument, IConfigXmlNode
44 #if NET_2_0 && CONFIGURATION_DEP
45 , IConfigErrorInfo
46 #endif
48 XmlTextReader reader;
49 string fileName;
50 int lineNumber;
52 public override XmlAttribute CreateAttribute (string prefix,
53 string localName,
54 string namespaceUri)
56 return new ConfigXmlAttribute (this, prefix, localName, namespaceUri);
59 public override XmlCDataSection CreateCDataSection (string data)
61 return new ConfigXmlCDataSection (this, data);
64 public override XmlComment CreateComment (string comment)
66 return new ConfigXmlComment (this, comment);
69 public override XmlElement CreateElement (string prefix, string localName, string namespaceUri)
71 return new ConfigXmlElement (this, prefix, localName, namespaceUri);
74 public override XmlSignificantWhitespace CreateSignificantWhitespace (string data)
76 return base.CreateSignificantWhitespace (data);
79 public override XmlText CreateTextNode (string text)
81 return new ConfigXmlText (this, text);
84 public override XmlWhitespace CreateWhitespace (string data)
86 return base.CreateWhitespace (data);
89 public override void Load (string filename)
91 XmlTextReader rd = new XmlTextReader (filename);
92 try {
93 rd.MoveToContent ();
94 LoadSingleElement (filename, rd);
95 } finally {
96 rd.Close ();
100 public void LoadSingleElement (string filename, XmlTextReader sourceReader)
102 fileName = filename;
103 lineNumber = sourceReader.LineNumber;
104 string xml = sourceReader.ReadOuterXml();
105 reader = new XmlTextReader (new StringReader (xml), sourceReader.NameTable);
106 Load (reader);
107 reader.Close ();
110 public string Filename
112 get {
113 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
114 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
116 return fileName;
120 public int LineNumber
122 get {
123 return lineNumber;
127 #if NET_2_0 && CONFIGURATION_DEP
128 string System.Configuration.Internal.IConfigErrorInfo.Filename {
129 get { return Filename; }
132 int System.Configuration.Internal.IConfigErrorInfo.LineNumber {
133 get { return LineNumber; }
135 #endif
137 string IConfigXmlNode.Filename {
138 get { return Filename; }
141 int IConfigXmlNode.LineNumber {
142 get { return LineNumber; }
146 // Wrappers for Xml* that just provide file name and line number addition
148 class ConfigXmlAttribute : XmlAttribute, IConfigXmlNode
149 #if NET_2_0 && CONFIGURATION_DEP
150 , IConfigErrorInfo
151 #endif
153 string fileName;
154 int lineNumber;
156 public ConfigXmlAttribute (ConfigXmlDocument document,
157 string prefix,
158 string localName,
159 string namespaceUri)
160 : base (prefix, localName, namespaceUri, document)
162 fileName = document.fileName;
163 lineNumber = document.LineNumber;
166 public string Filename
168 get {
169 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
170 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
172 return fileName;
176 public int LineNumber
178 get {
179 return lineNumber;
184 class ConfigXmlCDataSection : XmlCDataSection, IConfigXmlNode
185 #if NET_2_0 && CONFIGURATION_DEP
186 , IConfigErrorInfo
187 #endif
189 string fileName;
190 int lineNumber;
192 public ConfigXmlCDataSection (ConfigXmlDocument document, string data)
193 : base (data, document)
195 fileName = document.fileName;
196 lineNumber = document.LineNumber;
199 public string Filename
201 get {
202 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
203 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
205 return fileName;
209 public int LineNumber
211 get {
212 return lineNumber;
217 class ConfigXmlComment : XmlComment, IConfigXmlNode
219 string fileName;
220 int lineNumber;
222 public ConfigXmlComment (ConfigXmlDocument document, string comment)
223 : base (comment, document)
225 fileName = document.fileName;
226 lineNumber = document.LineNumber;
229 public string Filename
231 get {
232 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
233 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
235 return fileName;
239 public int LineNumber
241 get {
242 return lineNumber;
247 class ConfigXmlElement : XmlElement, IConfigXmlNode
248 #if NET_2_0 && CONFIGURATION_DEP
249 , IConfigErrorInfo
250 #endif
252 string fileName;
253 int lineNumber;
255 public ConfigXmlElement (ConfigXmlDocument document,
256 string prefix,
257 string localName,
258 string namespaceUri)
259 : base (prefix, localName, namespaceUri, document)
261 fileName = document.fileName;
262 lineNumber = document.LineNumber;
265 public string Filename
267 get {
268 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
269 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
271 return fileName;
275 public int LineNumber
277 get {
278 return lineNumber;
283 class ConfigXmlText : XmlText, IConfigXmlNode
284 #if NET_2_0 && CONFIGURATION_DEP
285 , IConfigErrorInfo
286 #endif
288 string fileName;
289 int lineNumber;
291 public ConfigXmlText (ConfigXmlDocument document, string data)
292 : base (data, document)
294 fileName = document.fileName;
295 lineNumber = document.LineNumber;
298 public string Filename
300 get {
301 if ((fileName != null) && (fileName.Length > 0) && SecurityManager.SecurityEnabled) {
302 new FileIOPermission (FileIOPermissionAccess.PathDiscovery, fileName).Demand ();
304 return fileName;
308 public int LineNumber
310 get {
311 return lineNumber;
318 #endif