131 * an installed AWTSecurityManager may return the applet's AppContext 132 * based on the execution context. 133 * 134 * @author Thomas Ball 135 * @author Fred Ecks 136 */ 137 public final class AppContext { 138 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.AppContext"); 139 140 /* Since the contents of an AppContext are unique to each Java 141 * session, this class should never be serialized. */ 142 143 /* 144 * The key to put()/get() the Java EventQueue into/from the AppContext. 145 */ 146 public static final Object EVENT_QUEUE_KEY = new StringBuffer("EventQueue"); 147 148 /* 149 * The keys to store EventQueue push/pop lock and condition. 150 */ 151 public final static Object EVENT_QUEUE_LOCK_KEY = new StringBuilder("EventQueue.Lock"); 152 public final static Object EVENT_QUEUE_COND_KEY = new StringBuilder("EventQueue.Condition"); 153 154 /* A map of AppContexts, referenced by ThreadGroup. 155 */ 156 private static final Map<ThreadGroup, AppContext> threadGroup2appContext = 157 Collections.synchronizedMap(new IdentityHashMap<ThreadGroup, AppContext>()); 158 159 /** 160 * Returns a set containing all <code>AppContext</code>s. 161 */ 162 public static Set<AppContext> getAppContexts() { 163 synchronized (threadGroup2appContext) { 164 return new HashSet<AppContext>(threadGroup2appContext.values()); 165 } 166 } 167 168 /* The main "system" AppContext, used by everything not otherwise 169 contained in another AppContext. It is implicitly created for 170 standalone apps only (i.e. not applets) 171 */ 172 private static volatile AppContext mainAppContext = null; 173 174 private static class GetAppContextLock {}; 175 private final static Object getAppContextLock = new GetAppContextLock(); 176 177 /* 178 * The hash map associated with this AppContext. A private delegate 179 * is used instead of subclassing HashMap so as to avoid all of 180 * HashMap's potentially risky methods, such as clear(), elements(), 181 * putAll(), etc. 182 */ 183 private final Map<Object, Object> table = new HashMap<>(); 184 185 private final ThreadGroup threadGroup; 186 187 /** 188 * If any <code>PropertyChangeListeners</code> have been registered, 189 * the <code>changeSupport</code> field describes them. 190 * 191 * @see #addPropertyChangeListener 192 * @see #removePropertyChangeListener 193 * @see PropertyChangeSupport#firePropertyChange 194 */ 195 private PropertyChangeSupport changeSupport = null; | 131 * an installed AWTSecurityManager may return the applet's AppContext 132 * based on the execution context. 133 * 134 * @author Thomas Ball 135 * @author Fred Ecks 136 */ 137 public final class AppContext { 138 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.AppContext"); 139 140 /* Since the contents of an AppContext are unique to each Java 141 * session, this class should never be serialized. */ 142 143 /* 144 * The key to put()/get() the Java EventQueue into/from the AppContext. 145 */ 146 public static final Object EVENT_QUEUE_KEY = new StringBuffer("EventQueue"); 147 148 /* 149 * The keys to store EventQueue push/pop lock and condition. 150 */ 151 public static final Object EVENT_QUEUE_LOCK_KEY = new StringBuilder("EventQueue.Lock"); 152 public static final Object EVENT_QUEUE_COND_KEY = new StringBuilder("EventQueue.Condition"); 153 154 /* A map of AppContexts, referenced by ThreadGroup. 155 */ 156 private static final Map<ThreadGroup, AppContext> threadGroup2appContext = 157 Collections.synchronizedMap(new IdentityHashMap<ThreadGroup, AppContext>()); 158 159 /** 160 * Returns a set containing all <code>AppContext</code>s. 161 */ 162 public static Set<AppContext> getAppContexts() { 163 synchronized (threadGroup2appContext) { 164 return new HashSet<AppContext>(threadGroup2appContext.values()); 165 } 166 } 167 168 /* The main "system" AppContext, used by everything not otherwise 169 contained in another AppContext. It is implicitly created for 170 standalone apps only (i.e. not applets) 171 */ 172 private static volatile AppContext mainAppContext = null; 173 174 private static class GetAppContextLock {}; 175 private static final Object getAppContextLock = new GetAppContextLock(); 176 177 /* 178 * The hash map associated with this AppContext. A private delegate 179 * is used instead of subclassing HashMap so as to avoid all of 180 * HashMap's potentially risky methods, such as clear(), elements(), 181 * putAll(), etc. 182 */ 183 private final Map<Object, Object> table = new HashMap<>(); 184 185 private final ThreadGroup threadGroup; 186 187 /** 188 * If any <code>PropertyChangeListeners</code> have been registered, 189 * the <code>changeSupport</code> field describes them. 190 * 191 * @see #addPropertyChangeListener 192 * @see #removePropertyChangeListener 193 * @see PropertyChangeSupport#firePropertyChange 194 */ 195 private PropertyChangeSupport changeSupport = null; |