01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.
14:
15: package org.apache.tapestry.ioc.internal.util;
16:
17: import org.apache.tapestry.ioc.Locatable;
18: import org.apache.tapestry.ioc.Location;
19:
20: /**
21: * Exception class used as a replacement for {@link java.lang.RuntimeException} when the exception
22: * is related to a particular location.
23: */
24: public class TapestryException extends RuntimeException implements
25: Locatable {
26: private static final long serialVersionUID = 6396903640977182682L;
27:
28: private transient final Location _location;
29:
30: /**
31: * @param message
32: * a message (may be null)
33: * @param locatable
34: * implements {@link Location} or {@link Locatable}
35: * @param cause
36: * if not null, the root cause of the exception
37: */
38: public TapestryException(String message, Object location,
39: Throwable cause) {
40: this (message, InternalUtils.locationOf(location), cause);
41: }
42:
43: /**
44: * @param message
45: * a message (may be null)
46: * @param cause
47: * if not null, the root cause of the exception, also used to set the location
48: */
49: public TapestryException(String message, Throwable cause) {
50: this (message, cause, cause);
51: }
52:
53: /**
54: * @param message
55: * a message (may be null)
56: * @param locatable
57: * location to associated with the exception, or null if not known
58: * @param cause
59: * if not null, the root cause of the exception
60: */
61: public TapestryException(String message, Location location,
62: Throwable cause) {
63: super (message, cause);
64:
65: _location = location;
66: }
67:
68: public Location getLocation() {
69: return _location;
70: }
71:
72: @Override
73: public String toString() {
74: if (_location == null)
75: return super .toString();
76:
77: return String.format("%s [at %s]", super.toString(), _location);
78: }
79:
80: }
|