Package com.opensymphony.webwork.portlet.util

Source Code of com.opensymphony.webwork.portlet.util.PortletMessaging

package com.opensymphony.webwork.portlet.util;


import java.io.NotSerializableException;
import java.io.Serializable;

import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;


/**
* @author Henry Hu  -- hu_pengfei@yahoo.com.cn
* @since 2005-7-6
*/
public class PortletMessaging
{

    public static final void publish(PortletRequest request, String messageName, Object message)
    throws NotSerializableException
    {
        String key = messageName;
        if (message instanceof Serializable)
        {
            request.getPortletSession().setAttribute(key, message, PortletSession.PORTLET_SCOPE);
        }
        else
        {
            throw new NotSerializableException("Message not serializable for " + key);
        }
    }

    public static final Object consume(PortletRequest request, String messageName)
    {
        String key = messageName;
        Object object = request.getPortletSession().getAttribute(key, PortletSession.PORTLET_SCOPE);
        // consume it
        request.getPortletSession().removeAttribute(key, PortletSession.PORTLET_SCOPE);       
        return object;
    }

    public static final Object receive(PortletRequest request, String messageName)
    {
        String key = messageName;
        Object object = request.getPortletSession().getAttribute(key, PortletSession.PORTLET_SCOPE);
        return object;
    }
   
    public static final void cancel(PortletRequest request, String messageName)
    {
        String key = messageName;
        request.getPortletSession().removeAttribute(key, PortletSession.PORTLET_SCOPE);
    }
   
}
TOP

Related Classes of com.opensymphony.webwork.portlet.util.PortletMessaging

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.