private static ContextualStorage findContextualStorage(VaadinSession session) { // session lock is checked inside return (ContextualStorage) session.getAttribute(ATTRIBUTE_NAME); }
private static ContextualStorage findContextualStorage(VaadinSession session) { // session lock is checked inside return (ContextualStorage) session.getAttribute(ATTRIBUTE_NAME); }
private static ContextualStorage findContextualStorage(VaadinSession session) { // session lock is checked inside return (ContextualStorage) session.getAttribute(ATTRIBUTE_NAME); }
/** * Get the {@link DeviceInfoRegistry} associated with current session, if available. * @return Optional session registry */ static Optional<DeviceInfoRegistry> getSessionRegistry() { VaadinSession session = VaadinSession.getCurrent(); if (session != null) { return Optional.ofNullable(session.getAttribute(DeviceInfoRegistry.class)); } return Optional.empty(); }
@Override public boolean remove(String resourceKey) throws UnsupportedOperationException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("Current VaadinSession not available"); } Object exist = session.getAttribute(resourceKey); session.setAttribute(resourceKey, null); return exist != null; }
public static AppLayout getCurrent() { return (AppLayout) UI.getCurrent().getSession().getAttribute(SESSION_ATTRIBUTE_APP_LAYOUT); }
@SuppressWarnings("unchecked") @Override public <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("Current VaadinSession not available"); } Object exist = session.getAttribute(resourceKey); session.setAttribute(resourceKey, value); try { T previous = (T) exist; return Optional.ofNullable(previous); } catch (@SuppressWarnings("unused") Exception e) { // ignore return Optional.empty(); } }
@SuppressWarnings("unchecked") @Override public <T> Optional<T> putIfAbsent(String resourceKey, T value) throws UnsupportedOperationException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session == null) { throw new IllegalStateException("Current VaadinSession not available"); } if (value != null) { synchronized (session) { Object exist = session.getAttribute(resourceKey); if (exist == null) { session.setAttribute(resourceKey, value); } else { return Optional.of((T) exist); } } } return Optional.empty(); }
/** * Get the session registry for VaadinSession. If no SessionRegistry exists * then one will be created for given VaadinSession. * * @param session * vaadin session to get registry for * @return session registry for given session */ public static RouteRegistry getSessionRegistry(VaadinSession session) { Objects.requireNonNull(session, "Null session is not supported for session route registry"); SessionRouteRegistry registry = session .getAttribute(SessionRouteRegistry.class); if (registry == null) { registry = new SessionRouteRegistry(session, session.getService()); session.setAttribute(SessionRouteRegistry.class, registry); } if (!registry.session.equals(session)) { throw new IllegalStateException( "Session has as the attribute a route registered to another session"); } return registry; }
@SuppressWarnings("unchecked") @Override public <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException { ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null"); ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null"); final VaadinSession session = VaadinSession.getCurrent(); if (session != null) { Object value = session.getAttribute(resourceKey); if (value != null) { // check type if (!TypeUtils.isAssignable(value.getClass(), resourceType)) { throw new TypeMismatchException("<" + NAME + "> Actual resource type [" + value.getClass().getName() + "] and required resource type [" + resourceType.getName() + "] mismatch"); } return Optional.of((T) value); } } return Optional.empty(); }
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { BeanStore beanStore = session.getAttribute(BeanStore.class); if (beanStore == null) { beanStore = new SessionBeanStore(session); session.setAttribute(BeanStore.class, beanStore); } return beanStore; } finally { session.unlock(); } }
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { BeanStore beanStore = session.getAttribute(BeanStore.class); if (beanStore == null) { beanStore = new SessionBeanStore(session); session.setAttribute(BeanStore.class, beanStore); } return beanStore; } finally { session.unlock(); } }
if (getAttribute(VaadinService.PRESERVE_UNBOUND_SESSION_ATTRIBUTE) == Boolean.TRUE) { return;
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { UIStoreWrapper wrapper = session.getAttribute(UIStoreWrapper.class); if (wrapper == null) { wrapper = new UIStoreWrapper(session); session.setAttribute(UIStoreWrapper.class, wrapper); } return wrapper.getBeanStore(getUI()); } finally { session.unlock(); } }
@Override protected BeanStore getBeanStore() { final VaadinSession session = getVaadinSession(); session.lock(); try { UIStoreWrapper wrapper = session.getAttribute(UIStoreWrapper.class); if (wrapper == null) { wrapper = new UIStoreWrapper(session); session.setAttribute(UIStoreWrapper.class, wrapper); } return wrapper.getBeanStore(getUI()); } finally { session.unlock(); } }
@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() + "]"); } } } }); }