1 /*
2 * Copyright (c) 2001, 2011, 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
23 * questions.
24 */
25
26 package sun.reflect;
27
28 import java.lang.reflect.Field;
29 import java.lang.reflect.Method;
30 import java.lang.reflect.Constructor;
31 import java.lang.reflect.Modifier;
32 import java.security.AccessController;
33 import java.security.Permission;
34 import java.security.PrivilegedAction;
35
36 /** <P> The master factory for all reflective objects, both those in
37 java.lang.reflect (Fields, Methods, Constructors) as well as their
38 delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
39 </P>
40
41 <P> The methods in this class are extremely unsafe and can cause
42 subversion of both the language and the verifier. For this reason,
43 they are all instance methods, and access to the constructor of
44 this factory is guarded by a security check, in similar style to
45 {@link sun.misc.Unsafe}. </P>
46 */
47
48 public class ReflectionFactory {
295
296 /** Makes a copy of the passed method. The returned method is a
297 "child" of the passed one; see the comments in Method.java for
298 details. */
299 public Method copyMethod(Method arg) {
300 return langReflectAccess().copyMethod(arg);
301 }
302
303 /** Makes a copy of the passed field. The returned field is a
304 "child" of the passed one; see the comments in Field.java for
305 details. */
306 public Field copyField(Field arg) {
307 return langReflectAccess().copyField(arg);
308 }
309
310 /** Makes a copy of the passed constructor. The returned
311 constructor is a "child" of the passed one; see the comments
312 in Constructor.java for details. */
313 public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
314 return langReflectAccess().copyConstructor(arg);
315 }
316
317 //--------------------------------------------------------------------------
318 //
319 // Routines used by serialization
320 //
321 //
322
323 public Constructor<?> newConstructorForSerialization
324 (Class<?> classToInstantiate, Constructor<?> constructorToCall)
325 {
326 // Fast path
327 if (constructorToCall.getDeclaringClass() == classToInstantiate) {
328 return constructorToCall;
329 }
330
331 ConstructorAccessor acc = new MethodAccessorGenerator().
332 generateSerializationConstructor(classToInstantiate,
333 constructorToCall.getParameterTypes(),
334 constructorToCall.getExceptionTypes(),
|
1 /*
2 * Copyright (c) 2001, 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
23 * questions.
24 */
25
26 package sun.reflect;
27
28 import java.lang.reflect.Field;
29 import java.lang.reflect.Executable;
30 import java.lang.reflect.Method;
31 import java.lang.reflect.Constructor;
32 import java.lang.reflect.Modifier;
33 import java.security.AccessController;
34 import java.security.Permission;
35 import java.security.PrivilegedAction;
36
37 /** <P> The master factory for all reflective objects, both those in
38 java.lang.reflect (Fields, Methods, Constructors) as well as their
39 delegates (FieldAccessors, MethodAccessors, ConstructorAccessors).
40 </P>
41
42 <P> The methods in this class are extremely unsafe and can cause
43 subversion of both the language and the verifier. For this reason,
44 they are all instance methods, and access to the constructor of
45 this factory is guarded by a security check, in similar style to
46 {@link sun.misc.Unsafe}. </P>
47 */
48
49 public class ReflectionFactory {
296
297 /** Makes a copy of the passed method. The returned method is a
298 "child" of the passed one; see the comments in Method.java for
299 details. */
300 public Method copyMethod(Method arg) {
301 return langReflectAccess().copyMethod(arg);
302 }
303
304 /** Makes a copy of the passed field. The returned field is a
305 "child" of the passed one; see the comments in Field.java for
306 details. */
307 public Field copyField(Field arg) {
308 return langReflectAccess().copyField(arg);
309 }
310
311 /** Makes a copy of the passed constructor. The returned
312 constructor is a "child" of the passed one; see the comments
313 in Constructor.java for details. */
314 public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
315 return langReflectAccess().copyConstructor(arg);
316 }
317
318 /** Gets the byte[] that encodes TypeAnnotations on an executable.
319 */
320 public byte[] getExecutableTypeAnnotationBytes(Executable ex) {
321 return langReflectAccess().getExecutableTypeAnnotationBytes(ex);
322 }
323
324 //--------------------------------------------------------------------------
325 //
326 // Routines used by serialization
327 //
328 //
329
330 public Constructor<?> newConstructorForSerialization
331 (Class<?> classToInstantiate, Constructor<?> constructorToCall)
332 {
333 // Fast path
334 if (constructorToCall.getDeclaringClass() == classToInstantiate) {
335 return constructorToCall;
336 }
337
338 ConstructorAccessor acc = new MethodAccessorGenerator().
339 generateSerializationConstructor(classToInstantiate,
340 constructorToCall.getParameterTypes(),
341 constructorToCall.getExceptionTypes(),
|