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