From 98a934554a8a88e0b64e9bc4069ee2af82286efa Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Sun, 9 Sep 2012 21:49:19 +0300 Subject: Allow storing values in VaadinSession (#9514) --- server/src/com/vaadin/server/VaadinSession.java | 109 ++++++++++++++++++++++++ 1 file changed, 109 insertions(+) (limited to 'server') diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index c6b2d91f29..a91c011ddf 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -204,6 +204,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { private transient WrappedSession session; + private final Map attributes = new HashMap(); + /** * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent) */ @@ -1306,4 +1308,111 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { return lock; } + /** + * Stores a value in this vaadin session. This can be used to associate data + * with the current user so that it can be retrieved at a later point from + * some other part of the application. Setting the value to + * null clears the stored value. + * + * @see #getAttribute(String) + * + * @param name + * the name to associate the value with, can not be + * null + * @param value + * the value to associate with the name, or null to + * remove a previous association. + */ + public void setAttribute(String name, Object value) { + if (name == null) { + throw new IllegalArgumentException("name can not be null"); + } + if (value != null) { + attributes.put(name, value); + } else { + attributes.remove(name); + } + } + + /** + * Stores a value in this vaadin session. This can be used to associate data + * with the current user so that it can be retrieved at a later point from + * some other part of the application. Setting the value to + * null clears the stored value. + *

+ * The fully qualified name of the type is used as the name when storing the + * value. The outcome of calling this method is thus the same as if calling
+ *
+ * setAttribute(type.getName(), value); + * + * @see #getAttribute(Class) + * @see #setAttribute(String, Object) + * + * @param type + * the type that the stored value represents, can not be null + * @param value + * the value to associate with the type, or null to + * remove a previous association. + */ + public void setAttribute(Class type, T value) { + if (type == null) { + throw new IllegalArgumentException("type can not be null"); + } + if (value != null && !type.isInstance(value)) { + throw new IllegalArgumentException("value of type " + + type.getName() + " expected but got " + + value.getClass().getName()); + } + setAttribute(type.getName(), value); + } + + /** + * Gets a stored attribute value. If a value has been stored for the + * session, that value is returned. If no value is stored for the name, + * null is returned. + * + * @see #setAttribute(String, Object) + * + * @param name + * the name of the value to get, can not be null. + * @return the value, or null if no value has been stored or if + * it has been set to null. + */ + public Object getAttribute(String name) { + if (name == null) { + throw new IllegalArgumentException("name can not be null"); + } + return attributes.get(name); + } + + /** + * Gets a stored attribute value. If a value has been stored for the + * session, that value is returned. If no value is stored for the name, + * null is returned. + *

+ * The fully qualified name of the type is used as the name when getting the + * value. The outcome of calling this method is thus the same as if calling
+ *
+ * getAttribute(type.getName()); + * + * @see #setAttribute(Class, Object) + * @see #getAttribute(String) + * + * @param type + * the type of the value to get, can not be null. + * @return the value, or null if no value has been stored or if + * it has been set to null. + */ + public T getAttribute(Class type) { + if (type == null) { + throw new IllegalArgumentException("type can not be null"); + } + Object value = getAttribute(type.getName()); + if (value == null) { + return null; + } else { + return type.cast(value); + } + } + } -- cgit v1.2.3 From 998c9c97b4b7d9531028b442df4c38a33b60e5f0 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Sun, 9 Sep 2012 22:16:51 +0300 Subject: Verify that lock is held when accessing state (#9515) --- server/src/com/vaadin/server/AbstractClientConnector.java | 2 ++ server/src/com/vaadin/server/VaadinSession.java | 11 ++++++++--- server/src/com/vaadin/ui/ConnectorTracker.java | 3 +++ .../src/com/vaadin/tests/data/converter/ConverterFactory.java | 2 ++ .../abstractfield/AbstractFieldValueConversions.java | 1 + .../component/abstractfield/RemoveListenersOnDetach.java | 5 +++-- 6 files changed, 19 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 4c22a96782..2fb468bd1c 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -146,6 +146,8 @@ public abstract class AbstractClientConnector implements ClientConnector { } protected SharedState getState() { + assert getSession() == null + || getSession().getLock().isHeldByCurrentThread() : VaadinSession.SESSION_LOCK_MESSAGE; if (null == sharedState) { sharedState = createState(); } diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index a91c011ddf..03e6420008 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -28,7 +28,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; @@ -71,6 +70,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { */ public static final String UI_PARAMETER = "UI"; + public static final String SESSION_LOCK_MESSAGE = "You are accessing UI state without proper synchronization!"; + private static final Method BOOTSTRAP_FRAGMENT_METHOD = ReflectTools .findMethod(BootstrapListener.class, "modifyBootstrapFragment", BootstrapFragmentResponse.class); @@ -78,7 +79,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { .findMethod(BootstrapListener.class, "modifyBootstrapPage", BootstrapPageResponse.class); - private final Lock lock = new ReentrantLock(); + private final ReentrantLock lock = new ReentrantLock(); /** * An event sent to {@link #start(SessionStartEvent)} when a new Application @@ -206,6 +207,10 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { private final Map attributes = new HashMap(); + public VaadinSession() { + // TODO Auto-generated constructor stub + } + /** * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent) */ @@ -1304,7 +1309,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * * @return the lock that should be used for synchronization */ - public Lock getLock() { + public ReentrantLock getLock() { return lock; } diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index d454df98ee..dbada63a47 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -29,6 +29,7 @@ import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.AbstractCommunicationManager; import com.vaadin.server.ClientConnector; import com.vaadin.server.GlobalResourceHandler; +import com.vaadin.server.VaadinSession; /** * A class which takes care of book keeping of {@link ClientConnector}s for a @@ -286,6 +287,8 @@ public class ConnectorTracker implements Serializable { * The connector that should be marked clean. */ public void markDirty(ClientConnector connector) { + assert uI.getSession() == null + || uI.getSession().getLock().isHeldByCurrentThread() : VaadinSession.SESSION_LOCK_MESSAGE; if (isWritingResponse()) { throw new IllegalStateException( "A connector should not be marked as dirty while a response is being written."); 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 b64514ea14..bc5846acf0 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java +++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java @@ -69,6 +69,7 @@ public class ConverterFactory extends TestCase { final VaadinSession appWithCustomIntegerConverter = new VaadinSession(); appWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); + appWithCustomIntegerConverter.getLock().lock(); TextField tf = new TextField("", "123") { @Override @@ -97,6 +98,7 @@ public class ConverterFactory extends TestCase { public void testApplicationConverterFactoryForDifferentThanCurrentApplication() { final VaadinSession fieldAppWithCustomIntegerConverter = new VaadinSession(); + fieldAppWithCustomIntegerConverter.getLock().lock(); fieldAppWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); VaadinSession.setCurrent(new VaadinSession()); 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 b48ad62bcc..031e0c80bd 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 @@ -187,6 +187,7 @@ public class AbstractFieldValueConversions extends TestCase { public void testNumberDoubleConverterChange() { final VaadinSession a = new VaadinSession(); + a.getLock().lock(); VaadinSession.setCurrent(a); TextField tf = new TextField() { @Override 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 c9f579a887..f259e156ff 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 @@ -19,10 +19,11 @@ public class RemoveListenersOnDetach { AbstractField field = new AbstractField() { final private VaadinSession application = new VaadinSession() { - + { + getLock().lock(); + } }; private UI uI = new UI() { - @Override protected void init(WrappedRequest request) { -- cgit v1.2.3 From e7f4e8f3feba0797b16c48299de5f35a347800a2 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Mon, 10 Sep 2012 08:44:39 +0300 Subject: Remove unused exception class reintroduced in a merge. --- .../data/RangeOutOfContainerBoundsException.java | 169 --------------------- 1 file changed, 169 deletions(-) delete mode 100644 server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java (limited to 'server') diff --git a/server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java b/server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java deleted file mode 100644 index 43058e45d8..0000000000 --- a/server/src/com/vaadin/data/RangeOutOfContainerBoundsException.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.vaadin.data; - -/** - * A exception that indicates that the container is unable to return all of the - * consecutive item ids requested by the caller. This can happen if the - * container size has changed since the input parameters for - * {@link Container.Indexed#getItemIds(int, int)} were computed or if the - * requested range exceeds the containers size due to some other factor.
- *
- * - * The exception can contain additional parameters for easier debugging. The - * additional parameters are the startIndex and - * numberOfIds which were given to - * {@link Container.Indexed#getItemIds(int, int)} as well as the size of the - * container when the fetch was executed. The container size can be retrieved - * with {@link #getContainerCurrentSize()}.
- *
- * - * The additional parameters are optional but the party that received the - * exception can check whether or not these were set by calling - * {@link #isAdditionalParametersSet()}. - * - * @since 7.0 - */ -public class RangeOutOfContainerBoundsException extends RuntimeException { - - private final int startIndex; - private final int numberOfIds; - private final int containerCurrentSize; - private final boolean additionalParametersSet; - - // Discourage users to create exceptions without at least some kind of - // message... - private RangeOutOfContainerBoundsException() { - super(); - startIndex = -1; - numberOfIds = -1; - containerCurrentSize = -1; - additionalParametersSet = false; - } - - public RangeOutOfContainerBoundsException(String message) { - super(message); - startIndex = -1; - numberOfIds = -1; - containerCurrentSize = -1; - additionalParametersSet = false; - } - - public RangeOutOfContainerBoundsException(String message, - Throwable throwable) { - super(message, throwable); - startIndex = -1; - numberOfIds = -1; - containerCurrentSize = -1; - additionalParametersSet = false; - } - - public RangeOutOfContainerBoundsException(Throwable throwable) { - super(throwable); - startIndex = -1; - numberOfIds = -1; - containerCurrentSize = -1; - additionalParametersSet = false; - } - - /** - * Create a new {@link RangeOutOfContainerBoundsException} with the - * additional parameters: - *

    - *
  • startIndex - start index for the query
  • - *
  • numberOfIds - the number of consecutive item ids to get
  • - *
  • containerCurrentSize - the size of the container during the execution - * of the query
  • - *
- * given. - * - * @param message - * @param startIndex - * the given startIndex for the query - * @param numberOfIds - * the number of item ids requested - * @param containerCurrentSize - * the current size of the container - */ - public RangeOutOfContainerBoundsException(String message, int startIndex, - int numberOfIds, int containerCurrentSize) { - super(message); - - this.startIndex = startIndex; - this.numberOfIds = numberOfIds; - this.containerCurrentSize = containerCurrentSize; - additionalParametersSet = true; - } - - /** - * Create a new {@link RangeOutOfContainerBoundsException} with the given - * query parameters set in the exception along with the containers current - * size and a @link {@link Throwable}. - * - * @param message - * @param startIndex - * the given startIndex for the query - * @param numberOfIds - * the number of item ids queried for - * @param containerCurrentSize - * the current size of the container - * @param throwable - */ - public RangeOutOfContainerBoundsException(String message, int startIndex, - int numberOfIds, int containerCurrentSize, Throwable throwable) { - super(message, throwable); - - this.startIndex = startIndex; - this.numberOfIds = numberOfIds; - this.containerCurrentSize = containerCurrentSize; - additionalParametersSet = true; - } - - /** - * Get the given startIndex for the query. Remember to check if this - * parameter is set by calling {@link #isAdditionalParametersSet()} - * - * @return the startIndex given to the container - */ - public int getStartIndex() { - return startIndex; - } - - /** - * Get the number of item ids requested. Remember to check if this parameter - * is set with {@link #isAdditionalParametersSet()} - * - * @return the number of item ids the container was ordered to fetch - */ - public int getNumberOfIds() { - return numberOfIds; - } - - /** - * Get the container size when the query was actually executed. Remember to - * check if this parameter is set with {@link #isAdditionalParametersSet()} - */ - public int getContainerCurrentSize() { - return containerCurrentSize; - } - - /** - * Check whether or not the additional parameters for the exception were set - * during creation or not. - * - * The additional parameters can be retrieved with:
- *
    - *
  • {@link #getStartIndex()}
  • - *
  • {@link #getNumberOfIds()}
  • - *
  • {@link #getContainerCurrentSize()}
  • - *
- * - * @return true if parameters are set, false otherwise. - * - * @see #RangeOutOfContainerBoundsException(String, int, int, int) - * RangeOutOfContainerBoundsException(String, int, int, int) for more - * details on the additional parameters - */ - public boolean isAdditionalParametersSet() { - return additionalParametersSet; - } - -} -- cgit v1.2.3 From 88f77a4e7c1b6e0a92a58c9d9bd175120684ef2f Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Sep 2012 12:00:33 +0300 Subject: Added info that debugger might cause log messages (#9481) --- server/src/com/vaadin/ui/AbstractField.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index f673babc26..13772b68b5 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -417,7 +417,8 @@ public abstract class AbstractField extends AbstractComponent implements public String toString() { logger.warning("You are using AbstractField.toString() to get the value for a " + getClass().getSimpleName() - + ". This is not recommended and will not be supported in future versions."); + + ". This will not be supported starting from Vaadin 7.1 " + + "(your debugger might call toString() and cause this message to appear)."); final Object value = getFieldValue(); if (value == null) { return null; -- cgit v1.2.3 From def6b2fee7f8922e73858b15c956c11276adf176 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 10 Sep 2012 12:02:14 +0300 Subject: Revert "Verify that lock is held when accessing state (#9515)" This reverts commit 998c9c97b4b7d9531028b442df4c38a33b60e5f0. --- server/src/com/vaadin/server/AbstractClientConnector.java | 2 -- server/src/com/vaadin/server/VaadinSession.java | 11 +++-------- server/src/com/vaadin/ui/ConnectorTracker.java | 3 --- .../src/com/vaadin/tests/data/converter/ConverterFactory.java | 2 -- .../abstractfield/AbstractFieldValueConversions.java | 1 - .../component/abstractfield/RemoveListenersOnDetach.java | 5 ++--- 6 files changed, 5 insertions(+), 19 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 2fb468bd1c..4c22a96782 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -146,8 +146,6 @@ public abstract class AbstractClientConnector implements ClientConnector { } protected SharedState getState() { - assert getSession() == null - || getSession().getLock().isHeldByCurrentThread() : VaadinSession.SESSION_LOCK_MESSAGE; if (null == sharedState) { sharedState = createState(); } diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index 03e6420008..a91c011ddf 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -28,6 +28,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; @@ -70,8 +71,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { */ public static final String UI_PARAMETER = "UI"; - public static final String SESSION_LOCK_MESSAGE = "You are accessing UI state without proper synchronization!"; - private static final Method BOOTSTRAP_FRAGMENT_METHOD = ReflectTools .findMethod(BootstrapListener.class, "modifyBootstrapFragment", BootstrapFragmentResponse.class); @@ -79,7 +78,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { .findMethod(BootstrapListener.class, "modifyBootstrapPage", BootstrapPageResponse.class); - private final ReentrantLock lock = new ReentrantLock(); + private final Lock lock = new ReentrantLock(); /** * An event sent to {@link #start(SessionStartEvent)} when a new Application @@ -207,10 +206,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { private final Map attributes = new HashMap(); - public VaadinSession() { - // TODO Auto-generated constructor stub - } - /** * @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent) */ @@ -1309,7 +1304,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * * @return the lock that should be used for synchronization */ - public ReentrantLock getLock() { + public Lock getLock() { return lock; } diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index dbada63a47..d454df98ee 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -29,7 +29,6 @@ import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.AbstractCommunicationManager; import com.vaadin.server.ClientConnector; import com.vaadin.server.GlobalResourceHandler; -import com.vaadin.server.VaadinSession; /** * A class which takes care of book keeping of {@link ClientConnector}s for a @@ -287,8 +286,6 @@ public class ConnectorTracker implements Serializable { * The connector that should be marked clean. */ public void markDirty(ClientConnector connector) { - assert uI.getSession() == null - || uI.getSession().getLock().isHeldByCurrentThread() : VaadinSession.SESSION_LOCK_MESSAGE; if (isWritingResponse()) { throw new IllegalStateException( "A connector should not be marked as dirty while a response is being written."); 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 bc5846acf0..b64514ea14 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java +++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java @@ -69,7 +69,6 @@ public class ConverterFactory extends TestCase { final VaadinSession appWithCustomIntegerConverter = new VaadinSession(); appWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); - appWithCustomIntegerConverter.getLock().lock(); TextField tf = new TextField("", "123") { @Override @@ -98,7 +97,6 @@ public class ConverterFactory extends TestCase { public void testApplicationConverterFactoryForDifferentThanCurrentApplication() { final VaadinSession fieldAppWithCustomIntegerConverter = new VaadinSession(); - fieldAppWithCustomIntegerConverter.getLock().lock(); fieldAppWithCustomIntegerConverter .setConverterFactory(new ConverterFactory42()); VaadinSession.setCurrent(new VaadinSession()); 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 031e0c80bd..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 @@ -187,7 +187,6 @@ public class AbstractFieldValueConversions extends TestCase { public void testNumberDoubleConverterChange() { final VaadinSession a = new VaadinSession(); - a.getLock().lock(); VaadinSession.setCurrent(a); TextField tf = new TextField() { @Override 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 f259e156ff..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 @@ -19,11 +19,10 @@ public class RemoveListenersOnDetach { AbstractField field = new AbstractField() { final private VaadinSession application = new VaadinSession() { - { - getLock().lock(); - } + }; private UI uI = new UI() { + @Override protected void init(WrappedRequest request) { -- cgit v1.2.3 From bd0e2ecb01ce4ba873c7bf5f31c1ef583c85bd30 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 10 Sep 2012 13:47:08 +0300 Subject: Don't use Resource with the Page.open API (#9522) --- server/src/com/vaadin/server/Page.java | 97 ++++++++++++++++------ .../com/vaadin/server/VaadinPortletSession.java | 4 +- server/src/com/vaadin/ui/UI.java | 20 ++++- uitest/src/com/vaadin/tests/TestForWindowOpen.java | 16 ++-- 4 files changed, 97 insertions(+), 40 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 9a0948edc8..1b22c93d78 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -29,6 +29,7 @@ import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.ui.PageClientRpc; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.ui.JavaScript; +import com.vaadin.ui.Link; import com.vaadin.ui.Notification; import com.vaadin.ui.UI; import com.vaadin.util.ReflectTools; @@ -129,6 +130,25 @@ public class Page implements Serializable { */ private final BorderStyle border; + /** + * Creates a new open resource. + * + * @param url + * The URL to open + * @param name + * The name of the target window + * @param width + * The width of the target window + * @param height + * The height of the target window + * @param border + * The border style of the target window + */ + private OpenResource(String url, String name, int width, int height, + BorderStyle border) { + this(new ExternalResource(url), name, width, height, border); + } + /** * Creates a new open resource. * @@ -550,19 +570,19 @@ public class Page implements Serializable { } /** - * Opens the given resource in this uI. The contents of this UI is replaced - * by the {@code Resource}. + * Navigates this page to the given URL. The contents of this page in the + * browser is replaced with whatever is returned for the given URL. * - * @param resource - * the resource to show in this uI + * @param url + * the URL to show */ - public void open(Resource resource) { - openList.add(new OpenResource(resource, null, -1, -1, BORDER_DEFAULT)); + public void setLocation(String url) { + openList.add(new OpenResource(url, null, -1, -1, BORDER_DEFAULT)); uI.markAsDirty(); } /** - * Opens the given resource in a window with the given name. + * Opens the given URL in a window with the given name. *

* The supplied {@code windowName} is used as the target name in a * window.open call in the client. This means that special values such as @@ -570,47 +590,63 @@ public class Page implements Serializable { * null window name is also a special case. *

*

- * "", null and "_self" as {@code windowName} all causes the resource to be + * "", null and "_self" as {@code windowName} all causes the URL to be * opened in the current window, replacing any old contents. For * downloadable content you should avoid "_self" as "_self" causes the * client to skip rendering of any other changes as it considers them - * irrelevant (the page will be replaced by the resource). This can speed up - * the opening of a resource, but it might also put the client side into an - * inconsistent state if the window content is not completely replaced e.g., - * if the resource is downloaded instead of displayed in the browser. + * irrelevant (the page will be replaced by the response from the URL). This + * can speed up the opening of a URL, but it might also put the client side + * into an inconsistent state if the window content is not completely + * replaced e.g., if the URL is downloaded instead of displayed in the + * browser. *

*

- * "_blank" as {@code windowName} causes the resource to always be opened in - * a new window or tab (depends on the browser and browser settings). + * "_blank" as {@code windowName} causes the URL to always be opened in a + * new window or tab (depends on the browser and browser settings). *

*

* "_top" and "_parent" as {@code windowName} works as specified by the HTML * standard. *

*

- * Any other {@code windowName} will open the resource in a window with that + * Any other {@code windowName} will open the URL in a window with that * name, either by opening a new window/tab in the browser or by replacing * the contents of an existing window with that name. *

+ *

+ * Please note that opening a popup window in this way may be blocked by the + * browser's popup-blocker because the new browser window is opened when + * processing a response from the server. To avoid this, you should instead + * use {@link Link} for opening the window because browsers are more + * forgiving then the window is opened directly from a client-side click + * event. + *

* - * @param resource - * the resource. + * @param url + * the URL to open. * @param windowName * the name of the window. */ - public void open(Resource resource, String windowName) { - openList.add(new OpenResource(resource, windowName, -1, -1, - BORDER_DEFAULT)); + public void open(String url, String windowName) { + openList.add(new OpenResource(url, windowName, -1, -1, BORDER_DEFAULT)); uI.markAsDirty(); } /** - * Opens the given resource in a window with the given size, border and - * name. For more information on the meaning of {@code windowName}, see - * {@link #open(Resource, String)}. + * Opens the given URL in a window with the given size, border and name. For + * more information on the meaning of {@code windowName}, see + * {@link #open(String, String)}. + *

+ * Please note that opening a popup window in this way may be blocked by the + * browser's popup-blocker because the new browser window is opened when + * processing a response from the server. To avoid this, you should instead + * use {@link Link} for opening the window because browsers are more + * forgiving then the window is opened directly from a client-side click + * event. + *

* - * @param resource - * the resource. + * @param url + * the URL to open. * @param windowName * the name of the window. * @param width @@ -620,6 +656,17 @@ public class Page implements Serializable { * @param border * the border style of the window. */ + public void open(String url, String windowName, int width, int height, + BorderStyle border) { + openList.add(new OpenResource(url, windowName, width, height, border)); + uI.markAsDirty(); + } + + /** + * @deprecated only retained to maintain compatibility with + * LegacyWindow.open methods + */ + @Deprecated public void open(Resource resource, String windowName, int width, int height, BorderStyle border) { openList.add(new OpenResource(resource, windowName, width, height, diff --git a/server/src/com/vaadin/server/VaadinPortletSession.java b/server/src/com/vaadin/server/VaadinPortletSession.java index 5bd94c623d..bb37bbbcf3 100644 --- a/server/src/com/vaadin/server/VaadinPortletSession.java +++ b/server/src/com/vaadin/server/VaadinPortletSession.java @@ -216,7 +216,7 @@ public class VaadinPortletSession extends VaadinSession { if (actionUrl != null) { eventActionDestinationMap.put(actionKey, name); eventActionValueMap.put(actionKey, value); - uI.getPage().open(new ExternalResource(actionUrl.toString())); + uI.getPage().setLocation(actionUrl.toString()); } else { // this should never happen as we already know the response is a // MimeResponse @@ -263,7 +263,7 @@ public class VaadinPortletSession extends VaadinSession { if (actionUrl != null) { sharedParameterActionNameMap.put(actionKey, name); sharedParameterActionValueMap.put(actionKey, value); - uI.getPage().open(new ExternalResource(actionUrl.toString())); + uI.getPage().setLocation(actionUrl.toString()); } else { // this should never happen as we already know the response is a // MimeResponse diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index ef77142312..adb2a63c2e 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -222,11 +222,11 @@ public abstract class UI extends AbstractComponentContainer implements * @param resource * the resource to show in this UI * - * @deprecated As of 7.0, use getPage().open instead + * @deprecated As of 7.0, use getPage().setLocation instead */ @Deprecated public void open(Resource resource) { - getPage().open(resource); + open(resource, null); } /* ********************************************************************* */ @@ -264,6 +264,13 @@ public abstract class UI extends AbstractComponentContainer implements * that name, either by opening a new window/tab in the browser or by * replacing the contents of an existing window with that name. *

+ *

+ * As of Vaadin 7.0.0, the functionality for opening a Resource in a + * Page has been replaced with similar methods based on a String URL. + * This is because the usage of Resource is problematic with memory + * management and with security features in some browsers. Is is + * recommended to instead use {@link Link} for starting downloads. + *

* * @param resource * the resource. @@ -273,13 +280,20 @@ public abstract class UI extends AbstractComponentContainer implements */ @Deprecated public void open(Resource resource, String windowName) { - getPage().open(resource, windowName); + open(resource, windowName, -1, -1, Page.BORDER_DEFAULT); } /** * Opens the given resource in a window with the given size, border and * name. For more information on the meaning of {@code windowName}, see * {@link #open(Resource, String)}. + *

+ * As of Vaadin 7.0.0, the functionality for opening a Resource in a + * Page has been replaced with similar methods based on a String URL. + * This is because the usage of Resource is problematic with memory + * management and with security features in some browsers. Is is + * recommended to instead use {@link Link} for starting downloads. + *

* * @param resource * the resource. diff --git a/uitest/src/com/vaadin/tests/TestForWindowOpen.java b/uitest/src/com/vaadin/tests/TestForWindowOpen.java index 253fd3aeea..c3827e47ee 100644 --- a/uitest/src/com/vaadin/tests/TestForWindowOpen.java +++ b/uitest/src/com/vaadin/tests/TestForWindowOpen.java @@ -16,7 +16,6 @@ package com.vaadin.tests; -import com.vaadin.server.ExternalResource; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.CustomComponent; @@ -35,9 +34,8 @@ public class TestForWindowOpen extends CustomComponent { @Override public void buttonClick(ClickEvent event) { - final ExternalResource r = new ExternalResource( - "http://www.google.com"); - UI.getCurrent().getPage().open(r); + UI.getCurrent().getPage() + .setLocation("http://www.google.com"); } @@ -48,9 +46,8 @@ public class TestForWindowOpen extends CustomComponent { @Override public void buttonClick(ClickEvent event) { - final ExternalResource r = new ExternalResource( - "http://www.google.com"); - UI.getCurrent().getPage().open(r, "mytarget"); + UI.getCurrent().getPage() + .open("http://www.google.com", "mytarget"); } @@ -61,9 +58,8 @@ public class TestForWindowOpen extends CustomComponent { @Override public void buttonClick(ClickEvent event) { - final ExternalResource r = new ExternalResource( - "http://www.google.com"); - UI.getCurrent().getPage().open(r, "secondtarget"); + UI.getCurrent().getPage() + .open("http://www.google.com", "secondtarget"); } -- cgit v1.2.3 From 38bcbdfa5c44564bed22cfac4ae17be4943bc6a1 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 10 Sep 2012 13:50:22 +0300 Subject: Make AddonContext serializable (#9273) --- server/src/com/vaadin/server/AddonContext.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/AddonContext.java b/server/src/com/vaadin/server/AddonContext.java index 606d3c3568..ddb8394468 100644 --- a/server/src/com/vaadin/server/AddonContext.java +++ b/server/src/com/vaadin/server/AddonContext.java @@ -16,6 +16,7 @@ package com.vaadin.server; +import java.io.Serializable; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; @@ -41,7 +42,7 @@ import com.vaadin.util.ReflectTools; * @author Vaadin Ltd * @since 7.0.0 */ -public class AddonContext { +public class AddonContext implements Serializable { private static final Method APPLICATION_STARTED_METHOD = ReflectTools .findMethod(ApplicationStartedListener.class, "applicationStarted", ApplicationStartedEvent.class); -- cgit v1.2.3 From 2be77292ab17ba09ccb1dd6aec79b290905d9d1f Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 10 Sep 2012 13:58:30 +0300 Subject: Add rudimentary javadocs (#9402) --- .../src/com/vaadin/DefaultDeploymentConfiguration.java | 17 +++++++++++++++++ server/src/com/vaadin/server/AbstractVaadinService.java | 13 +++++++++++++ 2 files changed, 30 insertions(+) (limited to 'server') diff --git a/server/src/com/vaadin/DefaultDeploymentConfiguration.java b/server/src/com/vaadin/DefaultDeploymentConfiguration.java index 6159137cc3..fed558c5b5 100644 --- a/server/src/com/vaadin/DefaultDeploymentConfiguration.java +++ b/server/src/com/vaadin/DefaultDeploymentConfiguration.java @@ -22,6 +22,13 @@ import java.util.logging.Logger; import com.vaadin.server.Constants; import com.vaadin.server.DeploymentConfiguration; +/** + * The default implementation of {@link DeploymentConfiguration} based on a base + * class for resolving system properties and a set of init parameters. + * + * @author Vaadin Ltd + * @since 7.0.0 + */ public class DefaultDeploymentConfiguration implements DeploymentConfiguration { private final Properties initParameters; private boolean productionMode; @@ -31,6 +38,16 @@ public class DefaultDeploymentConfiguration implements DeploymentConfiguration { private boolean idleRootCleanupEnabled; private final Class systemPropertyBaseClass; + /** + * Create a new deployment configuration instance. + * + * @param systemPropertyBaseClass + * the class that should be used as a basis when reading system + * properties + * @param initParameters + * the init parameters that should make up the foundation for + * this configuration + */ public DefaultDeploymentConfiguration(Class systemPropertyBaseClass, Properties initParameters) { this.initParameters = initParameters; diff --git a/server/src/com/vaadin/server/AbstractVaadinService.java b/server/src/com/vaadin/server/AbstractVaadinService.java index 6e14c1984b..7150fdf0da 100644 --- a/server/src/com/vaadin/server/AbstractVaadinService.java +++ b/server/src/com/vaadin/server/AbstractVaadinService.java @@ -20,11 +20,24 @@ import java.lang.reflect.Constructor; import java.util.Iterator; import java.util.ServiceLoader; +/** + * Abstract implementation of VaadinService that takes care of those parts that + * are common to both servlets and portlets. + * + * @author Vaadin Ltd + * @since 7.0.0 + */ public abstract class AbstractVaadinService implements VaadinService { private AddonContext addonContext; private final DeploymentConfiguration deploymentConfiguration; + /** + * Creates a new vaadin service based on a deployment configuration + * + * @param deploymentConfiguration + * the deployment configuration for the service + */ public AbstractVaadinService(DeploymentConfiguration deploymentConfiguration) { this.deploymentConfiguration = deploymentConfiguration; } -- cgit v1.2.3 From e80f96db8fd08e718818c36a010f2d59667154fe Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 10 Sep 2012 16:31:01 +0300 Subject: Make WebBrowser serializable again (#8027) --- server/src/com/vaadin/server/WebBrowser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/WebBrowser.java b/server/src/com/vaadin/server/WebBrowser.java index 9e29e957d9..6a377a3de9 100644 --- a/server/src/com/vaadin/server/WebBrowser.java +++ b/server/src/com/vaadin/server/WebBrowser.java @@ -16,6 +16,7 @@ package com.vaadin.server; +import java.io.Serializable; import java.util.Date; import java.util.Locale; import java.util.TimeZone; @@ -29,7 +30,7 @@ import com.vaadin.shared.VBrowserDetails; * * @author Vaadin Ltd. */ -public class WebBrowser { +public class WebBrowser implements Serializable { private int screenHeight = 0; private int screenWidth = 0; -- cgit v1.2.3 From 7d591785b167c3f8a82b8af15491b494a0c7433f Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 10 Sep 2012 16:32:11 +0300 Subject: Improved deprecation message based on review (#9522) --- server/src/com/vaadin/server/Page.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 1b22c93d78..ccc400341e 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -32,6 +32,7 @@ import com.vaadin.ui.JavaScript; import com.vaadin.ui.Link; import com.vaadin.ui.Notification; import com.vaadin.ui.UI; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.util.ReflectTools; public class Page implements Serializable { @@ -664,7 +665,9 @@ public class Page implements Serializable { /** * @deprecated only retained to maintain compatibility with - * LegacyWindow.open methods + * LegacyWindow.open methods. See documentation for + * {@link LegacyWindow#open(Resource, String, int, int, BorderStyle)} + * for discussion about replacing API. */ @Deprecated public void open(Resource resource, String windowName, int width, -- cgit v1.2.3