001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.servlet;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.util.CollectionFactory;
025: import com.liferay.util.ListUtil;
026: import com.liferay.util.PwdGenerator;
027:
028: import java.util.Collections;
029: import java.util.Enumeration;
030: import java.util.List;
031: import java.util.Map;
032:
033: import javax.servlet.ServletContext;
034: import javax.servlet.http.HttpSession;
035:
036: /**
037: * <a href="NullSession.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class NullSession implements HttpSession {
043:
044: public NullSession() {
045: _attributes = CollectionFactory.getSyncHashMap();
046: _creationTime = System.currentTimeMillis();
047: _id = NullSession.class.getName() + StringPool.POUND
048: + PwdGenerator.getPinNumber();
049: _lastAccessedTime = _creationTime;
050: _maxInactiveInterval = 0;
051: _servletContext = null;
052: _new = true;
053: }
054:
055: public Object getAttribute(String name) {
056: return _attributes.get(name);
057: }
058:
059: public Enumeration getAttributeNames() {
060: return Collections.enumeration(_attributes.keySet());
061: }
062:
063: public long getCreationTime() {
064: return _creationTime;
065: }
066:
067: public String getId() {
068: return _id;
069: }
070:
071: public long getLastAccessedTime() {
072: return _lastAccessedTime;
073: }
074:
075: public int getMaxInactiveInterval() {
076: return _maxInactiveInterval;
077: }
078:
079: public ServletContext getServletContext() {
080: return _servletContext;
081: }
082:
083: /**
084: * @deprecated
085: */
086: public javax.servlet.http.HttpSessionContext getSessionContext() {
087: return null;
088: }
089:
090: public Object getValue(String name) {
091: return getAttribute(name);
092: }
093:
094: public String[] getValueNames() {
095: List names = ListUtil.fromEnumeration(getAttributeNames());
096:
097: return (String[]) names.toArray(new String[0]);
098: }
099:
100: public void invalidate() {
101: _attributes.clear();
102: }
103:
104: public boolean isNew() {
105: return _new;
106: }
107:
108: public void putValue(String name, Object value) {
109: setAttribute(name, value);
110: }
111:
112: public void removeAttribute(String name) {
113: _attributes.remove(name);
114: }
115:
116: public void removeValue(String name) {
117: removeAttribute(name);
118: }
119:
120: public void setAttribute(String name, Object value) {
121: _attributes.put(name, value);
122: }
123:
124: public void setMaxInactiveInterval(int maxInactiveInterval) {
125: _maxInactiveInterval = maxInactiveInterval;
126: }
127:
128: private Map _attributes;
129: private long _creationTime;
130: private String _id;
131: private long _lastAccessedTime;
132: private int _maxInactiveInterval;
133: private ServletContext _servletContext;
134: private boolean _new;
135:
136: }
|