Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework / Providers / DefaultResourceDescriptorProvider.cs
blobd6e4370846edf000e60979676a1470a58b30add7
1 // Copyright 2004-2008 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.Providers
17 using System.Collections;
18 using System.Reflection;
19 using Castle.Core.Logging;
20 using Castle.MonoRail.Framework.Descriptors;
22 /// <summary>
23 /// Creates <see cref="ResourceDescriptor"/> from attributes
24 /// associated with the <see cref="IController"/>
25 /// </summary>
26 public class DefaultResourceDescriptorProvider : IResourceDescriptorProvider
28 /// <summary>
29 /// The logger instance
30 /// </summary>
31 private ILogger logger = NullLogger.Instance;
33 #region IMRServiceEnabled implementation
35 /// <summary>
36 /// Invoked by the framework in order to give a chance to
37 /// obtain other services
38 /// </summary>
39 /// <param name="provider">The service proviver</param>
40 public void Service(IMonoRailServices provider)
42 ILoggerFactory loggerFactory = (ILoggerFactory) provider.GetService(typeof(ILoggerFactory));
44 if (loggerFactory != null)
46 logger = loggerFactory.Create(typeof(DefaultResourceDescriptorProvider));
50 #endregion
52 /// <summary>
53 /// Collects the resources.
54 /// </summary>
55 /// <param name="memberInfo">The member info.</param>
56 /// <returns></returns>
57 public ResourceDescriptor[] CollectResources(MemberInfo memberInfo)
59 if (logger.IsDebugEnabled)
61 logger.DebugFormat("Collecting resources information for {0}", memberInfo.Name);
64 object[] attributes = memberInfo.GetCustomAttributes(typeof(IResourceDescriptorBuilder), true);
66 ArrayList descriptors = new ArrayList();
68 foreach(IResourceDescriptorBuilder builder in attributes)
70 ResourceDescriptor[] descs = builder.BuildResourceDescriptors();
72 if (logger.IsDebugEnabled)
74 foreach(ResourceDescriptor desc in descs)
76 logger.DebugFormat("Collected resource {0} Assembly Name {1} Culture {2} ResName {3} ResType {4}",
77 desc.Name, desc.AssemblyName, desc.CultureName, desc.ResourceName, desc.ResourceType);
81 descriptors.AddRange(descs);
84 return (ResourceDescriptor[]) descriptors.ToArray(typeof(ResourceDescriptor));