Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / ControllersConfig.cs
blob31cb4c8178e8efd356fc50129231b8b76e1f3879
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System;
18 using System.Collections;
19 using System.Configuration;
20 using System.Xml;
22 /// <summary>
23 /// Represents the controller node configuration
24 /// </summary>
25 public class ControllersConfig : ISerializedConfig
27 private String[] assemblies;
28 private Type customControllerFactory;
30 #region ISerializedConfig implementation
32 /// <summary>
33 /// Deserializes the specified section.
34 /// </summary>
35 /// <param name="section">The section.</param>
36 public void Deserialize(XmlNode section)
38 XmlNode customFactoryNode = section.SelectSingleNode("customControllerFactory");
40 if (customFactoryNode != null)
42 XmlAttribute typeAtt = customFactoryNode.Attributes["type"];
44 if (typeAtt == null || typeAtt.Value == String.Empty)
46 String message = "If the node customControllerFactory is " +
47 "present, you must specify the 'type' attribute";
48 throw new ConfigurationErrorsException(message);
51 String typeName = typeAtt.Value;
53 customControllerFactory = TypeLoadUtil.GetType(typeName);
56 XmlNodeList nodeList = section.SelectNodes("controllers/assembly");
58 ArrayList items = new ArrayList();
60 foreach(XmlNode node in nodeList)
62 items.Add(node.ChildNodes[0].Value);
65 assemblies = (String[]) items.ToArray(typeof(String));
68 #endregion
70 /// <summary>
71 /// Gets or sets the assemblies.
72 /// </summary>
73 /// <value>The assemblies.</value>
74 public string[] Assemblies
76 get { return assemblies; }
77 set { assemblies = value; }
80 /// <summary>
81 /// Gets or sets the custom controller factory.
82 /// </summary>
83 /// <value>The custom controller factory.</value>
84 public Type CustomControllerFactory
86 get { return customControllerFactory; }
87 set { customControllerFactory = value; }