001
014
015 package com.liferay.util.servlet;
016
017 import com.liferay.portal.kernel.util.ListUtil;
018 import com.liferay.portal.kernel.util.StringPool;
019 import com.liferay.util.PwdGenerator;
020
021 import java.util.Collections;
022 import java.util.Enumeration;
023 import java.util.HashMap;
024 import java.util.List;
025 import java.util.Map;
026
027 import javax.servlet.ServletContext;
028 import javax.servlet.http.HttpSession;
029
030
033 public class NullSession implements HttpSession {
034
035 public NullSession() {
036 _attributes = new HashMap<String, Object>();
037 _creationTime = System.currentTimeMillis();
038 _id =
039 NullSession.class.getName() + StringPool.POUND +
040 PwdGenerator.getPinNumber();
041 _lastAccessedTime = _creationTime;
042 _maxInactiveInterval = 0;
043 _servletContext = null;
044 _new = true;
045 }
046
047 public Object getAttribute(String name) {
048 return _attributes.get(name);
049 }
050
051 public Enumeration<String> getAttributeNames() {
052 return Collections.enumeration(_attributes.keySet());
053 }
054
055 public long getCreationTime() {
056 return _creationTime;
057 }
058
059 public String getId() {
060 return _id;
061 }
062
063 public long getLastAccessedTime() {
064 return _lastAccessedTime;
065 }
066
067 public int getMaxInactiveInterval() {
068 return _maxInactiveInterval;
069 }
070
071 public ServletContext getServletContext() {
072 return _servletContext;
073 }
074
075
078 public javax.servlet.http.HttpSessionContext getSessionContext() {
079 return null;
080 }
081
082 public Object getValue(String name) {
083 return getAttribute(name);
084 }
085
086 public String[] getValueNames() {
087 List<String> names = ListUtil.fromEnumeration(getAttributeNames());
088
089 return names.toArray(new String[0]);
090 }
091
092 public void invalidate() {
093 _attributes.clear();
094 }
095
096 public boolean isNew() {
097 return _new;
098 }
099
100 public void putValue(String name, Object value) {
101 setAttribute(name, value);
102 }
103
104 public void removeAttribute(String name) {
105 _attributes.remove(name);
106 }
107
108 public void removeValue(String name) {
109 removeAttribute(name);
110 }
111
112 public void setAttribute(String name, Object value) {
113 _attributes.put(name, value);
114 }
115
116 public void setMaxInactiveInterval(int maxInactiveInterval) {
117 _maxInactiveInterval = maxInactiveInterval;
118 }
119
120 private Map<String, Object> _attributes;
121 private long _creationTime;
122 private String _id;
123 private long _lastAccessedTime;
124 private int _maxInactiveInterval;
125 private ServletContext _servletContext;
126 private boolean _new;
127
128 }