home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / BAX1F3 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.1 KB  |  51 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.util.Hashtable;
  4.  
  5. final class AppContext {
  6.    private static Hashtable security2appContexts = new Hashtable(2);
  7.    private static Object nullSecurityContext = new Object();
  8.    private final Hashtable table = new Hashtable(2);
  9.  
  10.    private AppContext(Object securityContext) {
  11.       security2appContexts.put(securityContext, this);
  12.    }
  13.  
  14.    public Object get(Object key) {
  15.       return this.table.get(key);
  16.    }
  17.  
  18.    public static AppContext getAppContext() {
  19.       Object securityContext = nullSecurityContext;
  20.       AppContext appContext = (AppContext)security2appContexts.get(securityContext);
  21.       if (appContext == null) {
  22.          appContext = new AppContext(securityContext);
  23.          security2appContexts.put(securityContext, appContext);
  24.       }
  25.  
  26.       return appContext;
  27.    }
  28.  
  29.    public Object put(Object key, Object value) {
  30.       return this.table.put(key, value);
  31.    }
  32.  
  33.    public Object remove(Object key) {
  34.       return this.table.remove(key);
  35.    }
  36.  
  37.    public String toString() {
  38.       Object securityContext = nullSecurityContext;
  39.       SecurityManager sm = System.getSecurityManager();
  40.       if (sm != null) {
  41.          Object context = System.getSecurityManager().getSecurityContext();
  42.          if (context != null) {
  43.             securityContext = context;
  44.          }
  45.       }
  46.  
  47.       String contextName = securityContext.equals(nullSecurityContext) ? "null" : securityContext.toString();
  48.       return this.getClass().getName() + "[SecurityContext=" + contextName + "]";
  49.    }
  50. }
  51.