1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.interceptor;
18
19
20 import org.apache.ldap.common.exception.LdapException;
21 import org.apache.ldap.common.exception.LdapNamingException;
22 import org.apache.ldap.common.message.ResultCodeEnum;
23 import org.apache.ldap.server.invocation.Invocation;
24
25
26 /***
27 * A {@link LdapNamingException} that wraps uncaught runtime exceptions thrown from {@link Interceptor}s.
28 *
29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30 * @version $Rev: 159316 $, $Date: 2005-03-28 17:20:10 -0500 (Mon, 28 Mar 2005) $
31 */
32 public class InterceptorException extends LdapNamingException
33 {
34 private static final long serialVersionUID = 3258690996517746233L;
35
36 /***
37 * The Invocation the Interceptor failed on
38 */
39 private final Invocation invocation;
40
41 /***
42 * The Interceptor causing the failure
43 */
44 private final Interceptor interceptor;
45
46
47 /***
48 * Creates an InterceptorException without a message.
49 *
50 * @param interceptor the Interceptor causing the failure
51 * @param invocation the Invocation the Interceptor failed on
52 */
53 public InterceptorException( Interceptor interceptor, Invocation invocation )
54 {
55 super( ResultCodeEnum.OTHER );
56
57 this.invocation = invocation;
58
59 this.interceptor = interceptor;
60 }
61
62
63 /***
64 * Creates an InterceptorException with a custom message.
65 *
66 * @param interceptor the Interceptor causing the failure
67 * @param invocation the Invocation the Interceptor failed on
68 * @param explanation String explanation of why the Interceptor failed
69 */
70 public InterceptorException( Interceptor interceptor, Invocation invocation, String explanation )
71 {
72 super( explanation, ResultCodeEnum.OTHER );
73
74 this.invocation = invocation;
75
76 this.interceptor = interceptor;
77 }
78
79
80 /***
81 * Creates an InterceptorException without a message.
82 *
83 * @param interceptor the Interceptor causing the failure
84 * @param invocation the Invocation the Interceptor failed on
85 * @param rootCause the root cause of this exception
86 */
87 public InterceptorException( Interceptor interceptor, Invocation invocation, Throwable rootCause )
88 {
89 this( interceptor, invocation );
90
91 super.setRootCause( rootCause );
92 }
93
94
95 /***
96 * Creates an InterceptorException without a message.
97 *
98 * @param interceptor the Interceptor causing the failure
99 * @param invocation the Invocation the Interceptor failed on
100 * @param explanation String explanation of why the Interceptor failed
101 * @param rootCause the root cause of this exception
102 */
103 public InterceptorException( Interceptor interceptor, Invocation invocation, String explanation,
104 Throwable rootCause )
105 {
106 this( interceptor, invocation, explanation );
107
108 super.setRootCause( rootCause );
109 }
110
111
112 /***
113 * Gets the invovation object this exception is associated with.
114 *
115 * @return the invovation object this exception is associated with
116 */
117 public Invocation getInvocation()
118 {
119 return invocation;
120 }
121
122
123 /***
124 * Gets the interceptor this exception is associated with.
125 *
126 * @return the interceptor this exception is associated with
127 */
128 public Interceptor getInterceptor()
129 {
130 return interceptor;
131 }
132
133
134 /***
135 * Will return the resultCode of the root cause if the root cause implements LdapException.
136 *
137 * @see org.apache.ldap.common.exception.LdapException#getResultCode()
138 */
139 public ResultCodeEnum getResultCode()
140 {
141 if ( getRootCause() != null && ( getRootCause() instanceof LdapException ) )
142 {
143 return ( ( LdapException ) getRootCause() ).getResultCode();
144 }
145
146 return super.getResultCode();
147 }
148 }