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 Logger
Logger -
Constructor Summary
ConstructorsConstructorDescriptionServiceExtensionLoader
(Iterable<ClassLoader> classLoaders) Creates a new instance, using the specifiedClassLoader
s 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) void
addToCache
(Class<?> extensionClass, Class<?> extensionImplClass) private <T extends Assignable>
TcreateExtension
(Class<T> extensionImplClass, Archive<?> archive) Creates an instance ofextensionImplClass
usingarchive
as 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 aextensionClass
implementation.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 forextensionClass
in META-INF/services/ using its binary name.<T extends Archive<T>>
ArchiveFormatGets theArchiveFormat
for 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) boolean
boolean
isOverriden
(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.implementingClassName
private <T extends Assignable>
Class<T> loadExtensionClass
(String extensionClassName) Delegates class loading ofextensionClassName
toClassLoaderSearchUtilDelegator.findClassFromClassLoaders(String, Iterable)
passing theextensionClassName
and the instance'sclassLoaders
.private <T extends Assignable>
ExtensionWrapperloadExtensionMapping
(Class<T> extensionClass) Finds the SPI configuration, wraps it into aExtensionWrapper
and loads it toextensionMappings
.private <T extends Assignable>
ExtensionWrapperloadExtensionWrapper
(InputStream extensionStream, Class<T> extensionClass) Wraps the provider-configuration fileextensionStream
, the SPIextensionClass
and its implementation class name into aExtensionWrapper
instance.
-
Field Details
-
log
Logger -
cache
-
extensionMappings
-
classLoaders
ClassLoader used for loading extensions
-
-
Constructor Details
-
ServiceExtensionLoader
Creates a new instance, using the specifiedClassLoader
s to create extensions- Parameters:
classLoaders
-- Throws:
IllegalArgumentException
- If theClassLoader
is not specified
-
-
Method Details
-
load
public <T extends Assignable> T load(Class<T> extensionClass, Archive<?> baseArchive) throws UnknownExtensionTypeException Load a Extension.- Specified by:
load
in 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:
addOverride
in 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:
getExtensionFromExtensionMapping
in interfaceExtensionLoader
- Type Parameters:
T
- The type of Extension- Parameters:
type
- The Extension interface class- Returns:
- the filename extension
- See Also:
-
getArchiveFormatFromExtensionMapping
Gets theArchiveFormat
for the given type from the extensionMapping- Specified by:
getArchiveFormatFromExtensionMapping
in 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 aextensionClass
implementation. 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 aExtensionWrapper
and loads it toextensionMappings
.- Type Parameters:
T
-- Parameters:
extensionClass
-- Returns:
-
findExtensionImpl
Iterates through the classloaders to load the provider-configuration file forextensionClass
in META-INF/services/ using its binary name.- Type Parameters:
T
-- Parameters:
extensionClass
- SPI type for which the configuration file is looked for- Returns:
- An
InputStream
representingextensionClass
's configuration file
-
loadExtensionWrapper
private <T extends Assignable> ExtensionWrapper loadExtensionWrapper(InputStream extensionStream, Class<T> extensionClass) Wraps the provider-configuration fileextensionStream
, the SPIextensionClass
and its implementation class name into aExtensionWrapper
instance.- Type Parameters:
T
-- Parameters:
extensionStream
- - a bytes stream representation of the provider-configuration fileextensionClass
- - SPI type- Returns:
- a
ExtensionWrapper
instance
-
loadExtensionClass
Delegates class loading ofextensionClassName
toClassLoaderSearchUtilDelegator.findClassFromClassLoaders(String, Iterable)
passing theextensionClassName
and the instance'sclassLoaders
.- Type Parameters:
T
-- Parameters:
extensionClassName
-- Returns:
-
createExtension
Creates an instance ofextensionImplClass
usingarchive
as 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 ofAssignable
with a one-argument list's element which implementsArchive
.- Returns:
-
getClassLoaders
-