2 // FilterConfiguration.cs: Filter Configuration
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
11 using System
.Configuration
;
14 namespace Microsoft
.Web
.Services
.Configuration
{
16 public class ConfigurationBase
{
18 public ConfigurationBase () {}
20 protected static void CheckForChildNodes (XmlNode node
)
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
)
31 throw new ArgumentNullException ("node");
32 int n
= node
.ChildNodes
.Count
;
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
)
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
)
57 throw new ArgumentNullException ("node");
58 XmlNode xn
= node
.Attributes
[attrib
];
60 node
.Attributes
.Remove (xn
as XmlAttribute
);
62 throw new ConfigurationException (Locale
.GetText ("missing required attribute"));
66 protected static XmlNode
GetAndRemoveBoolAttribute (XmlNode node
, string attrib
, bool fRequired
, ref bool val
)
68 XmlNode xn
= GetAndRemoveAttribute (node
, attrib
, fRequired
);
70 val
= Convert
.ToBoolean (xn
.Value
);
74 protected static XmlNode
GetAndRemoveIntegerAttribute (XmlNode node
, string attrib
, bool fRequired
, ref int val
)
76 XmlNode xn
= GetAndRemoveAttribute (node
, attrib
, fRequired
);
78 val
= Convert
.ToInt32 (xn
.Value
);
82 protected static XmlNode
GetAndRemoveStringAttribute (XmlNode node
, string attrib
, bool fRequired
, ref string val
)
84 XmlNode xn
= GetAndRemoveAttribute (node
, attrib
, fRequired
);
90 protected static void ThrowIfElement (XmlNode node
)
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
)
101 throw new ArgumentNullException ("node");
102 if (node
.NodeType
!= XmlNodeType
.Comment
)
103 throw new ConfigurationException (Locale
.GetText ("node isn't XmlNodeType.Comment"));