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