test/java/util/logging/TestAppletLoggerContext.java

Print this page




  93 
  94     // The bridge class initializes the logging system.
  95     // It stubs the applet context in order to simulate context changes.
  96     //
  97     public static class Bridge {
  98 
  99         private static class JavaAWTAccessStub implements JavaAWTAccess {
 100             boolean active = true;
 101 
 102             private static class TestExc {
 103                 private final Map<Object, Object> map = new HashMap<>();
 104                 void put(Object key, Object v) { map.put(key, v); }
 105                 Object get(Object key) { return map.get(key); }
 106                 void remove(Object o) { map.remove(o); }
 107                 public static TestExc exc(Object o) {
 108                     return TestExc.class.cast(o);
 109                 }
 110             }
 111 
 112             TestExc exc;
 113             TestExc global = new TestExc();
 114 
 115             @Override
 116             public Object getContext() { return active ? global : null; }
 117             @Override
 118             public Object getExecutionContext() { return active ? exc : null; }
 119             @Override
 120             public Object get(Object o, Object o1) { return TestExc.exc(o).get(o1); }
 121             @Override
 122             public void put(Object o, Object o1, Object o2) { TestExc.exc(o).put(o1, o2); }
 123             @Override
 124             public void remove(Object o, Object o1) { TestExc.exc(o).remove(o1); }
 125             @Override
 126             public Object get(Object o) { return global.get(o); }
 127             @Override
 128             public void put(Object o, Object o1) { global.put(o, o1); }
 129             @Override
 130             public void remove(Object o) { global.remove(o); }
 131             @Override
 132             public boolean isDisposed() { return false; }
 133             @Override
 134             public boolean isMainAppContext() { return exc == null; }
 135         }
 136 
 137         final static JavaAWTAccessStub javaAwtAccess = new JavaAWTAccessStub();
 138         public static void init() {
 139             SharedSecrets.setJavaAWTAccess(javaAwtAccess);
 140             if (System.getProperty("test.security", "on").equals("on")) {
 141                 Policy p = new SimplePolicy(new LoggingPermission("control", null),
 142                     new RuntimePermission("setContextClassLoader"),
 143                     new RuntimePermission("shutdownHooks"));
 144                 Policy.setPolicy(p);
 145                 System.setSecurityManager(new SecurityManager());
 146             }
 147         }
 148 
 149         public static void changeContext() {
 150             System.out.println("... Switching to a new applet context ...");
 151             javaAwtAccess.active = true;
 152             javaAwtAccess.exc = new JavaAWTAccessStub.TestExc();
 153         }
 154 




  93 
  94     // The bridge class initializes the logging system.
  95     // It stubs the applet context in order to simulate context changes.
  96     //
  97     public static class Bridge {
  98 
  99         private static class JavaAWTAccessStub implements JavaAWTAccess {
 100             boolean active = true;
 101 
 102             private static class TestExc {
 103                 private final Map<Object, Object> map = new HashMap<>();
 104                 void put(Object key, Object v) { map.put(key, v); }
 105                 Object get(Object key) { return map.get(key); }
 106                 void remove(Object o) { map.remove(o); }
 107                 public static TestExc exc(Object o) {
 108                     return TestExc.class.cast(o);
 109                 }
 110             }
 111 
 112             TestExc exc;

 113 
 114             @Override
 115             public Object getAppletContext() { return active ? exc : null; }
 116             @Override
 117             public Object get(Object o) { return exc.get(o); }
 118             @Override
 119             public void put(Object o, Object o1) { exc.put(o, o1); }
 120             @Override
 121             public void remove(Object o) { exc.remove(o); }








 122             @Override
 123             public boolean isDisposed() { return false; }
 124             @Override
 125             public boolean isMainAppContext() { return !active || exc == null; }
 126         }
 127 
 128         final static JavaAWTAccessStub javaAwtAccess = new JavaAWTAccessStub();
 129         public static void init() {
 130             SharedSecrets.setJavaAWTAccess(javaAwtAccess);
 131             if (System.getProperty("test.security", "on").equals("on")) {
 132                 Policy p = new SimplePolicy(new LoggingPermission("control", null),
 133                     new RuntimePermission("setContextClassLoader"),
 134                     new RuntimePermission("shutdownHooks"));
 135                 Policy.setPolicy(p);
 136                 System.setSecurityManager(new SecurityManager());
 137             }
 138         }
 139 
 140         public static void changeContext() {
 141             System.out.println("... Switching to a new applet context ...");
 142             javaAwtAccess.active = true;
 143             javaAwtAccess.exc = new JavaAWTAccessStub.TestExc();
 144         }
 145