XmlSchemaException.cs 4.4 KB

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