Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / ControllerNotFoundException.cs
blobaaaf8f3a0d9f6e2cdb65369a00f329e6fa3e7d1f
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;
20 using Castle.MonoRail.Framework.Internal;
22 /// <summary>
23 /// Thrown when a controller is not found.
24 /// </summary>
25 [Serializable]
26 public class ControllerNotFoundException : ApplicationException
28 private readonly String area, controller;
30 /// <summary>
31 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
32 /// </summary>
33 /// <param name="area">The area.</param>
34 /// <param name="controller">The controller.</param>
35 public ControllerNotFoundException(String area, String controller) : base(BuildExceptionMessage(area, controller))
39 /// <summary>
40 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
41 /// </summary>
42 /// <param name="area">The area.</param>
43 /// <param name="controller">The controller.</param>
44 /// <param name="innerException">The inner exception.</param>
45 public ControllerNotFoundException(String area, String controller, Exception innerException)
46 : base(BuildExceptionMessage(area, controller), innerException)
50 /// <summary>
51 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
52 /// </summary>
53 /// <param name="url">The URL.</param>
54 public ControllerNotFoundException(UrlInfo url) : this(url.Area, url.Controller)
58 /// <summary>
59 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
60 /// </summary>
61 /// <param name="url">The URL.</param>
62 /// <param name="innerException">The inner exception.</param>
63 public ControllerNotFoundException(UrlInfo url, Exception innerException)
64 : this(url.Area, url.Controller, innerException)
68 /// <summary>
69 /// Gets the area name.
70 /// </summary>
71 /// <value>The area name.</value>
72 public String Area
74 get { return area; }
77 /// <summary>
78 /// Gets the controller name.
79 /// </summary>
80 /// <value>The controller name.</value>
81 public String Controller
83 get { return controller; }
86 #region Serialization Support
88 /// <summary>
89 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
90 /// </summary>
91 /// <param name="info">The object that holds the serialized object data.</param>
92 /// <param name="context">The contextual information about the source or destination.</param>
93 protected ControllerNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context)
95 area = info.GetString("rails.area");
96 controller = info.GetString("rails.controller");
99 /// <summary>
100 /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
101 /// with information about the exception.
102 /// </summary>
103 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
104 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
105 /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (<see langword="Nothing"/> in Visual Basic).</exception>
106 public override void GetObjectData(SerializationInfo info, StreamingContext context)
108 base.GetObjectData(info, context);
109 info.AddValue("rails.area", area);
110 info.AddValue("rails.controller", controller);
113 #endregion
115 /// <summary>
116 /// Builds the exception message.
117 /// </summary>
118 /// <param name="area">The area.</param>
119 /// <param name="controller">The controller.</param>
120 /// <returns></returns>
121 private static String BuildExceptionMessage(String area, String controller)
123 StringBuilder sb = new StringBuilder("Controller not found.");
125 sb.AppendFormat(" Area: '{0}'", area);
126 sb.AppendFormat(" Controller Name: '{0}'", controller);
128 return sb.ToString();