1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.service.impl;
16  
17  import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
18  import com.liferay.portal.kernel.cache.PortalCache;
19  import com.liferay.portal.kernel.util.StringBundler;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portlet.PortletPreferencesImpl;
22  
23  import java.util.Map;
24  import java.util.concurrent.ConcurrentHashMap;
25  
26  /**
27   * <a href="PortletPreferencesLocalUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Michael Young
31   */
32  public class PortletPreferencesLocalUtil {
33  
34      public static final String CACHE_NAME =
35          PortletPreferencesLocalUtil.class.getName();
36  
37      protected static void clearPreferencesPool() {
38          _cache.removeAll();
39      }
40  
41      protected static void clearPreferencesPool(long ownerId, int ownerType) {
42          String key = _encodeKey(ownerId, ownerType);
43  
44          _cache.remove(key);
45      }
46  
47      protected static Map<String, PortletPreferencesImpl> getPreferencesPool(
48              long ownerId, int ownerType) {
49          String key = _encodeKey(ownerId, ownerType);
50  
51          Map<String, PortletPreferencesImpl> preferencesPool =
52              (Map<String, PortletPreferencesImpl>)_cache.get(key);
53  
54          if (preferencesPool == null) {
55              preferencesPool =
56                  new ConcurrentHashMap<String, PortletPreferencesImpl>();
57  
58              _cache.put(key, preferencesPool);
59          }
60  
61          return preferencesPool;
62      }
63  
64      private static String _encodeKey(long ownerId, int ownerType) {
65          StringBundler sb = new StringBundler(5);
66  
67          sb.append(CACHE_NAME);
68          sb.append(StringPool.POUND);
69          sb.append(ownerId);
70          sb.append(StringPool.POUND);
71          sb.append(ownerType);
72  
73          return sb.toString();
74      }
75  
76      private static PortalCache _cache = MultiVMPoolUtil.getCache(CACHE_NAME);
77  
78  }