Interface ClassLoaderService
-
- All Known Implementing Classes:
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl,ClassLoaderServiceTestingImpl,ExtraJavaServicesClassLoaderService,OSGiClassLoaderServiceImpl
public interface ClassLoaderService extends Service, Stoppable
A service for interacting with class loaders.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceClassLoaderService.Work<T>
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> java.lang.Class<T>classForName(java.lang.String className)Locate a class by name.<T> TgenerateProxy(java.lang.reflect.InvocationHandler handler, java.lang.Class... interfaces)<S> java.util.Collection<S>loadJavaServices(java.lang.Class<S> serviceContract)Discovers and instantiates implementations of the named service contract.java.net.URLlocateResource(java.lang.String name)Locate a resource by name (classpath lookup).java.util.List<java.net.URL>locateResources(java.lang.String name)Locate a series of resource by name (classpath lookup).java.io.InputStreamlocateResourceStream(java.lang.String name)Locate a resource by name (classpath lookup) and gets its stream.java.lang.PackagepackageForNameOrNull(java.lang.String packageName)Loading a Package from the classloader.<T> TworkWithClassLoader(ClassLoaderService.Work<T> work)
-
-
-
Method Detail
-
classForName
<T> java.lang.Class<T> classForName(java.lang.String className)
Locate a class by name.- Type Parameters:
T- The returned class type.- Parameters:
className- The name of the class to locate- Returns:
- The class reference
- Throws:
ClassLoadingException- Indicates the class could not be found
-
locateResource
java.net.URL locateResource(java.lang.String name)
Locate a resource by name (classpath lookup).- Parameters:
name- The resource name.- Returns:
- The located URL; may return
nullto indicate the resource was not found
-
locateResourceStream
java.io.InputStream locateResourceStream(java.lang.String name)
Locate a resource by name (classpath lookup) and gets its stream.- Parameters:
name- The resource name.- Returns:
- The stream of the located resource; may return
nullto indicate the resource was not found
-
locateResources
java.util.List<java.net.URL> locateResources(java.lang.String name)
Locate a series of resource by name (classpath lookup).- Parameters:
name- The resource name.- Returns:
- The list of URL matching; may return
nullto indicate the resource was not found
-
loadJavaServices
<S> java.util.Collection<S> loadJavaServices(java.lang.Class<S> serviceContract)
Discovers and instantiates implementations of the named service contract. NOTE : the terms service here is used differently thanService. Instead here we are talking about services as defined byServiceLoader.- Type Parameters:
S- The type of the service contract- Parameters:
serviceContract- The java type defining the service contract- Returns:
- The ordered set of discovered services.
-
generateProxy
<T> T generateProxy(java.lang.reflect.InvocationHandler handler, java.lang.Class... interfaces)
-
packageForNameOrNull
java.lang.Package packageForNameOrNull(java.lang.String packageName)
Loading a Package from the classloader. In case it's not found or an internal error (such as @seeLinkageErroroccurs, we return null rather than throwing an exception. This is significantly different than loading a Class, as in all currently known usages, being unable to load the Package will only result in ignoring annotations on it - which is totally fine when the object doesn't exist. In case of other errors, implementations are expected to log a warning but it's still not treated as a fatal error.- Parameters:
packageName-- Returns:
- the matching Package, or null.
-
workWithClassLoader
<T> T workWithClassLoader(ClassLoaderService.Work<T> work)
-
-