1 22 package org.netbeans.lib.cvsclient.command; 23 24 import java.io.*; 25 import java.text.*; 26 import java.util.*; 27 28 import org.netbeans.lib.cvsclient.util.*; 29 30 35 public class CommandException extends Exception { 36 private Exception underlyingException; 37 private String localizedMessage; 38 private String message; 39 40 public CommandException(Exception underlyingException, String localizedMessage) { 41 this.underlyingException = underlyingException; 42 this.localizedMessage = localizedMessage; 43 } 44 45 public CommandException(String message, String localizedMessage) { 46 super(message); 47 this.message = message; 48 this.localizedMessage = localizedMessage; 49 } 50 51 public Exception getUnderlyingException() { 52 return underlyingException; 53 } 54 55 public void printStackTrace() { 56 if (underlyingException != null) { 57 underlyingException.printStackTrace(); 58 } 59 else { 60 super.printStackTrace(); 61 } 62 } 63 64 public void printStackTrace(PrintStream stream) { 65 if (underlyingException != null) { 66 underlyingException.printStackTrace(stream); 67 } 68 else { 69 super.printStackTrace(stream); 70 } 71 } 72 73 public void printStackTrace(PrintWriter writer) { 74 if (underlyingException != null) { 75 underlyingException.printStackTrace(writer); 76 } 77 else { 78 super.printStackTrace(writer); 79 } 80 } 81 82 public String getLocalizedMessage() { 83 if (localizedMessage == null) { 84 return message; 85 } 86 return localizedMessage; 87 } 88 89 public String getMessage() { 90 if (message == null) { 91 return localizedMessage; 92 } 93 return message; 94 } 95 96 protected static String getBundleString(String key) { 97 String value = null; 98 try { 99 ResourceBundle bundle = BundleUtilities.getResourceBundle(CommandException.class, "Bundle"); if (bundle != null) { 101 value = bundle.getString(key); 102 } 103 } 104 catch (MissingResourceException exc) { 105 } 106 return value; 107 } 108 109 public static String getLocalMessage(String key) { 110 return getLocalMessage(key, null); 111 } 112 113 public static String getLocalMessage(String key, Object [] arguments) { 114 String locMessage = CommandException.getBundleString(key); 115 if (locMessage == null) { 116 return null; 117 } 118 if (arguments != null) { 119 locMessage = MessageFormat.format(locMessage, arguments); 120 } 121 return locMessage; 122 } 123 } 124 | Popular Tags |