Class ExtensionRegistry



  • @API(status=INTERNAL,
         since="5.0")
    public class ExtensionRegistry
    extends java.lang.Object
    An 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.

    Since:
    5.0
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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>
      java.util.List<E>
      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>
      java.util.List<E>
      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.
      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>
      java.util.stream.Stream<E>
      stream​(java.lang.Class<E> extensionType)
      Stream all Extensions of the specified type that are present in this registry or one of its ancestors.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createRegistryWithDefaultExtensions

        public static ExtensionRegistry createRegistryWithDefaultExtensions​(ConfigurationParameters configParams)
        Factory for creating and populating a new root registry with the default extensions.

        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.

        Parameters:
        configParams - configuration parameters used to retrieve the extension auto-detection flag; never null
        Returns:
        a new ExtensionRegistry; never null
      • createRegistryFrom

        public 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.
        Parameters:
        parentRegistry - the parent registry
        extensionTypes - the types of extensions to be registered in the new registry
        Returns:
        a new ExtensionRegistry; never null
      • stream

        public <E extends Extension> java.util.stream.Stream<E> stream​(java.lang.Class<E> extensionType)
        Stream all Extensions of the specified type that are present in this registry or one of its ancestors.
        Parameters:
        extensionType - the type of Extension to stream
        See Also:
        getReversedExtensions(Class), getExtensions(Class)
      • getExtensions

        public <E extends Extension> java.util.List<E> getExtensions​(java.lang.Class<E> extensionType)
        Get all Extensions of the specified type that are present in this registry or one of its ancestors.
        Parameters:
        extensionType - the type of Extension to get
        See Also:
        getReversedExtensions(Class), stream(Class)
      • getReversedExtensions

        public <E extends Extension> java.util.List<E> 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.
        Parameters:
        extensionType - the type of Extension to get
        See Also:
        getExtensions(Class), stream(Class)
      • registerExtension

        public 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.

        Semantics for Source

        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 via @RegisterExtension, the source object should be the Field that is annotated with @RegisterExtension. Similarly, if an extension is registered programmatically as a lambda expression or method reference, the source object should be the underlying Method that implements the extension API.

        Parameters:
        extension - the extension to register
        source - the source of the extension