src/share/classes/sun/misc/SharedSecrets.java

Print this page




  28 import java.util.jar.JarFile;
  29 import java.io.Console;
  30 import java.io.FileDescriptor;
  31 import java.security.ProtectionDomain;
  32 
  33 import java.security.AccessController;
  34 
  35 /** A repository of "shared secrets", which are a mechanism for
  36     calling implementation-private methods in another package without
  37     using reflection. A package-private class implements a public
  38     interface and provides the ability to call package-private methods
  39     within that package; the object implementing that interface is
  40     provided through a third package to which access is restricted.
  41     This framework avoids the primary disadvantage of using reflection
  42     for this purpose, namely the loss of compile-time checking. */
  43 
  44 public class SharedSecrets {
  45     private static final Unsafe unsafe = Unsafe.getUnsafe();
  46     private static JavaUtilJarAccess javaUtilJarAccess;
  47     private static JavaLangAccess javaLangAccess;

  48     private static JavaIOAccess javaIOAccess;
  49     private static JavaNetAccess javaNetAccess;
  50     private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
  51     private static JavaNioAccess javaNioAccess;
  52     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
  53     private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
  54     private static JavaSecurityAccess javaSecurityAccess;
  55     private static JavaUtilZipFileAccess javaUtilZipFileAccess;
  56     private static JavaAWTAccess javaAWTAccess;
  57 
  58     public static JavaUtilJarAccess javaUtilJarAccess() {
  59         if (javaUtilJarAccess == null) {
  60             // Ensure JarFile is initialized; we know that that class
  61             // provides the shared secret
  62             unsafe.ensureClassInitialized(JarFile.class);
  63         }
  64         return javaUtilJarAccess;
  65     }
  66 
  67     public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
  68         javaUtilJarAccess = access;
  69     }
  70 
  71     public static void setJavaLangAccess(JavaLangAccess jla) {
  72         javaLangAccess = jla;
  73     }
  74 
  75     public static JavaLangAccess getJavaLangAccess() {
  76         return javaLangAccess;








  77     }
  78 
  79     public static void setJavaNetAccess(JavaNetAccess jna) {
  80         javaNetAccess = jna;
  81     }
  82 
  83     public static JavaNetAccess getJavaNetAccess() {
  84         return javaNetAccess;
  85     }
  86 
  87     public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) {
  88         javaNetHttpCookieAccess = a;
  89     }
  90 
  91     public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() {
  92         if (javaNetHttpCookieAccess == null)
  93             unsafe.ensureClassInitialized(java.net.HttpCookie.class);
  94         return javaNetHttpCookieAccess;
  95     }
  96 




  28 import java.util.jar.JarFile;
  29 import java.io.Console;
  30 import java.io.FileDescriptor;
  31 import java.security.ProtectionDomain;
  32 
  33 import java.security.AccessController;
  34 
  35 /** A repository of "shared secrets", which are a mechanism for
  36     calling implementation-private methods in another package without
  37     using reflection. A package-private class implements a public
  38     interface and provides the ability to call package-private methods
  39     within that package; the object implementing that interface is
  40     provided through a third package to which access is restricted.
  41     This framework avoids the primary disadvantage of using reflection
  42     for this purpose, namely the loss of compile-time checking. */
  43 
  44 public class SharedSecrets {
  45     private static final Unsafe unsafe = Unsafe.getUnsafe();
  46     private static JavaUtilJarAccess javaUtilJarAccess;
  47     private static JavaLangAccess javaLangAccess;
  48     private static JavaLangRefAccess javaLangRefAccess;
  49     private static JavaIOAccess javaIOAccess;
  50     private static JavaNetAccess javaNetAccess;
  51     private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
  52     private static JavaNioAccess javaNioAccess;
  53     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
  54     private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
  55     private static JavaSecurityAccess javaSecurityAccess;
  56     private static JavaUtilZipFileAccess javaUtilZipFileAccess;
  57     private static JavaAWTAccess javaAWTAccess;
  58 
  59     public static JavaUtilJarAccess javaUtilJarAccess() {
  60         if (javaUtilJarAccess == null) {
  61             // Ensure JarFile is initialized; we know that that class
  62             // provides the shared secret
  63             unsafe.ensureClassInitialized(JarFile.class);
  64         }
  65         return javaUtilJarAccess;
  66     }
  67 
  68     public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
  69         javaUtilJarAccess = access;
  70     }
  71 
  72     public static void setJavaLangAccess(JavaLangAccess jla) {
  73         javaLangAccess = jla;
  74     }
  75 
  76     public static JavaLangAccess getJavaLangAccess() {
  77         return javaLangAccess;
  78     }
  79 
  80     public static void setJavaLangRefAccess(JavaLangRefAccess jlra) {
  81         javaLangRefAccess = jlra;
  82     }
  83 
  84     public static JavaLangRefAccess getJavaLangRefAccess() {
  85         return javaLangRefAccess;
  86     }
  87 
  88     public static void setJavaNetAccess(JavaNetAccess jna) {
  89         javaNetAccess = jna;
  90     }
  91 
  92     public static JavaNetAccess getJavaNetAccess() {
  93         return javaNetAccess;
  94     }
  95 
  96     public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) {
  97         javaNetHttpCookieAccess = a;
  98     }
  99 
 100     public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() {
 101         if (javaNetHttpCookieAccess == null)
 102             unsafe.ensureClassInitialized(java.net.HttpCookie.class);
 103         return javaNetHttpCookieAccess;
 104     }
 105