jdk/src/share/classes/sun/awt/AppContext.java

Print this page
rev 5709 : 6664509: Add logging context
6664528: Find log level matching its name or value given at construction time
Reviewed-by: alanb, ahgross, jgish, hawtin


 310                     // all the intermediate ThreadGroups to threadGroup2appContext
 311                     // so we won't spin again.
 312                     for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
 313                         threadGroup2appContext.put(tg, context);
 314                     }
 315                     // Now we're done, so we cache the latest key/value pair.
 316                     // (we do this before checking with any AWTSecurityManager, so if
 317                     // this Thread equates with the main AppContext in the cache, it
 318                     // still will)
 319                     threadAppContext.set(context);
 320 
 321                     return context;
 322                 }
 323             });
 324         }
 325 
 326         if (appContext == mainAppContext)  {
 327             // Before we return the main "system" AppContext, check to
 328             // see if there's an AWTSecurityManager installed.  If so,
 329             // allow it to choose the AppContext to return.
 330             SecurityManager securityManager = System.getSecurityManager();
 331             if ((securityManager != null) &&
 332                 (securityManager instanceof AWTSecurityManager))
 333             {
 334                 AWTSecurityManager awtSecMgr = (AWTSecurityManager)securityManager;
 335                 AppContext secAppContext = awtSecMgr.getAppContext();
 336                 if (secAppContext != null)  {
 337                     appContext = secAppContext; // Return what we're told
 338                 }
 339             }
 340         }
 341 
 342         return appContext;
 343     }
 344 












 345     /**
 346      * Returns the main ("system") AppContext.
 347      *
 348      * @return  the main AppContext
 349      * @since   1.8
 350      */
 351     final static AppContext getMainAppContext() {
 352         return mainAppContext;
 353     }
 354 
 355     private long DISPOSAL_TIMEOUT = 5000;  // Default to 5-second timeout
 356                                            // for disposal of all Frames
 357                                            // (we wait for this time twice,
 358                                            // once for dispose(), and once
 359                                            // to clear the EventQueue).
 360 
 361     private long THREAD_INTERRUPT_TIMEOUT = 1000;
 362                             // Default to 1-second timeout for all
 363                             // interrupted Threads to exit, and another
 364                             // 1 second for all stopped Threads to die.


 788         return changeSupport.getPropertyChangeListeners(propertyName);
 789     }
 790 
 791     // Set up JavaAWTAccess in SharedSecrets
 792     static {
 793         sun.misc.SharedSecrets.setJavaAWTAccess(new sun.misc.JavaAWTAccess() {
 794             public Object get(Object key) {
 795                 return getAppContext().get(key);
 796             }
 797             public void put(Object key, Object value) {
 798                 getAppContext().put(key, value);
 799             }
 800             public void remove(Object key) {
 801                 getAppContext().remove(key);
 802             }
 803             public boolean isDisposed() {
 804                 return getAppContext().isDisposed();
 805             }
 806             public boolean isMainAppContext() {
 807                 return (numAppContexts == 1);















 808             }
 809         });
 810     }
 811 }
 812 
 813 final class MostRecentKeyValue {
 814     Object key;
 815     Object value;
 816     MostRecentKeyValue(Object k, Object v) {
 817         key = k;
 818         value = v;
 819     }
 820     void setPair(Object k, Object v) {
 821         key = k;
 822         value = v;
 823     }
 824 }


 310                     // all the intermediate ThreadGroups to threadGroup2appContext
 311                     // so we won't spin again.
 312                     for (ThreadGroup tg = currentThreadGroup; tg != threadGroup; tg = tg.getParent()) {
 313                         threadGroup2appContext.put(tg, context);
 314                     }
 315                     // Now we're done, so we cache the latest key/value pair.
 316                     // (we do this before checking with any AWTSecurityManager, so if
 317                     // this Thread equates with the main AppContext in the cache, it
 318                     // still will)
 319                     threadAppContext.set(context);
 320 
 321                     return context;
 322                 }
 323             });
 324         }
 325 
 326         if (appContext == mainAppContext)  {
 327             // Before we return the main "system" AppContext, check to
 328             // see if there's an AWTSecurityManager installed.  If so,
 329             // allow it to choose the AppContext to return.
 330             AppContext secAppContext = getExecutionAppContext();





 331             if (secAppContext != null) {
 332                 appContext = secAppContext; // Return what we're told
 333             }
 334         }

 335 
 336         return appContext;
 337     }
 338 
 339     private final static AppContext getExecutionAppContext() {
 340         SecurityManager securityManager = System.getSecurityManager();
 341         if ((securityManager != null) &&
 342             (securityManager instanceof AWTSecurityManager))
 343         {
 344             AWTSecurityManager awtSecMgr = (AWTSecurityManager) securityManager;
 345             AppContext secAppContext = awtSecMgr.getAppContext();
 346             return secAppContext; // Return what we're told
 347         }
 348         return null;
 349     }
 350 
 351     /**
 352      * Returns the main ("system") AppContext.
 353      *
 354      * @return  the main AppContext
 355      * @since   1.8
 356      */
 357     final static AppContext getMainAppContext() {
 358         return mainAppContext;
 359     }
 360 
 361     private long DISPOSAL_TIMEOUT = 5000;  // Default to 5-second timeout
 362                                            // for disposal of all Frames
 363                                            // (we wait for this time twice,
 364                                            // once for dispose(), and once
 365                                            // to clear the EventQueue).
 366 
 367     private long THREAD_INTERRUPT_TIMEOUT = 1000;
 368                             // Default to 1-second timeout for all
 369                             // interrupted Threads to exit, and another
 370                             // 1 second for all stopped Threads to die.


 794         return changeSupport.getPropertyChangeListeners(propertyName);
 795     }
 796 
 797     // Set up JavaAWTAccess in SharedSecrets
 798     static {
 799         sun.misc.SharedSecrets.setJavaAWTAccess(new sun.misc.JavaAWTAccess() {
 800             public Object get(Object key) {
 801                 return getAppContext().get(key);
 802             }
 803             public void put(Object key, Object value) {
 804                 getAppContext().put(key, value);
 805             }
 806             public void remove(Object key) {
 807                 getAppContext().remove(key);
 808             }
 809             public boolean isDisposed() {
 810                 return getAppContext().isDisposed();
 811             }
 812             public boolean isMainAppContext() {
 813                 return (numAppContexts == 1);
 814             }
 815             public Object getContext() {
 816                 return getAppContext();
 817             }
 818             public Object getExecutionContext() {
 819                 return getExecutionAppContext();
 820             }
 821             public Object get(Object context, Object key) {
 822                 return ((AppContext)context).get(key);
 823             }
 824             public void put(Object context, Object key, Object value) {
 825                 ((AppContext)context).put(key, value);
 826             }
 827             public void remove(Object context, Object key) {
 828                 ((AppContext)context).remove(key);
 829             }
 830         });
 831     }
 832 }
 833 
 834 final class MostRecentKeyValue {
 835     Object key;
 836     Object value;
 837     MostRecentKeyValue(Object k, Object v) {
 838         key = k;
 839         value = v;
 840     }
 841     void setPair(Object k, Object v) {
 842         key = k;
 843         value = v;
 844     }
 845 }