001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
025     * @author Michael C. Han
026     * @deprecated As of 7.0.0, with no direct replacement
027     */
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    }