1 4 package com.opensymphony.webwork.portlet.util; 5 6 import javax.portlet.PortletRequest; 7 import javax.portlet.PortletSession; 8 import java.io.NotSerializableException ; 9 import java.io.Serializable ; 10 11 12 16 public class PortletMessaging { 17 18 public static final void publish(PortletRequest request, String messageName, Object message) 19 throws NotSerializableException { 20 String key = messageName; 21 if (message instanceof Serializable ) { 22 request.getPortletSession().setAttribute(key, message, PortletSession.PORTLET_SCOPE); 23 } else { 24 throw new NotSerializableException ("Message not serializable for " + key); 25 } 26 } 27 28 public static final Object consume(PortletRequest request, String messageName) { 29 String key = messageName; 30 Object object = request.getPortletSession().getAttribute(key, PortletSession.PORTLET_SCOPE); 31 request.getPortletSession().removeAttribute(key, PortletSession.PORTLET_SCOPE); 33 return object; 34 } 35 36 public static final Object receive(PortletRequest request, String messageName) { 37 String key = messageName; 38 Object object = request.getPortletSession().getAttribute(key, PortletSession.PORTLET_SCOPE); 39 return object; 40 } 41 42 public static final void cancel(PortletRequest request, String messageName) { 43 String key = messageName; 44 request.getPortletSession().removeAttribute(key, PortletSession.PORTLET_SCOPE); 45 } 46 47 } 48 | Popular Tags |