1   /*
2    * Copyright 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  package org.portletbridge.mock;
17  
18  import java.util.Enumeration;
19  import java.util.Hashtable;
20  
21  import javax.portlet.PortletContext;
22  import javax.portlet.PortletSession;
23  
24  /***
25   * @author jmccrindle
26   */
27  public class MockPortletSession implements PortletSession {
28  
29      private Hashtable localAttributes = new Hashtable();
30      private Hashtable globalAttributes = new Hashtable();
31      
32      /***
33       * 
34       */
35      public MockPortletSession() {
36          super();
37      }
38  
39      /* (non-Javadoc)
40       * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
41       */
42      public Object getAttribute(String name) {
43          return localAttributes.get(name);
44      }
45  
46      /* (non-Javadoc)
47       * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
48       */
49      public Object getAttribute(String name, int scope) {
50          return scope == PortletSession.PORTLET_SCOPE ? localAttributes.get(name) : globalAttributes.get(name);
51      }
52  
53      /* (non-Javadoc)
54       * @see javax.portlet.PortletSession#getAttributeNames()
55       */
56      public Enumeration getAttributeNames() {
57          return localAttributes.keys();
58      }
59  
60      /* (non-Javadoc)
61       * @see javax.portlet.PortletSession#getAttributeNames(int)
62       */
63      public Enumeration getAttributeNames(int scope) {
64          return scope == PortletSession.PORTLET_SCOPE ? localAttributes.keys() : globalAttributes.keys();
65      }
66  
67      /* (non-Javadoc)
68       * @see javax.portlet.PortletSession#getCreationTime()
69       */
70      public long getCreationTime() {
71          // TODO Auto-generated method stub
72          return 0;
73      }
74  
75      /* (non-Javadoc)
76       * @see javax.portlet.PortletSession#getId()
77       */
78      public String getId() {
79          // TODO Auto-generated method stub
80          return null;
81      }
82  
83      /* (non-Javadoc)
84       * @see javax.portlet.PortletSession#getLastAccessedTime()
85       */
86      public long getLastAccessedTime() {
87          // TODO Auto-generated method stub
88          return 0;
89      }
90  
91      /* (non-Javadoc)
92       * @see javax.portlet.PortletSession#getMaxInactiveInterval()
93       */
94      public int getMaxInactiveInterval() {
95          // TODO Auto-generated method stub
96          return 0;
97      }
98  
99      /* (non-Javadoc)
100      * @see javax.portlet.PortletSession#invalidate()
101      */
102     public void invalidate() {
103         // TODO Auto-generated method stub
104         
105     }
106 
107     /* (non-Javadoc)
108      * @see javax.portlet.PortletSession#isNew()
109      */
110     public boolean isNew() {
111         // TODO Auto-generated method stub
112         return false;
113     }
114 
115     /* (non-Javadoc)
116      * @see javax.portlet.PortletSession#removeAttribute(java.lang.String)
117      */
118     public void removeAttribute(String name) {
119         localAttributes.remove(name);
120     }
121 
122     /* (non-Javadoc)
123      * @see javax.portlet.PortletSession#removeAttribute(java.lang.String, int)
124      */
125     public void removeAttribute(String name, int scope) {
126         if(scope == PortletSession.PORTLET_SCOPE) {
127             localAttributes.remove(name);
128         } else {
129             globalAttributes.remove(name);
130         }
131     }
132 
133     /* (non-Javadoc)
134      * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object)
135      */
136     public void setAttribute(String name, Object value) {
137         localAttributes.put(name, value);
138     }
139 
140     /* (non-Javadoc)
141      * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object, int)
142      */
143     public void setAttribute(String name, Object value, int scope) {
144         if(scope == PortletSession.PORTLET_SCOPE) {
145             localAttributes.put(name, value);
146         } else {
147             globalAttributes.put(name, value);
148         }
149     }
150 
151     /* (non-Javadoc)
152      * @see javax.portlet.PortletSession#setMaxInactiveInterval(int)
153      */
154     public void setMaxInactiveInterval(int arg0) {
155         // TODO Auto-generated method stub
156         
157     }
158 
159     /* (non-Javadoc)
160      * @see javax.portlet.PortletSession#getPortletContext()
161      */
162     public PortletContext getPortletContext() {
163         // TODO Auto-generated method stub
164         return null;
165     }
166 
167 }