Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * @(#)AFSSecurityException.java 2.0 01/04/16 | |
3 | * | |
4 | * Copyright (c) 2001 International Business Machines Corp. | |
5 | * All rights reserved. | |
6 | * | |
7 | * This software has been released under the terms of the IBM Public | |
8 | * License. For details, see the LICENSE file in the top-level source | |
9 | * directory or online at http://www.openafs.org/dl/license10.html | |
10 | * | |
11 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
12 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
13 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
14 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR | |
15 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
16 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
17 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
18 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
19 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
20 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
21 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
22 | */ | |
23 | ||
24 | package org.openafs.jafs; | |
25 | ||
26 | import java.util.Locale; | |
27 | ||
28 | /** | |
29 | * An exception indicating that a security related error has occured in the | |
30 | * Java AFS API, in the Java AFS JNI, or in the AFS file system. | |
31 | * | |
32 | * @version 1.0, 04/16/2001 | |
33 | * @see AFSException | |
34 | */ | |
35 | public class AFSSecurityException extends SecurityException | |
36 | { | |
37 | /** | |
38 | * The AFS specific error number (code). | |
39 | * @see #getErrorCode() | |
40 | */ | |
41 | protected int errno; | |
42 | ||
43 | /** | |
44 | * Constructs an <code>AFSSecurityException</code> with the specified detail | |
45 | * message. | |
46 | * | |
47 | * @param reason the detail message. | |
48 | */ | |
49 | public AFSSecurityException (String reason) | |
50 | { | |
51 | super(reason); | |
52 | } | |
53 | /** | |
54 | * Constructs an <code>AFSSecurityException</code> with the specified error | |
55 | * code. This constructor will also generate the appropriate error message | |
56 | * respective to the specified error code. | |
57 | * | |
58 | * @param errno the AFS error number (error code). | |
59 | */ | |
60 | public AFSSecurityException (int errno) | |
61 | { | |
62 | super(ErrorTable.getMessage( (errno == 0) ? ErrorTable.UNKNOWN : errno )); | |
63 | this.errno = (errno == 0) ? ErrorTable.UNKNOWN : errno; | |
64 | } | |
65 | /** | |
66 | * Constructs an <code>AFSFileException</code> with the specified detail | |
67 | * message and specified error code. In this constructor the specified | |
68 | * detail message overrides the default AFS error message defined by the | |
69 | * <code>ErrorTable</code> class. Therefore, to retrieve the AFS specific | |
70 | * error message, you must use the <code>{@link #getAFSMessage} | |
71 | * </code> method. The <code>{@link #getMessage}</code> method will return | |
72 | * the message specified in this constructor. | |
73 | * | |
74 | * @param reason the detail message. | |
75 | * @param errno the AFS error number (error code). | |
76 | * @see #getAFSMessage() | |
77 | */ | |
78 | public AFSSecurityException (String reason, int errno) | |
79 | { | |
80 | super( (reason == null) ? ErrorTable.getMessage( errno ) : reason ); | |
81 | this.errno = errno; | |
82 | } | |
83 | /*-----------------------------------------------------------------------*/ | |
84 | /** | |
85 | * Returns the AFS specific error number (code). This code can be interpreted | |
86 | * by use of the <code>{@link ErrorTable}</code> class method | |
87 | * <code>{@link ErrorTable#getMessage(int)}</code>. | |
88 | * | |
89 | * @return the AFS error code of this <code>AFSException</code> | |
90 | * object. | |
91 | * @see ErrorTable#getMessage(int) | |
92 | */ | |
93 | public int getErrorCode() | |
94 | { | |
95 | return errno; | |
96 | } | |
97 | /*-----------------------------------------------------------------------*/ | |
98 | /** | |
99 | * Returns the error message string of this exception. | |
100 | * | |
101 | * @return the error message string of this exception object. | |
102 | * | |
103 | * @see #getAFSMessage() | |
104 | */ | |
105 | public String getMessage() | |
106 | { | |
107 | String msg = super.getMessage(); | |
108 | return (msg == null) ? ErrorTable.getMessage(errno) : msg; | |
109 | } | |
110 | /*-----------------------------------------------------------------------*/ | |
111 | /** | |
112 | * Returns the locale specific error message string of this exception. | |
113 | * | |
114 | * @return the error message string of this exception object. | |
115 | * @param locale the locale for which this message will be displayed | |
116 | * | |
117 | * @see #getAFSMessage() | |
118 | */ | |
119 | public String getMessage(Locale locale) | |
120 | { | |
121 | String msg = super.getMessage(); | |
122 | return (msg == null) ? ErrorTable.getMessage(errno, locale) : msg; | |
123 | } | |
124 | /*-----------------------------------------------------------------------*/ | |
125 | /** | |
126 | * Returns the AFS error message string defined by the <code>ErrorTable | |
127 | * </code> class. The message will be formatted according to the default | |
128 | * Locale. | |
129 | * | |
130 | * <P> This message is also available from this object's super class | |
131 | * method <code>getMessage</code>. However, this method will always return | |
132 | * the string message associated with the actual AFS error code/number | |
133 | * specified, whereas the {@link #getMessage()} method will return the | |
134 | * string message intended for this Exception object, which may be | |
135 | * an overridden message defined in the constructor of this Exception. | |
136 | * | |
137 | * @return the AFS error message string of this exception object. | |
138 | * | |
139 | * @see #getAFSMessage(Locale) | |
140 | * @see AFSSecurityException#AFSSecurityException(String, int) | |
141 | * @see ErrorTable#getMessage(int) | |
142 | * @see java.lang.Exception#getMessage() | |
143 | */ | |
144 | public String getAFSMessage() | |
145 | { | |
146 | return ErrorTable.getMessage(errno); | |
147 | } | |
148 | /*-----------------------------------------------------------------------*/ | |
149 | /** | |
150 | * Returns the AFS error message defined by the <code>ErrorTable</code> | |
151 | * class. The message will be formatted according to the specified Locale. | |
152 | * | |
153 | * <P> This message is also available from this object's super class | |
154 | * method <code>getMessage</code>. However, this method will always return | |
155 | * the string message associated with the actual AFS error code/number | |
156 | * specified, whereas the {@link #getMessage()} method will return the | |
157 | * string message intended for this Exception object, which may be | |
158 | * an overridden message defined in the constructor of this Exception. | |
159 | * | |
160 | * @return the AFS error message string of this exception object. | |
161 | * @param locale the locale for which this message will be displayed | |
162 | * | |
163 | * @see #getAFSMessage() | |
164 | * @see AFSSecurityException#AFSSecurityException(String, int) | |
165 | * @see ErrorTable#getMessage(int, Locale) | |
166 | * @see java.lang.Exception#getMessage() | |
167 | */ | |
168 | public String getAFSMessage(Locale locale) | |
169 | { | |
170 | return ErrorTable.getMessage(errno, locale); | |
171 | } | |
172 | /*-----------------------------------------------------------------------*/ | |
173 | /** | |
174 | * Returns a string representation of this AFS Exception. | |
175 | * | |
176 | * @return the AFS error message string of this | |
177 | * <code>AFSSecurityException</code> object. | |
178 | * | |
179 | * @see #getMessage() | |
180 | */ | |
181 | public String toString() | |
182 | { | |
183 | return "AFSSecurityException: Error Code: " + errno + "; Message: " + | |
184 | getMessage(); | |
185 | } | |
186 | /*-----------------------------------------------------------------------*/ | |
187 | } | |
188 | ||
189 | ||
190 | ||
191 | ||
192 | ||
193 | ||
194 | ||
195 | ||
196 | ||
197 | ||
198 | ||
199 | ||
200 | ||
201 | ||
202 |