/** * Get the current {@link I18NProvider}, if available. * @return Optional current {@link I18NProvider} */ private static Optional<I18NProvider> getCurrentI18nProvider() { final VaadinService service = VaadinService.getCurrent(); if (service != null) { return Optional.ofNullable(VaadinService.getCurrent().getInstantiator().getI18NProvider()); } return Optional.empty(); }
return getService().accessSession(this, command);
/** * Gets the dependencies, defined using annotations ({@link HtmlImport}, * {@link JavaScript}, {@link StyleSheet} and {@link Uses}). * <p> * Framework internal data, thus package-private. * * @param service * the service to use for resolving dependencies * * @return the dependencies for the given class */ public DependencyInfo getDependencyInfo(VaadinService service) { return dependencyInfo.computeIfAbsent(service, ignore -> { service.addServiceDestroyListener( event -> dependencyInfo.remove(service)); return findDependencies(service, componentClass); }); }
/** * Creates and registers a new VaadinSession for this service. Assumes * proper locking has been taken care of by the caller. * * @param request * The request which triggered session creation. * @return A new VaadinSession instance */ private VaadinSession createAndRegisterSession(VaadinRequest request) { assert ((ReentrantLock) getSessionLock(request.getWrappedSession())) .isHeldByCurrentThread() : "Session has not been locked by this thread"; VaadinSession session = createVaadinSession(request); VaadinSession.setCurrent(session); storeSession(session, request.getWrappedSession()); // Initial WebBrowser data comes from the request session.getBrowser().updateRequestDetails(request); session.setConfiguration(getDeploymentConfiguration()); // Initial locale comes from the request if (getInstantiator().getI18NProvider() != null) { setLocale(request, session); } onVaadinSessionStarted(request, session); return session; }
assert ((ReentrantLock) getSessionLock(request.getWrappedSession())) .isHeldByCurrentThread() : "Session has not been locked by this thread"; VaadinSession session = getExistingSession(request, requestCanCreateSession); final boolean restartApplication = hasParameter(request, URL_PARAMETER_RESTART_APPLICATION); final boolean closeApplication = hasParameter(request, URL_PARAMETER_CLOSE_APPLICATION); closeSession(session, request.getWrappedSession(false)); return null; } else if (restartApplication) { closeSession(session, request.getWrappedSession(false)); return createAndRegisterSession(request); } else { return session; return createAndRegisterSession(request); } else {
if (isSessionActive(session)) { closeInactiveUIs(session); removeClosedUIs(session); } else { if (session.getState() == VaadinSessionState.OPEN) { closeSession(session); if (session.getSession() != null) { getLogger().debug("Closing inactive session {}", session.getSession().getId()); removeSession(session.getSession()); fireSessionDestroy(session);
private UIStoreWrapper(VaadinSession session) { assert session.hasLock(); uiStores = new HashMap<>(); this.session = session; if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
private void reportException(Exception exception, String path, String exceptionText) { getElement().appendChild(Element.createText(exceptionText)); VaadinService vaadinService = VaadinService.getCurrent(); // Check that we have a vaadinService as else we will fail on a NPE and // the stacktrace we actually got will disappear and getting a NPE is // confusing. boolean productionMode = vaadinService != null && vaadinService .getDeploymentConfiguration().isProductionMode(); if (!productionMode) { checkLogBinding(); printStacktrace(exception); } getLogger().error( "There was an exception while trying to navigate to '{}'", path, exception); }
private Router getRouter() { Router router = null; if (getElement().getNode().isAttached()) { StateTree tree = (StateTree) getElement().getNode().getOwner(); router = tree.getUI().getRouter(); } if (router == null) { router = VaadinService.getCurrent().getRouter(); } if (router == null) { throw new IllegalStateException( "Implicit router instance is not available. " + "Use overloaded method with explicit router parameter."); } return router; }
/** * Creates the component that is responsible for Polymer template * functionality using the provided {@code parser}. * * @param parser * a template parser */ public PolymerTemplate(TemplateParser parser) { this(parser, VaadinService.getCurrent()); }
@Override public void serviceInit(ServiceInitEvent event) { // Session event.getSource().addSessionInitListener(e -> { // DeviceInfo registry is available if (e.getSession().getAttribute(DeviceInfoRegistry.class) == null) { e.getSession().setAttribute(DeviceInfoRegistry.class, new DefaultDeviceInfoRegistry()); } }); // UI init event.getSource().addUIInitListener(e -> { if (e.getUI().getSession() != null) { // configure DeviceInfo final DeviceInfoRegistry registry = e.getUI().getSession().getAttribute(DeviceInfoRegistry.class); if (registry != null && !registry.hasDeviceInfo(e.getUI())) { final VaadinRequest request = VaadinRequest.getCurrent(); if (request != null) { registry.setDeviceInfo(e.getUI(), DeviceInfo.create(e.getUI(), request)); // log LOGGER.debug(() -> "A DeviceInfo was configured for UI with id [" + e.getUI().getUIId() + "]"); } } } }); }
/** * Gets the instantiator to use for the given UI. * * @param ui * the attached UI for which to find an instantiator, not * <code>null</code> * @return the instantiator, not <code>null</code> */ static Instantiator get(UI ui) { assert ui != null; VaadinSession session = ui.getSession(); assert session != null; return session.getService().getInstantiator(); }
@Override public void serviceInit(ServiceInitEvent event) { event.getSource().addUIInitListener(e -> { e.getUI().addBeforeEnterListener(new SecuredRouteBeforeEnterListener()); LOGGER.debug(() -> "Secured route before enter listener setted up"); }); }
/** * Called after the framework has handled a request and the response has * been written. * * @param request * The request object * @param response * The response object * @param session * The session which was used during the request or null if the * request did not use a session */ public void requestEnd(VaadinRequest request, VaadinResponse response, VaadinSession session) { if (session != null) { assert VaadinSession.getCurrent() == session; session.lock(); try { cleanupSession(session); final long duration = (System.nanoTime() - (Long) request .getAttribute(REQUEST_START_TIME_ATTRIBUTE)) / 1000000; session.setLastRequestDuration(duration); } finally { session.unlock(); } } CurrentInstance.clearAll(); }
private UIStoreWrapper(VaadinSession session) { assert session.hasLock(); uiStores = new HashMap<>(); this.session = session; if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }
/** * Creates the component that is responsible for Polymer template * functionality. */ public PolymerTemplate() { this(DefaultTemplateParser.getInstance(), VaadinService.getCurrent()); }
private void setLocale(VaadinRequest request, VaadinSession session) { I18NProvider provider = getInstantiator().getI18NProvider(); List<Locale> providedLocales = provider.getProvidedLocales(); if (providedLocales.size() == 1) { session.setLocale(providedLocales.get(0)); } else { Optional<Locale> foundLocale = LocaleUtil .getExactLocaleMatch(request, providedLocales); if (!foundLocale.isPresent()) { foundLocale = LocaleUtil .getLocaleMatchByLanguage(request, providedLocales); } // Set locale by match found in I18N provider, first provided locale // or else leave as default locale if (foundLocale.isPresent()) { session.setLocale(foundLocale.get()); } else if (!providedLocales.isEmpty()) { session.setLocale(providedLocales.get(0)); } } }
private I18NProvider getI18NProvider() { return VaadinService.getCurrent().getInstantiator().getI18NProvider(); }
private SessionBeanStore(VaadinSession session) { super(session); if (session instanceof SpringVaadinSession) { sessionDestroyListenerRegistration = null; ((SpringVaadinSession) session) .addDestroyListener(event -> destroy()); } else { sessionDestroyListenerRegistration = session.getService() .addSessionDestroyListener(event -> destroy()); } }