Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / ServiceEntry.cs
blob0ab9f3734aef75da5c6bcce5d2c2822835180665
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.Configuration;
19 using System.Xml;
20 using Castle.Components.Common.EmailSender;
21 using Castle.Components.Validator;
22 using Castle.MonoRail.Framework.Services.AjaxProxyGenerator;
23 using Framework;
24 using Internal;
26 /// <summary>
27 /// Enum for all known MonoRail services.
28 /// </summary>
29 public enum ServiceIdentification
31 /// <summary>
32 /// Custom ( not know service )
33 /// </summary>
34 Custom,
35 /// <summary>
36 /// The <see cref="IControllerFactory"/> service
37 /// </summary>
38 ControllerFactory,
39 /// <summary>
40 /// The <see cref="IViewComponentFactory"/> service
41 /// </summary>
42 ViewComponentFactory,
43 /// <summary>
44 /// The <see cref="IViewSourceLoader"/> service.
45 /// </summary>
46 ViewSourceLoader,
47 /// <summary>
48 /// The <see cref="IFilterFactory"/> service.
49 /// </summary>
50 FilterFactory,
51 /// <summary>
52 /// The <see cref="IEmailSender"/> service.
53 /// </summary>
54 EmailSender,
55 /// <summary>
56 /// The <see cref="IControllerDescriptorProvider"/> service
57 /// </summary>
58 ControllerDescriptorProvider,
59 /// <summary>
60 /// The <see cref="IResourceDescriptorProvider"/> service
61 /// </summary>
62 ResourceDescriptorProvider,
63 /// <summary>
64 /// The <see cref="IRescueDescriptorProvider"/> service
65 /// </summary>
66 RescueDescriptorProvider,
67 /// <summary>
68 /// The <see cref="ILayoutDescriptorProvider"/> service
69 /// </summary>
70 LayoutDescriptorProvider,
71 /// <summary>
72 /// The <see cref="IHelperDescriptorProvider"/> service
73 /// </summary>
74 HelperDescriptorProvider,
75 /// <summary>
76 /// The <see cref="IFilterDescriptorProvider"/> service
77 /// </summary>
78 FilterDescriptorProvider,
79 /// <summary>
80 /// The <see cref="IResourceFactory"/> service
81 /// </summary>
82 ResourceFactory,
83 /// <summary>
84 /// The <see cref="IEmailTemplateService"/> service
85 /// </summary>
86 EmailTemplateService,
87 /// <summary>
88 /// The <see cref="IControllerTree"/> service
89 /// </summary>
90 ControllerTree,
91 /// <summary>
92 /// The <see cref="ICacheProvider"/> service
93 /// </summary>
94 CacheProvider,
95 /// <summary>
96 /// The <see cref="IScaffoldingSupport"/> service
97 /// </summary>
98 ScaffoldingSupport,
99 /// <summary>
100 /// The <see cref="IControllerLifecycleExecutorFactory"/> service
101 /// </summary>
102 ExecutorFactory,
103 /// <summary>
104 /// The <see cref="ITransformFilterDescriptorProvider"/> service
105 /// </summary>
106 TransformFilterDescriptorProvider,
107 /// <summary>
108 /// The <see cref="ITransformFilterFactory"/> service
109 /// </summary>
110 TransformationFilterFactory,
111 /// <summary>
112 /// The <see cref="IViewEngineManager"/> service
113 /// </summary>
114 ViewEngineManager,
115 /// <summary>
116 /// The <see cref="IUrlBuilder"/> service
117 /// </summary>
118 UrlBuilder,
119 /// <summary>
120 /// The <see cref="IUrlTokenizer"/> service
121 /// </summary>
122 UrlTokenizer,
123 /// <summary>
124 /// The <see cref="IServerUtility"/> service
125 /// </summary>
126 ServerUtility,
127 /// <summary>
128 /// The <see cref="IValidatorRegistry"/> service
129 /// </summary>
130 ValidatorRegistry,
131 /// <summary>
132 /// The <see cref="IAjaxProxyGenerator"/> service
133 /// </summary>
134 AjaxProxyGenerator,
137 /// <summary>
138 /// Represents a MonoRail service entry
139 /// </summary>
140 public class ServiceEntry : ISerializedConfig
142 private ServiceIdentification serviceType;
143 private Type service;
144 private Type _interface;
146 #region ISerializedConfig implementation
148 /// <summary>
149 /// Deserializes the specified section.
150 /// </summary>
151 /// <param name="section">The section.</param>
152 public void Deserialize(XmlNode section)
154 XmlAttribute idAtt = section.Attributes["id"];
155 XmlAttribute typeAtt = section.Attributes["type"];
156 XmlAttribute interAtt = section.Attributes["interface"];
158 if (idAtt == null || idAtt.Value == String.Empty)
160 String message = "To add a service, please specify the 'id' attribute. " +
161 "Check the documentation for more information";
162 throw new ConfigurationErrorsException(message);
165 if (typeAtt == null || typeAtt.Value == String.Empty)
167 String message = "To add a service, please specify the 'type' attribute. " +
168 "Check the documentation for more information";
169 throw new ConfigurationErrorsException(message);
174 serviceType = (ServiceIdentification)
175 Enum.Parse(typeof(ServiceIdentification), idAtt.Value, true);
177 catch(Exception ex)
179 String message = "Invalid service id: " + idAtt.Value;
180 throw new ConfigurationErrorsException(message, ex);
183 service = TypeLoadUtil.GetType(typeAtt.Value);
185 if (interAtt != null)
187 _interface = TypeLoadUtil.GetType(interAtt.Value);
191 #endregion
193 /// <summary>
194 /// Gets the type of the service.
195 /// </summary>
196 /// <value>The type of the service.</value>
197 public ServiceIdentification ServiceType
199 get { return serviceType; }
202 /// <summary>
203 /// Gets the service.
204 /// </summary>
205 /// <value>The service.</value>
206 public Type Service
208 get { return service; }
211 /// <summary>
212 /// Gets the interface.
213 /// </summary>
214 /// <value>The interface.</value>
215 public Type Interface
217 get { return _interface; }