1 /*
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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 private static JavaBeansIntrospectorAccess javaBeansIntrospectorAccess;
59
60 public static JavaUtilJarAccess javaUtilJarAccess() {
61 if (javaUtilJarAccess == null) {
62 // Ensure JarFile is initialized; we know that that class
63 // provides the shared secret
64 unsafe.ensureClassInitialized(JarFile.class);
65 }
66 return javaUtilJarAccess;
67 }
68
69 public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
70 javaUtilJarAccess = access;
71 }
72
73 public static void setJavaLangAccess(JavaLangAccess jla) {
74 javaLangAccess = jla;
75 }
76
77 public static JavaLangAccess getJavaLangAccess() {
163 return javaSecurityAccess;
164 }
165
166 public static JavaUtilZipFileAccess getJavaUtilZipFileAccess() {
167 if (javaUtilZipFileAccess == null)
168 unsafe.ensureClassInitialized(java.util.zip.ZipFile.class);
169 return javaUtilZipFileAccess;
170 }
171
172 public static void setJavaUtilZipFileAccess(JavaUtilZipFileAccess access) {
173 javaUtilZipFileAccess = access;
174 }
175
176 public static void setJavaAWTAccess(JavaAWTAccess jaa) {
177 javaAWTAccess = jaa;
178 }
179
180 public static JavaAWTAccess getJavaAWTAccess() {
181 // this may return null in which case calling code needs to
182 // provision for.
183 if (javaAWTAccess == null) {
184 return null;
185 }
186 return javaAWTAccess;
187 }
188
189 public static JavaBeansIntrospectorAccess getJavaBeansIntrospectorAccess() {
190 return javaBeansIntrospectorAccess;
191 }
192
193 public static void setJavaBeansIntrospectorAccess(JavaBeansIntrospectorAccess access) {
194 javaBeansIntrospectorAccess = access;
195 }
196 }
|
1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
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 private static JavaAWTFontAccess javaAWTFontAccess;
59 private static JavaBeansIntrospectorAccess javaBeansIntrospectorAccess;
60
61 public static JavaUtilJarAccess javaUtilJarAccess() {
62 if (javaUtilJarAccess == null) {
63 // Ensure JarFile is initialized; we know that that class
64 // provides the shared secret
65 unsafe.ensureClassInitialized(JarFile.class);
66 }
67 return javaUtilJarAccess;
68 }
69
70 public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
71 javaUtilJarAccess = access;
72 }
73
74 public static void setJavaLangAccess(JavaLangAccess jla) {
75 javaLangAccess = jla;
76 }
77
78 public static JavaLangAccess getJavaLangAccess() {
164 return javaSecurityAccess;
165 }
166
167 public static JavaUtilZipFileAccess getJavaUtilZipFileAccess() {
168 if (javaUtilZipFileAccess == null)
169 unsafe.ensureClassInitialized(java.util.zip.ZipFile.class);
170 return javaUtilZipFileAccess;
171 }
172
173 public static void setJavaUtilZipFileAccess(JavaUtilZipFileAccess access) {
174 javaUtilZipFileAccess = access;
175 }
176
177 public static void setJavaAWTAccess(JavaAWTAccess jaa) {
178 javaAWTAccess = jaa;
179 }
180
181 public static JavaAWTAccess getJavaAWTAccess() {
182 // this may return null in which case calling code needs to
183 // provision for.
184 return javaAWTAccess;
185 }
186
187 public static void setJavaAWTFontAccess(JavaAWTFontAccess jafa) {
188 javaAWTFontAccess = jafa;
189 }
190
191 public static JavaAWTFontAccess getJavaAWTFontAccess() {
192 // this may return null in which case calling code needs to
193 // provision for.
194 return javaAWTFontAccess;
195 }
196
197 public static JavaBeansIntrospectorAccess getJavaBeansIntrospectorAccess() {
198 return javaBeansIntrospectorAccess;
199 }
200
201 public static void setJavaBeansIntrospectorAccess(JavaBeansIntrospectorAccess access) {
202 javaBeansIntrospectorAccess = access;
203 }
204 }
|