diff options
3 files changed, 35 insertions, 53 deletions
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<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>(); + private final Set<PortletListener> portletListeners = new LinkedHashSet<PortletListener>(); private final Map<String, QName> eventActionDestinationMap = new HashMap<String, QName>(); private final Map<String, Serializable> eventActionValueMap = new HashMap<String, Serializable>(); @@ -108,35 +108,25 @@ public class PortletApplicationContext2 extends ApplicationContext { .getPortletConfig(); } - public void addPortletListener(Application app, PortletListener listener) { - Set<PortletListener> l = portletListeners.get(app); - if (l == null) { - l = new LinkedHashSet<PortletListener>(); - portletListeners.put(app, l); - } - l.add(listener); + public void addPortletListener(PortletListener listener) { + portletListeners.add(listener); } - public void removePortletListener(Application app, PortletListener listener) { - Set<PortletListener> 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<PortletListener> 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<PortletListener>( + 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<PortletListener> listeners = portletListeners.get(app); - if (listeners != null) { - for (PortletListener l : listeners) { - l.handleActionRequest(request, response, uI); - } + for (PortletListener l : new ArrayList<PortletListener>( + portletListeners)) { + l.handleActionRequest(request, response, uI); } } } - public void firePortletEventRequest(Application app, UI uI, - EventRequest request, EventResponse response) { - Set<PortletListener> 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<PortletListener>( + portletListeners)) { + l.handleEventRequest(request, response, uI); } } - public void firePortletResourceRequest(Application app, UI uI, - ResourceRequest request, ResourceResponse response) { - Set<PortletListener> 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<PortletListener>( + 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); |