001: /*
002: * $Id: $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.portlet.servlet;
022:
023: import java.util.ArrayList;
024: import java.util.Enumeration;
025: import java.util.List;
026:
027: import javax.portlet.PortletSession;
028: import javax.servlet.ServletContext;
029: import javax.servlet.http.HttpSession;
030: import javax.servlet.http.HttpSessionContext;
031:
032: /**
033: * Wrapper object exposing a {@link PortletSession} as a {@link HttpSession} instance.
034: * Clients accessing this session object will in fact operate on the
035: * {@link PortletSession} object wrapped by this session object.
036: */
037: public class PortletHttpSession implements HttpSession {
038:
039: private PortletSession portletSession;
040:
041: public PortletHttpSession(PortletSession portletSession) {
042: this .portletSession = portletSession;
043: }
044:
045: /*
046: * (non-Javadoc)
047: *
048: * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
049: */
050: public Object getAttribute(String name) {
051: return portletSession.getAttribute(name);
052: }
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see javax.servlet.http.HttpSession#getAttributeNames()
058: */
059: public Enumeration getAttributeNames() {
060: return portletSession.getAttributeNames();
061: }
062:
063: /*
064: * (non-Javadoc)
065: *
066: * @see javax.servlet.http.HttpSession#getCreationTime()
067: */
068: public long getCreationTime() {
069: return portletSession.getCreationTime();
070: }
071:
072: /*
073: * (non-Javadoc)
074: *
075: * @see javax.servlet.http.HttpSession#getId()
076: */
077: public String getId() {
078: return portletSession.getId();
079: }
080:
081: /*
082: * (non-Javadoc)
083: *
084: * @see javax.servlet.http.HttpSession#getLastAccessedTime()
085: */
086: public long getLastAccessedTime() {
087: return portletSession.getLastAccessedTime();
088: }
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
094: */
095: public int getMaxInactiveInterval() {
096: return portletSession.getMaxInactiveInterval();
097: }
098:
099: /*
100: * (non-Javadoc)
101: *
102: * @see javax.servlet.http.HttpSession#getServletContext()
103: */
104: public ServletContext getServletContext() {
105: return new PortletServletContext(portletSession
106: .getPortletContext());
107: }
108:
109: /**
110: * @see javax.servlet.http.HttpSession#getSessionContext()
111: * @throws IllegalStateException
112: * Not supported in a portlet.
113: */
114: public HttpSessionContext getSessionContext() {
115: throw new IllegalStateException("Not supported in a portlet");
116: }
117:
118: /*
119: * (non-Javadoc)
120: *
121: * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
122: */
123: public Object getValue(String name) {
124: return getAttribute(name);
125: }
126:
127: /*
128: * (non-Javadoc)
129: *
130: * @see javax.servlet.http.HttpSession#getValueNames()
131: */
132: public String[] getValueNames() {
133: List<String> names = new ArrayList<String>();
134: Enumeration attrNames = getAttributeNames();
135: while (attrNames.hasMoreElements()) {
136: names.add((String) attrNames.nextElement());
137: }
138: return names.toArray(new String[0]);
139: }
140:
141: /*
142: * (non-Javadoc)
143: *
144: * @see javax.servlet.http.HttpSession#invalidate()
145: */
146: public void invalidate() {
147: portletSession.invalidate();
148: }
149:
150: /*
151: * (non-Javadoc)
152: *
153: * @see javax.servlet.http.HttpSession#isNew()
154: */
155: public boolean isNew() {
156: return portletSession.isNew();
157: }
158:
159: /*
160: * (non-Javadoc)
161: *
162: * @see javax.servlet.http.HttpSession#putValue(java.lang.String,
163: * java.lang.Object)
164: */
165: public void putValue(String name, Object value) {
166: setAttribute(name, value);
167: }
168:
169: /*
170: * (non-Javadoc)
171: *
172: * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
173: */
174: public void removeAttribute(String name) {
175: portletSession.removeAttribute(name);
176: }
177:
178: /*
179: * (non-Javadoc)
180: *
181: * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
182: */
183: public void removeValue(String name) {
184: removeAttribute(name);
185: }
186:
187: /*
188: * (non-Javadoc)
189: *
190: * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String,
191: * java.lang.Object)
192: */
193: public void setAttribute(String name, Object value) {
194: portletSession.setAttribute(name, value);
195: }
196:
197: /*
198: * (non-Javadoc)
199: *
200: * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
201: */
202: public void setMaxInactiveInterval(int interval) {
203: portletSession.setMaxInactiveInterval(interval);
204: }
205:
206: /**
207: * Get the wrapped portlet session.
208: *
209: * @return The wrapped portlet session.
210: */
211: public PortletSession getPortletSession() {
212: return portletSession;
213: }
214:
215: }
|