Applying patch from Jonathon Rossi
[castle.git] / Experiments / MVC / Castle.MVC / States / BaseState.cs
blobc4670b19dc69531a6ecf38778a16f23a8217066e
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 System;
31 using System.Collections;
32 using System.Collections.Specialized;
33 using Castle.Core;
34 using Castle.MVC.StatePersister;
36 #endregion
38 namespace Castle.MVC.States
40 /// <summary>
41 /// Represent the base State.
42 /// You could inherit from this class when developing your state.
43 /// </summary>
44 [Serializable]
45 [Transient]
46 public abstract class BaseState : DictionaryBase, IState
49 /// <summary>
50 /// Key used to retrieve the session.
51 /// </summary>
52 public const string SESSION_KEY = "_MVC_SESSION_STATE_";
54 #region Fields
56 private string _command = string.Empty;
57 [NonSerialized]
58 private HybridDictionary _items = new HybridDictionary();
59 private string _currentView = string.Empty;
60 private string _previousView = string.Empty;
61 IStatePersister _statePersister = null;
62 #endregion
64 #region Constructor
66 /// <summary>
67 /// Constructor
68 /// </summary>
69 public BaseState()
72 #endregion
74 #region IState members
76 /// <summary>
77 /// A state persister provider.
78 /// </summary>
79 public IStatePersister StatePersister
81 get
83 return _statePersister;
85 set
87 _statePersister = value;
91 /// <summary>
92 /// Gets or sets the command id value. This value determines
93 /// which view is the next view in the navigation graph.
94 /// </summary>
95 public string Command
97 get{ return _command;}
98 set{ _command = value; }
101 /// <summary>
102 /// Gets or sets the current view name.
103 /// </summary>
104 public string CurrentView
106 get{ return _currentView; }
107 set{_currentView = value;}
110 /// <summary>
111 /// Gets or sets the previous view.
112 /// </summary>
113 public string PreviousView
115 get{ return _previousView; }
116 set{_previousView = value;}
119 /// <summary>
120 /// Provides access to a dictionary of volative items.
121 /// </summary>
122 public IDictionary Items
124 get{ return _items; }
127 #endregion
129 #region Methods
131 /// <summary>
132 /// Gets or sets an element saved on the state with the specified key.
133 /// </summary>
134 public object this[ string key ]
136 set{this.Dictionary[ key ] = value;}
137 get{ return this.Dictionary[ key ]; }
140 /// <summary>
141 /// Reset state.
142 /// </summary>
143 public void Reset()
145 _items.Clear();
148 /// <summary>
149 /// Save the state
150 /// </summary>
151 public void Save()
153 _statePersister.Save(this);
155 #endregion