1
19
20 package com.liferay.portlet.wsrp;
21
22 import java.util.Hashtable;
23 import java.util.Map;
24
25 import javax.portlet.PortletSession;
26
27 import oasis.names.tc.wsrp.v1.intf.WSRP_v1_Markup_PortType;
28
29 import org.apache.wsrp4j.consumer.GroupSessionMgr;
30 import org.apache.wsrp4j.consumer.driver.GenericUserSessionImpl;
31 import org.apache.wsrp4j.consumer.util.ConsumerConstants;
32 import org.apache.wsrp4j.exception.WSRPException;
33
34
40 public class UserSessionImpl extends GenericUserSessionImpl {
41
42 public UserSessionImpl(String producerID, String userID,
43 String portletServicesURL, PortletSession portletSession)
44 throws WSRPException {
45
46 super(producerID, userID, portletServicesURL);
47
48 this._portletSession = portletSession;
49 _userSession = getUserSessionMap();
50 setGroupSessionTable(getGroupSessionTable());
51 }
52
53 private Hashtable getGroupSessionTable() {
54
55 if ((groupSessions = (Hashtable) _userSession
56 .get(ConsumerConstants.WSRP_GROUPSESSIONS)) == null) {
57 groupSessions = new Hashtable();
58 _userSession
59 .put(ConsumerConstants.WSRP_GROUPSESSIONS, groupSessions);
60 }
61
62 return groupSessions;
63 }
64
65
72 public GroupSessionMgr getGroupSession(String groupID)
73 throws WSRPException {
74
75 if (groupID != null) {
76 GroupSessionMgr groupSession = (GroupSessionMgr) this.groupSessions
77 .get(groupID);
78 if (groupSession == null) {
79
80 groupSession = new GroupSessionImpl(groupID, this
81 .getMarkupInterfaceURL());
82 addGroupSession(groupSession);
83 }
84
85 return groupSession;
86 }
87 return null;
88 }
89
90 public WSRP_v1_Markup_PortType getWSRPBaseService() {
91 WSRP_v1_Markup_PortType markupPort = null;
92 if ((markupPort = (WSRP_v1_Markup_PortType) _userSession
93 .get(ConsumerConstants.WSRP_MARKUP_PORT)) == null) {
94 markupPort = super.getWSRPBaseService();
95 _userSession.put(ConsumerConstants.WSRP_MARKUP_PORT, markupPort);
96 }
97
98 this.setWSRPBaseService(markupPort);
99 return markupPort;
100 }
101
102 public boolean isInitCookieRequired() {
103 Boolean initCookieReq = null;
104 if ((initCookieReq = (Boolean) _userSession
105 .get(ConsumerConstants.WSRP_INIT_COOKIE_REQ)) == null) {
106 initCookieReq = Boolean.valueOf(super.isInitCookieRequired());
107 setInitCookieRequired(initCookieReq.booleanValue());
108 }
109
110 return initCookieReq.booleanValue();
111 }
112
113 public void setInitCookieRequired(boolean initCookieRequired) {
114 _userSession.put(ConsumerConstants.WSRP_INIT_COOKIE_REQ, Boolean.valueOf(
115 initCookieRequired));
116 super.setInitCookieRequired(initCookieRequired);
117 }
118
119 public boolean isInitCookieDone() {
120 Boolean initCookieDone = null;
121 if ((initCookieDone = (Boolean) _userSession
122 .get(ConsumerConstants.WSRP_INIT_COOKIE_DONE)) == null) {
123 initCookieDone = Boolean.valueOf(super.isInitCookieDone());
124 setInitCookieDone(initCookieDone.booleanValue());
125 }
126
127 return initCookieDone.booleanValue();
128 }
129
130 public void setInitCookieDone(boolean initCookieDone) {
131 _userSession.put(ConsumerConstants.WSRP_INIT_COOKIE_DONE, Boolean.valueOf(
132 initCookieDone));
133 super.setInitCookieRequired(initCookieDone);
134 }
135
136 private Map getUserSessionMap() {
137 String key = createKey();
138 Map myMap = (Map) this._portletSession.getAttribute(key,
139 PortletSession.APPLICATION_SCOPE);
140
141 if (myMap == null) {
142 myMap = new Hashtable();
143 this._portletSession.setAttribute(key, myMap,
144 PortletSession.APPLICATION_SCOPE);
145 }
146
147 return myMap;
148 }
149
150 private String createKey() {
151 return "user :" + this.getUserID() + " producer:"
152 + this.getProducerID();
153 }
154
155 private PortletSession _portletSession = null;
156
157 private Map _userSession = null;
158
159 }