1 // Author: Dwivedi, Ajay kumar
\r
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:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
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.
25 using System.Globalization;
\r
26 using System.Runtime.Serialization;
\r
29 namespace System.Xml.Schema
\r
32 /// Summary description for XmlSchemaException.
\r
35 public class XmlSchemaException : System.SystemException
\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
44 protected XmlSchemaException(SerializationInfo info, StreamingContext context)
\r
45 : base (info, context)
\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
54 internal XmlSchemaException(string message, int lineNumber, int linePosition,
\r
55 XmlSchemaObject sourceObject, string sourceUri, Exception innerException)
\r
56 : base(message, innerException)
\r
59 this.lineNumber = lineNumber;
\r
60 this.linePosition = linePosition;
\r
61 this.sourceObj = sourceObject;
\r
62 this.sourceUri = sourceUri;
\r
65 internal XmlSchemaException(string message, object sender,
\r
66 string sourceUri, XmlSchemaObject sourceObject, Exception innerException)
\r
67 : base(message, innerException)
\r
69 IXmlLineInfo li = sender as IXmlLineInfo;
\r
70 if (li != null && li.HasLineInfo ()) {
\r
72 this.lineNumber = li.LineNumber;
\r
73 this.linePosition = li.LinePosition;
\r
75 this.sourceObj = sourceObject;
\r
78 internal XmlSchemaException(string message, XmlSchemaObject sourceObject,
\r
79 Exception innerException)
\r
80 : base(message, innerException)
\r
83 this.lineNumber = sourceObject.LineNumber;
\r
84 this.linePosition = sourceObject.LinePosition;
\r
85 this.sourceObj = sourceObject;
\r
86 this.sourceUri = sourceObject.SourceUri;
\r
89 public XmlSchemaException(string message, Exception innerException)
\r
90 : base(message,innerException){}
\r
93 public int LineNumber
\r
95 get{ return this.lineNumber;}
\r
97 public int LinePosition
\r
99 get{ return this.linePosition;}
\r
101 public XmlSchemaObject SourceSchemaObject
\r
103 get{ return this.sourceObj; }
\r
105 public string SourceUri
\r
107 get{ return this.sourceUri; }
\r
110 public override string Message
\r
113 string msg = "XmlSchema error: " + base.Message;
\r
115 msg += String.Format (CultureInfo.InvariantCulture, " XML {0} Line {1}, Position {2}.",
\r
116 (sourceUri != null && sourceUri != "") ? "URI: " + sourceUri + " ." : "",
\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
127 public override void GetObjectData(SerializationInfo info, StreamingContext context)
\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