(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Configuration / ConfigurationBase.cs
blob942680122a1c1e2e793a612560a09b9cb0917e57
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 //
10 using System;
11 using System.Configuration;
12 using System.Xml;
14 namespace Microsoft.Web.Services.Configuration {
16 public class ConfigurationBase {
18 public ConfigurationBase () {}
20 protected static void CheckForChildNodes (XmlNode node)
22 if (node == null)
23 throw new ArgumentNullException ("node");
24 if (node.HasChildNodes)
25 throw new ConfigurationException (Locale.GetText ("has child nodes"));
28 protected static void CheckForDuplicateChildNodes (XmlNode node)
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"));
46 protected static void CheckForUnrecognizedAttributes (XmlNode node)
48 if (node == null)
49 throw new ArgumentNullException ("node");
50 if (node.Attributes.Count > 0)
51 throw new ConfigurationException (Locale.GetText ("node has attributes"));
54 protected static XmlNode GetAndRemoveAttribute (XmlNode node, string attrib, bool fRequired)
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;
66 protected static XmlNode GetAndRemoveBoolAttribute (XmlNode node, string attrib, bool fRequired, ref bool val)
68 XmlNode xn = GetAndRemoveAttribute (node, attrib, fRequired);
69 if (xn != null)
70 val = Convert.ToBoolean (xn.Value);
71 return xn;
73 #if WSE2
74 protected static XmlNode GetAndRemoveIntegerAttribute (XmlNode node, string attrib, bool fRequired, ref int val)
76 XmlNode xn = GetAndRemoveAttribute (node, attrib, fRequired);
77 if (xn != null)
78 val = Convert.ToInt32 (xn.Value);
79 return xn;
81 #endif
82 protected static XmlNode GetAndRemoveStringAttribute (XmlNode node, string attrib, bool fRequired, ref string val)
84 XmlNode xn = GetAndRemoveAttribute (node, attrib, fRequired);
85 if (xn != null)
86 val = xn.Value;
87 return xn;
90 protected static void ThrowIfElement (XmlNode node)
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"));
98 protected static void ThrowIfNotComment (XmlNode node)
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"));