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
;
21 using Castle
.Components
.Common
.EmailSender
;
22 using Castle
.Components
.Validator
;
23 using Castle
.MonoRail
.Framework
.Internal
;
24 using Castle
.MonoRail
.Framework
.Services
.AjaxProxyGenerator
;
27 public class ServiceEntryCollection
: ISerializedConfig
29 private Hashtable service2Impl
= new Hashtable();
30 private IList customServices
= new ArrayList();
32 public ServiceEntryCollection()
36 public ICollection CustomServices
38 get { return customServices; }
41 #region ISerializedConfig implementation
43 public void Deserialize(XmlNode section
)
45 XmlNodeList services
= section
.SelectNodes("services/service");
47 foreach(XmlNode node
in services
)
49 ServiceEntry entry
= new ServiceEntry();
51 entry
.Deserialize(node
);
53 if (entry
.ServiceType
== ServiceIdentification
.Custom
)
55 if (entry
.Interface
!= null)
57 RegisterService(entry
.Interface
, entry
.Service
);
61 customServices
.Add(entry
.Service
);
66 RegisterService(entry
.ServiceType
, entry
.Service
);
73 public void RegisterService(ServiceIdentification id
, Type service
)
75 RegisterService(ToInterface(id
), service
);
78 public void RegisterService(Type inter
, Type service
)
80 service2Impl
[inter
] = service
;
83 public Type
GetService(ServiceIdentification id
)
85 return (Type
) service2Impl
[ToInterface(id
)];
88 public bool HasService(ServiceIdentification id
)
90 return service2Impl
.Contains(ToInterface(id
));
93 public IDictionary ServiceImplMap
95 get { return service2Impl; }
98 private Type
ToInterface(ServiceIdentification id
)
102 case ServiceIdentification
.ControllerFactory
:
103 return typeof(IControllerFactory
);
104 case ServiceIdentification
.ViewComponentFactory
:
105 return typeof(IViewComponentFactory
);
106 case ServiceIdentification
.FilterFactory
:
107 return typeof(IFilterFactory
);
108 case ServiceIdentification
.EmailSender
:
109 return typeof(IEmailSender
);
110 case ServiceIdentification
.ControllerDescriptorProvider
:
111 return typeof(IControllerDescriptorProvider
);
112 case ServiceIdentification
.ResourceDescriptorProvider
:
113 return typeof(IResourceDescriptorProvider
);
114 case ServiceIdentification
.RescueDescriptorProvider
:
115 return typeof(IRescueDescriptorProvider
);
116 case ServiceIdentification
.LayoutDescriptorProvider
:
117 return typeof(ILayoutDescriptorProvider
);
118 case ServiceIdentification
.HelperDescriptorProvider
:
119 return typeof(IHelperDescriptorProvider
);
120 case ServiceIdentification
.FilterDescriptorProvider
:
121 return typeof(IFilterDescriptorProvider
);
122 case ServiceIdentification
.EmailTemplateService
:
123 return typeof(IEmailTemplateService
);
124 case ServiceIdentification
.ControllerTree
:
125 return typeof(IControllerTree
);
126 case ServiceIdentification
.CacheProvider
:
127 return typeof(ICacheProvider
);
128 case ServiceIdentification
.ViewSourceLoader
:
129 return typeof(IViewSourceLoader
);
130 case ServiceIdentification
.ScaffoldingSupport
:
131 return typeof(IScaffoldingSupport
);
132 case ServiceIdentification
.ViewEngineManager
:
133 return typeof(IViewEngineManager
);
134 case ServiceIdentification
.ResourceFactory
:
135 return typeof(IResourceFactory
);
136 case ServiceIdentification
.ExecutorFactory
:
137 return typeof(IControllerLifecycleExecutorFactory
);
138 case ServiceIdentification
.TransformationFilterFactory
:
139 return typeof(ITransformFilterFactory
);
140 case ServiceIdentification
.TransformFilterDescriptorProvider
:
141 return typeof(ITransformFilterDescriptorProvider
);
142 case ServiceIdentification
.UrlBuilder
:
143 return typeof(IUrlBuilder
);
144 case ServiceIdentification
.UrlTokenizer
:
145 return typeof(IUrlTokenizer
);
146 case ServiceIdentification
.ServerUtility
:
147 return typeof(IServerUtility
);
148 case ServiceIdentification
.ValidatorRegistry
:
149 return typeof(IValidatorRegistry
);
150 case ServiceIdentification
.AjaxProxyGenerator
:
151 return typeof(IAjaxProxyGenerator
);
153 throw new NotSupportedException("Id not supported " + id
);