001: /*
002: * Copyright 2000-2001,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.wsrp4j.consumer.driver;
018:
019: import java.util.Hashtable;
020: import java.util.Iterator;
021:
022: import org.apache.wsrp4j.consumer.GroupSessionMgr;
023: import org.apache.wsrp4j.consumer.PortletSession;
024: import org.apache.wsrp4j.exception.WSRPException;
025: import org.apache.wsrp4j.log.LogManager;
026: import org.apache.wsrp4j.log.Logger;
027:
028: /**
029: * Class implements a consumer based group session
030: *
031: */
032: public abstract class GenericGroupSessionImpl extends
033: InitCookieInfoImpl implements GroupSessionMgr {
034:
035: // ID of the group this session is bind to
036: private String groupID = null;
037:
038: // holding all the portlet session objects for this group
039: protected Hashtable portletSessions = null;
040:
041: // logger
042: private static final Logger logger = LogManager.getLogManager()
043: .getLogger(GenericGroupSessionImpl.class);
044:
045: public GenericGroupSessionImpl(String groupID,
046: String markupInterfaceURL) throws WSRPException {
047: super (markupInterfaceURL);
048:
049: final String MN = "constructor";
050: if (logger.isLogging(Logger.TRACE_HIGH)) {
051: logger.entry(Logger.TRACE_HIGH, MN);
052: }
053:
054: this .groupID = groupID;
055: this .portletSessions = new Hashtable();
056:
057: if (logger.isLogging(Logger.TRACE_HIGH)) {
058: logger.exit(Logger.TRACE_HIGH, MN);
059: }
060: }
061:
062: public String getGroupID() {
063: return this .groupID;
064: }
065:
066: public void setGroupID(String groupID) {
067: if (groupID != null) {
068: this .groupID = groupID;
069: }
070: }
071:
072: public void addPortletSession(PortletSession portletSession) {
073: final String MN = "addPortletSession";
074:
075: if (portletSession != null) {
076: this .portletSessions.put(portletSession.getPortletHandle(),
077: portletSession);
078: if (logger.isLogging(Logger.TRACE_HIGH)) {
079: logger.text(Logger.TRACE_HIGH, MN,
080: "added PortletSession with handle: "
081: + portletSession.getPortletHandle()
082: + " to GroupSession with ID: "
083: + groupID);
084: }
085: }
086: }
087:
088: public abstract PortletSession getPortletSession(
089: String portletHandle);
090:
091: public Iterator getAllPortletSessions() {
092: return this .portletSessions.values().iterator();
093: }
094:
095: public void removePortletSession(String portletHandle) {
096: final String MN = "removePortletSession";
097: if (portletHandle == null) {
098: this .portletSessions.remove(portletHandle);
099: if (logger.isLogging(Logger.TRACE_HIGH)) {
100: logger.text(Logger.TRACE_HIGH, MN,
101: "deleted PortletSession with handle: "
102: + portletHandle
103: + " from GroupSession with ID: "
104: + groupID);
105: }
106: }
107: }
108:
109: public void removeAllPortletSessions() {
110: this .portletSessions.clear();
111: }
112:
113: public boolean existsPortletSession(String portletHandle) {
114: if (portletHandle == null)
115: return false;
116: return this.portletSessions.containsKey(portletHandle);
117: }
118: }
|