KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > wsrp > consumer > SessionHandlerImpl


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.wsrp.consumer;
17
18 import java.util.Hashtable JavaDoc;
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 /**
28  * Simple Session Handler<br/>
29  *
30  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
31  * @author <a HREF="mailto:malessandrini@s-und-n.de">Michel Alessandrini</a>
32  *
33  * @version $Id: SessionHandlerImpl.java 264755 2005-08-30 10:29:21Z cziegeler $
34  **/

35 public class SessionHandlerImpl
36     extends AbstractLogEnabled
37     implements SessionHandler, RequiresConsumerEnvironment {
38
39     /** Holds all user-sessions */
40     protected Hashtable JavaDoc userSessions = new Hashtable JavaDoc();
41     
42     /** The consumerEnvironment */
43     protected ConsumerEnvironment consumerEnv;
44     
45     /**
46      * @see org.apache.cocoon.portal.wsrp.consumer.RequiresConsumerEnvironment#setConsumerEnvironment(org.apache.wsrp4j.consumer.ConsumerEnvironment)
47      */

48     public void setConsumerEnvironment(ConsumerEnvironment env) {
49         this.consumerEnv = env;
50     }
51
52     /**
53      * Get the session manager of the user session with the given user ID and producer ID<br/>
54      *
55      * @return The user session object representing a session between an end-user and
56      * a producer.
57      **/

58     public UserSessionMgr getUserSession(String JavaDoc producerID, String JavaDoc userID)
59     throws WSRPException {
60         UserSessionMgr userSession = null;
61
62         if (producerID != null && userID != null) {
63             String JavaDoc key = createKey(userID, producerID);
64             userSession = (UserSessionMgr)this.userSessions.get(key);
65
66             if (userSession == null) {
67                 String JavaDoc 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     /**
77      * Set the Session into the sessionHandler
78      *
79      * @param userSession
80      */

81     private void addUserSession(UserSession userSession) {
82         if (userSession != null) {
83             this.userSessions.put(createKey(userSession.getUserID(), userSession.getProducerID()), userSession);
84         }
85     }
86
87     /**
88      * Represents the values of the user and the producer in a nice form<br/>
89      *
90      * @param userID
91      * @param producerID
92      * @return the string containing information of the user and the producer
93      */

94     private String JavaDoc createKey(String JavaDoc userID, String JavaDoc producerID) {
95         return "user :" + userID + " producer:" + producerID;
96     }
97 }
98
Popular Tags