@API(status=INTERNAL,
since="5.0")
public class ExtensionRegistry
extends java.lang.Object
ExtensionRegistry
holds all registered extensions (i.e.
instances of Extension
) for a given
Node
.
A registry has a reference to its parent registry, and all lookups are performed first in the current registry itself and then recursively in its ancestors.
Modifier and Type | Field and Description |
---|---|
private static java.util.List<Extension> |
DEFAULT_EXTENSIONS |
private static Logger |
logger |
private ExtensionRegistry |
parent |
private java.util.List<Extension> |
registeredExtensions |
private java.util.Set<java.lang.Class<? extends Extension>> |
registeredExtensionTypes |
Modifier | Constructor and Description |
---|---|
private |
ExtensionRegistry(ExtensionRegistry parent) |
Modifier and Type | Method and Description |
---|---|
static ExtensionRegistry |
createRegistryFrom(ExtensionRegistry parentRegistry,
java.util.List<java.lang.Class<? extends Extension>> extensionTypes)
Factory for creating and populating a new registry from a list of
extension types and a parent registry.
|
static ExtensionRegistry |
createRegistryWithDefaultExtensions(ConfigurationParameters configParams)
Factory for creating and populating a new root registry with the default
extensions.
|
<E extends Extension> |
getExtensions(java.lang.Class<E> extensionType)
Get all
Extensions of the specified type that are present
in this registry or one of its ancestors. |
<E extends Extension> |
getReversedExtensions(java.lang.Class<E> extensionType)
Get all
Extensions of the specified type that are present
in this registry or one of its ancestors, in reverse order. |
private boolean |
isAlreadyRegistered(java.lang.Class<? extends Extension> extensionType)
Determine if the supplied type is already registered in this registry or in a
parent registry.
|
private static void |
registerAutoDetectedExtensions(ExtensionRegistry extensionRegistry) |
private void |
registerDefaultExtension(Extension extension) |
(package private) void |
registerExtension(java.lang.Class<? extends Extension> extensionType)
Instantiate an extension of the given type using its default constructor
and register it in this registry.
|
private void |
registerExtension(Extension extension) |
void |
registerExtension(Extension extension,
java.lang.Object source)
Register the supplied
Extension in this registry, without checking
if an extension of that type already exists in this registry. |
<E extends Extension> |
stream(java.lang.Class<E> extensionType)
Stream all
Extensions of the specified type that are present
in this registry or one of its ancestors. |
private <E extends Extension> |
streamLocal(java.lang.Class<E> extensionType)
Stream all
Extensions of the specified type that are present
in this registry. |
private static final Logger logger
private static final java.util.List<Extension> DEFAULT_EXTENSIONS
private final ExtensionRegistry parent
private final java.util.Set<java.lang.Class<? extends Extension>> registeredExtensionTypes
private final java.util.List<Extension> registeredExtensions
private ExtensionRegistry(ExtensionRegistry parent)
public static ExtensionRegistry createRegistryWithDefaultExtensions(ConfigurationParameters configParams)
If the Constants.EXTENSIONS_AUTODETECTION_ENABLED_PROPERTY_NAME
configuration parameter has been set to true
, extensions will be
auto-detected using Java's ServiceLoader
mechanism and automatically
registered after the default extensions.
configParams
- configuration parameters used to retrieve the extension
auto-detection flag; never null
ExtensionRegistry
; never null
private static void registerAutoDetectedExtensions(ExtensionRegistry extensionRegistry)
public static ExtensionRegistry createRegistryFrom(ExtensionRegistry parentRegistry, java.util.List<java.lang.Class<? extends Extension>> extensionTypes)
parentRegistry
- the parent registryextensionTypes
- the types of extensions to be registered in
the new registryExtensionRegistry
; never null
public <E extends Extension> java.util.stream.Stream<E> stream(java.lang.Class<E> extensionType)
Extensions
of the specified type that are present
in this registry or one of its ancestors.extensionType
- the type of Extension
to streamgetReversedExtensions(Class)
,
getExtensions(Class)
private <E extends Extension> java.util.stream.Stream<E> streamLocal(java.lang.Class<E> extensionType)
Extensions
of the specified type that are present
in this registry.
Extensions in ancestors are ignored.
extensionType
- the type of Extension
to streamgetReversedExtensions(Class)
public <E extends Extension> java.util.List<E> getExtensions(java.lang.Class<E> extensionType)
Extensions
of the specified type that are present
in this registry or one of its ancestors.extensionType
- the type of Extension
to getgetReversedExtensions(Class)
,
stream(Class)
public <E extends Extension> java.util.List<E> getReversedExtensions(java.lang.Class<E> extensionType)
Extensions
of the specified type that are present
in this registry or one of its ancestors, in reverse order.extensionType
- the type of Extension
to getgetExtensions(Class)
,
stream(Class)
private boolean isAlreadyRegistered(java.lang.Class<? extends Extension> extensionType)
void registerExtension(java.lang.Class<? extends Extension> extensionType)
A new Extension
will not be registered if an extension of the
given type already exists in this registry or a parent registry.
extensionType
- the type of extension to registerprivate void registerDefaultExtension(Extension extension)
private void registerExtension(Extension extension)
public void registerExtension(Extension extension, java.lang.Object source)
Extension
in this registry, without checking
if an extension of that type already exists in this registry.
If an extension is registered declaratively via @ExtendWith
,
the source
and the extension
should be the same object. However,
if an extension is registered programmatically — for example, as a lambda
expression or method reference — the source
object should be the
underlying Method
that implements the extension
API, or similar.
extension
- the extension to registersource
- the source of the extension