1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Configuration
18 using System
.Collections
;
19 using System
.Configuration
;
22 public class RoutingRuleCollection
: CollectionBase
, ISerializedConfig
24 #region ISerializedConfig implementation
26 public void Deserialize(XmlNode section
)
28 XmlNodeList services
= section
.SelectNodes("routing/rule");
30 foreach(XmlNode node
in services
)
32 XmlNode patternNode
= node
.SelectSingleNode("pattern");
33 XmlNode replaceNode
= node
.SelectSingleNode("replace");
35 if (patternNode
== null || patternNode
.ChildNodes
.Count
== 0 || patternNode
.ChildNodes
[0] == null)
37 String message
= "A rule node must have a pattern (child) " +
38 "node denoting the regular expression to be matched";
39 throw new ConfigurationErrorsException(message
);
41 if (replaceNode
== null || replaceNode
.ChildNodes
.Count
== 0 || replaceNode
.ChildNodes
[0] == null)
43 String message
= "A rule node must have a replace (child) " +
44 "node denoting the string to be replaced";
45 throw new ConfigurationErrorsException(message
);
48 String pattern
= patternNode
.ChildNodes
[0].Value
;
49 String replace
= replaceNode
.ChildNodes
[0].Value
;
51 RoutingRule rule
= new RoutingRule(pattern
.Trim(), replace
.Trim());
59 public RoutingRule
this[int index
]
61 get { return InnerList[index] as RoutingRule; }