001: package org.wings.portlet;
002:
003: import java.util.Iterator;
004: import java.util.Map;
005: import java.util.Set;
006:
007: import javax.swing.event.EventListenerList;
008:
009: import org.apache.commons.logging.Log;
010: import org.apache.commons.logging.LogFactory;
011: import org.wings.SPortletAnchor;
012: import org.wings.session.Session;
013: import org.wings.session.SessionManager;
014:
015: /**
016: *
017: * This class provides the parameters as events from the RenderRequest set by a
018: * {@link SPortletAnchor} and the parameters set in the portlet. The parameters
019: * set in the portlet must be encoded with the {@link PortletParameterCodec}.
020: * The SPortletAnchor encodes the parameters automatically
021: *
022: * @author <a href="mailto:marc.musch@mercatis.com">Marc Musch</a>
023: *
024: */
025: public class PortletParameterProvider {
026:
027: private final transient static Log log = LogFactory
028: .getLog(PortletParameterProvider.class);
029:
030: /**
031: * list for the registered listeners
032: */
033: private EventListenerList listeners = new EventListenerList();
034:
035: private PortletParameterProvider() {
036: }
037:
038: /**
039: * Use this method to get an instance of this class, the constructir is
040: * hidden.
041: *
042: * @return Instance of this class
043: */
044: public static PortletParameterProvider getInstance() {
045:
046: Session session = SessionManager.getSession();
047:
048: PortletParameterProvider ppp = (PortletParameterProvider) session
049: .getProperty(Const.WINGS_SESSION_PROPERTY_PORTLET_PARAMETER_PROVIDER);
050: if (ppp != null) {
051: return ppp;
052: } else {
053: PortletParameterProvider newPpp = new PortletParameterProvider();
054: session
055: .setProperty(
056: Const.WINGS_SESSION_PROPERTY_PORTLET_PARAMETER_PROVIDER,
057: newPpp);
058: return newPpp;
059: }
060: }
061:
062: /**
063: * Adds a new listner for arriving portlet parameters
064: *
065: * @param listener -
066: * the listner for these events
067: */
068: public void addPortletParameterListener(
069: PortletParameterListener listener) {
070: listeners.add(PortletParameterListener.class, listener);
071: }
072:
073: /**
074: * Forces the updating of the portlet parameters
075: */
076: public void updateParameters() {
077: Session session = SessionManager.getSession();
078: Map<String, String[]> portletParameters = (Map<String, String[]>) session
079: .getProperty(Const.WINGS_SESSION_PROPERTY_PORTLET_PARAMETER_MAP);
080: if (log.isDebugEnabled()) {
081: if (portletParameters != null) {
082: Set names = portletParameters.keySet();
083: Iterator iter = names.iterator();
084: log.debug("WingS-Portlet-Bridge: Portlet Parameters "
085: + "stored in Session and deliverd as events: ");
086: while (iter.hasNext()) {
087: String name = (String) iter.next();
088: log.debug(name + ", ");
089: }
090: }
091: }
092: notifyNewPortletParameters(new PortletParameterEvent(this ,
093: portletParameters));
094: }
095:
096: /**
097: * Notifies the listeners
098: *
099: * @param e -
100: * the event to deliver
101: */
102: private synchronized void notifyNewPortletParameters(
103: PortletParameterEvent e) {
104: for (PortletParameterListener l : listeners
105: .getListeners(PortletParameterListener.class))
106: l.newPortletParameters(e);
107: }
108:
109: }
|