Interface EnhancementEnvironment

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface EnhancementEnvironment

Resolves class-file resources for an EnhancementSession without defining application classes. A resource may come from a class loader, build output, an archive, or another bytecode source. The contract has no dependency on a particular bytecode provider.

Bytes supplied directly to an enhancement or discovery operation take precedence for that class. Other classes are resolved through this environment. Sessions may cache these resolutions; after replacing resources, the caller must invoke EnhancementSession.invalidateMetadata() before using the changed resource view. Changes to persistence mappings require a new session.

Environments are borrowed by sessions. The owner manages their resource lifetime; closing a session does not close its environment or class loader. Implementations must support concurrent resolution when their sessions are used concurrently.

Since:
8.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a resource view using ClassLoader.getResourceAsStream().
    byte[]
    locate(String className)
    Resolves the bytes of one class without loading or initializing it.
  • Method Details

    • locate

      byte[] locate(String className) throws IOException
      Resolves the bytes of one class without loading or initializing it.
      Parameters:
      className - a binary class name, for example com.acme.Book or com.acme.Book$Details
      Returns:
      the class-file bytes, or null if the resource is absent; the bytes must remain stable while the enhancement operation consumes them
      Throws:
      IOException - if resource access fails, as distinct from an absent resource
    • forClassLoader

      static EnhancementEnvironment forClassLoader(ClassLoader loader)
      Creates a resource view using ClassLoader.getResourceAsStream(). The loader is borrowed and is never closed by the returned environment or its sessions. Each lookup opens and closes its own resource stream.
      Parameters:
      loader - the resource loader, or null to use the platform loader's resource view, which also exposes bootstrap resources
      Returns:
      an environment resolving binary names as .class resource paths