From cc3ddcac953a087b09ae330ff37126dcd5ec727f Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 5 Sep 2012 19:30:41 +0300 Subject: Remove getApplication() and add getSession() (#9402) --- server/src/com/vaadin/ui/AbstractComponent.java | 29 +------------- server/src/com/vaadin/ui/AbstractField.java | 2 +- server/src/com/vaadin/ui/Component.java | 25 +----------- server/src/com/vaadin/ui/ConnectorTracker.java | 2 +- server/src/com/vaadin/ui/Label.java | 2 +- server/src/com/vaadin/ui/LoginForm.java | 6 +-- server/src/com/vaadin/ui/Table.java | 2 +- server/src/com/vaadin/ui/UI.java | 53 +++++++++++++++++-------- 8 files changed, 46 insertions(+), 75 deletions(-) (limited to 'server/src/com/vaadin/ui') 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; @@ -626,31 +626,6 @@ public abstract class AbstractComponent extends AbstractClientConnector } } - /** - * Gets the application object to which the component is attached. - * - *

- * 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. - *

- *

- * This method is not meant to be overridden. Due to CDI requirements we - * cannot declare it as final even though it should be final. - *

- * - * @return the parent application of the component or null. - * @see #attach() - */ - @Override - public VaadinSession getApplication() { - // Just make method inherited from Component interface public - return super.getApplication(); - } - /** * Build CSS compatible string representation of 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 extends AbstractComponent implements */ public void setConverter(Class datamodelType) { Converter c = (Converter) 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; /** @@ -521,35 +520,13 @@ public interface Component extends ClientConnector, Sizeable, Serializable { @Override public UI getUI(); - /** - * Gets the application object to which the component is attached. - * - *

- * The method will return {@code null} if the component is not currently - * attached to an application. - *

- * - *

- * 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. - *

- * - * @return the parent application of the component or null. - * @see #attach() - */ - public VaadinSession getApplication(); - /** * {@inheritDoc} * *

* 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, newDataSource.getType())) { // Try to find a converter Converter 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 (" + * The method will return {@code null} if the component is not currently + * attached to an application. + *

+ * + *

+ * 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. + *

+ * + * @return the parent application of the component or null. + * @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. *

* - * @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); -- cgit v1.2.3