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

Print this page




 821             }
 822             public void put(Object key, Object value) {
 823                 AppContext ac = getAppContext();
 824                 if (ac != null) {
 825                     ac.put(key, value);
 826                 }
 827             }
 828             public void remove(Object key) {
 829                 AppContext ac = getAppContext();
 830                 if (ac != null) {
 831                     ac.remove(key);
 832                 }
 833             }
 834             public boolean isDisposed() {
 835                 AppContext ac = getAppContext();
 836                 return (ac == null) ? true : ac.isDisposed();
 837             }
 838             public boolean isMainAppContext() {
 839                 return (numAppContexts.get() == 1 && mainAppContext != null);
 840             }
 841             public Object getContext() {
 842                 return getAppContext();
 843             }
 844             public Object getExecutionContext() {
 845                 return getExecutionAppContext();
 846             }
 847             public Object get(Object context, Object key) {
 848                 return ((AppContext)context).get(key);
 849             }
 850             public void put(Object context, Object key, Object value) {
 851                 ((AppContext)context).put(key, value);


























 852             }
 853             public void remove(Object context, Object key) {
 854                 ((AppContext)context).remove(key);











 855             }

 856         });
 857     }
 858 }
 859 
 860 final class MostRecentKeyValue {
 861     Object key;
 862     Object value;
 863     MostRecentKeyValue(Object k, Object v) {
 864         key = k;
 865         value = v;
 866     }
 867     void setPair(Object k, Object v) {
 868         key = k;
 869         value = v;
 870     }
 871 }


 821             }
 822             public void put(Object key, Object value) {
 823                 AppContext ac = getAppContext();
 824                 if (ac != null) {
 825                     ac.put(key, value);
 826                 }
 827             }
 828             public void remove(Object key) {
 829                 AppContext ac = getAppContext();
 830                 if (ac != null) {
 831                     ac.remove(key);
 832                 }
 833             }
 834             public boolean isDisposed() {
 835                 AppContext ac = getAppContext();
 836                 return (ac == null) ? true : ac.isDisposed();
 837             }
 838             public boolean isMainAppContext() {
 839                 return (numAppContexts.get() == 1 && mainAppContext != null);
 840             }
 841 
 842             /**
 843              * Returns the AppContext used for applet logging isolation, or null if
 844              * the default global context can be used.
 845              * If there's no applet, or if the caller is a stand alone application,
 846              * or running in the main app context, returns null.
 847              * Otherwise, returns the AppContext of the calling applet.
 848              * @return null if the global default context can be used,
 849              *         an AppContext otherwise.
 850              **/
 851             public Object getAppletContext() {
 852                 // There's no AppContext: return null.
 853                 // No need to call getAppContext() if numAppContext == 0:
 854                 // it means that no AppContext has been created yet, and
 855                 // we don't want to trigger the creation of a main app
 856                 // context since we don't need it.
 857                 if (numAppContexts.get() == 0) return null;
 858 
 859                 // Get the context from the security manager
 860                 AppContext ecx = getExecutionAppContext();
 861 
 862                 // Not sure we really need to re-check numAppContexts here.
 863                 // If all applets have gone away then we could have a
 864                 // numAppContexts coming back to 0. So we recheck
 865                 // it here because we don't want to trigger the
 866                 // creation of a main AppContext in that case.
 867                 // This is probably not 100% MT-safe but should reduce
 868                 // the window of opportunity in which that issue could
 869                 // happen.
 870                 if (numAppContexts.get() > 0) {
 871                    // Defaults to thread group caching.
 872                    // This is probably not required as we only really need
 873                    // isolation in a deployed applet environment, in which
 874                    // case ecx will not be null when we reach here
 875                    // However it helps emulate the deployed environment,
 876                    // in tests for instance.
 877                    ecx = ecx != null ? ecx : getAppContext();
 878                 }
 879 
 880                 // getAppletContext() may be called when initializing the main
 881                 // app context - in which case mainAppContext will still be
 882                 // null. To work around this issue we simply use
 883                 // AppContext.threadGroup.getParent() == null instead, since
 884                 // mainAppContext is the only AppContext which should have
 885                 // the root TG as its thread group.
 886                 // See: JDK-8023258
 887                 final boolean isMainAppContext = ecx == null
 888                     || mainAppContext == ecx
 889                     || mainAppContext == null && ecx.threadGroup.getParent() == null;
 890 
 891                 return isMainAppContext ? null : ecx;
 892             }
 893 
 894         });
 895     }
 896 }
 897 
 898 final class MostRecentKeyValue {
 899     Object key;
 900     Object value;
 901     MostRecentKeyValue(Object k, Object v) {
 902         key = k;
 903         value = v;
 904     }
 905     void setPair(Object k, Object v) {
 906         key = k;
 907         value = v;
 908     }
 909 }