1 16 package org.apache.cocoon.portal.wsrp.consumer; 17 18 import java.util.Hashtable ; 19 20 import org.apache.avalon.framework.logger.AbstractLogEnabled; 21 import org.apache.wsrp4j.consumer.ConsumerEnvironment; 22 import org.apache.wsrp4j.consumer.SessionHandler; 23 import org.apache.wsrp4j.consumer.UserSession; 24 import org.apache.wsrp4j.consumer.UserSessionMgr; 25 import org.apache.wsrp4j.exception.WSRPException; 26 27 35 public class SessionHandlerImpl 36 extends AbstractLogEnabled 37 implements SessionHandler, RequiresConsumerEnvironment { 38 39 40 protected Hashtable userSessions = new Hashtable (); 41 42 43 protected ConsumerEnvironment consumerEnv; 44 45 48 public void setConsumerEnvironment(ConsumerEnvironment env) { 49 this.consumerEnv = env; 50 } 51 52 58 public UserSessionMgr getUserSession(String producerID, String userID) 59 throws WSRPException { 60 UserSessionMgr userSession = null; 61 62 if (producerID != null && userID != null) { 63 String key = createKey(userID, producerID); 64 userSession = (UserSessionMgr)this.userSessions.get(key); 65 66 if (userSession == null) { 67 String url = consumerEnv.getProducerRegistry().getProducer(producerID).getMarkupInterfaceEndpoint(); 68 userSession = new UserSessionImpl(producerID, userID, url, this.getLogger()); 69 addUserSession(userSession); 70 } 71 } 72 73 return userSession; 74 } 75 76 81 private void addUserSession(UserSession userSession) { 82 if (userSession != null) { 83 this.userSessions.put(createKey(userSession.getUserID(), userSession.getProducerID()), userSession); 84 } 85 } 86 87 94 private String createKey(String userID, String producerID) { 95 return "user :" + userID + " producer:" + producerID; 96 } 97 } 98 | Popular Tags |