Package org.jboss.shrinkwrap.impl.base
Class ServiceExtensionLoader
java.lang.Object
org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader
- All Implemented Interfaces:
ExtensionLoader
ServiceExtensionLoader
This class is the default strategy to load extensions when an instance of
ExtensionLoader is not provided to
the ConfigurationBuilder and the ConfigurationBuilder.build() method is invoked. If the
ConfigurationBuilder doesn't provide any ClassLoader, ConfigurationBuilder.build() defaults
to a one-element collection holding the TCCL. The classLoaders are used to find the
provider-configuration file for the extension to be loaded in META-INF/services/. This provider-configuration file is
used to make an instance of the SPI implementation and cached in cache.- Version:
- $Revision: $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Iterable<ClassLoader> ClassLoader used for loading extensionsprivate Map<Class<?>, ExtensionWrapper> private static final LoggerLogger -
Constructor Summary
ConstructorsConstructorDescriptionServiceExtensionLoader(Iterable<ClassLoader> classLoaders) Creates a new instance, using the specifiedClassLoaders to create extensions -
Method Summary
Modifier and TypeMethodDescription<T extends Assignable>
ServiceExtensionLoaderaddOverride(Class<T> extensionClass, Class<? extends T> extensionImplClass) Add a Override to the normal Extension loading.(package private) voidaddToCache(Class<?> extensionClass, Class<?> extensionImplClass) private <T extends Assignable>
TcreateExtension(Class<T> extensionImplClass, Archive<?> archive) Creates an instance ofextensionImplClassusingarchiveas the parameter for its one-argument list constructor.private <T extends Assignable>
TcreateFromCache(Class<T> extensionClass, Archive<?> archive) private <T extends Assignable>
TcreateFromLoadExtension(Class<T> extensionClass, Archive<?> archive) Creates a new instance of aextensionClassimplementation.private <T extends Assignable>
Constructor<T> findConstructor(Class<T> extensionImplClass) Finds a constructor with a one-argument list's element which implementsArchive.private <T extends Assignable>
InputStreamfindExtensionImpl(Class<T> extensionClass) Iterates through the classloaders to load the provider-configuration file forextensionClassin META-INF/services/ using its binary name.<T extends Archive<T>>
ArchiveFormatGets theArchiveFormatfor the given type from the extensionMappingprivate Iterable<ClassLoader> <T extends Assignable>
StringgetExtensionFromExtensionMapping(Class<T> type) Gets the extension for the given type from the extensionMapping(package private) <T extends Assignable>
Class<T> getFromCache(Class<T> extensionClass) (package private) booleanbooleanisOverriden(Class<?> extensionClass) Check to see if a specific extension interface is beeing overloaded<T extends Assignable>
TLoad a Extension.private <T extends Assignable>
Class<T> loadExtension(ExtensionWrapper extensionWrapper) Loads the implementation class hold inExtensionWrapper.implementingClassNameprivate <T extends Assignable>
Class<T> loadExtensionClass(String extensionClassName) Delegates class loading ofextensionClassNametoClassLoaderSearchUtilDelegator.findClassFromClassLoaders(String, Iterable)passing theextensionClassNameand the instance'sclassLoaders.private <T extends Assignable>
ExtensionWrapperloadExtensionMapping(Class<T> extensionClass) Finds the SPI configuration, wraps it into aExtensionWrapperand loads it toextensionMappings.private <T extends Assignable>
ExtensionWrapperloadExtensionWrapper(InputStream extensionStream, Class<T> extensionClass) Wraps the provider-configuration fileextensionStream, the SPIextensionClassand its implementation class name into aExtensionWrapperinstance.
-
Field Details
-
log
Logger -
cache
-
extensionMappings
-
classLoaders
ClassLoader used for loading extensions
-
-
Constructor Details
-
ServiceExtensionLoader
Creates a new instance, using the specifiedClassLoaders to create extensions- Parameters:
classLoaders-- Throws:
IllegalArgumentException- If theClassLoaderis not specified
-
-
Method Details
-
load
public <T extends Assignable> T load(Class<T> extensionClass, Archive<?> baseArchive) throws UnknownExtensionTypeException Load a Extension.- Specified by:
loadin interfaceExtensionLoader- Type Parameters:
T-- Parameters:
extensionClass- The Extension interfacebaseArchive- The base archive to use- Returns:
- a
- Throws:
UnknownExtensionTypeException- See Also:
-
isCached
-
createFromCache
-
addToCache
-
getFromCache
-
addOverride
public <T extends Assignable> ServiceExtensionLoader addOverride(Class<T> extensionClass, Class<? extends T> extensionImplClass) Add a Override to the normal Extension loading. If a specific class is found to be overridden, the class will not be loaded using the normal strategy.- Specified by:
addOverridein interfaceExtensionLoader- Type Parameters:
T- The type of Extension- Parameters:
extensionClass- The Extension interface classextensionImplClass- The Extension implementation class- Returns:
- this ExtensionLoader
- See Also:
-
getExtensionFromExtensionMapping
Gets the extension for the given type from the extensionMapping- Specified by:
getExtensionFromExtensionMappingin interfaceExtensionLoader- Type Parameters:
T- The type of Extension- Parameters:
type- The Extension interface class- Returns:
- the filename extension
- See Also:
-
getArchiveFormatFromExtensionMapping
Gets theArchiveFormatfor the given type from the extensionMapping- Specified by:
getArchiveFormatFromExtensionMappingin interfaceExtensionLoader- Type Parameters:
T- The type of Extension- Parameters:
type- The Extension interface class- Returns:
- the archive format
- See Also:
-
isOverriden
Check to see if a specific extension interface is beeing overloaded- Parameters:
extensionClass- The ExtensionType interface class- Returns:
- true if found
-
createFromLoadExtension
private <T extends Assignable> T createFromLoadExtension(Class<T> extensionClass, Archive<?> archive) Creates a new instance of aextensionClassimplementation. The implementation class is found in a provider-configuration file in META-INF/services/- Type Parameters:
T-- Parameters:
extensionClass-archive-- Returns:
- an instance of the
extensionClass' implementation.
-
loadExtension
Loads the implementation class hold inExtensionWrapper.implementingClassName- Type Parameters:
T-- Parameters:
extensionWrapper-- Returns:
-
loadExtensionMapping
Finds the SPI configuration, wraps it into aExtensionWrapperand loads it toextensionMappings.- Type Parameters:
T-- Parameters:
extensionClass-- Returns:
-
findExtensionImpl
Iterates through the classloaders to load the provider-configuration file forextensionClassin META-INF/services/ using its binary name.- Type Parameters:
T-- Parameters:
extensionClass- SPI type for which the configuration file is looked for- Returns:
- An
InputStreamrepresentingextensionClass's configuration file
-
loadExtensionWrapper
private <T extends Assignable> ExtensionWrapper loadExtensionWrapper(InputStream extensionStream, Class<T> extensionClass) Wraps the provider-configuration fileextensionStream, the SPIextensionClassand its implementation class name into aExtensionWrapperinstance.- Type Parameters:
T-- Parameters:
extensionStream- - a bytes stream representation of the provider-configuration fileextensionClass- - SPI type- Returns:
- a
ExtensionWrapperinstance
-
loadExtensionClass
Delegates class loading ofextensionClassNametoClassLoaderSearchUtilDelegator.findClassFromClassLoaders(String, Iterable)passing theextensionClassNameand the instance'sclassLoaders.- Type Parameters:
T-- Parameters:
extensionClassName-- Returns:
-
createExtension
Creates an instance ofextensionImplClassusingarchiveas the parameter for its one-argument list constructor.- Type Parameters:
T-- Parameters:
extensionImplClass-archive-- Returns:
-
findConstructor
Finds a constructor with a one-argument list's element which implementsArchive.- Type Parameters:
T-- Parameters:
extensionImplClass- - Implementation ofAssignablewith a one-argument list's element which implementsArchive.- Returns:
-
getClassLoaders
-