summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/Application.java184
-rw-r--r--server/src/com/vaadin/server/AbstractUIProvider.java5
-rw-r--r--server/src/com/vaadin/server/LegacyVaadinPortlet.java62
-rw-r--r--server/src/com/vaadin/server/LegacyVaadinServlet.java63
-rw-r--r--server/src/com/vaadin/server/ServletPortletHelper.java38
-rw-r--r--server/src/com/vaadin/server/UIProvider.java19
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java49
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java67
-rw-r--r--uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java25
-rw-r--r--uitest/src/com/vaadin/tests/Parameters.java4
-rw-r--r--uitest/src/com/vaadin/tests/TestBench.java4
-rw-r--r--uitest/src/com/vaadin/tests/TreeFilesystem.java6
-rw-r--r--uitest/src/com/vaadin/tests/TreeFilesystemContainer.java6
-rw-r--r--uitest/src/com/vaadin/tests/appengine/GAESyncTest.java5
-rw-r--r--uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html7
-rw-r--r--uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java31
-rw-r--r--uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html16
-rw-r--r--uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java28
-rw-r--r--uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java (renamed from uitest/src/com/vaadin/tests/components/AbstractTestApplication.java)5
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java3
-rw-r--r--uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java15
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java35
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java36
-rw-r--r--uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java4
-rw-r--r--uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java4
-rw-r--r--uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java4
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java46
-rw-r--r--uitest/src/com/vaadin/tests/tickets/Ticket1589.java2
-rw-r--r--uitest/src/com/vaadin/tests/tickets/Ticket1921.java2
-rw-r--r--uitest/src/com/vaadin/tests/tickets/Ticket2292.java2
30 files changed, 473 insertions, 304 deletions
diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java
index 745d0ad784..634f96bfe1 100644
--- a/server/src/com/vaadin/Application.java
+++ b/server/src/com/vaadin/Application.java
@@ -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);
+ }
+
}
diff --git a/server/src/com/vaadin/server/AbstractUIProvider.java b/server/src/com/vaadin/server/AbstractUIProvider.java
index 49f8e3ec77..c7a137ebbd 100644
--- a/server/src/com/vaadin/server/AbstractUIProvider.java
+++ b/server/src/com/vaadin/server/AbstractUIProvider.java
@@ -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
index 0000000000..036242a0c2
--- /dev/null
+++ b/server/src/com/vaadin/server/LegacyVaadinPortlet.java
@@ -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
index 0000000000..f53e9d4bf0
--- /dev/null
+++ b/server/src/com/vaadin/server/LegacyVaadinServlet.java
@@ -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;
+ }
+
+}
diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java
index 26913d8ba8..18fbb66114 100644
--- a/server/src/com/vaadin/server/ServletPortletHelper.java
+++ b/server/src/com/vaadin/server/ServletPortletHelper.java
@@ -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.");
+ }
+ }
+
}
diff --git a/server/src/com/vaadin/server/UIProvider.java b/server/src/com/vaadin/server/UIProvider.java
index 60b79cdbb9..6a45b06c63 100644
--- a/server/src/com/vaadin/server/UIProvider.java
+++ b/server/src/com/vaadin/server/UIProvider.java
@@ -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);
+
}
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index bf8fb5dc84..eae01e9369 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -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 {
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index ba19072503..8f33382110 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -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;
}
@@ -849,35 +869,6 @@ public class VaadinServlet extends HttpServlet implements Constants {
}
/**
- * 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.
*
* @param request
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
index 3d63c7dfb9..3372651e5c 100644
--- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
+++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
@@ -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");
diff --git a/uitest/src/com/vaadin/tests/Parameters.java b/uitest/src/com/vaadin/tests/Parameters.java
index b16d4ef65b..f5ab18cfe3 100644
--- a/uitest/src/com/vaadin/tests/Parameters.java
+++ b/uitest/src/com/vaadin/tests/Parameters.java
@@ -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, "
diff --git a/uitest/src/com/vaadin/tests/TestBench.java b/uitest/src/com/vaadin/tests/TestBench.java
index 67e1180d75..bae677001a 100644
--- a/uitest/src/com/vaadin/tests/TestBench.java
+++ b/uitest/src/com/vaadin/tests/TestBench.java
@@ -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;
diff --git a/uitest/src/com/vaadin/tests/TreeFilesystem.java b/uitest/src/com/vaadin/tests/TreeFilesystem.java
index f2a0d97b08..2e7b215ad7 100644
--- a/uitest/src/com/vaadin/tests/TreeFilesystem.java
+++ b/uitest/src/com/vaadin/tests/TreeFilesystem.java
@@ -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);
diff --git a/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java b/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java
index 672c518ea8..8107ea702d 100644
--- a/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java
+++ b/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java
@@ -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);
diff --git a/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java b/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
index a7d2b03415..2f81c08ae6 100644
--- a/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
+++ b/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
@@ -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");
diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html
index 47e766e76a..ea8c0c93b6 100644
--- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html
+++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html
@@ -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>
@@ -43,10 +43,9 @@
</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>
diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
index 8962f5de9a..13ceceab6c 100644
--- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
+++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
@@ -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
diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html
index b7fbca4c04..0d3a746152 100644
--- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html
+++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html
@@ -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>
diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
index bad5b53478..1eda9e54fe 100644
--- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
+++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
@@ -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/AbstractTestUIProvider.java
index db17c67fdd..3d380c7835 100644
--- a/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java
+++ b/uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java
@@ -1,16 +1,17 @@
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 AbstractTestApplication extends Application {
+public abstract class AbstractTestUIProvider extends AbstractUIProvider {
protected abstract String getTestDescription();
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- ApplicationContext context = getContext();
+ ApplicationContext context = Application.getCurrent().getContext();
WebBrowser webBrowser = context.getBrowser();
return webBrowser;
}
diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java b/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java
index 9b29ae1bab..327ed0f86b 100644
--- a/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java
+++ b/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java
@@ -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);
}
diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
index 84c14763ab..f640b3f9c4 100644
--- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
+++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
@@ -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 {
diff --git a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
index f33037f171..b141dc0990 100644
--- a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
+++ b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
@@ -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);
}
diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
index fe2fe16d93..9a66e9ad0a 100644
--- a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
+++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
@@ -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
diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java b/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java
index 8da94feb7f..4470404105 100644
--- a/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java
+++ b/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java
@@ -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();
}
diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java b/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java
index 0042f0ba11..eb0976dfb9 100644
--- a/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java
+++ b/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java
@@ -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();
}
diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java b/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java
index 3e668289fe..f6cf3a4bae 100644
--- a/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java
+++ b/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java
@@ -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();
}
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
index 8c2a816e1c..05da2506e8 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
@@ -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);
+ }
}
}
diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket1589.java b/uitest/src/com/vaadin/tests/tickets/Ticket1589.java
index 37f9197285..7cbe8cb6cf 100644
--- a/uitest/src/com/vaadin/tests/tickets/Ticket1589.java
+++ b/uitest/src/com/vaadin/tests/tickets/Ticket1589.java
@@ -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)",
diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket1921.java b/uitest/src/com/vaadin/tests/tickets/Ticket1921.java
index ac5f990915..17314c3fb6 100644
--- a/uitest/src/com/vaadin/tests/tickets/Ticket1921.java
+++ b/uitest/src/com/vaadin/tests/tickets/Ticket1921.java
@@ -42,7 +42,7 @@ public class Ticket1921 extends Application.LegacyApplication implements
newState();
- addRequestHandler(this);
+ Application.getCurrent().addRequestHandler(this);
}
public void newState() {
diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2292.java b/uitest/src/com/vaadin/tests/tickets/Ticket2292.java
index ce7960a169..f3b5b68491 100644
--- a/uitest/src/com/vaadin/tests/tickets/Ticket2292.java
+++ b/uitest/src/com/vaadin/tests/tickets/Ticket2292.java
@@ -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