1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
.Descriptors
18 using System
.Collections
;
19 using System
.Collections
.Generic
;
20 using System
.Collections
.Specialized
;
21 using System
.Reflection
;
24 /// Holds all meta information a controller might
25 /// expose, so the attributes are collected only once.
26 /// This approach translates into a huge performance boost.
29 public class ControllerMetaDescriptor
: BaseMetaDescriptor
31 private ControllerDescriptor controllerDescriptor
;
32 private DefaultActionAttribute defaultAction
;
33 private HelperDescriptor
[] helpers
= new HelperDescriptor
[0];
34 private FilterDescriptor
[] filters
= new FilterDescriptor
[0];
35 private TransformFilterDescriptor
[] transformFilters
= new TransformFilterDescriptor
[0];
36 private Dictionary
<object, ActionMetaDescriptor
> actionMetaDescriptors
= new Dictionary
<object, ActionMetaDescriptor
>();
37 private IList
<ScaffoldingAttribute
> scaffoldings
= new List
<ScaffoldingAttribute
>();
38 private IList
<Type
> actionProviders
= new List
<Type
>();
39 private IList
<MethodInfo
> ajaxActions
= new List
<MethodInfo
>();
40 private IDictionary actions
= new HybridDictionary(true);
43 /// Initializes a new instance of the <see cref="ControllerMetaDescriptor"/> class.
45 public ControllerMetaDescriptor()
50 /// Gets an action descriptor with information about an action.
52 /// <param name="actionMethod">The action method.</param>
53 /// <returns></returns>
54 public ActionMetaDescriptor
GetAction(object actionMethod
)
56 if (actionMethod
== null) throw new ArgumentNullException("actionMethod");
58 ActionMetaDescriptor desc
;
60 actionMetaDescriptors
.TryGetValue(actionMethod
, out desc
);
68 /// <param name="action">The action.</param>
69 /// <param name="metaDescriptor">The meta descriptor.</param>
70 public void AddAction(object action
, ActionMetaDescriptor metaDescriptor
)
72 if (action
== null) throw new ArgumentNullException("action");
73 if (metaDescriptor
== null) throw new ArgumentNullException("metaDescriptor");
75 actionMetaDescriptors
[action
] = metaDescriptor
;
79 /// Gets or sets the controller descriptor.
81 /// <value>The controller descriptor.</value>
82 public ControllerDescriptor ControllerDescriptor
84 get { return controllerDescriptor; }
85 set { controllerDescriptor = value; }
91 /// <value>The actions.</value>
92 public IDictionary Actions
94 get { return actions; }
98 /// Gets the action descriptors dictionary.
99 /// They key is an action (might be a method or something else).
101 /// <value>The action descriptors.</value>
102 public Dictionary
<object, ActionMetaDescriptor
> ActionDescriptors
104 get { return actionMetaDescriptors; }
108 /// Gets the ajax actions.
110 /// <value>The ajax actions.</value>
111 public IList
<MethodInfo
> AjaxActions
113 get { return ajaxActions; }
117 /// Gets or sets the default action.
119 /// <value>The default action.</value>
120 public DefaultActionAttribute DefaultAction
122 get { return defaultAction; }
123 set { defaultAction = value; }
127 /// Gets or sets the helpers.
129 /// <value>The helpers.</value>
130 public HelperDescriptor
[] Helpers
132 get { return helpers; }
133 set { helpers = value; }
137 /// Gets or sets the filters.
139 /// <value>The filters.</value>
140 public FilterDescriptor
[] Filters
142 get { return filters; }
143 set { filters = value; }
147 /// Gets the scaffoldings.
149 /// <value>The scaffoldings.</value>
150 public IList
<ScaffoldingAttribute
> Scaffoldings
152 get { return scaffoldings; }
156 /// Gets the action providers.
158 /// <value>The action providers.</value>
159 public IList
<Type
> ActionProviders
161 get { return actionProviders; }
165 /// Gets or sets the transform filters.
167 /// <value>The transform filters.</value>
168 public TransformFilterDescriptor
[] TransformFilters
170 get { return transformFilters; }
171 set { transformFilters = value; }