001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels;
007:
008: import java.util.Collections;
009: import java.util.HashMap;
010: import java.util.Map;
011:
012: import org.apache.commons.logging.Log;
013: import org.apache.commons.logging.LogFactory;
014: import org.jasig.portal.ChannelRuntimeData;
015: import org.jasig.portal.ChannelRuntimeProperties;
016: import org.jasig.portal.ChannelStaticData;
017: import org.jasig.portal.IMultithreadedChannel;
018: import org.jasig.portal.PortalEvent;
019: import org.jasig.portal.PortalException;
020: import org.xml.sax.ContentHandler;
021:
022: /**
023: * A base class from which channels implementing IMultithreadedChannel interface can be derived.
024: * Use this only if you are familiar with the IMultithreadedChannel interface.
025: * Channels that extend BaseMultithreadedChannel typically only need to override the renderXML method
026: * and should not contain any non-static member variables.
027: * @author Ken Weiner, kweiner@unicon.net
028: * @version $Revision: 35614 $
029: */
030: public abstract class BaseMultithreadedChannel implements
031: IMultithreadedChannel {
032: protected static Map channelStateMap;
033:
034: /**
035: * A Commons Logging log instance which will log as the runtime class extending
036: * this BaseChannel. Channels extending BaseChannel can use this Log instance
037: * rather than instantiating their own.
038: */
039: protected Log log = LogFactory.getLog(getClass());
040:
041: /**
042: * The channel's state including the static data, runtime data,
043: * portal event, and a channelData map which is analagous to the
044: * session for a servlet - the channel can stash objects in it.
045: */
046: protected class ChannelState {
047: private ChannelStaticData staticData = null;
048: private ChannelRuntimeData runtimeData = null;
049: private PortalEvent portalEvent = null;
050: private Map channelData = new HashMap();
051:
052: public ChannelStaticData getStaticData() {
053: return this .staticData;
054: }
055:
056: public ChannelRuntimeData getRuntimeData() {
057: return this .runtimeData;
058: }
059:
060: public PortalEvent getPortalEvent() {
061: return this .portalEvent;
062: }
063:
064: public Map getChannelData() {
065: return this .channelData;
066: }
067:
068: public void setStaticData(ChannelStaticData sd) {
069: this .staticData = sd;
070: }
071:
072: public void setRuntimeData(ChannelRuntimeData rd) {
073: this .runtimeData = rd;
074: }
075:
076: public void setPortalEvent(PortalEvent ev) {
077: this .portalEvent = ev;
078: }
079:
080: public void setChannelData(Map cd) {
081: this .channelData = cd;
082: }
083: }
084:
085: static {
086: channelStateMap = Collections.synchronizedMap(new HashMap());
087: }
088:
089: /**
090: * Sets channel runtime properties.
091: * @param uid a unique ID used to identify the state of the channel
092: * @return channel runtime properties
093: */
094: public ChannelRuntimeProperties getRuntimeProperties(String uid) {
095: return new ChannelRuntimeProperties();
096: }
097:
098: /**
099: * React to portal events.
100: * Removes channel state from the channel state map when the session expires.
101: * @param ev a portal event
102: * @param uid a unique ID used to identify the state of the channel
103: */
104: public void receiveEvent(PortalEvent ev, String uid) {
105: ChannelState channelState = (ChannelState) channelStateMap
106: .get(uid);
107: if (channelState != null) {
108: channelState.setPortalEvent(ev);
109: if (ev.getEventNumber() == PortalEvent.SESSION_DONE) {
110: channelStateMap.remove(uid); // Clean up
111: }
112: }
113: }
114:
115: /**
116: * Sets the channel static data.
117: * @param sd the channel static data
118: * @param uid a unique ID used to identify the state of the channel
119: * @throws org.jasig.portal.PortalException
120: */
121: public void setStaticData(ChannelStaticData sd, String uid)
122: throws PortalException {
123: ChannelState channelState = new ChannelState();
124: channelState.setStaticData(sd);
125: channelStateMap.put(uid, channelState);
126: }
127:
128: /**
129: * Sets the channel runtime data.
130: * @param rd the channel runtime data
131: * @param uid a unique ID used to identify the state of the channel
132: * @throws org.jasig.portal.PortalException
133: */
134: public void setRuntimeData(ChannelRuntimeData rd, String uid)
135: throws PortalException {
136: ChannelState channelState = (ChannelState) channelStateMap
137: .get(uid);
138: channelState.setRuntimeData(rd);
139: }
140:
141: /**
142: * Render nothing.
143: * @param out the content handler to which the channel sends SAX events
144: * @param uid a unique ID used to identify the state of the channel
145: * @throws org.jasig.portal.PortalException
146: */
147: public void renderXML(ContentHandler out, String uid)
148: throws PortalException {
149: }
150: }
|