Applying patch from Jonathon Rossi
[castle.git] / Experiments / MVC / Castle.MVC / Controllers / Controller.cs
blob2f7a7be51b73d9fe5e26c3b028dfa727978b7572
1 #region Apache Notice
2 /*****************************************************************************
3 *
4 * Castle.MVC
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 ********************************************************************************/
19 #endregion
21 #region Autors
23 /************************************************
24 * Gilles Bayon
25 *************************************************/
26 #endregion
28 #region Using
30 using Castle.Core;
31 using Castle.MVC.Configuration;
32 using Castle.MVC.Navigation;
33 using Castle.MVC.States;
35 #endregion
37 namespace Castle.MVC.Controllers
39 /// <summary>
40 /// Abstract base class to control the navigation between views.
41 /// You must inherit from this class when developing yours controllers.
42 /// </summary>
43 public abstract class Controller : IController
46 #region Fields
47 private INavigator _navigator = null;
48 private string _nextViewToDisplay = null;
49 #endregion
51 #region Constructor
53 /// <summary>
54 /// Default constructor
55 /// </summary>
56 public Controller()
59 #endregion
61 #region IController Members
64 /// <summary>
65 /// The next view to display.
66 /// </summary>
67 public string NextView
69 get { return _nextViewToDisplay; }
70 set { _nextViewToDisplay = value; }
73 /// <summary>
74 /// Get the user process state.
75 /// </summary>
76 public IState State
78 get { return _navigator.CurrentState; }
81 /// <summary>
82 /// The navigator coordinates the interactions of views and controllers
83 /// </summary>
84 public INavigator Navigator
86 get { return _navigator; }
87 set { _navigator = value;}
90 #endregion
92 #region Methods
94 /// <summary>
95 /// Calls the Navigate method on the appropriate navigator
96 /// and navigate to the next view according to the config file.
97 /// </summary>
98 public void Navigate()
100 this.State.PreviousView = this.State.CurrentView;
101 this.State.CurrentView = ConfigUtil.Settings.GetNextView(this.State.CurrentView, this.State.Command);
102 _navigator.Navigate();
105 /// <summary>
106 /// Calls the Navigate method on the appropriate navigator
107 /// </summary>
108 /// <param name="view">the Next View To Display</param>
109 public void Navigate(string view)
111 this.State.PreviousView = this.State.CurrentView;
112 this.State.CurrentView = view;
113 _navigator.Navigate();
115 #endregion