Class ClassDefiner


  • public final class ClassDefiner
    extends java.lang.Object
    A hook for frameworks which need to define additional classes to a module's class loader.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass, java.lang.String className, byte[] classBytes)
      Define a class using the module and protection domain of an existing class.
      java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass, java.lang.String className, byte[] classBytes, int off, int len)
      Define a class using the module and protection domain of an existing class.
      java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass, java.lang.String className, java.nio.ByteBuffer classBytes)
      Define a class using the module and protection domain of an existing class.
      java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass, java.lang.String className, java.security.ProtectionDomain protectionDomain, byte[] classBytes)
      Define a class using the module of an existing class.
      java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass, java.lang.String className, java.security.ProtectionDomain protectionDomain, byte[] classBytes, int off, int len)
      Define a class using the module of an existing class.
      java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass, java.lang.String className, java.security.ProtectionDomain protectionDomain, java.nio.ByteBuffer classBytes)
      Define a class using the module of an existing class.
      java.lang.Class<?> defineClass​(Module module, java.lang.String className, java.security.ProtectionDomain protectionDomain, byte[] classBytes)
      Define a class.
      java.lang.Class<?> defineClass​(Module module, java.lang.String className, java.security.ProtectionDomain protectionDomain, byte[] classBytes, int off, int len)
      Define a class.
      java.lang.Class<?> defineClass​(Module module, java.lang.String className, java.security.ProtectionDomain protectionDomain, java.nio.ByteBuffer classBytes)
      Define a class.
      static ClassDefiner getInstance()
      Get the class definer instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass,
                                              java.lang.String className,
                                              java.nio.ByteBuffer classBytes)
        Define a class using the module and protection domain of an existing class.
        Parameters:
        originalClass - the existing class (must not be null)
        className - the new class name (must not be null)
        classBytes - the new class bytes (must not be null)
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass,
                                              java.lang.String className,
                                              byte[] classBytes,
                                              int off,
                                              int len)
        Define a class using the module and protection domain of an existing class.
        Parameters:
        originalClass - the existing class (must not be null)
        className - the new class name (must not be null)
        classBytes - the new class bytes (must not be null)
        off - the offset into the classBytes array
        len - the number of bytes to use from the classBytes array
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass,
                                              java.lang.String className,
                                              byte[] classBytes)
        Define a class using the module and protection domain of an existing class.
        Parameters:
        originalClass - the existing class (must not be null)
        className - the new class name (must not be null)
        classBytes - the new class bytes (must not be null)
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass,
                                              java.lang.String className,
                                              java.security.ProtectionDomain protectionDomain,
                                              java.nio.ByteBuffer classBytes)
        Define a class using the module of an existing class.
        Parameters:
        originalClass - the existing class (must not be null)
        className - the new class name (must not be null)
        protectionDomain - the protection domain of the new class (must not be null)
        classBytes - the new class bytes (must not be null)
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass,
                                              java.lang.String className,
                                              java.security.ProtectionDomain protectionDomain,
                                              byte[] classBytes,
                                              int off,
                                              int len)
        Define a class using the module of an existing class.
        Parameters:
        originalClass - the existing class (must not be null)
        className - the new class name (must not be null)
        protectionDomain - the protection domain of the new class (must not be null)
        classBytes - the new class bytes (must not be null)
        off - the offset into the classBytes array
        len - the number of bytes to use from the classBytes array
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(java.lang.Class<?> originalClass,
                                              java.lang.String className,
                                              java.security.ProtectionDomain protectionDomain,
                                              byte[] classBytes)
        Define a class using the module of an existing class.
        Parameters:
        originalClass - the existing class (must not be null)
        className - the new class name (must not be null)
        protectionDomain - the protection domain of the new class (must not be null)
        classBytes - the new class bytes (must not be null)
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(Module module,
                                              java.lang.String className,
                                              java.security.ProtectionDomain protectionDomain,
                                              java.nio.ByteBuffer classBytes)
        Define a class.
        Parameters:
        module - the module to define the class to (must not be null)
        className - the new class name (must not be null)
        protectionDomain - the protection domain of the new class (must not be null)
        classBytes - the new class bytes (must not be null)
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(Module module,
                                              java.lang.String className,
                                              java.security.ProtectionDomain protectionDomain,
                                              byte[] classBytes,
                                              int off,
                                              int len)
        Define a class.
        Parameters:
        module - the module to define the class to (must not be null)
        className - the new class name (must not be null)
        protectionDomain - the protection domain of the new class (must not be null)
        classBytes - the new class bytes (must not be null)
        off - the offset into the classBytes array
        len - the number of bytes to use from the classBytes array
        Returns:
        the defined class (not null)
      • defineClass

        public java.lang.Class<?> defineClass​(Module module,
                                              java.lang.String className,
                                              java.security.ProtectionDomain protectionDomain,
                                              byte[] classBytes)
        Define a class.
        Parameters:
        module - the module to define the class to (must not be null)
        className - the new class name (must not be null)
        protectionDomain - the protection domain of the new class (must not be null)
        classBytes - the new class bytes (must not be null)
        Returns:
        the defined class (not null)
      • getInstance

        public static ClassDefiner getInstance()
        Get the class definer instance. The caller must have the createClassLoader RuntimePermission.
        Returns:
        the singleton class definer instance (not null)