diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-09-05 19:30:41 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-09-05 19:30:41 +0300 |
commit | cc3ddcac953a087b09ae330ff37126dcd5ec727f (patch) | |
tree | 35a0b367042298b212038e9cba0ea7d81e6909c3 | |
parent | d1c361e251800c6f7d596ddf79ed1c7569196856 (diff) | |
download | vaadin-framework-cc3ddcac953a087b09ae330ff37126dcd5ec727f.tar.gz vaadin-framework-cc3ddcac953a087b09ae330ff37126dcd5ec727f.zip |
Remove getApplication() and add getSession() (#9402)
33 files changed, 122 insertions, 135 deletions
diff --git a/server/src/com/vaadin/LegacyApplication.java b/server/src/com/vaadin/LegacyApplication.java index 9f02a2d588..66b2ca3973 100644 --- a/server/src/com/vaadin/LegacyApplication.java +++ b/server/src/com/vaadin/LegacyApplication.java @@ -68,9 +68,9 @@ public abstract class LegacyApplication extends AbstractUIProvider implements if (this.mainWindow != null) { throw new IllegalStateException("mainWindow has already been set"); } - if (mainWindow.getApplication() == null) { - mainWindow.setApplication(VaadinSession.getCurrent()); - } else if (mainWindow.getApplication() != VaadinSession.getCurrent()) { + if (mainWindow.getSession() == null) { + mainWindow.setSession(VaadinSession.getCurrent()); + } else if (mainWindow.getSession() != VaadinSession.getCurrent()) { throw new IllegalStateException( "mainWindow is attached to another application"); } @@ -242,7 +242,7 @@ public abstract class LegacyApplication extends AbstractUIProvider implements } legacyUINames.put(uI.getName(), uI); - uI.setApplication(VaadinSession.getCurrent()); + uI.setSession(VaadinSession.getCurrent()); } /** diff --git a/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java b/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java index 6258aed423..dee807c610 100644 --- a/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java +++ b/server/src/com/vaadin/event/dd/acceptcriteria/SourceIs.java @@ -48,7 +48,7 @@ public class SourceIs extends ClientSideCriterion { int paintedComponents = 0; for (int i = 0; i < components.length; i++) { Component c = components[i]; - if (c.getApplication() != null) { + if (c.getUI() != null && c.getUI().getSession() != null) { target.addAttribute("component" + paintedComponents++, c); } else { Logger.getLogger(SourceIs.class.getName()) diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 82a154d4e5..f8fbbeeb4c 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -342,11 +342,11 @@ public abstract class AbstractClientConnector implements ClientConnector { @Override public String getConnectorId() { if (connectorId == null) { - if (getApplication() == null) { + if (getSession() == null) { throw new RuntimeException( "Component must be attached to an application when getConnectorId() is called for the first time"); } - connectorId = getApplication().createConnectorId(this); + connectorId = getSession().createConnectorId(this); } return connectorId; } @@ -357,12 +357,12 @@ public abstract class AbstractClientConnector implements ClientConnector { * * @return The connector's application, or <code>null</code> if not attached */ - protected VaadinSession getApplication() { + protected VaadinSession getSession() { UI uI = getUI(); if (uI == null) { return null; } else { - return uI.getApplication(); + return uI.getSession(); } } @@ -501,7 +501,7 @@ public abstract class AbstractClientConnector implements ClientConnector { } // Send detach event if the component have been connected to a window - if (getApplication() != null) { + if (getSession() != null) { detach(); } @@ -509,7 +509,7 @@ public abstract class AbstractClientConnector implements ClientConnector { this.parent = parent; // Send attach event if connected to an application - if (getApplication() != null) { + if (getSession() != null) { attach(); } } @@ -535,7 +535,7 @@ public abstract class AbstractClientConnector implements ClientConnector { * {@inheritDoc} * * <p> - * The {@link #getApplication()} and {@link #getUI()} methods might return + * The {@link #getSession()} and {@link #getUI()} methods might return * <code>null</code> after this method is called. * </p> */ diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 71f5a07d77..4f408d6fe9 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -676,7 +676,7 @@ public abstract class AbstractCommunicationManager implements Serializable { } sb.append("\nComponent hierarchy:\n"); - VaadinSession application2 = component.getApplication(); + VaadinSession application2 = component.getUI().getSession(); sb.append(application2.getClass().getName()); sb.append("."); sb.append(application2.getClass().getSimpleName()); @@ -789,7 +789,7 @@ public abstract class AbstractCommunicationManager implements Serializable { final PrintWriter outWriter, UI ui, boolean analyzeLayouts) throws PaintException, JSONException { ArrayList<ClientConnector> dirtyVisibleConnectors = new ArrayList<ClientConnector>(); - VaadinSession application = ui.getApplication(); + VaadinSession application = ui.getSession(); // Paints components ConnectorTracker uiConnectorTracker = ui.getConnectorTracker(); getLogger().log(Level.FINE, "* Creating response to client"); @@ -1697,7 +1697,7 @@ public abstract class AbstractCommunicationManager implements Serializable { if (connector instanceof Component) { errorComponent = (Component) connector; } - handleChangeVariablesError(uI.getApplication(), + handleChangeVariablesError(uI.getSession(), errorComponent, realException, null); } } else { @@ -1729,7 +1729,7 @@ public abstract class AbstractCommunicationManager implements Serializable { errorComponent = (Component) dropHandlerOwner; } } - handleChangeVariablesError(uI.getApplication(), + handleChangeVariablesError(uI.getSession(), errorComponent, e, changes); } } @@ -2154,8 +2154,8 @@ public abstract class AbstractCommunicationManager implements Serializable { * Ends the Application. * * The browser is redirected to the Application logout URL set with - * {@link VaadinSession#setLogoutURL(String)}, or to the application URL if no - * logout URL is given. + * {@link VaadinSession#setLogoutURL(String)}, or to the application URL if + * no logout URL is given. * * @param request * the request instance. @@ -2450,7 +2450,7 @@ public abstract class AbstractCommunicationManager implements Serializable { StringWriter sWriter = new StringWriter(); PrintWriter pWriter = new PrintWriter(sWriter); pWriter.print("{"); - if (isXSRFEnabled(uI.getApplication())) { + if (isXSRFEnabled(uI.getSession())) { pWriter.print(getSecurityKeyUIDL(request)); } writeUidlResponse(request, true, pWriter, uI, false); diff --git a/server/src/com/vaadin/server/CommunicationManager.java b/server/src/com/vaadin/server/CommunicationManager.java index 3cc8831901..32c4d2c217 100644 --- a/server/src/com/vaadin/server/CommunicationManager.java +++ b/server/src/com/vaadin/server/CommunicationManager.java @@ -112,7 +112,7 @@ public class CommunicationManager extends AbstractCommunicationManager { protected InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) { VaadinServletSession context = (VaadinServletSession) uI - .getApplication(); + .getSession(); ServletContext servletContext = context.getHttpSession() .getServletContext(); return servletContext.getResourceAsStream("/" diff --git a/server/src/com/vaadin/server/ConnectorResourceHandler.java b/server/src/com/vaadin/server/ConnectorResourceHandler.java index 80d3a60a1a..6702fb140f 100644 --- a/server/src/com/vaadin/server/ConnectorResourceHandler.java +++ b/server/src/com/vaadin/server/ConnectorResourceHandler.java @@ -44,7 +44,7 @@ public class ConnectorResourceHandler implements RequestHandler { } UI.setCurrent(ui); - VaadinSession.setCurrent(ui.getApplication()); + VaadinSession.setCurrent(ui.getSession()); ClientConnector connector = ui.getConnectorTracker().getConnector( cid); diff --git a/server/src/com/vaadin/server/JsonPaintTarget.java b/server/src/com/vaadin/server/JsonPaintTarget.java index b193c47528..d2f90c33b6 100644 --- a/server/src/com/vaadin/server/JsonPaintTarget.java +++ b/server/src/com/vaadin/server/JsonPaintTarget.java @@ -345,7 +345,7 @@ public class JsonPaintTarget implements PaintTarget { throw new NullPointerException(); } ClientConnector ownerConnector = openPaintables.peek(); - ownerConnector.getUI().getApplication().getGlobalResourceHandler(true) + ownerConnector.getUI().getSession().getGlobalResourceHandler(true) .register(value, ownerConnector); ResourceReference reference = ResourceReference.create(value, diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index a1c181dcb9..9a0948edc8 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -391,7 +391,7 @@ public class Page implements Serializable { } public WebBrowser getWebBrowser() { - return uI.getApplication().getBrowser(); + return uI.getSession().getBrowser(); } public void setBrowserWindowSize(int width, int height) { diff --git a/server/src/com/vaadin/server/PortletCommunicationManager.java b/server/src/com/vaadin/server/PortletCommunicationManager.java index 6eccfa6084..1a2b892a32 100644 --- a/server/src/com/vaadin/server/PortletCommunicationManager.java +++ b/server/src/com/vaadin/server/PortletCommunicationManager.java @@ -157,7 +157,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { protected InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) { VaadinPortletSession context = (VaadinPortletSession) uI - .getApplication(); + .getSession(); PortletContext portletContext = context.getPortletSession() .getPortletContext(); return portletContext.getResourceAsStream("/" diff --git a/server/src/com/vaadin/server/ResourceReference.java b/server/src/com/vaadin/server/ResourceReference.java index 098fb6c3e4..815cbee275 100644 --- a/server/src/com/vaadin/server/ResourceReference.java +++ b/server/src/com/vaadin/server/ResourceReference.java @@ -71,7 +71,7 @@ public class ResourceReference extends URLReference { ConnectorResource connectorResource = (ConnectorResource) resource; GlobalResourceHandler globalResourceHandler = connector.getUI() - .getApplication().getGlobalResourceHandler(false); + .getSession().getGlobalResourceHandler(false); if (globalResourceHandler != null) { String uri = globalResourceHandler.getUri(connector, connectorResource); diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index 10532559f0..440fc02ee6 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -1706,8 +1706,8 @@ public class VaadinSession implements Terminal.ErrorListener, UI ui = createUIInstance(request, uiClass); // Initialize some fields for a newly created UI - if (ui.getApplication() == null) { - ui.setApplication(this); + if (ui.getSession() == null) { + ui.setSession(this); } // Get the next id Integer uiId = Integer.valueOf(nextUIId++); diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index e6cc80f1cf..85938c4fe3 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -259,7 +259,7 @@ public abstract class AbstractComponent extends AbstractClientConnector if (parent != null) { return parent.getLocale(); } - final VaadinSession app = getApplication(); + final VaadinSession app = getSession(); if (app != null) { return app.getLocale(); } @@ -616,7 +616,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ protected void focus() { if (this instanceof Focusable) { - final VaadinSession app = getApplication(); + final VaadinSession app = getSession(); if (app != null) { getUI().setFocusedComponent((Focusable) this); delayedFocus = false; @@ -627,31 +627,6 @@ public abstract class AbstractComponent extends AbstractClientConnector } /** - * Gets the application object to which the component is attached. - * - * <p> - * The method will return {@code null} if the component is not currently - * attached to an application. This is often a problem in constructors of - * regular components and in the initializers of custom composite - * components. A standard workaround is to move the problematic - * initialization to {@link #attach()}, as described in the documentation of - * the method. - * </p> - * <p> - * <b>This method is not meant to be overridden. Due to CDI requirements we - * cannot declare it as final even though it should be final.</b> - * </p> - * - * @return the parent application of the component or <code>null</code>. - * @see #attach() - */ - @Override - public VaadinSession getApplication() { - // Just make method inherited from Component interface public - return super.getApplication(); - } - - /** * Build CSS compatible string representation of height. * * @return CSS height diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 548cb06c8f..f673babc26 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -697,7 +697,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ public void setConverter(Class<?> datamodelType) { Converter<T, ?> c = (Converter<T, ?>) ConverterUtil.getConverter( - getType(), datamodelType, getApplication()); + getType(), datamodelType, getSession()); setConverter(c); } diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index 812edbb8d2..492e0c25c6 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -26,7 +26,6 @@ import com.vaadin.server.ClientConnector; import com.vaadin.server.ErrorMessage; import com.vaadin.server.Resource; import com.vaadin.server.Sizeable; -import com.vaadin.server.VaadinSession; import com.vaadin.server.VariableOwner; /** @@ -522,34 +521,12 @@ public interface Component extends ClientConnector, Sizeable, Serializable { public UI getUI(); /** - * Gets the application object to which the component is attached. - * - * <p> - * The method will return {@code null} if the component is not currently - * attached to an application. - * </p> - * - * <p> - * Getting a null value is often a problem in constructors of regular - * components and in the initializers of custom composite components. A - * standard workaround is to use {@link VaadinSession#getCurrent()} to - * retrieve the application instance that the current request relates to. - * Another way is to move the problematic initialization to - * {@link #attach()}, as described in the documentation of the method. - * </p> - * - * @return the parent application of the component or <code>null</code>. - * @see #attach() - */ - public VaadinSession getApplication(); - - /** * {@inheritDoc} * * <p> * Reimplementing the {@code attach()} method is useful for tasks that need * to get a reference to the parent, window, or application object with the - * {@link #getParent()}, {@link #getUI()}, and {@link #getApplication()} + * {@link #getParent()}, {@link #getUI()}, and {@link #getSession()} * methods. A component does not yet know these objects in the constructor, * so in such case, the methods will return {@code null}. For example, the * following is invalid: diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index c84b75ca51..d454df98ee 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -152,7 +152,7 @@ public class ConnectorTracker implements Serializable { } private void removeFromGlobalResourceHandler(ClientConnector connector) { - GlobalResourceHandler globalResourceHandler = uI.getApplication() + GlobalResourceHandler globalResourceHandler = uI.getSession() .getGlobalResourceHandler(false); // Nothing to do if there is no handler if (globalResourceHandler != null) { diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java index ff4a5dcb07..53b618a87f 100644 --- a/server/src/com/vaadin/ui/Label.java +++ b/server/src/com/vaadin/ui/Label.java @@ -254,7 +254,7 @@ public class Label extends AbstractComponent implements Property<String>, newDataSource.getType())) { // Try to find a converter Converter<String, ?> c = ConverterUtil.getConverter(String.class, - newDataSource.getType(), getApplication()); + newDataSource.getType(), getSession()); setConverter(c); } dataSource = newDataSource; diff --git a/server/src/com/vaadin/ui/LoginForm.java b/server/src/com/vaadin/ui/LoginForm.java index 1d0c5c41b6..b57b271778 100644 --- a/server/src/com/vaadin/ui/LoginForm.java +++ b/server/src/com/vaadin/ui/LoginForm.java @@ -132,7 +132,7 @@ public class LoginForm extends CustomComponent { * @return byte array containing login page html */ protected byte[] getLoginHTML() { - String appUri = getApplication().getURL().toString(); + String appUri = getSession().getURL().toString(); try { return ("<!DOCTYPE html PUBLIC \"-//W3C//DTD " @@ -186,13 +186,13 @@ public class LoginForm extends CustomComponent { @Override public void attach() { super.attach(); - getApplication().addRequestHandler(requestHandler); + getSession().addRequestHandler(requestHandler); iframe.setSource(loginPage); } @Override public void detach() { - getApplication().removeRequestHandler(requestHandler); + getSession().removeRequestHandler(requestHandler); super.detach(); } diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 65189fed0c..e0469f6522 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -3717,7 +3717,7 @@ public class Table extends AbstractSelect implements Action.Container, converter = getConverter(colId); } else { ConverterUtil.getConverter(String.class, property.getType(), - getApplication()); + getSession()); } Object value = property.getValue(); if (converter != null) { diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index e2d79454f6..0b376f54c1 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -27,7 +27,6 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; -import com.vaadin.LegacyApplication; import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.event.ActionManager; @@ -174,7 +173,7 @@ public abstract class UI extends AbstractComponentContainer implements public void setName(String name) { this.name = name; // The name can not be changed in application - if (getApplication() != null) { + if (getSession() != null) { throw new IllegalStateException( "Window name can not be changed while " + "the window is in application"); @@ -193,7 +192,7 @@ public abstract class UI extends AbstractComponentContainer implements * to an application */ public URL getURL() { - VaadinSession application = getApplication(); + VaadinSession application = getSession(); if (application == null) { return null; } @@ -424,7 +423,7 @@ public abstract class UI extends AbstractComponentContainer implements /** * The application to which this UI belongs */ - private VaadinSession application; + private VaadinSession session; /** * List of windows in this UI. @@ -563,9 +562,29 @@ public abstract class UI extends AbstractComponentContainer implements throw new UnsupportedOperationException(); } + /** + * Gets the application object to which the component is attached. + * + * <p> + * The method will return {@code null} if the component is not currently + * attached to an application. + * </p> + * + * <p> + * Getting a null value is often a problem in constructors of regular + * components and in the initializers of custom composite components. A + * standard workaround is to use {@link VaadinSession#getCurrent()} to + * retrieve the application instance that the current request relates to. + * Another way is to move the problematic initialization to + * {@link #attach()}, as described in the documentation of the method. + * </p> + * + * @return the parent application of the component or <code>null</code>. + * @see #attach() + */ @Override - public VaadinSession getApplication() { - return application; + public VaadinSession getSession() { + return session; } @Override @@ -676,25 +695,25 @@ public abstract class UI extends AbstractComponentContainer implements * This method is mainly intended for internal use by the framework. * </p> * - * @param application + * @param session * the application to set * * @throws IllegalStateException * if the application has already been set * - * @see #getApplication() + * @see #getSession() */ - public void setApplication(VaadinSession application) { - if ((application == null) == (this.application == null)) { + public void setSession(VaadinSession session) { + if ((session == null) == (this.session == null)) { throw new IllegalStateException("Application has already been set"); } else { - if (application == null) { + if (session == null) { detach(); } - this.application = application; + this.session = session; } - if (application != null) { + if (session != null) { attach(); } } @@ -703,8 +722,8 @@ public abstract class UI extends AbstractComponentContainer implements * Gets the id of the UI, used to identify this UI within its application * when processing requests. The UI id should be present in every request to * the server that originates from this UI. - * {@link VaadinSession#getUIForRequest(WrappedRequest)} uses this id to find - * the route to which the request belongs. + * {@link VaadinSession#getUIForRequest(WrappedRequest)} uses this id to + * find the route to which the request belongs. * * @return */ @@ -732,7 +751,7 @@ public abstract class UI extends AbstractComponentContainer implements throw new NullPointerException("Argument must not be null"); } - if (window.getApplication() != null) { + if (window.getUI() != null && window.getUI().getSession() != null) { throw new IllegalArgumentException( "Window is already attached to an application."); } @@ -937,7 +956,7 @@ public abstract class UI extends AbstractComponentContainer implements throw new IllegalStateException("UI id has already been defined"); } this.uiId = uiId; - theme = getApplication().getUiProvider(request, getClass()) + theme = getSession().getUiProvider(request, getClass()) .getThemeForUI(request, getClass()); getPage().init(request); diff --git a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java index 66160907b2..b64514ea14 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java +++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java @@ -72,7 +72,7 @@ public class ConverterFactory extends TestCase { TextField tf = new TextField("", "123") { @Override - public VaadinSession getApplication() { + public VaadinSession getSession() { return appWithCustomIntegerConverter; }; }; @@ -103,7 +103,7 @@ public class ConverterFactory extends TestCase { TextField tf = new TextField("", "123") { @Override - public VaadinSession getApplication() { + public VaadinSession getSession() { return fieldAppWithCustomIntegerConverter; } }; diff --git a/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java b/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java index e286e7231e..0dd7efa507 100644 --- a/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java +++ b/server/tests/src/com/vaadin/tests/server/TestStreamVariableMapping.java @@ -30,7 +30,7 @@ public class TestStreamVariableMapping extends TestCase { } @Override - public VaadinSession getApplication() { + public VaadinSession getSession() { return application; } }; diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java index d372b96339..b48ad62bcc 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java @@ -190,7 +190,7 @@ public class AbstractFieldValueConversions extends TestCase { VaadinSession.setCurrent(a); TextField tf = new TextField() { @Override - public VaadinSession getApplication() { + public VaadinSession getSession() { return a; } }; diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java index b498bbe73f..c9f579a887 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java @@ -29,7 +29,7 @@ public class RemoveListenersOnDetach { } @Override - public VaadinSession getApplication() { + public VaadinSession getSession() { return application; } @@ -59,7 +59,7 @@ public class RemoveListenersOnDetach { }; @Override - public VaadinSession getApplication() { + public VaadinSession getSession() { return application; }; }; diff --git a/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java b/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java index bab7ca2c8c..ec722fdffb 100644 --- a/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java +++ b/server/tests/src/com/vaadin/tests/server/component/window/AttachDetachWindow.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; +import com.vaadin.server.ClientConnector; import com.vaadin.server.VaadinSession; import com.vaadin.server.WrappedRequest; import com.vaadin.ui.Label; @@ -23,7 +24,7 @@ public class AttachDetachWindow { public TestContent getTestContent(); - public VaadinSession getApplication(); + public VaadinSession getSession(); } private class TestWindow extends Window implements TestContainer { @@ -61,6 +62,11 @@ public class AttachDetachWindow { public TestContent getTestContent() { return testContent; } + + @Override + public VaadinSession getSession() { + return super.getSession(); + } } private class TestContent extends VerticalLayout { @@ -155,7 +161,7 @@ public class AttachDetachWindow { assertUnattached(sub); // attaching main should recurse to sub - main.setApplication(testApp); + main.setSession(testApp); assertAttached(main); assertAttached(sub); } @@ -165,7 +171,7 @@ public class AttachDetachWindow { assertUnattached(main); assertUnattached(sub); - main.setApplication(testApp); + main.setSession(testApp); assertAttached(main); assertUnattached(sub); @@ -177,7 +183,7 @@ public class AttachDetachWindow { @Test public void removeSubWindowBeforeDetachingMainWindow() { - main.setApplication(testApp); + main.setSession(testApp); main.addWindow(sub); // sub should be detached when removing from attached main @@ -186,18 +192,18 @@ public class AttachDetachWindow { assertDetached(sub); // main detach should recurse to sub - main.setApplication(null); + main.setSession(null); assertDetached(main); assertDetached(sub); } @Test public void removeSubWindowAfterDetachingMainWindow() { - main.setApplication(testApp); + main.setSession(testApp); main.addWindow(sub); // main detach should recurse to sub - main.setApplication(null); + main.setSession(null); assertDetached(main); assertDetached(sub); @@ -219,22 +225,31 @@ public class AttachDetachWindow { assertTrue("window child attach not called", testContent.childAttachCalled); - assertSame("window not attached", win.getApplication(), testApp); - assertSame("window content not attached", testContent.getApplication(), - testApp); - assertSame("window children not attached", - testContent.child.getApplication(), testApp); + assertSame("window not attached", win.getSession(), testApp); + assertSame("window content not attached", testContent.getUI() + .getSession(), testApp); + assertSame("window children not attached", testContent.child.getUI() + .getSession(), testApp); } /** * Asserts that win and its children are not attached. */ private void assertUnattached(TestContainer win) { - assertSame("window not detached", win.getApplication(), null); - assertSame("window content not detached", win.getTestContent() - .getApplication(), null); + assertSame("window not detached", win.getSession(), null); + assertSame("window content not detached", + getVaadinSession(win.getTestContent()), null); assertSame("window children not detached", - win.getTestContent().child.getApplication(), null); + getVaadinSession(win.getTestContent().child), null); + } + + private VaadinSession getVaadinSession(ClientConnector testContainer) { + UI ui = testContainer.getUI(); + if (ui != null) { + return ui.getSession(); + } else { + return null; + } } /** diff --git a/uitest/src/com/vaadin/tests/StressComponentsInTable.java b/uitest/src/com/vaadin/tests/StressComponentsInTable.java index 7c4cca2b0b..fa0b98b1b1 100644 --- a/uitest/src/com/vaadin/tests/StressComponentsInTable.java +++ b/uitest/src/com/vaadin/tests/StressComponentsInTable.java @@ -54,7 +54,7 @@ public class StressComponentsInTable extends CustomComponent { Button b = event.getButton(); System.out.println(b.getCaption() + " click: " + (new Date()).toString()); - System.out.println(b.getApplication()); + System.out.println(b.getUI().getSession()); } })); diff --git a/uitest/src/com/vaadin/tests/TestForUpload.java b/uitest/src/com/vaadin/tests/TestForUpload.java index b0697d337d..7c2359a404 100644 --- a/uitest/src/com/vaadin/tests/TestForUpload.java +++ b/uitest/src/com/vaadin/tests/TestForUpload.java @@ -244,7 +244,7 @@ public class TestForUpload extends CustomComponent implements @Override public void buttonClick(ClickEvent event) { - getApplication().close(); + getSession().close(); } }); main.addComponent(restart); diff --git a/uitest/src/com/vaadin/tests/application/ApplicationCloseTest.java b/uitest/src/com/vaadin/tests/application/ApplicationCloseTest.java index 7250ba3cfb..8cfed569dc 100644 --- a/uitest/src/com/vaadin/tests/application/ApplicationCloseTest.java +++ b/uitest/src/com/vaadin/tests/application/ApplicationCloseTest.java @@ -26,7 +26,7 @@ public class ApplicationCloseTest extends TestBase { @Override public void buttonClick(ClickEvent event) { - event.getButton().getApplication().close(); + event.getButton().getUI().getSession().close(); } }); diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index 92ac336df7..210cb2535e 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -54,7 +54,7 @@ public abstract class AbstractTestUI extends UI { protected abstract Integer getTicketNumber(); protected WebBrowser getBrowser() { - return getApplication().getBrowser(); + return getSession().getBrowser(); } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableFirstRowFlicker.java b/uitest/src/com/vaadin/tests/components/table/TableFirstRowFlicker.java index 30b878b7eb..5d36b8381b 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableFirstRowFlicker.java +++ b/uitest/src/com/vaadin/tests/components/table/TableFirstRowFlicker.java @@ -5,8 +5,8 @@ import com.vaadin.data.Container; import com.vaadin.data.util.IndexedContainer; import com.vaadin.ui.Label; import com.vaadin.ui.ProgressIndicator; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Table; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; public class TableFirstRowFlicker extends LegacyApplication { @@ -43,7 +43,7 @@ public class TableFirstRowFlicker extends LegacyApplication { @Override public void run() { while (t != null) { - synchronized (t.getApplication()) { + synchronized (t.getUI().getSession()) { int firstId = t.getCurrentPageFirstItemIndex(); Object selected = t.getValue(); t.setContainerDataSource(buildContainer()); diff --git a/uitest/src/com/vaadin/tests/components/textfield/SelectionAndCursorPosition.java b/uitest/src/com/vaadin/tests/components/textfield/SelectionAndCursorPosition.java index f6368f0c78..d63d7ddc66 100644 --- a/uitest/src/com/vaadin/tests/components/textfield/SelectionAndCursorPosition.java +++ b/uitest/src/com/vaadin/tests/components/textfield/SelectionAndCursorPosition.java @@ -30,7 +30,8 @@ public class SelectionAndCursorPosition extends TestBase { ml.addListener(new Property.ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { - if (textField.getApplication() == null) { + if (textField.getUI() == null + || textField.getUI().getSession() == null) { replaceComponent(textArea, textField); activeComponent = textField; } else { diff --git a/uitest/src/com/vaadin/tests/layouts/ComplexGLColumnExpansionWithColSpan.java b/uitest/src/com/vaadin/tests/layouts/ComplexGLColumnExpansionWithColSpan.java index f4050ea085..b584cdb5cf 100644 --- a/uitest/src/com/vaadin/tests/layouts/ComplexGLColumnExpansionWithColSpan.java +++ b/uitest/src/com/vaadin/tests/layouts/ComplexGLColumnExpansionWithColSpan.java @@ -73,7 +73,7 @@ public class ComplexGLColumnExpansionWithColSpan extends AbstractTestCase { restart.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { - mainLayout.getUI().getApplication().close(); + mainLayout.getUI().getSession().close(); } }); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryUI.java index 2cbff64117..ff2263e208 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryUI.java @@ -7,7 +7,7 @@ import com.vaadin.ui.TextField; public class CustomConverterFactoryUI extends AbstractTestUI { @Override public void setup(WrappedRequest request) { - getApplication().setConverterFactory(new MyConverterFactory()); + getSession().setConverterFactory(new MyConverterFactory()); TextField tf = new TextField("This is my double field"); tf.setImmediate(true); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java index d78cdd9ad5..632eda2491 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java @@ -20,12 +20,12 @@ public class DynamicImageUI extends AbstractTestUI { @Override public void setup(WrappedRequest request) { // Add the request handler that handles our dynamic image - getApplication().addRequestHandler(new DynamicImageRequestHandler()); + getSession().addRequestHandler(new DynamicImageRequestHandler()); // Create a URL that we can handle in DynamicImageRequestHandler URL imageUrl; try { - imageUrl = new URL(getApplication().getURL(), + imageUrl = new URL(getSession().getURL(), DynamicImageRequestHandler.IMAGE_URL + "?text=Hello!"); } catch (MalformedURLException e) { // This should never happen |