o fixes for windows build
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Configuration / ConfigurationBase.cs
1 //
2 // FilterConfiguration.cs: Filter Configuration
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using System;
11 using System.Configuration;
12 using System.Xml;
13
14 namespace Microsoft.Web.Services.Configuration {
15         
16         public class ConfigurationBase {
17
18                 public ConfigurationBase () {}
19
20                 protected static void CheckForChildNodes (XmlNode node)
21                 {
22                         if (node == null)
23                                 throw new ArgumentNullException ("node");
24                         if (node.HasChildNodes)
25                                 throw new ConfigurationException (Locale.GetText ("has child nodes"));
26                 }
27
28                 protected static void CheckForDuplicateChildNodes (XmlNode node)
29                 {
30                         if (node == null)
31                                 throw new ArgumentNullException ("node");
32                         int n = node.ChildNodes.Count;
33                         if (n > 1) {
34                                 // (n - 1) last is unimportant
35                                 for (int i=0; i < n - 1; i++) {
36                                         string xname = node.ChildNodes [i].Name;
37                                         // (i + 1) don't look back (again)
38                                         for (int j=i+1; j < n; i++) {
39                                                 if (xname == node.ChildNodes [j].Name)
40                                                         throw new ConfigurationException (Locale.GetText ("found duplicate nodes"));
41                                         }
42                                 }
43                         }
44                 }
45
46                 protected static void CheckForUnrecognizedAttributes (XmlNode node)
47                 {
48                         if (node == null)
49                                 throw new ArgumentNullException ("node");
50                         if (node.Attributes.Count > 0)
51                                 throw new ConfigurationException (Locale.GetText ("node has attributes"));
52                 }
53
54                 protected static XmlNode GetAndRemoveAttribute (XmlNode node, string attrib, bool fRequired)
55                 {
56                         if (node == null)
57                                 throw new ArgumentNullException ("node");
58                         XmlNode xn = node.Attributes [attrib];
59                         if (xn != null)
60                                 node.Attributes.Remove (xn as XmlAttribute);
61                         else if (fRequired)
62                                 throw new ConfigurationException (Locale.GetText ("missing required attribute"));
63                         return xn;
64                 }
65
66                 protected static XmlNode GetAndRemoveBoolAttribute (XmlNode node, string attrib, bool fRequired, ref bool val)
67                 {
68                         XmlNode xn = GetAndRemoveAttribute (node, attrib, fRequired);
69                         if (xn != null)
70                                 val = Convert.ToBoolean (xn.Value);
71                         return xn;
72                 }
73 #if WSE2
74                 protected static XmlNode GetAndRemoveIntegerAttribute (XmlNode node, string attrib, bool fRequired, ref int val)
75                 {
76                         XmlNode xn = GetAndRemoveAttribute (node, attrib, fRequired);
77                         if (xn != null)
78                                 val = Convert.ToInt32 (xn.Value);
79                         return xn;
80                 }
81 #endif
82                 protected static XmlNode GetAndRemoveStringAttribute (XmlNode node, string attrib, bool fRequired, ref string val) 
83                 {
84                         XmlNode xn = GetAndRemoveAttribute (node, attrib, fRequired);
85                         if (xn != null)
86                                 val = xn.Value;
87                         return xn;
88                 }
89
90                 protected static void ThrowIfElement (XmlNode node)
91                 {
92                         if (node == null)
93                                 throw new ArgumentNullException ("node");
94                         if (node.NodeType == XmlNodeType.Element)
95                                 throw new ConfigurationException (Locale.GetText ("node is XmlNodeType.Element"));
96                 }
97
98                 protected static void ThrowIfNotComment (XmlNode node)
99                 {
100                         if (node == null)
101                                 throw new ArgumentNullException ("node");
102                         if (node.NodeType != XmlNodeType.Comment)
103                                 throw new ConfigurationException (Locale.GetText ("node isn't XmlNodeType.Comment"));
104                 }
105         }
106 }