public interface ClassLoaderService extends Service, Stoppable
Modifier and Type | Interface and Description |
---|---|
static interface |
ClassLoaderService.Work<T> |
Modifier and Type | Method and Description |
---|---|
<T> Class<T> |
classForName(String className)
Locate a class by name.
|
<T> T |
generateProxy(InvocationHandler handler,
Class... interfaces) |
<S> Collection<S> |
loadJavaServices(Class<S> serviceContract)
Discovers and instantiates implementations of the named service contract.
|
URL |
locateResource(String name)
Locate a resource by name (classpath lookup).
|
List<URL> |
locateResources(String name)
Locate a series of resource by name (classpath lookup).
|
InputStream |
locateResourceStream(String name)
Locate a resource by name (classpath lookup) and gets its stream.
|
Package |
packageForNameOrNull(String packageName)
Loading a Package from the classloader.
|
<T> T |
workWithClassLoader(ClassLoaderService.Work<T> work) |
<T> Class<T> classForName(String className)
T
- The returned class type.className
- The name of the class to locateClassLoadingException
- Indicates the class could not be foundURL locateResource(String name)
name
- The resource name.null
to indicate the resource was not foundInputStream locateResourceStream(String name)
name
- The resource name.null
to indicate the resource was not foundList<URL> locateResources(String name)
name
- The resource name.null
to indicate the resource was not found<S> Collection<S> loadJavaServices(Class<S> serviceContract)
Service
. Instead here we are talking about
services as defined by ServiceLoader
.S
- The type of the service contractserviceContract
- The java type defining the service contract<T> T generateProxy(InvocationHandler handler, Class... interfaces)
Package packageForNameOrNull(String packageName)
LinkageError
occurs, 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.packageName
- <T> T workWithClassLoader(ClassLoaderService.Work<T> work)
Copyright © 2001-2022 Red Hat, Inc. All Rights Reserved.