New test.
[mono.git] / mcs / class / System.Web / System.Web.Configuration / TraceConfigurationHandler.cs
1 //
2 // System.Web.Configuation.TraceConfigurationHandler
3 //
4 // Author(s):
5 //  Jackson Harper (jackson@ximian.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Web;
33 using System.Xml;
34 using System.Configuration;
35
36 namespace System.Web.Configuration {
37
38         internal class TraceConfigurationHandler : IConfigurationSectionHandler {
39
40                 public object Create (object parent, object context, XmlNode section)
41                 {
42                         TraceConfig config = new TraceConfig ();
43
44                         string enabled_str = AttValue ("enabled", section);
45                         if (enabled_str != null) {
46                                 try {
47                                         config.Enabled = Boolean.Parse (enabled_str);
48                                 } catch {
49                                         ThrowException ("The 'enabled' attribute is case sensitive" +
50                                                         " and must be set to 'true' or 'false'.", section);
51                                 }
52                         }
53
54                         string local_str = AttValue ("localOnly", section);
55                         if (local_str != null) {
56                                 try {
57                                         config.LocalOnly = Boolean.Parse (local_str);
58                                 } catch {
59                                         ThrowException ("The 'localOnly' attribute is case sensitive" +
60                                                         " and must be set to 'true' or 'false'.", section);
61                                 }
62                         }
63
64                         string page_str = AttValue ("pageOutput", section);
65                         if (page_str != null) {
66                                 try {
67                                         config.PageOutput = Boolean.Parse (page_str);
68                                 } catch {
69                                         ThrowException ("The 'pageOutput' attribute is case sensitive" +
70                                                         " and must be set to 'true' or 'false'.", section);
71                                 }
72                         }
73
74                         string limit_str = AttValue ("requestLimit", section);
75                         if (limit_str != null) {
76                                 try {
77                                         config.RequestLimit = Int32.Parse (limit_str);
78                                 } catch {
79                                         ThrowException ("The 'requestLimit' attribute must be an integer value.",
80                                                         section);
81                                 }
82                         }
83
84                         string trace_str = AttValue ("traceMode", section);
85                         if (trace_str != null) {
86                                 try {
87                                         config.TraceMode = (TraceMode) Enum.Parse (typeof (TraceMode), trace_str);
88                                 } catch {
89                                         ThrowException ("The 'traceMode' attribute is case sensitive and must be" +
90                                                         " one of the following values: SortByTime, SortByCategory.",
91                                                         section);
92                                 }
93                         }
94                         
95                         return config;
96                 }
97
98                 // A few methods to save some typing
99                 static string AttValue (string name, XmlNode node)
100                 {
101                         return HandlersUtil.ExtractAttributeValue (name, node, true);
102                 }
103
104                 static void ThrowException (string message, XmlNode node)
105                 {
106                         HandlersUtil.ThrowException (message, node);
107                 }
108         }
109 }
110