View Javadoc
1   package org.andromda.cartridges.jsf.portlet.myfaces.tomahawk.support;
2   
3   import java.util.ArrayList;
4   import java.util.Enumeration;
5   import java.util.List;
6   import javax.portlet.PortletContext;
7   import javax.portlet.PortletSession;
8   import javax.servlet.ServletContext;
9   import javax.servlet.http.HttpSession;
10  import javax.servlet.http.HttpSessionContext;
11  
12  /**
13   * This class is a dummy HttpSessionWrapper.
14   *
15   * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
16   */
17  @SuppressWarnings("deprecation")
18  public class HttpSessionWrapper
19      implements HttpSession
20  {
21      private final PortletSession portletSession;
22      private final PortletContext portletContext;
23  
24      /**
25       * @param portletSession
26       * @param portletContext
27       */
28      public HttpSessionWrapper(
29          final PortletSession portletSession,
30          final PortletContext portletContext)
31      {
32          this.portletSession = portletSession;
33          this.portletContext = portletContext;
34      }
35  
36      /**
37       * @see javax.servlet.http.HttpSession#getCreationTime()
38       */
39      public long getCreationTime()
40      {
41          return portletSession.getCreationTime();
42      }
43  
44      /**
45       * @see javax.servlet.http.HttpSession#getId()
46       */
47      public String getId()
48      {
49          return portletSession.getId();
50      }
51  
52      /**
53       * @see javax.servlet.http.HttpSession#getLastAccessedTime()
54       */
55      public long getLastAccessedTime()
56      {
57          return portletSession.getLastAccessedTime();
58      }
59  
60      /**
61       * @see javax.servlet.http.HttpSession#getServletContext()
62       */
63      public ServletContext getServletContext()
64      {
65          return new ServletContextWrapper(portletContext);
66      }
67  
68      /**
69       * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
70       */
71      public void setMaxInactiveInterval(final int arg0)
72      {
73          portletSession.setMaxInactiveInterval(arg0);
74      }
75  
76      /**
77       * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
78       */
79      public int getMaxInactiveInterval()
80      {
81          return portletSession.getMaxInactiveInterval();
82      }
83  
84      /**
85       * return null
86       * @see javax.servlet.http.HttpSession#getSessionContext()
87       * @deprecated
88       */
89      @Deprecated
90      public HttpSessionContext getSessionContext()
91      {
92          // TODO Portlet API does not have this method
93          return null;
94      }
95  
96      /**
97       * @see javax.servlet.http.HttpSession#getAttribute(String)
98       */
99      public Object getAttribute(final String arg0)
100     {
101         return portletSession.getAttribute(arg0);
102     }
103 
104     /**
105      * @see javax.servlet.http.HttpSession#getValue(String)
106      * @deprecated
107      */
108     @Deprecated
109     public Object getValue(final String arg0)
110     {
111         return portletSession.getAttribute(arg0);
112     }
113 
114     /**
115      * @see javax.servlet.http.HttpSession#getAttributeNames()
116      */
117     public Enumeration getAttributeNames()
118     {
119         return portletSession.getAttributeNames();
120     }
121 
122     /**
123      * @see javax.servlet.http.HttpSession#getValueNames()
124      * @deprecated
125      */
126     @Deprecated
127     public String[] getValueNames()
128     {
129         final List objs = new ArrayList();
130         for (final Enumeration e = portletSession.getAttributeNames(); e.hasMoreElements();)
131         {
132             final String key = (String)e.nextElement();
133             objs.add(key);
134         }
135         final String[] values = new String[objs.size()];
136         for (int i = 0; i < objs.size(); i++)
137         {
138             values[i] = (String)objs.get(i);
139         }
140         return values;
141     }
142 
143     /**
144      * @see javax.servlet.http.HttpSession#setAttribute(String, Object)
145      */
146     public void setAttribute(final String arg0, final Object arg1)
147     {
148         portletSession.setAttribute(arg0, arg1);
149     }
150 
151     /**
152      * @see javax.servlet.http.HttpSession#putValue(String, Object)
153      * @deprecated
154      */
155     @Deprecated
156     public void putValue(final String arg0, final Object arg1)
157     {
158         portletSession.setAttribute(arg0, arg1);
159     }
160 
161     /**
162      * @see javax.servlet.http.HttpSession#removeAttribute(String)
163      */
164     public void removeAttribute(final String arg0)
165     {
166         portletSession.removeAttribute(arg0);
167     }
168 
169     /**
170      * @see javax.servlet.http.HttpSession#removeValue(String)
171      * @deprecated
172      */
173     @Deprecated
174     public void removeValue(final String arg0)
175     {
176         portletSession.removeAttribute(arg0);
177     }
178 
179     /**
180      * @see javax.servlet.http.HttpSession#invalidate()
181      */
182     public void invalidate()
183     {
184         portletSession.invalidate();
185     }
186 
187     /**
188      * @see javax.servlet.http.HttpSession#isNew()
189      */
190     public boolean isNew()
191     {
192         return portletSession.isNew();
193     }
194 }