001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.taskadmin.context;
006:
007: import java.util.Map;
008: import java.util.HashMap;
009: import java.util.Iterator;
010:
011: import javax.servlet.http.HttpServletRequest;
012:
013: import com.sun.portal.taskadmin.TaskAdminException;
014: import com.sun.portal.taskadmin.TaskAdminConstants;
015:
016: import com.sun.portal.desktop.context.ContextError;
017:
018: import com.sun.portal.util.ResourceLoader;
019:
020: import com.iplanet.sso.SSOToken;
021: import com.iplanet.sso.SSOTokenListener;
022: import com.iplanet.sso.SSOTokenEvent;
023:
024: public class ISChannelTaskAdminContextFactory implements
025: ChannelTaskAdminContextFactory, SSOTokenListener {
026:
027: private Map channelTaskAdminContexts = new HashMap();
028:
029: public ISChannelTaskAdminContextFactory() {
030: //do nothing
031: }
032:
033: public void init() {
034: // do nothing for now.
035: }
036:
037: public ChannelTaskAdminContext getChannelTaskAdminContext(
038: HttpServletRequest req) throws TaskAdminException {
039: return getChannelTaskAdminContext(req, true);
040: }
041:
042: public synchronized ChannelTaskAdminContext getChannelTaskAdminContext(
043: HttpServletRequest req, boolean create)
044: throws TaskAdminException {
045: String portalId = ResourceLoader.getInstance(
046: System.getProperties()).getPortalId();
047: ISChannelTaskAdminContext context = null;
048: String sid = getSessionID(req);
049: Map contextsperPortal = (Map) channelTaskAdminContexts.get(sid);
050: if (contextsperPortal != null && !contextsperPortal.isEmpty()
051: && contextsperPortal.containsKey(portalId)) {
052: context = (ISChannelTaskAdminContext) contextsperPortal
053: .get(portalId);
054: }
055:
056: if (context == null && create) {
057: //
058: // could not find in cache
059: // create a new one
060: //
061:
062: try {
063: context = new ISChannelTaskAdminContext();
064: context.init(req);
065: //
066: // put the new object into the cache
067: //
068: context.addSSOTokenListener(this );
069: //context.debugError("added the token listener for channeltaskadmincontext");
070: if (contextsperPortal == null) {
071: contextsperPortal = new HashMap();
072: }
073: contextsperPortal.put(portalId, context);
074: channelTaskAdminContexts.put(sid, contextsperPortal);
075: } catch (SecurityException se) {
076: throw new ContextError(
077: "TaskAdminContextFactory.getTaskAdminContext(): ",
078: se);
079: }
080: }
081:
082: return context;
083: }
084:
085: public ChannelTaskAdminContext getChannelTaskAdminContext(
086: SSOToken ssoToken, String portalId)
087: throws TaskAdminException {
088: return getChannelTaskAdminContext(ssoToken, portalId, true);
089: }
090:
091: public synchronized ChannelTaskAdminContext getChannelTaskAdminContext(
092: SSOToken ssoToken, String portalId, boolean create)
093: throws TaskAdminException {
094:
095: ISChannelTaskAdminContext context = null;
096: String sid = ssoToken.getTokenID().toString();
097: Map contextsperPortal = (Map) channelTaskAdminContexts.get(sid);
098: if (contextsperPortal != null && !contextsperPortal.isEmpty()
099: && contextsperPortal.containsKey(portalId)) {
100: context = (ISChannelTaskAdminContext) contextsperPortal
101: .get(portalId);
102: }
103:
104: if (context == null && create) {
105: //
106: // could not find in cache
107: // create a new one
108: //
109:
110: try {
111: context = new ISChannelTaskAdminContext();
112: context.init(ssoToken, portalId);
113: //
114: // put the new object into the cache
115: //
116: context.addSSOTokenListener(this );
117: if (contextsperPortal == null) {
118: contextsperPortal = new HashMap();
119: }
120: contextsperPortal.put(portalId, context);
121: channelTaskAdminContexts.put(sid, contextsperPortal);
122: } catch (SecurityException se) {
123: throw new ContextError(
124: "TaskAdminContextFactory.getTaskAdminContext(): ",
125: se);
126: }
127: }
128:
129: return context;
130: }
131:
132: public synchronized void ssoTokenChanged(SSOTokenEvent se) {
133: String sid = se.getToken().getTokenID().toString();
134: DPRootCacheManager.clearCache(sid);
135: channelTaskAdminContexts.remove(sid);
136:
137: }
138:
139: public String getSessionID(HttpServletRequest req)
140: throws TaskAdminException {
141: return TaskAdminISConnection.getSSOToken(req).getTokenID()
142: .toString();
143: }
144:
145: }
|