use of com.vaadin.flow.di.AbstractLookupInitializer in project flow by vaadin.
the class LookupServletContainerInitializer method getLookupInitializer.
private AbstractLookupInitializer getLookupInitializer(Map<Class<?>, Collection<Class<?>>> services) throws ServletException {
Collection<Class<?>> initializers = services.remove(AbstractLookupInitializer.class);
if (initializers == null) {
initializers = Collections.emptyList();
} else {
initializers.remove(LookupInitializer.class);
}
AbstractLookupInitializer initializer;
if (initializers.isEmpty()) {
initializer = new LookupInitializer();
} else if (initializers.size() > 1) {
throw new ServletException("Several implementation of " + AbstractLookupInitializer.class.getSimpleName() + " are found in the claspath: " + initializers);
} else {
initializer = AbstractLookupInitializer.class.cast(ReflectTools.createInstance(initializers.iterator().next()));
}
return initializer;
}
use of com.vaadin.flow.di.AbstractLookupInitializer in project flow by vaadin.
the class LookupServletContainerInitializer method process.
@Override
public void process(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException {
if (classSet == null) {
throw new ServletException(ServletContainerInitializer.class.getSimpleName() + " is called but the " + "provided set of classes is 'null'. " + LookupInitializer.class + " always presents " + "and has to be passed to the 'onStartup' method as an argument " + "in the set of classes if the servlet container supports Servlet 3.0 specification. " + "The propject configuration is broken somehow or you are using Servlet 3.0 incompatible container.");
}
if (!classSet.contains(LookupInitializer.class)) {
// executed at all.
return;
}
VaadinServletContext vaadinContext = new VaadinServletContext(servletContext);
Map<Class<?>, Collection<Class<?>>> services = new HashMap<>();
collectSubclasses(AbstractLookupInitializer.class, classSet, services);
AbstractLookupInitializer initializer = getLookupInitializer(services);
services.remove(AbstractLookupInitializer.class);
collectServiceImplementations(classSet, services);
initializer.initialize(vaadinContext, services, lookup -> {
vaadinContext.setAttribute(Lookup.class, lookup);
DeferredServletContextInitializers deferredInitializers;
synchronized (servletContext) {
deferredInitializers = vaadinContext.getAttribute(DeferredServletContextInitializers.class);
vaadinContext.removeAttribute(DeferredServletContextInitializers.class);
}
if (deferredInitializers != null) {
deferredInitializers.runInitializers(servletContext);
}
});
}
Aggregations