001    /**
002     * Copyright (c) 2000-2010 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.util;
016    
017    import java.util.Map;
018    import java.util.concurrent.ConcurrentHashMap;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public class WebAppPool {
024    
025            public static Object get(String webAppId, String key) {
026                    return _instance._get(webAppId, key);
027            }
028    
029            public static void put(String webAppId, String key, Object obj) {
030                    _instance._put(webAppId, key, obj);
031            }
032    
033            public static Object remove(String webAppId, String key) {
034                    return _instance._remove(webAppId, key);
035            }
036    
037            private WebAppPool() {
038                    _webAppPool = new ConcurrentHashMap<String, Map<String, Object>>();
039            }
040    
041            private Object _get(String webAppId, String key) {
042                    Map<String, Object> map = _webAppPool.get(webAppId);
043    
044                    if (map == null) {
045                            return null;
046                    }
047                    else {
048                            return map.get(key);
049                    }
050            }
051    
052            private void _put(String webAppId, String key, Object obj) {
053                    Map<String, Object> map = _webAppPool.get(webAppId);
054    
055                    if (map == null) {
056                            map = new ConcurrentHashMap<String, Object>();
057    
058                            _webAppPool.put(webAppId, map);
059                    }
060    
061                    map.put(key, obj);
062            }
063    
064            private Object _remove(String webAppId, String key) {
065                    Map<String, Object> map = _webAppPool.get(webAppId);
066    
067                    if (map == null) {
068                            return null;
069                    }
070                    else {
071                            return map.remove(key);
072                    }
073            }
074    
075            private static WebAppPool _instance = new WebAppPool();
076    
077            private Map<String, Map<String, Object>> _webAppPool;
078    
079    }