2005-01-13 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / ValidationHandler.cs
1
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 // 
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 // 
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 using System;\r
23 \r
24 namespace System.Xml.Schema\r
25 {\r
26         /// <summary>\r
27         /// </summary>\r
28         public delegate void ValidationEventHandler(object sender,ValidationEventArgs e);\r
29 \r
30         /// <summary>\r
31         /// Docs say we need to raise an exception if ValidationEventHandler is not set(null)\r
32         /// So we use this class to raise the events rather than calling the delegate by itself\r
33         /// </summary>\r
34         internal class ValidationHandler\r
35         {\r
36                 public static void RaiseValidationEvent(ValidationEventHandler handle,\r
37                         Exception innerException,\r
38                         string message,\r
39                         XmlSchemaObject xsobj,\r
40                         object sender,\r
41                         string sourceUri,\r
42                         XmlSeverityType severity)\r
43                 {\r
44                         XmlSchemaException ex = new XmlSchemaException (\r
45                                 message, sender, sourceUri, xsobj, innerException);\r
46                         ValidationEventArgs e = new ValidationEventArgs(ex,message,severity);\r
47                         if(handle == null)\r
48                         {\r
49                                 if (e.Severity == XmlSeverityType.Error)\r
50                                         throw e.Exception;\r
51                         }\r
52                         else\r
53                         {\r
54                                 handle(sender,e);\r
55                         }\r
56                 }\r
57 \r
58                 /*\r
59                 public static void RaiseValidationEvent(ValidationEventHandler handle, Exception innerException,  object sender, string message, XmlSeverityType severity)\r
60                 {\r
61                         RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);\r
62                 }\r
63 \r
64                 public static void RaiseValidationError(ValidationEventHandler handle, object sender, string message)\r
65                 {\r
66                         RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Error);\r
67                 }\r
68                 \r
69                 public static void RaiseValidationError(ValidationEventHandler handle, string message, Exception innerException)\r
70                 {\r
71                         RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Error);\r
72                 }\r
73 \r
74                 public static void RaiseValidationWarning (ValidationEventHandler handle, object sender, string message)\r
75                 {\r
76                         RaiseValidationEvent(handle,null,sender,message,XmlSeverityType.Warning);\r
77                 }\r
78 \r
79                 public static void RaiseValidationWarning(ValidationEventHandler handle, string message, Exception innerException)\r
80                 {\r
81                         RaiseValidationEvent(handle, innerException, null, message, XmlSeverityType.Warning);\r
82                 }\r
83                 */\r
84         }\r
85 }\r