001: /* PortletHttpSession.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Tue Jan 17 10:46:06 2006, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.web.portlet;
020:
021: import javax.servlet.http.HttpSession;
022: import javax.portlet.PortletSession;
023:
024: /**
025: * A facade of PortletSession for implementing HttpSession.
026: *
027: * @author tomyeh
028: */
029: public class PortletHttpSession implements HttpSession {
030: private final PortletSession _sess;
031:
032: public static HttpSession getInstance(PortletSession sess) {
033: if (sess instanceof HttpSession)
034: return (HttpSession) sess;
035: return new PortletHttpSession(sess);
036: }
037:
038: private PortletHttpSession(PortletSession sess) {
039: if (sess == null)
040: throw new IllegalArgumentException("null");
041: _sess = sess;
042: }
043:
044: //-- HttpSession --//
045: public Object getAttribute(String name) {
046: final Object o = _sess.getAttribute(name);
047: return o != null ? o : _sess.getAttribute(name,
048: PortletSession.APPLICATION_SCOPE);
049: }
050:
051: public java.util.Enumeration getAttributeNames() {
052: return _sess.getAttributeNames();
053: }
054:
055: public long getCreationTime() {
056: return _sess.getCreationTime();
057: }
058:
059: public String getId() {
060: return _sess.getId();
061: }
062:
063: public long getLastAccessedTime() {
064: return _sess.getLastAccessedTime();
065: }
066:
067: public int getMaxInactiveInterval() {
068: return _sess.getMaxInactiveInterval();
069: }
070:
071: public javax.servlet.ServletContext getServletContext() {
072: return PortletServletContext.getInstance(_sess
073: .getPortletContext());
074: }
075:
076: /**
077: * @deprecated
078: */
079: public javax.servlet.http.HttpSessionContext getSessionContext() {
080: return null;
081: }
082:
083: /**
084: * @deprecated
085: */
086: public Object getValue(String name) {
087: return null;
088: }
089:
090: /**
091: * @deprecated
092: */
093: public String[] getValueNames() {
094: return null;
095: }
096:
097: public void invalidate() {
098: _sess.invalidate();
099: }
100:
101: public boolean isNew() {
102: return _sess.isNew();
103: }
104:
105: /**
106: * @deprecated
107: */
108: public void putValue(String name, Object value) {
109: }
110:
111: public void removeAttribute(String name) {
112: _sess.removeAttribute(name);
113: }
114:
115: /**
116: * @deprecated
117: */
118: public void removeValue(String name) {
119: }
120:
121: public void setAttribute(String name, Object value) {
122: if (name != null && name.startsWith("javax."))
123: _sess.setAttribute(name, value,
124: PortletSession.APPLICATION_SCOPE);
125: else
126: _sess.setAttribute(name, value);
127: }
128:
129: public void setMaxInactiveInterval(int interval) {
130: _sess.setMaxInactiveInterval(interval);
131: }
132: }
|