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