1
22
23 package com.liferay.portlet.wsrp;
24
25 import java.util.Hashtable;
26 import java.util.Map;
27
28 import javax.portlet.PortletSession;
29
30 import oasis.names.tc.wsrp.v1.intf.WSRP_v1_Markup_PortType;
31
32 import org.apache.wsrp4j.consumer.GroupSessionMgr;
33 import org.apache.wsrp4j.consumer.driver.GenericUserSessionImpl;
34 import org.apache.wsrp4j.consumer.util.ConsumerConstants;
35 import org.apache.wsrp4j.exception.WSRPException;
36
37
43 public class UserSessionImpl extends GenericUserSessionImpl {
44
45 public UserSessionImpl(String producerID, String userID,
46 String portletServicesURL, PortletSession portletSession)
47 throws WSRPException {
48
49 super(producerID, userID, portletServicesURL);
50
51 this._portletSession = portletSession;
52 _userSession = getUserSessionMap();
53 setGroupSessionTable(getGroupSessionTable());
54 }
55
56 private Hashtable getGroupSessionTable() {
57
58 if ((groupSessions = (Hashtable) _userSession
59 .get(ConsumerConstants.WSRP_GROUPSESSIONS)) == null) {
60 groupSessions = new Hashtable();
61 _userSession
62 .put(ConsumerConstants.WSRP_GROUPSESSIONS, groupSessions);
63 }
64
65 return groupSessions;
66 }
67
68
75 public GroupSessionMgr getGroupSession(String groupID)
76 throws WSRPException {
77
78 if (groupID != null) {
79 GroupSessionMgr groupSession = (GroupSessionMgr) this.groupSessions
80 .get(groupID);
81 if (groupSession == null) {
82
83 groupSession = new GroupSessionImpl(groupID, this
84 .getMarkupInterfaceURL());
85 addGroupSession(groupSession);
86 }
87
88 return groupSession;
89 }
90 return null;
91 }
92
93 public WSRP_v1_Markup_PortType getWSRPBaseService() {
94 WSRP_v1_Markup_PortType markupPort = null;
95 if ((markupPort = (WSRP_v1_Markup_PortType) _userSession
96 .get(ConsumerConstants.WSRP_MARKUP_PORT)) == null) {
97 markupPort = super.getWSRPBaseService();
98 _userSession.put(ConsumerConstants.WSRP_MARKUP_PORT, markupPort);
99 }
100
101 this.setWSRPBaseService(markupPort);
102 return markupPort;
103 }
104
105 public boolean isInitCookieRequired() {
106 Boolean initCookieReq = null;
107 if ((initCookieReq = (Boolean) _userSession
108 .get(ConsumerConstants.WSRP_INIT_COOKIE_REQ)) == null) {
109 initCookieReq = Boolean.valueOf(super.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, Boolean.valueOf(
118 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, Boolean.valueOf(
135 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 }