374 checkPermission(); 375 if (l != null) { 376 PropertyChangeListener listener = l; 377 synchronized (listenerMap) { 378 Integer value = listenerMap.get(listener); 379 if (value != null) { 380 // remove from map if registration count is 1, otherwise 381 // just decrement its count 382 int i = value.intValue(); 383 if (i == 1) { 384 listenerMap.remove(listener); 385 } else { 386 assert i > 1; 387 listenerMap.put(listener, i - 1); 388 } 389 } 390 } 391 } 392 } 393 394 // Returns the LoggerContext for the user code (i.e. application or AppContext). 395 // Loggers are isolated from each AppContext. 396 private LoggerContext getUserContext() { 397 LoggerContext context = null; 398 399 SecurityManager sm = System.getSecurityManager(); 400 JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess(); 401 if (sm != null && javaAwtAccess != null) { 402 synchronized (javaAwtAccess) { 403 // AppContext.getAppContext() returns the system AppContext if called 404 // from a system thread but Logger.getLogger might be called from 405 // an applet code. Instead, find the AppContext of the applet code 406 // from the execution stack. 407 Object ecx = javaAwtAccess.getExecutionContext(); 408 if (ecx == null) { 409 // fall back to thread group seach of AppContext 410 ecx = javaAwtAccess.getContext(); 411 } 412 if (ecx != null) { 413 context = (LoggerContext)javaAwtAccess.get(ecx, LoggerContext.class); 414 if (context == null) { 415 if (javaAwtAccess.isMainAppContext()) { 416 context = userContext; 417 } else { 418 // Create a new LoggerContext for the applet. 419 // The new logger context has its requiresDefaultLoggers 420 // flag set to true - so that these loggers will be 421 // lazily added when the context is firt accessed. 422 context = new LoggerContext(true); 423 } 424 javaAwtAccess.put(ecx, LoggerContext.class, context); 425 } 426 } 427 } 428 } 429 return context != null ? context : userContext; 430 } 431 432 private List<LoggerContext> contexts() { 433 List<LoggerContext> cxs = new ArrayList<>(); 434 cxs.add(systemContext); 435 cxs.add(getUserContext()); 436 return cxs; 437 } 438 439 // Find or create a specified logger instance. If a logger has 440 // already been created with the given name it is returned. 441 // Otherwise a new logger instance is created and registered 442 // in the LogManager global namespace. 443 // This method will always return a non-null Logger object. 444 // Synchronization is not required here. All synchronization for 445 // adding a new Logger object is handled by addLogger(). 446 // 447 // This method must delegate to the LogManager implementation to 448 // add a new Logger or return the one that has been added previously | 374 checkPermission(); 375 if (l != null) { 376 PropertyChangeListener listener = l; 377 synchronized (listenerMap) { 378 Integer value = listenerMap.get(listener); 379 if (value != null) { 380 // remove from map if registration count is 1, otherwise 381 // just decrement its count 382 int i = value.intValue(); 383 if (i == 1) { 384 listenerMap.remove(listener); 385 } else { 386 assert i > 1; 387 listenerMap.put(listener, i - 1); 388 } 389 } 390 } 391 } 392 } 393 394 // LoggerContext maps from AppContext 395 private static WeakHashMap<Object, LoggerContext> contextsMap = null; 396 397 // Returns the LoggerContext for the user code (i.e. application or AppContext). 398 // Loggers are isolated from each AppContext. 399 private LoggerContext getUserContext() { 400 LoggerContext context = null; 401 402 SecurityManager sm = System.getSecurityManager(); 403 JavaAWTAccess javaAwtAccess = SharedSecrets.getJavaAWTAccess(); 404 if (sm != null && javaAwtAccess != null) { 405 // for each applet, it has its own LoggerContext isolated from others 406 synchronized (javaAwtAccess) { 407 // find the AppContext of the applet code 408 // will be null if we are in the main app context. 409 final Object ecx = javaAwtAccess.getAppletContext(); 410 if (ecx != null) { 411 if (contextsMap == null) { 412 contextsMap = new WeakHashMap<>(); 413 } 414 context = contextsMap.get(ecx); 415 if (context == null) { 416 // Create a new LoggerContext for the applet. 417 // The new logger context has its requiresDefaultLoggers 418 // flag set to true - so that these loggers will be 419 // lazily added when the context is firt accessed. 420 context = new LoggerContext(true); 421 contextsMap.put(ecx, context); 422 } 423 } 424 } 425 } 426 // for standalone app, return userContext 427 return context != null ? context : userContext; 428 } 429 430 private List<LoggerContext> contexts() { 431 List<LoggerContext> cxs = new ArrayList<>(); 432 cxs.add(systemContext); 433 cxs.add(getUserContext()); 434 return cxs; 435 } 436 437 // Find or create a specified logger instance. If a logger has 438 // already been created with the given name it is returned. 439 // Otherwise a new logger instance is created and registered 440 // in the LogManager global namespace. 441 // This method will always return a non-null Logger object. 442 // Synchronization is not required here. All synchronization for 443 // adding a new Logger object is handled by addLogger(). 444 // 445 // This method must delegate to the LogManager implementation to 446 // add a new Logger or return the one that has been added previously |