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 useServiceLoader
for finding an instantiator implementation. Deployment will fail if multiple candidates are returningtrue
frominit(VaadinService)
. If no candidate is found,DefaultInstantiator
will be used. It is possible to override this mechanism by overridingVaadinService.createInstantiator()
.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description <T extends Component>
TcreateComponent(Class<T> componentClass)
Creates an instance of a component by itscomponentClass
.default <T extends HasElement>
TcreateRouteTarget(Class<T> routeTargetType, NavigationEvent event)
Creates an instance of a navigation target or router layout.static Instantiator
get(UI ui)
Gets the instantiator to use for the given UI.default Stream<BootstrapListener>
getBootstrapListeners(Stream<BootstrapListener> serviceInitListeners)
Deprecated.Since 3.0, this API is deprecated in favor ofgetIndexHtmlRequestListeners(Stream)
when using client-side bootstrappingdefault Stream<DependencyFilter>
getDependencyFilters(Stream<DependencyFilter> serviceInitFilters)
Processes the available dependency filters.default I18NProvider
getI18NProvider()
Get the I18NProvider if one has been defined.default Stream<IndexHtmlRequestListener>
getIndexHtmlRequestListeners(Stream<IndexHtmlRequestListener> indexHtmlRequestListeners)
Processes the available Index HTML request listeners.<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.Stream<VaadinServiceInitListener>
getServiceInitListeners()
Gets all service init listeners to use.boolean
init(VaadinService service)
Deprecated.TheInstantiator
instance should be created by anInstantiatorFactory
which should just returnnull
if the providedservice
can't be handled by it
-
-
-
Method Detail
-
init
@Deprecated boolean init(VaadinService service)
Deprecated.TheInstantiator
instance should be created by anInstantiatorFactory
which should just returnnull
if the providedservice
can't be handled by itInitializes this instantiator. This method is run only once and before running any other method. An implementation can opt-out from being used by returningfalse
. 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 defaultServiceLoader
convention. This can be done by including the items fromDefaultInstantiator.getServiceInitListeners()
in the returned stream.- Returns:
- stream of service init listeners, not
null
-
getBootstrapListeners
@Deprecated default Stream<BootstrapListener> getBootstrapListeners(Stream<BootstrapListener> serviceInitListeners)
Deprecated.Since 3.0, this API is deprecated in favor ofgetIndexHtmlRequestListeners(Stream)
when using client-side bootstrappingProcesses the available bootstrap listeners. This method can supplement the set of bootstrap listeners provided byVaadinServiceInitListener
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:
serviceInitListeners
- a stream of bootstrap listeners provided by service init listeners, notnull
- Returns:
- a stream of all bootstrap listeners to use, 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 byVaadinServiceInitListener
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, notnull
- 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 byVaadinServiceInitListener
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, notnull
- 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, notnull
- 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, notnull
event
- the navigation event for which the instance is created, notnull
- Returns:
- the created instance, not
null
-
createComponent
<T extends Component> T createComponent(Class<T> componentClass)
Creates an instance of a component by itscomponentClass
.- Type Parameters:
T
- the component type- Parameters:
componentClass
- the instance type to create, notnull
- 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, notnull
- Returns:
- the instantiator, not
null
-
getI18NProvider
default I18NProvider getI18NProvider()
Get the I18NProvider if one has been defined.- Returns:
- I18NProvier instance
-
-