001
014
015 package com.liferay.portal.servlet;
016
017 import java.io.Serializable;
018
019 import java.util.Map;
020 import java.util.concurrent.ConcurrentHashMap;
021
022 import javax.servlet.http.HttpSession;
023
024
028 public class SharedSessionAttributeCache implements Serializable {
029
030 public static SharedSessionAttributeCache getInstance(HttpSession session) {
031 synchronized (session) {
032 SharedSessionAttributeCache cache =
033 (SharedSessionAttributeCache)session.getAttribute(_SESSION_KEY);
034
035 if (cache == null) {
036 cache = new SharedSessionAttributeCache();
037
038 session.setAttribute(_SESSION_KEY, cache);
039 }
040
041 return cache;
042 }
043 }
044
045 public boolean contains(String name) {
046 return _attributes.containsKey(name);
047 }
048
049 public Map<String, Object> getValues() {
050 return _attributes;
051 }
052
053 public void removeAttribute(String key) {
054 _attributes.remove(key);
055 }
056
057 public void setAttribute(String key, Object value) {
058 _attributes.put(key, value);
059 }
060
061 private SharedSessionAttributeCache() {
062 _attributes = new ConcurrentHashMap<String, Object>();
063 }
064
065 private static final String _SESSION_KEY =
066 SharedSessionAttributeCache.class.getName();
067
068 private final Map<String, Object> _attributes;
069
070 }