1 7 8 9 package org.enhydra.oyster.exception; 10 11 import java.io.*; 12 import java.util.Date ; 13 import java.text.SimpleDateFormat ; 14 15 import javax.crypto.BadPaddingException; 16 import javax.crypto.IllegalBlockSizeException; 17 import javax.crypto.NoSuchPaddingException; 18 import java.security.NoSuchProviderException ; 19 import java.security.NoSuchAlgorithmException ; 20 import java.security.InvalidKeyException ; 21 import java.security.cert.CertificateException ; 22 import java.security.UnrecoverableKeyException ; 23 import java.security.KeyStoreException ; 24 import java.net.UnknownHostException ; 25 import java.io.FileNotFoundException ; 26 import java.security.SignatureException ; 27 import java.security.cert.CertificateEncodingException ; 28 29 44 public class SMIMEException extends Exception { 45 46 49 private String className; 50 51 54 public static final String errorFileName = "SMIMEerr.log"; 55 56 59 private static String errorFilePath = ""; 60 61 65 private Exception foreignExc = null; 66 67 70 private String exceptionName = "org.enhydra.oyster.exception.SMIMEException"; 71 72 78 public SMIMEException (Object obj0, String text0) { 79 super(text0); 80 if (obj0 instanceof String ) 81 className = (String )obj0; 82 else 83 className = obj0.getClass().getName(); 84 } 85 86 93 public SMIMEException (Object obj0, int errNumb0) { 94 this(obj0, ErrorStorage.getErrorMesage(errNumb0)); 95 } 96 97 137 public static SMIMEException getInstance(Object obj0, Exception e0, String method0) { 138 139 String excType = "java.lang.Exception"; 140 String name = null; 141 if (obj0 instanceof String ) 142 name = (String )obj0; 143 else 144 name = obj0.getClass().getName(); 145 146 if(e0 instanceof java.io.UnsupportedEncodingException ) 147 excType = "java.io.UnsupportedEncodingException"; 148 else if (e0 instanceof java.security.cert.CertificateEncodingException ) 149 excType = "java.security.cert.CertificateEncodingException"; 150 else if (e0 instanceof java.lang.IndexOutOfBoundsException ) 151 excType = "java.lang.IndexOutOfBoundsException"; 152 else if (e0 instanceof java.lang.NullPointerException ) 153 excType = "java.lang.NullPointerException"; 154 else if (e0 instanceof javax.crypto.NoSuchPaddingException) 155 excType = "javax.crypto.NoSuchPaddingException"; 156 else if (e0 instanceof java.security.SignatureException ) 157 excType = "java.security.SignatureException"; 158 else if (e0 instanceof java.security.NoSuchProviderException ) 159 excType = "java.security.NoSuchProviderException"; 160 else if (e0 instanceof java.security.NoSuchAlgorithmException ) 161 excType = "java.security.NoSuchAlgorithmException"; 162 else if (e0 instanceof java.security.InvalidKeyException ) 163 excType = "java.security.InvalidKeyException"; 164 else if (e0 instanceof javax.crypto.BadPaddingException) 165 excType = "javax.crypto.BadPaddingException"; 166 else if (e0 instanceof javax.crypto.IllegalBlockSizeException) 167 excType = "javax.crypto.IllegalBlockSizeException"; 168 else if (e0 instanceof java.security.KeyStoreException ) 169 excType = "java.security.KeyStoreException"; 170 else if (e0 instanceof java.security.UnrecoverableKeyException ) 171 excType = "java.security.UnrecoverableKeyException"; 172 else if (e0 instanceof java.net.UnknownHostException ) 173 excType = "java.net.UnknownHostException"; 174 else if (e0 instanceof java.io.FileNotFoundException ) 175 excType = "java.io.FileNotFoundException"; 176 else if (e0 instanceof java.lang.NumberFormatException ) 177 excType = "java.lang.NumberFormatException"; 178 else if (e0 instanceof java.security.cert.CertificateException ) 179 excType = "java.security.cert.CertificateException"; 180 else if (e0 instanceof org.enhydra.oyster.exception.SMIMEIOException) 181 return ((SMIMEIOException)e0).getSMIMEException(); 182 else if (e0 instanceof javax.mail.MessagingException ) 183 excType = "javax.mail.MessagingException"; 184 else if (e0 instanceof java.io.IOException ) 185 excType = "java.io.IOException"; 186 else if (e0 instanceof org.enhydra.oyster.exception.SMIMEException) 187 return (SMIMEException)e0; 188 189 if (method0 == null) 190 method0 = "unknown"; 191 192 String err = ErrorStorage.getErrorMesage(1999) + 193 System.getProperty("line.separator") + 194 e0.getMessage() + 195 System.getProperty("line.separator") + 196 excType + " captured in " + method0 + " method of " + 197 name + " class and thrown as SMIMEException."; 198 SMIMEException es = new SMIMEException(name, err); 199 es.addNonSMIMEException(e0, excType); 200 return es; 201 } 202 203 207 public String getClassOfException () { 208 return className; 209 } 210 211 216 public String getInformation () { 217 return super.getMessage() + System.getProperty("line.separator") + 218 "SMIMEException rised in instance of the class: " + className; 219 } 220 221 226 public static void setErrorFilePath(String path0) { 227 if(path0!=null & !path0.equalsIgnoreCase("")){ 228 errorFilePath = new String (path0); 229 if (errorFilePath.charAt(errorFilePath.length()-1) == File.separatorChar) 230 errorFilePath.substring(0, errorFilePath.length()-1); 231 } 232 } 233 234 238 public static String getErrorFilePath(String path0) { 239 return errorFilePath; 240 } 241 242 247 public void displayErrors(String errorText0) { 248 249 if ( errorText0 == null || errorText0.equalsIgnoreCase("") ) 250 System.out.println(this.getInformation()); 251 else 252 System.out.println(errorText0); 253 } 254 255 261 public void loggingErrors(String errorText0) { 262 263 File logDir = new File(errorFilePath); 264 if ( !(logDir.isFile() | logDir.isDirectory()) ) 265 logDir.mkdirs(); 266 267 File logFile = new File(logDir, errorFileName); 268 269 PrintWriter outData = null; 270 try { 271 outData = new PrintWriter( new BufferedWriter( new FileWriter( 272 logFile.getAbsolutePath(),true ) ) ); 273 274 Date dat = new Date (System.currentTimeMillis()); 275 SimpleDateFormat datForm = new SimpleDateFormat ("dd.MM.yyyy. HH:mm:ss"); 276 outData.println( "-----> " + datForm.format(dat) + 277 " <-----------------------------------------------------------------" ); 278 outData.flush(); 279 280 if ( errorText0 == null || errorText0.equalsIgnoreCase("") ) 281 outData.println(this.getInformation()); 282 else 283 outData.println(errorText0); 284 outData.flush(); 285 } 286 catch(FileNotFoundException e){ 287 System.err.println( e.getMessage() ); 288 outData.close(); 289 } 290 catch(IOException e){ 291 System.err.println( e.getMessage() ); 292 outData.close(); 293 } 294 outData.close(); 295 } 296 297 298 306 public void addNonSMIMEException(Exception exception0 , String exceptionName0) { 307 exceptionName = new String (exceptionName0); 308 foreignExc = exception0; 309 } 310 311 319 public Exception getNonSMIMEException() { 320 return foreignExc; 321 } 322 323 328 public String getNonSMIMEExceptionName() { 329 return exceptionName; 330 } 331 332 } 333 334 335 336 | Popular Tags |