1 // Copyright 2004-2007 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
19 using System
.Runtime
.Serialization
;
20 using Castle
.MonoRail
.Framework
.Internal
;
23 /// Thrown when a controller is not found.
26 public class ControllerNotFoundException
: ApplicationException
28 private readonly String area
, controller
;
31 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
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
))
40 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
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
)
51 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
53 /// <param name="url">The URL.</param>
54 public ControllerNotFoundException(UrlInfo url
) : this(url
.Area
, url
.Controller
)
59 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
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
)
69 /// Gets the area name.
71 /// <value>The area name.</value>
78 /// Gets the controller name.
80 /// <value>The controller name.</value>
81 public String Controller
83 get { return controller; }
86 #region Serialization Support
89 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
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");
100 /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
101 /// with information about the exception.
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
);
116 /// Builds the exception message.
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();