]> source.dussan.org Git - vaadin-framework.git/commitdiff
Change LegacyApplication to be a UIProvider (#9402)
authorLeif Åstrand <leif@vaadin.com>
Wed, 5 Sep 2012 12:42:02 +0000 (15:42 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 5 Sep 2012 12:42:02 +0000 (15:42 +0300)
31 files changed:
server/src/com/vaadin/Application.java
server/src/com/vaadin/server/AbstractUIProvider.java
server/src/com/vaadin/server/LegacyVaadinPortlet.java [new file with mode: 0644]
server/src/com/vaadin/server/LegacyVaadinServlet.java [new file with mode: 0644]
server/src/com/vaadin/server/ServletPortletHelper.java
server/src/com/vaadin/server/UIProvider.java
server/src/com/vaadin/server/VaadinPortlet.java
server/src/com/vaadin/server/VaadinServlet.java
uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
uitest/src/com/vaadin/tests/Parameters.java
uitest/src/com/vaadin/tests/TestBench.java
uitest/src/com/vaadin/tests/TreeFilesystem.java
uitest/src/com/vaadin/tests/TreeFilesystemContainer.java
uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html
uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html
uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
uitest/src/com/vaadin/tests/components/AbstractTestApplication.java [deleted file]
uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java
uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java
uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java
uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java
uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
uitest/src/com/vaadin/tests/tickets/Ticket1589.java
uitest/src/com/vaadin/tests/tickets/Ticket1921.java
uitest/src/com/vaadin/tests/tickets/Ticket2292.java

index 745d0ad784fa287b38eb4744ec46055711322111..634f96bfe1f3a989f1dd3be0327756ba5d687048 100644 (file)
@@ -58,6 +58,8 @@ import com.vaadin.server.GlobalResourceHandler;
 import com.vaadin.server.RequestHandler;
 import com.vaadin.server.ServletApplicationContext;
 import com.vaadin.server.Terminal;
+import com.vaadin.server.Terminal.ErrorEvent;
+import com.vaadin.server.Terminal.ErrorListener;
 import com.vaadin.server.UIProvider;
 import com.vaadin.server.VaadinServlet;
 import com.vaadin.server.VariableOwner;
@@ -152,7 +154,8 @@ public class Application implements Terminal.ErrorListener, Serializable {
      * @since 7.0
      */
     @Deprecated
-    public static class LegacyApplication extends Application {
+    public static abstract class LegacyApplication extends AbstractUIProvider
+            implements ErrorListener {
         /**
          * Ignore initial / and then get everything up to the next /
          */
@@ -177,8 +180,8 @@ public class Application implements Terminal.ErrorListener, Serializable {
                         "mainWindow has already been set");
             }
             if (mainWindow.getApplication() == null) {
-                mainWindow.setApplication(this);
-            } else if (mainWindow.getApplication() != this) {
+                mainWindow.setApplication(Application.getCurrent());
+            } else if (mainWindow.getApplication() != Application.getCurrent()) {
                 throw new IllegalStateException(
                         "mainWindow is attached to another application");
             }
@@ -190,45 +193,44 @@ public class Application implements Terminal.ErrorListener, Serializable {
             this.mainWindow = mainWindow;
         }
 
+        public void doInit() {
+            Application.getCurrent().setErrorHandler(this);
+            init();
+        }
+
+        protected abstract void init();
+
         @Override
-        public void start(ApplicationStartEvent event) {
-            super.start(event);
-            addUIProvider(new AbstractUIProvider() {
-                @Override
-                public Class<? extends UI> getUIClass(Application application,
-                        WrappedRequest request) {
-                    if (application == LegacyApplication.this) {
-                        UI uiInstance = getUIInstance(request);
-                        if (uiInstance != null) {
-                            return uiInstance.getClass();
-                        }
-                    }
-                    return null;
-                }
+        public Class<? extends UI> getUIClass(Application application,
+                WrappedRequest request) {
+            UI uiInstance = getUIInstance(request);
+            if (uiInstance != null) {
+                return uiInstance.getClass();
+            }
+            return null;
+        }
 
-                @Override
-                public UI createInstance(Application application,
-                        Class<? extends UI> type, WrappedRequest request) {
-                    return getUIInstance(request);
-                }
+        @Override
+        public UI createInstance(Application application,
+                Class<? extends UI> type, WrappedRequest request) {
+            return getUIInstance(request);
+        }
 
-                @Override
-                public String getThemeForUI(WrappedRequest request,
-                        Class<? extends UI> uiClass) {
-                    return theme;
-                }
+        @Override
+        public String getThemeForUI(WrappedRequest request,
+                Class<? extends UI> uiClass) {
+            return theme;
+        }
 
-                @Override
-                public String getPageTitleForUI(WrappedRequest request,
-                        Class<? extends UI> uiClass) {
-                    UI uiInstance = getUIInstance(request);
-                    if (uiInstance != null) {
-                        return uiInstance.getCaption();
-                    } else {
-                        return super.getPageTitleForUI(request, uiClass);
-                    }
-                }
-            });
+        @Override
+        public String getPageTitleForUI(WrappedRequest request,
+                Class<? extends UI> uiClass) {
+            UI uiInstance = getUIInstance(request);
+            if (uiInstance != null) {
+                return uiInstance.getCaption();
+            } else {
+                return super.getPageTitleForUI(request, uiClass);
+            }
         }
 
         /**
@@ -273,7 +275,7 @@ public class Application implements Terminal.ErrorListener, Serializable {
          * {@inheritDoc}
          */
         @Override
-        public UI getUIForRequest(WrappedRequest request) {
+        public UI getExistingUI(WrappedRequest request) {
             UI uiInstance = getUIInstance(request);
             if (uiInstance.getUIId() == -1) {
                 // Not initialized -> Let go through createUIInstance to make it
@@ -352,7 +354,7 @@ public class Application implements Terminal.ErrorListener, Serializable {
             }
 
             legacyUINames.put(uI.getName(), uI);
-            uI.setApplication(this);
+            uI.setApplication(Application.getCurrent());
         }
 
         /**
@@ -389,6 +391,27 @@ public class Application implements Terminal.ErrorListener, Serializable {
         public Collection<UI.LegacyWindow> getWindows() {
             return Collections.unmodifiableCollection(legacyUINames.values());
         }
+
+        @Override
+        public void terminalError(ErrorEvent event) {
+            Application.getCurrent().terminalError(event);
+        }
+
+        public ApplicationContext getContext() {
+            return Application.getCurrent().getContext();
+        }
+
+        protected void close() {
+            Application.getCurrent().close();
+        }
+
+        public boolean isRunning() {
+            return Application.getCurrent().isRunning();
+        }
+
+        public URL getURL() {
+            return Application.getCurrent().getURL();
+        }
     }
 
     /**
@@ -1854,39 +1877,10 @@ public class Application implements Terminal.ErrorListener, Serializable {
         Integer uiId = getUIId(request);
 
         synchronized (this) {
-            BrowserDetails browserDetails = request.getBrowserDetails();
-            boolean hasBrowserDetails = browserDetails != null
-                    && browserDetails.getUriFragment() != null;
-
             uI = uIs.get(uiId);
-            Class<? extends UI> uiClass = null;
-
-            if (uI == null && hasBrowserDetails
-                    && !retainOnRefreshUIs.isEmpty()) {
-                uiClass = getUIClass(request);
-
-                // Check for a known UI
-
-                @SuppressWarnings("null")
-                String windowName = browserDetails.getWindowName();
-                Integer retainedUIId = retainOnRefreshUIs.get(windowName);
-
-                if (retainedUIId != null) {
-                    UI retainedUI = uIs.get(retainedUIId);
-                    // We've had the same UI instance in a window with this
-                    // name, but should we still use it?
-                    if (retainedUI.getClass() == uiClass) {
-                        uiId = retainedUIId;
-                        uI = retainedUI;
-                    } else {
-                        getLogger().info(
-                                "Not using retained UI in " + windowName
-                                        + " because retained UI was of type "
-                                        + retainedUIId.getClass() + " but "
-                                        + uiClass
-                                        + " is expected for the request.");
-                    }
-                }
+
+            if (uI == null) {
+                uI = findExistingUi(request);
             }
 
         } // end synchronized block
@@ -1896,6 +1890,48 @@ public class Application implements Terminal.ErrorListener, Serializable {
         return uI;
     }
 
+    private UI findExistingUi(WrappedRequest request) {
+        // Check if some UI provider has an existing UI available
+        for (int i = uiProviders.size() - 1; i >= 0; i--) {
+            UIProvider provider = uiProviders.get(i);
+            UI existingUi = provider.getExistingUI(request);
+            if (existingUi != null) {
+                return existingUi;
+            }
+        }
+
+        BrowserDetails browserDetails = request.getBrowserDetails();
+        boolean hasBrowserDetails = browserDetails != null
+                && browserDetails.getUriFragment() != null;
+
+        if (hasBrowserDetails && !retainOnRefreshUIs.isEmpty()) {
+            // Check for a known UI
+
+            @SuppressWarnings("null")
+            String windowName = browserDetails.getWindowName();
+            Integer retainedUIId = retainOnRefreshUIs.get(windowName);
+
+            if (retainedUIId != null) {
+                Class<? extends UI> expectedUIClass = getUIClass(request);
+                UI retainedUI = uIs.get(retainedUIId);
+                // We've had the same UI instance in a window with this
+                // name, but should we still use it?
+                if (retainedUI.getClass() == expectedUIClass) {
+                    return retainedUI;
+                } else {
+                    getLogger().info(
+                            "Not using retained UI in " + windowName
+                                    + " because retained UI was of type "
+                                    + retainedUIId.getClass() + " but "
+                                    + expectedUIClass
+                                    + " is expected for the request.");
+                }
+            }
+        }
+
+        return null;
+    }
+
     public UI createUI(WrappedRequest request) {
         Class<? extends UI> uiClass = getUIClass(request);
 
@@ -2167,4 +2203,8 @@ public class Application implements Terminal.ErrorListener, Serializable {
         return globalResourceHandler;
     }
 
+    public Collection<UIProvider> getUIProviders() {
+        return Collections.unmodifiableCollection(uiProviders);
+    }
+
 }
index 49f8e3ec778287b61e816c9e25c7fca5289b291c..c7a137ebbd2a8b3ca707df05263762db8717b382 100644 (file)
@@ -115,4 +115,9 @@ public abstract class AbstractUIProvider implements UIProvider {
             return titleAnnotation.value();
         }
     }
+
+    @Override
+    public UI getExistingUI(WrappedRequest request) {
+        return null;
+    }
 }
diff --git a/server/src/com/vaadin/server/LegacyVaadinPortlet.java b/server/src/com/vaadin/server/LegacyVaadinPortlet.java
new file mode 100644 (file)
index 0000000..036242a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+
+import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
+import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
+
+public class LegacyVaadinPortlet extends VaadinPortlet {
+
+    protected Class<? extends LegacyApplication> getApplicationClass()
+            throws ClassNotFoundException {
+        try {
+            return ServletPortletHelper
+                    .getLegacyApplicationClass(getDeploymentConfiguration());
+        } catch (ApplicationClassException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected LegacyApplication getNewApplication(PortletRequest request)
+            throws PortletException {
+        try {
+            Class<? extends LegacyApplication> applicationClass = getApplicationClass();
+            return applicationClass.newInstance();
+        } catch (Exception e) {
+            throw new PortletException(e);
+        }
+    }
+
+    @Override
+    protected Application createApplication(PortletRequest request)
+            throws PortletException {
+        Application application = super.createApplication(request);
+
+        // Must set current before running init()
+        Application.setCurrent(application);
+
+        LegacyApplication legacyApplication = getNewApplication(request);
+        legacyApplication.doInit();
+        application.addUIProvider(legacyApplication);
+
+        return application;
+    }
+}
diff --git a/server/src/com/vaadin/server/LegacyVaadinServlet.java b/server/src/com/vaadin/server/LegacyVaadinServlet.java
new file mode 100644 (file)
index 0000000..f53e9d4
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
+import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
+
+public class LegacyVaadinServlet extends VaadinServlet {
+
+    protected Class<? extends LegacyApplication> getApplicationClass()
+            throws ClassNotFoundException {
+        try {
+            return ServletPortletHelper
+                    .getLegacyApplicationClass(getDeploymentConfiguration());
+        } catch (ApplicationClassException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected LegacyApplication getNewApplication(HttpServletRequest request)
+            throws ServletException {
+        try {
+            Class<? extends LegacyApplication> applicationClass = getApplicationClass();
+            return applicationClass.newInstance();
+        } catch (Exception e) {
+            throw new ServletException(e);
+        }
+    }
+
+    @Override
+    protected Application createApplication(HttpServletRequest request)
+            throws ServletException {
+        Application application = super.createApplication(request);
+
+        // Must set current before running init()
+        Application.setCurrent(application);
+
+        LegacyApplication legacyApplication = getNewApplication(request);
+        legacyApplication.doInit();
+        application.addUIProvider(legacyApplication);
+
+        return application;
+    }
+
+}
index 26913d8ba881542a23ec831e742c070e1c96344a..18fbb66114cc7408ebc839a08435f7df4579be82 100644 (file)
@@ -4,6 +4,7 @@ import java.io.Serializable;
 import java.util.Properties;
 
 import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.ui.UI;
 
@@ -41,28 +42,22 @@ class ServletPortletHelper implements Serializable {
         }
     }
 
-    static Class<? extends Application> getApplicationClass(
+    static Class<? extends LegacyApplication> getLegacyApplicationClass(
             DeploymentConfiguration deploymentConfiguration)
             throws ApplicationClassException {
         Properties initParameters = deploymentConfiguration
                 .getApplicationConfiguration().getInitParameters();
         String applicationParameter = initParameters.getProperty("application");
-        String uiParameter = initParameters
-                .getProperty(Application.UI_PARAMETER);
         ClassLoader classLoader = deploymentConfiguration.getClassLoader();
 
         if (applicationParameter == null) {
-
-            // Validate the parameter value
-            verifyUIClass(uiParameter, classLoader);
-
-            // Application can be used if a valid rootLayout is defined
-            return Application.class;
+            throw new ApplicationClassException(
+                    "No \"application\" init parameter found");
         }
 
         try {
-            return (Class<? extends Application>) classLoader
-                    .loadClass(applicationParameter);
+            return classLoader.loadClass(applicationParameter).asSubclass(
+                    LegacyApplication.class);
         } catch (final ClassNotFoundException e) {
             throw new ApplicationClassException(
                     "Failed to load application class: " + applicationParameter,
@@ -138,4 +133,25 @@ class ServletPortletHelper implements Serializable {
                 ApplicationConstants.HEARTBEAT_REQUEST_PATH);
     }
 
+    public static void initDefaultUIProvider(Application application,
+            DeploymentConfiguration deploymentConfiguration)
+            throws ApplicationClassException {
+        String uiProperty = deploymentConfiguration
+                .getApplicationConfiguration().getInitParameters()
+                .getProperty(Application.UI_PARAMETER);
+        if (uiProperty != null) {
+            verifyUIClass(uiProperty, deploymentConfiguration.getClassLoader());
+            application.addUIProvider(new DefaultUIProvider());
+        }
+    }
+
+    public static void checkUiProviders(Application newApplication)
+            throws ApplicationClassException {
+        if (newApplication.getUIProviders().isEmpty()) {
+            throw new ApplicationClassException(
+                    "No UIProvider has been added to the application and there is no \""
+                            + Application.UI_PARAMETER + "\" init parameter.");
+        }
+    }
+
 }
index 60b79cdbb99602a8d2656328e10d374584de95f7..6a45b06c63a6b4413be014b48476045b9f44b8d1 100644 (file)
@@ -78,4 +78,23 @@ public interface UIProvider {
     public String getThemeForUI(WrappedRequest request,
             Class<? extends UI> uiClass);
 
+    /**
+     * Finds an existing {@link UI} for a request.
+     * <p>
+     * Implementations should take care to not return an UI instance that might
+     * be used in some other browser as that might cause synchronization issues
+     * when changes from one browser window are not present in the other.
+     * <p>
+     * If no UI provider returns an existing UI, the framework does also check
+     * the window.name for an existing instance with
+     * {@link #isUiPreserved(WrappedRequest, Class)} before falling back to
+     * bootstrapping and creating a new UI instance.
+     * 
+     * @param request
+     *            the request for which a UI is desired
+     * @return a UI belonging to the request, or <code>null</code> if this UI
+     *         provider doesn't have an existing UI for the request.
+     */
+    public UI getExistingUI(WrappedRequest request);
+
 }
index bf8fb5dc8433d4e58d017b46fba2a51ca46b6ad7..eae01e9369ef8e187ac6b838d1f04b948548806f 100644 (file)
@@ -814,7 +814,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
 
             if (restartApplication) {
                 closeApplication(application, request.getPortletSession(false));
-                return createApplication(request);
+                return createAndRegisterApplication(request);
             } else if (closeApplication) {
                 closeApplication(application, request.getPortletSession(false));
                 return null;
@@ -826,7 +826,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
         // No existing application was found
 
         if (requestCanCreateApplication) {
-            return createApplication(request);
+            return createAndRegisterApplication(request);
         } else {
             throw new SessionExpiredException();
         }
@@ -845,9 +845,16 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
         }
     }
 
-    private Application createApplication(PortletRequest request)
+    private Application createAndRegisterApplication(PortletRequest request)
             throws PortletException {
-        Application newApplication = getNewApplication(request);
+        Application newApplication = createApplication(request);
+
+        try {
+            ServletPortletHelper.checkUiProviders(newApplication);
+        } catch (ApplicationClassException e) {
+            throw new PortletException(e);
+        }
+
         final PortletApplicationContext2 context = getApplicationContext(request
                 .getPortletSession());
         context.setApplication(newApplication, new PortletCommunicationManager(
@@ -855,6 +862,20 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
         return newApplication;
     }
 
+    protected Application createApplication(PortletRequest request)
+            throws PortletException {
+        Application application = new Application();
+
+        try {
+            ServletPortletHelper.initDefaultUIProvider(application,
+                    getDeploymentConfiguration());
+        } catch (ApplicationClassException e) {
+            throw new PortletException(e);
+        }
+
+        return application;
+    }
+
     private Application getExistingApplication(PortletRequest request,
             boolean allowSessionCreation) throws MalformedURLException,
             SessionExpiredException {
@@ -880,26 +901,6 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
         return null;
     }
 
-    protected Class<? extends Application> getApplicationClass()
-            throws ApplicationClassException {
-        return ServletPortletHelper
-                .getApplicationClass(getDeploymentConfiguration());
-    }
-
-    protected Application getNewApplication(PortletRequest request)
-            throws PortletException {
-        try {
-            final Application application = getApplicationClass().newInstance();
-            return application;
-        } catch (final IllegalAccessException e) {
-            throw new PortletException("getNewApplication failed", e);
-        } catch (final InstantiationException e) {
-            throw new PortletException("getNewApplication failed", e);
-        } catch (final ApplicationClassException e) {
-            throw new PortletException("getNewApplication failed", e);
-        }
-    }
-
     private void handleServiceException(WrappedPortletRequest request,
             WrappedPortletResponse response, Application application,
             Throwable e) throws IOException, PortletException {
index ba190725031f263200bc98b3eac41a791bcea6da..8f333821101ed00cd063b061c7d51674d6cbdff1 100644 (file)
@@ -603,7 +603,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
 
             if (restartApplication) {
                 closeApplication(application, request.getSession(false));
-                return createApplication(request);
+                return createAndRegisterApplication(request);
             } else if (closeApplication) {
                 closeApplication(application, request.getSession(false));
                 return null;
@@ -619,7 +619,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
              * If the request is such that it should create a new application if
              * one as not found, we do that.
              */
-            return createApplication(request);
+            return createAndRegisterApplication(request);
         } else {
             /*
              * The application was not found and a new one should not be
@@ -630,6 +630,24 @@ public class VaadinServlet extends HttpServlet implements Constants {
 
     }
 
+    private Application createAndRegisterApplication(HttpServletRequest request)
+            throws ServletException {
+        Application newApplication = createApplication(request);
+
+        try {
+            ServletPortletHelper.checkUiProviders(newApplication);
+        } catch (ApplicationClassException e) {
+            throw new ServletException(e);
+        }
+
+        final ServletApplicationContext context = getApplicationContext(request
+                .getSession());
+        context.setApplication(newApplication,
+                createCommunicationManager(newApplication));
+
+        return newApplication;
+    }
+
     /**
      * Check if the request should create an application if an existing
      * application is not found.
@@ -699,14 +717,16 @@ public class VaadinServlet extends HttpServlet implements Constants {
      * @throws ServletException
      * @throws MalformedURLException
      */
-    private Application createApplication(HttpServletRequest request)
-            throws ServletException, MalformedURLException {
-        Application newApplication = getNewApplication(request);
+    protected Application createApplication(HttpServletRequest request)
+            throws ServletException {
+        Application newApplication = new Application();
 
-        final ServletApplicationContext context = getApplicationContext(request
-                .getSession());
-        context.setApplication(newApplication,
-                createCommunicationManager(newApplication));
+        try {
+            ServletPortletHelper.initDefaultUIProvider(newApplication,
+                    getDeploymentConfiguration());
+        } catch (ApplicationClassException e) {
+            throw new ServletException(e);
+        }
 
         return newApplication;
     }
@@ -848,35 +868,6 @@ public class VaadinServlet extends HttpServlet implements Constants {
         log("Invalid security key received from " + request.getRemoteHost());
     }
 
-    /**
-     * Creates a new application for the given request.
-     * 
-     * @param request
-     *            the HTTP request.
-     * @return A new Application instance.
-     * @throws ServletException
-     */
-    protected Application getNewApplication(HttpServletRequest request)
-            throws ServletException {
-
-        // Creates a new application instance
-        try {
-            Class<? extends Application> applicationClass = ServletPortletHelper
-                    .getApplicationClass(getDeploymentConfiguration());
-
-            final Application application = applicationClass.newInstance();
-            application.addUIProvider(new DefaultUIProvider());
-
-            return application;
-        } catch (final IllegalAccessException e) {
-            throw new ServletException("getNewApplication failed", e);
-        } catch (final InstantiationException e) {
-            throw new ServletException("getNewApplication failed", e);
-        } catch (ApplicationClassException e) {
-            throw new ServletException("getNewApplication failed", e);
-        }
-    }
-
     /**
      * Starts the application if it is not already running.
      * 
index 3d63c7dfb97ecf1ab423861768e51f5baada1ca0..3372651e5c60dc3bcb225e22e326a6d560ffaca3 100644 (file)
@@ -30,16 +30,18 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.server.AbstractUIProvider;
 import com.vaadin.server.ApplicationConfiguration;
-import com.vaadin.server.VaadinServlet;
+import com.vaadin.server.LegacyVaadinServlet;
+import com.vaadin.server.UIProvider;
 import com.vaadin.server.WrappedHttpServletRequest;
 import com.vaadin.server.WrappedRequest;
 import com.vaadin.tests.components.TestBase;
 import com.vaadin.ui.UI;
 
 @SuppressWarnings("serial")
-public class ApplicationRunnerServlet extends VaadinServlet {
+public class ApplicationRunnerServlet extends LegacyVaadinServlet {
 
     /**
      * The name of the application class currently used. Only valid within one
@@ -104,10 +106,14 @@ public class ApplicationRunnerServlet extends VaadinServlet {
     }
 
     @Override
-    protected Application getNewApplication(HttpServletRequest request)
-            throws ServletException {
+    protected Class<? extends LegacyApplication> getApplicationClass()
+            throws ClassNotFoundException {
+        return getClassToRun().asSubclass(LegacyApplication.class);
+    }
 
-        // Creates a new application instance
+    @Override
+    protected Application createApplication(HttpServletRequest request)
+            throws ServletException {
         try {
             final Class<?> classToRun = getClassToRun();
             if (UI.class.isAssignableFrom(classToRun)) {
@@ -121,8 +127,13 @@ public class ApplicationRunnerServlet extends VaadinServlet {
                     }
                 });
                 return application;
-            } else if (Application.class.isAssignableFrom(classToRun)) {
-                return (Application) classToRun.newInstance();
+            } else if (LegacyApplication.class.isAssignableFrom(classToRun)) {
+                return super.createApplication(request);
+            } else if (UIProvider.class.isAssignableFrom(classToRun)) {
+                Application application = new Application();
+                application
+                        .addUIProvider((UIProvider) classToRun.newInstance());
+                return application;
             } else {
                 throw new ServletException(classToRun.getCanonicalName()
                         + " is neither an Application nor a UI");
index b16d4ef65be67e3f3749e924cf451c955b1dbed0..f5ab18cfe3a61657fc12dc068eb679c94f0fc1bd 100644 (file)
@@ -30,8 +30,8 @@ import com.vaadin.ui.Label;
 import com.vaadin.ui.Layout.MarginHandler;
 import com.vaadin.ui.Link;
 import com.vaadin.ui.Panel;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Table;
+import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.VerticalLayout;
 
 /**
@@ -56,7 +56,7 @@ public class Parameters extends com.vaadin.Application.LegacyApplication
         setMainWindow(main);
 
         // This class acts both as URI handler and parameter handler
-        addRequestHandler(this);
+        Application.getCurrent().addRequestHandler(this);
 
         final VerticalLayout layout = new VerticalLayout();
         final Label info = new Label("To test URI and Parameter Handlers, "
index 67e1180d75125e38aad9ca0039bfc0467201b0ea..bae677001a6f6024bde55ab9067ffb179f91b56d 100644 (file)
@@ -37,8 +37,8 @@ import com.vaadin.ui.Label;
 import com.vaadin.ui.Layout;
 import com.vaadin.ui.Link;
 import com.vaadin.ui.Panel;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Tree;
+import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.VerticalLayout;
 
 /**
@@ -225,7 +225,7 @@ public class TestBench extends com.vaadin.Application.LegacyApplication
         try {
             final Application.LegacyApplication app = (Application.LegacyApplication) c
                     .newInstance();
-            app.init();
+            app.doInit();
             Layout lo = (Layout) app.getMainWindow().getContent();
             lo.setParent(null);
             return lo;
index f2a0d97b0881ab5a7439ba7eda331555f0e67cdb..2e7b215ad77def7d3581b699da38821bf60bc997 100644 (file)
@@ -18,14 +18,15 @@ package com.vaadin.tests;
 
 import java.io.File;
 
+import com.vaadin.Application;
 import com.vaadin.data.Item;
 import com.vaadin.shared.ui.label.ContentMode;
 import com.vaadin.tests.util.SampleDirectory;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.Panel;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Tree;
 import com.vaadin.ui.Tree.ExpandEvent;
+import com.vaadin.ui.UI.LegacyWindow;
 
 /**
  * Browsable file explorer using Vaadin Tree component. Demonstrates: how to add
@@ -61,7 +62,8 @@ public class TreeFilesystem extends com.vaadin.Application.LegacyApplication
         tree.addListener(this);
 
         // Get sample directory
-        final File sampleDir = SampleDirectory.getDirectory(this, main);
+        final File sampleDir = SampleDirectory.getDirectory(
+                Application.getCurrent(), main);
         // populate tree's root node with example directory
         if (sampleDir != null) {
             populateNode(sampleDir.getAbsolutePath(), null);
index 672c518ea827babc4d1520437f9dbcedf5d5dbd3..8107ea702d0b33d5f25d2061b91c110cea09ffb0 100644 (file)
@@ -18,6 +18,7 @@ package com.vaadin.tests;
 
 import java.io.File;
 
+import com.vaadin.Application;
 import com.vaadin.data.util.FilesystemContainer;
 import com.vaadin.data.util.FilesystemContainer.FileItem;
 import com.vaadin.tests.util.SampleDirectory;
@@ -26,8 +27,8 @@ import com.vaadin.ui.Component.Listener;
 import com.vaadin.ui.Field;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.Panel;
-import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.Tree;
+import com.vaadin.ui.UI.LegacyWindow;
 import com.vaadin.ui.VerticalLayout;
 
 /**
@@ -77,7 +78,8 @@ public class TreeFilesystemContainer extends
         propertyPanel.setEnabled(false);
 
         // Get sample directory
-        final File sampleDir = SampleDirectory.getDirectory(this, w);
+        final File sampleDir = SampleDirectory.getDirectory(
+                Application.getCurrent(), w);
         // Populate tree with FilesystemContainer
         final FilesystemContainer fsc = new FilesystemContainer(sampleDir, true);
         filesystem.setContainerDataSource(fsc);
index a7d2b03415b3fbb1b5b3cae058549358027c0fef..2f81c08ae6b679524ea05b00d30805358ffc5987 100644 (file)
@@ -2,6 +2,7 @@ package com.vaadin.tests.appengine;
 
 import com.google.apphosting.api.DeadlineExceededException;
 import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.data.Property;
 import com.vaadin.data.Property.ValueChangeEvent;
 import com.vaadin.server.ClassResource;
@@ -50,10 +51,10 @@ public class GAESyncTest extends Application.LegacyApplication {
         private static final long serialVersionUID = -6521351715072191625l;
         TextField tf;
         Label l;
-        Application app;
+        LegacyApplication app;
         GridLayout gl;
 
-        private IntrWindow(Application app) {
+        private IntrWindow(LegacyApplication app) {
 
             this.app = app;
             tf = new TextField("Echo thingie");
index 47e766e76a3f9b15c472a7ac0286e889c0afa594..ea8c0c93b60f7f535d23bea4add07015d24737dc 100644 (file)
@@ -18,7 +18,7 @@
 </tr>
 <tr>
        <td>assertText</td>
-       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td>
+       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
        <td>UI id: 0</td>
 </tr>
 <tr>
@@ -28,7 +28,7 @@
 </tr>
 <tr>
        <td>assertText</td>
-       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td>
+       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
        <td>UI id: 0</td>
 </tr>
 <tr>
 </tr>
 <tr>
        <td>assertText</td>
-       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td>
+       <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
        <td>UI id: 0</td>
 </tr>
-
 </tbody></table>
 </body>
 </html>
index 8962f5de9af9a6cbd7a9b22f560a5ef5839f8076..13ceceab6c42e519528ed0a88886d154b9e90c1b 100644 (file)
@@ -1,35 +1,18 @@
 package com.vaadin.tests.application;
 
-import com.vaadin.Application;
 import com.vaadin.annotations.PreserveOnRefresh;
-import com.vaadin.server.AbstractUIProvider;
 import com.vaadin.server.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestApplication;
+import com.vaadin.tests.components.AbstractTestUI;
 import com.vaadin.ui.Label;
-import com.vaadin.ui.UI;
 
-public class RefreshStatePreserve extends AbstractTestApplication {
-    @PreserveOnRefresh
-    public static class RefreshStateUI extends UI {
-        @Override
-        public void init(WrappedRequest request) {
-            getContent().addComponent(
-                    new Label("window.name: "
-                            + request.getBrowserDetails().getWindowName()));
-            getContent().addComponent(new Label("UI id: " + getUIId()));
-        }
-    }
+@PreserveOnRefresh
+public class RefreshStatePreserve extends AbstractTestUI {
 
     @Override
-    public void init() {
-        super.init();
-        addUIProvider(new AbstractUIProvider() {
-            @Override
-            public Class<? extends UI> getUIClass(Application application,
-                    WrappedRequest request) {
-                return RefreshStateUI.class;
-            }
-        });
+    protected void setup(WrappedRequest request) {
+        addComponent(new Label("window.name: "
+                + request.getBrowserDetails().getWindowName()));
+        addComponent(new Label("UI id: " + getUIId()));
     }
 
     @Override
index b7fbca4c040e53f3397f2f5b89394e59b8065f4a..0d3a74615237d4c8281ec6210504155638277e4e 100644 (file)
@@ -29,7 +29,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_15</td>
-       <td>1. null app in class init</td>
+       <td>1. some app in class init</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -39,7 +39,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_13</td>
-       <td>3. null app in app constructor</td>
+       <td>3. some app in app constructor</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -49,7 +49,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_11</td>
-       <td>5. this app in app init</td>
+       <td>5. some app in app init</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -59,7 +59,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_9</td>
-       <td>7. this app in root init</td>
+       <td>7. some app in root init</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -69,7 +69,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_7</td>
-       <td>9. this app in root paint</td>
+       <td>9. some app in root paint</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -79,7 +79,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_5</td>
-       <td>11. this app in background thread</td>
+       <td>11. some app in background thread</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -89,7 +89,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_3</td>
-       <td>13. this app in resource handler</td>
+       <td>13. some app in resource handler</td>
 </tr>
 <tr>
        <td>assertText</td>
@@ -99,7 +99,7 @@
 <tr>
        <td>assertText</td>
        <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_1</td>
-       <td>15. this app in button listener</td>
+       <td>15. some app in button listener</td>
 </tr>
 <tr>
        <td>assertText</td>
index bad5b53478197d72ce0d1ba82ed4b799368653a5..1eda9e54febaaa7be8974cd847ac1237af1b686e 100644 (file)
@@ -1,24 +1,24 @@
 package com.vaadin.tests.application;
 
 import com.vaadin.Application;
-import com.vaadin.server.AbstractUIProvider;
 import com.vaadin.server.DownloadStream;
 import com.vaadin.server.PaintException;
 import com.vaadin.server.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestApplication;
+import com.vaadin.tests.components.AbstractTestCase;
 import com.vaadin.tests.integration.FlagSeResource;
 import com.vaadin.tests.util.Log;
 import com.vaadin.ui.Button;
 import com.vaadin.ui.Button.ClickEvent;
 import com.vaadin.ui.Embedded;
 import com.vaadin.ui.UI;
+import com.vaadin.ui.UI.LegacyWindow;
 
-public class ThreadLocalInstances extends AbstractTestApplication {
+public class ThreadLocalInstances extends AbstractTestCase {
     private static final Application staticInitApplication = Application
             .getCurrent();
     private static final UI staticInitRoot = UI.getCurrent();
 
-    private final UI mainWindow = new UI() {
+    private final LegacyWindow mainWindow = new LegacyWindow() {
         boolean paintReported = false;
 
         @Override
@@ -71,25 +71,13 @@ public class ThreadLocalInstances extends AbstractTestApplication {
     }
 
     @Override
-    public void init() {
+    protected void init() {
         reportCurrentStatus("app init");
-        addUIProvider(new AbstractUIProvider() {
-            @Override
-            public UI createInstance(Application application,
-                    Class<? extends UI> type, WrappedRequest request) {
-                return mainWindow;
-            }
-
-            @Override
-            public Class<? extends UI> getUIClass(Application application,
-                    WrappedRequest request) {
-                return mainWindow.getClass();
-            }
-        });
+        setMainWindow(mainWindow);
     }
 
     @Override
-    protected String getTestDescription() {
+    protected String getDescription() {
         return "Tests the precence of Application.getCurrentApplication() and UI.getCurrentRoot() from different contexts";
     }
 
@@ -113,7 +101,7 @@ public class ThreadLocalInstances extends AbstractTestApplication {
         } else if (value == reference) {
             return "this";
         } else {
-            return value.toString();
+            return "some";
         }
     }
 
diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java b/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java
deleted file mode 100644 (file)
index db17c67..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.vaadin.tests.components;
-
-import com.vaadin.Application;
-import com.vaadin.server.ApplicationContext;
-import com.vaadin.server.WebBrowser;
-
-public abstract class AbstractTestApplication extends Application {
-    protected abstract String getTestDescription();
-
-    protected abstract Integer getTicketNumber();
-
-    protected WebBrowser getBrowser() {
-        ApplicationContext context = getContext();
-        WebBrowser webBrowser = context.getBrowser();
-        return webBrowser;
-    }
-}
diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java b/uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java
new file mode 100644 (file)
index 0000000..3d380c7
--- /dev/null
@@ -0,0 +1,18 @@
+package com.vaadin.tests.components;
+
+import com.vaadin.Application;
+import com.vaadin.server.AbstractUIProvider;
+import com.vaadin.server.ApplicationContext;
+import com.vaadin.server.WebBrowser;
+
+public abstract class AbstractTestUIProvider extends AbstractUIProvider {
+    protected abstract String getTestDescription();
+
+    protected abstract Integer getTicketNumber();
+
+    protected WebBrowser getBrowser() {
+        ApplicationContext context = Application.getCurrent().getContext();
+        WebBrowser webBrowser = context.getBrowser();
+        return webBrowser;
+    }
+}
index 9b29ae1bab64bc0deca267f5e410634e11faf594..327ed0f86b3dd5e8d9eebfed87f0afdbe537575e 100644 (file)
@@ -4,6 +4,7 @@ import java.util.HashSet;
 import java.util.Locale;
 import java.util.Set;
 
+import com.vaadin.Application;
 import com.vaadin.data.Container;
 import com.vaadin.data.Item;
 import com.vaadin.data.Property.ValueChangeEvent;
@@ -54,7 +55,7 @@ public abstract class AbstractComponentDataBindingTest extends TestBase
     }
 
     protected void updateLocale(Locale locale) {
-        setLocale(locale);
+        Application.getCurrent().setLocale(locale);
         for (Component c : fields) {
             removeComponent(c);
         }
index 84c14763ab0baf5072984a0ef1f4be6d383bb835..f640b3f9c4ab5e9ed7bba4cb53ce8f66ed9b09d2 100644 (file)
@@ -1,26 +1,17 @@
 package com.vaadin.tests.components.loginform;
 
-import com.vaadin.Application;
-import com.vaadin.server.AbstractUIProvider;
-import com.vaadin.server.WrappedRequest;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.ui.LoginForm;
 import com.vaadin.ui.LoginForm.LoginEvent;
 import com.vaadin.ui.LoginForm.LoginListener;
-import com.vaadin.ui.UI;
 import com.vaadin.ui.UI.LegacyWindow;
 
 @SuppressWarnings("serial")
-public class LoginFormWithMultipleWindows extends Application {
+public class LoginFormWithMultipleWindows extends LegacyApplication {
 
     @Override
     public void init() {
-        addUIProvider(new AbstractUIProvider() {
-            @Override
-            public Class<? extends UI> getUIClass(Application application,
-                    WrappedRequest request) {
-                return LoginFormWindow.class;
-            }
-        });
+        setMainWindow(new LoginFormWindow());
     }
 
     public static class LoginFormWindow extends LegacyWindow {
index f33037f171b7e02fc5ab787bff84a98dc2c91bc9..b141dc099089991db2e980072dbf0c36ce56dd49 100644 (file)
@@ -1,16 +1,15 @@
 package com.vaadin.tests.components.ui;
 
 import com.vaadin.Application;
-import com.vaadin.server.AbstractUIProvider;
 import com.vaadin.server.ExternalResource;
 import com.vaadin.server.WrappedRequest;
 import com.vaadin.shared.ui.label.ContentMode;
-import com.vaadin.tests.components.AbstractTestApplication;
+import com.vaadin.tests.components.AbstractTestUIProvider;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.Link;
 import com.vaadin.ui.UI;
 
-public class LazyInitUIs extends AbstractTestApplication {
+public class LazyInitUIs extends AbstractTestUIProvider {
 
     // @EagerInit
     private static class EagerInitUI extends UI {
@@ -21,21 +20,15 @@ public class LazyInitUIs extends AbstractTestApplication {
     }
 
     @Override
-    public void init() {
-        addUIProvider(new AbstractUIProvider() {
-
-            @Override
-            public UI createInstance(Application application,
-                    Class<? extends UI> type, WrappedRequest request) {
-                return getUI(request);
-            }
+    public UI createInstance(Application application, Class<? extends UI> type,
+            WrappedRequest request) {
+        return getUI(request);
+    }
 
-            @Override
-            public Class<? extends UI> getUIClass(Application application,
-                    WrappedRequest request) {
-                return getUI(request).getClass();
-            }
-        });
+    @Override
+    public Class<? extends UI> getUIClass(Application application,
+            WrappedRequest request) {
+        return getUI(request).getClass();
     }
 
     private UI getUI(WrappedRequest request) {
@@ -59,14 +52,14 @@ public class LazyInitUIs extends AbstractTestApplication {
                     addComponent(getRequestInfo("NormalUI", request));
 
                     Link lazyCreateLink = new Link("Open lazyCreate UI",
-                            new ExternalResource(getURL()
-                                    + "?lazyCreate#lazyCreate"));
+                            new ExternalResource(Application.getCurrent()
+                                    .getURL() + "?lazyCreate#lazyCreate"));
                     lazyCreateLink.setTargetName("_blank");
                     addComponent(lazyCreateLink);
 
                     Link lazyInitLink = new Link("Open eagerInit UI",
-                            new ExternalResource(getURL()
-                                    + "?eagerInit#eagerInit"));
+                            new ExternalResource(Application.getCurrent()
+                                    .getURL() + "?eagerInit#eagerInit"));
                     lazyInitLink.setTargetName("_blank");
                     addComponent(lazyInitLink);
                 }
index fe2fe16d938ce9cbff3a20090ac4d44c4a46dfd5..9a66e9ad0ac8b2e99a74e82c1215d4a98ba66839 100644 (file)
@@ -1,34 +1,40 @@
 package com.vaadin.tests.components.ui;
 
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import com.vaadin.Application;
-import com.vaadin.server.AbstractUIProvider;
 import com.vaadin.server.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestApplication;
+import com.vaadin.tests.components.AbstractTestUIProvider;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.UI;
 
-public class UIsInMultipleTabs extends AbstractTestApplication {
-    private int numberOfUIsOpened;
+public class UIsInMultipleTabs extends AbstractTestUIProvider {
+    // No cleanup -> will leak, but shouldn't matter for tests
+    private static ConcurrentHashMap<Application, AtomicInteger> numberOfUIsOpened = new ConcurrentHashMap<Application, AtomicInteger>();
 
     public static class TabUI extends UI {
         @Override
         protected void init(WrappedRequest request) {
-            UIsInMultipleTabs application = (UIsInMultipleTabs) getApplication();
-            String message = "This is UI number "
-                    + ++application.numberOfUIsOpened;
+            Application application = Application.getCurrent();
+            AtomicInteger count = numberOfUIsOpened.get(application);
+            if (count == null) {
+                numberOfUIsOpened.putIfAbsent(application, new AtomicInteger());
+                // Get our added instance or another instance that was added by
+                // another thread between previous get and putIfAbsent
+                count = numberOfUIsOpened.get(application);
+            }
+            int currentCount = count.incrementAndGet();
+            String message = "This is UI number " + currentCount;
 
             addComponent(new Label(message));
         }
     }
 
-    public UIsInMultipleTabs() {
-        addUIProvider(new AbstractUIProvider() {
-            @Override
-            public Class<? extends UI> getUIClass(Application application,
-                    WrappedRequest request) {
-                return TabUI.class;
-            }
-        });
+    @Override
+    public Class<? extends UI> getUIClass(Application application,
+            WrappedRequest request) {
+        return TabUI.class;
     }
 
     @Override
index 8da94feb7f0d95374a1e913a11ac7a41c20f0e85..44704041053782736f34c619eda6faaf76768785 100644 (file)
@@ -2,7 +2,7 @@ package com.vaadin.tests.layouts.layouttester;
 
 import java.util.Date;
 
-import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.server.Resource;
 import com.vaadin.server.SystemError;
 import com.vaadin.server.ThemeResource;
@@ -32,7 +32,7 @@ public class GridLayoutTests extends AbstractLayoutTests {
 
     private AbstractComponent rc1, col1, col2, col3, row1, row2, row3, x3, x22;
 
-    public GridLayoutTests(Application application) {
+    public GridLayoutTests(LegacyApplication application) {
         super();
     }
 
index 0042f0ba117981255c14cbbabf463120c259dfa6..eb0976dfb9ee293ffc486176fc55a46c34322b21 100644 (file)
@@ -1,6 +1,6 @@
 package com.vaadin.tests.layouts.layouttester;
 
-import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.server.Resource;
 import com.vaadin.server.SystemError;
 import com.vaadin.server.ThemeResource;
@@ -26,7 +26,7 @@ import com.vaadin.ui.themes.Reindeer;
 
 public class HorizontalLayoutTests extends AbstractLayoutTests {
 
-    public HorizontalLayoutTests(Application application) {
+    public HorizontalLayoutTests(LegacyApplication application) {
         super();
     }
 
index 3e668289fe8ce1b06ae2dd38e57f9a17bcf28577..f6cf3a4bae03254fb928495b665f65f42cc9726f 100644 (file)
@@ -1,6 +1,6 @@
 package com.vaadin.tests.layouts.layouttester;
 
-import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
 import com.vaadin.server.Resource;
 import com.vaadin.server.SystemError;
 import com.vaadin.server.ThemeResource;
@@ -26,7 +26,7 @@ import com.vaadin.ui.VerticalLayout;
 
 public class VerticalLayoutTests extends AbstractLayoutTests {
 
-    public VerticalLayoutTests(Application application) {
+    public VerticalLayoutTests(LegacyApplication application) {
         super();
     }
 
index 8c2a816e1cd90b0e7a6da2477ab51642f912e861..05da2506e824fbefb47a2dfa27e5c6cb21565e93 100644 (file)
@@ -31,35 +31,29 @@ import com.vaadin.ui.UI;
  * @author Vaadin Ltd
  * @since 7.0.0
  */
-public class DifferentFeaturesForDifferentClients extends Application {
+public class DifferentFeaturesForDifferentClients extends AbstractUIProvider {
 
     @Override
-    public void init() {
-        super.init();
-        addUIProvider(new AbstractUIProvider() {
-            @Override
-            public Class<? extends UI> getUIClass(Application application,
-                    WrappedRequest request) {
-                // could also use browser version etc.
-                if (request.getHeader("user-agent").contains("mobile")) {
-                    return TouchRoot.class;
-                } else {
-                    return DefaultRoot.class;
-                }
-            }
+    public Class<? extends UI> getUIClass(Application application,
+            WrappedRequest request) {
+        // could also use browser version etc.
+        if (request.getHeader("user-agent").contains("mobile")) {
+            return TouchRoot.class;
+        } else {
+            return DefaultRoot.class;
+        }
+    }
 
-            // Must override as default implementation isn't allowed to
-            // instantiate our non-public classes
-            @Override
-            public UI createInstance(Application application,
-                    Class<? extends UI> type, WrappedRequest request) {
-                try {
-                    return type.newInstance();
-                } catch (Exception e) {
-                    throw new RuntimeException(e);
-                }
-            }
-        });
+    // Must override as default implementation isn't allowed to
+    // instantiate our non-public classes
+    @Override
+    public UI createInstance(Application application, Class<? extends UI> type,
+            WrappedRequest request) {
+        try {
+            return type.newInstance();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 }
 
index 37f9197285dfb1bfd4c7d79e3172731f5ee21425..7cbe8cb6cf6027664d8063d8c6b5eed83869c431 100644 (file)
@@ -28,7 +28,7 @@ public class Ticket1589 extends Application.LegacyApplication {
 
         MyDynamicResource res = new MyDynamicResource();
 
-        addRequestHandler(res);
+        Application.getCurrent().addRequestHandler(res);
 
         w.addComponent(new Link(
                 "Test (without Content-Disposition, should suggest generatedFile.png when saving, browser default for actual disposition)",
index ac5f990915ae8e2b860de62bca8ed20a97f082ff..17314c3fb6692686743dbb4cb6d1ab0e387950f1 100644 (file)
@@ -42,7 +42,7 @@ public class Ticket1921 extends Application.LegacyApplication implements
 
         newState();
 
-        addRequestHandler(this);
+        Application.getCurrent().addRequestHandler(this);
     }
 
     public void newState() {
index ce7960a169b1133b7164fb3e4a972244f683f62c..f3b5b684913631a7bb1c9c815daeb6930939910e 100644 (file)
@@ -44,7 +44,7 @@ public class Ticket2292 extends com.vaadin.Application.LegacyApplication
         Link l = new Link("l", icon);
         main.addComponent(l);
 
-        addRequestHandler(this);
+        Application.getCurrent().addRequestHandler(this);
     }
 
     @Override