1 // Copyright 2004-2008 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
.Generic
;
19 using System
.Configuration
;
20 using System
.Reflection
;
24 /// Represents the controller node configuration
26 public class ControllersConfig
: ISerializedConfig
28 private readonly List
<string> assemblies
= new List
<string>();
29 private Type customControllerFactory
;
32 /// Initializes a new instance of the <see cref="ControllersConfig"/> class.
34 public ControllersConfig()
38 #region ISerializedConfig implementation
41 /// Deserializes the specified section.
43 /// <param name="section">The section.</param>
44 public void Deserialize(XmlNode section
)
46 XmlNode customFactoryNode
= section
.SelectSingleNode("customControllerFactory");
48 if (customFactoryNode
!= null)
50 XmlAttribute typeAtt
= customFactoryNode
.Attributes
["type"];
52 if (typeAtt
== null || typeAtt
.Value
== String
.Empty
)
54 String message
= "If the node customControllerFactory is " +
55 "present, you must specify the 'type' attribute";
56 throw new ConfigurationErrorsException(message
);
59 String typeName
= typeAtt
.Value
;
61 customControllerFactory
= TypeLoadUtil
.GetType(typeName
);
64 XmlNodeList nodeList
= section
.SelectNodes("controllers/assembly");
66 foreach(XmlNode node
in nodeList
)
68 assemblies
.Add(node
.ChildNodes
[0].Value
);
75 /// Adds an assembly that should be source of controllers.
77 /// <param name="assembly">The assembly.</param>
78 public void AddAssembly(Assembly assembly
)
80 if (assembly
== null) throw new ArgumentNullException("assembly");
82 assemblies
.Add(assembly
.FullName
);
86 /// Adds an assembly that should be source of controllers.
88 /// <param name="assemblyName">Name of the assembly.</param>
89 public void AddAssembly(string assemblyName
)
91 if (assemblyName
== null) throw new ArgumentNullException("assemblyName");
93 assemblies
.Add(assemblyName
);
97 /// Gets or sets the assemblies.
99 /// <value>The assemblies.</value>
100 public List
<string> Assemblies
102 get { return assemblies; }
106 /// Gets or sets the custom controller factory.
108 /// <seealso cref="IControllerFactory"/>
109 /// <value>The custom controller factory.</value>
110 public Type CustomControllerFactory
112 get { return customControllerFactory; }
113 set { customControllerFactory = value; }