test/java/util/logging/TestAppletLoggerContext.java

Print this page




  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 




  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         }
 117 
 118         final static JavaAWTAccessStub javaAwtAccess = new JavaAWTAccessStub();
 119         public static void init() {
 120             SharedSecrets.setJavaAWTAccess(javaAwtAccess);
 121             if (System.getProperty("test.security", "on").equals("on")) {
 122                 Policy p = new SimplePolicy(new LoggingPermission("control", null),
 123                     new RuntimePermission("setContextClassLoader"),
 124                     new RuntimePermission("shutdownHooks"));
 125                 Policy.setPolicy(p);
 126                 System.setSecurityManager(new SecurityManager());
 127             }
 128         }
 129 
 130         public static void changeContext() {
 131             System.out.println("... Switching to a new applet context ...");
 132             javaAwtAccess.active = true;
 133             javaAwtAccess.exc = new JavaAWTAccessStub.TestExc();
 134         }
 135