From: Leif Åstrand Date: Wed, 5 Sep 2012 07:58:12 +0000 (+0300) Subject: Don't require an Application with portlet listeners (#9402) X-Git-Tag: 7.0.0.beta1~184^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c8ba35652ebdea8c659b5fc2485690cc637da96a;p=vaadin-framework.git Don't require an Application with portlet listeners (#9402) --- diff --git a/server/src/com/vaadin/server/PortletApplicationContext2.java b/server/src/com/vaadin/server/PortletApplicationContext2.java index 63f02ac4ec..a7b6d5b40a 100644 --- a/server/src/com/vaadin/server/PortletApplicationContext2.java +++ b/server/src/com/vaadin/server/PortletApplicationContext2.java @@ -16,6 +16,7 @@ package com.vaadin.server; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -40,7 +41,6 @@ import javax.portlet.StateAwareResponse; import javax.servlet.http.HttpSessionBindingListener; import javax.xml.namespace.QName; -import com.vaadin.Application; import com.vaadin.ui.UI; import com.vaadin.util.CurrentInstance; @@ -55,7 +55,7 @@ import com.vaadin.util.CurrentInstance; @SuppressWarnings("serial") public class PortletApplicationContext2 extends ApplicationContext { - protected Map> portletListeners = new HashMap>(); + private final Set portletListeners = new LinkedHashSet(); private final Map eventActionDestinationMap = new HashMap(); private final Map eventActionValueMap = new HashMap(); @@ -108,35 +108,25 @@ public class PortletApplicationContext2 extends ApplicationContext { .getPortletConfig(); } - public void addPortletListener(Application app, PortletListener listener) { - Set l = portletListeners.get(app); - if (l == null) { - l = new LinkedHashSet(); - portletListeners.put(app, l); - } - l.add(listener); + public void addPortletListener(PortletListener listener) { + portletListeners.add(listener); } - public void removePortletListener(Application app, PortletListener listener) { - Set l = portletListeners.get(app); - if (l != null) { - l.remove(listener); - } + public void removePortletListener(PortletListener listener) { + portletListeners.remove(listener); } - public void firePortletRenderRequest(Application app, UI uI, - RenderRequest request, RenderResponse response) { - Set listeners = portletListeners.get(app); - if (listeners != null) { - for (PortletListener l : listeners) { - l.handleRenderRequest(request, new RestrictedRenderResponse( - response), uI); - } + public void firePortletRenderRequest(UI uI, RenderRequest request, + RenderResponse response) { + for (PortletListener l : new ArrayList( + portletListeners)) { + l.handleRenderRequest(request, new RestrictedRenderResponse( + response), uI); } } - public void firePortletActionRequest(Application app, UI uI, - ActionRequest request, ActionResponse response) { + public void firePortletActionRequest(UI uI, ActionRequest request, + ActionResponse response) { String key = request.getParameter(ActionRequest.ACTION_NAME); if (eventActionDestinationMap.containsKey(key)) { // this action request is only to send queued portlet events @@ -154,32 +144,26 @@ public class PortletApplicationContext2 extends ApplicationContext { sharedParameterActionValueMap.remove(key); } else { // normal action request, notify listeners - Set listeners = portletListeners.get(app); - if (listeners != null) { - for (PortletListener l : listeners) { - l.handleActionRequest(request, response, uI); - } + for (PortletListener l : new ArrayList( + portletListeners)) { + l.handleActionRequest(request, response, uI); } } } - public void firePortletEventRequest(Application app, UI uI, - EventRequest request, EventResponse response) { - Set listeners = portletListeners.get(app); - if (listeners != null) { - for (PortletListener l : listeners) { - l.handleEventRequest(request, response, uI); - } + public void firePortletEventRequest(UI uI, EventRequest request, + EventResponse response) { + for (PortletListener l : new ArrayList( + portletListeners)) { + l.handleEventRequest(request, response, uI); } } - public void firePortletResourceRequest(Application app, UI uI, - ResourceRequest request, ResourceResponse response) { - Set listeners = portletListeners.get(app); - if (listeners != null) { - for (PortletListener l : listeners) { - l.handleResourceRequest(request, response, uI); - } + public void firePortletResourceRequest(UI uI, ResourceRequest request, + ResourceResponse response) { + for (PortletListener l : new ArrayList( + portletListeners)) { + l.handleResourceRequest(request, response, uI); } } diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 2bec4249ed..3b8e7cd7ba 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -544,19 +544,17 @@ public class VaadinPortlet extends GenericPortlet implements Constants { // TODO Should this happen before or after the transaction // starts? if (request instanceof RenderRequest) { - applicationContext.firePortletRenderRequest(application, - uI, (RenderRequest) request, - (RenderResponse) response); + applicationContext.firePortletRenderRequest(uI, + (RenderRequest) request, (RenderResponse) response); } else if (request instanceof ActionRequest) { - applicationContext.firePortletActionRequest(application, - uI, (ActionRequest) request, - (ActionResponse) response); + applicationContext.firePortletActionRequest(uI, + (ActionRequest) request, (ActionResponse) response); } else if (request instanceof EventRequest) { - applicationContext.firePortletEventRequest(application, uI, + applicationContext.firePortletEventRequest(uI, (EventRequest) request, (EventResponse) response); } else if (request instanceof ResourceRequest) { - applicationContext.firePortletResourceRequest(application, - uI, (ResourceRequest) request, + applicationContext.firePortletResourceRequest(uI, + (ResourceRequest) request, (ResourceResponse) response); } diff --git a/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java b/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java index 2243adf336..50de6b4882 100644 --- a/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java +++ b/uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java @@ -89,7 +89,7 @@ public class JSR286PortletApplication extends Application.LegacyApplication { if (getContext() instanceof PortletApplicationContext2) { PortletApplicationContext2 ctx = (PortletApplicationContext2) getContext(); - ctx.addPortletListener(this, new DemoPortletListener()); + ctx.addPortletListener(new DemoPortletListener()); } else { getMainWindow().showNotification("Not inited via Portal!", Notification.TYPE_ERROR_MESSAGE);