2005-11-03 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / System / System.Configuration / ConfigurationException.cs
1 //
2 // System.Configuration.ConfigurationException.cs
3 //
4 // Author:
5 //   Duncan Mak (duncan@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Globalization;
33 using System.Runtime.Serialization;
34
35 #if (XML_DEP)
36 using System.Xml;
37 #endif
38
39 namespace System.Configuration 
40 {
41         [Serializable]
42         public class ConfigurationException : SystemException
43         {
44                 // Fields               
45                 string bareMessage;
46                 string filename;
47                 int line;
48
49                 //
50                 // Constructors
51                 //
52 #if NET_2_0
53                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
54 #endif
55                 public ConfigurationException ()
56                         : base (Locale.GetText ("There is an error in a configuration setting."))
57                 {
58                         filename = null;
59                         bareMessage = Locale.GetText ("There is an error in a configuration setting.");
60                         line = 0;
61                 }
62
63 #if NET_2_0
64                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
65 #endif
66                 public ConfigurationException (string message)
67                         : base (message)
68                 {
69                         bareMessage = message;
70                 }
71
72                 protected ConfigurationException (SerializationInfo info, StreamingContext context)
73                         : base (info, context)
74                 {
75                         filename = info.GetString ("filename");
76                         line = info.GetInt32 ("line");
77                 }
78
79 #if NET_2_0
80                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
81 #endif
82                 public ConfigurationException (string message, Exception inner)
83                         : base (message, inner)
84                 {
85                         bareMessage = message;
86                 }
87
88 #if (XML_DEP)
89 #if NET_2_0
90                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
91 #endif
92                 public ConfigurationException (string message, XmlNode node)
93                         : base (message)
94                 {
95                         filename = GetXmlNodeFilename(node);
96                         line = GetXmlNodeLineNumber(node);
97                         bareMessage = message;
98                 }
99
100 #if NET_2_0
101                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
102 #endif
103                 public ConfigurationException (string message, Exception inner, XmlNode node)
104                         : base (message, inner)
105                 {
106                         filename = GetXmlNodeFilename (node);
107                         line = GetXmlNodeLineNumber (node);
108                         bareMessage = message;
109                 }
110 #endif
111 #if NET_2_0
112                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
113 #endif
114                 public ConfigurationException (string message, string filename, int line)
115                         : base (message)
116                 {
117                         bareMessage = message;
118                         this.filename = filename;
119                         this.line= line;
120                 }
121
122 #if NET_2_0
123                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
124 #endif
125                 public ConfigurationException (string message, Exception inner, string filename, int line)
126                         : base (message)
127                 {
128                         bareMessage = message;
129                         this.filename = filename;
130                         this.line = line;
131                 }
132                 //
133                 // Properties
134                 //
135                 public string BareMessage
136                 {
137                         get  { return bareMessage; }
138                 }
139
140                 public string Filename
141                 {
142                         get { return filename; }
143                 }
144                 
145                 public int Line
146                 {
147                         get { return line; }
148                 }
149
150                 public override string Message
151                 {
152                         get {
153                                 string baseMsg = base.Message;
154                                 string f = (filename == null) ? String.Empty : filename;
155                                 string l = (line == 0) ? String.Empty : (" line " + line);
156
157                                 return baseMsg + " (" + f + l + ")";
158                         }
159                 }
160
161                 //
162                 // Methods
163                 //
164 #if (XML_DEP)
165 #if NET_2_0
166                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
167 #endif
168                 public static string GetXmlNodeFilename (XmlNode node)
169                 {
170                         if (!(node is IConfigXmlNode))
171                                 return String.Empty;
172
173                         return ((IConfigXmlNode) node).Filename;
174                 }
175
176 #if NET_2_0
177                 [Obsolete ("This class is obsolete.  Use System.Configuration.ConfigurationErrorsException")]
178 #endif
179                 public static int GetXmlNodeLineNumber (XmlNode node)
180                 {
181                         if (!(node is IConfigXmlNode))
182                                 return 0;
183
184                         return ((IConfigXmlNode) node).LineNumber;
185                 }
186 #endif
187                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
188                 {
189                         base.GetObjectData (info, context);
190                         info.AddValue ("filename", filename);
191                         info.AddValue ("line", line);
192                 }
193         }
194 }