* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.XML / System.Xml.Xsl / XsltException.cs
1 //\r
2 // System.Xml.Xsl.XsltException.cs\r
3 //\r
4 // Authors:\r
5 //  Tim Coleman (tim@timcoleman.com)\r
6 //  Andreas Nahr (ClassDevelopment@A-SoftTech.com)\r
7 //\r
8 // (C) Copyright 2002 Tim Coleman\r
9 // (C) 2003 Andreas Nahr\r
10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)\r
11 //\r
12 // Permission is hereby granted, free of charge, to any person obtaining\r
13 // a copy of this software and associated documentation files (the\r
14 // "Software"), to deal in the Software without restriction, including\r
15 // without limitation the rights to use, copy, modify, merge, publish,\r
16 // distribute, sublicense, and/or sell copies of the Software, and to\r
17 // permit persons to whom the Software is furnished to do so, subject to\r
18 // the following conditions:\r
19 // \r
20 // The above copyright notice and this permission notice shall be\r
21 // included in all copies or substantial portions of the Software.\r
22 // \r
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
30 //\r
31 \r
32 using System.Globalization;\r
33 using System.Runtime.Serialization;\r
34 using System.Xml.XPath;\r
35 using System.Security.Permissions;\r
36 \r
37 namespace System.Xml.Xsl\r
38 {\r
39         [Serializable]\r
40         public class XsltException : SystemException\r
41         {\r
42                 static string CreateMessage (string message, XPathNavigator nav)\r
43                 {\r
44                         IXmlLineInfo li = nav as IXmlLineInfo;\r
45                         int lineNumber = li != null ? li.LineNumber : 0;\r
46                         int linePosition = li != null ? li.LinePosition : 0;\r
47                         string sourceUri = nav != null ? nav.BaseURI : string.Empty;\r
48 \r
49                         if (lineNumber != 0) {\r
50                                 return CreateMessage ("{0} at {1}({2},{3}).", message, lineNumber, linePosition, sourceUri);\r
51                         }\r
52                         return CreateMessage ("{0}.", message, lineNumber, linePosition, sourceUri);\r
53                 }\r
54 \r
55                 static string CreateMessage (string msgFormat, string message, int lineNumber, int linePosition, string sourceUri)\r
56                 {\r
57                         return string.Format (CultureInfo.InvariantCulture, msgFormat,\r
58                                 message, sourceUri, lineNumber.ToString (CultureInfo.InvariantCulture),\r
59                                 linePosition.ToString (CultureInfo.InvariantCulture));\r
60                 }\r
61 \r
62                 #region Fields\r
63 \r
64                 int lineNumber;\r
65                 int linePosition;\r
66                 string sourceUri;\r
67 \r
68                 #endregion\r
69 \r
70                 #region Constructors\r
71 \r
72 #if NET_2_0\r
73                 public XsltException ()\r
74                         : this (string.Empty, (Exception) null)\r
75                 {\r
76                 }\r
77 \r
78                 public XsltException (string message)\r
79                         : this (message, (Exception) null)\r
80                 {\r
81                 }\r
82 #endif\r
83 \r
84                 public XsltException (string message, Exception innerException)\r
85                         : this ("{0}", message, innerException, 0, 0, (string) null)\r
86                 {\r
87                 }\r
88 \r
89                 protected XsltException (SerializationInfo info, StreamingContext context)\r
90                 {\r
91                         lineNumber = info.GetInt32 ("lineNumber");\r
92                         linePosition = info.GetInt32 ("linePosition");\r
93                         sourceUri = info.GetString ("sourceUri");\r
94                 }\r
95 \r
96                 internal XsltException (string msgFormat, string message, Exception innerException, int lineNumber, int linePosition, string sourceUri)\r
97                         : base (CreateMessage (msgFormat, message, lineNumber, linePosition, sourceUri), innerException)\r
98                 {\r
99                         this.lineNumber = lineNumber;\r
100                         this.linePosition = linePosition;\r
101                         this.sourceUri = sourceUri;\r
102                 }\r
103 \r
104                 internal XsltException (string message, Exception innerException, XPathNavigator nav)\r
105                         : base (CreateMessage (message, nav), innerException)\r
106                 {\r
107                         IXmlLineInfo li = nav as IXmlLineInfo;\r
108                         this.lineNumber = li != null ? li.LineNumber : 0;\r
109                         this.linePosition = li != null ? li.LinePosition : 0;\r
110                         this.sourceUri = nav != null ? nav.BaseURI : string.Empty;\r
111                 }\r
112 \r
113                 #endregion\r
114 \r
115                 #region Properties\r
116 \r
117 #if NET_2_0\r
118                 public virtual int LineNumber {\r
119 #else\r
120                 public int LineNumber {\r
121 #endif\r
122                         get { return lineNumber; }\r
123                 }\r
124 \r
125 #if NET_2_0\r
126                 public virtual int LinePosition {\r
127 #else\r
128                 public int LinePosition {\r
129 #endif\r
130                         get { return linePosition; }\r
131                 }\r
132 \r
133                 public override string Message {\r
134                         get {\r
135                                 return base.Message;\r
136                         }\r
137                 }\r
138 \r
139 #if NET_2_0\r
140                 public virtual string SourceUri {\r
141 #else\r
142                 public string SourceUri {\r
143 #endif\r
144                         get { return sourceUri; }\r
145                 }\r
146 \r
147                 #endregion\r
148 \r
149                 #region Methods\r
150 \r
151                 [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]\r
152                 public override void GetObjectData (SerializationInfo info, StreamingContext context)\r
153                 {\r
154                         base.GetObjectData (info, context);\r
155                         info.AddValue ("lineNumber", lineNumber);\r
156                         info.AddValue ("linePosition", linePosition);\r
157                         info.AddValue ("sourceUri", sourceUri);\r
158                 }\r
159 \r
160                 #endregion\r
161         }\r
162 }\r