setting all protected methods on WizardStepPage as virtual
[castle.git] / MonoRail2 / Castle.MonoRail / ControllerExecutor.cs
blobb4d5023c0bdc4e838c8f00b35012f4c3c2f5ef35
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
17 using System;
18 using System.Reflection;
20 /// <summary>
21 /// Manages the execution of the steps associated with
22 /// a controller (filters/action/disposal).
23 /// </summary>
24 /// <remarks>
25 /// This class is statefull.
26 /// </remarks>
27 public class ControllerExecutor
29 private readonly object controller;
30 private readonly IExecutionContext executionContext;
32 /// <summary>
33 /// Initializes a new instance of the <see cref="ControllerExecutor"/> class.
34 /// </summary>
35 /// <param name="controller">The controller.</param>
36 /// <param name="executionContext">The execution context.</param>
37 public ControllerExecutor(object controller, IExecutionContext executionContext)
39 if (controller == null) throw new ArgumentNullException("controller");
40 if (executionContext == null) throw new ArgumentNullException("executionContext");
42 UrlInfo url = executionContext.OriginalUrl;
44 IController properController = controller as IController;
46 if (properController != null)
48 properController.SetInitialState(url.Area, url.Controller, url.Action);
51 this.controller = controller;
52 this.executionContext = executionContext;
55 public ActionExecutor SelectAction()
57 return SelectAction(executionContext.OriginalUrl.Action);
60 public ActionExecutor SelectAction(string actionName)
62 // There is room for a clever cache here
64 // Right now let's support method action only
66 BindingFlags flags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
68 MethodInfo actionMethod = controller.GetType().GetMethod(actionName, flags);
70 if (actionMethod != null)
72 return new MethodActionExecutor(actionMethod);
75 return null;
78 public void Execute(ActionExecutor executor)
80 if (executor == null) throw new ArgumentNullException("executor");
82 executor.Execute(controller);