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
.Configuration
;
20 using Castle
.Components
.Common
.EmailSender
;
21 using Castle
.Components
.Validator
;
22 using Castle
.MonoRail
.Framework
.Services
.AjaxProxyGenerator
;
27 /// Enum for all known MonoRail services.
29 public enum ServiceIdentification
32 /// Custom ( not know service )
36 /// The <see cref="IControllerFactory"/> service
40 /// The <see cref="IViewComponentFactory"/> service
44 /// The <see cref="IViewSourceLoader"/> service.
48 /// The <see cref="IFilterFactory"/> service.
52 /// The <see cref="IEmailSender"/> service.
56 /// The <see cref="IControllerDescriptorProvider"/> service
58 ControllerDescriptorProvider
,
60 /// The <see cref="IResourceDescriptorProvider"/> service
62 ResourceDescriptorProvider
,
64 /// The <see cref="IRescueDescriptorProvider"/> service
66 RescueDescriptorProvider
,
68 /// The <see cref="ILayoutDescriptorProvider"/> service
70 LayoutDescriptorProvider
,
72 /// The <see cref="IHelperDescriptorProvider"/> service
74 HelperDescriptorProvider
,
76 /// The <see cref="IFilterDescriptorProvider"/> service
78 FilterDescriptorProvider
,
80 /// The <see cref="IResourceFactory"/> service
84 /// The <see cref="IEmailTemplateService"/> service
88 /// The <see cref="IControllerTree"/> service
92 /// The <see cref="ICacheProvider"/> service
96 /// The <see cref="IScaffoldingSupport"/> service
100 /// The <see cref="IControllerLifecycleExecutorFactory"/> service
104 /// The <see cref="ITransformFilterDescriptorProvider"/> service
106 TransformFilterDescriptorProvider
,
108 /// The <see cref="ITransformFilterFactory"/> service
110 TransformationFilterFactory
,
112 /// The <see cref="IViewEngineManager"/> service
116 /// The <see cref="IUrlBuilder"/> service
120 /// The <see cref="IUrlTokenizer"/> service
124 /// The <see cref="IServerUtility"/> service
128 /// The <see cref="IValidatorRegistry"/> service
132 /// The <see cref="IAjaxProxyGenerator"/> service
138 /// Represents a MonoRail service entry
140 public class ServiceEntry
: ISerializedConfig
142 private ServiceIdentification serviceType
;
143 private Type service
;
144 private Type _interface
;
146 #region ISerializedConfig implementation
149 /// Deserializes the specified section.
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);
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
);
194 /// Gets the type of the service.
196 /// <value>The type of the service.</value>
197 public ServiceIdentification ServiceType
199 get { return serviceType; }
203 /// Gets the service.
205 /// <value>The service.</value>
208 get { return service; }
212 /// Gets the interface.
214 /// <value>The interface.</value>
215 public Type Interface
217 get { return _interface; }