1 17 package com.sun.org.apache.xml.internal.security.exceptions; 18 19 20 21 import java.io.PrintStream ; 22 import java.io.PrintWriter ; 23 import java.text.MessageFormat ; 24 25 import com.sun.org.apache.xml.internal.security.utils.Constants; 26 import com.sun.org.apache.xml.internal.security.utils.I18n; 27 28 29 61 public class XMLSecurityException extends Exception { 62 63 64 65 68 private static final long serialVersionUID = 1L; 69 70 71 protected Exception originalException = null; 72 73 74 protected String msgID; 75 76 80 public XMLSecurityException() { 81 82 super("Missing message string"); 83 84 this.msgID = null; 85 this.originalException = null; 86 } 87 88 93 public XMLSecurityException(String _msgID) { 94 95 super(I18n.getExceptionMessage(_msgID)); 96 97 this.msgID = _msgID; 98 this.originalException = null; 99 } 100 101 107 public XMLSecurityException(String _msgID, Object exArgs[]) { 108 109 super(MessageFormat.format(I18n.getExceptionMessage(_msgID), exArgs)); 110 111 this.msgID = _msgID; 112 this.originalException = null; 113 } 114 115 120 public XMLSecurityException(Exception _originalException) { 121 122 super("Missing message ID to locate message string in resource bundle \"" 123 + Constants.exceptionMessagesResourceBundleBase 124 + "\". Original Exception was a " 125 + _originalException.getClass().getName() + " and message " 126 + _originalException.getMessage()); 127 128 this.originalException = _originalException; 129 } 130 131 137 public XMLSecurityException(String _msgID, Exception _originalException) { 138 139 super(I18n.getExceptionMessage(_msgID, _originalException)); 140 141 this.msgID = _msgID; 142 this.originalException = _originalException; 143 } 144 145 152 public XMLSecurityException(String _msgID, Object exArgs[], 153 Exception _originalException) { 154 155 super(MessageFormat.format(I18n.getExceptionMessage(_msgID), exArgs)); 156 157 this.msgID = _msgID; 158 this.originalException = _originalException; 159 } 160 161 166 public String getMsgID() { 167 168 if (msgID == null) { 169 return "Missing message ID"; 170 } 171 return msgID; 172 } 173 174 175 public String toString() { 176 177 String s = this.getClass().getName(); 178 String message = super.getLocalizedMessage(); 179 180 if (message != null) { 181 message = s + ": " + message; 182 } else { 183 message = s; 184 } 185 186 if (originalException != null) { 187 message = message + "\nOriginal Exception was " 188 + originalException.toString(); 189 } 190 191 return message; 192 } 193 194 198 public void printStackTrace() { 199 200 synchronized (System.err) { 201 super.printStackTrace(System.err); 202 203 if (this.originalException != null) { 204 this.originalException.printStackTrace(System.err); 205 } 206 } 207 } 208 209 214 public void printStackTrace(PrintWriter printwriter) { 215 216 super.printStackTrace(printwriter); 217 218 if (this.originalException != null) { 219 this.originalException.printStackTrace(printwriter); 220 } 221 } 222 223 228 public void printStackTrace(PrintStream printstream) { 229 230 super.printStackTrace(printstream); 231 232 if (this.originalException != null) { 233 this.originalException.printStackTrace(printstream); 234 } 235 } 236 237 242 public Exception getOriginalException() { 243 return originalException; 244 } 245 } 246 | Popular Tags |