Class Bridge
- java.lang.Object
-
- org.glassfish.pfl.basic.reflection.BridgeBase
-
- org.glassfish.pfl.basic.reflection.Bridge
-
public final class Bridge extends BridgeBase
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
Fields Modifier and Type Field Description private static Bridgebridgeprivate static java.security.PermissionGET_BRIDGE_PERMISSIONprivate static java.lang.reflect.MethodhasStaticInitializerMethodprivate java.lang.reflect.MethodlatestUserDefinedLoaderMethodprivate java.lang.reflect.Constructor<java.io.OptionalDataException>optionalDataExceptionConstructorprivate sun.reflect.ReflectionFactoryreflectionFactory-
Fields inherited from class org.glassfish.pfl.basic.reflection.BridgeBase
INVALID_FIELD_OFFSET
-
-
Constructor Summary
Constructors Modifier Constructor Description privateBridge()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Bridgeget()Fetch the Bridge singleton.private static java.lang.reflect.MethodgetHasStaticInitializerMethod()private static java.lang.reflect.MethodgetInheritableMethod(java.lang.Class<?> cl, java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>... argTypes)java.lang.ClassLoadergetLatestUserDefinedLoader()Obtain the latest user defined ClassLoader from the call stack.private java.lang.reflect.MethodgetLatestUserDefinedLoaderMethod()private static java.lang.reflect.MethodgetMatchingMethod(java.lang.Class<?> cl, java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>[] argTypes)private static <T> java.lang.Class<?>getNearestNonSerializableBaseClass(java.lang.Class<T> clazz)private java.lang.reflect.Constructor<java.io.OptionalDataException>getOptDataExceptionCtor()private static java.lang.reflect.MethodgetPrivateMethod(java.lang.Class<?> cl, java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>... argTypes)booleanhasStaticInitializerForSerialization(java.lang.Class<?> cl)Returns true if the given class defines a static initializer method, false otherwise.private static booleaninSamePackage(java.lang.Class<?> clazz, java.lang.Class<?> baseClass)private static booleanisAccessibleFromSubclass(java.lang.reflect.Constructor<?> constructor, java.lang.Class<?> clazz, java.lang.Class<?> baseClass)private static booleanisMethodInheritableBy(java.lang.Class<?> callingClass, java.lang.reflect.Method method)private static booleanisPrivate(java.lang.reflect.Constructor<?> cons)private static booleanisPrivate(java.lang.reflect.Method method)private static booleanisPublic(java.lang.reflect.Constructor<?> cons)private static booleanisPublicOrProtected(java.lang.reflect.Constructor<?> constructor)private static booleanisStatic(java.lang.reflect.Method method)<T> java.lang.reflect.Constructor<T>newConstructorForExternalization(java.lang.Class<T> cl)Return a constructor that can be used to create an instance of the class for externalization.<T> java.lang.reflect.Constructor<T>newConstructorForSerialization(java.lang.Class<T> aClass)Return a no-arg constructor for the specified class, based on the default constructor for its nearest non-serializable base class.<T> java.lang.reflect.Constructor<T>newConstructorForSerialization(java.lang.Class<T> aClass, java.lang.reflect.Constructor<?> cons)Return a no-arg constructor for the specified class which invokes the specified constructor.java.io.OptionalDataExceptionnewOptionalDataExceptionForSerialization(boolean endOfData)Return a new OptionalDataException instance.private static booleanpackageEquals(java.lang.Class<?> cl1, java.lang.Class<?> cl2)Returns true if classes are defined in the same package, false Copied from the Merlin java.io.ObjectStreamClass.java.lang.invoke.MethodHandlereadObjectForSerialization(java.lang.Class<?> cl)Returns a method handle to allow invocation of the specified class's readObject method.java.lang.invoke.MethodHandlereadResolveForSerialization(java.lang.Class<?> cl)Returns a method handle to allow invocation of the specified class's readResolve method.private static java.lang.invoke.MethodHandletoMethodHandle(java.lang.reflect.Method method)java.lang.invoke.MethodHandlewriteObjectForSerialization(java.lang.Class<?> cl)Returns a method handle to allow invocation of the specified class's writeObject method.java.lang.invoke.MethodHandlewriteReplaceForSerialization(java.lang.Class<?> cl)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 Detail
-
GET_BRIDGE_PERMISSION
private static final java.security.Permission GET_BRIDGE_PERMISSION
-
bridge
private static Bridge bridge
-
latestUserDefinedLoaderMethod
private final java.lang.reflect.Method latestUserDefinedLoaderMethod
-
optionalDataExceptionConstructor
private final java.lang.reflect.Constructor<java.io.OptionalDataException> optionalDataExceptionConstructor
-
reflectionFactory
private final sun.reflect.ReflectionFactory reflectionFactory
-
hasStaticInitializerMethod
private static java.lang.reflect.Method hasStaticInitializerMethod
-
-
Method Detail
-
getLatestUserDefinedLoaderMethod
private java.lang.reflect.Method getLatestUserDefinedLoaderMethod()
-
getOptDataExceptionCtor
private java.lang.reflect.Constructor<java.io.OptionalDataException> getOptDataExceptionCtor()
-
get
public static Bridge 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:
java.lang.SecurityException- if the caller does not have the required permissions and the caller has a non-null security manager.
-
getLatestUserDefinedLoader
public final java.lang.ClassLoader getLatestUserDefinedLoader()
Description copied from class:BridgeBaseObtain the latest user defined ClassLoader from the call stack. This is required by the RMI-IIOP specification.- Specified by:
getLatestUserDefinedLoaderin classBridgeBase
-
newConstructorForExternalization
public final <T> java.lang.reflect.Constructor<T> newConstructorForExternalization(java.lang.Class<T> cl)
Description copied from class:BridgeBaseReturn a constructor that can be used to create an instance of the class for externalization.- Specified by:
newConstructorForExternalizationin classBridgeBase- Parameters:
cl- the class
-
isPublic
private static boolean isPublic(java.lang.reflect.Constructor<?> cons)
-
newConstructorForSerialization
public final <T> java.lang.reflect.Constructor<T> newConstructorForSerialization(java.lang.Class<T> aClass, java.lang.reflect.Constructor<?> cons)Description copied from class:BridgeBaseReturn a no-arg constructor for the specified class which invokes the specified constructor.- Specified by:
newConstructorForSerializationin classBridgeBase- Parameters:
aClass- the class for which a constructor should be returned.cons- the default constructor on which to model the new constructor.
-
newConstructorForSerialization
public <T> java.lang.reflect.Constructor<T> newConstructorForSerialization(java.lang.Class<T> aClass)
Description copied from class:BridgeBaseReturn a no-arg constructor for the specified class, based on the default constructor for its nearest non-serializable base class.- Specified by:
newConstructorForSerializationin classBridgeBase- Parameters:
aClass- the class for which a constructor should be returned.
-
getNearestNonSerializableBaseClass
private static <T> java.lang.Class<?> getNearestNonSerializableBaseClass(java.lang.Class<T> clazz)
-
isAccessibleFromSubclass
private static boolean isAccessibleFromSubclass(java.lang.reflect.Constructor<?> constructor, java.lang.Class<?> clazz, java.lang.Class<?> baseClass)
-
inSamePackage
private static boolean inSamePackage(java.lang.Class<?> clazz, java.lang.Class<?> baseClass)
-
isPublicOrProtected
private static boolean isPublicOrProtected(java.lang.reflect.Constructor<?> constructor)
-
isPrivate
private static boolean isPrivate(java.lang.reflect.Constructor<?> cons)
-
hasStaticInitializerForSerialization
public boolean hasStaticInitializerForSerialization(java.lang.Class<?> cl)
Description copied from class:BridgeBaseReturns true if the given class defines a static initializer method, false otherwise.- Specified by:
hasStaticInitializerForSerializationin classBridgeBase
-
getHasStaticInitializerMethod
private static java.lang.reflect.Method getHasStaticInitializerMethod() throws java.lang.NoSuchMethodException- Throws:
java.lang.NoSuchMethodException
-
writeObjectForSerialization
public java.lang.invoke.MethodHandle writeObjectForSerialization(java.lang.Class<?> cl)
Description copied from class:BridgeBaseReturns a method handle to allow invocation of the specified class's writeObject method.- Specified by:
writeObjectForSerializationin classBridgeBase- Parameters:
cl- the class containing the method
-
toMethodHandle
private static java.lang.invoke.MethodHandle toMethodHandle(java.lang.reflect.Method method)
-
getPrivateMethod
private static java.lang.reflect.Method getPrivateMethod(java.lang.Class<?> cl, java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>... argTypes)
-
isStatic
private static boolean isStatic(java.lang.reflect.Method method)
-
isPrivate
private static boolean isPrivate(java.lang.reflect.Method method)
-
readObjectForSerialization
public java.lang.invoke.MethodHandle readObjectForSerialization(java.lang.Class<?> cl)
Description copied from class:BridgeBaseReturns a method handle to allow invocation of the specified class's readObject method.- Specified by:
readObjectForSerializationin classBridgeBase- Parameters:
cl- the class containing the method
-
readResolveForSerialization
public java.lang.invoke.MethodHandle readResolveForSerialization(java.lang.Class<?> cl)
Description copied from class:BridgeBaseReturns a method handle to allow invocation of the specified class's readResolve method.- Specified by:
readResolveForSerializationin classBridgeBase- Parameters:
cl- the class containing the method
-
getInheritableMethod
private static java.lang.reflect.Method getInheritableMethod(java.lang.Class<?> cl, java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>... argTypes)
-
getMatchingMethod
private static java.lang.reflect.Method getMatchingMethod(java.lang.Class<?> cl, java.lang.String name, java.lang.Class<?> returnType, java.lang.Class<?>[] argTypes)
-
isMethodInheritableBy
private static boolean isMethodInheritableBy(java.lang.Class<?> callingClass, java.lang.reflect.Method method)
-
packageEquals
private static boolean packageEquals(java.lang.Class<?> cl1, java.lang.Class<?> cl2)Returns true if classes are defined in the same package, false Copied from the Merlin java.io.ObjectStreamClass.
-
writeReplaceForSerialization
public java.lang.invoke.MethodHandle writeReplaceForSerialization(java.lang.Class<?> cl)
Description copied from class:BridgeBaseReturns a method handle to allow invocation of the specified class's writeReplace method.- Specified by:
writeReplaceForSerializationin classBridgeBase- Parameters:
cl- the class containing the method
-
newOptionalDataExceptionForSerialization
public java.io.OptionalDataException newOptionalDataExceptionForSerialization(boolean endOfData)
Description copied from class:BridgeBaseReturn a new OptionalDataException instance.- Specified by:
newOptionalDataExceptionForSerializationin classBridgeBase- Returns:
- a new OptionalDataException instance
-
-