1 7 8 9 package java.util.logging; 10 11 29 30 public abstract class Handler { 31 private static final int offValue = Level.OFF.intValue(); 32 private LogManager manager = LogManager.getLogManager(); 33 private Filter filter; 34 private Formatter formatter; 35 private Level logLevel = Level.ALL; 36 private ErrorManager errorManager = new ErrorManager (); 37 private String encoding; 38 39 boolean sealed = true; 42 43 49 protected Handler() { 50 } 51 52 64 public abstract void publish(LogRecord record); 65 66 69 public abstract void flush(); 70 71 82 public abstract void close() throws SecurityException ; 83 84 95 public void setFormatter(Formatter newFormatter) throws SecurityException { 96 checkAccess(); 97 newFormatter.getClass(); 99 formatter = newFormatter; 100 } 101 102 106 public Formatter getFormatter() { 107 return formatter; 108 } 109 110 123 public void setEncoding(String encoding) 124 throws SecurityException , java.io.UnsupportedEncodingException { 125 checkAccess(); 126 if (encoding != null) { 127 sun.io.CharToByteConverter.getConverter(encoding); 129 } 130 this.encoding = encoding; 131 } 132 133 139 public String getEncoding() { 140 return encoding; 141 } 142 143 154 public void setFilter(Filter newFilter) throws SecurityException { 155 checkAccess(); 156 filter = newFilter; 157 } 158 159 164 public Filter getFilter() { 165 return filter; 166 } 167 168 178 public void setErrorManager(ErrorManager em) { 179 checkAccess(); 180 if (em == null) { 181 throw new NullPointerException (); 182 } 183 errorManager = em; 184 } 185 186 192 public ErrorManager getErrorManager() { 193 checkAccess(); 194 return errorManager; 195 } 196 197 207 protected void reportError(String msg, Exception ex, int code) { 208 try { 209 errorManager.error(msg, ex, code); 210 } catch (Exception ex2) { 211 System.err.println("Handler.reportError caught:"); 212 ex2.printStackTrace(); 213 } 214 } 215 216 229 public synchronized void setLevel(Level newLevel) throws SecurityException { 230 if (newLevel == null) { 231 throw new NullPointerException (); 232 } 233 checkAccess(); 234 logLevel = newLevel; 235 } 236 237 243 public synchronized Level getLevel() { 244 return logLevel; 245 } 246 247 260 public boolean isLoggable(LogRecord record) { 261 int levelValue = getLevel().intValue(); 262 if (record.getLevel().intValue() < levelValue || levelValue == offValue) { 263 return false; 264 } 265 Filter filter = getFilter(); 266 if (filter == null) { 267 return true; 268 } 269 return filter.isLoggable(record); 270 } 271 272 void checkAccess() throws SecurityException { 277 if (sealed) { 278 manager.checkAccess(); 279 } 280 } 281 } 282 | Popular Tags |