1   /*
2    * Copyright 2000-2001,2004 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  
17  package org.apache.wsrp4j.consumer.driver;
18  
19  import java.util.Hashtable;
20  import java.util.Iterator;
21  
22  import org.apache.wsrp4j.consumer.GroupSessionMgr;
23  import org.apache.wsrp4j.consumer.PortletSession;
24  import org.apache.wsrp4j.exception.WSRPException;
25  import org.apache.wsrp4j.log.LogManager;
26  import org.apache.wsrp4j.log.Logger;
27  
28  /**
29   * Class implements a consumer based group session
30   * 
31   */
32  public abstract class GenericGroupSessionImpl extends InitCookieInfoImpl
33          implements GroupSessionMgr {
34  
35      // ID of the group this session is bind to 
36      private String groupID = null;
37  
38      // holding all the portlet session objects for this group
39      protected Hashtable portletSessions = null;
40  
41      // logger
42      private static final Logger logger = LogManager.getLogManager().getLogger(
43              GenericGroupSessionImpl.class);
44  
45      public GenericGroupSessionImpl(String groupID, String markupInterfaceURL)
46              throws WSRPException {
47          super(markupInterfaceURL);
48  
49          final String MN = "constructor";
50          if (logger.isLogging(Logger.TRACE_HIGH)) {
51              logger.entry(Logger.TRACE_HIGH, MN);
52          }
53  
54          this.groupID = groupID;
55          this.portletSessions = new Hashtable();
56  
57          if (logger.isLogging(Logger.TRACE_HIGH)) {
58              logger.exit(Logger.TRACE_HIGH, MN);
59          }
60      }
61  
62      public String getGroupID() {
63          return this.groupID;
64      }
65  
66      public void setGroupID(String groupID) {
67          if (groupID != null) {
68              this.groupID = groupID;
69          }
70      }
71  
72      public void addPortletSession(PortletSession portletSession) {
73          final String MN = "addPortletSession";
74  
75          if (portletSession != null) {
76              this.portletSessions.put(portletSession.getPortletHandle(),
77                      portletSession);
78              if (logger.isLogging(Logger.TRACE_HIGH)) {
79                  logger.text(Logger.TRACE_HIGH, MN,
80                          "added PortletSession with handle: "
81                                  + portletSession.getPortletHandle()
82                                  + " to GroupSession with ID: " + groupID);
83              }
84          }
85      }
86  
87      public abstract PortletSession getPortletSession(String portletHandle);
88  
89      public Iterator getAllPortletSessions() {
90          return this.portletSessions.values().iterator();
91      }
92  
93      public void removePortletSession(String portletHandle) {
94          final String MN = "removePortletSession";
95          if (portletHandle == null) {
96              this.portletSessions.remove(portletHandle);
97              if (logger.isLogging(Logger.TRACE_HIGH)) {
98                  logger.text(Logger.TRACE_HIGH, MN,
99                          "deleted PortletSession with handle: " + portletHandle
100                                 + " from GroupSession with ID: " + groupID);
101             }
102         }
103     }
104 
105     public void removeAllPortletSessions() {
106         this.portletSessions.clear();
107     }
108 
109     public boolean existsPortletSession(String portletHandle) {
110         if (portletHandle == null)
111             return false;
112         return this.portletSessions.containsKey(portletHandle);
113     }
114 }