1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.ws.security.components.crypto;
19
20 import java.text.MessageFormat;
21 import java.util.MissingResourceException;
22 import java.util.ResourceBundle;
23
24 /***
25 * CredentialException.
26 * <p/>
27 *
28 * @author Davanum Srinivas (dims@yahoo.com).
29 */
30 public class CredentialException extends Exception {
31 public static final int FAILURE = -1;
32 public static final int EXPIRED = 1;
33 public static final int DEFECTIVE = 2;
34 public static final int IO_ERROR = 3;
35 public static final int SEC_ERROR = 3;
36 private static ResourceBundle resources;
37 private int errorCode;
38
39 static {
40 try {
41 resources = ResourceBundle.getBundle("org.apache.ws.security.components.crypto.errors");
42 } catch (MissingResourceException e) {
43 throw new RuntimeException(e.getMessage());
44 }
45 }
46
47 /***
48 * Constructor.
49 * <p/>
50 *
51 * @param errorCode
52 * @param msgId
53 * @param root
54 */
55 public CredentialException(int errorCode, String msgId, Throwable root) {
56 this(errorCode, msgId, null, root);
57 }
58
59 /***
60 * Constructor.
61 * <p/>
62 *
63 * @param errorCode
64 * @param msgId
65 * @param args
66 */
67 public CredentialException(int errorCode, String msgId, Object[] args) {
68 this(errorCode, msgId, args, null);
69 }
70
71 /***
72 * Constructor.
73 * <p/>
74 *
75 * @param errorCode
76 * @param msgId
77 * @param args
78 * @param root
79 */
80 public CredentialException(int errorCode, String msgId, Object[] args, Throwable root) {
81 super(getMessage(msgId, args) + (root == null ? "[]" : " Inner Exception: [" + root.getMessage() + "]"));
82 this.errorCode = -1;
83 this.errorCode = errorCode;
84 }
85
86 /***
87 * get the error code.
88 * <p/>
89 *
90 * @return error code of this exception See values above.
91 */
92 public int getErrorCode() {
93 return errorCode;
94 }
95
96 /***
97 * get the actual message.
98 * <p/>
99 *
100 * @param msgId
101 * @param args
102 * @return the message translated from the property (message) file.
103 */
104 private static String getMessage(String msgId, Object[] args) {
105 try {
106 return MessageFormat.format(resources.getString(msgId), args);
107 } catch (MissingResourceException e) {
108 throw new RuntimeException("bad" + msgId);
109 }
110 }
111 }
112