Package com.vaadin.server

Examples of com.vaadin.server.VaadinSession


     * stores the {@link BeanStore} in the current {@link com.vaadin.server.VaadinSession}.
     */
    public static class VaadinSessionBeanStoreRetrievalStrategy implements BeanStoreRetrievalStrategy {

        private VaadinSession getVaadinSession() {
            VaadinSession current = VaadinSession.getCurrent();
            if (current == null) {
                throw new IllegalStateException("No VaadinSession bound to current thread");
            }
            if (current.getState() != VaadinSession.State.OPEN) {
                throw new IllegalStateException("Current VaadinSession is not open");
            }
            return current;
        }
View Full Code Here


            return current;
        }

        @Override
        public BeanStore getBeanStore() {
            VaadinSession session = getVaadinSession();
            session.lock();
            try {
                BeanStore beanStore = session.getAttribute(BeanStore.class);
                if (beanStore == null) {
                    beanStore = new BeanStore("session " + session.getSession().getId());
                    session.setAttribute(BeanStore.class, beanStore);
                    final BeanStore theBeanStore = beanStore;
                    session.getService().addSessionDestroyListener(new SessionDestroyListener() {
                        @Override
                        public void sessionDestroy(SessionDestroyEvent event) {
                            theBeanStore.destroy();
                            event.getService().removeSessionDestroyListener(this);
                        }
                    });
                }
                return beanStore;
            } finally {
                session.unlock();
            }
        }
View Full Code Here

     * stores the {@link BeanStore} in the current {@link com.vaadin.server.VaadinSession}.
     */
    public static class VaadinSessionBeanStoreRetrievalStrategy implements BeanStoreRetrievalStrategy {

        private VaadinSession getVaadinSession() {
            VaadinSession current = VaadinSession.getCurrent();
            if (current == null) {
                throw new IllegalStateException("No VaadinSession bound to current thread");
            }
            if (current.getState() != VaadinSession.State.OPEN) {
                throw new IllegalStateException("Current VaadinSession is not open");
            }
            return current;
        }
View Full Code Here

            }
            return current;
        }

        private UIStore getUIStore() {
            VaadinSession session = getVaadinSession();
            session.lock();
            try {
                UIStore uiStore = session.getAttribute(UIStore.class);
                if (uiStore == null) {
                    uiStore = new UIStore();
                    session.setAttribute(UIStore.class, uiStore);
                }
                return uiStore;
            } finally {
                session.unlock();
            }
        }
View Full Code Here

            throws IOException {
        StringWriter writer = new StringWriter();
        try {
            writer.write("{");

            VaadinSession session = uI.getSession();
            if (session.getConfiguration().isXsrfProtectionEnabled()) {
                writer.write(getSecurityKeyUIDL(session));
            }
            new UidlWriter().write(uI, writer, true, false);
            writer.write("}");
View Full Code Here

        }
        HasComponents parent = getParent();
        if (parent != null) {
            return parent.getLocale();
        }
        final VaadinSession session = getSession();
        if (session != null) {
            return session.getLocale();
        }
        return null;
    }
View Full Code Here

    /**
     * Sets the focus for this component if the component is {@link Focusable}.
     */
    protected void focus() {
        if (this instanceof Focusable) {
            final VaadinSession session = getSession();
            if (session != null) {
                getUI().setFocusedComponent((Focusable) this);
                delayedFocus = false;
            } else {
                delayedFocus = true;
View Full Code Here

    public void setPushMode(PushMode pushMode) {
        if (pushMode == null) {
            throw new IllegalArgumentException("Push mode cannot be null");
        }

        VaadinSession session = ui.getSession();

        if (session == null) {
            throw new UIDetachedException(
                    "Cannot set the push mode for a detached UI");
        }

        assert session.hasLock();

        if (pushMode.isEnabled() && !session.getService().ensurePushAvailable()) {
            throw new IllegalStateException(
                    "Push is not available. See previous log messages for more information.");
        }

        PushMode oldMode = getState().mode;
View Full Code Here

        DeploymentConfiguration configuration = CurrentInstance
                .get(DeploymentConfiguration.class);

        if (configuration == null) {
            // Not in cache, try to find a VaadinSession to get it from
            VaadinSession session = VaadinSession.getCurrent();

            if (session == null) {
                /*
                 * There's no current session, request or response when serving
                 * static resources, but there's still the current request
                 * maintained by AppliationRunnerServlet, and there's most
                 * likely also a HttpSession containing a VaadinSession for that
                 * request.
                 */

                HttpServletRequest currentRequest = request.get();
                if (currentRequest != null) {
                    HttpSession httpSession = currentRequest.getSession(false);
                    if (httpSession != null) {
                        Map<Class<?>, CurrentInstance> oldCurrent = CurrentInstance
                                .setCurrent((VaadinSession) null);
                        try {
                            session = getService().findVaadinSession(
                                    new VaadinServletRequest(currentRequest,
                                            getService()));
                        } finally {
                            /*
                             * Clear some state set by findVaadinSession to
                             * avoid accidentally depending on it when coding on
                             * e.g. static request handling.
                             */
                            CurrentInstance.restoreInstances(oldCurrent);
                            currentRequest.removeAttribute(VaadinSession.class
                                    .getName());
                        }
                    }
                }
            }

            if (session != null) {
                String name = ApplicationRunnerServlet.class.getName()
                        + ".deploymentConfiguration";
                try {
                    session.lock();
                    configuration = (DeploymentConfiguration) session
                            .getAttribute(name);

                    if (configuration == null) {
                        Class<?> classToRun;
                        try {
                            classToRun = getClassToRun();
                        } catch (ClassNotFoundException e) {
                            /*
                             * This happens e.g. if the UI class defined in the
                             * URL is not found or if this servlet just serves
                             * static resources while there's some other servlet
                             * that serves the UI (e.g. when using /run-push/).
                             */
                            return originalConfiguration;
                        }

                        CustomDeploymentConfiguration customDeploymentConfiguration = classToRun
                                .getAnnotation(CustomDeploymentConfiguration.class);
                        if (customDeploymentConfiguration != null) {
                            Properties initParameters = new Properties(
                                    originalConfiguration.getInitParameters());

                            for (Conf entry : customDeploymentConfiguration
                                    .value()) {
                                initParameters.put(entry.name(), entry.value());
                            }

                            configuration = new DefaultDeploymentConfiguration(
                                    getClass(), initParameters);
                        } else {
                            configuration = originalConfiguration;
                        }

                        session.setAttribute(name, configuration);
                    }
                } finally {
                    session.unlock();
                }

                CurrentInstance.set(DeploymentConfiguration.class,
                        configuration);

View Full Code Here

    private LegacyCommunicationManager cm;

    @Override
    protected void setUp() throws Exception {
        final VaadinSession application = new AlwaysLockedVaadinSession(null);
        final UI uI = new UI() {
            @Override
            protected void init(VaadinRequest request) {
                // TODO Auto-generated method stub
View Full Code Here

TOP

Related Classes of com.vaadin.server.VaadinSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.