2 * @(#)AFSSecurityException.java 2.0 01/04/16
4 * Copyright (c) 2001 International Business Machines Corp.
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
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.
24 package org.openafs.jafs;
26 import java.util.Locale;
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.
32 * @version 1.0, 04/16/2001
35 public class AFSSecurityException extends SecurityException
38 * The AFS specific error number (code).
39 * @see #getErrorCode()
44 * Constructs an <code>AFSSecurityException</code> with the specified detail
47 * @param reason the detail message.
49 public AFSSecurityException (String reason)
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.
58 * @param errno the AFS error number (error code).
60 public AFSSecurityException (int errno)
62 super(ErrorTable.getMessage( (errno == 0) ? ErrorTable.UNKNOWN : errno ));
63 this.errno = (errno == 0) ? ErrorTable.UNKNOWN : errno;
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.
74 * @param reason the detail message.
75 * @param errno the AFS error number (error code).
76 * @see #getAFSMessage()
78 public AFSSecurityException (String reason, int errno)
80 super( (reason == null) ? ErrorTable.getMessage( errno ) : reason );
83 /*-----------------------------------------------------------------------*/
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>.
89 * @return the AFS error code of this <code>AFSException</code>
91 * @see ErrorTable#getMessage(int)
93 public int getErrorCode()
97 /*-----------------------------------------------------------------------*/
99 * Returns the error message string of this exception.
101 * @return the error message string of this exception object.
103 * @see #getAFSMessage()
105 public String getMessage()
107 String msg = super.getMessage();
108 return (msg == null) ? ErrorTable.getMessage(errno) : msg;
110 /*-----------------------------------------------------------------------*/
112 * Returns the locale specific error message string of this exception.
114 * @return the error message string of this exception object.
115 * @param locale the locale for which this message will be displayed
117 * @see #getAFSMessage()
119 public String getMessage(Locale locale)
121 String msg = super.getMessage();
122 return (msg == null) ? ErrorTable.getMessage(errno, locale) : msg;
124 /*-----------------------------------------------------------------------*/
126 * Returns the AFS error message string defined by the <code>ErrorTable
127 * </code> class. The message will be formatted according to the default
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.
137 * @return the AFS error message string of this exception object.
139 * @see #getAFSMessage(Locale)
140 * @see AFSSecurityException#AFSSecurityException(String, int)
141 * @see ErrorTable#getMessage(int)
142 * @see java.lang.Exception#getMessage()
144 public String getAFSMessage()
146 return ErrorTable.getMessage(errno);
148 /*-----------------------------------------------------------------------*/
150 * Returns the AFS error message defined by the <code>ErrorTable</code>
151 * class. The message will be formatted according to the specified Locale.
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.
160 * @return the AFS error message string of this exception object.
161 * @param locale the locale for which this message will be displayed
163 * @see #getAFSMessage()
164 * @see AFSSecurityException#AFSSecurityException(String, int)
165 * @see ErrorTable#getMessage(int, Locale)
166 * @see java.lang.Exception#getMessage()
168 public String getAFSMessage(Locale locale)
170 return ErrorTable.getMessage(errno, locale);
172 /*-----------------------------------------------------------------------*/
174 * Returns a string representation of this AFS Exception.
176 * @return the AFS error message string of this
177 * <code>AFSSecurityException</code> object.
181 public String toString()
183 return "AFSSecurityException: Error Code: " + errno + "; Message: " +
186 /*-----------------------------------------------------------------------*/