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
027 public class SharedSessionAttributeCache implements Serializable {
028
029 public static SharedSessionAttributeCache getInstance(HttpSession session) {
030 synchronized (session) {
031 SharedSessionAttributeCache cache =
032 (SharedSessionAttributeCache)session.getAttribute(_SESSION_KEY);
033
034 if (cache == null) {
035 cache = new SharedSessionAttributeCache();
036
037 session.setAttribute(_SESSION_KEY, cache);
038 }
039
040 return cache;
041 }
042 }
043
044 public boolean contains(String name) {
045 return _attributes.containsKey(name);
046 }
047
048 public Map<String, Object> getValues() {
049 return _attributes;
050 }
051
052 public void removeAttribute(String key) {
053 _attributes.remove(key);
054 }
055
056 public void setAttribute(String key, Object value) {
057 _attributes.put(key, value);
058 }
059
060 private SharedSessionAttributeCache() {
061 _attributes = new ConcurrentHashMap<String, Object>();
062 }
063
064 private static final String _SESSION_KEY =
065 SharedSessionAttributeCache.class.getName();
066
067 private Map<String, Object> _attributes;
068
069 }