2 // XmlSchemaException.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Enomoto, Atsushi atsushi@ximian.com
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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 using System
.Globalization
;
31 using System
.Runtime
.Serialization
;
32 using System
.Security
.Permissions
;
34 namespace System
.Xml
.Schema
37 /// Summary description for XmlSchemaException.
40 public class XmlSchemaException
: System
.SystemException
43 private bool hasLineInfo
;
44 private int lineNumber
;
45 private int linePosition
;
46 private XmlSchemaObject sourceObj
;
47 private string sourceUri
;
50 public XmlSchemaException ()
51 : this ("A schema error occured.", null)
61 XmlSchemaException (string message
)
62 : this (message
, null)
66 protected XmlSchemaException(SerializationInfo info
, StreamingContext context
)
67 : base (info
, context
)
69 this.hasLineInfo
= info
.GetBoolean ("hasLineInfo");
70 this.lineNumber
= info
.GetInt32 ("lineNumber");
71 this.linePosition
= info
.GetInt32 ("linePosition");
72 this.sourceUri
= info
.GetString ("sourceUri");
73 this.sourceObj
= info
.GetValue ("sourceObj", typeof (XmlSchemaObject
)) as XmlSchemaObject
;
77 public XmlSchemaException (string message
, Exception innerException
, int lineNumber
, int linePosition
)
78 : this (message
, lineNumber
, linePosition
, null, null, innerException
)
83 internal XmlSchemaException (string message
, int lineNumber
, int linePosition
,
84 XmlSchemaObject sourceObject
, string sourceUri
, Exception innerException
)
86 GetMessage (message
, sourceUri
, lineNumber
, linePosition
, sourceObject
),
90 this.lineNumber
= lineNumber
;
91 this.linePosition
= linePosition
;
92 this.sourceObj
= sourceObject
;
93 this.sourceUri
= sourceUri
;
96 internal XmlSchemaException (string message
, object sender
,
97 string sourceUri
, XmlSchemaObject sourceObject
, Exception innerException
)
98 : base (GetMessage (message
, sourceUri
, sender
, sourceObject
), innerException
)
100 IXmlLineInfo li
= sender
as IXmlLineInfo
;
101 if (li
!= null && li
.HasLineInfo ()) {
103 this.lineNumber
= li
.LineNumber
;
104 this.linePosition
= li
.LinePosition
;
106 this.sourceObj
= sourceObject
;
109 internal XmlSchemaException(string message
, XmlSchemaObject sourceObject
,
110 Exception innerException
)
112 GetMessage (message
, null, 0, 0, sourceObject
),
117 this.lineNumber
= sourceObject
.LineNumber
;
118 this.linePosition
= sourceObject
.LinePosition
;
119 this.sourceObj
= sourceObject
;
120 this.sourceUri
= sourceObject
.SourceUri
;
124 public XmlSchemaException(string message
, Exception innerException
)
126 GetMessage (message
, null, 0, 0, null),
132 public int LineNumber
134 get{ return this.lineNumber;}
136 public int LinePosition
138 get{ return this.linePosition;}
140 public XmlSchemaObject SourceSchemaObject
142 get{ return this.sourceObj; }
144 public string SourceUri
146 get{ return this.sourceUri; }
149 private static string GetMessage (string message
, string sourceUri
, object sender
, XmlSchemaObject sourceObj
)
151 IXmlLineInfo li
= sender
as IXmlLineInfo
;
153 return GetMessage (message
, sourceUri
, 0, 0, sourceObj
);
155 return GetMessage (message
, sourceUri
, li
.LineNumber
, li
.LinePosition
, sourceObj
);
158 private static string GetMessage (string message
, string sourceUri
, int lineNumber
, int linePosition
, XmlSchemaObject sourceObj
)
160 string msg
= "XmlSchema error: " + message
;
162 msg
+= String
.Format (CultureInfo
.InvariantCulture
, " XML {0} Line {1}, Position {2}.",
163 (sourceUri
!= null && sourceUri
!= "") ? "URI: " + sourceUri
+ " ." : "",
167 if (sourceObj
!= null)
168 msg
+= String
.Format (CultureInfo
.InvariantCulture
, " Related schema item SourceUri: {0}, Line {1}, Position {2}.",
169 sourceObj
.SourceUri
, sourceObj
.LineNumber
, sourceObj
.LinePosition
);
174 public override string Message
{
175 get { return base.Message; }
180 [SecurityPermission (SecurityAction
.Demand
, SerializationFormatter
= true)]
181 public override void GetObjectData(SerializationInfo info
, StreamingContext context
)
183 base.GetObjectData (info
, context
);
184 info
.AddValue ("hasLineInfo", hasLineInfo
);
185 info
.AddValue ("lineNumber", lineNumber
);
186 info
.AddValue ("linePosition", linePosition
);
187 info
.AddValue ("sourceUri", sourceUri
);
188 info
.AddValue ("sourceObj", sourceObj
);