Top Description Fields Constructors Methods
org.apache.catalina.startup

public Class WebappServiceLoader<T>

extends Object
Class Inheritance
Type Parameters
<T>
The type of service to load
Imports
java.io.BufferedReader, .FileNotFoundException, .IOException, .InputStream, .InputStreamReader, java.net.URI, .URISyntaxException, .URL, java.nio.charset.StandardCharsets, java.util.ArrayList, .Collections, .Enumeration, .HashSet, .LinkedHashSet, .List, .Set, java.util.regex.Pattern, jakarta.servlet.ServletContext, org.apache.catalina.Context, org.apache.tomcat.util.scan.JarFactory

A variation of Java's JAR ServiceLoader that respects exclusion rules for web applications.

Primarily intended for use loading ServletContainerInitializers as defined by Servlet 8.2.4. This implementation does not attempt lazy loading as the container is required to introspect all implementations discovered.

If the ServletContext defines ORDERED_LIBS, then only JARs in WEB-INF/lib that are named in that set will be included in the search for provider configuration files; if ORDERED_LIBS is not defined then all JARs will be searched for provider configuration files. Providers defined by resources in the parent ClassLoader will always be returned.

Provider classes will be loaded using the context's ClassLoader.

See Also
jakarta.servlet.ServletContainerInitializer, java.util.ServiceLoader

Field Summary

Modifier and TypeField and Description
private static final String
private final Pattern
private final Context
private static final String
private static final String
private final ServletContext

Constructor Summary

AccessConstructor and Description
public
WebappServiceLoader(Context
the context to use
context
)

Construct a loader to load services from a ServletContext.

Method Summary

Modifier and TypeMethod and Description
public List<T>

Returns:

an unmodifiable collection of service providers
load
(Class<T>
the type of service to load
serviceType
)

Load the providers for a service type.

pack-priv List<T>
loadServices(Class<T> serviceType, LinkedHashSet<String> servicesFound)

pack-priv void
parseConfigFile(LinkedHashSet<String> servicesFound, URL url)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLASSESback to summary
private static final String CLASSES
containerSciFilterPatternback to summary
private final Pattern containerSciFilterPattern
contextback to summary
private final Context context
LIBback to summary
private static final String LIB
SERVICESback to summary
private static final String SERVICES
servletContextback to summary
private final ServletContext servletContext

Constructor Detail

WebappServiceLoaderback to summary
public WebappServiceLoader(Context context)

Construct a loader to load services from a ServletContext.

Parameters
context:Context

the context to use

Method Detail

loadback to summary
public List<T> load(Class<T> serviceType) throws IOException

Load the providers for a service type. Container defined services will be loaded before application defined services in case the application depends on a Container provided service. Note that services are always loaded via the Context (web application) class loader so it is possible for an application to provide an alternative implementation of what would normally be a Container provided service.

Parameters
serviceType:Class<T>

the type of service to load

Returns:List<T>

an unmodifiable collection of service providers

Exceptions
IOException:
if there was a problem loading any service
loadServicesback to summary
pack-priv List<T> loadServices(Class<T> serviceType, LinkedHashSet<String> servicesFound) throws IOException
parseConfigFileback to summary
pack-priv void parseConfigFile(LinkedHashSet<String> servicesFound, URL url) throws IOException