2 * @(#)ErrorTable.java 2.0 11/06/2000
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
.ResourceBundle
;
27 import java
.util
.Locale
;
30 * Static class for error code message management.
32 * <P>Simply translates all error codes returned by the AFS native library
33 * to literal string messages according to the defined locale.
35 * @version 2.0, 11/06/2000
37 public final class ErrorTable
39 /* Undefined Error Constants */
40 public static final int UNKNOWN
= -3;
41 public static final int SPECIAL_CASE
= -2;
42 public static final int GENERAL_FAILURE
= -1;
44 /* Java Application Error Constants */
45 public static final int NULL
= 1000;
46 public static final int INVALID_SESSION
= 1001;
47 public static final int EXPIRED_SESSION
= 1002;
48 public static final int OPERATION_ABORTED
= 1003;
49 public static final int FORCED_ABORT
= 1004;
51 /* General UNIX Error Constants */
52 public static final int NOT_PERMITTED
= 1;
53 public static final int NOT_FOUND
= 2;
54 public static final int IO_ERROR
= 5;
55 public static final int NO_DEVICE_ADDRESS
= 6;
56 public static final int BAD_FILE
= 9;
57 public static final int TRY_AGAIN
= 11;
58 public static final int OUT_OF_MEMORY
= 12;
59 public static final int PERMISSION_DENIED
= 13;
60 public static final int BAD_ADDRESS
= 14;
61 public static final int DEVICE_BUSY
= 16;
62 public static final int FILE_EXISTS
= 17;
63 public static final int NO_DEVICE
= 19;
64 public static final int NOT_DIRECTORY
= 20;
65 public static final int IS_DIRECTORY
= 21;
66 public static final int INVALID_ARG
= 22;
67 public static final int FILE_OVERFLOW
= 23;
68 public static final int FILE_BUSY
= 26;
69 public static final int NAME_TOO_LONG
= 36;
70 public static final int DIRECTORY_NOT_EMPTY
= 39;
71 public static final int CONNECTION_TIMED_OUT
= 110;
72 public static final int QUOTA_EXCEEDED
= 122;
74 /* AFS Error Constants */
75 public static final int BAD_USERNAME
= 180486;
76 public static final int BAD_PASSWORD
= 180490;
77 public static final int EXPIRED_PASSWORD
= 180519;
78 public static final int SKEWED_CLOCK
= 180514;
79 public static final int ID_LOCKED
= 180522;
80 public static final int CELL_NOT_FOUND
= 180501;
81 public static final int USERNAME_EXISTS
= 180481;
82 public static final int USER_DOES_NOT_EXIST
= 180484;
84 /* AFS Authentication Error Constants */
85 public static final int PRPERM
= 267269;
86 public static final int UNOACCESS
= 5407;
87 public static final int BZACCESS
= 39430;
88 public static final int KANOAUTH
= 180488;
89 public static final int RXKADNOAUTH
= 19270405;
91 private static java
.util
.Hashtable bundles
;
95 bundles
= new java
.util
.Hashtable(2);
97 bundles
.put(Locale
.US
,
98 ResourceBundle
.getBundle("ErrorMessages", Locale
.US
));
99 bundles
.put(Locale
.SIMPLIFIED_CHINESE
,
100 ResourceBundle
.getBundle("ErrorMessages", Locale
.SIMPLIFIED_CHINESE
));
101 } catch (Exception e
) {
102 bundles
.put(Locale
.getDefault(),
103 ResourceBundle
.getBundle("ErrorMessages"));
107 /*-----------------------------------------------------------------------*/
109 * Tests to identify if the return code is a "Permission Denied" error.
111 * <P> This method will qualify <CODE>errno</CODE> against:
112 * <LI><CODE>ErrorTable.PERMISSION_DENIED</CODE>
113 * <LI><CODE>ErrorTable.PRPERM</CODE>
114 * <LI><CODE>ErrorTable.UNOACCESS</CODE>
115 * <LI><CODE>ErrorTable.BZACCESS</CODE>
116 * <LI><CODE>ErrorTable.KANOAUTH</CODE>
117 * <LI><CODE>ErrorTable.RXKADNOAUTH</CODE>
119 * @param errno Error Code/Number
120 * @return boolean If <CODE>errno</CODE> is a "Permission Denied"
123 public static boolean isPermissionDenied(int errno
)
125 return (errno
== PERMISSION_DENIED
|| errno
== PRPERM
||
126 errno
== UNOACCESS
|| errno
== BZACCESS
|| errno
== KANOAUTH
127 || errno
== RXKADNOAUTH
);
129 /*-----------------------------------------------------------------------*/
131 * Returns a String message representing the error code (number) provided.
133 * <P> If the error code provided is out of range of the library of defined
134 * error codes, this method will return <CODE>Error number [###] unknown
135 * </CODE>. If an exception is thrown, this method will return either:
136 * <CODE>Unknown error</CODE>, <CODE>Special case error</CODE>, or
137 * <CODE>Invalid error code: ###</CODE>.
139 * @param errno Error Code/Number
140 * @return String Interpreted error message derived from
141 * <CODE>errno</CODE>.
143 public static String
getMessage(int errno
)
145 return getMessage(errno
, Locale
.getDefault());
147 /*-----------------------------------------------------------------------*/
149 * Returns a String message, respective to the provided locale, representing
150 * the error code (number) provided.
152 * <P> If the error code provided is out of range of the library of defined
153 * error codes, this method will return <CODE>Error number [###] unknown
154 * </CODE>. If an exception is thrown, this method will return either:
155 * <CODE>Unknown error</CODE>, <CODE>Special case error</CODE>, or
156 * <CODE>Invalid error code: ###</CODE>.
158 * @param errno Error Code/Number
159 * @param locale Locale of to be used for translating the message.
160 * @return String Interpreted error message derived from
161 * <CODE>errno</CODE>.
163 public static String
getMessage(int errno
, Locale locale
)
165 String msg
= "Error number [" + errno
+ "] unknown.";
167 msg
= getBundle(locale
).getString("E" + errno
);
168 } catch (Exception e
) {
172 } else if (errno
== GENERAL_FAILURE
) {
173 msg
= getBundle(locale
).getString("GENERAL_FAILURE");
174 } else if (errno
== UNKNOWN
) {
175 msg
= getBundle(locale
).getString("UNKNOWN");
176 } else if (errno
== SPECIAL_CASE
) {
177 msg
= getBundle(locale
).getString("SPECIAL_CASE");
179 System
.err
.println("ERROR in ErrorCode getMessage(): " + e
);
180 msg
= "Invaid error code: " + errno
;
182 } catch (Exception e2
) {
189 /*-----------------------------------------------------------------------*/
190 private static ResourceBundle
getBundle(Locale locale
) throws Exception
192 if (locale
== null) return getBundle(Locale
.getDefault());
193 ResourceBundle rb
= (ResourceBundle
)bundles
.get(locale
);
195 rb
= ResourceBundle
.getBundle("ErrorMessages", locale
);
196 bundles
.put(locale
, rb
);