Interface ClassResolver


public interface ClassResolver
Platform-neutral strategy for loading classes and classpath resources across the different runtimes that Camel supports (standalone JVM, Spring Boot, Quarkus, OSGi, JBang, and others).

A single CamelContext maintains one ClassResolver instance. Instead of calling Class.forName() or ClassLoader.getResourceAsStream() directly, all Camel internals delegate to this interface so that custom or container-aware class loaders can participate in class resolution without changes to the framework. Additional class loaders can be plugged in at any time via addClassLoader(ClassLoader).

The interface exposes both optional-return (resolveClass(String)) and throwing (resolveMandatoryClass(String)) variants so that callers can choose the appropriate error-handling strategy.

See Also:
  • Method Details

    • addClassLoader

      void addClassLoader(ClassLoader classLoader)
      Adds a custom class loader to use.
      Parameters:
      classLoader - a custom class loader
    • getClassLoaders

      Set<ClassLoader> getClassLoaders()
      Gets the custom class loaders.
    • getClassLoader

      @Nullable ClassLoader getClassLoader(String name)
      Gets a custom class loader by its name
      Parameters:
      name - the name of the custom classloader
      Returns:
      the class loader or null if not found
    • resolveClass

      @Nullable Class<?> resolveClass(String name)
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      Returns:
      the class if resolved, null if not found.
    • resolveClass

      <T> @Nullable Class<T> resolveClass(String name, Class<T> type)
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      type - the expected type of the class
      Returns:
      the class if resolved, null if not found.
    • resolveClass

      @Nullable Class<?> resolveClass(String name, ClassLoader loader)
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      loader - use the provided class loader
      Returns:
      the class if resolved, null if not found.
    • resolveClass

      <T> @Nullable Class<T> resolveClass(String name, Class<T> type, ClassLoader loader)
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      type - the expected type of the class
      loader - use the provided class loader
      Returns:
      the class if resolved, null if not found.
    • resolveMandatoryClass

      Class<?> resolveMandatoryClass(String name) throws ClassNotFoundException
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      Returns:
      the class if resolved, null if not found.
      Throws:
      ClassNotFoundException - is thrown if class not found
    • resolveMandatoryClass

      <T> Class<T> resolveMandatoryClass(String name, Class<T> type) throws ClassNotFoundException
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      type - the expected type of the class
      Returns:
      the class if resolved, null if not found.
      Throws:
      ClassNotFoundException - is thrown if class not found
    • resolveMandatoryClass

      Class<?> resolveMandatoryClass(String name, ClassLoader loader) throws ClassNotFoundException
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      loader - use the provided class loader
      Returns:
      the class if resolved, null if not found.
      Throws:
      ClassNotFoundException - is thrown if class not found
    • resolveMandatoryClass

      <T> Class<T> resolveMandatoryClass(String name, Class<T> type, ClassLoader loader) throws ClassNotFoundException
      Resolves the given class by its name
      Parameters:
      name - full qualified name of class
      type - the expected type of the class
      loader - use the provided class loader
      Returns:
      the class if resolved, null if not found.
      Throws:
      ClassNotFoundException - is thrown if class not found
    • loadResourceAsStream

      @Nullable InputStream loadResourceAsStream(String uri)
      Loads the given resource as a stream
      Parameters:
      uri - the uri of the resource
      Returns:
      as a stream
    • loadResourceAsURL

      @Nullable URL loadResourceAsURL(String uri)
      Loads the given resource as a URL
      Parameters:
      uri - the uri of the resource
      Returns:
      as a URL
    • loadResourcesAsURL

      Enumeration<URL> loadResourcesAsURL(String uri)
      Loads the given resources as a URL from the current bundle/classloader
      Parameters:
      uri - the uri of the resource
      Returns:
      the URLs found on the classpath
    • loadAllResourcesAsURL

      Enumeration<URL> loadAllResourcesAsURL(String uri)
      Loads the given resources as a URL from all bundles/classloaders
      Parameters:
      uri - the uri of the resource
      Returns:
      the URLs found on the classpath