1 23 24 29 30 package com.sun.enterprise.util.io; 31 import java.util.*; 32 import java.util.logging.*; 33 import com.sun.enterprise.util.OS; 34 35 40 41 class NativeResults 42 { 43 NativeResults(int id) 44 { 45 this.id = id; 46 initStrings(); 47 setResultString(); 48 setResultException(); 49 } 50 51 54 String getResultString() 55 { 56 return resultString; 57 } 58 59 62 NativeIOException getResultException() 63 { 64 return exception; } 66 67 69 private void setResultString() 70 { 71 if(rb == null) 72 { 73 resultString = genericError + id; 74 return; 75 } 76 77 try 78 { 79 resultString = rb.getString(errorKey + id); 80 return; 81 } 82 catch(Throwable t) 83 { 84 } 86 87 try 88 { 89 resultString = rb.getString(unknownErrorKey) + id; 91 return; 92 } 93 catch(Throwable t) 94 { 95 resultString = genericError + id; 96 } 97 } 98 99 101 void setResultException() 102 { 103 if(id != 0) exception = new NativeIOException(resultString, id); 105 } 106 107 109 private void initStrings() 110 { 111 try 112 { 113 rb = ResourceBundle.getBundle(RESOURCE_BUNDLE); 114 } 115 catch(Throwable t) 116 { 117 rb = null; 119 logger.severe("Unable to get a ResourceBundle: " + RESOURCE_BUNDLE); 120 } 121 122 if(OS.isWindows()) 123 osString = "Windows"; 124 else 125 osString = "UNIX"; 126 127 errorKey = "enterprise_util." + osString + ".error."; 128 unknownErrorKey = errorKey + "unknown"; 129 genericError = "UNKNOWN " + osString + " Error returned. Errno ="; 130 } 131 132 134 private Logger logger = IOLogger.getLogger(); 135 private ResourceBundle rb = null; 136 private static final String RESOURCE_BUNDLE = "com.sun.logging.enterprise.system.util.LogStrings"; 137 private String errorKey; private String unknownErrorKey; private String genericError; private String osString; private int id; private String resultString; 143 private NativeIOException exception = null; 144 145 147 public static void main(String [] args) 148 { 149 int errs[] = { 0, 1, 2, 4, 5, 13, 14, 20, 22, 30, 67, 78, 9999, 111, -2}; 150 151 for(int i = 0; i < errs.length; i++) 152 { 153 int id = errs[i]; 154 155 NativeResults nr = new NativeResults(id); 156 String s = "ID: " + id + ", "; 157 158 if(nr.getResultException() == null) 159 s += "NO ERROR, "; 160 else 161 s += "YES ERROR, "; 162 163 s += nr.getResultString(); 164 165 System.out.println(s); 166 } 167 } 168 } 169 170 | Popular Tags |