SharedSecrets.java revision 0
0N/A/*
0N/A * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/Apackage sun.misc;
0N/A
0N/Aimport java.util.jar.JarFile;
0N/Aimport java.io.Console;
0N/Aimport java.io.File;
0N/Aimport java.io.FileDescriptor;
0N/A
0N/A/** A repository of "shared secrets", which are a mechanism for
0N/A calling implementation-private methods in another package without
0N/A using reflection. A package-private class implements a public
0N/A interface and provides the ability to call package-private methods
0N/A within that package; the object implementing that interface is
0N/A provided through a third package to which access is restricted.
0N/A This framework avoids the primary disadvantage of using reflection
0N/A for this purpose, namely the loss of compile-time checking. */
0N/A
0N/Apublic class SharedSecrets {
0N/A private static final Unsafe unsafe = Unsafe.getUnsafe();
0N/A private static JavaUtilJarAccess javaUtilJarAccess;
0N/A private static JavaLangAccess javaLangAccess;
0N/A private static JavaIOAccess javaIOAccess;
0N/A private static JavaIODeleteOnExitAccess javaIODeleteOnExitAccess;
0N/A private static JavaNetAccess javaNetAccess;
0N/A private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
0N/A
0N/A public static JavaUtilJarAccess javaUtilJarAccess() {
0N/A if (javaUtilJarAccess == null) {
0N/A // Ensure JarFile is initialized; we know that that class
0N/A // provides the shared secret
0N/A unsafe.ensureClassInitialized(JarFile.class);
0N/A }
0N/A return javaUtilJarAccess;
0N/A }
0N/A
0N/A public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
0N/A javaUtilJarAccess = access;
0N/A }
0N/A
0N/A public static void setJavaLangAccess(JavaLangAccess jla) {
0N/A javaLangAccess = jla;
0N/A }
0N/A
0N/A public static JavaLangAccess getJavaLangAccess() {
0N/A return javaLangAccess;
0N/A }
0N/A
0N/A public static void setJavaNetAccess(JavaNetAccess jna) {
0N/A javaNetAccess = jna;
0N/A }
0N/A
0N/A public static JavaNetAccess getJavaNetAccess() {
0N/A return javaNetAccess;
0N/A }
0N/A
0N/A public static void setJavaIOAccess(JavaIOAccess jia) {
0N/A javaIOAccess = jia;
0N/A }
0N/A
0N/A public static JavaIOAccess getJavaIOAccess() {
0N/A if (javaIOAccess == null) {
0N/A unsafe.ensureClassInitialized(Console.class);
0N/A }
0N/A return javaIOAccess;
0N/A }
0N/A
0N/A public static void setJavaIODeleteOnExitAccess(JavaIODeleteOnExitAccess jida) {
0N/A javaIODeleteOnExitAccess = jida;
0N/A }
0N/A
0N/A public static JavaIODeleteOnExitAccess getJavaIODeleteOnExitAccess() {
0N/A if (javaIODeleteOnExitAccess == null) {
0N/A unsafe.ensureClassInitialized(File.class);
0N/A }
0N/A return javaIODeleteOnExitAccess;
0N/A }
0N/A
0N/A public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) {
0N/A javaIOFileDescriptorAccess = jiofda;
0N/A }
0N/A
0N/A public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() {
0N/A if (javaIOFileDescriptorAccess == null)
0N/A unsafe.ensureClassInitialized(FileDescriptor.class);
0N/A
0N/A return javaIOFileDescriptorAccess;
0N/A }
0N/A
0N/A}