Class LookupInitializer

java.lang.Object
com.vaadin.flow.di.LookupInitializer
All Implemented Interfaces:
AbstractLookupInitializer
Direct Known Subclasses:
SpringLookupInitializer

public class LookupInitializer extends Object implements AbstractLookupInitializer
Default implementation of AbstractLookupInitializer.
Since:
Author:
Vaadin Ltd
See Also:
  • Field Details

  • Constructor Details

    • LookupInitializer

      public LookupInitializer()
  • Method Details

    • initialize

      public void initialize(VaadinContext context, Map<Class<?>,Collection<Class<?>>> services, VaadinApplicationInitializationBootstrap bootstrap) throws jakarta.servlet.ServletException
      Description copied from interface: AbstractLookupInitializer
      Creates a new Lookup instance, initializes it and passes it to the provided bootstrap.

      The method should creates a new initialized Lookup instance. In some cases it's not possible to create the instance right away when the method is called. To be able to support this usecase the method contract doesn't require to return the Lookup instance. Instead the created instance should be passed to the provided bootstrap consumer once the instance is created and completely initialized. The bootstrap will start the application initialization which otherwise is postponed until a Lookup becomes available.

      The implementation must use the provided bootstrap to pass the Lookup instance otherwise the web application based on this LookupInitializer will never be bootstrapped.

      The provided services map contains service implementations found in application classpath using @HandlesTypes annotation declared for LookupServletContainerInitializer.

      Specified by:
      initialize in interface AbstractLookupInitializer
      Parameters:
      context - a Vaadin context to run initialization for
      services - the map of internal services with their implementations found in the application classpath
      bootstrap - the web application bootstrap
      Throws:
      jakarta.servlet.ServletException - if initialization failed
    • createLookup

      protected Lookup createLookup(VaadinContext context, Map<Class<?>,Collection<Class<?>>> services)
      Creates a lookup based on provided services.
      Parameters:
      context - a Vaadin context to create a lookup for
      services - the service objects mapped to the service type to create a lookup
      Returns:
      the lookup instance created with provided services
    • ensureService

      protected <T> void ensureService(Map<Class<?>,Collection<Class<?>>> services, Class<T> serviceType, Class<? extends T> serviceImpl)
      Ensures that provided services contain implementation for serviceType SPI.

      The default serviceImpl implementation will be set as the service into services if there is no other services available.

      Parameters:
      services - map of internal services
      serviceType - SPI type
      serviceImpl - the default SPI implementation
    • instantiate

      protected <T> T instantiate(Class<T> serviceClass, Class<?> implementation)
      Instantiates service implementation type with the given serviceClass .
      Type Parameters:
      T - service type
      Parameters:
      serviceClass - service class
      implementation - service implementation class
      Returns:
      an instantiated service implementation object
    • getDefaultImplementations

      public static Set<Class<?>> getDefaultImplementations()
      Returns the default implementation classes included.

      This method is public only for internal purposes.

      Returns:
      a set of classes