001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.wsrp;
022:
023: import java.util.Hashtable;
024: import java.util.Map;
025:
026: import javax.portlet.PortletSession;
027:
028: import oasis.names.tc.wsrp.v1.intf.WSRP_v1_Markup_PortType;
029:
030: import org.apache.wsrp4j.consumer.GroupSessionMgr;
031: import org.apache.wsrp4j.consumer.driver.GenericUserSessionImpl;
032: import org.apache.wsrp4j.consumer.util.ConsumerConstants;
033: import org.apache.wsrp4j.exception.WSRPException;
034:
035: /**
036: * <a href="UserSessionImpl.java.html"><b><i>View Source</i></b></a>
037: *
038: * @author Michael Young
039: *
040: */
041: public class UserSessionImpl extends GenericUserSessionImpl {
042:
043: public UserSessionImpl(String producerID, String userID,
044: String portletServicesURL, PortletSession portletSession)
045: throws WSRPException {
046:
047: super (producerID, userID, portletServicesURL);
048:
049: this ._portletSession = portletSession;
050: _userSession = getUserSessionMap();
051: setGroupSessionTable(getGroupSessionTable());
052: }
053:
054: private Hashtable getGroupSessionTable() {
055:
056: if ((groupSessions = (Hashtable) _userSession
057: .get(ConsumerConstants.WSRP_GROUPSESSIONS)) == null) {
058: groupSessions = new Hashtable();
059: _userSession.put(ConsumerConstants.WSRP_GROUPSESSIONS,
060: groupSessions);
061: }
062:
063: return groupSessions;
064: }
065:
066: /**
067: * Get the group session for this group ID
068: *
069: * @param groupID
070: * ID of the portlet application
071: * @return The group session for the provided group ID
072: */
073: public GroupSessionMgr getGroupSession(String groupID)
074: throws WSRPException {
075:
076: if (groupID != null) {
077: GroupSessionMgr groupSession = (GroupSessionMgr) this .groupSessions
078: .get(groupID);
079: if (groupSession == null) {
080:
081: groupSession = new GroupSessionImpl(groupID, this
082: .getMarkupInterfaceURL());
083: addGroupSession(groupSession);
084: }
085:
086: return groupSession;
087: }
088: return null;
089: }
090:
091: public WSRP_v1_Markup_PortType getWSRPBaseService() {
092: WSRP_v1_Markup_PortType markupPort = null;
093: if ((markupPort = (WSRP_v1_Markup_PortType) _userSession
094: .get(ConsumerConstants.WSRP_MARKUP_PORT)) == null) {
095: markupPort = super .getWSRPBaseService();
096: _userSession.put(ConsumerConstants.WSRP_MARKUP_PORT,
097: markupPort);
098: }
099:
100: this .setWSRPBaseService(markupPort);
101: return markupPort;
102: }
103:
104: public boolean isInitCookieRequired() {
105: Boolean initCookieReq = null;
106: if ((initCookieReq = (Boolean) _userSession
107: .get(ConsumerConstants.WSRP_INIT_COOKIE_REQ)) == null) {
108: initCookieReq = Boolean.valueOf(super
109: .isInitCookieRequired());
110: setInitCookieRequired(initCookieReq.booleanValue());
111: }
112:
113: return initCookieReq.booleanValue();
114: }
115:
116: public void setInitCookieRequired(boolean initCookieRequired) {
117: _userSession.put(ConsumerConstants.WSRP_INIT_COOKIE_REQ,
118: Boolean.valueOf(initCookieRequired));
119: super .setInitCookieRequired(initCookieRequired);
120: }
121:
122: public boolean isInitCookieDone() {
123: Boolean initCookieDone = null;
124: if ((initCookieDone = (Boolean) _userSession
125: .get(ConsumerConstants.WSRP_INIT_COOKIE_DONE)) == null) {
126: initCookieDone = Boolean.valueOf(super .isInitCookieDone());
127: setInitCookieDone(initCookieDone.booleanValue());
128: }
129:
130: return initCookieDone.booleanValue();
131: }
132:
133: public void setInitCookieDone(boolean initCookieDone) {
134: _userSession.put(ConsumerConstants.WSRP_INIT_COOKIE_DONE,
135: Boolean.valueOf(initCookieDone));
136: super .setInitCookieRequired(initCookieDone);
137: }
138:
139: private Map getUserSessionMap() {
140: String key = createKey();
141: Map myMap = (Map) this ._portletSession.getAttribute(key,
142: PortletSession.APPLICATION_SCOPE);
143:
144: if (myMap == null) {
145: myMap = new Hashtable();
146: this ._portletSession.setAttribute(key, myMap,
147: PortletSession.APPLICATION_SCOPE);
148: }
149:
150: return myMap;
151: }
152:
153: private String createKey() {
154: return "user :" + this .getUserID() + " producer:"
155: + this .getProducerID();
156: }
157:
158: private PortletSession _portletSession = null;
159:
160: private Map _userSession = null;
161:
162: }
|