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 Summary
Modifier and TypeMethodDescriptionvoidaddClassLoader(ClassLoader classLoader) Adds a custom class loader to use.@Nullable ClassLoadergetClassLoader(String name) Gets a custom class loader by its nameGets the custom class loaders.Loads the given resources as a URL from all bundles/classloaders@Nullable InputStreamLoads the given resource as a stream@Nullable URLloadResourceAsURL(String uri) Loads the given resource as a URLloadResourcesAsURL(String uri) Loads the given resources as a URL from the current bundle/classloader@Nullable Class<?> resolveClass(String name) Resolves the given class by its name<T> @Nullable Class<T> resolveClass(String name, Class<T> type) Resolves the given class by its name<T> @Nullable Class<T> resolveClass(String name, Class<T> type, ClassLoader loader) Resolves the given class by its name@Nullable Class<?> resolveClass(String name, ClassLoader loader) Resolves the given class by its nameClass<?> resolveMandatoryClass(String name) Resolves the given class by its name<T> Class<T> resolveMandatoryClass(String name, Class<T> type) Resolves the given class by its name<T> Class<T> resolveMandatoryClass(String name, Class<T> type, ClassLoader loader) Resolves the given class by its nameClass<?> resolveMandatoryClass(String name, ClassLoader loader) Resolves the given class by its name
-
Method Details
-
addClassLoader
Adds a custom class loader to use.- Parameters:
classLoader- a custom class loader
-
getClassLoaders
Set<ClassLoader> getClassLoaders()Gets the custom class loaders. -
getClassLoader
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
-
resolveClass
-
resolveClass
Resolves the given class by its name- Parameters:
name- full qualified name of classloader- use the provided class loader- Returns:
- the class if resolved, null if not found.
-
resolveClass
Resolves the given class by its name- Parameters:
name- full qualified name of classtype- the expected type of the classloader- use the provided class loader- Returns:
- the class if resolved, null if not found.
-
resolveMandatoryClass
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
Resolves the given class by its name- Parameters:
name- full qualified name of classtype- the expected type of the class- Returns:
- the class if resolved, null if not found.
- Throws:
ClassNotFoundException- is thrown if class not found
-
resolveMandatoryClass
Resolves the given class by its name- Parameters:
name- full qualified name of classloader- 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 classtype- the expected type of the classloader- use the provided class loader- Returns:
- the class if resolved, null if not found.
- Throws:
ClassNotFoundException- is thrown if class not found
-
loadResourceAsStream
Loads the given resource as a stream- Parameters:
uri- the uri of the resource- Returns:
- as a stream
-
loadResourceAsURL
-
loadResourcesAsURL
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
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
-