1 /* 2 Copyright (C) 2000 - 2007 Grid Systems, S.A. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2, as 6 published by the Free Software Foundation. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 package com.gridsystems.innergrid.api; 18 19 import java.util.ResourceBundle; 20 21 import com.gridsystems.innergrid.kernel.KernelException; 22 23 /** 24 * KernelException that takes care of some codes that can 25 * only appear on the client side. 26 * <p> 27 * The following is a list of the client-side known codes and their meanings: 28 * <ul> 29 * <li><code>UNK000</code> Unknown Error 30 * <li><code>CLT000</code> Cannot connect to the Server 31 * <li><code>CLT001</code> Connection refused. Remote port is not open. 32 * <li><code>CLT002</code> Connection closed by Server 33 * <li><code>CLT003</code> Service not found in Server. 34 * <li><code>CLT004</code> Bean cannot be serialized by the Server. 35 * <li><code>CLT005</code> Bean used as a parameter could not be deserialized by the 36 * Server 37 * <li><code>CLT006</code> Could not find the SOAP servlet in the remote Server; it may 38 * not be an appropriate Server. 39 * <li><code>CLT007</code> Unknown client error 40 * <li><code>CLT008</code> Malformed URL 41 * <li><code>CLT009</code> Unknown error parsing response 42 * <li><code>CLT011</code> Null connection 43 * <li><code>CLT012</code> Null host 44 * <li><code>CLT013</code> Invalid port (negative or zero) 45 * <li><code>CLT014</code> A default connection must be defined, using 46 * <code>ConnectionProvider.setDefaultConnection()</code> 47 * <li><code>CLT015</code> Interface implementation not found 48 * <li><code>CLT016</code> The method cannot be called statically. You need to instantiate 49 * the class 50 * <li><code>CLT017</code> Connection parameter expected 51 * <li><code>CLT020</code> Attachment filename is not valid 52 * <li><code>CLT021</code> Attached file not found 53 * <li><code>CLT031</code> Certificate verification failed 54 * <li><code>CLT030</code> CA file cannot be read 55 * <li><code>CLT032</code> Keystore file cannot be read 56 * <li><code>CLT033</code> Keystore file is not valid, or the password is incorrect 57 * <li><code>CLT040</code> Method <code>initialize(...)</code> must be called to define 58 * the connection parameters 59 * <li><code>CLT041</code> Method <code>setConnection(conn)</code> must be called to 60 * define a connection for this API 61 * <li><code>CLT042</code> Method <code>initialize(...)</code> cannot be called twice 62 * <li><code>CLT050</code> The active Server is down. Wait a few minutes for a backup 63 * Server to become active, and try again. 64 * <li><code>CLT060</code> Port not answering; it could not be checked 65 * <li><code>CLT061</code> Incorrect protocol 66 * <li><code>CLT062</code> Cannot check port because a proper URL could not be created 67 * <li><code>CLT063</code> SSL Handshake Exception 68 * </ul> 69 * 70 * @author Rodrigo Ruiz 71 * @version 1.0 72 */ 73 public class CKernelException extends KernelException { 74 75 /** 76 * Serial Version UID. 77 */ 78 private static final long serialVersionUID = 18765876580897L; 79 80 /** Resource Bundle for translations. */ 81 private static ResourceBundle translations = 82 ResourceBundle.getBundle("clienterrors"); 83 84 /** 85 * Creates a new instance without parameters and cause. 86 * 87 * @param code a string with the error code 88 */ 89 public CKernelException(String code) { 90 super(null, code, getTranslation(code)); 91 } 92 93 /** 94 * Creates a new instance. 95 * 96 * @param code a string with the error code 97 * @param cause a string with the error cause 98 * @deprecated Use {@link #CKernelException(Throwable, String, String...)} instead 99 */ 100 public CKernelException(String code, Throwable cause) { 101 super(cause, code, getTranslation(code)); 102 } 103 104 105 /** 106 * Creates a new instance without cause. 107 * 108 * @param code a string with the error code 109 * @param params an array of string with the message parameters 110 */ 111 public CKernelException(String code, String... params) { 112 super(null, code, getTranslation(code), (Object[])params); 113 } 114 115 /** 116 * Creates a new instance. 117 * 118 * @param code a string with the error code 119 * @param params an array of string with the message parameters 120 * @param cause a string with the error cause 121 * @deprecated Use {@link #CKernelException(Throwable, String, String...)} instead 122 */ 123 public CKernelException(String code, String[] params, Throwable cause) { 124 super(cause, code, getTranslation(code), (Object[])params); 125 } 126 127 /** 128 * Creates a new instance. 129 * 130 * @param cause a string with the error cause 131 * @param code a string with the error code 132 * @param params an array of string with the message parameters 133 */ 134 public CKernelException(Throwable cause, String code, String... params) { 135 super(cause, code, getTranslation(code), (Object[])params); 136 } 137 138 /** 139 * Gets the translation for the specified error code. 140 * 141 * @param errorCode the code of the error 142 * @return the message for the error code 143 */ 144 private static String getTranslation(String errorCode) { 145 String msg = "Translation not found for " + errorCode + " error code."; 146 if (translations == null) { 147 return msg; 148 } 149 String trans; 150 151 try { 152 trans = (String)translations.getString(errorCode); 153 } catch (Exception e) { 154 //e.printStackTrace(); 155 return (msg); 156 } 157 return trans; 158 } 159 }