Class Bridge
java.lang.Object
org.glassfish.pfl.basic.reflection.BridgeBase
org.glassfish.pfl.basic.reflection.Bridge
This class provides the methods for fundamental JVM operations
needed in the ORB that are not part of the public Java API. This includes:
- throwException, which can throw undeclared checked exceptions. This is needed to handle throwing arbitrary exceptions across a standardized OMG interface that (incorrectly) does not specify appropriate exceptions.
- putXXX/getXXX methods that allow unchecked access to fields of objects. This is used for setting uninitialzed non-static final fields (which is impossible with reflection) and for speed.
- objectFieldOffset to obtain the field offsets for use in the putXXX/getXXX methods
- newConstructorForSerialization to get the special constructor required for a Serializable class
- latestUserDefinedLoader to get the latest user defined class loader from the call stack as required by the RMI-IIOP specification (really from the JDK 1.1 days)
- RuntimePermission "reflectionFactoryAccess"
- BridgePermission "getBridge"
- ReflectPermission "suppressAccessChecks"
All of these permissions are required to obtain and correctly initialize the instance of Bridge. No security checks are performed on calls made to Bridge instance methods, so access to the Bridge instance must be protected.
This class is a singleton (per ClassLoader of course). Access to the instance is obtained through the Bridge.get() method.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Bridge
private static final Permission
private static Method
private final Method
private final Constructor
<OptionalDataException> private final sun.reflect.ReflectionFactory
Fields inherited from class org.glassfish.pfl.basic.reflection.BridgeBase
INVALID_FIELD_OFFSET
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Bridge
get()
Fetch the Bridge singleton.private static Method
private static Method
getInheritableMethod
(Class<?> cl, String name, Class<?> returnType, Class<?>... argTypes) final ClassLoader
Obtain the latest user defined ClassLoader from the call stack.private Method
private static Method
getMatchingMethod
(Class<?> cl, String name, Class<?> returnType, Class<?>[] argTypes) private static <T> Class
<?> getNearestNonSerializableBaseClass
(Class<T> clazz) private Constructor
<OptionalDataException> private static Method
getPrivateMethod
(Class<?> cl, String name, Class<?> returnType, Class<?>... argTypes) boolean
Returns true if the given class defines a static initializer method, false otherwise.private static boolean
inSamePackage
(Class<?> clazz, Class<?> baseClass) private static boolean
isAccessibleFromSubclass
(Constructor<?> constructor, Class<?> clazz, Class<?> baseClass) private static boolean
isMethodInheritableBy
(Class<?> callingClass, Method method) private static boolean
isPrivate
(Constructor<?> cons) private static boolean
private static boolean
isPublic
(Constructor<?> cons) private static boolean
isPublicOrProtected
(Constructor<?> constructor) private static boolean
final <T> Constructor
<T> Return a constructor that can be used to create an instance of the class for externalization.<T> Constructor
<T> newConstructorForSerialization
(Class<T> aClass) Return a no-arg constructor for the specified class, based on the default constructor for its nearest non-serializable base class.final <T> Constructor
<T> newConstructorForSerialization
(Class<T> aClass, Constructor<?> cons) Return a no-arg constructor for the specified class which invokes the specified constructor.newOptionalDataExceptionForSerialization
(boolean endOfData) Return a new OptionalDataException instance.private static boolean
packageEquals
(Class<?> cl1, Class<?> cl2) Returns true if classes are defined in the same package, false Copied from the Merlin java.io.ObjectStreamClass.readObjectForSerialization
(Class<?> cl) Returns a method handle to allow invocation of the specified class's readObject method.readResolveForSerialization
(Class<?> cl) Returns a method handle to allow invocation of the specified class's readResolve method.private static MethodHandle
toMethodHandle
(Method method) writeObjectForSerialization
(Class<?> cl) Returns a method handle to allow invocation of the specified class's writeObject method.Returns a method handle to allow invocation of the specified class's writeReplace method.Methods inherited from class org.glassfish.pfl.basic.reflection.BridgeBase
defineClass, defineClass, ensureClassInitialized, getBoolean, getByte, getChar, getDouble, getFloat, getInt, getLong, getObject, getShort, objectFieldOffset, putBoolean, putByte, putChar, putDouble, putFloat, putInt, putLong, putObject, putShort, staticFieldOffset, throwException, toAccessibleField, toAccessibleMethod
-
Field Details
-
GET_BRIDGE_PERMISSION
-
bridge
-
latestUserDefinedLoaderMethod
-
optionalDataExceptionConstructor
-
reflectionFactory
private final sun.reflect.ReflectionFactory reflectionFactory -
hasStaticInitializerMethod
-
-
Constructor Details
-
Bridge
private Bridge()
-
-
Method Details
-
getLatestUserDefinedLoaderMethod
-
getOptDataExceptionCtor
-
get
Fetch the Bridge singleton. This requires the following permissions:- RuntimePermission "reflectionFactoryAccess"
- BridgePermission "getBridge"
- ReflectPermission "suppressAccessChecks"
- Returns:
- The singleton instance of the Bridge class
- Throws:
SecurityException
- if the caller does not have the required permissions and the caller has a non-null security manager.
-
getLatestUserDefinedLoader
Description copied from class:BridgeBase
Obtain the latest user defined ClassLoader from the call stack. This is required by the RMI-IIOP specification.- Specified by:
getLatestUserDefinedLoader
in classBridgeBase
-
newConstructorForExternalization
Description copied from class:BridgeBase
Return a constructor that can be used to create an instance of the class for externalization.- Specified by:
newConstructorForExternalization
in classBridgeBase
- Parameters:
cl
- the class
-
isPublic
-
newConstructorForSerialization
public final <T> Constructor<T> newConstructorForSerialization(Class<T> aClass, Constructor<?> cons) Description copied from class:BridgeBase
Return a no-arg constructor for the specified class which invokes the specified constructor.- Specified by:
newConstructorForSerialization
in classBridgeBase
- Parameters:
aClass
- the class for which a constructor should be returned.cons
- the default constructor on which to model the new constructor.
-
newConstructorForSerialization
Description copied from class:BridgeBase
Return a no-arg constructor for the specified class, based on the default constructor for its nearest non-serializable base class.- Specified by:
newConstructorForSerialization
in classBridgeBase
- Parameters:
aClass
- the class for which a constructor should be returned.
-
getNearestNonSerializableBaseClass
-
isAccessibleFromSubclass
private static boolean isAccessibleFromSubclass(Constructor<?> constructor, Class<?> clazz, Class<?> baseClass) -
inSamePackage
-
isPublicOrProtected
-
isPrivate
-
hasStaticInitializerForSerialization
Description copied from class:BridgeBase
Returns true if the given class defines a static initializer method, false otherwise.- Specified by:
hasStaticInitializerForSerialization
in classBridgeBase
-
getHasStaticInitializerMethod
- Throws:
NoSuchMethodException
-
writeObjectForSerialization
Description copied from class:BridgeBase
Returns a method handle to allow invocation of the specified class's writeObject method.- Specified by:
writeObjectForSerialization
in classBridgeBase
- Parameters:
cl
- the class containing the method
-
toMethodHandle
-
getPrivateMethod
-
isStatic
-
isPrivate
-
readObjectForSerialization
Description copied from class:BridgeBase
Returns a method handle to allow invocation of the specified class's readObject method.- Specified by:
readObjectForSerialization
in classBridgeBase
- Parameters:
cl
- the class containing the method
-
readResolveForSerialization
Description copied from class:BridgeBase
Returns a method handle to allow invocation of the specified class's readResolve method.- Specified by:
readResolveForSerialization
in classBridgeBase
- Parameters:
cl
- the class containing the method
-
getInheritableMethod
-
getMatchingMethod
-
isMethodInheritableBy
-
packageEquals
Returns true if classes are defined in the same package, false Copied from the Merlin java.io.ObjectStreamClass. -
writeReplaceForSerialization
Description copied from class:BridgeBase
Returns a method handle to allow invocation of the specified class's writeReplace method.- Specified by:
writeReplaceForSerialization
in classBridgeBase
- Parameters:
cl
- the class containing the method
-
newOptionalDataExceptionForSerialization
Description copied from class:BridgeBase
Return a new OptionalDataException instance.- Specified by:
newOptionalDataExceptionForSerialization
in classBridgeBase
- Returns:
- a new OptionalDataException instance
-