Add MIT license to System.XML.DLL
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaException.cs
1 // Author: Dwivedi, Ajay kumar\r
2 //            Adwiv@Yahoo.com\r
3
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 // 
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 // 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 using System;\r
25 using System.Globalization;\r
26 using System.Runtime.Serialization;\r
27 \r
28 \r
29 namespace System.Xml.Schema\r
30 {\r
31         /// <summary>\r
32         /// Summary description for XmlSchemaException.\r
33         /// </summary>\r
34         [Serializable]\r
35         public class XmlSchemaException : System.SystemException\r
36         {\r
37                 //fields\r
38                 private bool hasLineInfo;\r
39                 private int lineNumber;\r
40                 private int linePosition;\r
41                 private XmlSchemaObject sourceObj;\r
42                 private string sourceUri;\r
43 \r
44                 protected XmlSchemaException(SerializationInfo info, StreamingContext context)\r
45                         : base (info, context)\r
46                 {\r
47                         hasLineInfo = true;\r
48                         this.lineNumber = info.GetInt32 ("lineNumber");\r
49                         this.linePosition = info.GetInt32 ("linePosition");\r
50                         this.sourceUri = info.GetString ("sourceUri");\r
51                         this.sourceObj = info.GetValue ("sourceObj", typeof (XmlSchemaObject)) as XmlSchemaObject;\r
52                 }\r
53                 \r
54                 internal XmlSchemaException(string message, int lineNumber, int linePosition,\r
55                         XmlSchemaObject sourceObject, string sourceUri, Exception innerException)\r
56                         : base(message, innerException)\r
57                 {\r
58                         hasLineInfo = true;\r
59                         this.lineNumber         = lineNumber;\r
60                         this.linePosition       = linePosition;\r
61                         this.sourceObj          = sourceObject;\r
62                         this.sourceUri          = sourceUri;\r
63                 }\r
64 \r
65                 internal XmlSchemaException(string message, object sender,\r
66                         string sourceUri, XmlSchemaObject sourceObject, Exception innerException)\r
67                         : base(message, innerException)\r
68                 {\r
69                         IXmlLineInfo li = sender as IXmlLineInfo;\r
70                         if (li != null && li.HasLineInfo ()) {\r
71                                 hasLineInfo = true;\r
72                                 this.lineNumber = li.LineNumber;\r
73                                 this.linePosition = li.LinePosition;\r
74                         }\r
75                         this.sourceObj = sourceObject;\r
76                 }\r
77 \r
78                 internal XmlSchemaException(string message, XmlSchemaObject sourceObject,\r
79                         Exception innerException)\r
80                         : base(message, innerException)\r
81                 {\r
82                         hasLineInfo = true;\r
83                         this.lineNumber = sourceObject.LineNumber;\r
84                         this.linePosition = sourceObject.LinePosition;\r
85                         this.sourceObj  =       sourceObject;\r
86                         this.sourceUri  =       sourceObject.SourceUri;\r
87                 }\r
88 \r
89                 public XmlSchemaException(string message, Exception innerException)\r
90                         : base(message,innerException){}\r
91 \r
92                 // Properties\r
93                 public int LineNumber \r
94                 { \r
95                         get{ return this.lineNumber;} \r
96                 }\r
97                 public int LinePosition \r
98                 { \r
99                         get{ return this.linePosition;} \r
100                 }\r
101                 public XmlSchemaObject SourceSchemaObject \r
102                 {\r
103                         get{ return this.sourceObj; } \r
104                 }\r
105                 public string SourceUri \r
106                 { \r
107                         get{ return this.sourceUri; } \r
108                 }\r
109 \r
110                 public override string Message\r
111                 {\r
112                         get {\r
113                                 string msg = "XmlSchema error: " + base.Message;\r
114                                 if (hasLineInfo)\r
115                                         msg += String.Format (CultureInfo.InvariantCulture, " XML {0} Line {1}, Position {2}.",\r
116                                                 (sourceUri != null && sourceUri != "") ? "URI: " + sourceUri + " ." : "",\r
117                                                 lineNumber,\r
118                                                 linePosition);\r
119                                 if (sourceObj != null)\r
120                                         msg += String.Format (CultureInfo.InvariantCulture, " Related schema item SourceUri: {0}, Line {1}, Position {2}.",\r
121                                                 sourceObj.SourceUri, sourceObj.LineNumber, sourceObj.LinePosition);\r
122                                 return msg;\r
123                         }\r
124                 }\r
125 \r
126                 // Methods\r
127                 public override void GetObjectData(SerializationInfo info, StreamingContext context)\r
128                 {\r
129                         base.GetObjectData (info, context);\r
130                         info.AddValue ("lineNumber", lineNumber);\r
131                         info.AddValue ("linePosition", linePosition);\r
132                         info.AddValue ("sourceUri", sourceUri);\r
133                         info.AddValue ("sourceObj", sourceObj);\r
134                 }\r
135         }\r
136 }\r