< prev index next >

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

Print this page

        

*** 69,98 **** * of "default" to be ThreadGroup-specific. Application services * lookup their singleton in the AppContext.<p> * * For example, here we have a Foo service, with its pre-AppContext * code:<p> ! * <code><pre> * public class Foo { * private static Foo defaultFoo = new Foo(); * * public static Foo getDefaultFoo() { * return defaultFoo; * } * * ... Foo service methods ! * }</pre></code><p> * * The problem with the above is that the Foo service is global in scope, * so that applets and other untrusted code can execute methods on the * single, shared Foo instance. The Foo service therefore either needs * to block its use by untrusted code using a SecurityManager test, or * restrict its capabilities so that it doesn't matter if untrusted code * executes it.<p> * * Here's the Foo class written to use the AppContext:<p> ! * <code><pre> * public class Foo { * public static Foo getDefaultFoo() { * Foo foo = (Foo)AppContext.getAppContext().get(Foo.class); * if (foo == null) { * foo = new Foo(); --- 69,99 ---- * of "default" to be ThreadGroup-specific. Application services * lookup their singleton in the AppContext.<p> * * For example, here we have a Foo service, with its pre-AppContext * code:<p> ! * <pre>{@code * public class Foo { * private static Foo defaultFoo = new Foo(); * * public static Foo getDefaultFoo() { * return defaultFoo; * } * * ... Foo service methods ! * } ! * }</pre><p> * * The problem with the above is that the Foo service is global in scope, * so that applets and other untrusted code can execute methods on the * single, shared Foo instance. The Foo service therefore either needs * to block its use by untrusted code using a SecurityManager test, or * restrict its capabilities so that it doesn't matter if untrusted code * executes it.<p> * * Here's the Foo class written to use the AppContext:<p> ! * <pre>{@code * public class Foo { * public static Foo getDefaultFoo() { * Foo foo = (Foo)AppContext.getAppContext().get(Foo.class); * if (foo == null) { * foo = new Foo();
*** 100,110 **** * } * return foo; * } * * ... Foo service methods ! * }</pre></code><p> * * Since a separate AppContext can exist for each ThreadGroup, trusted * and untrusted code have access to different Foo instances. This allows * untrusted code access to "system-wide" services -- the service remains * within the AppContext "sandbox". For example, say a malicious applet --- 101,112 ---- * } * return foo; * } * * ... Foo service methods ! * } ! * }</pre><p> * * Since a separate AppContext can exist for each ThreadGroup, trusted * and untrusted code have access to different Foo instances. This allows * untrusted code access to "system-wide" services -- the service remains * within the AppContext "sandbox". For example, say a malicious applet
*** 157,167 **** */ private static final Map<ThreadGroup, AppContext> threadGroup2appContext = Collections.synchronizedMap(new IdentityHashMap<ThreadGroup, AppContext>()); /** ! * Returns a set containing all <code>AppContext</code>s. */ public static Set<AppContext> getAppContexts() { synchronized (threadGroup2appContext) { return new HashSet<AppContext>(threadGroup2appContext.values()); } --- 159,169 ---- */ private static final Map<ThreadGroup, AppContext> threadGroup2appContext = Collections.synchronizedMap(new IdentityHashMap<ThreadGroup, AppContext>()); /** ! * Returns a set containing all {@code AppContext}s. */ public static Set<AppContext> getAppContexts() { synchronized (threadGroup2appContext) { return new HashSet<AppContext>(threadGroup2appContext.values()); }
*** 185,196 **** private final Map<Object, Object> table = new HashMap<>(); private final ThreadGroup threadGroup; /** ! * If any <code>PropertyChangeListeners</code> have been registered, ! * the <code>changeSupport</code> field describes them. * * @see #addPropertyChangeListener * @see #removePropertyChangeListener * @see PropertyChangeSupport#firePropertyChange */ --- 187,198 ---- private final Map<Object, Object> table = new HashMap<>(); private final ThreadGroup threadGroup; /** ! * If any {@code PropertyChangeListeners} have been registered, ! * the {@code changeSupport} field describes them. * * @see #addPropertyChangeListener * @see #removePropertyChangeListener * @see PropertyChangeSupport#firePropertyChange */
*** 628,638 **** /** * Returns the value to which the specified key is mapped in this context. * * @param key a key in the AppContext. * @return the value to which the key is mapped in this AppContext; ! * <code>null</code> if the key is not mapped to any value. * @see #put(Object, Object) * @since 1.2 */ public Object get(Object key) { /* --- 630,640 ---- /** * Returns the value to which the specified key is mapped in this context. * * @param key a key in the AppContext. * @return the value to which the key is mapped in this AppContext; ! * {@code null} if the key is not mapped to any value. * @see #put(Object, Object) * @since 1.2 */ public Object get(Object key) { /*
*** 665,687 **** return value; } } /** ! * Maps the specified <code>key</code> to the specified ! * <code>value</code> in this AppContext. Neither the key nor the ! * value can be <code>null</code>. * <p> ! * The value can be retrieved by calling the <code>get</code> method * with a key that is equal to the original key. * * @param key the AppContext key. * @param value the value. * @return the previous value of the specified key in this ! * AppContext, or <code>null</code> if it did not have one. * @exception NullPointerException if the key or value is ! * <code>null</code>. * @see #get(Object) * @since 1.2 */ public Object put(Object key, Object value) { synchronized (table) { --- 667,689 ---- return value; } } /** ! * Maps the specified {@code key} to the specified ! * {@code value} in this AppContext. Neither the key nor the ! * value can be {@code null}. * <p> ! * The value can be retrieved by calling the {@code get} method * with a key that is equal to the original key. * * @param key the AppContext key. * @param value the value. * @return the previous value of the specified key in this ! * AppContext, or {@code null} if it did not have one. * @exception NullPointerException if the key or value is ! * {@code null}. * @see #get(Object) * @since 1.2 */ public Object put(Object key, Object value) { synchronized (table) {
*** 697,707 **** * AppContext. This method does nothing if the key is not in the * AppContext. * * @param key the key that needs to be removed. * @return the value to which the key had been mapped in this AppContext, ! * or <code>null</code> if the key did not have a mapping. * @since 1.2 */ public Object remove(Object key) { synchronized (table) { MostRecentKeyValue recent = mostRecentKeyValue; --- 699,709 ---- * AppContext. This method does nothing if the key is not in the * AppContext. * * @param key the key that needs to be removed. * @return the value to which the key had been mapped in this AppContext, ! * or {@code null} if the key did not have a mapping. * @since 1.2 */ public Object remove(Object key) { synchronized (table) { MostRecentKeyValue recent = mostRecentKeyValue;
*** 741,751 **** /** * Returns an array of all the property change listeners * registered on this component. * ! * @return all of this component's <code>PropertyChangeListener</code>s * or an empty array if no property change * listeners are currently registered * * @see #addPropertyChangeListener * @see #removePropertyChangeListener --- 743,753 ---- /** * Returns an array of all the property change listeners * registered on this component. * ! * @return all of this component's {@code PropertyChangeListener}s * or an empty array if no property change * listeners are currently registered * * @see #addPropertyChangeListener * @see #removePropertyChangeListener
*** 820,830 **** /** * Returns an array of all the listeners which have been associated * with the named property. * ! * @return all of the <code>PropertyChangeListeners</code> associated with * the named property or an empty array if no listeners have * been added * * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) --- 822,832 ---- /** * Returns an array of all the listeners which have been associated * with the named property. * ! * @return all of the {@code PropertyChangeListeners} associated with * the named property or an empty array if no listeners have * been added * * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener) * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
< prev index next >