001    /**
002     * Copyright (c) 2000-2013 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.kernel.portlet;
016    
017    import com.liferay.portal.kernel.security.pacl.PACLConstants;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    
020    import java.util.Map;
021    import java.util.concurrent.ConcurrentHashMap;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class PortletBagPool {
027    
028            public static PortletBag get(String portletId) {
029                    PortalRuntimePermission.checkPortletBagPool(portletId);
030    
031                    return _instance._get(portletId);
032            }
033    
034            public static void put(String portletId, PortletBag portletBag) {
035                    PortalRuntimePermission.checkPortletBagPool(portletId);
036    
037                    _instance._put(portletId, portletBag);
038            }
039    
040            public static PortletBag remove(String portletId) {
041                    PortalRuntimePermission.checkPortletBagPool(portletId);
042    
043                    return _instance._remove(portletId);
044            }
045    
046            public static void reset() {
047                    PortalRuntimePermission.checkPortletBagPool(
048                            PACLConstants.
049                                    PORTAL_RUNTIME_PERMISSION_PORTLET_BAG_POOL_ALL_PORTLETS);
050    
051                    _instance._reset();
052            }
053    
054            private PortletBagPool() {
055                    _portletBagPool = new ConcurrentHashMap<String, PortletBag>();
056            }
057    
058            private PortletBag _get(String portletId) {
059                    return _portletBagPool.get(portletId);
060            }
061    
062            private void _put(String portletId, PortletBag portletBag) {
063                    _portletBagPool.put(portletId, portletBag);
064            }
065    
066            private PortletBag _remove(String portletId) {
067                    return _portletBagPool.remove(portletId);
068            }
069    
070            private void _reset() {
071                    _portletBagPool.clear();
072            }
073    
074            private static PortletBagPool _instance = new PortletBagPool();
075    
076            private Map<String, PortletBag> _portletBagPool;
077    
078    }