1 7 8 package java.util.logging; 9 import java.util.ResourceBundle ; 10 11 43 44 public class Level implements java.io.Serializable { 45 private static java.util.ArrayList known = new java.util.ArrayList (); 46 private static String defaultBundle = "sun.util.logging.resources.logging"; 47 48 51 private final String name; 52 53 56 private final int value; 57 58 61 private final String resourceBundleName; 62 63 67 public static final Level OFF = new Level ("OFF",Integer.MAX_VALUE, defaultBundle); 68 69 78 public static final Level SEVERE = new Level ("SEVERE",1000, defaultBundle); 79 80 88 public static final Level WARNING = new Level ("WARNING", 900, defaultBundle); 89 90 99 public static final Level INFO = new Level ("INFO", 800, defaultBundle); 100 101 111 public static final Level CONFIG = new Level ("CONFIG", 700, defaultBundle); 112 113 132 public static final Level FINE = new Level ("FINE", 500, defaultBundle); 133 134 140 public static final Level FINER = new Level ("FINER", 400, defaultBundle); 141 142 146 public static final Level FINEST = new Level ("FINEST", 300, defaultBundle); 147 148 152 public static final Level ALL = new Level ("ALL", Integer.MIN_VALUE, defaultBundle); 153 154 166 protected Level(String name, int value) { 167 this(name, value, null); 168 } 169 170 181 protected Level(String name, int value, String resourceBundleName) { 182 if (name == null) { 183 throw new NullPointerException (); 184 } 185 this.name = name; 186 this.value = value; 187 this.resourceBundleName = resourceBundleName; 188 synchronized (Level .class) { 189 known.add(this); 190 } 191 } 192 193 199 public String getResourceBundleName() { 200 return resourceBundleName; 201 } 202 203 208 public String getName() { 209 return name; 210 } 211 212 221 public String getLocalizedName() { 222 try { 223 ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName); 224 return rb.getString(name); 225 } catch (Exception ex) { 226 return name; 227 } 228 } 229 230 233 public final String toString() { 234 return name; 235 } 236 237 243 public final int intValue() { 244 return value; 245 } 246 247 private static final long serialVersionUID = -8176160795706313070L; 248 249 private Object readResolve() { 252 synchronized (Level .class) { 253 for (int i = 0; i < known.size(); i++) { 254 Level other = (Level ) known.get(i); 255 if (this.name.equals(other.name) && this.value == other.value 256 && (this.resourceBundleName == other.resourceBundleName || 257 (this.resourceBundleName != null && 258 this.resourceBundleName.equals(other.resourceBundleName)))) { 259 return other; 260 } 261 } 262 known.add(this); 265 return this; 266 } 267 } 268 269 295 public static synchronized Level parse(String name) throws IllegalArgumentException { 296 name.length(); 298 299 for (int i = 0; i < known.size(); i++) { 301 Level l = (Level ) known.get(i); 302 if (name.equals(l.name)) { 303 return l; 304 } 305 } 306 307 try { 311 int x = Integer.parseInt(name); 312 for (int i = 0; i < known.size(); i++) { 313 Level l = (Level ) known.get(i); 314 if (l.value == x) { 315 return l; 316 } 317 } 318 return new Level (name, x); 320 } catch (NumberFormatException ex) { 321 } 324 325 for (int i = 0; i < known.size(); i++) { 329 Level l = (Level ) known.get(i); 330 if (name.equals(l.getLocalizedName())) { 331 return l; 332 } 333 } 334 335 throw new IllegalArgumentException ("Bad level \"" + name + "\""); 337 } 338 339 343 public boolean equals(Object ox) { 344 try { 345 Level lx = (Level )ox; 346 return (lx.value == this.value); 347 } catch (Exception ex) { 348 return false; 349 } 350 } 351 352 356 public int hashCode() { 357 return this.value; 358 } 359 } 360 | Popular Tags |