]> source.dussan.org Git - vaadin-framework.git/commitdiff
Don't require an Application with portlet listeners (#9402)
authorLeif Åstrand <leif@vaadin.com>
Wed, 5 Sep 2012 07:58:12 +0000 (10:58 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 5 Sep 2012 08:39:37 +0000 (11:39 +0300)
server/src/com/vaadin/server/PortletApplicationContext2.java
server/src/com/vaadin/server/VaadinPortlet.java
uitest/src/com/vaadin/tests/integration/JSR286PortletApplication.java

index 63f02ac4ec757cba9a6ee48f602b16fe1ec4e5d9..a7b6d5b40a3ff9ce68fce0feb17a3a3692e52b51 100644 (file)
@@ -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);
         }
     }
 
index 2bec4249ede1e4521318b2d437a618d397c80591..3b8e7cd7ba34ba44b5efe55bce4a23dbc325c974 100644 (file)
@@ -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);
                 }
 
index 2243adf336541ffd50322424b8d9c85e24c33064..50de6b4882dfe25345c94629ac2e864805c3687c 100644 (file)
@@ -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);