| 1 |
/* |
| 2 |
* Copyright 1999-2010 University of Chicago |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 11 |
* express or implied. |
| 12 |
* |
| 13 |
* See the License for the specific language governing permissions and limitations under the License. |
| 14 |
*/ |
| 15 |
package org.globus.gsi; |
| 16 |
|
| 17 |
import java.text.MessageFormat; |
| 18 |
import java.util.ResourceBundle; |
| 19 |
import java.util.MissingResourceException; |
| 20 |
|
| 21 |
/** |
| 22 |
* Encapsulates the exceptions caused |
| 23 |
* by various errors in/problems with Globus proxies. |
| 24 |
*/ |
| 25 |
public class GlobusCredentialException extends Exception { |
| 26 |
|
| 27 |
public static final int FAILURE = -1; |
| 28 |
public static final int EXPIRED = 1; |
| 29 |
public static final int DEFECTIVE = 2; |
| 30 |
public static final int IO_ERROR = 3; |
| 31 |
public static final int SEC_ERROR = 3; |
| 32 |
|
| 33 |
private static ResourceBundle resources; |
| 34 |
|
| 35 |
static { |
| 36 |
try { |
| 37 |
resources = ResourceBundle.getBundle("org.globus.gsi.errors"); |
| 38 |
} catch (MissingResourceException e) { |
| 39 |
throw new RuntimeException(e.getMessage()); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
private int errorCode = FAILURE; |
| 44 |
|
| 45 |
public GlobusCredentialException(int errorCode, |
| 46 |
String msgId, |
| 47 |
Throwable root) { |
| 48 |
this(errorCode, msgId, null, root); |
| 49 |
} |
| 50 |
|
| 51 |
public GlobusCredentialException(int errorCode, |
| 52 |
String msgId, |
| 53 |
Object [] args) { |
| 54 |
this(errorCode, msgId, args, null); |
| 55 |
} |
| 56 |
|
| 57 |
public GlobusCredentialException(int errorCode, |
| 58 |
String msgId, |
| 59 |
Object [] args, |
| 60 |
Throwable root) { |
| 61 |
super(getMessage(msgId, args), root); |
| 62 |
this.errorCode = errorCode; |
| 63 |
} |
| 64 |
|
| 65 |
public int getErrorCode() { |
| 66 |
return this.errorCode; |
| 67 |
} |
| 68 |
|
| 69 |
private static String getMessage(String msgId, Object[] args) { |
| 70 |
try { |
| 71 |
return MessageFormat.format(resources.getString(msgId), args); |
| 72 |
} catch (MissingResourceException e) { |
| 73 |
throw new RuntimeException(msgId); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
} |