1 package org.tigris.scarab.util; 2 3 48 49 import org.tigris.scarab.tools.ScarabLocalizationTool; 51 import org.tigris.scarab.tools.localization.L10NMessage; 52 import org.tigris.scarab.tools.localization.LocalizationKey; 53 import org.tigris.scarab.tools.localization.Localizable; 54 55 65 public class ScarabRuntimeException extends RuntimeException implements Localizable 66 { 67 71 Localizable l10nMessage; 72 73 76 Throwable nested; 77 78 83 public ScarabRuntimeException(LocalizationKey theKey) 84 { 85 l10nMessage = new L10NMessage(theKey); 86 nested = null; 87 } 88 89 95 public ScarabRuntimeException(LocalizationKey theKey, Throwable aNested) 96 { 97 super(); 98 l10nMessage = new L10NMessage(theKey, nested); 99 nested = aNested; 100 } 101 102 103 108 public ScarabRuntimeException(Localizable theL10nInstance) 109 { 110 l10nMessage = theL10nInstance; 111 nested = null; 112 } 113 114 120 public ScarabRuntimeException(Localizable theL10nInstance, Throwable aNested) 121 { 122 super(); 123 l10nMessage = theL10nInstance; 124 nested = aNested; 125 } 126 127 128 134 public ScarabRuntimeException (LocalizationKey theKey, Object [] theParams) 135 { 136 l10nMessage = new L10NMessage(theKey, theParams); 137 nested = null; 138 } 139 140 146 public ScarabRuntimeException (LocalizationKey theKey, Object p1) 147 { 148 this(theKey, new Object [] {p1}); 149 } 150 151 158 public ScarabRuntimeException (LocalizationKey theKey, Object p1, Object p2) 159 { 160 this(theKey, new Object [] {p1, p2}); 161 } 162 163 171 public ScarabRuntimeException (LocalizationKey theKey, Object p1, Object p2, Object p3) 172 { 173 this(theKey, new Object [] {p1, p2, p3}); 174 } 175 176 177 185 public ScarabRuntimeException (LocalizationKey theKey, Throwable nested, Object [] theParams) 186 { 187 this(new L10NMessage(theKey, theParams),nested); 188 } 189 190 197 public ScarabRuntimeException (LocalizationKey theKey, Throwable nested, Object p1) 198 { 199 this(new L10NMessage(theKey, p1),nested); 200 } 201 202 210 public ScarabRuntimeException (LocalizationKey theKey, Throwable nested, Object p1, Object p2) 211 { 212 this(new L10NMessage(theKey, p1, p2),nested); 213 } 214 215 224 public ScarabRuntimeException (LocalizationKey theKey, Throwable nested, Object p1, Object p2, Object p3) 225 { 226 this(new L10NMessage(theKey, p1, p2, p3),nested); 227 } 228 229 233 public Localizable getL10nMessage() 234 { 235 return l10nMessage; 236 } 237 238 246 public String getMessage(ScarabLocalizationTool l10n) 247 { 248 String result; 249 if (l10nMessage == null) 250 { 251 if (nested == null) 252 { 253 result = super.getMessage(); 254 } 255 else 256 { 257 if ( nested instanceof ScarabRuntimeException ) 258 { 259 result = ((ScarabRuntimeException)nested).getMessage(l10n); 260 } 261 else if ( nested instanceof ScarabException ) 262 { 263 result = ((ScarabException)nested).getMessage(l10n); 264 } 265 else 266 { 267 result = nested.getMessage(); 268 } 269 } 270 } 271 else 272 { 273 result = l10nMessage.getMessage(l10n); 274 } 275 return result; 276 } 277 278 285 public String getMessage() 286 { 287 String result; 288 if (l10nMessage == null) 289 { 290 if (nested == null) 291 { 292 result = super.getMessage(); 293 } 294 else 295 { 296 result = nested.getMessage(); 297 } 298 } 299 else 300 { 301 result = l10nMessage.toString(); 302 } 303 return result; 304 } 305 306 } 307 | Popular Tags |