1
19
20 package com.liferay.util.servlet;
21
22 import com.liferay.portal.kernel.util.ListUtil;
23 import com.liferay.portal.kernel.util.StringPool;
24 import com.liferay.util.PwdGenerator;
25
26 import java.util.Collections;
27 import java.util.Enumeration;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import javax.servlet.ServletContext;
33 import javax.servlet.http.HttpSession;
34
35
41 public class NullSession implements HttpSession {
42
43 public NullSession() {
44 _attributes = new HashMap<String, Object>();
45 _creationTime = System.currentTimeMillis();
46 _id =
47 NullSession.class.getName() + StringPool.POUND +
48 PwdGenerator.getPinNumber();
49 _lastAccessedTime = _creationTime;
50 _maxInactiveInterval = 0;
51 _servletContext = null;
52 _new = true;
53 }
54
55 public Object getAttribute(String name) {
56 return _attributes.get(name);
57 }
58
59 public Enumeration<String> getAttributeNames() {
60 return Collections.enumeration(_attributes.keySet());
61 }
62
63 public long getCreationTime() {
64 return _creationTime;
65 }
66
67 public String getId() {
68 return _id;
69 }
70
71 public long getLastAccessedTime() {
72 return _lastAccessedTime;
73 }
74
75 public int getMaxInactiveInterval() {
76 return _maxInactiveInterval;
77 }
78
79 public ServletContext getServletContext() {
80 return _servletContext;
81 }
82
83
86 public javax.servlet.http.HttpSessionContext getSessionContext() {
87 return null;
88 }
89
90 public Object getValue(String name) {
91 return getAttribute(name);
92 }
93
94 public String[] getValueNames() {
95 List<String> names = ListUtil.fromEnumeration(getAttributeNames());
96
97 return names.toArray(new String[0]);
98 }
99
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<String, Object> _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 }