Class ByteArrayClassLoader.ChildFirst

  • Enclosing class:
    ByteArrayClassLoader

    public static class ByteArrayClassLoader.ChildFirst
    extends ByteArrayClassLoader

    A ByteArrayClassLoader which applies child-first semantics for the given type definitions.

    Important: Package definitions remain their parent-first semantics as loaded package definitions do not expose their class loaders. Also, it is not possible to make this class or its subclass parallel-capable as the loading strategy is overridden.

    • Field Detail

      • CLASS_FILE_SUFFIX

        private static final java.lang.String CLASS_FILE_SUFFIX
        The suffix of files in the Java class file format.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          boolean sealed,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        sealed - true if this class loader is sealed.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions,
                          ByteArrayClassLoader.PersistenceHandler persistenceHandler)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
        persistenceHandler - The persistence handler of this class loader.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          boolean sealed,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions,
                          ByteArrayClassLoader.PersistenceHandler persistenceHandler)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        sealed - true if this class loader is sealed.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
        persistenceHandler - The persistence handler of this class loader.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions,
                          java.security.ProtectionDomain protectionDomain,
                          ByteArrayClassLoader.PersistenceHandler persistenceHandler,
                          PackageDefinitionStrategy packageDefinitionStrategy)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
        protectionDomain - The protection domain to apply where null references an implicit protection domain.
        persistenceHandler - The persistence handler of this class loader.
        packageDefinitionStrategy - The package definer to be queried for package definitions.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          boolean sealed,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions,
                          java.security.ProtectionDomain protectionDomain,
                          ByteArrayClassLoader.PersistenceHandler persistenceHandler,
                          PackageDefinitionStrategy packageDefinitionStrategy)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        sealed - true if this class loader is sealed.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
        protectionDomain - The protection domain to apply where null references an implicit protection domain.
        persistenceHandler - The persistence handler of this class loader.
        packageDefinitionStrategy - The package definer to be queried for package definitions.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions,
                          java.security.ProtectionDomain protectionDomain,
                          ByteArrayClassLoader.PersistenceHandler persistenceHandler,
                          PackageDefinitionStrategy packageDefinitionStrategy,
                          java.lang.instrument.ClassFileTransformer classFileTransformer)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
        protectionDomain - The protection domain to apply where null references an implicit protection domain.
        persistenceHandler - The persistence handler of this class loader.
        packageDefinitionStrategy - The package definer to be queried for package definitions.
        classFileTransformer - The class file transformer to apply on loaded classes.
      • ChildFirst

        public ChildFirst​(java.lang.ClassLoader parent,
                          boolean sealed,
                          java.util.Map<java.lang.String,​byte[]> typeDefinitions,
                          java.security.ProtectionDomain protectionDomain,
                          ByteArrayClassLoader.PersistenceHandler persistenceHandler,
                          PackageDefinitionStrategy packageDefinitionStrategy,
                          java.lang.instrument.ClassFileTransformer classFileTransformer)
        Creates a new child-first byte array class loader.
        Parameters:
        parent - The ClassLoader that is the parent of this class loader.
        sealed - true if this class loader is sealed.
        typeDefinitions - A map of fully qualified class names pointing to their binary representations.
        protectionDomain - The protection domain to apply where null references an implicit protection domain.
        persistenceHandler - The persistence handler of this class loader.
        packageDefinitionStrategy - The package definer to be queried for package definitions.
        classFileTransformer - The class file transformer to apply on loaded classes.
    • Method Detail

      • load

        public static java.util.Map<TypeDescription,​java.lang.Class<?>> load​(java.lang.ClassLoader classLoader,
                                                                                   java.util.Map<TypeDescription,​byte[]> types)
        Loads a given set of class descriptions and their binary representations using a child-first class loader.
        Parameters:
        classLoader - The parent class loader.
        types - The unloaded types to be loaded.
        Returns:
        A map of the given type descriptions pointing to their loaded representations.
      • load

        public static java.util.Map<TypeDescription,​java.lang.Class<?>> load​(java.lang.ClassLoader classLoader,
                                                                                   java.util.Map<TypeDescription,​byte[]> types,
                                                                                   java.security.ProtectionDomain protectionDomain,
                                                                                   ByteArrayClassLoader.PersistenceHandler persistenceHandler,
                                                                                   PackageDefinitionStrategy packageDefinitionStrategy,
                                                                                   boolean forbidExisting,
                                                                                   boolean sealed)
        Loads a given set of class descriptions and their binary representations using a child-first class loader.
        Parameters:
        classLoader - The parent class loader.
        types - The unloaded types to be loaded.
        protectionDomain - The protection domain to apply where null references an implicit protection domain.
        persistenceHandler - The persistence handler of the created class loader.
        packageDefinitionStrategy - The package definer to be queried for package definitions.
        forbidExisting - true if the class loading should throw an exception if a class was already loaded by a parent class loader.
        sealed - true if the class loader should be sealed.
        Returns:
        A map of the given type descriptions pointing to their loaded representations.
      • loadClass

        protected java.lang.Class<?> loadClass​(java.lang.String name,
                                               boolean resolve)
                                        throws java.lang.ClassNotFoundException
        Overrides:
        loadClass in class java.lang.ClassLoader
        Throws:
        java.lang.ClassNotFoundException
      • getResource

        public java.net.URL getResource​(java.lang.String name)
        Overrides:
        getResource in class java.lang.ClassLoader
      • getResources

        public java.util.Enumeration<java.net.URL> getResources​(java.lang.String name)
                                                         throws java.io.IOException
        Overrides:
        getResources in class java.lang.ClassLoader
        Throws:
        java.io.IOException
      • isShadowed

        private boolean isShadowed​(java.lang.String resourceName)
        Checks if a resource name represents a class file of a class that was loaded by this class loader.
        Parameters:
        resourceName - The resource name of the class to be exposed as its class file.
        Returns:
        true if this class represents a class that is being loaded by this class loader.