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)
The code that calls Bridge.get() must have the following Permissions:
  • 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.

  • Method Details

    • 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:
      SecurityException - if the caller does not have the required permissions and the caller has a non-null security manager.
    • getLatestUserDefinedLoader

      public final ClassLoader 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 class BridgeBase
    • newConstructorForExternalization

      public final <T> Constructor<T> newConstructorForExternalization(Class<T> cl)
      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 class BridgeBase
      Parameters:
      cl - the class
    • 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 class BridgeBase
      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> Constructor<T> newConstructorForSerialization(Class<T> aClass)
      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 class BridgeBase
      Parameters:
      aClass - the class for which a constructor should be returned.
    • hasStaticInitializerForSerialization

      public boolean hasStaticInitializerForSerialization(Class<?> cl)
      Description copied from class: BridgeBase
      Returns true if the given class defines a static initializer method, false otherwise.
      Specified by:
      hasStaticInitializerForSerialization in class BridgeBase
    • writeObjectForSerialization

      public MethodHandle writeObjectForSerialization(Class<?> cl)
      Description copied from class: BridgeBase
      Returns a method handle to allow invocation of the specified class's writeObject method.
      Specified by:
      writeObjectForSerialization in class BridgeBase
      Parameters:
      cl - the class containing the method
    • readObjectForSerialization

      public MethodHandle readObjectForSerialization(Class<?> cl)
      Description copied from class: BridgeBase
      Returns a method handle to allow invocation of the specified class's readObject method.
      Specified by:
      readObjectForSerialization in class BridgeBase
      Parameters:
      cl - the class containing the method
    • readResolveForSerialization

      public MethodHandle readResolveForSerialization(Class<?> cl)
      Description copied from class: BridgeBase
      Returns a method handle to allow invocation of the specified class's readResolve method.
      Specified by:
      readResolveForSerialization in class BridgeBase
      Parameters:
      cl - the class containing the method
    • writeReplaceForSerialization

      public MethodHandle writeReplaceForSerialization(Class<?> cl)
      Description copied from class: BridgeBase
      Returns a method handle to allow invocation of the specified class's writeReplace method.
      Specified by:
      writeReplaceForSerialization in class BridgeBase
      Parameters:
      cl - the class containing the method
    • newOptionalDataExceptionForSerialization

      public OptionalDataException newOptionalDataExceptionForSerialization(boolean endOfData)
      Description copied from class: BridgeBase
      Return a new OptionalDataException instance.
      Specified by:
      newOptionalDataExceptionForSerialization in class BridgeBase
      Returns:
      a new OptionalDataException instance