1
14
15 package com.liferay.portal.servlet;
16
17 import java.io.Serializable;
18
19 import java.util.Map;
20 import java.util.concurrent.ConcurrentHashMap;
21
22 import javax.servlet.http.HttpSession;
23
24
29 public class SharedSessionAttributeCache implements Serializable {
30
31 public static SharedSessionAttributeCache getInstance(HttpSession session) {
32 synchronized (session) {
33 SharedSessionAttributeCache cache =
34 (SharedSessionAttributeCache)session.getAttribute(_SESSION_KEY);
35
36 if (cache == null) {
37 cache = new SharedSessionAttributeCache();
38
39 session.setAttribute(_SESSION_KEY, cache);
40 }
41
42 return cache;
43 }
44 }
45
46 public boolean contains(String name) {
47 return _attributes.containsKey(name);
48 }
49
50 public Map<String, Object> getValues() {
51 return _attributes;
52 }
53
54 public void removeAttribute(String key) {
55 _attributes.remove(key);
56 }
57
58 public void setAttribute(String key, Object value) {
59 _attributes.put(key, value);
60 }
61
62 private SharedSessionAttributeCache() {
63 _attributes = new ConcurrentHashMap<String, Object>();
64 }
65
66 private static final String _SESSION_KEY =
67 SharedSessionAttributeCache.class.getName();
68
69 private Map<String, Object> _attributes;
70
71 }