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.portal.kernel.util.StringUtil;
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<>();
037 _creationTime = System.currentTimeMillis();
038 _id =
039 NullSession.class.getName() + StringPool.POUND +
040 StringUtil.randomId();
041 _lastAccessedTime = _creationTime;
042 _maxInactiveInterval = 0;
043 _servletContext = null;
044 _new = true;
045 }
046
047 @Override
048 public Object getAttribute(String name) {
049 return _attributes.get(name);
050 }
051
052 @Override
053 public Enumeration<String> getAttributeNames() {
054 return Collections.enumeration(_attributes.keySet());
055 }
056
057 @Override
058 public long getCreationTime() {
059 return _creationTime;
060 }
061
062 @Override
063 public String getId() {
064 return _id;
065 }
066
067 @Override
068 public long getLastAccessedTime() {
069 return _lastAccessedTime;
070 }
071
072 @Override
073 public int getMaxInactiveInterval() {
074 return _maxInactiveInterval;
075 }
076
077 @Override
078 public ServletContext getServletContext() {
079 return _servletContext;
080 }
081
082
085 @Deprecated
086 @Override
087 public javax.servlet.http.HttpSessionContext getSessionContext() {
088 return null;
089 }
090
091
094 @Deprecated
095 @Override
096 public Object getValue(String name) {
097 return getAttribute(name);
098 }
099
100
103 @Deprecated
104 @Override
105 public String[] getValueNames() {
106 List<String> names = ListUtil.fromEnumeration(getAttributeNames());
107
108 return names.toArray(new String[0]);
109 }
110
111 @Override
112 public void invalidate() {
113 _attributes.clear();
114 }
115
116 @Override
117 public boolean isNew() {
118 return _new;
119 }
120
121
124 @Deprecated
125 @Override
126 public void putValue(String name, Object value) {
127 setAttribute(name, value);
128 }
129
130 @Override
131 public void removeAttribute(String name) {
132 _attributes.remove(name);
133 }
134
135
138 @Deprecated
139 @Override
140 public void removeValue(String name) {
141 removeAttribute(name);
142 }
143
144 @Override
145 public void setAttribute(String name, Object value) {
146 _attributes.put(name, value);
147 }
148
149 @Override
150 public void setMaxInactiveInterval(int maxInactiveInterval) {
151 _maxInactiveInterval = maxInactiveInterval;
152 }
153
154 private final Map<String, Object> _attributes;
155 private final long _creationTime;
156 private final String _id;
157 private final long _lastAccessedTime;
158 private int _maxInactiveInterval;
159 private final boolean _new;
160 private final ServletContext _servletContext;
161
162 }