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.HashMap;
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: import oasis.names.tc.wsrp.v1.types.SessionContext;
024:
025: import org.apache.wsrp4j.consumer.PortletSession;
026: import org.apache.wsrp4j.consumer.PortletWindowSession;
027: import org.apache.wsrp4j.log.LogManager;
028: import org.apache.wsrp4j.log.Logger;
029:
030: public abstract class GenericPortletSessionImpl implements
031: PortletSession {
032: // the session context passed from the producer to store
033: private SessionContext sessionCtx = null;
034:
035: // the portlet handle identifying the where the session belogns to
036: private String handle = null;
037:
038: // holds the varios window sessions for this portlet instance
039: protected final Map windowSessions;
040:
041: // logger
042: private static final Logger logger = LogManager.getLogManager()
043: .getLogger(GenericPortletSessionImpl.class);
044:
045: public GenericPortletSessionImpl(String handle) {
046: final String MN = "constructor";
047: if (logger.isLogging(Logger.TRACE_HIGH)) {
048: logger.entry(Logger.TRACE_HIGH, MN);
049: }
050:
051: this .windowSessions = new HashMap();
052: this .handle = handle;
053:
054: if (logger.isLogging(Logger.TRACE_HIGH)) {
055: logger.exit(Logger.TRACE_HIGH, MN);
056: }
057: }
058:
059: public String getPortletHandle() {
060: return handle;
061: }
062:
063: public void setPortletHandle(String handle) {
064: if (handle != null) {
065: this .handle = handle;
066: }
067: }
068:
069: public SessionContext getSessionContext() {
070: return sessionCtx;
071: }
072:
073: public void setSessionContext(SessionContext ctx) {
074: this .sessionCtx = ctx;
075: }
076:
077: /**
078: * Get the <code>PortletWindowSession</code> of the portlet window with the given ID.
079: *
080: * @param windowID The ID of the portlet window
081: * @return The <code>PorletWindowSession</code> with the given ID.
082: **/
083: public abstract PortletWindowSession getPortletWindowSession(
084: String windowID);
085:
086: /**
087: * Get all window session which belong to the portlet session
088: *
089: * @return An Iterator of <code>SimplePortletWindowSession</code> objects.
090: **/
091: public Iterator getAllPorletWindowSessions() {
092:
093: return this .windowSessions.entrySet().iterator();
094: }
095:
096: /**
097: * Remove the porlet window session with the given window id.
098: *
099: * @param windowID The ID of the portlet window whichs session shoul dbe removed
100: * @return The portlet window session which has been removed or null if the session did not exist.
101: **/
102: public PortletWindowSession removePortletWindowSession(
103: String windowID) {
104: final String MN = "getPortletWindowSession";
105:
106: PortletWindowSession winSession = (PortletWindowSession) this .windowSessions
107: .remove(windowID);
108:
109: if (logger.isLogging(Logger.TRACE_HIGH) && winSession != null) {
110: logger
111: .text(Logger.TRACE_HIGH, MN,
112: "removed PortletWindowSession with ID: "
113: + windowID);
114: }
115:
116: return winSession;
117: }
118:
119: /**
120: * Remove all portlet window sessions which belong to this portlet session.
121: **/
122: public void removeAllPortletWindowSessions() {
123: this.windowSessions.clear();
124: }
125: }
|