1 21 22 package com.izforge.izpack.util.os; 23 24 import com.coi.tools.os.win.NativeLibException; 25 import com.izforge.izpack.LocaleDatabase; 26 27 36 public class WrappedNativeLibException extends Exception 37 { 38 39 private static final long serialVersionUID = 3257562893309720112L; 40 41 42 protected static LocaleDatabase langpack = null; 43 44 47 public WrappedNativeLibException() 48 { 49 super(); 50 } 51 52 55 public WrappedNativeLibException(String message) 56 { 57 super(message); 58 } 59 60 63 public WrappedNativeLibException(Throwable cause) 64 { 65 super(cause); 66 } 67 68 72 public WrappedNativeLibException(String message, Throwable cause) 73 { 74 super(message, cause); 75 } 76 77 82 public String getMessage() 83 { 84 StringBuffer retval = new StringBuffer (); 85 boolean next = false; 86 boolean ok = false; 87 if (getCause() instanceof NativeLibException) 88 { 89 NativeLibException nle = (NativeLibException) getCause(); 90 if (langpack != null) 91 { 92 while (true) 93 { 94 if (nle.getLibMessage() != null) 95 { 96 String val = (String ) langpack.get("NativeLibException." 97 + nle.getLibMessage()); 98 if (val == null) break; 99 retval.append(val); 100 next = true; 101 } 102 else if (nle.getLibErr() != 0) 103 { 104 String val = (String ) langpack.get("NativeLibException.libErrNumber." 105 + Integer.toString(nle.getLibErr())); 106 if (val == null) break; 107 if (next) retval.append("\n"); 108 next = true; 109 retval.append(val); 110 } 111 if (nle.getOsErr() != 0) 112 { 113 String val = (String ) langpack 114 .get("NativeLibException.libInternal.OsErrNumPraefix") 115 + Integer.toString(nle.getOsErr()); 116 if (val == null) break; 117 if (next) retval.append("\n"); 118 next = true; 119 retval.append(val); 120 } 121 if (nle.getOsMessage() != null) 122 { 123 String val = (String ) langpack 124 .get("NativeLibException.libInternal.OsErrStringPraefix") 125 + nle.getOsMessage(); 126 if (val == null) break; 127 if (next) retval.append("\n"); 128 next = true; 129 retval.append(val); 130 } 131 ok = true; 132 break; 133 } 134 } 135 if (ok && retval.length() > 0) 136 return (nle.reviseMsgWithArgs(retval.toString())); 137 else 138 return (nle.getMessage()); 139 140 } 141 else 142 return (super.getMessage()); 143 } 144 145 150 public static LocaleDatabase getLangpack() 151 { 152 return langpack; 153 } 154 155 160 public static void setLangpack(LocaleDatabase langpack) 161 { 162 WrappedNativeLibException.langpack = langpack; 163 } 164 } 165 | Popular Tags |