1 // Author: Dwivedi, Ajay kumar
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
;
26 using System
.Runtime
.Serialization
;
29 namespace System
.Xml
.Schema
32 /// Summary description for XmlSchemaException.
35 public class XmlSchemaException
: System
.SystemException
38 private bool hasLineInfo
;
39 private int lineNumber
;
40 private int linePosition
;
41 private XmlSchemaObject sourceObj
;
42 private string sourceUri
;
44 protected XmlSchemaException(SerializationInfo info
, StreamingContext context
)
45 : base (info
, context
)
48 this.lineNumber
= info
.GetInt32 ("lineNumber");
49 this.linePosition
= info
.GetInt32 ("linePosition");
50 this.sourceUri
= info
.GetString ("sourceUri");
51 this.sourceObj
= info
.GetValue ("sourceObj", typeof (XmlSchemaObject
)) as XmlSchemaObject
;
54 internal XmlSchemaException(string message
, int lineNumber
, int linePosition
,
55 XmlSchemaObject sourceObject
, string sourceUri
, Exception innerException
)
56 : base(message
, innerException
)
59 this.lineNumber
= lineNumber
;
60 this.linePosition
= linePosition
;
61 this.sourceObj
= sourceObject
;
62 this.sourceUri
= sourceUri
;
65 internal XmlSchemaException(string message
, object sender
,
66 string sourceUri
, XmlSchemaObject sourceObject
, Exception innerException
)
67 : base(message
, innerException
)
69 IXmlLineInfo li
= sender
as IXmlLineInfo
;
70 if (li
!= null && li
.HasLineInfo ()) {
72 this.lineNumber
= li
.LineNumber
;
73 this.linePosition
= li
.LinePosition
;
75 this.sourceObj
= sourceObject
;
78 internal XmlSchemaException(string message
, XmlSchemaObject sourceObject
,
79 Exception innerException
)
80 : base(message
, innerException
)
83 this.lineNumber
= sourceObject
.LineNumber
;
84 this.linePosition
= sourceObject
.LinePosition
;
85 this.sourceObj
= sourceObject
;
86 this.sourceUri
= sourceObject
.SourceUri
;
89 public XmlSchemaException(string message
, Exception innerException
)
90 : base(message
,innerException
){}
95 get{ return this.lineNumber;}
97 public int LinePosition
99 get{ return this.linePosition;}
101 public XmlSchemaObject SourceSchemaObject
103 get{ return this.sourceObj; }
105 public string SourceUri
107 get{ return this.sourceUri; }
110 public override string Message
113 string msg
= "XmlSchema error: " + base.Message
;
115 msg
+= String
.Format (CultureInfo
.InvariantCulture
, " XML {0} Line {1}, Position {2}.",
116 (sourceUri
!= null && sourceUri
!= "") ? "URI: " + sourceUri
+ " ." : "",
119 if (sourceObj
!= null)
120 msg
+= String
.Format (CultureInfo
.InvariantCulture
, " Related schema item SourceUri: {0}, Line {1}, Position {2}.",
121 sourceObj
.SourceUri
, sourceObj
.LineNumber
, sourceObj
.LinePosition
);
127 public override void GetObjectData(SerializationInfo info
, StreamingContext context
)
129 base.GetObjectData (info
, context
);
130 info
.AddValue ("lineNumber", lineNumber
);
131 info
.AddValue ("linePosition", linePosition
);
132 info
.AddValue ("sourceUri", sourceUri
);
133 info
.AddValue ("sourceObj", sourceObj
);