1
22
23 package com.liferay.util.servlet;
24
25 import com.liferay.portal.kernel.util.ListUtil;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.util.PwdGenerator;
28
29 import java.util.Collections;
30 import java.util.Enumeration;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 import javax.servlet.ServletContext;
36 import javax.servlet.http.HttpSession;
37
38
44 public class NullSession implements HttpSession {
45
46 public NullSession() {
47 _attributes = new HashMap<String, Object>();
48 _creationTime = System.currentTimeMillis();
49 _id =
50 NullSession.class.getName() + StringPool.POUND +
51 PwdGenerator.getPinNumber();
52 _lastAccessedTime = _creationTime;
53 _maxInactiveInterval = 0;
54 _servletContext = null;
55 _new = true;
56 }
57
58 public Object getAttribute(String name) {
59 return _attributes.get(name);
60 }
61
62 public Enumeration<String> getAttributeNames() {
63 return Collections.enumeration(_attributes.keySet());
64 }
65
66 public long getCreationTime() {
67 return _creationTime;
68 }
69
70 public String getId() {
71 return _id;
72 }
73
74 public long getLastAccessedTime() {
75 return _lastAccessedTime;
76 }
77
78 public int getMaxInactiveInterval() {
79 return _maxInactiveInterval;
80 }
81
82 public ServletContext getServletContext() {
83 return _servletContext;
84 }
85
86
89 public javax.servlet.http.HttpSessionContext getSessionContext() {
90 return null;
91 }
92
93 public Object getValue(String name) {
94 return getAttribute(name);
95 }
96
97 public String[] getValueNames() {
98 List<String> names = ListUtil.fromEnumeration(getAttributeNames());
99
100 return names.toArray(new String[0]);
101 }
102
103 public void invalidate() {
104 _attributes.clear();
105 }
106
107 public boolean isNew() {
108 return _new;
109 }
110
111 public void putValue(String name, Object value) {
112 setAttribute(name, value);
113 }
114
115 public void removeAttribute(String name) {
116 _attributes.remove(name);
117 }
118
119 public void removeValue(String name) {
120 removeAttribute(name);
121 }
122
123 public void setAttribute(String name, Object value) {
124 _attributes.put(name, value);
125 }
126
127 public void setMaxInactiveInterval(int maxInactiveInterval) {
128 _maxInactiveInterval = maxInactiveInterval;
129 }
130
131 private Map<String, Object> _attributes;
132 private long _creationTime;
133 private String _id;
134 private long _lastAccessedTime;
135 private int _maxInactiveInterval;
136 private ServletContext _servletContext;
137 private boolean _new;
138
139 }