001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }