<commit_before>// Copyright 2004-2005 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.Framework.Internal
{
	using System;
	using System.Collections;
	using System.Reflection;
	using System.Threading;

	public class ControllerDescriptorBuilder
	{
		private ReaderWriterLock locker = new ReaderWriterLock();
		private Hashtable descriptorRepository = new Hashtable();

		/// <summary>
		/// Builds the <see cref="ControllerMetaDescriptor"/>.
		/// </summary>
		/// <param name="controller">Controller.</param>
		/// <returns></returns>
		public ControllerMetaDescriptor BuildDescriptor(Controller controller)
		{
			Type controllerType = controller.GetType();

			locker.AcquireReaderLock(-1);

			ControllerMetaDescriptor desc = (ControllerMetaDescriptor) 
				descriptorRepository[controllerType];

			if (desc != null)
			{
				locker.ReleaseReaderLock();
				
				return desc;
			}

			locker.UpgradeToWriterLock(-1);

			try
			{
				desc = BuildDescriptor(controller, controllerType);

				descriptorRepository[controllerType] = desc;
			}
			finally
			{
				locker.ReleaseWriterLock();
			}

			return desc;
		}

		private ControllerMetaDescriptor BuildDescriptor(Controller controller, Type controllerType)
		{
			ControllerMetaDescriptor descriptor = new ControllerMetaDescriptor();

			CollectClassLevelAttributes(controllerType, descriptor);

			foreach(object action in controller.Actions)
			{
				if (action is IList)
				{
					foreach(MethodInfo overloadedAction in (action as IList))
					{
						CollectActionAttributes(overloadedAction, descriptor);
					}
					
					continue;
				}

				CollectActionAttributes(action as MethodInfo, descriptor);<commit_msg>- Updated to reflect new location of actions on MetaDescriptor.<commit_after>// Copyright 2004-2005 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.Framework.Internal
{
	using System;
	using System.Collections;
	using System.Reflection;
	using System.Threading;

	public class ControllerDescriptorBuilder
	{
		private ReaderWriterLock locker = new ReaderWriterLock();
		private Hashtable descriptorRepository = new Hashtable();

		/// <summary>
		/// Builds the <see cref="ControllerMetaDescriptor"/>.
		/// </summary>
		/// <param name="controller">Controller.</param>
		/// <returns></returns>
		public ControllerMetaDescriptor BuildDescriptor(Controller controller)
		{
			Type controllerType = controller.GetType();

			locker.AcquireReaderLock(-1);

			ControllerMetaDescriptor desc = (ControllerMetaDescriptor) 
				descriptorRepository[controllerType];

			if (desc != null)
			{
				locker.ReleaseReaderLock();
				
				return desc;
			}

			locker.UpgradeToWriterLock(-1);

			try
			{
				desc = BuildDescriptor( controllerType );

				descriptorRepository[controllerType] = desc;
			}
			finally
			{
				locker.ReleaseWriterLock();
			}

			return desc;
		}

		private ControllerMetaDescriptor BuildDescriptor(  Type controllerType )
		{
			ControllerMetaDescriptor descriptor = new ControllerMetaDescriptor( controllerType );
			
			CollectClassLevelAttributes(controllerType, descriptor);

			foreach(object action in descriptor.Actions.Values)
			{
				if (action is IList)
				{
					foreach(MethodInfo overloadedAction in (action as IList))
					{
						CollectActionAttributes(overloadedAction, descriptor);
					}
					
					continue;
				}

				CollectActionAttributes(action as MethodInfo, descriptor);
{'fraction_non_alphanumeric': 0.0924792304328815, 'fraction_numerical': 0.006121556624398776, 'mean_word_length': 3.649390243902439, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3635511', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1149, 'n_words': 364}