Package com.vaadin.flow.di
Class DefaultInstantiator
- java.lang.Object
-
- com.vaadin.flow.di.DefaultInstantiator
-
- All Implemented Interfaces:
Instantiator
,Serializable
public class DefaultInstantiator extends Object implements Instantiator
Default instantiator that is used if no other instantiator has been registered. This implementation uses vanilla Java mechanisms such asClass.newInstance()
andServiceLoader
.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultInstantiator(VaadinService service)
Creates a new instantiator for the given service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Component>
TcreateComponent(Class<T> componentClass)
Creates an instance of a component by itscomponentClass
.I18NProvider
getI18NProvider()
Get the I18NProvider if one has been defined.<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.static Stream<VaadinServiceInitListener>
getServiceLoaderListeners(ClassLoader classloader)
Helper for finding service init listeners usingServiceLoader
.boolean
init(VaadinService service)
Initializes this instantiator.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.di.Instantiator
createRouteTarget, getBootstrapListeners, getDependencyFilters, getIndexHtmlRequestListeners
-
-
-
-
Constructor Detail
-
DefaultInstantiator
public DefaultInstantiator(VaadinService service)
Creates a new instantiator for the given service.- Parameters:
service
- the service to use
-
-
Method Detail
-
init
public boolean init(VaadinService service)
Description copied from interface:Instantiator
Initializes 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.- Specified by:
init
in interfaceInstantiator
- 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
public Stream<VaadinServiceInitListener> getServiceInitListeners()
Description copied from interface:Instantiator
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 fromgetServiceInitListeners()
in the returned stream.- Specified by:
getServiceInitListeners
in interfaceInstantiator
- Returns:
- stream of service init listeners, not
null
-
getOrCreate
public <T> T getOrCreate(Class<T> type)
Description copied from interface:Instantiator
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.
- Specified by:
getOrCreate
in interfaceInstantiator
- 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
-
createComponent
public <T extends Component> T createComponent(Class<T> componentClass)
Description copied from interface:Instantiator
Creates an instance of a component by itscomponentClass
.- Specified by:
createComponent
in interfaceInstantiator
- Type Parameters:
T
- the component type- Parameters:
componentClass
- the instance type to create, notnull
- Returns:
- the created instance, not
null
-
getServiceLoaderListeners
public static Stream<VaadinServiceInitListener> getServiceLoaderListeners(ClassLoader classloader)
Helper for finding service init listeners usingServiceLoader
.- Parameters:
classloader
- the classloader to use for finding the listeners- Returns:
- a stream of service init listeners
-
getI18NProvider
public I18NProvider getI18NProvider()
Description copied from interface:Instantiator
Get the I18NProvider if one has been defined.- Specified by:
getI18NProvider
in interfaceInstantiator
- Returns:
- I18NProvier instance
-
-