Interface Instantiator

  • All Superinterfaces:
    Serializable
    All Known Implementing Classes:
    DefaultInstantiator

    public interface Instantiator
    extends Serializable
    Delegate for discovering, creating and managing instances of various types used by Flow. Dependency injection frameworks can provide an implementation that manages instances according to the conventions of that framework.

    VaadinService will by default use ServiceLoader for finding an instantiator implementation. Deployment will fail if multiple candidates are returning true from init(VaadinService). If no candidate is found, DefaultInstantiator will be used. It is possible to override this mechanism by overriding VaadinService.createInstantiator().

    Since:
    1.0
    Author:
    Vaadin Ltd
    • Method Detail

      • init

        @Deprecated
        boolean init​(VaadinService service)
        Deprecated.
        The Instantiator instance should be created by an InstantiatorFactory which should just return null if the provided service can't be handled by it
        Initializes this instantiator. This method is run only once and before running any other method. An implementation can opt-out from being used by returning false. It is recommended that all implementations provide a way for application developers to disable an implementation so that it can be present on the classpath without preventing the application from being deployed in cases when multiple candidates are available.
        Parameters:
        service - the Vaadin service for which this instance is initialized
        Returns:
        true if this instance should be considered as a candidate for usage for the provided service; false to opt-out from the selection process
      • getServiceInitListeners

        Stream<VaadinServiceInitListener> getServiceInitListeners()
        Gets all service init listeners to use. In addition to listeners defined in some way native to a specific instantiator, it is also recommended to support the default ServiceLoader convention. This can be done by including the items from DefaultInstantiator.getServiceInitListeners() in the returned stream.
        Returns:
        stream of service init listeners, not null
      • getIndexHtmlRequestListeners

        default Stream<IndexHtmlRequestListener> getIndexHtmlRequestListeners​(Stream<IndexHtmlRequestListener> indexHtmlRequestListeners)
        Processes the available Index HTML request listeners. This method can supplement the set of Index HTML request listeners provided by VaadinServiceInitListener implementations.

        The default implementation returns the original listeners without changes.

        The order of the listeners inside the stream defines the order of the execution of those listeners by the VaadinService.modifyBootstrapPage(BootstrapPageResponse) method.

        Parameters:
        indexHtmlRequestListeners - a stream of Index HTML request listeners provided by service init listeners, not null
        Returns:
        a stream of all Index HTML request listeners to use, not null
      • getDependencyFilters

        default Stream<DependencyFilter> getDependencyFilters​(Stream<DependencyFilter> serviceInitFilters)
        Processes the available dependency filters. This method can supplement the set of dependency filters provided by VaadinServiceInitListener implementations.

        The default implementation returns the original handlers without changes.

        The order of the filters inside the stream defines the order of the execution of those listeners by the UidlWriter.createUidl(UI, boolean) method.

        Parameters:
        serviceInitFilters - a stream of dependency filters provided by service init listeners, not null
        Returns:
        a stream of all dependency filters to use, not null
      • getOrCreate

        <T> T getOrCreate​(Class<T> type)
        Provides an instance of any given type, this is an abstraction that allows to make use of DI-frameworks from add-ons.

        How the object is created and whether it is being cached or not is up to the implementation.

        Type Parameters:
        T - the type of the instance to create
        Parameters:
        type - the instance type to create, not null
        Returns:
        an instance of the given type
      • createRouteTarget

        default <T extends HasElement> T createRouteTarget​(Class<T> routeTargetType,
                                                           NavigationEvent event)
        Creates an instance of a navigation target or router layout. This method is not called in cases when a component instance is reused when navigating.
        Type Parameters:
        T - the route target type
        Parameters:
        routeTargetType - the instance type to create, not null
        event - the navigation event for which the instance is created, not null
        Returns:
        the created instance, not null
      • createComponent

        <T extends Component> T createComponent​(Class<T> componentClass)
        Creates an instance of a component by its componentClass.
        Type Parameters:
        T - the component type
        Parameters:
        componentClass - the instance type to create, not null
        Returns:
        the created instance, not null
      • get

        static Instantiator get​(UI ui)
        Gets the instantiator to use for the given UI.
        Parameters:
        ui - the attached UI for which to find an instantiator, not null
        Returns:
        the instantiator, not null
      • getI18NProvider

        default I18NProvider getI18NProvider()
        Get the I18NProvider if one has been defined.
        Returns:
        I18NProvier instance