Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / ControllerNotFoundException.cs
blob3dd822382b556f5c2f0eeefbdd3f23efa8376a18
1 // Copyright 2004-2007 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.Framework
17 using System;
18 using System.Text;
19 using System.Runtime.Serialization;
21 /// <summary>
22 /// Thrown when a controller is not found.
23 /// </summary>
24 [Serializable]
25 public class ControllerNotFoundException : ApplicationException
27 private readonly String area, controller;
29 /// <summary>
30 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
31 /// </summary>
32 /// <param name="message">The message.</param>
33 public ControllerNotFoundException(string message) : base(message)
37 /// <summary>
38 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
39 /// </summary>
40 /// <param name="area">The area.</param>
41 /// <param name="controller">The controller.</param>
42 public ControllerNotFoundException(String area, String controller) : base(BuildExceptionMessage(area, controller))
46 /// <summary>
47 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
48 /// </summary>
49 /// <param name="area">The area.</param>
50 /// <param name="controller">The controller.</param>
51 /// <param name="innerException">The inner exception.</param>
52 public ControllerNotFoundException(String area, String controller, Exception innerException)
53 : base(BuildExceptionMessage(area, controller), innerException)
57 /// <summary>
58 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
59 /// </summary>
60 /// <param name="url">The URL.</param>
61 public ControllerNotFoundException(UrlInfo url) : this(url.Area, url.Controller)
65 /// <summary>
66 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
67 /// </summary>
68 /// <param name="url">The URL.</param>
69 /// <param name="innerException">The inner exception.</param>
70 public ControllerNotFoundException(UrlInfo url, Exception innerException)
71 : this(url.Area, url.Controller, innerException)
75 /// <summary>
76 /// Gets the area name.
77 /// </summary>
78 /// <value>The area name.</value>
79 public String Area
81 get { return area; }
84 /// <summary>
85 /// Gets the controller name.
86 /// </summary>
87 /// <value>The controller name.</value>
88 public String Controller
90 get { return controller; }
93 #region Serialization Support
95 /// <summary>
96 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
97 /// </summary>
98 /// <param name="info">The object that holds the serialized object data.</param>
99 /// <param name="context">The contextual information about the source or destination.</param>
100 protected ControllerNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
102 area = info.GetString("rails.area");
103 controller = info.GetString("rails.controller");
106 /// <summary>
107 /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
108 /// with information about the exception.
109 /// </summary>
110 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
111 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
112 /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (<see langword="Nothing"/> in Visual Basic).</exception>
113 public override void GetObjectData(SerializationInfo info, StreamingContext context)
115 base.GetObjectData(info, context);
116 info.AddValue("rails.area", area);
117 info.AddValue("rails.controller", controller);
120 #endregion
122 /// <summary>
123 /// Builds the exception message.
124 /// </summary>
125 /// <param name="area">The area.</param>
126 /// <param name="controller">The controller.</param>
127 /// <returns></returns>
128 private static String BuildExceptionMessage(String area, String controller)
130 StringBuilder sb = new StringBuilder("Controller not found.");
132 sb.AppendFormat(" Area: '{0}'", area);
133 sb.AppendFormat(" Controller Name: '{0}'", controller);
135 return sb.ToString();